[Bf-blender-cvs] [8cb9b42] master: Math Lib: minor optimization for angle functions
Campbell Barton
noreply at git.blender.org
Mon Jan 13 23:52:05 CET 2014
Commit: 8cb9b42c9c3ec09e78d59ac80fd7db9d50342170
Author: Campbell Barton
Date: Tue Jan 14 09:14:34 2014 +1100
https://developer.blender.org/rB8cb9b42c9c3ec09e78d59ac80fd7db9d50342170
Math Lib: minor optimization for angle functions
===================================================================
M source/blender/blenlib/intern/math_vector.c
===================================================================
diff --git a/source/blender/blenlib/intern/math_vector.c b/source/blender/blenlib/intern/math_vector.c
index 48134cb..6d3c74a 100644
--- a/source/blender/blenlib/intern/math_vector.c
+++ b/source/blender/blenlib/intern/math_vector.c
@@ -292,41 +292,40 @@ float angle_signed_v2v2(const float v1[2], const float v2[2])
float angle_normalized_v3v3(const float v1[3], const float v2[3])
{
+ const float len_sq = dot_v3v3(v1, v2);
+
/* double check they are normalized */
BLI_ASSERT_UNIT_V3(v1);
BLI_ASSERT_UNIT_V3(v2);
/* this is the same as acos(dot_v3v3(v1, v2)), but more accurate */
- if (dot_v3v3(v1, v2) < 0.0f) {
+ if (len_sq >= 0.0f) {
+ return 2.0f * saasin(sqrtf(len_sq) / 2.0f);
+ }
+ else {
float vec[3];
-
- vec[0] = -v2[0];
- vec[1] = -v2[1];
- vec[2] = -v2[2];
-
- return (float)M_PI - 2.0f * (float)saasin(len_v3v3(vec, v1) / 2.0f);
+ negate_v3_v3(vec, v2);
+ return (float)M_PI - 2.0f * saasin(len_v3v3(vec, v1) / 2.0f);
}
- else
- return 2.0f * (float)saasin(len_v3v3(v2, v1) / 2.0f);
}
float angle_normalized_v2v2(const float v1[2], const float v2[2])
{
+ const float len_sq = dot_v2v2(v1, v2);
+
/* double check they are normalized */
BLI_ASSERT_UNIT_V2(v1);
BLI_ASSERT_UNIT_V2(v2);
/* this is the same as acos(dot_v3v3(v1, v2)), but more accurate */
- if (dot_v2v2(v1, v2) < 0.0f) {
+ if (len_sq >= 0.0f) {
+ return 2.0f * saasin(sqrtf(len_sq) / 2.0f);
+ }
+ else {
float vec[2];
-
- vec[0] = -v2[0];
- vec[1] = -v2[1];
-
+ negate_v2_v2(vec, v2);
return (float)M_PI - 2.0f * saasin(len_v2v2(vec, v1) / 2.0f);
}
- else
- return 2.0f * (float)saasin(len_v2v2(v2, v1) / 2.0f);
}
/**
More information about the Bf-blender-cvs
mailing list