From e5766752d04794c2693dedad75baeb8c7d68f4cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Foucault?= Date: Wed, 12 Jan 2022 12:43:40 +0100 Subject: Revert "BLI: Refactor vector types & functions to use templates" Reverted because the commit removes a lot of commits. This reverts commit a2c1c368af48644fa8995ecbe7138cc0d7900c30. --- source/blender/blenlib/intern/mesh_boolean.cc | 51 ++++++++++++++------------- 1 file changed, 26 insertions(+), 25 deletions(-) (limited to 'source/blender/blenlib/intern/mesh_boolean.cc') diff --git a/source/blender/blenlib/intern/mesh_boolean.cc b/source/blender/blenlib/intern/mesh_boolean.cc index a3eae1896d3..ce4db0c6b9d 100644 --- a/source/blender/blenlib/intern/mesh_boolean.cc +++ b/source/blender/blenlib/intern/mesh_boolean.cc @@ -28,6 +28,8 @@ # include "BLI_array.hh" # include "BLI_assert.h" # include "BLI_delaunay_2d.h" +# include "BLI_double3.hh" +# include "BLI_float3.hh" # include "BLI_hash.hh" # include "BLI_kdopbvh.h" # include "BLI_map.hh" @@ -35,9 +37,8 @@ # include "BLI_math_boolean.hh" # include "BLI_math_geom.h" # include "BLI_math_mpq.hh" -# include "BLI_math_vec_mpq_types.hh" -# include "BLI_math_vec_types.hh" # include "BLI_mesh_intersect.hh" +# include "BLI_mpq3.hh" # include "BLI_set.hh" # include "BLI_span.hh" # include "BLI_stack.hh" @@ -1632,13 +1633,13 @@ static Edge find_good_sorting_edge(const Vert *testp, ordinate[axis_next] = -abscissa[axis]; ordinate[axis_next_next] = 0; /* By construction, dot(abscissa, ordinate) == 0, so they are perpendicular. */ - mpq3 normal = math::cross(abscissa, ordinate); + mpq3 normal = mpq3::cross(abscissa, ordinate); if (dbg_level > 0) { std::cout << "abscissa = " << abscissa << "\n"; std::cout << "ordinate = " << ordinate << "\n"; std::cout << "normal = " << normal << "\n"; } - mpq_class nlen2 = math::length_squared(normal); + mpq_class nlen2 = normal.length_squared(); mpq_class max_abs_slope = -1; Edge esort; const Vector &edges = tmtopo.vert_edges(closestp); @@ -1647,12 +1648,12 @@ static Edge find_good_sorting_edge(const Vert *testp, const mpq3 &co_other = v_other->co_exact; mpq3 evec = co_other - co_closest; /* Get projection of evec onto plane of abscissa and ordinate. */ - mpq3 proj_evec = evec - (math::dot(evec, normal) / nlen2) * normal; + mpq3 proj_evec = evec - (mpq3::dot(evec, normal) / nlen2) * normal; /* The projection calculations along the abscissa and ordinate should * be scaled by 1/abscissa and 1/ordinate respectively, * but we can skip: it won't affect which `evec` has the maximum slope. */ - mpq_class evec_a = math::dot(proj_evec, abscissa); - mpq_class evec_o = math::dot(proj_evec, ordinate); + mpq_class evec_a = mpq3::dot(proj_evec, abscissa); + mpq_class evec_o = mpq3::dot(proj_evec, ordinate); if (dbg_level > 0) { std::cout << "e = " << e << "\n"; std::cout << "v_other = " << v_other << "\n"; @@ -1790,8 +1791,8 @@ static mpq_class closest_on_tri_to_point(const mpq3 &p, ap = p; ap -= a; - mpq_class d1 = math::dot_with_buffer(ab, ap, m); - mpq_class d2 = math::dot_with_buffer(ac, ap, m); + mpq_class d1 = mpq3::dot_with_buffer(ab, ap, m); + mpq_class d2 = mpq3::dot_with_buffer(ac, ap, m); if (d1 <= 0 && d2 <= 0) { /* Barycentric coordinates (1,0,0). */ *r_edge = -1; @@ -1799,13 +1800,13 @@ static mpq_class closest_on_tri_to_point(const mpq3 &p, if (dbg_level > 0) { std::cout << " answer = a\n"; } - return math::distance_squared_with_buffer(p, a, m); + return mpq3::distance_squared_with_buffer(p, a, m); } /* Check if p in vertex region outside b. */ bp = p; bp -= b; - mpq_class d3 = math::dot_with_buffer(ab, bp, m); - mpq_class d4 = math::dot_with_buffer(ac, bp, m); + mpq_class d3 = mpq3::dot_with_buffer(ab, bp, m); + mpq_class d4 = mpq3::dot_with_buffer(ac, bp, m); if (d3 >= 0 && d4 <= d3) { /* Barycentric coordinates (0,1,0). */ *r_edge = -1; @@ -1813,7 +1814,7 @@ static mpq_class closest_on_tri_to_point(const mpq3 &p, if (dbg_level > 0) { std::cout << " answer = b\n"; } - return math::distance_squared_with_buffer(p, b, m); + return mpq3::distance_squared_with_buffer(p, b, m); } /* Check if p in region of ab. */ mpq_class vc = d1 * d4 - d3 * d2; @@ -1828,13 +1829,13 @@ static mpq_class closest_on_tri_to_point(const mpq3 &p, if (dbg_level > 0) { std::cout << " answer = on ab at " << r << "\n"; } - return math::distance_squared_with_buffer(p, r, m); + return mpq3::distance_squared_with_buffer(p, r, m); } /* Check if p in vertex region outside c. */ cp = p; cp -= c; - mpq_class d5 = math::dot_with_buffer(ab, cp, m); - mpq_class d6 = math::dot_with_buffer(ac, cp, m); + mpq_class d5 = mpq3::dot_with_buffer(ab, cp, m); + mpq_class d6 = mpq3::dot_with_buffer(ac, cp, m); if (d6 >= 0 && d5 <= d6) { /* Barycentric coordinates (0,0,1). */ *r_edge = -1; @@ -1842,7 +1843,7 @@ static mpq_class closest_on_tri_to_point(const mpq3 &p, if (dbg_level > 0) { std::cout << " answer = c\n"; } - return math::distance_squared_with_buffer(p, c, m); + return mpq3::distance_squared_with_buffer(p, c, m); } /* Check if p in edge region of ac. */ mpq_class vb = d5 * d2 - d1 * d6; @@ -1857,7 +1858,7 @@ static mpq_class closest_on_tri_to_point(const mpq3 &p, if (dbg_level > 0) { std::cout << " answer = on ac at " << r << "\n"; } - return math::distance_squared_with_buffer(p, r, m); + return mpq3::distance_squared_with_buffer(p, r, m); } /* Check if p in edge region of bc. */ mpq_class va = d3 * d6 - d5 * d4; @@ -1873,7 +1874,7 @@ static mpq_class closest_on_tri_to_point(const mpq3 &p, if (dbg_level > 0) { std::cout << " answer = on bc at " << r << "\n"; } - return math::distance_squared_with_buffer(p, r, m); + return mpq3::distance_squared_with_buffer(p, r, m); } /* p inside face region. Compute barycentric coordinates (u,v,w). */ mpq_class denom = 1 / (va + vb + vc); @@ -1889,7 +1890,7 @@ static mpq_class closest_on_tri_to_point(const mpq3 &p, if (dbg_level > 0) { std::cout << " answer = inside at " << r << "\n"; } - return math::distance_squared_with_buffer(p, r, m); + return mpq3::distance_squared_with_buffer(p, r, m); } static float closest_on_tri_to_point_float_dist_squared(const float3 &p, @@ -2609,7 +2610,7 @@ static void test_tri_inside_shapes(const IMesh &tm, double3 test_point = calc_point_inside_tri_db(tri_test); /* Offset the test point a tiny bit in the tri_test normal direction. */ tri_test.populate_plane(false); - double3 norm = math::normalize(tri_test.plane->norm); + double3 norm = tri_test.plane->norm.normalized(); const double offset_amount = 1e-5; double3 offset_test_point = test_point + offset_amount * norm; if (dbg_level > 0) { @@ -3001,7 +3002,7 @@ static void init_face_merge_state(FaceMergeState *fms, std::cout << "process tri = " << &tri << "\n"; } BLI_assert(tri.plane_populated()); - if (math::dot(norm, tri.plane->norm) <= 0.0) { + if (double3::dot(norm, tri.plane->norm) <= 0.0) { if (dbg_level > 0) { std::cout << "triangle has wrong orientation, skipping\n"; } @@ -3026,7 +3027,7 @@ static void init_face_merge_state(FaceMergeState *fms, } if (me_index == -1) { double3 vec = new_me.v2->co - new_me.v1->co; - new_me.len_squared = math::length_squared(vec); + new_me.len_squared = vec.length_squared(); new_me.orig = tri.edge_orig[i]; new_me.is_intersect = tri.is_intersect[i]; new_me.dissolvable = (new_me.orig == NO_INDEX && !new_me.is_intersect); @@ -3266,7 +3267,7 @@ static Vector merge_tris_for_face(Vector tris, bool done = false; double3 first_tri_normal = tm.face(tris[0])->plane->norm; double3 second_tri_normal = tm.face(tris[1])->plane->norm; - if (tris.size() == 2 && math::dot(first_tri_normal, second_tri_normal) > 0.0) { + if (tris.size() == 2 && double3::dot(first_tri_normal, second_tri_normal) > 0.0) { /* Is this a case where quad with one diagonal remained unchanged? * Worth special handling because this case will be very common. */ Face &tri1 = *tm.face(tris[0]); @@ -3331,7 +3332,7 @@ static bool approx_in_line(const double3 &a, const double3 &b, const double3 &c) { double3 vec1 = b - a; double3 vec2 = c - b; - double cos_ang = math::dot(math::normalize(vec1), math::normalize(vec2)); + double cos_ang = double3::dot(vec1.normalized(), vec2.normalized()); return fabs(cos_ang - 1.0) < 1e-4; } -- cgit v1.2.3