[Bf-blender-cvs] [25c5542] master: Math Lib: add constant: M_SQRT1_3 1/sqrt(3)

Campbell Barton noreply at git.blender.org
Sat Nov 22 18:21:54 CET 2014


Commit: 25c5542fe78abe79cdf9d2ec46607de01762f32e
Author: Campbell Barton
Date:   Sat Nov 22 18:11:46 2014 +0100
Branches: master
https://developer.blender.org/rB25c5542fe78abe79cdf9d2ec46607de01762f32e

Math Lib: add constant: M_SQRT1_3 1/sqrt(3)

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

M	source/blender/blenlib/BLI_math_base.h
M	source/blender/blenlib/intern/math_matrix.c
M	source/blender/bmesh/tools/bmesh_bevel.c

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

diff --git a/source/blender/blenlib/BLI_math_base.h b/source/blender/blenlib/BLI_math_base.h
index 5711d09..13718e8 100644
--- a/source/blender/blenlib/BLI_math_base.h
+++ b/source/blender/blenlib/BLI_math_base.h
@@ -48,13 +48,16 @@
 #define M_PI_2      1.57079632679489661923
 #endif
 #ifndef M_SQRT2
-#define M_SQRT2     1.41421356237309504880
+#define M_SQRT2     1.41421356237309504880  /* sqrt(2) */
 #endif
 #ifndef M_SQRT1_2
-#define M_SQRT1_2   0.70710678118654752440
+#define M_SQRT1_2   0.70710678118654752440  /* 1/sqrt(2) */
 #endif
 #ifndef M_SQRT3
-#define M_SQRT3   1.7320508075688772
+#define M_SQRT3     1.73205080756887729352  /* sqrt(3) */
+#endif
+#ifndef M_SQRT1_3
+#define M_SQRT1_3   0.57735026918962576450  /* 1/sqrt(3) */
 #endif
 #ifndef M_1_PI
 #define M_1_PI      0.318309886183790671538
diff --git a/source/blender/blenlib/intern/math_matrix.c b/source/blender/blenlib/intern/math_matrix.c
index 0204c3b..2da1f22 100644
--- a/source/blender/blenlib/intern/math_matrix.c
+++ b/source/blender/blenlib/intern/math_matrix.c
@@ -1448,7 +1448,7 @@ float mat3_to_scale(float mat[3][3])
 {
 	/* unit length vector */
 	float unit_vec[3];
-	copy_v3_fl(unit_vec, (float)(1.0 / M_SQRT3));
+	copy_v3_fl(unit_vec, (float)M_SQRT1_3);
 	mul_m3_v3(mat, unit_vec);
 	return len_v3(unit_vec);
 }
@@ -1457,7 +1457,7 @@ float mat4_to_scale(float mat[4][4])
 {
 	/* unit length vector */
 	float unit_vec[3];
-	copy_v3_fl(unit_vec, (float)(1.0 / M_SQRT3));
+	copy_v3_fl(unit_vec, (float)M_SQRT1_3);
 	mul_mat3_m4_v3(mat, unit_vec);
 	return len_v3(unit_vec);
 }
diff --git a/source/blender/bmesh/tools/bmesh_bevel.c b/source/blender/bmesh/tools/bmesh_bevel.c
index 99ff699..c3d1ca8 100644
--- a/source/blender/bmesh/tools/bmesh_bevel.c
+++ b/source/blender/bmesh/tools/bmesh_bevel.c
@@ -2229,7 +2229,6 @@ static VMesh *make_cube_corner_adj_vmesh(BevelParams *bp)
 	BoundVert *bndv;
 	int i, j, k, ns2;
 	float co[3], coc[3];
-	float w;
 
 	if (r == PRO_SQUARE_R)
 		return make_cube_corner_straight(mem_arena, nseg);
@@ -2262,10 +2261,8 @@ static VMesh *make_cube_corner_adj_vmesh(BevelParams *bp)
 		bndv = bndv->next;
 	}
 	/* center vertex */
-	w = (float)(1.0 / M_SQRT3);
-	co[0] = w;
-	co[1] = w;
-	co[2] = w;
+	copy_v3_fl(co, M_SQRT1_3);
+
 	if (nseg > 2) {
 		if (r > 1.5f)
 			mul_v3_fl(co, 1.4f);




More information about the Bf-blender-cvs mailing list