Correct bad mistake in own recent to commit to angle calculation

This commit is contained in:
Campbell Barton 2014-01-14 13:47:24 +11:00
parent 20cea92db1
commit aa986c3f3d
Notes: blender-bot 2023-02-14 11:20:30 +01:00
Referenced by issue #38207, UI Tab bugs
Referenced by issue #38208, blurry tooltips
1 changed files with 10 additions and 14 deletions

View File

@ -292,39 +292,35 @@ 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 (len_sq >= 0.0f) {
return 2.0f * saasin(sqrtf(len_sq) / 2.0f);
if (dot_v3v3(v1, v2) >= 0.0f) {
return 2.0f * saasin(len_v3v3(v1, v2) / 2.0f);
}
else {
float vec[3];
negate_v3_v3(vec, v2);
return (float)M_PI - 2.0f * saasin(len_v3v3(vec, v1) / 2.0f);
float v2_n[3];
negate_v3_v3(v2_n, v2);
return (float)M_PI - 2.0f * saasin(len_v3v3(v1, v2_n) / 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 (len_sq >= 0.0f) {
return 2.0f * saasin(sqrtf(len_sq) / 2.0f);
if (dot_v2v2(v1, v2) >= 0.0f) {
return 2.0f * saasin(len_v2v2(v1, v2) / 2.0f);
}
else {
float vec[2];
negate_v2_v2(vec, v2);
return (float)M_PI - 2.0f * saasin(len_v2v2(vec, v1) / 2.0f);
float v2_n[2];
negate_v2_v2(v2_n, v2);
return (float)M_PI - 2.0f * saasin(len_v2v2(v1, v2_n) / 2.0f);
}
}