2017-05-09 01:48:36 +02:00
|
|
|
/**
|
|
|
|
* @author Edouard DUPIN
|
|
|
|
* @copyright 2011, Edouard DUPIN, all right reserved
|
|
|
|
* @license MPL v2.0 (see license file)
|
|
|
|
*/
|
|
|
|
|
2017-09-05 23:07:32 +02:00
|
|
|
#include <etest/etest.hpp>
|
2017-05-09 01:48:36 +02:00
|
|
|
#include <etk/math/Vector3D.hpp>
|
|
|
|
#include <test-debug/debug.hpp>
|
2018-06-19 07:16:00 +02:00
|
|
|
#include "ConstructDestruct.hpp"
|
2017-05-09 01:48:36 +02:00
|
|
|
|
|
|
|
#define NAME "etk:Vector3D<float>"
|
|
|
|
|
|
|
|
TEST(TestVector3D_f, constructor) {
|
|
|
|
// Test contructor value
|
2017-05-16 21:17:16 +02:00
|
|
|
vec3 test0(0,0,0);
|
2017-05-09 01:48:36 +02:00
|
|
|
EXPECT_FLOAT_EQ(test0.x(), 0.0);
|
|
|
|
EXPECT_FLOAT_EQ(test0.y(), 0.0);
|
|
|
|
EXPECT_FLOAT_EQ(test0.z(), 0.0);
|
2017-05-16 21:17:16 +02:00
|
|
|
vec3 vect1(4,5,8);
|
2017-05-09 01:48:36 +02:00
|
|
|
EXPECT_FLOAT_EQ(vect1.x(), 4.0);
|
|
|
|
EXPECT_FLOAT_EQ(vect1.y(), 5.0);
|
|
|
|
EXPECT_FLOAT_EQ(vect1.z(), 8.0);
|
2017-05-16 21:17:16 +02:00
|
|
|
vec3 vect2(vect1);
|
2017-05-09 01:48:36 +02:00
|
|
|
EXPECT_FLOAT_EQ(vect2.x(), 4.0);
|
|
|
|
EXPECT_FLOAT_EQ(vect2.y(), 5.0);
|
|
|
|
EXPECT_FLOAT_EQ(vect2.z(), 8.0);
|
2017-05-16 21:17:16 +02:00
|
|
|
vec3 vect3 = vect1;
|
2017-05-09 01:48:36 +02:00
|
|
|
EXPECT_FLOAT_EQ(vect3.x(), 4.0);
|
|
|
|
EXPECT_FLOAT_EQ(vect3.y(), 5.0);
|
|
|
|
EXPECT_FLOAT_EQ(vect3.z(), 8.0);
|
|
|
|
test0 = vect2;
|
|
|
|
EXPECT_FLOAT_EQ(test0.x(), 4.0);
|
|
|
|
EXPECT_FLOAT_EQ(test0.y(), 5.0);
|
|
|
|
EXPECT_FLOAT_EQ(test0.z(), 8.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(TestVector3D_f, equity) {
|
2017-05-16 21:17:16 +02:00
|
|
|
vec3 test1(99,32,56);
|
|
|
|
vec3 test2(11,22,33);
|
|
|
|
vec3 test3(11,22,33);
|
2017-05-09 01:48:36 +02:00
|
|
|
EXPECT_EQ(test1 == test2, false);
|
|
|
|
EXPECT_EQ(test1 != test2, true);
|
|
|
|
EXPECT_EQ(test3 == test2, true);
|
|
|
|
EXPECT_EQ(test3 != test2, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(TestVector3D_f, set) {
|
|
|
|
// Test contructor value
|
2017-05-16 21:17:16 +02:00
|
|
|
vec3 test1(0,0,0);
|
2017-05-09 01:48:36 +02:00
|
|
|
EXPECT_FLOAT_EQ(test1.x(), 0.0);
|
|
|
|
EXPECT_FLOAT_EQ(test1.y(), 0.0);
|
|
|
|
EXPECT_FLOAT_EQ(test1.z(), 0.0);
|
|
|
|
test1.setValue(1,2,3);
|
|
|
|
EXPECT_FLOAT_EQ(test1.x(), 1.0);
|
|
|
|
EXPECT_FLOAT_EQ(test1.y(), 2.0);
|
|
|
|
EXPECT_FLOAT_EQ(test1.z(), 3.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(TestVector3D_f, setSetZero) {
|
|
|
|
// Test contructor value
|
2017-05-16 21:17:16 +02:00
|
|
|
vec3 test1(4,5,6);
|
2017-05-09 01:48:36 +02:00
|
|
|
EXPECT_FLOAT_EQ(test1.x(), 4.0);
|
|
|
|
EXPECT_FLOAT_EQ(test1.y(), 5.0);
|
|
|
|
EXPECT_FLOAT_EQ(test1.z(), 6.0);
|
|
|
|
test1.setZero();
|
|
|
|
EXPECT_FLOAT_EQ(test1.x(), 0.0);
|
|
|
|
EXPECT_FLOAT_EQ(test1.y(), 0.0);
|
|
|
|
EXPECT_FLOAT_EQ(test1.z(), 0.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(TestVector3D_f, length) {
|
|
|
|
// Test contructor value
|
2017-05-16 21:17:16 +02:00
|
|
|
vec3 test1(0,0,0);
|
2017-05-09 01:48:36 +02:00
|
|
|
EXPECT_FLOAT_EQ(test1.length(), 0.0);
|
|
|
|
EXPECT_FLOAT_EQ(test1.length2(), 0.0);
|
|
|
|
test1.setValue(2,0,0);
|
|
|
|
EXPECT_FLOAT_EQ(test1.length(), 2.0);
|
|
|
|
test1.setValue(0,3,0);
|
|
|
|
EXPECT_FLOAT_EQ(test1.length(), 3.0);
|
|
|
|
test1.setValue(0,0,4);
|
|
|
|
EXPECT_FLOAT_EQ(test1.length(), 4.0);
|
|
|
|
test1.setValue(3,4,5);
|
|
|
|
EXPECT_FLOAT_EQ(test1.length2(), 50.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(TestVector3D_f, normalize) {
|
2017-05-16 21:17:16 +02:00
|
|
|
vec3 test1(11,22,33);
|
|
|
|
vec3 test2 = test1.normalized();
|
2017-05-09 01:48:36 +02:00
|
|
|
EXPECT_FLOAT_EQ(test1.x(), 11.0);
|
|
|
|
EXPECT_FLOAT_EQ(test1.y(), 22.0);
|
|
|
|
EXPECT_FLOAT_EQ(test1.z(), 33.0);
|
|
|
|
EXPECT_FLOAT_EQ(test2.x(), 0.26726124);
|
|
|
|
EXPECT_FLOAT_EQ(test2.y(), 0.53452247);
|
|
|
|
EXPECT_FLOAT_EQ(test2.z(), 0.80178374);
|
|
|
|
test1.normalize();
|
|
|
|
EXPECT_FLOAT_EQ(test1.x(), 0.26726124);
|
|
|
|
EXPECT_FLOAT_EQ(test1.y(), 0.53452247);
|
|
|
|
EXPECT_FLOAT_EQ(test1.z(), 0.80178374);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(TestVector3D_f, dot) {
|
2017-05-16 21:17:16 +02:00
|
|
|
vec3 test1(11,0,0);
|
|
|
|
vec3 test2(0,88,66);
|
2017-05-09 01:48:36 +02:00
|
|
|
EXPECT_FLOAT_EQ(test1.dot(test1), 121.0);
|
|
|
|
EXPECT_FLOAT_EQ(test1.dot(test2), 0.0);
|
|
|
|
test1.setValue(2,3,5);
|
|
|
|
test2.setValue(9,7,6);
|
|
|
|
EXPECT_FLOAT_EQ(test1.dot(test2), 69.0); // ????
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(TestVector3D_f, cross) {
|
2017-05-16 21:17:16 +02:00
|
|
|
vec3 test1(0,0,0);
|
|
|
|
vec3 test2(-55,88,66);
|
2017-05-09 01:48:36 +02:00
|
|
|
EXPECT_EQ(test1.cross(test1), vec3(0,0,0));
|
|
|
|
EXPECT_EQ(test2.cross(test2), vec3(0,0,0));
|
|
|
|
test1.setValue(1,0,0);
|
|
|
|
test2.setValue(0,1,0);
|
|
|
|
EXPECT_EQ(test1.cross(test2), vec3(0,0,1));
|
|
|
|
test2.setValue(0,0,1);
|
|
|
|
EXPECT_EQ(test1.cross(test2), vec3(0,-1,0));
|
|
|
|
test1.setValue(0,1,0);
|
|
|
|
EXPECT_EQ(test1.cross(test2), vec3(1,0,0));
|
|
|
|
test1.setValue(8,9,-10);
|
|
|
|
test2.setValue(2,-3,5);
|
|
|
|
EXPECT_EQ(test1.cross(test2), vec3(15,-60,-42));
|
|
|
|
}
|