[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [54548] trunk/blender/source/blender/ blenlib/intern/math_geom.c: modify own changes to is_quad_convex_v3() to allow quads with a co-linear side to be considered convex ( as it did in last release).

Campbell Barton ideasman42 at gmail.com
Thu Feb 14 10:17:50 CET 2013


Revision: 54548
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=54548
Author:   campbellbarton
Date:     2013-02-14 09:17:50 +0000 (Thu, 14 Feb 2013)
Log Message:
-----------
modify own changes to is_quad_convex_v3() to allow quads with a co-linear side to be considered convex (as it did in last release).
this is needed so zero area faces be dealt with by beauty fill.

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-02-14 07:49:50 UTC (rev 54547)
+++ trunk/blender/source/blender/blenlib/intern/math_geom.c	2013-02-14 09:17:50 UTC (rev 54548)
@@ -3578,30 +3578,43 @@
 /* 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])
 {
-	float nor[3], nor1[3], nor2[3], vec[4][2];
+	float nor[3], nor_a[3], nor_b[3], vec[4][2];
 	float mat[3][3];
+	const bool is_ok_a = (normal_tri_v3(nor_a, v1, v2, v3) > FLT_EPSILON);
+	const bool is_ok_b = (normal_tri_v3(nor_b, v1, v3, v4) > FLT_EPSILON);
 
 	/* define projection, do both trias apart, quad is undefined! */
 
 	/* check normal length incase one size is zero area */
-	if (UNLIKELY((normal_tri_v3(nor1, v1, v2, v3) <= FLT_EPSILON) ||
-	             (normal_tri_v3(nor2, v1, v3, v4) <= FLT_EPSILON)))
-	{
-		return false;
-	}
+	if (is_ok_a) {
+		if (is_ok_b) {
+			/* use both, most common outcome */
 
-	/* when the face is folded over as 2 tris we probably don't want to create
-	 * a quad from it, but go ahead with the intersection test since this
-	 * isn't a function for degenerate faces */
-	if (UNLIKELY(dot_v3v3(nor1, nor2) < 0.0f)) {
-		/* flip so adding normals in the opposite direction
-		 * doesnt give a zero length vector */
-		negate_v3(nor2);
+			/* when the face is folded over as 2 tris we probably don't want to create
+			 * a quad from it, but go ahead with the intersection test since this
+			 * isn't a function for degenerate faces */
+			if (UNLIKELY(dot_v3v3(nor_a, nor_b) < 0.0f)) {
+				/* flip so adding normals in the opposite direction
+				 * doesn't give a zero length vector */
+				negate_v3(nor_b);
+			}
+
+			add_v3_v3v3(nor, nor_a, nor_b);
+			normalize_v3(nor);
+		}
+		else {
+			copy_v3_v3(nor, nor_a);  /* only 'a' */
+		}
 	}
+	else {
+		if (is_ok_b) {
+			copy_v3_v3(nor, nor_b);  /* only 'b' */
+		}
+		else {
+			return false;  /* both zero, we can't do anything useful here */
+		}
+	}
 
-	add_v3_v3v3(nor, nor1, nor2);
-	normalize_v3(nor);
-
 	axis_dominant_v3_to_m3(mat, nor);
 
 	mul_v2_m3v3(vec[0], mat, v1);
@@ -3610,12 +3623,12 @@
 	mul_v2_m3v3(vec[3], mat, v4);
 
 	/* linetests, the 2 diagonals have to instersect to be convex */
-	return (isect_line_line_v2(vec[0], vec[2], vec[1], vec[3]) == ISECT_LINE_LINE_CROSS);
+	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])
 {
 	/* linetests, the 2 diagonals have to instersect to be convex */
-	return (isect_line_line_v2(v1, v3, v2, v4) == ISECT_LINE_LINE_CROSS);
+	return (isect_line_line_v2(v1, v3, v2, v4) > 0);
 }
 




More information about the Bf-blender-cvs mailing list