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:
authorJacques Lucke <jacques@blender.org>2021-01-11 20:39:12 +0300
committerJacques Lucke <jacques@blender.org>2021-01-11 20:39:12 +0300
commitb3d34a6690a68e6922bc0f6d7a66482a12625b78 (patch)
treedaba9c19d2b09bf2d7b17cef09514c7f5530d3ca
parent3c112c5e46828e093c81a74a9b258aa354cd9290 (diff)
use new style for isect_seg_seg and cross_polytemp-experimental-cpp-math-refactor
-rw-r--r--source/blender/blenlib/BLI_double2.hh30
-rw-r--r--source/blender/blenlib/BLI_double3.hh4
-rw-r--r--source/blender/blenlib/BLI_float2.hh32
-rw-r--r--source/blender/blenlib/BLI_mpq2.hh27
-rw-r--r--source/blender/blenlib/BLI_mpq3.hh9
-rw-r--r--source/blender/blenlib/intern/delaunay_2d.cc11
-rw-r--r--source/blender/blenlib/intern/math_vec.cc61
-rw-r--r--source/blender/blenlib/intern/mesh_intersect.cc4
8 files changed, 86 insertions, 92 deletions
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]) - (v1[0] - v3[0]) * (v2[1] - v1[1])) / div;
if (ans.lambda >= 0.0 && ans.lambda <= 1.0 && mu >= 0.0 && mu <= 1.0) {
if (ans.lambda == 0.0 || ans.lambda == 1.0 || mu == 0.0 || mu == 1.0) {
- ans.kind = double2::isect_result::LINE_LINE_EXACT;
+ ans.kind = isect_result_double2::LINE_LINE_EXACT;
}
else {
- ans.kind = double2::isect_result::LINE_LINE_CROSS;
+ ans.kind = isect_result_double2::LINE_LINE_CROSS;
}
}
else {
- ans.kind = double2::isect_result::LINE_LINE_NONE;
+ ans.kind = isect_result_double2::LINE_LINE_NONE;
}
}
return ans;
}
#ifdef WITH_GMP
-mpq2::isect_result mpq2::isect_seg_seg(const mpq2 &v1,
- const mpq2 &v2,
- const mpq2 &v3,
- const mpq2 &v4)
+isect_result_mpq2 isect_seg_seg(const mpq2 &v1, const mpq2 &v2, const mpq2 &v3, const mpq2 &v4)
{
- mpq2::isect_result ans;
+ isect_result_mpq2 ans;
mpq_class 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 = mpq2::isect_result::LINE_LINE_COLINEAR;
+ ans.kind = isect_result_mpq2::LINE_LINE_COLINEAR;
}
else {
ans.lambda = ((v1[1] - v3[1]) * (v4[0] - v3[0]) - (v1[0] - v3[0]) * (v4[1] - v3[1])) / div;
@@ -109,21 +106,21 @@ mpq2::isect_result mpq2::isect_seg_seg(const mpq2 &v1,
if (ans.lambda >= 0 && ans.lambda <= 1 &&
((div > 0 && mudiv >= 0 && mudiv <= div) || (div < 0 && mudiv <= 0 && mudiv >= div))) {
if (ans.lambda == 0 || ans.lambda == 1 || mudiv == 0 || mudiv == div) {
- ans.kind = mpq2::isect_result::LINE_LINE_EXACT;
+ ans.kind = isect_result_mpq2::LINE_LINE_EXACT;
}
else {
- ans.kind = mpq2::isect_result::LINE_LINE_CROSS;
+ ans.kind = isect_result_mpq2::LINE_LINE_CROSS;
}
}
else {
- ans.kind = mpq2::isect_result::LINE_LINE_NONE;
+ ans.kind = isect_result_mpq2::LINE_LINE_NONE;
}
}
return ans;
-}
+} // namespace math
#endif
-double3 double3::cross_poly(Span<double3> poly)
+double3 cross_poly(Span<double3> poly)
{
/* Newell's Method. */
int nv = static_cast<int>(poly.size());
@@ -147,7 +144,7 @@ double3 double3::cross_poly(Span<double3> poly)
}
#ifdef WITH_GMP
-mpq3 mpq3::cross_poly(Span<mpq3> poly)
+mpq3 cross_poly(Span<mpq3> poly)
{
/* Newell's Method. */
int nv = static_cast<int>(poly.size());
@@ -192,4 +189,4 @@ uint64_t mpq3::hash() const
}
#endif
-} // namespace blender
+} // namespace blender::math
diff --git a/source/blender/blenlib/intern/mesh_intersect.cc b/source/blender/blenlib/intern/mesh_intersect.cc
index 04f692385c9..ccb585fe283 100644
--- a/source/blender/blenlib/intern/mesh_intersect.cc
+++ b/source/blender/blenlib/intern/mesh_intersect.cc
@@ -193,7 +193,7 @@ 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 = cross_poly(co);
}
else {
mpq3 tr02 = vert[0]->co_exact - vert[2]->co_exact;
@@ -210,7 +210,7 @@ void Face::populate_plane(bool need_exact)
for (int i : index_range()) {
co[i] = vert[i]->co;
}
- normal = double3::cross_poly(co);
+ normal = cross_poly(co);
}
else {
double3 tr02 = vert[0]->co - vert[2]->co;