[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [52274] trunk/blender/source/blender/ blenlib/intern/math_vector.c: BLI_assert() when math functions that require are normalize vector are called without one .

Campbell Barton ideasman42 at gmail.com
Fri Nov 16 13:41:42 CET 2012


Revision: 52274
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=52274
Author:   campbellbarton
Date:     2012-11-16 12:41:40 +0000 (Fri, 16 Nov 2012)
Log Message:
-----------
BLI_assert() when math functions that require are normalize vector are called without one.

Modified Paths:
--------------
    trunk/blender/source/blender/blenlib/intern/math_vector.c

Modified: trunk/blender/source/blender/blenlib/intern/math_vector.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/math_vector.c	2012-11-16 12:33:24 UTC (rev 52273)
+++ trunk/blender/source/blender/blenlib/intern/math_vector.c	2012-11-16 12:41:40 UTC (rev 52274)
@@ -208,6 +208,13 @@
 
 float angle_normalized_v3v3(const float v1[3], const float v2[3])
 {
+	/* double check they are normalized */
+#ifdef DEBUG
+	float test;
+	BLI_assert(fabsf((test = len_squared_v3(v1)) - 1.0f) < 0.0001f || fabsf(test) < 0.0001f);
+	BLI_assert(fabsf((test = len_squared_v3(v2)) - 1.0f) < 0.0001f || fabsf(test) < 0.0001f);
+#endif
+
 	/* this is the same as acos(dot_v3v3(v1, v2)), but more accurate */
 	if (dot_v3v3(v1, v2) < 0.0f) {
 		float vec[3];
@@ -224,6 +231,13 @@
 
 float angle_normalized_v2v2(const float v1[2], const float v2[2])
 {
+	/* double check they are normalized */
+#ifdef DEBUG
+	float test;
+	BLI_assert(fabsf((test = len_squared_v2(v1)) - 1.0f) < 0.0001f || fabsf(test) < 0.0001f);
+	BLI_assert(fabsf((test = len_squared_v2(v2)) - 1.0f) < 0.0001f || fabsf(test) < 0.0001f);
+#endif
+
 	/* this is the same as acos(dot_v3v3(v1, v2)), but more accurate */
 	if (dot_v2v2(v1, v2) < 0.0f) {
 		float vec[2];
@@ -408,6 +422,12 @@
 	const float costheta = cos(angle);
 	const float sintheta = sin(angle);
 
+	/* double check they are normalized */
+#ifdef DEBUG
+	float test;
+	BLI_assert(fabsf((test = len_squared_v3(axis)) - 1.0f) < 0.0001f || fabsf(test) < 0.0001f);
+#endif
+
 	r[0] = ((costheta + (1 - costheta) * axis[0] * axis[0]) * p[0]) +
 	       (((1 - costheta) * axis[0] * axis[1] - axis[2] * sintheta) * p[1]) +
 	       (((1 - costheta) * axis[0] * axis[2] + axis[1] * sintheta) * p[2]);




More information about the Bf-blender-cvs mailing list