Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/blenlib/intern/mesh_intersect.cc')
-rw-r--r--source/blender/blenlib/intern/mesh_intersect.cc88
1 files changed, 43 insertions, 45 deletions
diff --git a/source/blender/blenlib/intern/mesh_intersect.cc b/source/blender/blenlib/intern/mesh_intersect.cc
index 1f150137ba3..982759ffcff 100644
--- a/source/blender/blenlib/intern/mesh_intersect.cc
+++ b/source/blender/blenlib/intern/mesh_intersect.cc
@@ -30,15 +30,13 @@
# 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"
# include "BLI_math_boolean.hh"
# include "BLI_math_mpq.hh"
-# include "BLI_mpq2.hh"
-# include "BLI_mpq3.hh"
+# include "BLI_math_vec_mpq_types.hh"
+# include "BLI_math_vec_types.hh"
# include "BLI_polyfill_2d.h"
# include "BLI_set.hh"
# include "BLI_span.hh"
@@ -198,14 +196,14 @@ void Face::populate_plane(bool need_exact)
for (int i : index_range()) {
co[i] = vert[i]->co_exact;
}
- normal_exact = mpq3::cross_poly(co);
+ normal_exact = math::cross_poly(co.as_span());
}
else {
mpq3 tr02 = vert[0]->co_exact - vert[2]->co_exact;
mpq3 tr12 = vert[1]->co_exact - vert[2]->co_exact;
- normal_exact = mpq3::cross(tr02, tr12);
+ normal_exact = math::cross(tr02, tr12);
}
- mpq_class d_exact = -mpq3::dot(normal_exact, vert[0]->co_exact);
+ mpq_class d_exact = -math::dot(normal_exact, vert[0]->co_exact);
plane = new Plane(normal_exact, d_exact);
}
else {
@@ -215,14 +213,14 @@ void Face::populate_plane(bool need_exact)
for (int i : index_range()) {
co[i] = vert[i]->co;
}
- normal = double3::cross_poly(co);
+ normal = math::cross_poly(co.as_span());
}
else {
double3 tr02 = vert[0]->co - vert[2]->co;
double3 tr12 = vert[1]->co - vert[2]->co;
- normal = double3::cross_high_precision(tr02, tr12);
+ normal = math::cross(tr02, tr12);
}
- double d = -double3::dot(normal, vert[0]->co);
+ double d = -math::dot(normal, vert[0]->co);
plane = new Plane(normal, d);
}
}
@@ -1098,15 +1096,15 @@ static mpq2 project_3d_to_2d(const mpq3 &p3d, int proj_axis)
*/
static double supremum_dot_cross(const double3 &a, const double3 &b)
{
- double3 abs_a = double3::abs(a);
- double3 abs_b = double3::abs(b);
+ double3 abs_a = math::abs(a);
+ double3 abs_b = math::abs(b);
double3 c;
/* This is dot(cross(a, b), cross(a,b)) but using absolute values for a and b
* and always using + when operation is + or -. */
c[0] = abs_a[1] * abs_b[2] + abs_a[2] * abs_b[1];
c[1] = abs_a[2] * abs_b[0] + abs_a[0] * abs_b[2];
c[2] = abs_a[0] * abs_b[1] + abs_a[1] * abs_b[0];
- return double3::dot(c, c);
+ return math::dot(c, c);
}
/* The index of dot when inputs are plane_coords with index 1 is much higher.
@@ -1143,11 +1141,11 @@ static int filter_plane_side(const double3 &p,
const double3 &abs_plane_p,
const double3 &abs_plane_no)
{
- double d = double3::dot(p - plane_p, plane_no);
+ double d = math::dot(p - plane_p, plane_no);
if (d == 0.0) {
return 0;
}
- double supremum = double3::dot(abs_p + abs_plane_p, abs_plane_no);
+ double supremum = math::dot(abs_p + abs_plane_p, abs_plane_no);
double err_bound = supremum * index_plane_side * DBL_EPSILON;
if (fabs(d) > err_bound) {
return d > 0 ? 1 : -1;
@@ -1178,9 +1176,9 @@ static inline mpq3 tti_interp(
ab -= b;
ac = a;
ac -= c;
- mpq_class den = mpq3::dot_with_buffer(ab, n, dotbuf);
+ mpq_class den = math::dot_with_buffer(ab, n, dotbuf);
BLI_assert(den != 0);
- mpq_class alpha = mpq3::dot_with_buffer(ac, n, dotbuf) / den;
+ mpq_class alpha = math::dot_with_buffer(ac, n, dotbuf) / den;
return a - alpha * ab;
}
@@ -1209,7 +1207,7 @@ static inline int tti_above(const mpq3 &a,
n.y = ba.z * ca.x - ba.x * ca.z;
n.z = ba.x * ca.y - ba.y * ca.x;
- return sgn(mpq3::dot_with_buffer(ad, n, dotbuf));
+ return sgn(math::dot_with_buffer(ad, n, dotbuf));
}
/**
@@ -1428,11 +1426,11 @@ static ITT_value intersect_tri_tri(const IMesh &tm, int t1, int t2)
const double3 &d_r2 = vr2->co;
const double3 &d_n2 = tri2.plane->norm;
- const double3 &abs_d_p1 = double3::abs(d_p1);
- const double3 &abs_d_q1 = double3::abs(d_q1);
- const double3 &abs_d_r1 = double3::abs(d_r1);
- const double3 &abs_d_r2 = double3::abs(d_r2);
- const double3 &abs_d_n2 = double3::abs(d_n2);
+ const double3 &abs_d_p1 = math::abs(d_p1);
+ const double3 &abs_d_q1 = math::abs(d_q1);
+ const double3 &abs_d_r1 = math::abs(d_r1);
+ const double3 &abs_d_r2 = math::abs(d_r2);
+ const double3 &abs_d_n2 = math::abs(d_n2);
int sp1 = filter_plane_side(d_p1, d_r2, d_n2, abs_d_p1, abs_d_r2, abs_d_n2);
int sq1 = filter_plane_side(d_q1, d_r2, d_n2, abs_d_q1, abs_d_r2, abs_d_n2);
@@ -1448,9 +1446,9 @@ static ITT_value intersect_tri_tri(const IMesh &tm, int t1, int t2)
}
const double3 &d_n1 = tri1.plane->norm;
- const double3 &abs_d_p2 = double3::abs(d_p2);
- const double3 &abs_d_q2 = double3::abs(d_q2);
- const double3 &abs_d_n1 = double3::abs(d_n1);
+ const double3 &abs_d_p2 = math::abs(d_p2);
+ const double3 &abs_d_q2 = math::abs(d_q2);
+ const double3 &abs_d_n1 = math::abs(d_n1);
int sp2 = filter_plane_side(d_p2, d_r1, d_n1, abs_d_p2, abs_d_r1, abs_d_n1);
int sq2 = filter_plane_side(d_q2, d_r1, d_n1, abs_d_q2, abs_d_r1, abs_d_n1);
@@ -1477,17 +1475,17 @@ static ITT_value intersect_tri_tri(const IMesh &tm, int t1, int t2)
if (sp1 == 0) {
buf[0] = p1;
buf[0] -= r2;
- sp1 = sgn(mpq3::dot_with_buffer(buf[0], n2, buf[1]));
+ sp1 = sgn(math::dot_with_buffer(buf[0], n2, buf[1]));
}
if (sq1 == 0) {
buf[0] = q1;
buf[0] -= r2;
- sq1 = sgn(mpq3::dot_with_buffer(buf[0], n2, buf[1]));
+ sq1 = sgn(math::dot_with_buffer(buf[0], n2, buf[1]));
}
if (sr1 == 0) {
buf[0] = r1;
buf[0] -= r2;
- sr1 = sgn(mpq3::dot_with_buffer(buf[0], n2, buf[1]));
+ sr1 = sgn(math::dot_with_buffer(buf[0], n2, buf[1]));
}
if (dbg_level > 1) {
@@ -1509,17 +1507,17 @@ static ITT_value intersect_tri_tri(const IMesh &tm, int t1, int t2)
if (sp2 == 0) {
buf[0] = p2;
buf[0] -= r1;
- sp2 = sgn(mpq3::dot_with_buffer(buf[0], n1, buf[1]));
+ sp2 = sgn(math::dot_with_buffer(buf[0], n1, buf[1]));
}
if (sq2 == 0) {
buf[0] = q2;
buf[0] -= r1;
- sq2 = sgn(mpq3::dot_with_buffer(buf[0], n1, buf[1]));
+ sq2 = sgn(math::dot_with_buffer(buf[0], n1, buf[1]));
}
if (sr2 == 0) {
buf[0] = r2;
buf[0] -= r1;
- sr2 = sgn(mpq3::dot_with_buffer(buf[0], n1, buf[1]));
+ sr2 = sgn(math::dot_with_buffer(buf[0], n1, buf[1]));
}
if (dbg_level > 1) {
@@ -1721,7 +1719,7 @@ static CDT_data prepare_cdt_input(const IMesh &tm, int t, const Vector<ITT_value
BLI_assert(tm.face(t)->plane_populated());
ans.t_plane = tm.face(t)->plane;
BLI_assert(ans.t_plane->exact_populated());
- ans.proj_axis = mpq3::dominant_axis(ans.t_plane->norm_exact);
+ ans.proj_axis = math::dominant_axis(ans.t_plane->norm_exact);
prepare_need_tri(ans, tm, t);
for (const ITT_value &itt : itts) {
switch (itt.kind) {
@@ -1757,7 +1755,7 @@ static CDT_data prepare_cdt_input_for_cluster(const IMesh &tm,
BLI_assert(tm.face(t0)->plane_populated());
ans.t_plane = tm.face(t0)->plane;
BLI_assert(ans.t_plane->exact_populated());
- ans.proj_axis = mpq3::dominant_axis(ans.t_plane->norm_exact);
+ ans.proj_axis = math::dominant_axis(ans.t_plane->norm_exact);
for (const int t : cl) {
prepare_need_tri(ans, tm, t);
}
@@ -2004,9 +2002,9 @@ static bool is_quad_flip_first_third(const double3 &v1,
const double3 &normal)
{
double3 dir_v3v1 = v3 - v1;
- double3 tangent = double3::cross_high_precision(dir_v3v1, normal);
- double dot = double3::dot(v1, tangent);
- return (double3::dot(v4, tangent) >= dot) || (double3::dot(v2, tangent) <= dot);
+ double3 tangent = math::cross(dir_v3v1, normal);
+ double dot = math::dot(v1, tangent);
+ return (math::dot(v4, tangent) >= dot) || (math::dot(v2, tangent) <= dot);
}
/**
@@ -2124,7 +2122,7 @@ static Array<Face *> exact_triangulate_poly(Face *f, IMeshArena *arena)
f->populate_plane(false);
}
const double3 &poly_normal = f->plane->norm;
- int axis = double3::dominant_axis(poly_normal);
+ int axis = math::dominant_axis(poly_normal);
/* If project down y axis as opposed to x or z, the orientation
* of the polygon will be reversed.
* Yet another reversal happens if the poly normal in the dominant
@@ -2203,15 +2201,15 @@ static bool face_is_degenerate(const Face *f)
}
double3 da = v2->co - v0->co;
double3 db = v2->co - v1->co;
- double3 dab = double3::cross_high_precision(da, db);
- double dab_length_squared = dab.length_squared();
+ double3 dab = math::cross(da, db);
+ double dab_length_squared = math::length_squared(dab);
double err_bound = supremum_dot_cross(dab, dab) * index_dot_cross * DBL_EPSILON;
if (dab_length_squared > err_bound) {
return false;
}
mpq3 a = v2->co_exact - v0->co_exact;
mpq3 b = v2->co_exact - v1->co_exact;
- mpq3 ab = mpq3::cross(a, b);
+ mpq3 ab = math::cross(a, b);
if (ab.x == 0 && ab.y == 0 && ab.z == 0) {
return true;
}
@@ -2231,8 +2229,8 @@ static bool any_degenerate_tris_fast(const Array<Face *> triangulation)
}
double3 da = v2->co - v0->co;
double3 db = v2->co - v1->co;
- double da_length_squared = da.length_squared();
- double db_length_squared = db.length_squared();
+ double da_length_squared = math::length_squared(da);
+ double db_length_squared = math::length_squared(db);
if (da_length_squared == 0.0 || db_length_squared == 0.0) {
return true;
}
@@ -2240,8 +2238,8 @@ static bool any_degenerate_tris_fast(const Array<Face *> triangulation)
* The triangle is almost degenerate if sin t is almost 0.
* sin^2 t = |da x db|^2 / (|da|^2 |db|^2)
*/
- double3 dab = double3::cross_high_precision(da, db);
- double dab_length_squared = dab.length_squared();
+ double3 dab = math::cross(da, db);
+ double dab_length_squared = math::length_squared(dab);
double sin_squared_t = dab_length_squared / (da_length_squared * db_length_squared);
if (sin_squared_t < 1e-8) {
return true;