diff options
author | Sybren A. Stüvel <sybren@blender.org> | 2021-08-03 14:43:24 +0300 |
---|---|---|
committer | Sybren A. Stüvel <sybren@blender.org> | 2021-08-03 14:43:42 +0300 |
commit | 0342fb5d20cd13b495a7511ccfdfc3044d83cb04 (patch) | |
tree | b1ee5f64b75c5f071999496daa7e2e4819627d2c /source/blender/blenlib/tests | |
parent | dbd34a5acb3d0be2bdbad54a427153de49e47f8e (diff) |
Fix T90387: division by zero when trying to invert scale
Fix division by zero when `BKE_bone_parent_transform_invert()` inverts a
scale vector with zero components.
Zero values in the to-be-inverted vector are now simply skipped, i.e.
remain zero after inversion. This at least ensures that
`invert_v3_safe(invert_v3_safe(vector))` results in the same vector.
This commit does NOT fix the conceptual problem that an inversion of a
potentially non-invertible vector is relied upon. It just avoids the
division by zero.
Diffstat (limited to 'source/blender/blenlib/tests')
-rw-r--r-- | source/blender/blenlib/tests/BLI_math_vector_test.cc | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/source/blender/blenlib/tests/BLI_math_vector_test.cc b/source/blender/blenlib/tests/BLI_math_vector_test.cc index 7e75a521d4c..955f02b8065 100644 --- a/source/blender/blenlib/tests/BLI_math_vector_test.cc +++ b/source/blender/blenlib/tests/BLI_math_vector_test.cc @@ -45,3 +45,21 @@ TEST(math_vector, ClampVecWithVecs) EXPECT_FLOAT_EQ(1.0f, c[0]); EXPECT_FLOAT_EQ(3.0f, c[1]); } + +TEST(math_vector, test_invert_v3_safe) +{ + float v3_with_zeroes[3] = {0.0f, 2.0f, 3.0f}; + invert_v3_safe(v3_with_zeroes); + EXPECT_FLOAT_EQ(0.0f, v3_with_zeroes[0]); + EXPECT_FLOAT_EQ(0.5f, v3_with_zeroes[1]); + EXPECT_FLOAT_EQ(0.33333333333f, v3_with_zeroes[2]); + + float v3_without_zeroes[3] = {1.0f, 2.0f, 3.0f}; + float inverted_unsafe[3] = {1.0f, 2.0f, 3.0f}; + invert_v3_safe(v3_without_zeroes); + invert_v3(inverted_unsafe); + + EXPECT_FLOAT_EQ(inverted_unsafe[0], v3_without_zeroes[0]); + EXPECT_FLOAT_EQ(inverted_unsafe[1], v3_without_zeroes[1]); + EXPECT_FLOAT_EQ(inverted_unsafe[2], v3_without_zeroes[2]); +} |