[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [53629] trunk/blender/source/blender/ blenlib: add area_poly_v3_max() for use with area_poly_v3

Campbell Barton ideasman42 at gmail.com
Mon Jan 7 13:16:15 CET 2013


Revision: 53629
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=53629
Author:   campbellbarton
Date:     2013-01-07 12:16:11 +0000 (Mon, 07 Jan 2013)
Log Message:
-----------
add area_poly_v3_max() for use with area_poly_v3

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

Modified: trunk/blender/source/blender/blenlib/BLI_math_geom.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_math_geom.h	2013-01-07 11:52:09 UTC (rev 53628)
+++ trunk/blender/source/blender/blenlib/BLI_math_geom.h	2013-01-07 12:16:11 UTC (rev 53629)
@@ -260,7 +260,12 @@
 float form_factor_hemi_poly(float p[3], float n[3],
                             float v1[3], float v2[3], float v3[3], float v4[3]);
 
-void axis_dominant_v3(int *axis_a, int *axis_b, const float axis[3]);
+void  axis_dominant_v3(int *r_axis_a, int *r_axis_b, const float axis[3]);
+float axis_dominant_v3_max(int *r_axis_a, int *r_axis_b, const float axis[3])
+#ifdef __GNUC__
+__attribute__((warn_unused_result))
+#endif
+;
 
 MINLINE int max_axis_v3(const float vec[3]);
 MINLINE int min_axis_v3(const float vec[3]);

Modified: trunk/blender/source/blender/blenlib/intern/math_geom.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/math_geom.c	2013-01-07 11:52:09 UTC (rev 53628)
+++ trunk/blender/source/blender/blenlib/intern/math_geom.c	2013-01-07 12:16:11 UTC (rev 53629)
@@ -131,30 +131,19 @@
 
 float area_poly_v3(int nr, float verts[][3], const float normal[3])
 {
-	float x, y, z, area, max;
-	float *cur, *prev;
-	int a, px = 0, py = 1;
+	int a, px, py;
+	const float max = axis_dominant_v3_max(&px, &py, normal);
+	float area;
+	float *co_curr, *co_prev;
 
-	/* first: find dominant axis: 0==X, 1==Y, 2==Z
-	 * don't use 'axis_dominant_v3()' because we need max axis too */
-	x = fabsf(normal[0]);
-	y = fabsf(normal[1]);
-	z = fabsf(normal[2]);
-	max = max_fff(x, y, z);
-	if (max == y) py = 2;
-	else if (max == x) {
-		px = 1;
-		py = 2;
-	}
-
 	/* The Trapezium Area Rule */
-	prev = verts[nr - 1];
-	cur = verts[0];
-	area = 0;
+	co_prev = verts[nr - 1];
+	co_curr = verts[0];
+	area = 0.0f;
 	for (a = 0; a < nr; a++) {
-		area += (cur[px] - prev[px]) * (cur[py] + prev[py]);
-		prev = verts[a];
-		cur = verts[a + 1];
+		area += (co_curr[px] - co_prev[px]) * (co_curr[py] + co_prev[py]);
+		co_prev = verts[a];
+		co_curr = verts[a + 1];
 	}
 
 	return fabsf(0.5f * area / max);
@@ -1952,17 +1941,29 @@
 /****************************** Interpolation ********************************/
 
 /* get the 2 dominant axis values, 0==X, 1==Y, 2==Z */
-void axis_dominant_v3(int *axis_a, int *axis_b, const float axis[3])
+void axis_dominant_v3(int *r_axis_a, int *r_axis_b, const float axis[3])
 {
 	const float xn = fabsf(axis[0]);
 	const float yn = fabsf(axis[1]);
 	const float zn = fabsf(axis[2]);
 
-	if      (zn >= xn && zn >= yn) { *axis_a = 0; *axis_b = 1; }
-	else if (yn >= xn && yn >= zn) { *axis_a = 0; *axis_b = 2; }
-	else                           { *axis_a = 1; *axis_b = 2; }
+	if      (zn >= xn && zn >= yn) { *r_axis_a = 0; *r_axis_b = 1; }
+	else if (yn >= xn && yn >= zn) { *r_axis_a = 0; *r_axis_b = 2; }
+	else                           { *r_axis_a = 1; *r_axis_b = 2; }
 }
 
+/* same as axis_dominant_v3 but return the max value */
+float axis_dominant_v3_max(int *r_axis_a, int *r_axis_b, const float axis[3])
+{
+	const float xn = fabsf(axis[0]);
+	const float yn = fabsf(axis[1]);
+	const float zn = fabsf(axis[2]);
+
+	if      (zn >= xn && zn >= yn) { *r_axis_a = 0; *r_axis_b = 1; return zn; }
+	else if (yn >= xn && yn >= zn) { *r_axis_a = 0; *r_axis_b = 2; return yn; }
+	else                           { *r_axis_a = 1; *r_axis_b = 2; return xn; }
+}
+
 static float tri_signed_area(const float v1[3], const float v2[3], const float v3[3], const int i, const int j)
 {
 	return 0.5f * ((v1[i] - v2[i]) * (v2[j] - v3[j]) + (v1[j] - v2[j]) * (v3[i] - v2[i]));




More information about the Bf-blender-cvs mailing list