28TEST(geom, single_point_no_transform) {
29 constexpr double error = 0.001;
31 Location translation (0.0, 0.0, 0.0);
33 Transform transform (translation, rotation);
37 Location result_point(1.0, 1.0, 1.0);
39 ASSERT_NEAR(point.
x, result_point.
x, error);
40 ASSERT_NEAR(point.
y, result_point.
y, error);
41 ASSERT_NEAR(point.
z, result_point.
z, error);
45TEST(geom, single_point_translation) {
46 constexpr double error = 0.001;
50 Transform transform (translation, rotation);
54 Location result_point(2.0, 5.0, 7.0);
56 ASSERT_NEAR(point.
x, result_point.
x, error);
57 ASSERT_NEAR(point.
y, result_point.
y, error);
58 ASSERT_NEAR(point.
z, result_point.
z, error);
62TEST(geom, single_point_transform_inverse_transform_coherence) {
63 constexpr double error = 0.001;
65 const Location point(-3.14f, 1.337f, 4.20f);
66 const Location translation (1.41f, -4.7f, 9.2f);
67 const Rotation rotation (-47.0f, 37.0f, 250.2f);
68 const Transform transform (translation, rotation);
70 auto transformed_point = point;
73 auto point_back_to_normal = transformed_point;
76 ASSERT_NEAR(point.
x, point_back_to_normal.x, error) <<
"result.x is " << point_back_to_normal.x <<
" but expected " << point.
x;
77 ASSERT_NEAR(point.
y, point_back_to_normal.y, error) <<
"result.y is " << point_back_to_normal.y <<
" but expected " << point.
y;
78 ASSERT_NEAR(point.
z, point_back_to_normal.z, error) <<
"result.z is " << point_back_to_normal.z <<
" but expected " << point.
z;
82TEST(geom, bbox_get_local_vertices_get_world_vertices_coherence) {
83 constexpr double error = 0.001;
87 const Location bbox_location(-3.14f, 1.337f, 4.20f);
88 const Rotation bbox_rotation (-59.0f, 17.0f, -650.2f);
89 const Transform bbox_transform(bbox_location, bbox_rotation);
93 for (
auto i = 0u; i < local_vertices.size(); ++i){
94 const auto &local_vertex = local_vertices[i];
96 auto transformed_local_vertex = local_vertex;
99 const auto &world_vertex = world_vertices[i];
101 ASSERT_NEAR(transformed_local_vertex.x, world_vertex.x, error) <<
"result.x is " << transformed_local_vertex.x <<
" but expected " << world_vertex.x;
102 ASSERT_NEAR(transformed_local_vertex.y, world_vertex.y, error) <<
"result.y is " << transformed_local_vertex.y <<
" but expected " << world_vertex.y;
103 ASSERT_NEAR(transformed_local_vertex.z, world_vertex.z, error) <<
"result.z is " << transformed_local_vertex.z <<
" but expected " << world_vertex.z;
108TEST(geom, single_point_rotation) {
109 constexpr double error = 0.001;
113 Transform transform (translation, rotation);
117 Location result_point(0.0, 0.0, 1.0);
118 ASSERT_NEAR(point.
x, result_point.
x, error);
119 ASSERT_NEAR(point.
y, result_point.
y, error);
120 ASSERT_NEAR(point.
z, result_point.
z, error);
123TEST(geom, single_point_translation_and_rotation) {
124 constexpr double error = 0.001;
126 Location translation (0.0,0.0,-1.0);
128 Transform transform (translation, rotation);
132 Location result_point(-2.0, 0.0, -1.0);
133 ASSERT_NEAR(point.
x, result_point.
x, error);
134 ASSERT_NEAR(point.
y, result_point.
y, error);
135 ASSERT_NEAR(point.
z, result_point.
z, error);
139 constexpr double error = .01;
141 ASSERT_NEAR(
Math::Distance({1, 1, 1}, {0, 0, 0}), 1.732051, error);
142 ASSERT_NEAR(
Math::Distance({0, 0, 0}, {1, 1, 1}), 1.732051, error);
143 ASSERT_NEAR(
Math::Distance({-1, -1, -1}, {0, 0, 0}), 1.732051, error);
144 ASSERT_NEAR(
Math::Distance({0, 0, 0}, {-1, -1, -1}), 1.732051, error);
145 ASSERT_NEAR(
Math::Distance({7, 4, 3}, {17, 6, 2}), 10.246951, error);
146 ASSERT_NEAR(
Math::Distance({7, -4, 3}, {-17, 6, 2}), 26.019224, error);
147 ASSERT_NEAR(
Math::Distance({5, 6, 7}, {-6, 3, -4}), 15.84298, error);
148 ASSERT_NEAR(
Math::Distance({7, 4, 3}, {17, 6, 2}), 10.246951, error);
151TEST(geom, nearest_point_segment) {
152 const float segment[] = {
178 const int results[] = {
179 0, 1, 7, 9, 8, 2, 9, 2, 8, 3
182 for (
int i = 0; i < 10; ++i) {
183 double min_dist = std::numeric_limits<double>::max();
185 for (
int j = 0; j < 40; j += 4) {
188 {segment[j + 0], segment[j + 1], 0},
189 {segment[j + 2], segment[j + 3], 0}).second;
190 if (dist < min_dist) {
195 ASSERT_EQ(
id, results[i]) <<
"Fails point number: " << i;
201 constexpr float eps = 2.0f * std::numeric_limits<float>::epsilon();
204 (std::abs(expected.x - result.x) < eps) &&
205 (std::abs(expected.y - result.y) < eps) &&
206 (std::abs(expected.z - result.z) < eps))
207 <<
"result = " << result <<
'\n'
208 <<
"expected = " << expected;
211 compare({ 0.0f, 0.0f, 0.0f}, {1.0f, 0.0f, 0.0f});
212 compare({ 0.0f, 0.0f, 123.0f}, {1.0f, 0.0f, 0.0f});
213 compare({360.0f, 360.0f, 0.0f}, {1.0f, 0.0f, 0.0f});
214 compare({ 0.0f, 90.0f, 0.0f}, {0.0f, 1.0f, 0.0f});
215 compare({ 0.0f, -90.0f, 0.0f}, {0.0f,-1.0f, 0.0f});
216 compare({ 90.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 1.0f});
217 compare({180.0f, -90.0f, 0.0f}, {0.0f, 1.0f, 0.0f});
222 Vector3D(0,0,0), 1.57f, 0, 1).second, 0.414214f, 0.01f);
224 Vector3D(0,0,0), 1.57f, 0, 1).second, 1.0f, 0.01f);
226 Vector3D(0,0,0), 1.57f, 0, 1).second, 1.0f, 0.01f);
228 Vector3D(0,0,0), 1.57f, 0, 1).second, 1.0f, 0.01f);
static std::pair< float, float > DistanceArcToPoint(Vector3D p, Vector3D start_pos, float length, float heading, float curvature)
Returns a pair containing: