[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [58014] trunk/blender/source/blender/ blenlib/intern/math_geom.c: fix [#35987] bevel gives nan vertices

Campbell Barton ideasman42 at gmail.com
Fri Jul 5 02:30:00 CEST 2013


Revision: 58014
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=58014
Author:   campbellbarton
Date:     2013-07-05 00:30:00 +0000 (Fri, 05 Jul 2013)
Log Message:
-----------
fix [#35987] bevel gives nan vertices
The line intersection function bevel uses could give nan intersections.

Modified Paths:
--------------
    trunk/blender/source/blender/blenlib/intern/math_geom.c

Modified: trunk/blender/source/blender/blenlib/intern/math_geom.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/math_geom.c	2013-07-05 00:13:14 UTC (rev 58013)
+++ trunk/blender/source/blender/blenlib/intern/math_geom.c	2013-07-05 00:30:00 UTC (rev 58014)
@@ -1452,7 +1452,7 @@
 int isect_line_line_v3(const float v1[3], const float v2[3], const float v3[3], const float v4[3], float i1[3], float i2[3])
 {
 	float a[3], b[3], c[3], ab[3], cb[3], dir1[3], dir2[3];
-	float d;
+	float d, div;
 
 	sub_v3_v3v3(c, v3, v1);
 	sub_v3_v3v3(a, v2, v1);
@@ -1468,12 +1468,17 @@
 
 	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)) {
+		return 0;
+	}
 	/* test if the two lines are coplanar */
-	if (d > -0.000001f && d < 0.000001f) {
+	else if (d > -0.000001f && d < 0.000001f) {
 		cross_v3_v3v3(cb, c, b);
 
-		mul_v3_fl(a, dot_v3v3(cb, ab) / dot_v3v3(ab, ab));
+		mul_v3_fl(a, dot_v3v3(cb, ab) / div);
 		add_v3_v3v3(i1, v1, a);
 		copy_v3_v3(i2, i1);
 
@@ -1518,7 +1523,7 @@
                                float vi[3], float *r_lambda)
 {
 	float a[3], b[3], c[3], ab[3], cb[3], ca[3], dir1[3], dir2[3];
-	float d;
+	float d, div;
 
 	sub_v3_v3v3(c, v3, v1);
 	sub_v3_v3v3(a, v2, v1);
@@ -1534,15 +1539,20 @@
 
 	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)) {
+		return 0;
+	}
 	/* test if the two lines are coplanar */
-	if (d > -0.000001f && d < 0.000001f) {
+	else if (d > -0.000001f && d < 0.000001f) {
 		float f1, f2;
 		cross_v3_v3v3(cb, c, b);
 		cross_v3_v3v3(ca, c, a);
 
-		f1 = dot_v3v3(cb, ab) / dot_v3v3(ab, ab);
-		f2 = dot_v3v3(ca, ab) / dot_v3v3(ab, ab);
+		f1 = dot_v3v3(cb, ab) / div;
+		f2 = dot_v3v3(ca, ab) / div;
 
 		if (f1 >= 0 && f1 <= 1 &&
 		    f2 >= 0 && f2 <= 1)




More information about the Bf-blender-cvs mailing list