|
| 1 | +#include "numerical/math/Geometry3D.hpp" |
| 2 | +#include "numerical/math/Tolerance.hpp" |
| 3 | +#include <gtest/gtest.h> |
| 4 | +#include <numbers> |
| 5 | + |
| 6 | +namespace |
| 7 | +{ |
| 8 | + class Geometry3DTest : public ::testing::Test |
| 9 | + { |
| 10 | + protected: |
| 11 | + static void ExpectNear(const math::Matrix3<float>& actual, const math::Matrix3<float>& expected) |
| 12 | + { |
| 13 | + for (std::size_t i = 0; i < 3; ++i) |
| 14 | + for (std::size_t j = 0; j < 3; ++j) |
| 15 | + EXPECT_NEAR(actual.at(i, j), expected.at(i, j), math::Tolerance<float>()); |
| 16 | + } |
| 17 | + |
| 18 | + float angle{ 0.7f }; |
| 19 | + }; |
| 20 | +} |
| 21 | + |
| 22 | +TEST_F(Geometry3DTest, ElementaryRotationsMatchTheRotationAboutTheirAxis) |
| 23 | +{ |
| 24 | + ExpectNear(math::RotationX(angle), math::RotationAboutAxis(math::Vector3<float>{ 1.0f, 0.0f, 0.0f }, angle)); |
| 25 | + ExpectNear(math::RotationY(angle), math::RotationAboutAxis(math::Vector3<float>{ 0.0f, 1.0f, 0.0f }, angle)); |
| 26 | + ExpectNear(math::RotationZ(angle), math::RotationAboutAxis(math::Vector3<float>{ 0.0f, 0.0f, 1.0f }, angle)); |
| 27 | +} |
| 28 | + |
| 29 | +TEST_F(Geometry3DTest, RotationZTurnsTheXAxisTowardsTheYAxis) |
| 30 | +{ |
| 31 | + const auto turned = math::RotationZ(std::numbers::pi_v<float> / 2.0f) * math::Vector3<float>{ 1.0f, 0.0f, 0.0f }; |
| 32 | + |
| 33 | + EXPECT_NEAR(turned.at(0, 0), 0.0f, math::Tolerance<float>()); |
| 34 | + EXPECT_NEAR(turned.at(1, 0), 1.0f, math::Tolerance<float>()); |
| 35 | + EXPECT_NEAR(turned.at(2, 0), 0.0f, math::Tolerance<float>()); |
| 36 | +} |
0 commit comments