[Bf-blender-cvs] [b3d34a6690a] temp-experimental-cpp-math-refactor: use new style for isect_seg_seg and cross_poly

Jacques Lucke noreply at git.blender.org
Mon Jan 11 18:40:53 CET 2021


Commit: b3d34a6690a68e6922bc0f6d7a66482a12625b78
Author: Jacques Lucke
Date:   Mon Jan 11 18:39:12 2021 +0100
Branches: temp-experimental-cpp-math-refactor
https://developer.blender.org/rBb3d34a6690a68e6922bc0f6d7a66482a12625b78

use new style for isect_seg_seg and cross_poly

===================================================================

M	source/blender/blenlib/BLI_double2.hh
M	source/blender/blenlib/BLI_double3.hh
M	source/blender/blenlib/BLI_float2.hh
M	source/blender/blenlib/BLI_mpq2.hh
M	source/blender/blenlib/BLI_mpq3.hh
M	source/blender/blenlib/intern/delaunay_2d.cc
M	source/blender/blenlib/intern/math_vec.cc
M	source/blender/blenlib/intern/mesh_intersect.cc

===================================================================

diff --git a/source/blender/blenlib/BLI_double2.hh b/source/blender/blenlib/BLI_double2.hh
index 236c429861a..cd8f4385504 100644
--- a/source/blender/blenlib/BLI_double2.hh
+++ b/source/blender/blenlib/BLI_double2.hh
@@ -50,21 +50,6 @@ struct double2 {
   {
     return &x;
   }
-
-  struct isect_result {
-    enum {
-      LINE_LINE_COLINEAR = -1,
-      LINE_LINE_NONE = 0,
-      LINE_LINE_EXACT = 1,
-      LINE_LINE_CROSS = 2,
-    } kind;
-    double lambda;
-  };
-
-  static isect_result isect_seg_seg(const double2 &v1,
-                                    const double2 &v2,
-                                    const double2 &v3,
-                                    const double2 &v4);
 };
 
 inline double length(const double2 &a)
@@ -140,6 +125,21 @@ inline double distance_squared(const double2 &a, const double2 &b)
   return dot(diff, diff);
 }
 
+struct isect_result_double2 {
+  enum {
+    LINE_LINE_COLINEAR = -1,
+    LINE_LINE_NONE = 0,
+    LINE_LINE_EXACT = 1,
+    LINE_LINE_CROSS = 2,
+  } kind;
+  double lambda;
+};
+
+isect_result_double2 isect_seg_seg(const double2 &v1,
+                                   const double2 &v2,
+                                   const double2 &v3,
+                                   const double2 &v4);
+
 }  // namespace blender::math
 
 namespace blender {
diff --git a/source/blender/blenlib/BLI_double3.hh b/source/blender/blenlib/BLI_double3.hh
index 5f7b0f330b9..758ddd2edbe 100644
--- a/source/blender/blenlib/BLI_double3.hh
+++ b/source/blender/blenlib/BLI_double3.hh
@@ -61,8 +61,6 @@ struct double3 {
   {
     return &x;
   }
-
-  static double3 cross_poly(Span<double3> poly);
 };
 
 inline double normalize_and_get_length(double3 &a)
@@ -243,6 +241,8 @@ inline int dominant_axis(const double3 &a)
   return ((x > y) ? ((x > z) ? 0 : 2) : ((y > z) ? 1 : 2));
 }
 
+double3 cross_poly(Span<double3> poly);
+
 }  // namespace blender::math
 
 namespace blender {
diff --git a/source/blender/blenlib/BLI_float2.hh b/source/blender/blenlib/BLI_float2.hh
index 77173aaa0d2..bb06906f1a1 100644
--- a/source/blender/blenlib/BLI_float2.hh
+++ b/source/blender/blenlib/BLI_float2.hh
@@ -53,22 +53,6 @@ struct float2 {
     uint64_t x2 = *reinterpret_cast<const uint32_t *>(&y);
     return (x1 * 812519) ^ (x2 * 707951);
   }
-
-  struct isect_result {
-    enum {
-      LINE_LINE_COLINEAR = -1,
-      LINE_LINE_NONE = 0,
-      LINE_LINE_EXACT = 1,
-      LINE_LINE_CROSS = 2,
-    } kind;
-    float lambda;
-    float mu;
-  };
-
-  static isect_result isect_seg_seg(const float2 &v1,
-                                    const float2 &v2,
-                                    const float2 &v3,
-                                    const float2 &v4);
 };
 
 inline bool operator==(const float2 &a, const float2 &b)
@@ -172,6 +156,22 @@ inline float distance_squared(const float2 &a, const float2 &b)
   return dot(diff, diff);
 }
 
