3 #include <gtest/gtest.h> 13 std::srand(time(NULL));
28 EXPECT_EQ(v.x(), p.
x());
29 EXPECT_EQ(v.y(), p.
y());
30 EXPECT_EQ(v.z(), p.
z());
39 EXPECT_EQ(10.2, p.
x());
45 EXPECT_EQ(p.
y(), 8.2);
47 EXPECT_EQ(p.
z(), 3.3);
49 double* ptr = p.
data();
51 EXPECT_EQ(ptr[0], p.
x());
52 EXPECT_EQ(ptr[1], p.
y());
53 EXPECT_EQ(ptr[2], p.
z());
67 for (
int i = 0; i < nTests; i++)
69 double x = unit_test_utils::getRandomNumber<double>();
70 double y = unit_test_utils::getRandomNumber<double>();
71 double z = unit_test_utils::getRandomNumber<double>();
75 double x2 = unit_test_utils::getRandomNumber<double>();
76 double y2 = unit_test_utils::getRandomNumber<double>();
77 double z2 = unit_test_utils::getRandomNumber<double>();
81 double distanceSquared = pow((x2 - x), 2) + pow((y2 - y), 2) + pow((z2 - z), 2);
86 for (
int i = 0; i < nTests; i++)
88 double x = unit_test_utils::getRandomNumber<double>();
89 double y = unit_test_utils::getRandomNumber<double>();
90 double z = unit_test_utils::getRandomNumber<double>();
94 double x2 = unit_test_utils::getRandomNumber<double>();
95 double y2 = unit_test_utils::getRandomNumber<double>();
96 double z2 = unit_test_utils::getRandomNumber<double>();
105 double distanceSquared = dx * dx + dy * dy + dz * dz;
113 for (
int i = 0; i < nTests; i++)
115 double x = unit_test_utils::getRandomNumber<double>();
116 double y = unit_test_utils::getRandomNumber<double>();
117 double z = unit_test_utils::getRandomNumber<double>();
121 double x2 = unit_test_utils::getRandomNumber<double>();
122 double y2 = unit_test_utils::getRandomNumber<double>();
123 double z2 = unit_test_utils::getRandomNumber<double>();
127 double distance = sqrt(pow((x2 - x), 2) + pow((y2 - y), 2) + pow((z2 - z), 2));
132 for (
int i = 0; i < nTests; i++)
134 double x = unit_test_utils::getRandomNumber<double>();
135 double y = unit_test_utils::getRandomNumber<double>();
136 double z = unit_test_utils::getRandomNumber<double>();
140 double x2 = unit_test_utils::getRandomNumber<double>();
141 double y2 = unit_test_utils::getRandomNumber<double>();
142 double z2 = unit_test_utils::getRandomNumber<double>();
151 double distance = sqrt(dx * dx + dy * dy + dz * dz);
159 for (
int i = 0; i < nTests; i++)
161 double x = unit_test_utils::getRandomNumber<double>();
162 double y = unit_test_utils::getRandomNumber<double>();
163 double z = unit_test_utils::getRandomNumber<double>();
167 double x2 = unit_test_utils::getRandomNumber<double>();
168 double y2 = unit_test_utils::getRandomNumber<double>();
169 double z2 = unit_test_utils::getRandomNumber<double>();
173 double distanceL1 = fabs(x2 - x) + fabs(y2 - y) + fabs(z2 - z);
178 for (
int i = 0; i < nTests; i++)
180 double x = unit_test_utils::getRandomNumber<double>();
181 double y = unit_test_utils::getRandomNumber<double>();
182 double z = unit_test_utils::getRandomNumber<double>();
186 double x2 = unit_test_utils::getRandomNumber<double>();
187 double y2 = unit_test_utils::getRandomNumber<double>();
188 double z2 = unit_test_utils::getRandomNumber<double>();
192 double distanceL1 = fabs(x2 - x) + fabs(y2 - y) + fabs(z2 - z);
200 for (
int i = 0; i < nTests; i++)
202 double x = unit_test_utils::getRandomNumber<double>();
203 double y = unit_test_utils::getRandomNumber<double>();
204 double z = unit_test_utils::getRandomNumber<double>();
208 double x2 = unit_test_utils::getRandomNumber<double>();
209 double y2 = unit_test_utils::getRandomNumber<double>();
210 double z2 = unit_test_utils::getRandomNumber<double>();
214 double distanceLInf = std::max(fabs(x2 - x), fabs(y2 - y));
215 distanceLInf = std::max(distanceLInf, fabs(z2 - z));
220 for (
int i = 0; i < nTests; i++)
222 double x = unit_test_utils::getRandomNumber<double>();
223 double y = unit_test_utils::getRandomNumber<double>();
224 double z = unit_test_utils::getRandomNumber<double>();
228 double x2 = unit_test_utils::getRandomNumber<double>();
229 double y2 = unit_test_utils::getRandomNumber<double>();
230 double z2 = unit_test_utils::getRandomNumber<double>();
234 double distanceLInf = std::max(fabs(x2 - x), fabs(y2 - y));
235 distanceLInf = std::max(distanceLInf, fabs(z2 - z));
245 Vector3d v(point2.
x() - point1.
x(), point2.
y() - point1.
y(), point2.
z() - point1.
z());
248 EXPECT_TRUE(v.isApprox(v2, 1e-12));
253 Point3d p(-0.132, 0.6135, 1.111);
254 Vector3d v(-8.711, 332.11, -9.8111);
257 EXPECT_NEAR(p_out.
x(), p.
x() - v.x(), 1.e-12);
258 EXPECT_NEAR(p_out.
y(), p.
y() - v.y(), 1.e-12);
259 EXPECT_NEAR(p_out.
z(), p.
z() - v.z(), 1.e-12);
262 EXPECT_NEAR(p_out.x(), p.
x() + v.x(), 1.e-12);
263 EXPECT_NEAR(p_out.y(), p.
y() + v.y(), 1.e-12);
264 EXPECT_NEAR(p_out.z(), p.
z() + v.z(), 1.e-12);
269 for (
int i = 0; i < 1000; i++)
273 double scale = rand() % 100 - 50;
289 for (
int i = 0; i < 1000; i++)
300 for (
int i = 0; i < 1000; i++)
315 Point3d point1(100., 200., 300.);
325 Point3d point1(100., 200., 300.);
440 double x = unit_test_utils::getRandomNumber<double>();
441 double y = unit_test_utils::getRandomNumber<double>();
442 double z = unit_test_utils::getRandomNumber<double>();
446 EXPECT_TRUE(point2 == point1);
447 EXPECT_FALSE(point2 != point1);
449 point2.
x() = point2.
x() + 0.1;
450 EXPECT_FALSE(point2 == point1);
454 float x = unit_test_utils::getRandomNumber<float>();
455 float y = unit_test_utils::getRandomNumber<float>();
456 float z = unit_test_utils::getRandomNumber<float>();
460 EXPECT_TRUE(point2 == point1);
461 EXPECT_FALSE(point2 != point1);
467 double x = unit_test_utils::getRandomNumber<double>();
468 double y = unit_test_utils::getRandomNumber<double>();
469 double z = unit_test_utils::getRandomNumber<double>();
543 int main(
int argc,
char** argv)
545 ::testing::InitGoogleTest(&argc, argv);
546 ::testing::FLAGS_gtest_death_test_style =
"threadsafe";
547 return RUN_ALL_TESTS();
EIGEN_STRONG_INLINE double & x()
void transform(const Math::SpatialTransform &X)
Performs in place point transform. Given a point, , this performs .
EIGEN_STRONG_INLINE void set(const std::vector< double > &vector)
void absoluteValue()
Set each element to the absolute value.
SpatialTransform Xroty(const double &yrot)
Get transform with zero translation and pure rotation about y axis.
void clampMax(const double max)
clamp any values that are greater than make to max
SpatialTransform Xtrans(const Vector3d &r)
Get pure translation transform.
TEST_F(Point3Test, testSimpleConstructors)
static Point3d getRandomPoint3()
SpatialTransform Xrotz(const double &zrot)
Get transform with zero translation and pure rotation about z axis.
EIGEN_STRONG_INLINE double * data()
SpatialTransform Xrotx(const double &xrot)
Get transform with zero translation and pure rotation about x axis.
int main(int argc, char **argv)
Math types such as vectors and matrices and utility functions.
EIGEN_STRONG_INLINE double & y()
Vector3d cross(const Vector3d &v)
Cross product between a point and vector.
static bool checkVector3dEpsilonClose(const RobotDynamics::Math::Vector3d &v1, const RobotDynamics::Math::Vector3d &v2, const double epsilon)
EIGEN_STRONG_INLINE bool epsilonEquals(const Point3d &point, const double epsilon) const
void clampMinMax(const double min, const double max)
clamp any values greater than max to max, and any value less than min to min
EIGEN_STRONG_INLINE double & z()
void clampMin(const double min)
clamp any values that are less than min to min
Point3d transform_copy(const Math::SpatialTransform &X)
Namespace for all structures of the RobotDynamics library.