File size: 4,437 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 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | #include <gtest/gtest.h>
#include <Base/CoordinateSystem.h>
#include <Base/Exception.h>
#include <Base/Placement.h>
// NOLINTBEGIN
TEST(CoordinateSystem, TestDefault)
{
Base::CoordinateSystem cs;
EXPECT_EQ(cs.getPosition(), Base::Vector3d(0, 0, 0));
EXPECT_EQ(cs.getXDirection(), Base::Vector3d(1, 0, 0));
EXPECT_EQ(cs.getYDirection(), Base::Vector3d(0, 1, 0));
EXPECT_EQ(cs.getZDirection(), Base::Vector3d(0, 0, 1));
}
TEST(CoordinateSystem, TestSetAxisFailure)
{
Base::CoordinateSystem cs;
EXPECT_THROW(cs.setAxes(Base::Vector3d(0, 0, 1), Base::Vector3d(0, 0, 1)), Base::ValueError);
}
TEST(CoordinateSystem, TestSetAxis)
{
Base::CoordinateSystem cs;
Base::Axis axis;
axis.setBase(Base::Vector3d(1, 2, 3));
axis.setDirection(Base::Vector3d(1, 1, 1));
cs.setAxes(axis, Base::Vector3d(0, 0, 1));
EXPECT_EQ(cs.getPosition(), Base::Vector3d(1, 2, 3));
EXPECT_EQ(cs.getXDirection(), Base::Vector3d(-1, -1, 2).Normalize());
EXPECT_EQ(cs.getYDirection(), Base::Vector3d(1, -1, 0).Normalize());
EXPECT_EQ(cs.getZDirection(), Base::Vector3d(1, 1, 1).Normalize());
}
TEST(CoordinateSystem, TestSetXDir)
{
Base::CoordinateSystem cs;
cs.setXDirection(Base::Vector3d(1, 1, 1));
EXPECT_EQ(cs.getXDirection(), Base::Vector3d(1, 1, 0).Normalize());
EXPECT_EQ(cs.getYDirection(), Base::Vector3d(-1, 1, 0).Normalize());
EXPECT_EQ(cs.getZDirection(), Base::Vector3d(0, 0, 1).Normalize());
}
TEST(CoordinateSystem, TestSetYDir)
{
Base::CoordinateSystem cs;
cs.setYDirection(Base::Vector3d(1, 1, 1));
EXPECT_EQ(cs.getXDirection(), Base::Vector3d(1, -1, 0).Normalize());
EXPECT_EQ(cs.getYDirection(), Base::Vector3d(1, 1, 0).Normalize());
EXPECT_EQ(cs.getZDirection(), Base::Vector3d(0, 0, 1).Normalize());
}
TEST(CoordinateSystem, TestSetZDir)
{
Base::CoordinateSystem cs;
cs.setZDirection(Base::Vector3d(1, 1, 1));
EXPECT_EQ(cs.getXDirection(), Base::Vector3d(2, -1, -1).Normalize());
EXPECT_EQ(cs.getYDirection(), Base::Vector3d(0, 1, -1).Normalize());
EXPECT_EQ(cs.getZDirection(), Base::Vector3d(1, 1, 1).Normalize());
}
TEST(CoordinateSystem, TestTransformPlacement)
{
Base::CoordinateSystem cs;
Base::CoordinateSystem csT;
Base::Placement plm;
plm.setPosition(Base::Vector3d(1, 2, 3));
plm.setRotation(Base::Rotation(1, 1, 2, 2));
csT.transform(plm);
Base::Placement dis = cs.displacement(csT);
EXPECT_EQ(plm.isSame(dis, 1e-15), true);
Base::Placement disT = csT.displacement(cs);
EXPECT_EQ(plm.inverse().isSame(disT, 1e-15), true);
}
TEST(CoordinateSystem, TestMultTransformPlacement)
{
Base::CoordinateSystem cs;
Base::CoordinateSystem csT;
Base::Placement plm;
plm.setPosition(Base::Vector3d(1, 2, 3));
plm.setRotation(Base::Rotation(1, 1, 2, 2));
csT.transform(plm);
csT.transform(plm);
plm = plm * plm;
Base::Placement dis = cs.displacement(csT);
EXPECT_EQ(plm.isSame(dis, 0.001), true);
Base::Placement disT = csT.displacement(cs);
EXPECT_EQ(plm.inverse().isSame(disT, 0.001), true);
}
TEST(CoordinateSystem, TestTransformRotation)
{
Base::CoordinateSystem cs;
Base::CoordinateSystem csT;
Base::Rotation rot(1, 1, 2, 2);
csT.transform(rot);
Base::Placement dis = cs.displacement(csT);
EXPECT_EQ(rot.isSame(dis.getRotation(), 1e-15), true);
Base::Placement disT = csT.displacement(cs);
EXPECT_EQ(rot.inverse().isSame(disT.getRotation(), 1e-15), true);
}
TEST(CoordinateSystem, TestTransformPoint)
{
Base::CoordinateSystem cs;
Base::CoordinateSystem csT;
Base::Placement plm;
plm.setPosition(Base::Vector3d(1, 2, 3));
plm.setRotation(Base::Rotation(1, 1, 2, 2));
csT.transform(plm);
Base::Vector3d src(-1, 5, 3), dst;
plm.inverse().multVec(src, dst);
csT.transformTo(src);
EXPECT_EQ(src, dst);
}
TEST(CoordinateSystem, TestSetPlacement)
{
Base::CoordinateSystem cs;
Base::CoordinateSystem csT;
Base::Placement plm;
plm.setPosition(Base::Vector3d(1, 2, 3));
plm.setRotation(Base::Rotation(1, 1, 2, 2));
csT.transform(plm);
csT.transform(plm);
csT.transform(plm);
csT.setPlacement(plm);
Base::Placement dis = cs.displacement(csT);
EXPECT_EQ(plm.isSame(dis, 1e-15), true);
Base::Placement disT = csT.displacement(cs);
EXPECT_EQ(plm.inverse().isSame(disT, 1e-15), true);
}
// NOLINTEND
|