+struct isect_result_float2 {
+  enum {
+    LINE_LINE_COLINEAR = -1,
+    LINE_LINE_NONE = 0,
+    LINE_LINE_EXACT = 1,
+    LINE_LINE_CROSS = 2,
+  } kind;
+  float lambda;
+  float mu;
+};
+
+isect_result_float2 isect_seg_seg(const float2 &v1,
+                                  const float2 &v2,
+                                  const float2 &v3,
+                                  const float2 &v4);
+
 }  // namespace blender::math
 
 namespace blender {
diff --git a/source/blender/blenlib/BLI_mpq2.hh b/source/blender/blenlib/BLI_mpq2.hh
index a5b9698b2f2..c8d7ff3c5ca 100644
--- a/source/blender/blenlib/BLI_mpq2.hh
+++ b/source/blender/blenlib/BLI_mpq2.hh
@@ -80,21 +80,6 @@ struct mpq2 {
     return &x;
   }
 
-  struct isect_result {
-    enum {
-      LINE_LINE_COLINEAR = -1,
-      LINE_LINE_NONE = 0,
-      LINE_LINE_EXACT = 1,
-      LINE_LINE_CROSS = 2,
-    } kind;
-    mpq_class lambda;
-  };
-
-  static isect_result isect_seg_seg(const mpq2 &v1,
-                                    const mpq2 &v2,
-                                    const mpq2 &v3,
-                                    const mpq2 &v4);
-
   /** There is a sensible use for hashing on exact arithmetic types. */
   uint64_t hash() const;
 };
@@ -179,6 +164,18 @@ inline mpq_class distance_squared(const mpq2 &a, const mpq2 &b)
   return dot(diff, diff);
 }
 
+struct isect_result_mpq2 {
+  enum {
+    LINE_LINE_COLINEAR = -1,
+    LINE_LINE_NONE = 0,
+    LINE_LINE_EXACT = 1,
+    LINE_LINE_CROSS = 2,
+  } kind;
+  mpq_class lambda;
+};
+
+isect_result_mpq2 isect_seg_seg(const mpq2 &v1, const mpq2 &v2, const mpq2 &v3, const mpq2 &v4);
+
 }  // namespace blender::math
 
 namespace blender {
diff --git a/source/blender/blenlib/BLI_mpq3.hh b/source/blender/blenlib/BLI_mpq3.hh
index 66200eea352..f28523bc658 100644
--- a/source/blender/blenlib/BLI_mpq3.hh
+++ b/source/blender/blenlib/BLI_mpq3.hh
@@ -65,8 +65,6 @@ struct mpq3 {
     return &x;
   }
 
-  static mpq3 cross_poly(Span<mpq3> poly);
-
   /** There is a sensible use for hashing on exact arithmetic types. */
   uint64_t hash() const;
 };
@@ -273,12 +271,13 @@ inline int dominant_axis(const mpq3 &a)
   return ((x > y) ? ((x > z) ? 0 : 2) : ((y > z) ? 1 : 2));
 }
 
+mpq3 cross_poly(Span<mpq3> poly);
+uint64_t hash_mpq_class(const mpq_class &value);
+
 }  // namespace blender::math
 
 namespace blender {
 using math::mpq3;
-
-uint64_t hash_mpq_class(const mpq_class &value);
-}  // namespace blender
+}
 
 #endif /* WITH_GMP */
