From 98262bb8cff57cf962f0e164945fcff51c2439e1 Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Mon, 11 Jan 2021 13:57:04 +0100 Subject: move remaining types --- source/blender/blenlib/BLI_double2.hh | 153 ++++----- source/blender/blenlib/BLI_double3.hh | 362 +++++++++++---------- source/blender/blenlib/BLI_mpq2.hh | 166 +++++----- source/blender/blenlib/BLI_mpq3.hh | 413 ++++++++++++------------ source/blender/blenlib/intern/delaunay_2d.cc | 20 +- source/blender/blenlib/intern/mesh_boolean.cc | 57 ++-- source/blender/blenlib/intern/mesh_intersect.cc | 64 ++-- 7 files changed, 625 insertions(+), 610 deletions(-) diff --git a/source/blender/blenlib/BLI_double2.hh b/source/blender/blenlib/BLI_double2.hh index 621ac4d01fc..236c429861a 100644 --- a/source/blender/blenlib/BLI_double2.hh +++ b/source/blender/blenlib/BLI_double2.hh @@ -22,7 +22,7 @@ #include "BLI_double3.hh" -namespace blender { +namespace blender::math { struct double2 { double x, y; @@ -51,78 +51,6 @@ struct double2 { return &x; } - double length() const - { - return len_v2_db(*this); - } - - friend double2 operator+(const double2 &a, const double2 &b) - { - return {a.x + b.x, a.y + b.y}; - } - - friend double2 operator-(const double2 &a, const double2 &b) - { - return {a.x - b.x, a.y - b.y}; - } - - friend double2 operator*(const double2 &a, double b) - { - return {a.x * b, a.y * b}; - } - - friend double2 operator/(const double2 &a, double b) - { - BLI_assert(b != 0.0); - return {a.x / b, a.y / b}; - } - - friend double2 operator*(double a, const double2 &b) - { - return b * a; - } - - friend bool operator==(const double2 &a, const double2 &b) - { - return a.x == b.x && a.y == b.y; - } - - friend bool operator!=(const double2 &a, const double2 &b) - { - return a.x != b.x || a.y != b.y; - } - - friend std::ostream &operator<<(std::ostream &stream, const double2 &v) - { - stream << "(" << v.x << ", " << v.y << ")"; - return stream; - } - - static double dot(const double2 &a, const double2 &b) - { - return a.x * b.x + a.y * b.y; - } - - static double2 interpolate(const double2 &a, const double2 &b, double t) - { - return a * (1 - t) + b * t; - } - - static double2 abs(const double2 &a) - { - return double2(fabs(a.x), fabs(a.y)); - } - - static double distance(const double2 &a, const double2 &b) - { - return (a - b).length(); - } - - static double distance_squared(const double2 &a, const double2 &b) - { - return double2::dot(a, b); - } - struct isect_result { enum { LINE_LINE_COLINEAR = -1, @@ -139,4 +67,81 @@ struct double2 { const double2 &v4); }; -} // namespace blender +inline double length(const double2 &a) +{ + return len_v2_db(a); +} + +inline double2 operator+(const double2 &a, const double2 &b) +{ + return {a.x + b.x, a.y + b.y}; +} + +inline double2 operator-(const double2 &a, const double2 &b) +{ + return {a.x - b.x, a.y - b.y}; +} + +inline double2 operator*(const double2 &a, double b) +{ + return {a.x * b, a.y * b}; +} + +inline double2 operator/(const double2 &a, double b) +{ + BLI_assert(b != 0.0); + return {a.x / b, a.y / b}; +} + +inline double2 operator*(double a, const double2 &b) +{ + return b * a; +} + +inline bool operator==(const double2 &a, const double2 &b) +{ + return a.x == b.x && a.y == b.y; +} + +inline bool operator!=(const double2 &a, const double2 &b) +{ + return a.x != b.x || a.y != b.y; +} + +inline std::ostream &operator<<(std::ostream &stream, const double2 &v) +{ + stream << "(" << v.x << ", " << v.y << ")"; + return stream; +} + +inline double dot(const double2 &a, const double2 &b) +{ + return a.x * b.x + a.y * b.y; +} + +inline double2 lerp(const double2 &a, const double2 &b, double t) +{ + return a * (1 - t) + b * t; +} + +inline double2 abs(const double2 &a) +{ + return double2(fabs(a.x), fabs(a.y)); +} + +inline double distance(const double2 &a, const double2 &b) +{ + return length(a - b); +} + +inline double distance_squared(const double2 &a, const double2 &b) +{ + double2 diff = a - b; + return dot(diff, diff); +} + +} // namespace blender::math + +namespace blender { +using blender::math::double2; +} diff --git a/source/blender/blenlib/BLI_double3.hh b/source/blender/blenlib/BLI_double3.hh index 5b6204935d7..0d60148e1de 100644 --- a/source/blender/blenlib/BLI_double3.hh +++ b/source/blender/blenlib/BLI_double3.hh @@ -25,7 +25,7 @@ #include "BLI_math_vector.h" #include "BLI_span.hh" -namespace blender { +namespace blender::math { struct double3 { double x, y, z; @@ -62,184 +62,188 @@ struct double3 { return &x; } - double normalize_and_get_length() - { - return normalize_v3_db(*this); - } - - double3 normalized() const - { - double3 result; - normalize_v3_v3_db(result, *this); - return result; - } - - double length() const - { - return len_v3_db(*this); - } - - double length_squared() const - { - return len_squared_v3_db(*this); - } - - void reflect(const double3 &normal) - { - *this = this->reflected(normal); - } - - double3 reflected(const double3 &normal) const - { - double3 result; - reflect_v3_v3v3_db(result, *this, normal); - return result; - } - - static double3 safe_divide(const double3 &a, const double3 &b) - { - double3 result; - result.x = (b.x == 0.0) ? 0.0 : a.x / b.x; - result.y = (b.y == 0.0) ? 0.0 : a.y / b.y; - result.z = (b.z == 0.0) ? 0.0 : a.z / b.z; - return result; - } - - void invert() - { - x = -x; - y = -y; - z = -z; - } - - friend double3 operator+(const double3 &a, const double3 &b) - { - return {a.x + b.x, a.y + b.y, a.z + b.z}; - } - - void operator+=(const double3 &b) - { - this->x += b.x; - this->y += b.y; - this->z += b.z; - } - - friend double3 operator-(const double3 &a, const double3 &b) - { - return {a.x - b.x, a.y - b.y, a.z - b.z}; - } - - friend double3 operator-(const double3 &a) - { - return {-a.x, -a.y, -a.z}; - } - - void operator-=(const double3 &b) - { - this->x -= b.x; - this->y -= b.y; - this->z -= b.z; - } - - void operator*=(const double &scalar) - { - this->x *= scalar; - this->y *= scalar; - this->z *= scalar; - } - - void operator*=(const double3 &other) - { - this->x *= other.x; - this->y *= other.y; - this->z *= other.z; - } - - friend double3 operator*(const double3 &a, const double3 &b) - { - return {a.x * b.x, a.y * b.y, a.z * b.z}; - } - - friend double3 operator*(const double3 &a, const double &b) - { - return {a.x * b, a.y * b, a.z * b}; - } - - friend double3 operator*(const double &a, const double3 &b) - { - return b * a; - } - - friend double3 operator/(const double3 &a, const double &b) - { - BLI_assert(b != 0.0); - return {a.x / b, a.y / b, a.z / b}; - } - - friend bool operator==(const double3 &a, const double3 &b) - { - return a.x == b.x && a.y == b.y && a.z == b.z; - } - - friend bool operator!=(const double3 &a, const double3 &b) - { - return a.x != b.x || a.y != b.y || a.z != b.z; - } - - friend std::ostream &operator<<(std::ostream &stream, const double3 &v) - { - stream << "(" << v.x << ", " << v.y << ", " << v.z << ")"; - return stream; - } - - static double dot(const double3 &a, const double3 &b) - { - return a.x * b.x + a.y * b.y + a.z * b.z; - } - - static double3 cross_high_precision(const double3 &a, const double3 &b) - { - double3 result; - cross_v3_v3v3_db(result, a, b); - return result; - } - - static double3 project(const double3 &a, const double3 &b) - { - double3 result; - project_v3_v3v3_db(result, a, b); - return result; - } - - static double distance(const double3 &a, const double3 &b) - { - return (a - b).length(); - } - - static double distance_squared(const double3 &a, const double3 &b) - { - return double3::dot(a, b); - } - - static double3 interpolate(const double3 &a, const double3 &b, double t) - { - return a * (1 - t) + b * t; - } - - static double3 abs(const double3 &a) - { - return double3(fabs(a.x), fabs(a.y), fabs(a.z)); - } - - static int dominant_axis(const double3 &a) - { - double x = (a.x >= 0) ? a.x : -a.x; - double y = (a.y >= 0) ? a.y : -a.y; - double z = (a.z >= 0) ? a.z : -a.z; - return ((x > y) ? ((x > z) ? 0 : 2) : ((y > z) ? 1 : 2)); - } - static double3 cross_poly(Span poly); }; -} // namespace blender +inline double normalize_and_get_length(double3 &a) +{ + return normalize_v3_db(a); +} + +inline double3 normalized(const double3 &a) +{ + double3 result; + normalize_v3_v3_db(result, a); + return result; +} + +inline double length(const double3 &a) +{ + return len_v3_db(a); +} + +inline double length_squared(const double3 &a) +{ + return len_squared_v3_db(a); +} + +inline double3 reflected(const double3 &a, const double3 &normal) +{ + double3 result; + reflect_v3_v3v3_db(result, a, normal); + return result; +} + +inline void reflect(double3 &a, const double3 &normal) +{ + a = reflected(a, normal); +} + +inline double3 safe_divide(const double3 &a, const double3 &b) +{ + double3 result; + result.x = (b.x == 0.0) ? 0.0 : a.x / b.x; + result.y = (b.y == 0.0) ? 0.0 : a.y / b.y; + result.z = (b.z == 0.0) ? 0.0 : a.z / b.z; + return result; +} + +inline void negate(double3 &a) +{ + a.x = -a.x; + a.y = -a.y; + a.z = -a.z; +} + +inline double3 operator+(const double3 &a, const double3 &b) +{ + return {a.x + b.x, a.y + b.y, a.z + b.z}; +} + +inline void operator+=(double3 &a, const double3 &b) +{ + a.x += b.x; + a.y += b.y; + a.z += b.z; +} + +inline double3 operator-(const double3 &a, const double3 &b) +{ + return {a.x - b.x, a.y - b.y, a.z - b.z}; +} + +inline double3 operator-(const double3 &a) +{ + return {-a.x, -a.y, -a.z}; +} + +inline void operator-=(double3 &a, const double3 &b) +{ + a.x -= b.x; + a.y -= b.y; + a.z -= b.z; +} + +inline void operator*=(double3 &a, const double &scalar) +{ + a.x *= scalar; + a.y *= scalar; + a.z *= scalar; +} + +inline void operator*=(double3 &a, const double3 &other) +{ + a.x *= other.x; + a.y *= other.y; + a.z *= other.z; +} + +inline double3 operator*(const double3 &a, const double3 &b) +{ + return {a.x * b.x, a.y * b.y, a.z * b.z}; +} + +inline double3 operator*(const double3 &a, const double &b) +{ + return {a.x * b, a.y * b, a.z * b}; +} + +inline double3 operator*(const double &a, const double3 &b) +{ + return b * a; +} + +inline double3 operator/(const double3 &a, const double &b) +{ + BLI_assert(b != 0.0); + return {a.x / b, a.y / b, a.z / b}; +} + +inline bool operator==(const double3 &a, const double3 &b) +{ + return a.x == b.x && a.y == b.y && a.z == b.z; +} + +inline bool operator!=(const double3 &a, const double3 &b) +{ + return a.x != b.x || a.y != b.y || a.z != b.z; +} + +inline std::ostream &operator<<(std::ostream &stream, const double3 &v) +{ + stream << "(" << v.x << ", " << v.y << ", " << v.z << ")"; + return stream; +} + +inline double dot(const double3 &a, const double3 &b) +{ + return a.x * b.x + a.y * b.y + a.z * b.z; +} + +inline double3 cross_high_precision(const double3 &a, const double3 &b) +{ + double3 result; + cross_v3_v3v3_db(result, a, b); + return result; +} + +inline double3 project(const double3 &a, const double3 &b) +{ + double3 result; + project_v3_v3v3_db(result, a, b); + return result; +} + +inline double distance(const double3 &a, const double3 &b) +{ + return length(a - b); +} + +inline double distance_squared(const double3 &a, const double3 &b) +{ + return dot(a, b); +} + +inline double3 lerp(const double3 &a, const double3 &b, double t) +{ + return a * (1 - t) + b * t; +} + +inline double3 abs(const double3 &a) +{ + return double3(fabs(a.x), fabs(a.y), fabs(a.z)); +} + +inline int dominant_axis(const double3 &a) +{ + double x = (a.x >= 0) ? a.x : -a.x; + double y = (a.y >= 0) ? a.y : -a.y; + double z = (a.z >= 0) ? a.z : -a.z; + return ((x > y) ? ((x > z) ? 0 : 2) : ((y > z) ? 1 : 2)); +} + +} // namespace blender::math + +namespace blender { +using math::double3; +} diff --git a/source/blender/blenlib/BLI_mpq2.hh b/source/blender/blenlib/BLI_mpq2.hh index 40e227019ce..de88bd82890 100644 --- a/source/blender/blenlib/BLI_mpq2.hh +++ b/source/blender/blenlib/BLI_mpq2.hh @@ -25,7 +25,7 @@ # include "BLI_math_mpq.hh" # include "BLI_mpq3.hh" -namespace blender { +namespace blender::math { struct mpq2 { mpq_class x, y; @@ -80,85 +80,6 @@ struct mpq2 { return &x; } - /** - * Cannot do this exactly in rational arithmetic! - * Approximate by going in and out of doubles. - */ - mpq_class length() const - { - mpq_class lsquared = dot(*this, *this); - return mpq_class(sqrt(lsquared.get_d())); - } - - friend mpq2 operator+(const mpq2 &a, const mpq2 &b) - { - return {a.x + b.x, a.y + b.y}; - } - - friend mpq2 operator-(const mpq2 &a, const mpq2 &b) - { - return {a.x - b.x, a.y - b.y}; - } - - friend mpq2 operator*(const mpq2 &a, mpq_class b) - { - return {a.x * b, a.y * b}; - } - - friend mpq2 operator/(const mpq2 &a, mpq_class b) - { - BLI_assert(b != 0); - return {a.x / b, a.y / b}; - } - - friend mpq2 operator*(mpq_class a, const mpq2 &b) - { - return b * a; - } - - friend bool operator==(const mpq2 &a, const mpq2 &b) - { - return a.x == b.x && a.y == b.y; - } - - friend bool operator!=(const mpq2 &a, const mpq2 &b) - { - return a.x != b.x || a.y != b.y; - } - - friend std::ostream &operator<<(std::ostream &stream, const mpq2 &v) - { - stream << "(" << v.x << ", " << v.y << ")"; - return stream; - } - - static mpq_class dot(const mpq2 &a, const mpq2 &b) - { - return a.x * b.x + a.y * b.y; - } - - static mpq2 interpolate(const mpq2 &a, const mpq2 &b, mpq_class t) - { - return a * (1 - t) + b * t; - } - - static mpq2 abs(const mpq2 &a) - { - mpq_class abs_x = (a.x >= 0) ? a.x : -a.x; - mpq_class abs_y = (a.y >= 0) ? a.y : -a.y; - return mpq2(abs_x, abs_y); - } - - static mpq_class distance(const mpq2 &a, const mpq2 &b) - { - return (a - b).length(); - } - - static mpq_class distance_squared(const mpq2 &a, const mpq2 &b) - { - return dot(a, b); - } - struct isect_result { enum { LINE_LINE_COLINEAR = -1, @@ -178,6 +99,89 @@ struct mpq2 { uint64_t hash() const; }; -} // namespace blender +inline mpq2 operator+(const mpq2 &a, const mpq2 &b) +{ + return {a.x + b.x, a.y + b.y}; +} + +inline mpq2 operator-(const mpq2 &a, const mpq2 &b) +{ + return {a.x - b.x, a.y - b.y}; +} + +inline mpq2 operator*(const mpq2 &a, mpq_class b) +{ + return {a.x * b, a.y * b}; +} + +inline mpq2 operator/(const mpq2 &a, mpq_class b) +{ + BLI_assert(b != 0); + return {a.x / b, a.y / b}; +} + +inline mpq2 operator*(mpq_class a, const mpq2 &b) +{ + return b * a; +} + +inline bool operator==(const mpq2 &a, const mpq2 &b) +{ + return a.x == b.x && a.y == b.y; +} + +inline bool operator!=(const mpq2 &a, const mpq2 &b) +{ + return a.x != b.x || a.y != b.y; +} + +inline std::ostream &operator<<(std::ostream &stream, const mpq2 &v) +{ + stream << "(" << v.x << ", " << v.y << ")"; + return stream; +} + +inline mpq_class dot(const mpq2 &a, const mpq2 &b) +{ + return a.x * b.x + a.y * b.y; +} + +/** + * Cannot do this exactly in rational arithmetic! + * Approximate by going in and out of doubles. + */ +inline mpq_class length(const mpq2 &a) +{ + mpq_class lsquared = dot(a, a); + return mpq_class(sqrt(lsquared.get_d())); +} + +inline mpq2 lerp(const mpq2 &a, const mpq2 &b, mpq_class t) +{ + return a * (1 - t) + b * t; +} + +inline mpq2 abs(const mpq2 &a) +{ + mpq_class abs_x = (a.x >= 0) ? a.x : -a.x; + mpq_class abs_y = (a.y >= 0) ? a.y : -a.y; + return mpq2(abs_x, abs_y); +} + +inline mpq_class distance(const mpq2 &a, const mpq2 &b) +{ + return length(a - b); +} + +inline mpq_class distance_squared(const mpq2 &a, const mpq2 &b) +{ + return dot(a, b); +} + +} // namespace blender::math + +namespace blender { +using math::mpq2; +} #endif /* WITH_GMP */ diff --git a/source/blender/blenlib/BLI_mpq3.hh b/source/blender/blenlib/BLI_mpq3.hh index fb5e2b61cdb..66200eea352 100644 --- a/source/blender/blenlib/BLI_mpq3.hh +++ b/source/blender/blenlib/BLI_mpq3.hh @@ -28,7 +28,7 @@ # include "BLI_math_mpq.hh" # include "BLI_span.hh" -namespace blender { +namespace blender::math { struct mpq3 { mpq_class x, y, z; @@ -65,217 +65,220 @@ struct mpq3 { return &x; } - /* Cannot do this exactly in rational arithmetic! - * Approximate by going in and out of doubles. - */ - mpq_class normalize_and_get_length() - { - double dv[3] = {x.get_d(), y.get_d(), z.get_d()}; - double len = normalize_v3_db(dv); - this->x = mpq_class(dv[0]); - this->y = mpq_class(dv[1]); - this->z = mpq_class(dv[2]); - return len; - } - - mpq3 normalized() const - { - double dv[3] = {x.get_d(), y.get_d(), z.get_d()}; - double dr[3]; - normalize_v3_v3_db(dr, dv); - return mpq3(mpq_class(dr[0]), mpq_class(dr[1]), mpq_class(dr[2])); - } - - /* Cannot do this exactly in rational arithmetic! - * Approximate by going in and out of double. - */ - mpq_class length() const - { - mpq_class lsquared = this->length_squared(); - double dsquared = lsquared.get_d(); - double d = sqrt(dsquared); - return mpq_class(d); - } - - mpq_class length_squared() const - { - return x * x + y * y + z * z; - } - - void reflect(const mpq3 &normal) - { - *this = this->reflected(normal); - } - - mpq3 reflected(const mpq3 &normal) const - { - mpq3 result; - const mpq_class dot2 = 2 * dot(*this, normal); - result.x = this->x - (dot2 * normal.x); - result.y = this->y - (dot2 * normal.y); - result.z = this->z - (dot2 * normal.z); - return result; - } - - static mpq3 safe_divide(const mpq3 &a, const mpq3 &b) - { - mpq3 result; - result.x = (b.x == 0) ? mpq_class(0) : a.x / b.x; - result.y = (b.y == 0) ? mpq_class(0) : a.y / b.y; - result.z = (b.z == 0) ? mpq_class(0) : a.z / b.z; - return result; - } - - void invert() - { - x = -x; - y = -y; - z = -z; - } - - friend mpq3 operator+(const mpq3 &a, const mpq3 &b) - { - return mpq3(a.x + b.x, a.y + b.y, a.z + b.z); - } - - void operator+=(const mpq3 &b) - { - this->x += b.x; - this->y += b.y; - this->z += b.z; - } - - friend mpq3 operator-(const mpq3 &a, const mpq3 &b) - { - return mpq3(a.x - b.x, a.y - b.y, a.z - b.z); - } - - friend mpq3 operator-(const mpq3 &a) - { - return mpq3(-a.x, -a.y, -a.z); - } - - void operator-=(const mpq3 &b) - { - this->x -= b.x; - this->y -= b.y; - this->z -= b.z; - } - - void operator*=(mpq_class scalar) - { - this->x *= scalar; - this->y *= scalar; - this->z *= scalar; - } - - void operator*=(const mpq3 &other) - { - this->x *= other.x; - this->y *= other.y; - this->z *= other.z; - } - - friend mpq3 operator*(const mpq3 &a, const mpq3 &b) - { - return {a.x * b.x, a.y * b.y, a.z * b.z}; - } - - friend mpq3 operator*(const mpq3 &a, const mpq_class &b) - { - return mpq3(a.x * b, a.y * b, a.z * b); - } - - friend mpq3 operator*(const mpq_class &a, const mpq3 &b) - { - return mpq3(a * b.x, a * b.y, a * b.z); - } - - friend mpq3 operator/(const mpq3 &a, const mpq_class &b) - { - BLI_assert(b != 0); - return mpq3(a.x / b, a.y / b, a.z / b); - } - - friend bool operator==(const mpq3 &a, const mpq3 &b) - { - return a.x == b.x && a.y == b.y && a.z == b.z; - } - - friend bool operator!=(const mpq3 &a, const mpq3 &b) - { - return a.x != b.x || a.y != b.y || a.z != b.z; - } - - friend std::ostream &operator<<(std::ostream &stream, const mpq3 &v) - { - stream << "(" << v.x << ", " << v.y << ", " << v.z << ")"; - return stream; - } - - static mpq_class dot(const mpq3 &a, const mpq3 &b) - { - return a.x * b.x + a.y * b.y + a.z * b.z; - } - - static mpq3 cross(const mpq3 &a, const mpq3 &b) - { - return mpq3(a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]); - } - - static mpq3 cross_high_precision(const mpq3 &a, const mpq3 &b) - { - return cross(a, b); - } - - static mpq3 project(const mpq3 &a, const mpq3 &b) - { - const mpq_class mul = mpq3::dot(a, b) / mpq3::dot(b, b); - return mpq3(mul * b[0], mul * b[1], mul * b[2]); - } - - static mpq_class distance(const mpq3 &a, const mpq3 &b) - { - mpq3 diff(a.x - b.x, a.y - b.y, a.z - b.z); - return diff.length(); - } - - static mpq_class distance_squared(const mpq3 &a, const mpq3 &b) - { - mpq3 diff(a.x - b.x, a.y - b.y, a.z - b.z); - return mpq3::dot(diff, diff); - } - - static mpq3 interpolate(const mpq3 &a, const mpq3 &b, mpq_class t) - { - mpq_class s = 1 - t; - return mpq3(a.x * s + b.x * t, a.y * s + b.y * t, a.z * s + b.z * t); - } - - static mpq3 abs(const mpq3 &a) - { - mpq_class abs_x = (a.x >= 0) ? a.x : -a.x; - mpq_class abs_y = (a.y >= 0) ? a.y : -a.y; - mpq_class abs_z = (a.z >= 0) ? a.z : -a.z; - return mpq3(abs_x, abs_y, abs_z); - } - - static int dominant_axis(const mpq3 &a) - { - mpq_class x = (a.x >= 0) ? a.x : -a.x; - mpq_class y = (a.y >= 0) ? a.y : -a.y; - mpq_class z = (a.z >= 0) ? a.z : -a.z; - return ((x > y) ? ((x > z) ? 0 : 2) : ((y > z) ? 1 : 2)); - } - static mpq3 cross_poly(Span poly); /** There is a sensible use for hashing on exact arithmetic types. */ uint64_t hash() const; }; -uint64_t hash_mpq_class(const mpq_class &value); +/* Cannot do this exactly in rational arithmetic! + * Approximate by going in and out of doubles. + */ +inline mpq_class normalize_and_get_length(mpq3 &a) +{ + double dv[3] = {a.x.get_d(), a.y.get_d(), a.z.get_d()}; + double len = normalize_v3_db(dv); + a.x = mpq_class(dv[0]); + a.y = mpq_class(dv[1]); + a.z = mpq_class(dv[2]); + return len; +} + +inline mpq3 normalized(const mpq3 &a) +{ + double dv[3] = {a.x.get_d(), a.y.get_d(), a.z.get_d()}; + double dr[3]; + normalize_v3_v3_db(dr, dv); + return mpq3(mpq_class(dr[0]), mpq_class(dr[1]), mpq_class(dr[2])); +} + +inline mpq_class length_squared(const mpq3 &a) +{ + return a.x * a.x + a.y * a.y + a.z * a.z; +} + +/* Cannot do this exactly in rational arithmetic! + * Approximate by going in and out of double. + */ +inline mpq_class length(const mpq3 &a) +{ + mpq_class lsquared = length_squared(a); + double dsquared = lsquared.get_d(); + double d = sqrt(dsquared); + return mpq_class(d); +} + +inline mpq_class dot(const mpq3 &a, const mpq3 &b) +{ + return a.x * b.x + a.y * b.y + a.z * b.z; +} + +inline mpq3 reflected(const mpq3 &a, const mpq3 &normal) +{ + mpq3 result; + const mpq_class dot2 = 2 * dot(a, normal); + result.x = a.x - (dot2 * normal.x); + result.y = a.y - (dot2 * normal.y); + result.z = a.z - (dot2 * normal.z); + return result; +} + +inline void reflect(mpq3 &a, const mpq3 &normal) +{ + a = reflected(a, normal); +} + +inline mpq3 safe_divide(const mpq3 &a, const mpq3 &b) +{ + mpq3 result; + result.x = (b.x == 0) ? mpq_class(0) : a.x / b.x; + result.y = (b.y == 0) ? mpq_class(0) : a.y / b.y; + result.z = (b.z == 0) ? mpq_class(0) : a.z / b.z; + return result; +} + +inline void negate(mpq3 &a) +{ + a.x = -a.x; + a.y = -a.y; + a.z = -a.z; +} + +inline mpq3 operator+(const mpq3 &a, const mpq3 &b) +{ + return mpq3(a.x + b.x, a.y + b.y, a.z + b.z); +} + +inline void operator+=(mpq3 &a, const mpq3 &b) +{ + a.x += b.x; + a.y += b.y; + a.z += b.z; +} + +inline mpq3 operator-(const mpq3 &a, const mpq3 &b) +{ + return mpq3(a.x - b.x, a.y - b.y, a.z - b.z); +} + +inline mpq3 operator-(const mpq3 &a) +{ + return mpq3(-a.x, -a.y, -a.z); +} + +inline void operator-=(mpq3 &a, const mpq3 &b) +{ + a.x -= b.x; + a.y -= b.y; + a.z -= b.z; +} + +inline void operator*=(mpq3 &a, mpq_class scalar) +{ + a.x *= scalar; + a.y *= scalar; + a.z *= scalar; +} + +inline void operator*=(mpq3 &a, const mpq3 &other) +{ + a.x *= other.x; + a.y *= other.y; + a.z *= other.z; +} + +inline mpq3 operator*(const mpq3 &a, const mpq3 &b) +{ + return {a.x * b.x, a.y * b.y, a.z * b.z}; +} + +inline mpq3 operator*(const mpq3 &a, const mpq_class &b) +{ + return mpq3(a.x * b, a.y * b, a.z * b); +} + +inline mpq3 operator*(const mpq_class &a, const mpq3 &b) +{ + return mpq3(a * b.x, a * b.y, a * b.z); +} + +inline mpq3 operator/(const mpq3 &a, const mpq_class &b) +{ + BLI_assert(b != 0); + return mpq3(a.x / b, a.y / b, a.z / b); +} + +inline bool operator==(const mpq3 &a, const mpq3 &b) +{ + return a.x == b.x && a.y == b.y && a.z == b.z; +} + +inline bool operator!=(const mpq3 &a, const mpq3 &b) +{ + return a.x != b.x || a.y != b.y || a.z != b.z; +} + +inline std::ostream &operator<<(std::ostream &stream, const mpq3 &v) +{ + stream << "(" << v.x << ", " << v.y << ", " << v.z << ")"; + return stream; +} + +inline mpq3 cross(const mpq3 &a, const mpq3 &b) +{ + return mpq3(a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]); +} + +inline mpq3 cross_high_precision(const mpq3 &a, const mpq3 &b) +{ + return cross(a, b); +} + +inline mpq3 project(const mpq3 &a, const mpq3 &b) +{ + const mpq_class mul = dot(a, b) / dot(b, b); + return mpq3(mul * b[0], mul * b[1], mul * b[2]); +} + +inline mpq_class distance(const mpq3 &a, const mpq3 &b) +{ + return length(a - b); +} + +inline mpq_class distance_squared(const mpq3 &a, const mpq3 &b) +{ + mpq3 diff(a.x - b.x, a.y - b.y, a.z - b.z); + return dot(diff, diff); +} + +inline mpq3 lerp(const mpq3 &a, const mpq3 &b, mpq_class t) +{ + mpq_class s = 1 - t; + return mpq3(a.x * s + b.x * t, a.y * s + b.y * t, a.z * s + b.z * t); +} + +inline mpq3 abs(const mpq3 &a) +{ + mpq_class abs_x = (a.x >= 0) ? a.x : -a.x; + mpq_class abs_y = (a.y >= 0) ? a.y : -a.y; + mpq_class abs_z = (a.z >= 0) ? a.z : -a.z; + return mpq3(abs_x, abs_y, abs_z); +} + +inline int dominant_axis(const mpq3 &a) +{ + mpq_class x = (a.x >= 0) ? a.x : -a.x; + mpq_class y = (a.y >= 0) ? a.y : -a.y; + mpq_class z = (a.z >= 0) ? a.z : -a.z; + return ((x > y) ? ((x > z) ? 0 : 2) : ((y > z) ? 1 : 2)); +} + +} // 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 f0b65a55816..a7693fea136 100644 --- a/source/blender/blenlib/intern/delaunay_2d.cc +++ b/source/blender/blenlib/intern/delaunay_2d.cc @@ -730,11 +730,11 @@ bool in_line(const FatCo &a, } vec2 exact_ab = b.exact - a.exact; vec2 exact_ac = c.exact - a.exact; - if (vec2::dot(exact_ab, exact_ac) < 0) { + if (dot(exact_ab, exact_ac) < 0) { return false; } vec2 exact_bc = c.exact - b.exact; - return vec2::dot(exact_bc, exact_ac) >= 0; + return dot(exact_bc, exact_ac) >= 0; } #endif @@ -743,11 +743,11 @@ bool in_line(const FatCo &a, const FatCo &b, const FatCo { vec2 ab = b.approx - a.approx; vec2 ac = c.approx - a.approx; - if (vec2::dot(ab, ac) < 0) { + if (dot(ab, ac) < 0) { return false; } vec2 bc = c.approx - b.approx; - return vec2::dot(bc, ac) >= 0; + return dot(bc, ac) >= 0; } template<> CDTVert::CDTVert(const vec2 &pt) @@ -1041,7 +1041,7 @@ template CDTEdge *CDTArrangement::split_edge(SymEdge *se, T SymEdge *sesymprev = prev(sesym); SymEdge *sesymprevsym = sym(sesymprev); SymEdge *senext = se->next; - CDTVert *v = this->add_vert(vec2::interpolate(*a, *b, lambda)); + CDTVert *v = this->add_vert(lerp(*a, *b, lambda)); CDTEdge *e = this->add_edge(v, se->next->vert, se->face, sesym->face); sesym->vert = v; SymEdge *newse = &e->symedges[0]; @@ -1673,7 +1673,7 @@ void fill_crossdata_for_intersect(const FatCo &curco, #else if (true) { #endif - double len_ab = vec2::distance(va->co.approx, vb->co.approx); + double len_ab = distance(va->co.approx, vb->co.approx); if (lambda * len_ab <= epsilon) { fill_crossdata_for_through_vert(va, se_vcva, cd, cd_next); } @@ -1727,8 +1727,8 @@ void fill_crossdata_for_intersect(const FatCo &curco, break; } case vec2::isect_result::LINE_LINE_COLINEAR: { - if (vec2::distance_squared(va->co.approx, v2->co.approx) <= - vec2::distance_squared(vb->co.approx, v2->co.approx)) { + 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); } else { @@ -1805,7 +1805,7 @@ void get_next_crossing_from_edge(CrossData *cd, { CDTVert *va = cd->in->vert; CDTVert *vb = cd->in->next->vert; - vec2 curco = vec2::interpolate(va->co.exact, vb->co.exact, cd->lambda); + vec2 curco = lerp(va->co.exact, vb->co.exact, cd->lambda); FatCo fat_curco(curco); SymEdge *se_ac = sym(cd->in)->next; CDTVert *vc = se_ac->next->vert; @@ -2332,7 +2332,7 @@ template void remove_non_constraint_edges_leave_valid_bmesh(CDT_stat dissolvable_edges[i].e = e; const vec2 &co1 = e->symedges[0].vert->co.approx; const vec2 &co2 = e->symedges[1].vert->co.approx; - dissolvable_edges[i].len_squared = vec2::distance_squared(co1, co2); + dissolvable_edges[i].len_squared = distance_squared(co1, co2); i++; } } diff --git a/source/blender/blenlib/intern/mesh_boolean.cc b/source/blender/blenlib/intern/mesh_boolean.cc index 88d90a7816f..8335a6b951e 100644 --- a/source/blender/blenlib/intern/mesh_boolean.cc +++ b/source/blender/blenlib/intern/mesh_boolean.cc @@ -1561,13 +1561,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 = mpq3::cross(abscissa, ordinate); + mpq3 normal = 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 = normal.length_squared(); + mpq_class nlen2 = length_squared(normal); mpq_class max_abs_slope = -1; Edge esort; const Vector &edges = tmtopo.vert_edges(closestp); @@ -1576,12 +1576,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 - (mpq3::dot(evec, normal) / nlen2) * normal; + mpq3 proj_evec = evec - (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 = mpq3::dot(proj_evec, abscissa); - mpq_class evec_o = mpq3::dot(proj_evec, ordinate); + mpq_class evec_a = dot(proj_evec, abscissa); + mpq_class evec_o = dot(proj_evec, ordinate); if (dbg_level > 0) { std::cout << "e = " << e << "\n"; std::cout << "v_other = " << v_other << "\n"; @@ -1700,8 +1700,8 @@ static mpq_class closest_on_tri_to_point( mpq3 ab = b - a; mpq3 ac = c - a; mpq3 ap = p - a; - mpq_class d1 = mpq3::dot(ab, ap); - mpq_class d2 = mpq3::dot(ac, ap); + mpq_class d1 = dot(ab, ap); + mpq_class d2 = dot(ac, ap); if (d1 <= 0 && d2 <= 0) { /* Barycentric coordinates (1,0,0). */ *r_edge = -1; @@ -1709,12 +1709,12 @@ static mpq_class closest_on_tri_to_point( if (dbg_level > 0) { std::cout << " answer = a\n"; } - return mpq3::distance_squared(p, a); + return distance_squared(p, a); } /* Check if p in vertex region outside b. */ mpq3 bp = p - b; - mpq_class d3 = mpq3::dot(ab, bp); - mpq_class d4 = mpq3::dot(ac, bp); + mpq_class d3 = dot(ab, bp); + mpq_class d4 = dot(ac, bp); if (d3 >= 0 && d4 <= d3) { /* Barycentric coordinates (0,1,0). */ *r_edge = -1; @@ -1722,7 +1722,7 @@ static mpq_class closest_on_tri_to_point( if (dbg_level > 0) { std::cout << " answer = b\n"; } - return mpq3::distance_squared(p, b); + return distance_squared(p, b); } /* Check if p in region of ab. */ mpq_class vc = d1 * d4 - d3 * d2; @@ -1735,12 +1735,12 @@ static mpq_class closest_on_tri_to_point( if (dbg_level > 0) { std::cout << " answer = on ab at " << r << "\n"; } - return mpq3::distance_squared(p, r); + return distance_squared(p, r); } /* Check if p in vertex region outside c. */ mpq3 cp = p - c; - mpq_class d5 = mpq3::dot(ab, cp); - mpq_class d6 = mpq3::dot(ac, cp); + mpq_class d5 = dot(ab, cp); + mpq_class d6 = dot(ac, cp); if (d6 >= 0 && d5 <= d6) { /* Barycentric coordinates (0,0,1). */ *r_edge = -1; @@ -1748,7 +1748,7 @@ static mpq_class closest_on_tri_to_point( if (dbg_level > 0) { std::cout << " answer = c\n"; } - return mpq3::distance_squared(p, c); + return distance_squared(p, c); } /* Check if p in edge region of ac. */ mpq_class vb = d5 * d2 - d1 * d6; @@ -1761,7 +1761,7 @@ static mpq_class closest_on_tri_to_point( if (dbg_level > 0) { std::cout << " answer = on ac at " << r << "\n"; } - return mpq3::distance_squared(p, r); + return distance_squared(p, r); } /* Check if p in edge region of bc. */ mpq_class va = d3 * d6 - d5 * d4; @@ -1776,7 +1776,7 @@ static mpq_class closest_on_tri_to_point( if (dbg_level > 0) { std::cout << " answer = on bc at " << r << "\n"; } - return mpq3::distance_squared(p, r); + return distance_squared(p, r); } /* p inside face region. Compute barycentric coordinates (u,v,w). */ mpq_class denom = 1 / (va + vb + vc); @@ -1790,7 +1790,7 @@ static mpq_class closest_on_tri_to_point( if (dbg_level > 0) { std::cout << " answer = inside at " << r << "\n"; } - return mpq3::distance_squared(p, r); + return distance_squared(p, r); } struct ComponentContainer { @@ -2375,13 +2375,12 @@ static double generalized_winding_number(const IMesh &tm, /* Calculate the solid angle of abc relative to origin. * See "The Solid Angle of a Plane Triangle" by Oosterom and Strackee * for the derivation of the formula. */ - double alen = a.length(); - double blen = b.length(); - double clen = c.length(); - double3 bxc = double3::cross_high_precision(b, c); - double num = double3::dot(a, bxc); - double denom = alen * blen * clen + double3::dot(a, b) * clen + double3::dot(a, c) * blen + - double3::dot(b, c) * alen; + double alen = length(a); + double blen = length(b); + double clen = length(c); + double3 bxc = cross_high_precision(b, c); + double num = dot(a, bxc); + double denom = alen * blen * clen + dot(a, b) * clen + dot(a, c) * blen + dot(b, c) * alen; if (denom == 0.0) { if (dbg_level > 0) { std::cout << "denom == 0, skipping this tri\n"; @@ -2569,7 +2568,7 @@ static Array 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 = 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 @@ -2783,7 +2782,7 @@ static void init_face_merge_state(FaceMergeState *fms, std::cout << "process tri = " << &tri << "\n"; } BLI_assert(tri.plane_populated()); - if (double3::dot(norm, tri.plane->norm) <= 0.0) { + if (dot(norm, tri.plane->norm) <= 0.0) { if (dbg_level > 0) { std::cout << "triangle has wrong orientation, skipping\n"; } @@ -2808,7 +2807,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 = vec.length_squared(); + new_me.len_squared = length_squared(vec); 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); @@ -3048,7 +3047,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 && double3::dot(first_tri_normal, second_tri_normal) > 0.0) { + if (tris.size() == 2 && 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]); diff --git a/source/blender/blenlib/intern/mesh_intersect.cc b/source/blender/blenlib/intern/mesh_intersect.cc index 85a6ab42013..04f692385c9 100644 --- a/source/blender/blenlib/intern/mesh_intersect.cc +++ b/source/blender/blenlib/intern/mesh_intersect.cc @@ -198,9 +198,9 @@ void Face::populate_plane(bool need_exact) 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 = cross(tr02, tr12); } - mpq_class d_exact = -mpq3::dot(normal_exact, vert[0]->co_exact); + mpq_class d_exact = -dot(normal_exact, vert[0]->co_exact); plane = new Plane(normal_exact, d_exact); } else { @@ -215,9 +215,9 @@ void Face::populate_plane(bool need_exact) 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 = cross_high_precision(tr02, tr12); } - double d = -double3::dot(normal, vert[0]->co); + double d = -dot(normal, vert[0]->co); plane = new Plane(normal, d); } } @@ -1174,15 +1174,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 = abs(a); + double3 abs_b = 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 dot(c, c); } /* The index of dot when inputs are plane_coords with index 1 is much higher. @@ -1219,11 +1219,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 = 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 = 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; @@ -1248,9 +1248,9 @@ static int filter_plane_side(const double3 &p, static inline mpq3 tti_interp(const mpq3 &a, const mpq3 &b, const mpq3 &c, const mpq3 &n) { mpq3 ab = a - b; - mpq_class den = mpq3::dot(ab, n); + mpq_class den = dot(ab, n); BLI_assert(den != 0); - mpq_class alpha = mpq3::dot(a - c, n) / den; + mpq_class alpha = dot(a - c, n) / den; return a - alpha * ab; } @@ -1261,8 +1261,8 @@ static inline mpq3 tti_interp(const mpq3 &a, const mpq3 &b, const mpq3 &c, const */ static inline int tti_above(const mpq3 &a, const mpq3 &b, const mpq3 &c, const mpq3 &ad) { - mpq3 n = mpq3::cross(b - a, c - a); - return sgn(mpq3::dot(ad, n)); + mpq3 n = cross(b - a, c - a); + return sgn(dot(ad, n)); } /** @@ -1480,11 +1480,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 = abs(d_p1); + const double3 &abs_d_q1 = abs(d_q1); + const double3 &abs_d_r1 = abs(d_r1); + const double3 &abs_d_r2 = abs(d_r2); + const double3 &abs_d_n2 = 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); @@ -1500,9 +1500,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 = abs(d_p2); + const double3 &abs_d_q2 = abs(d_q2); + const double3 &abs_d_n1 = 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); @@ -1526,13 +1526,13 @@ static ITT_value intersect_tri_tri(const IMesh &tm, int t1, int t2) const mpq3 &n2 = tri2.plane->norm_exact; if (sp1 == 0) { - sp1 = sgn(mpq3::dot(p1 - r2, n2)); + sp1 = sgn(dot(p1 - r2, n2)); } if (sq1 == 0) { - sq1 = sgn(mpq3::dot(q1 - r2, n2)); + sq1 = sgn(dot(q1 - r2, n2)); } if (sr1 == 0) { - sr1 = sgn(mpq3::dot(r1 - r2, n2)); + sr1 = sgn(dot(r1 - r2, n2)); } if (dbg_level > 1) { @@ -1552,13 +1552,13 @@ static ITT_value intersect_tri_tri(const IMesh &tm, int t1, int t2) /* Repeat for signs of t2's vertices with respect to plane of t1. */ const mpq3 &n1 = tri1.plane->norm_exact; if (sp2 == 0) { - sp2 = sgn(mpq3::dot(p2 - r1, n1)); + sp2 = sgn(dot(p2 - r1, n1)); } if (sq2 == 0) { - sq2 = sgn(mpq3::dot(q2 - r1, n1)); + sq2 = sgn(dot(q2 - r1, n1)); } if (sr2 == 0) { - sr2 = sgn(mpq3::dot(r2 - r1, n1)); + sr2 = sgn(dot(r2 - r1, n1)); } if (dbg_level > 1) { @@ -1757,7 +1757,7 @@ static CDT_data prepare_cdt_input(const IMesh &tm, int t, const Vectorplane_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 = dominant_axis(ans.t_plane->norm_exact); prepare_need_tri(ans, tm, t); for (const ITT_value &itt : itts) { switch (itt.kind) { @@ -1793,7 +1793,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 = dominant_axis(ans.t_plane->norm_exact); for (const int t : cl) { prepare_need_tri(ans, tm, t); } @@ -2535,15 +2535,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 = cross_high_precision(da, db); + double dab_length_squared = 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 = cross(a, b); if (ab.x == 0 && ab.y == 0 && ab.z == 0) { return true; } -- cgit v1.2.3