[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [60231] trunk/blender/source/blender/bmesh /intern/bmesh_polygon.c: minor edits to poly_find_ear() bmesh function, no functional changes.

Campbell Barton ideasman42 at gmail.com
Thu Sep 19 09:40:42 CEST 2013


Revision: 60231
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=60231
Author:   campbellbarton
Date:     2013-09-19 07:40:41 +0000 (Thu, 19 Sep 2013)
Log Message:
-----------
minor edits to poly_find_ear() bmesh function, no functional changes.

Modified Paths:
--------------
    trunk/blender/source/blender/bmesh/intern/bmesh_polygon.c

Modified: trunk/blender/source/blender/bmesh/intern/bmesh_polygon.c
===================================================================
--- trunk/blender/source/blender/bmesh/intern/bmesh_polygon.c	2013-09-19 01:21:34 UTC (rev 60230)
+++ trunk/blender/source/blender/bmesh/intern/bmesh_polygon.c	2013-09-19 07:40:41 UTC (rev 60231)
@@ -829,7 +829,9 @@
 			continue;
 		}
 
-		if (isect_point_tri_v2(pv1, v1, v2, v3) || isect_point_tri_v2(pv1, v3, v2, v1)) {
+		if (isect_point_tri_v2(pv1, v1, v2, v3) ||
+		    isect_point_tri_v2(pv1, v3, v2, v1))
+		{
 #if 0
 			if (isect_point_tri_v2(pv1, v1, v2, v3))
 				printf("%d in (%d, %d, %d)\n", v3i, i, v1i, v2i);
@@ -878,7 +880,7 @@
 		/* pick 0/1 based on best length */
 		/* XXX Can't only rely on such test, also must check we do not get (too much) degenerated triangles!!! */
 		i = (((len_squared_v3v3(larr[0]->v->co, larr[2]->v->co) >
-		     len_squared_v3v3(larr[1]->v->co, larr[3]->v->co) * bias)) != use_beauty);
+		       len_squared_v3v3(larr[1]->v->co, larr[3]->v->co) * bias)) != use_beauty);
 		i4 = (i + 3) % 4;
 		/* Check produced tris aren't too flat/narrow...
 		 * Probably not the best test, but is quite efficient and should at least avoid null-area faces! */
@@ -891,6 +893,7 @@
 #endif
 		if (cos1 < cos2)
 			cos1 = cos2;
+
 		if (cos1 > cos_threshold) {
 			if (cos1 > fabsf(cos_v3v3v3(larr[i]->v->co, larr[i4]->v->co, larr[i + 2]->v->co)) &&
 			    cos1 > fabsf(cos_v3v3v3(larr[i]->v->co, larr[i + 1]->v->co, larr[i + 2]->v->co)))
@@ -901,8 +904,10 @@
 		/* Last check we do not get overlapping triangles
 		 * (as much as possible, there are some cases with no good solution!) */
 		i4 = (i + 3) % 4;
-		if (!bm_face_goodline((float const (*)[2])projectverts, f, BM_elem_index_get(larr[i4]->v),
-		                      BM_elem_index_get(larr[i]->v), BM_elem_index_get(larr[i + 1]->v)))
+		if (!bm_face_goodline((float const (*)[2])projectverts, f,
+		                      BM_elem_index_get(larr[i4]->v),
+		                      BM_elem_index_get(larr[i]->v),
+		                      BM_elem_index_get(larr[i + 1]->v)))
 		{
 			i = !i;
 		}
@@ -912,13 +917,13 @@
 	}
 	else {
 		/* float angle, bestangle = 180.0f; */
-		float cos, bestcos = 1.0f;
-		int i, j, len;
+		const int len = f->len;
+		float cos, cos_best = 1.0f;
+		int i, j;
 
 		/* Compute cos of all corners! */
 		i = 0;
 		l_iter = l_first = BM_FACE_FIRST_LOOP(f);
-		len = l_iter->f->len;
 		do {
 			const BMVert *v1 = l_iter->prev->v;
 			const BMVert *v2 = l_iter->v;
@@ -937,7 +942,9 @@
 			const BMVert *v3 = l_iter->next->v;
 
 			if (bm_face_goodline((float const (*)[2])projectverts, f,
-			                     BM_elem_index_get(v1), BM_elem_index_get(v2), BM_elem_index_get(v3)))
+			                     BM_elem_index_get(v1),
+			                     BM_elem_index_get(v2),
+			                     BM_elem_index_get(v3)))
 			{
 				/* Compute highest cos (i.e. narrowest angle) of this tri. */
 				cos = max_fff(abscoss[i],
@@ -945,30 +952,30 @@
 				              fabsf(cos_v3v3v3(v3->co, v1->co, v2->co)));
 
 				/* Compare to prev best (i.e. lowest) cos. */
-				if (cos < bestcos) {
+				if (cos < cos_best) {
 					/* We must check this tri would not leave a (too much) degenerated remaining face! */
 					/* For now just assume if the average of cos of all
 					 * "remaining face"'s corners is below a given threshold, it's OK. */
-					float avgcos = fabsf(cos_v3v3v3(v1->co, v3->co, l_iter->next->next->v->co));
+					float cos_mean = fabsf(cos_v3v3v3(v1->co, v3->co, l_iter->next->next->v->co));
 					const int i_limit = (i - 1 + len) % len;
-					avgcos += fabsf(cos_v3v3v3(l_iter->prev->prev->v->co, v1->co, v3->co));
+					cos_mean += fabsf(cos_v3v3v3(l_iter->prev->prev->v->co, v1->co, v3->co));
 					j = (i + 2) % len;
 					do {
-						avgcos += abscoss[j];
+						cos_mean += abscoss[j];
 					} while ((j = (j + 1) % len) != i_limit);
-					avgcos /= len - 1;
+					cos_mean /= len - 1;
 
 					/* We need a best ear in any case... */
-					if (avgcos < cos_threshold || (!bestear && avgcos < 1.0f)) {
+					if (cos_mean < cos_threshold || (!bestear && cos_mean < 1.0f)) {
 						/* OKI, keep this ear (corner...) as a potential best one! */
 						bestear = l_iter;
-						bestcos = cos;
+						cos_best = cos;
 					}
 #if 0
 					else
-						printf("Had a nice tri (higest cos of %f, current bestcos is %f), "
+						printf("Had a nice tri (higest cos of %f, current cos_best is %f), "
 						       "but average cos of all \"remaining face\"'s corners is too high (%f)!\n",
-						       cos, bestcos, avgcos);
+						       cos, cos_best, cos_mean);
 #endif
 				}
 			}




More information about the Bf-blender-cvs mailing list