diff --git a/source/blender/blenlib/intern/delaunay_2d.cc b/source/blender/blenlib/intern/delaunay_2d.cc
index a7693fea136..c4daa776d2f 100644
--- a/source/blender/blenlib/intern/delaunay_2d.cc
+++ b/source/blender/blenlib/intern/delaunay_2d.cc
@@ -1664,10 +1664,11 @@ void fill_crossdata_for_intersect(const FatCo<T> &curco,
   BLI_assert(se_vcva->vert == vc && se_vcva->next->vert == va);
   BLI_assert(se_vcvb->vert == vc && se_vcvb->next->vert == vb);
   UNUSED_VARS_NDEBUG(vc);
-  auto isect = vec2<T>::isect_seg_seg(va->co.exact, vb->co.exact, curco.exact, v2->co.exact);
+  auto isect = isect_seg_seg(va->co.exact, vb->co.exact, curco.exact, v2->co.exact);
+  using isect_result = decltype(isect);
   T &lambda = isect.lambda;
   switch (isect.kind) {
-    case vec2<T>::isect_result::LINE_LINE_CROSS: {
+    case isect_result::LINE_LINE_CROSS: {
 #ifdef WITH_GMP
       if (!std::is_same<T, mpq_class>::value) {
 #else
@@ -1695,7 +1696,7 @@ void fill_crossdata_for_intersect(const FatCo<T> &curco,
       }
       break;
     }
-    case vec2<T>::isect_result::LINE_LINE_EXACT: {
+    case isect_result::LINE_LINE_EXACT: {
       if (lambda == 0) {
         fill_crossdata_for_through_vert(va, se_vcva, cd, cd_next);
       }
@@ -1710,7 +1711,7 @@ void fill_crossdata_for_intersect(const FatCo<T> &curco,
       }
       break;
     }
-    case vec2<T>::isect_result::LINE_LINE_NONE: {
+    case isect_result::LINE_LINE_NONE: {
 #ifdef WITH_GMP
       if (std::is_same<T, mpq_class>::value) {
         BLI_assert(false);
@@ -1726,7 +1727,7 @@ void fill_crossdata_for_intersect(const FatCo<T> &curco,
       }
       break;
     }
-    case vec2<T>::isect_result::LINE_LINE_COLINEAR: {
+    case isect_result::LINE_LINE_COLINEAR: {
       if (distance_squared(va->co.approx, v2->co.approx) <=
           distance_squared(vb->co.approx, v2->co.approx)) {
         fill_crossdata_for_through_vert(va, se_vcva, cd, cd_next);
diff --git a/source/blender/blenlib/intern/math_vec.cc b/source/blender/blenlib/intern/math_vec.cc
index 84fa6c69d17..0f0246bb3c2 100644
--- a/source/blender/blenlib/intern/math_vec.cc
+++ b/source/blender/blenlib/intern/math_vec.cc
@@ -29,78 +29,75 @@
 #include "BLI_span.hh"
 #include "BLI_utildefines.h"
 
-namespace blender {
+namespace blender::math {
 
-float2::isect_result float2::isect_seg_seg(const float2 &v1,
-                                           const float2 &v2,
-                                           const float2 &v3,
-                                           const float2 &v4)
+isect_result_float2 isect_seg_seg(const float2 &v1,
+                                  const float2 &v2,
+                                  const float2 &v3,
+                                  const float2 &v4)
 {
-  float2::isect_result ans;
+  isect_result_float2 ans;
   float div = (v2[0] - v1[0]) * (v4[1] - v3[1]) - (v2[1] - v1[1]) * (v4[0] - v3[0]);
   if (div == 0.0f) {
     ans.lambda = 0.0f;
     ans.mu = 0.0f;
-    ans.kind = float2::isect_result::LINE_LINE_COLINEAR;
+    ans.kind = isect_result_float2::LINE_LINE_COLINEAR;
   }
   else {
     ans.lambda = ((v1[1] - v3[1]) * (v4[0] - v3[0]) - (v1[0] - v3[0]) * (v4[1] - v3[1])) / div;
     ans.mu = ((v1[1] - v3[1]) * (v2[0] - v1[0]) - (v1[0] - v3[0]) * (v2[1] - v1[1])) / div;
     if (ans.lambda >= 0.0f && ans.lambda <= 1.0f && ans.mu >= 0.0f && ans.mu <= 1.0f) {
       if (ans.lambda == 0.0f || ans.lambda == 1.0f || ans.mu == 0.0f || ans.mu == 1.0f) {
-        ans.kind = float2::isect_result::LINE_LINE_EXACT;
+        ans.kind = isect_result_float2::LINE_LINE_EXACT;
       }
       else {
-        ans.kind = float2::isect_result::LINE_LINE_CROSS;
+        ans.kind = isect_result_float2::LINE_LINE_CROSS;
       }
     }
     else {
-      ans.kind = float2::isect_result::LINE_LINE_NONE;
+      ans.kind = isect_result_float2::LINE_LINE_NONE;
     }
   }
   return ans;
 }
 
-double2::isect_result double2::isect_seg_seg(const double2 &v1,
-                                             const double2 &v2,
-                                             const double2 &v3,
-                                             const double2 &v4)
+isect_result_double2 isect_seg_seg(const double2 &v1,
+                                   const double2 &v2,
+                                   const double2 &v3,
+                                   const double2 &v4)
 {
-  double2::isect_result ans;
+  isect_result_double2 ans;
   double div = (v2[0] - v1[0]) * (v4[1] - v3[1]) - (v2[1] - v1[1]) * (v4[0] - v3[0]);
   if (div == 0.0) {
     ans.lambda = 0.0;
-    ans.kind = double2::isect_result::LINE_LINE_COLINEAR;
+    ans.kind = isect_result_double2::LINE_LINE_COLINEAR;
   }
   else {
     ans.lambda = ((v1[1] - v3[1]) * (v4[0] - v3[0]) - (v1[0] - v3[0]) * (v4[1] - v3[1])) / div;
     double mu = ((v1[1] - v3[1]) * (v2[0] - v1[0]

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list