[Bf-blender-cvs] [fb0959f] master: Code cleanup: replace dot with len_squared and is_zero checks

Campbell Barton noreply at git.blender.org
Sat Mar 29 12:28:47 CET 2014


Commit: fb0959f88dc57a73eacd36600607cd10584da387
Author: Campbell Barton
Date:   Sat Mar 29 22:23:27 2014 +1100
https://developer.blender.org/rBfb0959f88dc57a73eacd36600607cd10584da387

Code cleanup: replace dot with len_squared and is_zero checks

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

M	source/blender/blenkernel/intern/armature.c
M	source/blender/blenlib/BLI_math_geom.h
M	source/blender/blenlib/intern/BLI_kdtree.c
M	source/blender/blenlib/intern/math_geom.c
M	source/blender/bmesh/intern/bmesh_polygon.c
M	source/blender/editors/sculpt_paint/sculpt.c
M	source/blender/editors/transform/transform_orientations.c
M	source/blender/editors/transform/transform_snap.c

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

diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c
index 11a34ce..afd3ae7 100644
--- a/source/blender/blenkernel/intern/armature.c
+++ b/source/blender/blenkernel/intern/armature.c
@@ -674,7 +674,7 @@ float distfactor_to_bone(const float vec[3], const float b1[3], const float b2[3
 	sub_v3_v3v3(pdelta, vec, b1);
 
 	a = dot_v3v3(bdelta, pdelta);
-	hsqr = dot_v3v3(pdelta, pdelta);
+	hsqr = len_squared_v3(pdelta);
 
 	if (a < 0.0f) {
 		/* If we're past the end of the bone, do a spherical field attenuation thing */
@@ -1459,7 +1459,7 @@ void vec_roll_to_mat3(const float vec[3], const float roll, float mat[3][3])
 	 * roll when toggling editmode again...
 	 * No good value here, trying 0.000000001 as best compromise. :/
 	 */
-	if (dot_v3v3(axis, axis) > 1.0e-9f) {
+	if (len_squared_v3(axis) > 1.0e-9f) {
 		/* if nor is *not* a multiple of target ... */
 		normalize_v3(axis);
 
diff --git a/source/blender/blenlib/BLI_math_geom.h b/source/blender/blenlib/BLI_math_geom.h
index 14357c0..29ebf9f 100644
--- a/source/blender/blenlib/BLI_math_geom.h
+++ b/source/blender/blenlib/BLI_math_geom.h
@@ -71,9 +71,9 @@ MINLINE float plane_point_side_v3(const float plane[4], const float co[3]);
 
 float volume_tetrahedron_v3(const float v1[3], const float v2[3], const float v3[3], const float v4[3]);
 
-int is_quad_convex_v3(const float v1[3], const float v2[3], const float v3[3], const float v4[3]);
-int is_quad_convex_v2(const float v1[2], const float v2[2], const float v3[2], const float v4[2]);
-int is_poly_convex_v2(const float verts[][2], unsigned int nr);
+bool is_quad_convex_v3(const float v1[3], const float v2[3], const float v3[3], const float v4[3]);
+bool is_quad_convex_v2(const float v1[2], const float v2[2], const float v3[2], const float v4[2]);
+bool is_poly_convex_v2(const float verts[][2], unsigned int nr);
 
 /********************************* Distance **********************************/
 
@@ -122,7 +122,7 @@ int isect_line_line_v2_int(const int a1[2], const int a2[2], const int b1[2], co
 int isect_line_sphere_v3(const float l1[3], const float l2[3], const float sp[3], const float r, float r_p1[3], float r_p2[3]);
 int isect_line_sphere_v2(const float l1[2], const float l2[2], const float sp[2], const float r, float r_p1[2], float r_p2[2]);
 int isect_seg_seg_v2_point(const float v1[2], const float v2[2], const float v3[2], const float v4[2], float vi[2]);
-int isect_seg_seg_v2(const float v1[2], const float v2[2], const float v3[2], const float v4[2]);
+bool isect_seg_seg_v2(const float v1[2], const float v2[2], const float v3[2], const float v4[2]);
 
 int isect_line_line_v3(const float v1[3], const float v2[3],
                        const float v3[3], const float v4[3],
@@ -162,9 +162,9 @@ bool isect_point_poly_v2_int(const int pt[2], const int verts[][2], const unsign
 
 int isect_point_quad_v2(const float p[2], const float a[2], const float b[2], const float c[2], const float d[2]);
 
-int isect_point_tri_v2(const float pt[2], const float v1[2], const float v2[2], const float v3[2]);
-int isect_point_tri_v2_cw(const float pt[2], const float v1[2], const float v2[2], const float v3[2]);
-int isect_point_tri_v2_int(const int x1, const int y1, const int x2, const int y2, const int a, const int b);
+int  isect_point_tri_v2(const float pt[2], const float v1[2], const float v2[2], const float v3[2]);
+bool isect_point_tri_v2_cw(const float pt[2], const float v1[2], const float v2[2], const float v3[2]);
+int  isect_point_tri_v2_int(const int x1, const int y1, const int x2, const int y2, const int a, const int b);
 bool isect_point_tri_prism_v3(const float p[3], const float v1[3], const float v2[3], const float v3[3]);
 
 /* axis-aligned bounding box */
diff --git a/source/blender/blenlib/intern/BLI_kdtree.c b/source/blender/blenlib/intern/BLI_kdtree.c
index 1a4d8bc..ed6e6e3 100644
--- a/source/blender/blenlib/intern/BLI_kdtree.c
+++ b/source/blender/blenlib/intern/BLI_kdtree.c
@@ -170,7 +170,7 @@ static float squared_distance(const float v2[3], const float v1[3], const float
 	d[1] = v2[1] - v1[1];
 	d[2] = v2[2] - v1[2];
 
-	dist = dot_v3v3(d, d);
+	dist = len_squared_v3(d);
 
 	/* can someone explain why this is done?*/
 	if (n2 && (dot_v3v3(d, n2) < 0.0f)) {
diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c
index 3daa741..e41ec8b 100644
--- a/source/blender/blenlib/intern/math_geom.c
+++ b/source/blender/blenlib/intern/math_geom.c
@@ -601,7 +601,7 @@ int isect_seg_seg_v2_point(const float v1[2], const float v2[2], const float v3[
 	return -1;
 }
 
-int isect_seg_seg_v2(const float v1[2], const float v2[2], const float v3[2], const float v4[2])
+bool isect_seg_seg_v2(const float v1[2], const float v2[2], const float v3[2], const float v4[2])
 {
 #define CCW(A, B, C) ((C[1] - A[1]) * (B[0] - A[0]) > (B[1]-A[1]) * (C[0]-A[0]))
 
@@ -638,7 +638,7 @@ int isect_line_sphere_v3(const float l1[3], const float l2[3],
 		l2[2] - l1[2]
 	};
 
-	const float a = dot_v3v3(ldir, ldir);
+	const float a = len_squared_v3(ldir);
 
 	const float b = 2.0f *
 	                (ldir[0] * (l1[0] - sp[0]) +
@@ -646,8 +646,8 @@ int isect_line_sphere_v3(const float l1[3], const float l2[3],
 	                 ldir[2] * (l1[2] - sp[2]));
 
 	const float c =
-	    dot_v3v3(sp, sp) +
-	    dot_v3v3(l1, l1) -
+	    len_squared_v3(sp) +
+	    len_squared_v3(l1) -
 	    (2.0f * dot_v3v3(sp, l1)) -
 	    (r * r);
 
@@ -854,7 +854,7 @@ bool isect_point_poly_v2_int(const int pt[2], const int verts[][2], const unsign
 /* point in tri */
 
 /* only single direction */
-int isect_point_tri_v2_cw(const float pt[2], const float v1[2], const float v2[2], const float v3[2])
+bool isect_point_tri_v2_cw(const float pt[2], const float v1[2], const float v2[2], const float v3[2])
 {
 	if (line_point_side_v2(v1, v2, pt) >= 0.0f) {
 		if (line_point_side_v2(v2, v3, pt) >= 0.0f) {
@@ -1145,7 +1145,7 @@ bool isect_ray_tri_threshold_v3(const float p1[3], const float d[3],
 	mul_v3_fl(e1, du);
 	mul_v3_fl(e2, dv);
 
-	if (dot_v3v3(e1, e1) + dot_v3v3(e2, e2) > threshold * threshold) {
+	if (len_squared_v3(e1) + len_squared_v3(e2) > threshold * threshold) {
 		return 0;
 	}
 
@@ -2140,7 +2140,7 @@ static float tri_signed_area(const float v1[3], const float v2[3], const float v
 }
 
 /* return 1 when degenerate */
-static int barycentric_weights(const float v1[3], const float v2[3], const float v3[3], const float co[3], const float n[3], float w[3])
+static bool barycentric_weights(const float v1[3], const float v2[3], const float v3[3], const float co[3], const float n[3], float w[3])
 {
 	float wtot;
 	int i, j;
@@ -2182,7 +2182,7 @@ void interp_weights_face_v3(float w[4], const float v1[3], const float v2[3], co
 	else {
 		/* otherwise compute barycentric interpolation weights */
 		float n1[3], n2[3], n[3];
-		int degenerate;
+		bool degenerate;
 
 		sub_v3_v3v3(n1, v1, v3);
 		if (v4) {
@@ -3791,7 +3791,7 @@ float form_factor_hemi_poly(float p[3], float n[3], float v1[3], float v2[3], fl
 }
 
 /* evaluate if entire quad is a proper convex quad */
-int is_quad_convex_v3(const float v1[3], const float v2[3], const float v3[3], const float v4[3])
+bool is_quad_convex_v3(const float v1[3], const float v2[3], const float v3[3], const float v4[3])
 {
 	float nor[3], nor_a[3], nor_b[3], vec[4][2];
 	float mat[3][3];
@@ -3841,13 +3841,13 @@ int is_quad_convex_v3(const float v1[3], const float v2[3], const float v3[3], c
 	return (isect_line_line_v2(vec[0], vec[2], vec[1], vec[3]) > 0);
 }
 
-int is_quad_convex_v2(const float v1[2], const float v2[2], const float v3[2], const float v4[2])
+bool is_quad_convex_v2(const float v1[2], const float v2[2], const float v3[2], const float v4[2])
 {
 	/* linetests, the 2 diagonals have to instersect to be convex */
 	return (isect_line_line_v2(v1, v3, v2, v4) > 0);
 }
 
-int is_poly_convex_v2(const float verts[][2], unsigned int nr)
+bool is_poly_convex_v2(const float verts[][2], unsigned int nr)
 {
 	unsigned int sign_flag = 0;
 	unsigned int a;
diff --git a/source/blender/bmesh/intern/bmesh_polygon.c b/source/blender/bmesh/intern/bmesh_polygon.c
index 867c54a..aff7d37 100644
--- a/source/blender/bmesh/intern/bmesh_polygon.c
+++ b/source/blender/bmesh/intern/bmesh_polygon.c
@@ -311,7 +311,7 @@ void BM_face_calc_plane(BMFace *f, float r_plane[3])
 		sub_v3_v3v3(vec_b, verts[1]->co, verts[2]->co);
 		add_v3_v3v3(vec, vec_a, vec_b);
 		/* use the biggest edge length */
-		if (dot_v3v3(r_plane, r_plane) < dot_v3v3(vec, vec)) {
+		if (len_squared_v3(r_plane) < len_squared_v3(vec)) {
 			copy_v3_v3(r_plane, vec);
 		}
 	}
@@ -723,7 +723,7 @@ bool BM_face_point_inside_test(BMFace *f, const float co[3])
 	int crosses = 0;
 	float onepluseps = 1.0f + (float)FLT_EPSILON * 150.0f;
 	
-	if (dot_v3v3(f->no, f->no) <= FLT_EPSILON * 10)
+	if (is_zero_v3(f->no))
 		BM_face_normal_update(f);
 	
 	/* find best projection of face XY, XZ or YZ: barycentric weights of
diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index 7752101..f8e2fc1 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -1045,7 +1045,7 @@ static bool sculpt_search_sphere_cb(PBVHNode *node, void *data_v)
 	
 	sub_v3_v3v3(t, center, nearest);
 
-	return dot_v3v3(t, t) < data->radius_squared;
+	return len_squared_v3(t) < data->radius_squared;
 }
 
 /* Handles clipping against a mirror modifier and SCULPT_LOCK axis flags */
diff --git a/source/blender/editors/transform/transform_orientations.c b/source/blender/editors/transform/transform_orientations.c
index 0279ee0..5d415d7 100644
--- a/source/blender/editors/transform/transform_orientations.c
+++ b/source/blender/editors/transform/transform_orientations.c
@@ -244,7 +244,7 @@ bool createSpaceNormal(float mat[3][3], const float normal[3])
 	}
 
 	cross_v3_v3v3(mat[0], mat[2], tangent);
-	if (dot_v3v3(mat[0], mat[0]) == 0.0f) {
+	if (is_zero_v3(mat[0])) {
 		tangent[0] = 1.0f;
 		tangent[1] = tangent[2] = 0.0f;
 		cross_v3_v3v3(mat[0], tangent, mat[2]);
diff --git a/source/blender/editors/transform/transform_snap.c b/source/blender/editors/transform/

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list