2013-11-10 20:14:10 +00:00
|
|
|
#include "BaseTestCase.h"
|
2013-11-10 16:03:07 +00:00
|
|
|
|
2013-11-10 20:14:10 +00:00
|
|
|
#include <cmath>
|
2013-11-20 16:09:55 +00:00
|
|
|
#include "Geometry.h"
|
|
|
|
#include "Vector3.h"
|
2013-04-20 11:28:56 +00:00
|
|
|
|
2013-11-10 20:14:10 +00:00
|
|
|
/*static inline int _Vector3_cmp(Vector3 v1, Vector3 v2)
|
2013-04-22 14:53:16 +00:00
|
|
|
{
|
|
|
|
return fabs(v1.x - v2.z) >= 0.00000000001 && fabs(v1.y - v2.y) >= 0.00000000001 && fabs(v1.z - v2.z) >= 0.00000000001;
|
|
|
|
}
|
2013-04-27 19:41:57 +00:00
|
|
|
|
2013-04-22 14:53:16 +00:00
|
|
|
static inline void _Vector3_str(Vector3 v, char* buffer, int length)
|
|
|
|
{
|
|
|
|
snprintf(buffer, length, "(%f,%f,%f)", v.x, v.y, v.z);
|
|
|
|
}
|
2013-11-10 20:14:10 +00:00
|
|
|
DEFINE_COMPARE_ASSERT(Vector3, _Vector3_cmp, _Vector3_str);*/
|
2013-04-22 14:53:16 +00:00
|
|
|
|
2013-11-10 20:14:10 +00:00
|
|
|
TEST(Euclid, get2DAngle)
|
2013-04-20 11:28:56 +00:00
|
|
|
{
|
2013-11-20 16:09:55 +00:00
|
|
|
EXPECT_DOUBLE_EQ(Geometry::get2DAngle(0.0, 0.0), 0.0);
|
2013-04-20 11:28:56 +00:00
|
|
|
|
2013-11-20 16:09:55 +00:00
|
|
|
EXPECT_DOUBLE_EQ(Geometry::get2DAngle(0.1, 0.0), 0.0);
|
|
|
|
EXPECT_DOUBLE_EQ(Geometry::get2DAngle(1.0, 0.0), 0.0);
|
|
|
|
EXPECT_DOUBLE_EQ(Geometry::get2DAngle(2.0, 0.0), 0.0);
|
2013-04-20 11:28:56 +00:00
|
|
|
|
2013-11-20 16:09:55 +00:00
|
|
|
EXPECT_DOUBLE_EQ(Geometry::get2DAngle(0.0, 0.1), M_PI_2);
|
|
|
|
EXPECT_DOUBLE_EQ(Geometry::get2DAngle(0.0, 1.0), M_PI_2);
|
|
|
|
EXPECT_DOUBLE_EQ(Geometry::get2DAngle(0.0, 2.0), M_PI_2);
|
2013-04-20 11:28:56 +00:00
|
|
|
|
2013-11-20 16:09:55 +00:00
|
|
|
EXPECT_DOUBLE_EQ(Geometry::get2DAngle(-0.1, 0.0), M_PI);
|
|
|
|
EXPECT_DOUBLE_EQ(Geometry::get2DAngle(-1.0, 0.0), M_PI);
|
|
|
|
EXPECT_DOUBLE_EQ(Geometry::get2DAngle(-2.0, 0.0), M_PI);
|
2013-04-20 11:28:56 +00:00
|
|
|
|
2013-11-20 16:09:55 +00:00
|
|
|
EXPECT_DOUBLE_EQ(Geometry::get2DAngle(0.0, -0.1), 3.0 * M_PI_2);
|
|
|
|
EXPECT_DOUBLE_EQ(Geometry::get2DAngle(0.0, -1.0), 3.0 * M_PI_2);
|
|
|
|
EXPECT_DOUBLE_EQ(Geometry::get2DAngle(0.0, -2.0), 3.0 * M_PI_2);
|
2013-04-20 11:28:56 +00:00
|
|
|
|
2013-11-20 16:09:55 +00:00
|
|
|
EXPECT_DOUBLE_EQ(Geometry::get2DAngle(0.5, 0.5), M_PI_4);
|
|
|
|
EXPECT_DOUBLE_EQ(Geometry::get2DAngle(0.5, -0.5), 7.0 * M_PI_4);
|
|
|
|
EXPECT_DOUBLE_EQ(Geometry::get2DAngle(-0.5, 0.5), 3.0 * M_PI_4);
|
|
|
|
EXPECT_DOUBLE_EQ(Geometry::get2DAngle(-0.5, -0.5), 5.0 * M_PI_4);
|
2013-04-20 11:28:56 +00:00
|
|
|
}
|
2013-04-27 19:41:57 +00:00
|
|
|
|
2013-11-10 20:14:10 +00:00
|
|
|
/*TEST(Euclid, Vector3)
|
2013-04-22 14:53:16 +00:00
|
|
|
{
|
|
|
|
Vector3 v1, v2, v3;
|
|
|
|
|
2013-11-10 20:14:10 +00:00
|
|
|
// Test scaling
|
2013-04-27 19:41:57 +00:00
|
|
|
v1.x = 0.0;
|
|
|
|
v1.y = -4.3;
|
|
|
|
v1.z = 8.2;
|
|
|
|
v2.x = 0.0;
|
|
|
|
v2.y = -8.6;
|
|
|
|
v2.z = 16.4;
|
|
|
|
v3.x = 0.0;
|
|
|
|
v3.y = 2.15;
|
|
|
|
v3.z = -4.1;
|
2013-11-10 20:14:10 +00:00
|
|
|
EXPECT_EQ(v3Scale(v1, 2.0), v2);
|
|
|
|
EXPECT_EQ(v3Scale(v1, -0.5), v3);
|
|
|
|
}*/
|
2013-04-27 19:41:57 +00:00
|
|
|
|
2013-11-10 20:14:10 +00:00
|
|
|
TEST(Euclid, VectorSpherical)
|
2013-04-27 19:41:57 +00:00
|
|
|
{
|
|
|
|
Vector3 v1;
|
|
|
|
VectorSpherical v2;
|
2013-04-22 14:53:16 +00:00
|
|
|
|
2013-04-27 19:41:57 +00:00
|
|
|
/* Test conversion to spherical */
|
2013-04-27 21:40:31 +00:00
|
|
|
v1.x = 0.0;
|
|
|
|
v1.y = 0.0;
|
|
|
|
v1.z = 0.0;
|
2013-12-11 10:32:10 +00:00
|
|
|
v2 = v1.toSpherical();
|
2013-11-10 20:14:10 +00:00
|
|
|
EXPECT_DOUBLE_EQ(v2.r, 0.0);
|
|
|
|
EXPECT_DOUBLE_EQ(v2.phi, 0.0);
|
|
|
|
EXPECT_DOUBLE_EQ(v2.theta, 0.0);
|
2013-04-27 21:40:31 +00:00
|
|
|
|
|
|
|
v1.x = 1.0;
|
|
|
|
v1.y = 0.0;
|
|
|
|
v1.z = 0.0;
|
2013-12-11 10:32:10 +00:00
|
|
|
v2 = v1.toSpherical();
|
2013-11-10 20:14:10 +00:00
|
|
|
EXPECT_DOUBLE_EQ(v2.r, 1.0);
|
|
|
|
EXPECT_DOUBLE_EQ(v2.phi, 0.0);
|
|
|
|
EXPECT_DOUBLE_EQ(v2.theta, 0.0);
|
2013-04-27 21:40:31 +00:00
|
|
|
|
|
|
|
v1.x = -1.0;
|
|
|
|
v1.y = 0.0;
|
|
|
|
v1.z = 0.0;
|
2013-12-11 10:32:10 +00:00
|
|
|
v2 = v1.toSpherical();
|
2013-11-10 20:14:10 +00:00
|
|
|
EXPECT_DOUBLE_EQ(v2.r, 1.0);
|
|
|
|
EXPECT_DOUBLE_EQ(v2.phi, M_PI);
|
|
|
|
EXPECT_DOUBLE_EQ(v2.theta, 0.0);
|
2013-04-27 21:40:31 +00:00
|
|
|
|
|
|
|
v1.x = 0.0;
|
|
|
|
v1.y = 1.0;
|
|
|
|
v1.z = 0.0;
|
2013-12-11 10:32:10 +00:00
|
|
|
v2 = v1.toSpherical();
|
2013-11-10 20:14:10 +00:00
|
|
|
EXPECT_DOUBLE_EQ(v2.r, 1.0);
|
|
|
|
EXPECT_DOUBLE_EQ(v2.phi, 0.0);
|
|
|
|
EXPECT_DOUBLE_EQ(v2.theta, M_PI_2);
|
2013-04-27 21:40:31 +00:00
|
|
|
|
|
|
|
v1.x = 0.0;
|
|
|
|
v1.y = -1.0;
|
|
|
|
v1.z = 0.0;
|
2013-12-11 10:32:10 +00:00
|
|
|
v2 = v1.toSpherical();
|
2013-11-10 20:14:10 +00:00
|
|
|
EXPECT_DOUBLE_EQ(v2.r, 1.0);
|
|
|
|
EXPECT_DOUBLE_EQ(v2.phi, 0.0);
|
|
|
|
EXPECT_DOUBLE_EQ(v2.theta, -M_PI_2);
|
2013-04-27 21:40:31 +00:00
|
|
|
|
|
|
|
v1.x = 0.0;
|
|
|
|
v1.y = 0.0;
|
|
|
|
v1.z = 1.0;
|
2013-12-11 10:32:10 +00:00
|
|
|
v2 = v1.toSpherical();
|
2013-11-10 20:14:10 +00:00
|
|
|
EXPECT_DOUBLE_EQ(v2.r, 1.0);
|
|
|
|
EXPECT_DOUBLE_EQ(v2.phi, 3.0 * M_PI_2);
|
|
|
|
EXPECT_DOUBLE_EQ(v2.theta, 0.0);
|
2013-04-27 21:40:31 +00:00
|
|
|
|
|
|
|
v1.x = 0.0;
|
|
|
|
v1.y = 0.0;
|
|
|
|
v1.z = -1.0;
|
2013-12-11 10:32:10 +00:00
|
|
|
v2 = v1.toSpherical();
|
2013-11-10 20:14:10 +00:00
|
|
|
EXPECT_DOUBLE_EQ(v2.r, 1.0);
|
|
|
|
EXPECT_DOUBLE_EQ(v2.phi, M_PI_2);
|
|
|
|
EXPECT_DOUBLE_EQ(v2.theta, 0.0);
|
2013-04-27 21:40:31 +00:00
|
|
|
|
2013-04-22 14:53:16 +00:00
|
|
|
v1.x = v1.y = v1.z = 0.5;
|
2013-12-11 10:32:10 +00:00
|
|
|
v2 = v1.toSpherical();
|
2013-11-10 20:14:10 +00:00
|
|
|
EXPECT_DOUBLE_EQ(v2.r, sqrt(0.5 * 0.5 + 0.5 * 0.5 + 0.5 * 0.5));
|
|
|
|
EXPECT_DOUBLE_EQ(v2.phi, 7.0 * M_PI_4);
|
|
|
|
EXPECT_DOUBLE_EQ(v2.theta, M_PI_2 - 0.955316618125);
|
2013-04-22 14:53:16 +00:00
|
|
|
}
|