2016-06-05 23:19:36 -03:00
|
|
|
#include <AP_gtest.h>
|
|
|
|
|
|
|
|
#include <AP_Math/vector2.h>
|
2016-06-19 20:30:35 -03:00
|
|
|
#include <AP_Math/vector3.h>
|
2016-06-05 23:19:36 -03:00
|
|
|
|
|
|
|
#define EXPECT_VECTOR2F_EQ(v1, v2) \
|
|
|
|
do { \
|
|
|
|
EXPECT_FLOAT_EQ(v1[0], v2[0]); \
|
|
|
|
EXPECT_FLOAT_EQ(v1[1], v2[1]); \
|
|
|
|
} while (false);
|
|
|
|
|
2016-06-19 20:30:35 -03:00
|
|
|
#define EXPECT_VECTOR3F_EQ(v1, v2) \
|
|
|
|
do { \
|
|
|
|
EXPECT_FLOAT_EQ(v1[0], v2[0]); \
|
|
|
|
EXPECT_FLOAT_EQ(v1[1], v2[1]); \
|
|
|
|
EXPECT_FLOAT_EQ(v1[2], v2[2]); \
|
|
|
|
} while (false);
|
|
|
|
|
|
|
|
|
|
|
|
#define PERP_TEST_2D(px,py, vx,vy, ex,ey) \
|
2016-06-05 23:19:36 -03:00
|
|
|
do { \
|
2016-06-19 20:30:35 -03:00
|
|
|
Vector2f p(px,py); \
|
|
|
|
Vector2f v(vx,vy); \
|
2016-06-05 23:19:36 -03:00
|
|
|
Vector2f expected(ex,ey); \
|
|
|
|
Vector2f result; \
|
2016-06-19 20:30:35 -03:00
|
|
|
result = Vector2f::perpendicular(p, v); \
|
|
|
|
EXPECT_VECTOR2F_EQ(expected, result); \
|
2016-06-05 23:19:36 -03:00
|
|
|
} while (false)
|
|
|
|
|
2016-06-19 20:30:35 -03:00
|
|
|
#define PERP_TEST_3D(px,py,pz, vx,vy,vz, ex,ey,ez) \
|
|
|
|
do { \
|
|
|
|
Vector3f p(px,py,pz); \
|
|
|
|
Vector3f v(vx,vy,vz); \
|
|
|
|
Vector3f expected(ex,ey,ez); \
|
|
|
|
Vector3f result; \
|
|
|
|
result = Vector3f::perpendicular(p, v); \
|
|
|
|
EXPECT_VECTOR3F_EQ(expected, result); \
|
|
|
|
} while (false)
|
|
|
|
|
2020-05-03 08:33:07 -03:00
|
|
|
void foo();
|
|
|
|
void foo() { }
|
2016-06-05 23:19:36 -03:00
|
|
|
TEST(ThreatTests, Distance)
|
|
|
|
{
|
|
|
|
|
2016-06-19 20:30:35 -03:00
|
|
|
PERP_TEST_2D( 0.0f,0.0f, 0.0f,0.0f, 0.0f,0.0f);
|
|
|
|
PERP_TEST_2D( 0.0f,0.0f, 1.0f,0.0f, 0.0f,-1.0f);
|
|
|
|
PERP_TEST_2D( 2.0f,0.0f, 1.0f,0.0f, 0.0f,-1.0f);
|
|
|
|
PERP_TEST_2D( 0.0f,2.0f, 1.0f,0.0f, 0.0f,1.0f);
|
|
|
|
PERP_TEST_2D( 0.0f,2.0f, 1.0f,2.0f, -2.0f,1.0f);
|
|
|
|
PERP_TEST_2D( 2.0f,0.0f, 1.0f,2.0f, 2.0f,-1.0f);
|
|
|
|
|
|
|
|
// 2D cases for the 3D code:
|
|
|
|
PERP_TEST_3D( 0.0f,0.0f,0.0f, 0.0f,0.0f,0.0f, 0.0f,0.0f,0.0f);
|
|
|
|
PERP_TEST_3D( 0.0f,0.0f,0.0f, 1.0f,0.0f,0.0f, 0.0f,0.0f,0.0f);
|
|
|
|
PERP_TEST_3D( 2.0f,0.0f,0.0f, 1.0f,0.0f,0.0f, 0.0f,0.0f,0.0f);
|
|
|
|
foo();
|
|
|
|
PERP_TEST_3D( 0.0f,2.0f,0.0f, 1.0f,0.0f,0.0f, 0.0f,2.0f,0.0f);
|
|
|
|
PERP_TEST_3D( 0.0f,2.0f,0.0f, 1.0f,2.0f,0.0f, -0.8f,0.4f,0.0f);
|
|
|
|
PERP_TEST_3D( 2.0f,0.0f,0.0f, 1.0f,2.0f,0.0f, 1.6f,-0.8f,0.0f);
|
|
|
|
|
|
|
|
|
|
|
|
// 3D-specific tests
|
|
|
|
PERP_TEST_3D( 1.0f,1.0f,1.0f, 1.0f,0.0f,0.0f, 0.0f,1.0f,1.0f);
|
|
|
|
PERP_TEST_3D( -1.0f,-1.0f,-1.0f, -1.0f,0.0f,0.0f, 0.0f,-1.0f,-1.0f);
|
|
|
|
PERP_TEST_3D(1.0f,1.0f,0.0f, 1.0f,0.0f,0.0f, 0.0f,1.0f,0.0f);
|
|
|
|
|
|
|
|
PERP_TEST_3D(1.0f,1.0f,1.0f, 1.0f,-1.0f,0.0f, 1.0f,1.0f,1.0f);
|
2016-06-05 23:19:36 -03:00
|
|
|
|
2016-06-19 20:30:35 -03:00
|
|
|
PERP_TEST_3D(1.0f,1.0f,1.0f, 1.0f,-1.0f,1.0f, 0.66666666f,1.33333333f,0.66666666f);
|
2016-06-05 23:19:36 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
AP_GTEST_MAIN()
|
|
|
|
|
|
|
|
|
|
|
|
int hal = 0; // bizarrely, this fixes an undefined-symbol error but doesn't raise a type exception. Yay.
|