35TEST(geom, single_point_no_transform) {
36 constexpr double error = 0.001;
38 Location translation (0.0, 0.0, 0.0);
40 Transform transform (translation, rotation);
44 Location result_point(1.0, 1.0, 1.0);
47 ASSERT_NEAR(point.
x, result_point.
x, error);
48 ASSERT_NEAR(point.
y, result_point.
y, error);
49 ASSERT_NEAR(point.
z, result_point.
z, error);
53TEST(geom, single_point_translation) {
54 constexpr double error = 0.001;
60 Transform transform (translation, rotation);
67 Location result_point(2.0, 5.0, 7.0);
70 ASSERT_NEAR(point.
x, result_point.
x, error);
72 ASSERT_NEAR(point.
y, result_point.
y, error);
74 ASSERT_NEAR(point.
z, result_point.
z, error);
78TEST(geom, single_point_transform_inverse_transform_coherence) {
79 constexpr double error = 0.001;
82 const Location point(-3.14f, 1.337f, 4.20f);
84 const Location translation (1.41f, -4.7f, 9.2f);
85 const Rotation rotation (-47.0f, 37.0f, 250.2f);
87 const Transform transform (translation, rotation);
89 auto transformed_point = point;
93 auto point_back_to_normal = transformed_point;
98 ASSERT_NEAR(point.x, point_back_to_normal.x, error) <<
"result.x is " << point_back_to_normal.x <<
" but expected " << point.x;
100 ASSERT_NEAR(point.y, point_back_to_normal.y, error) <<
"result.y is " << point_back_to_normal.y <<
" but expected " << point.y;
102 ASSERT_NEAR(point.z, point_back_to_normal.z, error) <<
"result.z is " << point_back_to_normal.z <<
" but expected " << point.z;
106TEST(geom, bbox_get_local_vertices_get_world_vertices_coherence) {
107 constexpr double error = 0.001;
111 const Location bbox_location(-3.14f, 1.337f, 4.20f);
113 const Rotation bbox_rotation (-59.0f, 17.0f, -650.2f);
115 const Transform bbox_transform(bbox_location, bbox_rotation);
123 for (
auto i = 0u; i < local_vertices.size(); ++i){
125 const auto &local_vertex = local_vertices[i];
128 auto transformed_local_vertex = local_vertex;
133 const auto &world_vertex = world_vertices[i];
135 ASSERT_NEAR(transformed_local_vertex.x, world_vertex.x, error) <<
"result.x is " << transformed_local_vertex.x <<
" but expected " << world_vertex.x;
136 ASSERT_NEAR(transformed_local_vertex.y, world_vertex.y, error) <<
"result.y is " << transformed_local_vertex.y <<
" but expected " << world_vertex.y;
137 ASSERT_NEAR(transformed_local_vertex.z, world_vertex.z, error) <<
"result.z is " << transformed_local_vertex.z <<
" but expected " << world_vertex.z;
145TEST(geom, single_point_translation_and_rotation) {
146 constexpr double error = 0.001;
148 Location translation (0.0, 0.0, -1.0);
152 Transform transform (translation, rotation);
158 Location result_point(-2.0, 0.0, -1.0);
160 ASSERT_NEAR(point.
x, result_point.
x, error);
161 ASSERT_NEAR(point.
y, result_point.
y, error);
162 ASSERT_NEAR(point.
z, result_point.
z, error);
167 constexpr double error = .01;
171 ASSERT_NEAR(
Math::Distance({1, 1, 1}, {0, 0, 0}), 1.732051, error);
173 ASSERT_NEAR(
Math::Distance({0, 0, 0}, {1, 1, 1}), 1.732051, error);
175 ASSERT_NEAR(
Math::Distance({-1, -1, -1}, {0, 0, 0}), 1.732051, error);
177 ASSERT_NEAR(
Math::Distance({0, 0, 0}, {-1, -1, -1}), 1.732051, error);
179 ASSERT_NEAR(
Math::Distance({7, 4, 3}, {17, 6, 2}), 10.246951, error);
181 ASSERT_NEAR(
Math::Distance({7, -4, 3}, {-17, 6, 2}), 26.019224, error);
183 ASSERT_NEAR(
Math::Distance({5, 6, 7}, {-6, 3, -4}), 15.84298, error);
185 ASSERT_NEAR(
Math::Distance({7, 4, 3}, {17, 6, 2}), 10.246951, error);
189TEST(geom, nearest_point_segment) {
192 const float segment[] = {
220 const int results[] = {
221 0, 1, 7, 9, 8, 2, 9, 2, 8, 3
226for (
int i = 0; i < 10; ++i) {
227 double min_dist = std::numeric_limits<double>::max();
230 for (
int j = 0; j < 40; j += 4) {
235 {segment[j + 0], segment[j + 1], 0},
236 {segment[j + 2], segment[j + 3], 0}
240 if (dist < min_dist) {
247 ASSERT_EQ(
id, results[i]) <<
"Fails point number: " << i;
253 TEST(geom, forward_vector) {
257 constexpr float eps = 2.0f * std::numeric_limits<float>::epsilon();
265 (std::abs(expected.x - result.x) < eps) &&
266 (std::abs(expected.y - result.y) < eps) &&
267 (std::abs(expected.z - result.z) < eps))
268 <<
"result = " << result <<
'\n'
269 <<
"expected = " << expected;
279 compare({0.0f, 0.0f, 0.0f}, {1.0f, 0.0f, 0.0f});
282compare({0.0f, 0.0f, 123.0f}, {1.0f, 0.0f, 0.0f});
286compare({360.0f, 360.0f, 0.0f}, {1.0f, 0.0f, 0.0f});
290compare({0.0f, 90.0f, 0.0f}, {0.0f, 1.0f, 0.0f});
295compare({0.0f, -90.0f, 0.0f}, {0.0f, -1.0f, 0.0f});
299compare({90.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 1.0f});
303compare({180.0f, -90.0f, 0.0f}, {0.0f, 1.0f, 0.0f});
static std::pair< float, float > DistanceArcToPoint(Vector3D p, Vector3D start_pos, float length, float heading, float curvature)
计算点到弧的距离 返回一个包含: