File size: 1,889 Bytes
985c397 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | #include <gtest/gtest.h>
#include <Base/Exception.h>
#include <Base/Matrix.h>
#include <Base/Rotation.h>
// NOLINTBEGIN(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers)
TEST(Rotation, TestNonUniformScaleLeft)
{
Base::Rotation rot;
rot.setYawPitchRoll(45.0, 0.0, 0.0);
Base::Matrix4D mat;
rot.getValue(mat);
Base::Matrix4D scale;
scale.scale(1.0, std::sqrt(3.0), 1.0);
Base::Rotation scaled_rot(scale * mat);
rot.setYawPitchRoll(60.0, 0.0, 0.0);
EXPECT_EQ(scaled_rot.isSame(rot, 1.0e-7), true);
EXPECT_EQ(rot.isSame(scaled_rot, 1.0e-7), true);
}
TEST(Rotation, TestNonUniformScaleRight)
{
Base::Rotation rot;
rot.setYawPitchRoll(20.0, 0.0, 0.0);
Base::Matrix4D mat;
rot.getValue(mat);
Base::Matrix4D scale;
scale.scale(2.0, 3.0, 4.0);
Base::Rotation scaled_rot(mat * scale);
EXPECT_EQ(scaled_rot.isSame(rot, 1.0e-7), true);
EXPECT_EQ(rot.isSame(scaled_rot, 1.0e-7), true);
}
TEST(Rotation, TestUniformScaleGT1)
{
Base::Rotation rot;
rot.setYawPitchRoll(20.0, 0.0, 0.0);
Base::Matrix4D mat;
rot.getValue(mat);
Base::Matrix4D scale;
scale.scale(3.0, 3.0, 3.0);
Base::Rotation scaled_rot(mat * scale);
EXPECT_EQ(scaled_rot.isSame(rot, 1.0e-7), true);
EXPECT_EQ(rot.isSame(scaled_rot, 1.0e-7), true);
}
TEST(Rotation, TestUniformScaleLT1)
{
Base::Matrix4D mat;
mat.scale(0.5);
Base::Rotation scaled_rot(mat);
EXPECT_EQ(scaled_rot.isSame(scaled_rot, 1.0e-7), true);
}
TEST(Rotation, TestRotationDecompose)
{
Base::Matrix4D mat;
mat.setCol(0, Base::Vector3d {1, 0, 0});
mat.setCol(1, Base::Vector3d {1, 1, 0});
mat.setCol(2, Base::Vector3d {0, 0, 1});
// decompose rotation part
EXPECT_TRUE(Base::Rotation {mat}.isIdentity());
}
// NOLINTEND(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers)
|