[Bf-blender-cvs] [c1c07b6] master: Use epsilon for line-intersect collinear test

Campbell Barton noreply at git.blender.org
Sat Aug 22 13:22:58 CEST 2015


Commit: c1c07b68b82e221db6dd9855a6c2c4162c1d8e02
Author: Campbell Barton
Date:   Sat Aug 22 21:03:12 2015 +1000
Branches: master
https://developer.blender.org/rBc1c07b68b82e221db6dd9855a6c2c4162c1d8e02

Use epsilon for line-intersect collinear test

Also remove 2x vector normalize since other parts of the code already check this.

Fixes T45849

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

M	source/blender/blenlib/intern/math_geom.c

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

diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c
index 60b1c03..0d02ff3 100644
--- a/source/blender/blenlib/intern/math_geom.c
+++ b/source/blender/blenlib/intern/math_geom.c
@@ -1969,27 +1969,19 @@ int isect_line_line_epsilon_v3(
         const float v3[3], const float v4[3], float i1[3], float i2[3],
         const float epsilon)
 {
-	float a[3], b[3], c[3], ab[3], cb[3], dir1[3], dir2[3];
+	float a[3], b[3], c[3], ab[3], cb[3];
 	float d, div;
 
 	sub_v3_v3v3(c, v3, v1);
 	sub_v3_v3v3(a, v2, v1);
 	sub_v3_v3v3(b, v4, v3);
 
-	normalize_v3_v3(dir1, a);
-	normalize_v3_v3(dir2, b);
-	d = dot_v3v3(dir1, dir2);
-	if (d == 1.0f || d == -1.0f) {
-		/* colinear */
-		return 0;
-	}
-
 	cross_v3_v3v3(ab, a, b);
 	d = dot_v3v3(c, ab);
 	div = dot_v3v3(ab, ab);
 
 	/* test zero length line */
-	if (UNLIKELY(div == 0.0f)) {
+	if (UNLIKELY(div <= epsilon)) {
 		return 0;
 	}
 	/* test if the two lines are coplanar */
@@ -2049,31 +2041,26 @@ bool isect_line_line_strict_v3(const float v1[3], const float v2[3],
                                float vi[3], float *r_lambda)
 {
 	const float epsilon = 0.000001f;
-	float a[3], b[3], c[3], ab[3], cb[3], ca[3], dir1[3], dir2[3];
+	float a[3], b[3], c[3], ab[3], cb[3], ca[3];
 	float d, div;
 
 	sub_v3_v3v3(c, v3, v1);
 	sub_v3_v3v3(a, v2, v1);
 	sub_v3_v3v3(b, v4, v3);
 
-	normalize_v3_v3(dir1, a);
-	normalize_v3_v3(dir2, b);
-	d = dot_v3v3(dir1, dir2);
-	if (d == 1.0f || d == -1.0f || d == 0) {
-		/* colinear or one vector is zero-length*/
-		return false;
-	}
-
 	cross_v3_v3v3(ab, a, b);
 	d = dot_v3v3(c, ab);
 	div = dot_v3v3(ab, ab);
 
 	/* test zero length line */
-	if (UNLIKELY(div == 0.0f)) {
+	if (UNLIKELY(div <= epsilon)) {
 		return false;
 	}
 	/* test if the two lines are coplanar */
-	else if (d > -epsilon && d < epsilon) {
+	else if (UNLIKELY(fabsf(d) < epsilon)) {
+		return false;
+	}
+	else {
 		float f1, f2;
 		cross_v3_v3v3(cb, c, b);
 		cross_v3_v3v3(ca, c, a);
@@ -2095,9 +2082,6 @@ bool isect_line_line_strict_v3(const float v1[3], const float v2[3],
 			return false;
 		}
 	}
-	else {
-		return false;
-	}
 }
 
 bool isect_aabb_aabb_v3(const float min1[3], const float max1[3], const float min2[3], const float max2[3])




More information about the Bf-blender-cvs mailing list