-
Notifications
You must be signed in to change notification settings - Fork 5
/
TestGeometry.cpp
101 lines (86 loc) · 3.8 KB
/
TestGeometry.cpp
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
/** \author Sipu Ruan */
#include "hrm/geometry/SuperEllipse.h"
#include "hrm/geometry/SuperQuadrics.h"
#include "hrm/geometry/TightFitEllipsoid.h"
#include "hrm/util/ExponentialFunction.h"
#include "gtest/gtest.h"
// Tests for SuperEllipse
TEST(TestSuperEllipse, BoundarySampling) {
const hrm::SuperEllipse S({5.0, 3.0}, 1.25, {-2.6, 3.2}, 0.0, 50);
const hrm::BoundaryPoints boundary = S.getOriginShape();
// Point on major semi axis
const double boundaryX = 2.4;
const double boundaryY = 3.2;
ASSERT_DOUBLE_EQ(boundary(0, 0), boundaryX);
ASSERT_DOUBLE_EQ(boundary(1, 0), boundaryY);
}
TEST(TestSuperEllipse, MinkowskiBoundarySampling) {
const hrm::SuperEllipse S({5.0, 3.0}, 1.25, {3.2, -2.5}, 0.0, 50);
const hrm::SuperEllipse E({2.5, 1.5}, 1.0, {0.0, 0.0}, 0.0, 50);
const hrm::BoundaryPoints minkBound = S.getMinkSum2D(E, +1);
// Point on major semi axis
const double boundaryX = 10.7;
const double boundaryY = -2.5;
ASSERT_DOUBLE_EQ(minkBound(0, 0), boundaryX);
ASSERT_DOUBLE_EQ(minkBound(1, 0), boundaryY);
}
// Tests for SuperQuadrics
TEST(TestSuperQuadrics, BoundarySampling) {
const hrm::SuperQuadrics S({5.0, 3.0, 2.0}, {1.25, 0.3}, {2.32, -1.5, 4.0},
Eigen::Quaterniond(0.0, 1.0, 0.0, 0.0), 20);
const hrm::BoundaryPoints boundary = S.getOriginShape();
// Point on semi axis
const double boundaryX = 2.32;
const double boundaryY = -1.5;
for (auto i = 0; i < boundary.cols(); ++i) {
if (std::fabs(boundary(0, i) - boundaryX) < hrm::EPSILON &&
std::fabs(boundary(1, i) - boundaryY) < hrm::EPSILON) {
EXPECT_TRUE(std::fabs(boundary(2, i) - 6.0) < hrm::EPSILON ||
std::fabs(boundary(2, i) - 2.0) < hrm::EPSILON);
}
}
}
TEST(TestSuperQuadrics, MinkowskiBoundarySampling) {
const hrm::SuperQuadrics S({5.0, 3.0, 2.0}, {1.25, 0.3},
{-3.2, 3.24, -2.13},
Eigen::Quaterniond(0.0, 1.0, 0.0, 0.0), 20);
const hrm::SuperQuadrics E({2.5, 1.5, 1.0}, {1.0, 1.0}, {0.0, 0.0, 0.0},
Eigen::Quaterniond(0.0, 1.0, 0.0, 0.0), 20);
const hrm::BoundaryPoints minkBound = S.getMinkSum3D(E, +1);
// Point on semi axis
const double boundaryX = -3.2;
const double boundaryY = 3.24;
for (auto i = 0; i < minkBound.cols(); ++i) {
if (std::fabs(minkBound(0, i) - boundaryX) < hrm::EPSILON &&
std::fabs(minkBound(1, i) - boundaryY) < hrm::EPSILON) {
EXPECT_TRUE(
std::fabs(minkBound(2, i) - (3.0 - 2.13)) < hrm::EPSILON ||
std::fabs(minkBound(2, i) - (-3.0 - 2.13)) < hrm::EPSILON);
}
}
}
// Test for TightFittedEllipsoid
TEST(TestTightFittedEllipsoid, MVCE2D) {
const hrm::SuperEllipse mvce =
hrm::getMVCE2D({5.0, 3.0}, {5.0, 3.0}, 0.0, hrm::HALF_PI, 50);
const double semiAxis1 = 5.0;
const double semiAxis2 = 5.0;
EXPECT_TRUE(std::fabs(mvce.getSemiAxis().at(0) - semiAxis1) < hrm::EPSILON);
EXPECT_TRUE(std::fabs(mvce.getSemiAxis().at(1) - semiAxis2) < hrm::EPSILON);
}
TEST(TestTightFittedEllipsoid, MVCE3D) {
const hrm::SuperQuadrics mvce =
hrm::getMVCE3D({5.0, 3.0, 2.0}, {2.0, 3.0, 5.0},
Eigen::Quaterniond(0.0, 1.0, 0.0, 0.0),
Eigen::Quaterniond(0.0, 1.0, 0.0, 0.0), 20);
const double semiAxis1 = 3.0;
const double semiAxis2 = 5.0;
const double semiAxis3 = 5.0;
EXPECT_TRUE(std::fabs(mvce.getSemiAxis().at(0) - semiAxis1) < hrm::EPSILON);
EXPECT_TRUE(std::fabs(mvce.getSemiAxis().at(1) - semiAxis2) < hrm::EPSILON);
EXPECT_TRUE(std::fabs(mvce.getSemiAxis().at(2) - semiAxis3) < hrm::EPSILON);
}
int main(int ac, char* av[]) {
testing::InitGoogleTest(&ac, av);
return RUN_ALL_TESTS();
}