APM:Libraries
test_closest_distance_between_radial_and_point.cpp
Go to the documentation of this file.
1 #include <AP_gtest.h>
2 
3 #include <AP_Math/vector2.h>
4 
5 #define TEST_DISTANCE_BOTH(line_segment_x,line_segment_y, point_x, point_y, expected_length) \
6  do { \
7  { \
8  Vector2f line_segment = Vector2f(line_segment_x, line_segment_y); \
9  Vector2f point = Vector2f(point_x, point_y); \
10  float result = Vector2<float>::closest_distance_between_radial_and_point( \
11  line_segment, \
12  point \
13  ); \
14  EXPECT_FLOAT_EQ(result, expected_length); \
15  } \
16  } while (false)
17 
18 
19 TEST(ThreatTests, Distance)
20 {
21 
22  TEST_DISTANCE_BOTH( 0, 0, 0, 0, 0);
23  TEST_DISTANCE_BOTH( 0, 0, 0, 1, 1);
24 
25  TEST_DISTANCE_BOTH( 1, 1, 1, 0, sqrt(0.5));
26  TEST_DISTANCE_BOTH(-1,-1, -1, 0, sqrt(0.5));
27 
28  TEST_DISTANCE_BOTH( 3, 1, 3, 0, 0.94868332);
29  TEST_DISTANCE_BOTH( 1, 3, 0, 3, 0.94868332);
30  TEST_DISTANCE_BOTH(-1, 3, 0, 3, 0.94868332);
31  TEST_DISTANCE_BOTH( 1,-3, 0,-3, 0.94868332);
32  TEST_DISTANCE_BOTH(-1,-3, 0,-3, 0.94868332);
33 
34  TEST_DISTANCE_BOTH( 2, 2, 1, 1, 0.0);
35  TEST_DISTANCE_BOTH( 2, 2, 3, 3, sqrt(2));
36  TEST_DISTANCE_BOTH( 2, 2, 2, 2, 0);
37  TEST_DISTANCE_BOTH( 0, 0, 1, 1, sqrt(2));
38  TEST_DISTANCE_BOTH( 0, 0, 1, 1, sqrt(2));
39 
40  TEST_DISTANCE_BOTH( 0, 0, 1, 1, sqrt(2));
41  TEST_DISTANCE_BOTH( 1, 1, 0, 3, sqrt(5));
42 }
43 
44 AP_GTEST_MAIN()
45 
46 
47 int hal = 0; // bizarrely, this fixes an undefined-symbol error but doesn't raise a type exception. Yay.
48 
49 
TEST(ThreatTests, Distance)
#define TEST_DISTANCE_BOTH(line_segment_x, line_segment_y, point_x, point_y, expected_length)
int hal
-*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-