[Bf-blender-cvs] [a9f8d366b4b] newboolean: Use doubles for boolean planes. Added needed double BLI routines.
Howard Trickey
noreply at git.blender.org
Fri Aug 30 04:23:43 CEST 2019
Commit: a9f8d366b4bf69fbd324abbb4ee2e38b879676c8
Author: Howard Trickey
Date: Thu Aug 29 22:21:21 2019 -0400
Branches: newboolean
https://developer.blender.org/rBa9f8d366b4bf69fbd324abbb4ee2e38b879676c8
Use doubles for boolean planes. Added needed double BLI routines.
===================================================================
M source/blender/blenlib/BLI_math_geom.h
M source/blender/blenlib/BLI_math_matrix.h
M source/blender/blenlib/BLI_math_vector.h
M source/blender/blenlib/intern/math_geom.c
M source/blender/blenlib/intern/math_matrix.c
M source/blender/blenlib/intern/math_vector.c
M source/blender/blenlib/intern/math_vector_inline.c
M source/blender/bmesh/tools/bmesh_boolean.c
===================================================================
diff --git a/source/blender/blenlib/BLI_math_geom.h b/source/blender/blenlib/BLI_math_geom.h
index caecc0aebc2..afcfb405ddb 100644
--- a/source/blender/blenlib/BLI_math_geom.h
+++ b/source/blender/blenlib/BLI_math_geom.h
@@ -482,6 +482,10 @@ bool isect_aabb_aabb_v3(const float min1[3],
const float max1[3],
const float min2[3],
const float max2[3]);
+bool isect_aabb_aabb_v3_db(const double min1[3],
+ const double max1[3],
+ const double min2[3],
+ const double max2[3]);
struct IsectRayAABB_Precalc {
float ray_origin[3];
@@ -762,6 +766,7 @@ float form_factor_hemi_poly(
void axis_dominant_v3_to_m3_negate(float r_mat[3][3], const float normal[3]);
void axis_dominant_v3_to_m3(float r_mat[3][3], const float normal[3]);
+void axis_dominant_v3_to_m3_db(double r_mat[3][3], const double normal[3]);
MINLINE void axis_dominant_v3(int *r_axis_a, int *r_axis_b, const float axis[3]);
MINLINE float axis_dominant_v3_max(int *r_axis_a,
diff --git a/source/blender/blenlib/BLI_math_matrix.h b/source/blender/blenlib/BLI_math_matrix.h
index f5d87667b73..976f6296b79 100644
--- a/source/blender/blenlib/BLI_math_matrix.h
+++ b/source/blender/blenlib/BLI_math_matrix.h
@@ -218,6 +218,7 @@ bool invert_m3_m3_ex(float m1[3][3], const float m2[3][3], const float epsilon);
bool invert_m3(float R[3][3]);
bool invert_m3_m3(float R[3][3], const float A[3][3]);
+bool invert_m3_m3_db(double R[3][3], const double A[3][3]);
bool invert_m4(float R[4][4]);
bool invert_m4_m4(float R[4][4], const float A[4][4]);
bool invert_m4_m4_fallback(float R[4][4], const float A[4][4]);
@@ -233,6 +234,7 @@ void mul_m3_v3_db(const double M[3][3], double r[3]);
/****************************** Linear Algebra *******************************/
void transpose_m3(float R[3][3]);
+void transpose_m3_db(double R[3][3]);
void transpose_m3_m3(float R[3][3], const float A[3][3]);
void transpose_m3_m4(float R[3][3], const float A[4][4]);
void transpose_m4(float R[4][4]);
@@ -266,12 +268,14 @@ bool is_uniform_scaled_m4(const float m[4][4]);
*/
void adjoint_m2_m2(float R[2][2], const float A[2][2]);
void adjoint_m3_m3(float R[3][3], const float A[3][3]);
+void adjoint_m3_m3_db(double R[3][3], const double A[3][3]);
void adjoint_m4_m4(float R[4][4], const float A[4][4]);
float determinant_m2(float a, float b, float c, float d);
float determinant_m3(
float a, float b, float c, float d, float e, float f, float g, float h, float i);
float determinant_m3_array(const float m[3][3]);
+double determinant_m3_array_db(const double m[3][3]);
float determinant_m4_mat3_array(const float m[4][4]);
float determinant_m4(const float A[4][4]);
diff --git a/source/blender/blenlib/BLI_math_vector.h b/source/blender/blenlib/BLI_math_vector.h
index 31d725af5ad..e19d61db05e 100644
--- a/source/blender/blenlib/BLI_math_vector.h
+++ b/source/blender/blenlib/BLI_math_vector.h
@@ -76,6 +76,8 @@ MINLINE void copy_v3_v3_int(int r[3], const int a[3]);
MINLINE void copy_v4_v4_int(int r[4], const int a[4]);
/* double */
MINLINE void zero_v3_db(double r[3]);
+MINLINE void zero_v4_db(double r[4]);
+MINLINE void copy_v3_db(double r[3], double d);
MINLINE void copy_v2_v2_db(double r[2], const double a[2]);
MINLINE void copy_v3_v3_db(double r[3], const double a[3]);
MINLINE void copy_v4_v4_db(double r[4], const double a[4]);
@@ -209,6 +211,7 @@ MINLINE void star_m3_v3(float rmat[3][3], float a[3]);
/*********************************** Length **********************************/
MINLINE float len_squared_v2(const float v[2]) ATTR_WARN_UNUSED_RESULT;
+MINLINE double len_squared_v2_db(const double v[2]) ATTR_WARN_UNUSED_RESULT;
MINLINE float len_squared_v3(const float v[3]) ATTR_WARN_UNUSED_RESULT;
MINLINE float len_manhattan_v2(const float v[2]) ATTR_WARN_UNUSED_RESULT;
MINLINE int len_manhattan_v2_int(const int v[2]) ATTR_WARN_UNUSED_RESULT;
@@ -400,6 +403,7 @@ void project_plane_normalized_v2_v2v2(float out[2], const float p[2], const floa
void project_v3_plane(float out[3], const float plane_no[3], const float plane_co[3]);
void reflect_v3_v3v3(float out[3], const float vec[3], const float normal[3]);
void ortho_basis_v3v3_v3(float r_n1[3], float r_n2[3], const float n[3]);
+void ortho_basis_v3v3_v3_db(double r_n1[3], double r_n2[3], const double n[3]);
void ortho_v3_v3(float out[3], const float v[3]);
void ortho_v2_v2(float out[2], const float v[2]);
void bisect_v3_v3v3v3(float r[3], const float a[3], const float b[3], const float c[3]);
diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c
index 0162f4552f0..e9ec706a338 100644
--- a/source/blender/blenlib/intern/math_geom.c
+++ b/source/blender/blenlib/intern/math_geom.c
@@ -3100,6 +3100,15 @@ bool isect_aabb_aabb_v3(const float min1[3],
min2[1] < max1[1] && min2[2] < max1[2]);
}
+bool isect_aabb_aabb_v3_db(const double min1[3],
+ const double max1[3],
+ const double min2[3],
+ const double max2[3])
+{
+ return (min1[0] < max2[0] && min1[1] < max2[1] && min1[2] < max2[2] && min2[0] < max1[0] &&
+ min2[1] < max1[1] && min2[2] < max1[2]);
+}
+
void isect_ray_aabb_v3_precalc(struct IsectRayAABB_Precalc *data,
const float ray_origin[3],
const float ray_direction[3])
@@ -3634,6 +3643,14 @@ void axis_dominant_v3_to_m3_negate(float r_mat[3][3], const float normal[3])
BLI_assert((dot_m3_v3_row_z(r_mat, normal) < BLI_ASSERT_UNIT_EPSILON) || is_zero_v3(normal));
}
+void axis_dominant_v3_to_m3_db(double r_mat[3][3], const double normal[3])
+{
+ copy_v3_v3_db(r_mat[2], normal);
+ ortho_basis_v3v3_v3_db(r_mat[0], r_mat[1], r_mat[2]);
+
+ transpose_m3_db(r_mat);
+}
+
/****************************** Interpolation ********************************/
static float tri_signed_area(
diff --git a/source/blender/blenlib/intern/math_matrix.c b/source/blender/blenlib/intern/math_matrix.c
index 2568d42566c..43f9becb9ad 100644
--- a/source/blender/blenlib/intern/math_matrix.c
+++ b/source/blender/blenlib/intern/math_matrix.c
@@ -1053,6 +1053,13 @@ float determinant_m3_array(const float m[3][3])
m[2][0] * (m[0][1] * m[1][2] - m[0][2] * m[1][1]));
}
+double determinant_m3_array_db(const double m[3][3])
+{
+ return (m[0][0] * (m[1][1] * m[2][2] - m[1][2] * m[2][1]) -
+ m[1][0] * (m[0][1] * m[2][2] - m[0][2] * m[2][1]) +
+ m[2][0] * (m[0][1] * m[1][2] - m[0][2] * m[1][1]));
+}
+
float determinant_m4_mat3_array(const float m[4][4])
{
return (m[0][0] * (m[1][1] * m[2][2] - m[1][2] * m[2][1]) -
@@ -1131,6 +1138,32 @@ bool invert_m3_m3(float m1[3][3], const float m2[3][3])
return success;
}
+bool invert_m3_m3_db(double m1[3][3], const double m2[3][3])
+{
+ double det;
+ int a, b;
+ bool success;
+
+ /* calc adjoint */
+ adjoint_m3_m3_db(m1, m2);
+
+ /* then determinant old matrix! */
+ det = determinant_m3_array_db(m2);
+
+ success = (det != 0.0);
+
+ if (LIKELY(det != 0.0)) {
+ det = 1.0 / det;
+ for (a = 0; a < 3; a++) {
+ for (b = 0; b < 3; b++) {
+ m1[a][b] *= det;
+ }
+ }
+ }
+
+ return success;
+}
+
bool invert_m4(float m[4][4])
{
float tmp[4][4];
@@ -1244,6 +1277,21 @@ void transpose_m3(float mat[3][3])
mat[2][1] = t;
}
+void transpose_m3_db(double mat[3][3])
+{
+ float t;
+
+ t = mat[0][1];
+ mat[0][1] = mat[1][0];
+ mat[1][0] = t;
+ t = mat[0][2];
+ mat[0][2] = mat[2][0];
+ mat[2][0] = t;
+ t = mat[1][2];
+ mat[1][2] = mat[2][1];
+ mat[2][1] = t;
+}
+
void transpose_m3_m3(float rmat[3][3], const float mat[3][3])
{
BLI_assert(rmat != mat);
@@ -1706,6 +1754,22 @@ void adjoint_m3_m3(float m1[3][3], const float m[3][3])
m1[2][2] = m[0][0] * m[1][1] - m[0][1] * m[1][0];
}
+void adjoint_m3_m3_db(double m1[3][3], const double m[3][3])
+{
+ BLI_assert(m1 != m);
+ m1[0][0] = m[1][1] * m[2][2] - m[1][2] * m[2][1];
+ m1[0][1] = -m[0][1] * m[2][2] + m[0][2] * m[2][1];
+ m1[0][2] = m[0][1] * m[1][2] - m[0][2] * m[1][1];
+
+ m1[1][0] = -m[1][0] * m[2][2] + m[1][2] * m[2][0];
+ m1[1][1] = m[0][0] * m[2][2] - m[0][2] * m[2][0];
+ m1[1][2] = -m[0][0] * m[1][2] + m[0][2] * m[1][0];
+
+ m1[2][0] = m[1][0] * m[2][1] - m[1][1] * m[2][0];
+ m1[2][1] = -m[0][0] * m[2][1] + m[0][1] * m[2][0];
+ m1[2][2] = m[0][0] * m[1][1] - m[0][1] * m[1][0];
+}
+
void adjoint_m4_m4(float out[4][4], const float in[4][4]) /* out = ADJ(in) */
{
float a1, a2, a3, a4, b1, b2, b3, b4;
diff --git a/source/blender/blenlib/intern/math_vector.c b/source/blender/blenlib/intern/math_vector.c
index 961850d3a9a..fae900bc93d 100644
--- a/source/blender/blenlib/intern/math_vector.c
+++ b/source/blender/blenlib/intern/math_vector.c
@@ -836,6 +836,31 @@ void ortho_basis_v3v3_v3(float r_n1[3], float r_n2[3], const float n[3])
}
}
+void ortho_basis_v3v3_v3_db(double r_n1[3], double r_n2[3], const double n[3])
+{
+ const double eps = FLT_EPSILON;
+ const double f = len_squared_v2_db(n);
+
+ if (f > eps) {
+ const double d = 1.0 / sqrt(f);
+
+ BLI_assert(isfinite(d));
+
+ r_n1[0] = n[1] * d;
+ r_n1[1] = -n[0] * d;
+ r_n1[2] = 0.0;
+ r_n2[0] = -n[2] * r_n1[1];
+ r_n2[1] = n[2] * r_n1[0];
+ r_n2[2] = n[0] * r_n1[1] - n[1] * r_n1[0];
+ }
+ else {
+ /* degenerate case */
+ r_n1[0] = (n[2] < 0.0f) ? -1.0f : 1.0f;
+ r_n1[1] = r_n1[2] = r_n2[0] = r_n2[2] = 0.0f;
+ r_n2[1] = 1.0;
+ }
+}
+
/**
* Calculates \a p - a perpendicular vector to \a v
*
diff --git a/source/blender/blenlib/intern/math_vector_inline.c b/source/blender/blenlib/intern/math_vector_inline.c
index b4b53a1dd58..1fcb31aad4a 100644
--- a/source/blender/blenlib/intern/math_vector_inline.c
+++ b/source/blender/blenlib/intern/math_vector_inline.c
@@ -205,6 +205,21 @@ MINLINE void zero_v3_db(double r[3])
r[2] = 0.0;
}
+MINLINE void zero_v4_db(double r[4])
+{
+ r[0] = 0.0;
+ r[1] = 0.0;
+ r[2] = 0.0;
+ r[3] = 0.0;
+}
+
+MINLINE void copy_v3_db(double r[3], double d)
+{
+ r[0] = d;
+ r[1] = d;
+ r[2] = d;
+}
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list