[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [45703] trunk/blender/source/blender: inline function for "Newell's Method" used for normal calc.

Campbell Barton ideasman42 at gmail.com
Mon Apr 16 18:49:37 CEST 2012


Revision: 45703
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=45703
Author:   campbellbarton
Date:     2012-04-16 16:49:37 +0000 (Mon, 16 Apr 2012)
Log Message:
-----------
inline function for "Newell's Method" used for normal calc.

Modified Paths:
--------------
    trunk/blender/source/blender/blenlib/BLI_math_vector.h
    trunk/blender/source/blender/blenlib/intern/math_base_inline.c
    trunk/blender/source/blender/blenlib/intern/math_vector_inline.c
    trunk/blender/source/blender/blenlib/intern/scanfill.c
    trunk/blender/source/blender/bmesh/intern/bmesh_polygon.c

Modified: trunk/blender/source/blender/blenlib/BLI_math_vector.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_math_vector.h	2012-04-16 16:26:47 UTC (rev 45702)
+++ trunk/blender/source/blender/blenlib/BLI_math_vector.h	2012-04-16 16:49:37 UTC (rev 45703)
@@ -124,6 +124,8 @@
 MINLINE float cross_v2v2(const float a[2], const float b[2]);
 MINLINE void cross_v3_v3v3(float r[3], const float a[3], const float b[3]);
 
+MINLINE void add_newell_cross_v3_v3v3(float n[3], const float v_prev[3], const float v_curr[3]);
+
 MINLINE void star_m3_v3(float rmat[3][3],float a[3]);
 
 /*********************************** Length **********************************/

Modified: trunk/blender/source/blender/blenlib/intern/math_base_inline.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/math_base_inline.c	2012-04-16 16:26:47 UTC (rev 45702)
+++ trunk/blender/source/blender/blenlib/intern/math_base_inline.c	2012-04-16 16:49:37 UTC (rev 45703)
@@ -92,7 +92,7 @@
 MINLINE float sasqrtf(float fac)
 {
 	if (fac <= 0.0f) return 0.0f;
-	return (float)sqrtf(fac);
+	return sqrtf(fac);
 }
 
 MINLINE float interpf(float target, float origin, float fac)

Modified: trunk/blender/source/blender/blenlib/intern/math_vector_inline.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/math_vector_inline.c	2012-04-16 16:26:47 UTC (rev 45702)
+++ trunk/blender/source/blender/blenlib/intern/math_vector_inline.c	2012-04-16 16:49:37 UTC (rev 45703)
@@ -480,6 +480,17 @@
 	r[2] = a[0] * b[1] - a[1] * b[0];
 }
 
+/* Newell's Method */
+/* excuse this fairly spesific function,
+ * its used for polygon normals all over the place
+ * could use a better name */
+MINLINE void add_newell_cross_v3_v3v3(float n[3], const float v_prev[3], const float v_curr[3])
+{
+	n[0] += (v_prev[1] - v_curr[1]) * (v_prev[2] + v_curr[2]);
+	n[1] += (v_prev[2] - v_curr[2]) * (v_prev[0] + v_curr[0]);
+	n[2] += (v_prev[0] - v_curr[0]) * (v_prev[1] + v_curr[1]);
+}
+
 MINLINE void star_m3_v3(float rmat[][3], float a[3])
 {
 	rmat[0][0] = rmat[1][1] = rmat[2][2] = 0.0;
@@ -505,7 +516,7 @@
 
 MINLINE float len_v2(const float v[2])
 {
-	return (float)sqrtf(v[0] * v[0] + v[1] * v[1]);
+	return sqrtf(v[0] * v[0] + v[1] * v[1]);
 }
 
 MINLINE float len_v2v2(const float v1[2], const float v2[2])
@@ -514,7 +525,7 @@
 
 	x = v1[0] - v2[0];
 	y = v1[1] - v2[1];
-	return (float)sqrtf(x * x + y * y);
+	return sqrtf(x * x + y * y);
 }
 
 MINLINE float len_v3(const float a[3])

Modified: trunk/blender/source/blender/blenlib/intern/scanfill.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/scanfill.c	2012-04-16 16:26:47 UTC (rev 45702)
+++ trunk/blender/source/blender/blenlib/intern/scanfill.c	2012-04-16 16:49:37 UTC (rev 45703)
@@ -864,9 +864,7 @@
 
 		for (eve = sf_ctx->fillvertbase.first; eve; eve = eve->next) {
 			if (LIKELY(!compare_v3v3(v_prev, eve->co, COMPLIMIT))) {
-				n[0] += (v_prev[1] - eve->co[1]) * (v_prev[2] + eve->co[2]);
-				n[1] += (v_prev[2] - eve->co[2]) * (v_prev[0] + eve->co[0]);
-				n[2] += (v_prev[0] - eve->co[0]) * (v_prev[1] + eve->co[1]);
+				add_newell_cross_v3_v3v3(n, v_prev, eve->co);
 			}
 			v_prev = eve->co;
 		}

Modified: trunk/blender/source/blender/bmesh/intern/bmesh_polygon.c
===================================================================
--- trunk/blender/source/blender/bmesh/intern/bmesh_polygon.c	2012-04-16 16:26:47 UTC (rev 45702)
+++ trunk/blender/source/blender/bmesh/intern/bmesh_polygon.c	2012-04-16 16:49:37 UTC (rev 45703)
@@ -84,9 +84,7 @@
 
 	/* Newell's Method */
 	for (i = 0; i < nverts; v_prev = v_curr, v_curr = verts[++i]) {
-		n[0] += (v_prev[1] - v_curr[1]) * (v_prev[2] + v_curr[2]);
-		n[1] += (v_prev[2] - v_curr[2]) * (v_prev[0] + v_curr[0]);
-		n[2] += (v_prev[0] - v_curr[0]) * (v_prev[1] + v_curr[1]);
+		add_newell_cross_v3_v3v3(n, v_prev, v_curr);
 	}
 
 	if (UNLIKELY(normalize_v3_v3(normal, n) == 0.0f)) {
@@ -109,9 +107,7 @@
 
 	/* Newell's Method */
 	do {
-		n[0] += (v_prev[1] - v_curr[1]) * (v_prev[2] + v_curr[2]);
-		n[1] += (v_prev[2] - v_curr[2]) * (v_prev[0] + v_curr[0]);
-		n[2] += (v_prev[0] - v_curr[0]) * (v_prev[1] + v_curr[1]);
+		add_newell_cross_v3_v3v3(n, v_prev, v_curr);
 
 		l_iter = l_iter->next;
 		v_prev = v_curr;
@@ -142,9 +138,7 @@
 
 	/* Newell's Method */
 	do {
-		n[0] += (v_prev[1] - v_curr[1]) * (v_prev[2] + v_curr[2]);
-		n[1] += (v_prev[2] - v_curr[2]) * (v_prev[0] + v_curr[0]);
-		n[2] += (v_prev[0] - v_curr[0]) * (v_prev[1] + v_curr[1]);
+		add_newell_cross_v3_v3v3(n, v_prev, v_curr);
 
 		l_iter = l_iter->next;
 		v_prev = v_curr;




More information about the Bf-blender-cvs mailing list