Peter Barker
9 years ago
committed by
Randy Mackay
3 changed files with 114 additions and 0 deletions
@ -0,0 +1,49 @@
@@ -0,0 +1,49 @@
|
||||
#include <AP_gtest.h> |
||||
|
||||
#include <AP_Math/vector2.h> |
||||
|
||||
#define TEST_DISTANCE_BOTH(line_segment_x,line_segment_y, point_x, point_y, expected_length) \ |
||||
do { \
|
||||
{ \
|
||||
Vector2f line_segment = Vector2f(line_segment_x, line_segment_y); \
|
||||
Vector2f point = Vector2f(point_x, point_y); \
|
||||
float result = Vector2<float>::closest_distance_between_radial_and_point( \
|
||||
line_segment, \
|
||||
point \
|
||||
); \
|
||||
EXPECT_FLOAT_EQ(result, expected_length); \
|
||||
} \
|
||||
} while (false) |
||||
|
||||
|
||||
TEST(ThreatTests, Distance) |
||||
{ |
||||
|
||||
TEST_DISTANCE_BOTH( 0, 0, 0, 0, 0); |
||||
TEST_DISTANCE_BOTH( 0, 0, 0, 1, 1); |
||||
|
||||
TEST_DISTANCE_BOTH( 1, 1, 1, 0, sqrt(0.5)); |
||||
TEST_DISTANCE_BOTH(-1,-1, -1, 0, sqrt(0.5)); |
||||
|
||||
TEST_DISTANCE_BOTH( 3, 1, 3, 0, 0.94868332); |
||||
TEST_DISTANCE_BOTH( 1, 3, 0, 3, 0.94868332); |
||||
TEST_DISTANCE_BOTH(-1, 3, 0, 3, 0.94868332); |
||||
TEST_DISTANCE_BOTH( 1,-3, 0,-3, 0.94868332); |
||||
TEST_DISTANCE_BOTH(-1,-3, 0,-3, 0.94868332); |
||||
|
||||
TEST_DISTANCE_BOTH( 2, 2, 1, 1, 0.0); |
||||
TEST_DISTANCE_BOTH( 2, 2, 3, 3, sqrt(2)); |
||||
TEST_DISTANCE_BOTH( 2, 2, 2, 2, 0); |
||||
TEST_DISTANCE_BOTH( 0, 0, 1, 1, sqrt(2)); |
||||
TEST_DISTANCE_BOTH( 0, 0, 1, 1, sqrt(2)); |
||||
|
||||
TEST_DISTANCE_BOTH( 0, 0, 1, 1, sqrt(2)); |
||||
TEST_DISTANCE_BOTH( 1, 1, 0, 3, sqrt(5)); |
||||
} |
||||
|
||||
AP_GTEST_MAIN() |
||||
|
||||
|
||||
int hal = 0; // bizarrely, this fixes an undefined-symbol error but doesn't raise a type exception. Yay.
|
||||
|
||||
|
@ -0,0 +1,36 @@
@@ -0,0 +1,36 @@
|
||||
#include <AP_gtest.h> |
||||
|
||||
#include <AP_Math/vector2.h> |
||||
|
||||
#define EXPECT_VECTOR2F_EQ(v1, v2) \ |
||||
do { \
|
||||
EXPECT_FLOAT_EQ(v1[0], v2[0]); \
|
||||
EXPECT_FLOAT_EQ(v1[1], v2[1]); \
|
||||
} while (false); |
||||
|
||||
#define PERP_TEST(px,py, vx,vy, ex,ey) \ |
||||
do { \
|
||||
Vector2f p(px,py); \
|
||||
Vector2f v(vx,vy); \
|
||||
Vector2f expected(ex,ey); \
|
||||
Vector2f result; \
|
||||
result = Vector2f::perpendicular(p, v); \
|
||||
EXPECT_VECTOR2F_EQ(result, expected); \
|
||||
} while (false) |
||||
|
||||
TEST(ThreatTests, Distance) |
||||
{ |
||||
|
||||
PERP_TEST( 0.0f,0.0f, 0.0f,0.0f, 0.0f,0.0f); |
||||
PERP_TEST( 0.0f,0.0f, 1.0f,0.0f, 0.0f,-1.0f); |
||||
PERP_TEST( 2.0f,0.0f, 1.0f,0.0f, 0.0f,-1.0f); |
||||
PERP_TEST( 0.0f,2.0f, 1.0f,0.0f, 0.0f,1.0f); |
||||
|
||||
PERP_TEST( 0.0f,2.0f, 1.0f,2.0f, -2.0f,1.0f); |
||||
PERP_TEST( 2.0f,0.0f, 1.0f,2.0f, 2.0f,-1.0f); |
||||
} |
||||
|
||||
AP_GTEST_MAIN() |
||||
|
||||
|
||||
int hal = 0; // bizarrely, this fixes an undefined-symbol error but doesn't raise a type exception. Yay.
|
Loading…
Reference in new issue