Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenlib/tests/BLI_math_rotation_test.cc
| /* SPDX-License-Identifier: Apache-2.0 */ | /* SPDX-License-Identifier: Apache-2.0 */ | ||||
| #include "testing/testing.h" | #include "testing/testing.h" | ||||
| #include "BLI_math_base.h" | #include "BLI_math_base.h" | ||||
| #include "BLI_math_rotation.h" | #include "BLI_math_rotation.h" | ||||
| #include "BLI_math_rotation.hh" | |||||
| #include "BLI_math_vector.hh" | |||||
| #include <cmath> | #include <cmath> | ||||
| /* Test that quaternion converts to itself via matrix. */ | /* Test that quaternion converts to itself via matrix. */ | ||||
| static void test_quat_to_mat_to_quat(float w, float x, float y, float z) | static void test_quat_to_mat_to_quat(float w, float x, float y, float z) | ||||
| { | { | ||||
| float in_quat[4] = {w, x, y, z}; | float in_quat[4] = {w, x, y, z}; | ||||
| float norm_quat[4], matrix[3][3], out_quat[4]; | float norm_quat[4], matrix[3][3], out_quat[4]; | ||||
| ▲ Show 20 Lines • Show All 127 Lines • ▼ Show 20 Lines | TEST(math_rotation, quat_split_swing_and_twist_negative) | ||||
| float swing[4], twist[4]; | float swing[4], twist[4]; | ||||
| float twist_angle = quat_split_swing_and_twist(input, 1, swing, twist); | float twist_angle = quat_split_swing_and_twist(input, 1, swing, twist); | ||||
| EXPECT_NEAR(twist_angle, -M_PI * 2 / 3, FLT_EPSILON); | EXPECT_NEAR(twist_angle, -M_PI * 2 / 3, FLT_EPSILON); | ||||
| EXPECT_V4_NEAR(swing, expected_swing, FLT_EPSILON); | EXPECT_V4_NEAR(swing, expected_swing, FLT_EPSILON); | ||||
| EXPECT_V4_NEAR(twist, expected_twist, FLT_EPSILON); | EXPECT_V4_NEAR(twist, expected_twist, FLT_EPSILON); | ||||
| } | } | ||||
| namespace blender::math::tests { | |||||
| TEST(math_rotation, RotateDirectionAroundAxis) | |||||
| { | |||||
| const float3 a = rotate_direction_around_axis({1, 0, 0}, {0, 0, 1}, M_PI_2); | |||||
| EXPECT_NEAR(a.x, 0.0f, FLT_EPSILON); | |||||
| EXPECT_NEAR(a.y, 1.0f, FLT_EPSILON); | |||||
| EXPECT_NEAR(a.z, 0.0f, FLT_EPSILON); | |||||
| const float3 b = rotate_direction_around_axis({1, 0, 0}, {0, 0, 1}, M_PI); | |||||
| EXPECT_NEAR(b.x, -1.0f, FLT_EPSILON); | |||||
| EXPECT_NEAR(b.y, 0.0f, FLT_EPSILON); | |||||
| EXPECT_NEAR(b.z, 0.0f, FLT_EPSILON); | |||||
| const float3 c = rotate_direction_around_axis({0, 0, 1}, {0, 0, 1}, 0.0f); | |||||
| EXPECT_NEAR(c.x, 0.0f, FLT_EPSILON); | |||||
| EXPECT_NEAR(c.y, 0.0f, FLT_EPSILON); | |||||
| EXPECT_NEAR(c.z, 1.0f, FLT_EPSILON); | |||||
| } | |||||
| } // namespace blender::math::tests | |||||