[Bf-blender-cvs] [880f4fb] blender-v2.73-release: cleanup: use cross_tri_v2 when area isn't needed.

Campbell Barton noreply at git.blender.org
Tue Jan 6 10:44:35 CET 2015


Commit: 880f4fbc3805308d1e56509abc14ab8b819cf4c1
Author: Campbell Barton
Date:   Thu Dec 25 21:14:13 2014 +1100
Branches: blender-v2.73-release
https://developer.blender.org/rB880f4fbc3805308d1e56509abc14ab8b819cf4c1

cleanup: use cross_tri_v2 when area isn't needed.

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

M	source/blender/blenlib/intern/math_geom.c
M	source/blender/blenlib/intern/polyfill2d_beautify.c
M	source/blender/bmesh/tools/bmesh_beautify.c

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

diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c
index 42aa24d..bcf2147 100644
--- a/source/blender/blenlib/intern/math_geom.c
+++ b/source/blender/blenlib/intern/math_geom.c
@@ -2350,15 +2350,15 @@ bool barycentric_coords_v2(const float v1[2], const float v2[2], const float v3[
 }
 
 /**
- * \note: using #area_tri_signed_v2 means locations outside the triangle are correctly weighted
+ * \note: using #cross_tri_v2 means locations outside the triangle are correctly weighted
  */
 void barycentric_weights_v2(const float v1[2], const float v2[2], const float v3[2], const float co[2], float w[3])
 {
 	float wtot;
 
-	w[0] = area_tri_signed_v2(v2, v3, co);
-	w[1] = area_tri_signed_v2(v3, v1, co);
-	w[2] = area_tri_signed_v2(v1, v2, co);
+	w[0] = cross_tri_v2(v2, v3, co);
+	w[1] = cross_tri_v2(v3, v1, co);
+	w[2] = cross_tri_v2(v1, v2, co);
 	wtot = w[0] + w[1] + w[2];
 
 	if (wtot != 0.0f) {
@@ -2377,9 +2377,9 @@ void barycentric_weights_v2_persp(const float v1[4], const float v2[4], const fl
 {
 	float wtot;
 
-	w[0] = area_tri_signed_v2(v2, v3, co) / v1[3];
-	w[1] = area_tri_signed_v2(v3, v1, co) / v2[3];
-	w[2] = area_tri_signed_v2(v1, v2, co) / v3[3];
+	w[0] = cross_tri_v2(v2, v3, co) / v1[3];
+	w[1] = cross_tri_v2(v3, v1, co) / v2[3];
+	w[2] = cross_tri_v2(v1, v2, co) / v3[3];
 	wtot = w[0] + w[1] + w[2];
 
 	if (wtot != 0.0f) {
diff --git a/source/blender/blenlib/intern/polyfill2d_beautify.c b/source/blender/blenlib/intern/polyfill2d_beautify.c
index c4e333d..b8922ef 100644
--- a/source/blender/blenlib/intern/polyfill2d_beautify.c
+++ b/source/blender/blenlib/intern/polyfill2d_beautify.c
@@ -179,8 +179,6 @@ static float quad_v2_rotate_beauty_calc(
 
 			float len_12, len_23, len_34, len_41, len_24, len_13;
 
-#define AREA_FROM_CROSS(val) (fabsf(val) / 2.0f)
-
 			/* edges around the quad */
 			len_12 = len_v2v2(v1, v2);
 			len_23 = len_v2v2(v2, v3);
@@ -190,22 +188,23 @@ static float quad_v2_rotate_beauty_calc(
 			len_13 = len_v2v2(v1, v3);
 			len_24 = len_v2v2(v2, v4);
 
+			/* note, area is in fact (area * 2),
+			 * but in this case its OK, since we're comparing ratios */
+
 			/* edge (2-4), current state */
-			area_a = AREA_FROM_CROSS(area_2x_234);
-			area_b = AREA_FROM_CROSS(area_2x_241);
+			area_a = fabsf(area_2x_234);
+			area_b = fabsf(area_2x_241);
 			prim_a = len_23 + len_34 + len_24;
-			prim_b = len_24 + len_41 + len_12;
+			prim_b = len_41 + len_12 + len_24;
 			fac_24 = (area_a / prim_a) + (area_b / prim_b);
 
 			/* edge (1-3), new state */
-			area_a = AREA_FROM_CROSS(area_2x_123);
-			area_b = AREA_FROM_CROSS(area_2x_134);
+			area_a = fabsf(area_2x_123);
+			area_b = fabsf(area_2x_134);
 			prim_a = len_12 + len_23 + len_13;
 			prim_b = len_34 + len_41 + len_13;
 			fac_13 = (area_a / prim_a) + (area_b / prim_b);
 
-#undef AREA_FROM_CROSS
-
 			/* negative number if (1-3) is an improved state */
 			return fac_24 - fac_13;
 		}
diff --git a/source/blender/bmesh/tools/bmesh_beautify.c b/source/blender/bmesh/tools/bmesh_beautify.c
index 1c6dc6f..6fb7f7c 100644
--- a/source/blender/bmesh/tools/bmesh_beautify.c
+++ b/source/blender/bmesh/tools/bmesh_beautify.c
@@ -187,8 +187,8 @@ static float bm_edge_calc_rotate_beauty__area(
 			 * into a different degenerate shape or flipping the face */
 			float area_a, area_b;
 
-			area_a = area_tri_signed_v2(v1_xy, v2_xy, v3_xy);
-			area_b = area_tri_signed_v2(v1_xy, v3_xy, v4_xy);
+			area_a = cross_tri_v2(v1_xy, v2_xy, v3_xy);
+			area_b = cross_tri_v2(v1_xy, v3_xy, v4_xy);
 
 			if ((fabsf(area_a) <= FLT_EPSILON) || (fabsf(area_b) <= FLT_EPSILON)) {
 				/* one of the new rotations is degenerate */
@@ -219,16 +219,19 @@ static float bm_edge_calc_rotate_beauty__area(
 			len_13 = len_v2v2(v1_xy, v3_xy);
 			len_24 = len_v2v2(v2_xy, v4_xy);
 
+			/* note, area is in fact (area * 2),
+			 * but in this case its OK, since we're comparing ratios */
+
 			/* edge (2-4), current state */
-			area_a = area_tri_v2(v2_xy, v3_xy, v4_xy);
-			area_b = area_tri_v2(v2_xy, v4_xy, v1_xy);
+			area_a = fabsf(cross_tri_v2(v2_xy, v3_xy, v4_xy));
+			area_b = fabsf(cross_tri_v2(v2_xy, v4_xy, v1_xy));
 			prim_a = len_23 + len_34 + len_24;
-			prim_b = len_24 + len_41 + len_12;
+			prim_b = len_41 + len_12 + len_24;
 			fac_24 = (area_a / prim_a) + (area_b / prim_b);
 
 			/* edge (1-3), new state */
-			area_a = area_tri_v2(v1_xy, v2_xy, v3_xy);
-			area_b = area_tri_v2(v1_xy, v3_xy, v4_xy);
+			area_a = fabsf(cross_tri_v2(v1_xy, v2_xy, v3_xy));
+			area_b = fabsf(cross_tri_v2(v1_xy, v3_xy, v4_xy));
 			prim_a = len_12 + len_23 + len_13;
 			prim_b = len_34 + len_41 + len_13;
 			fac_13 = (area_a / prim_a) + (area_b / prim_b);




More information about the Bf-blender-cvs mailing list