Initial commit
This commit is contained in:
104
test/math/quat.h
Normal file
104
test/math/quat.h
Normal file
@@ -0,0 +1,104 @@
|
||||
#include <cxxtest/TestSuite.h>
|
||||
|
||||
#include "math/quat.h"
|
||||
|
||||
class QuatTestSuite : public CxxTest::TestSuite {
|
||||
public:
|
||||
// Test Constructors
|
||||
void test_Quaternion() {
|
||||
// Create an empty unit quaternion
|
||||
Math::Quaternion q;
|
||||
|
||||
TS_ASSERT(q.x() == 0.0f);
|
||||
TS_ASSERT(q.y() == 0.0f);
|
||||
TS_ASSERT(q.z() == 0.0f);
|
||||
TS_ASSERT(q.w() == 1.0f);
|
||||
}
|
||||
|
||||
// Test Normalization
|
||||
void test_Normalize() {
|
||||
Math::Quaternion q(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
q.normalize();
|
||||
|
||||
// Check the values against the known result
|
||||
TS_ASSERT(fabs(q.x() - 0.182574f) < 0.0001f);
|
||||
TS_ASSERT(fabs(q.y() - 0.365148f) < 0.0001f);
|
||||
TS_ASSERT(fabs(q.z() - 0.547723f) < 0.0001f);
|
||||
TS_ASSERT(fabs(q.w() - 0.730297f) < 0.0001f);
|
||||
|
||||
// Check that the RMS is 1.0
|
||||
float r = sqrt(q.x() * q.x() + q.y() * q.y() + q.z() * q.z() + q.w() * q.w());
|
||||
TS_ASSERT(fabs(r - 1.0f) < 0.0001f);
|
||||
}
|
||||
|
||||
// Test going to a matrix and back
|
||||
void test_quatMatrix() {
|
||||
Math::Angle xAngle(20);
|
||||
Math::Angle yAngle(30);
|
||||
Math::Angle zAngle(40);
|
||||
|
||||
Math::Quaternion q = Math::Quaternion::fromEuler(xAngle, yAngle, zAngle, Math::EO_XYZ);
|
||||
Math::Matrix4 m = q.toMatrix();
|
||||
|
||||
Math::Quaternion r(m);
|
||||
|
||||
// Compare
|
||||
TS_ASSERT(fabs(q.x() - r.x()) < 0.0001f);
|
||||
TS_ASSERT(fabs(q.y() - r.y()) < 0.0001f);
|
||||
TS_ASSERT(fabs(q.z() - r.z()) < 0.0001f);
|
||||
TS_ASSERT(fabs(q.w() - r.w()) < 0.0001f);
|
||||
}
|
||||
|
||||
// Test rotations
|
||||
void test_quatRotationXYZ() {
|
||||
Math::Angle xAngle(20);
|
||||
Math::Angle yAngle(30);
|
||||
Math::Angle zAngle(40);
|
||||
|
||||
// First way
|
||||
Math::Quaternion q;
|
||||
q = Math::Quaternion::xAxis(xAngle);
|
||||
q *= Math::Quaternion::yAxis(yAngle);
|
||||
q *= Math::Quaternion::zAxis(zAngle);
|
||||
|
||||
// Second way
|
||||
Math::Quaternion r = Math::Quaternion::fromEuler(xAngle, yAngle, zAngle, Math::EO_XYZ);
|
||||
|
||||
// Compare to the known correct result
|
||||
TS_ASSERT(fabs(q.x() - 0.244792f) < 0.0001f);
|
||||
TS_ASSERT(fabs(q.y() - 0.182148f) < 0.0001f);
|
||||
TS_ASSERT(fabs(q.z() - 0.36758f) < 0.0001f);
|
||||
TS_ASSERT(fabs(q.w() - 0.878512f) < 0.0001f);
|
||||
|
||||
// Compare to the known correct result
|
||||
TS_ASSERT(fabs(r.x() - 0.244792f) < 0.0001f);
|
||||
TS_ASSERT(fabs(r.y() - 0.182148f) < 0.0001f);
|
||||
TS_ASSERT(fabs(r.z() - 0.36758f) < 0.0001f);
|
||||
TS_ASSERT(fabs(r.w() - 0.878512f) < 0.0001f);
|
||||
}
|
||||
|
||||
void test_quatAngleBetween() {
|
||||
Math::Angle a1(10);
|
||||
Math::Angle a2(20);
|
||||
Math::Quaternion q = Math::Quaternion::fromEuler(a1,0,0, Math::EO_XYZ);
|
||||
Math::Quaternion r = Math::Quaternion::fromEuler(a2,0,0, Math::EO_XYZ);
|
||||
|
||||
Math::Angle a = q.getAngleBetween(r);
|
||||
|
||||
TS_ASSERT(fabs(a.getDegrees() - 10) < 0.0001f);
|
||||
}
|
||||
|
||||
void test_invert() {
|
||||
Math::Angle a1(50);
|
||||
Math::Angle a2(30);
|
||||
Math::Angle a3(10);
|
||||
|
||||
Math::Quaternion q = Math::Quaternion::fromEuler(a1, a2, a3, Math::EO_XYZ);
|
||||
Math::Quaternion r = q.inverse();
|
||||
|
||||
TS_ASSERT(r.x() == -q.x());
|
||||
TS_ASSERT(r.y() == -q.y());
|
||||
TS_ASSERT(r.z() == -q.z());
|
||||
TS_ASSERT(r.w() == q.w());
|
||||
}
|
||||
};
|
||||
62
test/math/ray.h
Normal file
62
test/math/ray.h
Normal file
@@ -0,0 +1,62 @@
|
||||
#include <cxxtest/TestSuite.h>
|
||||
|
||||
#include "math/ray.h"
|
||||
|
||||
class RayTestSuite : public CxxTest::TestSuite {
|
||||
public:
|
||||
// Test Constructors
|
||||
void test_Ray() {
|
||||
Math::Ray r;
|
||||
|
||||
TS_ASSERT(r.getOrigin() == Math::Vector3d());
|
||||
TS_ASSERT(r.getDirection() == Math::Vector3d());
|
||||
|
||||
Math::Vector3d o(3, 2, 1);
|
||||
Math::Vector3d d(0, 1, 2);
|
||||
|
||||
Math::Ray r2(o, d);
|
||||
|
||||
TS_ASSERT(r2.getOrigin() == o);
|
||||
TS_ASSERT(r2.getDirection() == d);
|
||||
}
|
||||
|
||||
void test_translate() {
|
||||
Math::Vector3d o(3, 2, 1);
|
||||
Math::Vector3d d(0, 1, 2);
|
||||
Math::Ray r(o, d);
|
||||
|
||||
r.translate(Math::Vector3d(0.5f, 0.2f, 0.1f));
|
||||
TS_ASSERT(r.getDirection() == d);
|
||||
Math::Vector3d o2 = r.getOrigin();
|
||||
|
||||
TS_ASSERT_DELTA(o2.x(), 3.5, 0.0001);
|
||||
TS_ASSERT_DELTA(o2.y(), 2.2, 0.0001);
|
||||
TS_ASSERT_DELTA(o2.z(), 1.1, 0.0001);
|
||||
}
|
||||
|
||||
// TODO: Add tests for transform, rotate, rotateDirection, intersectAABB
|
||||
void test_intersectTriangle() {
|
||||
// A triangle that covers around the origin on the y plane.
|
||||
const Math::Vector3d v1(0, 0, -20);
|
||||
const Math::Vector3d v2(0, -10, 20);
|
||||
const Math::Vector3d v3(0, 10, 20);
|
||||
|
||||
// A ray that points along the x axis, should hit the triangle at the origin
|
||||
Math::Ray r(Math::Vector3d(-9.5f, 0, 0.7f), Math::Vector3d(1, 0, 0));
|
||||
|
||||
Math::Vector3d loc(7, 8, 9); // add values to ensure it's changed
|
||||
float dist = 99.0f;
|
||||
bool result = r.intersectTriangle(v1, v2, v3, loc, dist);
|
||||
// Should hit at the origin
|
||||
TS_ASSERT(result);
|
||||
TS_ASSERT_DELTA(dist, 9.5f, 0.0001);
|
||||
TS_ASSERT_DELTA(loc.x(), 0.0f, 0.0001);
|
||||
TS_ASSERT_DELTA(loc.y(), 0.0f, 0.0001);
|
||||
TS_ASSERT_DELTA(loc.z(), 0.7f, 0.0001);
|
||||
|
||||
// A ray that points along the x axis in the opposite direction, should never hit the triangle
|
||||
Math::Ray r2(Math::Vector3d(-1, 0, 0), Math::Vector3d(-1, 0, 0));
|
||||
result = r2.intersectTriangle(v1, v2, v3, loc, dist);
|
||||
TS_ASSERT(!result);
|
||||
}
|
||||
};
|
||||
198
test/math/rotation3d.h
Normal file
198
test/math/rotation3d.h
Normal file
@@ -0,0 +1,198 @@
|
||||
#include <cxxtest/TestSuite.h>
|
||||
|
||||
#include "math/matrix4.h"
|
||||
|
||||
class Rotation3DTestSuite : public CxxTest::TestSuite {
|
||||
public:
|
||||
void test_eulerXYX() {
|
||||
Math::Angle x(20);
|
||||
Math::Angle y(30);
|
||||
Math::Angle z(40);
|
||||
Math::Angle xx, yy, zz;
|
||||
|
||||
// Test going to matrix and back
|
||||
Math::Matrix4 rotMat;
|
||||
rotMat.buildFromEuler(x, y, z, Math::EO_XYX);
|
||||
rotMat.getEuler(&xx, &yy, &zz, Math::EO_XYX);
|
||||
|
||||
TS_ASSERT(x == xx);
|
||||
TS_ASSERT(y == yy);
|
||||
TS_ASSERT(z == zz);
|
||||
}
|
||||
|
||||
void test_eulerXYZ() {
|
||||
Math::Angle x(20);
|
||||
Math::Angle y(30);
|
||||
Math::Angle z(40);
|
||||
Math::Angle xx, yy, zz;
|
||||
|
||||
// Test going to matrix and back
|
||||
Math::Matrix4 rotMat;
|
||||
rotMat.buildFromEuler(x, y, z, Math::EO_XYZ);
|
||||
rotMat.getEuler(&xx, &yy, &zz, Math::EO_XYZ);
|
||||
|
||||
TS_ASSERT(x == xx);
|
||||
TS_ASSERT(y == yy);
|
||||
TS_ASSERT(z == zz);
|
||||
}
|
||||
|
||||
void test_eulerXZX() {
|
||||
Math::Angle x(20);
|
||||
Math::Angle y(30);
|
||||
Math::Angle z(40);
|
||||
Math::Angle xx, yy, zz;
|
||||
|
||||
// Test going to matrix and back
|
||||
Math::Matrix4 rotMat;
|
||||
rotMat.buildFromEuler(x, y, z, Math::EO_XZX);
|
||||
rotMat.getEuler(&xx, &yy, &zz, Math::EO_XZX);
|
||||
|
||||
TS_ASSERT(x == xx);
|
||||
TS_ASSERT(y == yy);
|
||||
TS_ASSERT(z == zz);
|
||||
}
|
||||
|
||||
void test_eulerXZY() {
|
||||
Math::Angle x(20);
|
||||
Math::Angle y(30);
|
||||
Math::Angle z(40);
|
||||
Math::Angle xx, yy, zz;
|
||||
|
||||
// Test going to matrix and back
|
||||
Math::Matrix4 rotMat;
|
||||
rotMat.buildFromEuler(x, y, z, Math::EO_XZY);
|
||||
rotMat.getEuler(&xx, &yy, &zz, Math::EO_XZY);
|
||||
|
||||
TS_ASSERT(x == xx);
|
||||
TS_ASSERT(y == yy);
|
||||
TS_ASSERT(z == zz);
|
||||
}
|
||||
|
||||
void test_eulerYXY() {
|
||||
Math::Angle x(20);
|
||||
Math::Angle y(30);
|
||||
Math::Angle z(40);
|
||||
Math::Angle xx, yy, zz;
|
||||
|
||||
// Test going to matrix and back
|
||||
Math::Matrix4 rotMat;
|
||||
rotMat.buildFromEuler(x, y, z, Math::EO_YXY);
|
||||
rotMat.getEuler(&xx, &yy, &zz, Math::EO_YXY);
|
||||
|
||||
TS_ASSERT(x == xx);
|
||||
TS_ASSERT(y == yy);
|
||||
TS_ASSERT(z == zz);
|
||||
}
|
||||
|
||||
void test_eulerYXZ() {
|
||||
Math::Angle x(20);
|
||||
Math::Angle y(30);
|
||||
Math::Angle z(40);
|
||||
Math::Angle xx, yy, zz;
|
||||
|
||||
// Test going to matrix and back
|
||||
Math::Matrix4 rotMat;
|
||||
rotMat.buildFromEuler(x, y, z, Math::EO_YXZ);
|
||||
rotMat.getEuler(&xx, &yy, &zz, Math::EO_YXZ);
|
||||
|
||||
TS_ASSERT(x == xx);
|
||||
TS_ASSERT(y == yy);
|
||||
TS_ASSERT(z == zz);
|
||||
}
|
||||
|
||||
void test_eulerYZX() {
|
||||
Math::Angle x(20);
|
||||
Math::Angle y(30);
|
||||
Math::Angle z(40);
|
||||
Math::Angle xx, yy, zz;
|
||||
|
||||
// Test going to matrix and back
|
||||
Math::Matrix4 rotMat;
|
||||
rotMat.buildFromEuler(x, y, z, Math::EO_YZX);
|
||||
rotMat.getEuler(&xx, &yy, &zz, Math::EO_YZX);
|
||||
|
||||
TS_ASSERT(x == xx);
|
||||
TS_ASSERT(y == yy);
|
||||
TS_ASSERT(z == zz);
|
||||
}
|
||||
|
||||
void test_eulerYZY() {
|
||||
Math::Angle x(20);
|
||||
Math::Angle y(30);
|
||||
Math::Angle z(40);
|
||||
Math::Angle xx, yy ,zz;
|
||||
|
||||
// Test going to matrix and back
|
||||
Math::Matrix4 rotMat;
|
||||
rotMat.buildFromEuler(x, y, z, Math::EO_YZY);
|
||||
rotMat.getEuler(&xx, &yy, &zz, Math::EO_YZY);
|
||||
|
||||
TS_ASSERT(x == xx);
|
||||
TS_ASSERT(y == yy);
|
||||
TS_ASSERT(z == zz);
|
||||
}
|
||||
|
||||
void test_eulerZXY() {
|
||||
Math::Angle x(20);
|
||||
Math::Angle y(30);
|
||||
Math::Angle z(40);
|
||||
Math::Angle xx, yy, zz;
|
||||
|
||||
// Test going to matrix and back
|
||||
Math::Matrix4 rotMat;
|
||||
rotMat.buildFromEuler(x, y, z, Math::EO_ZXY);
|
||||
rotMat.getEuler(&xx, &yy, &zz, Math::EO_ZXY);
|
||||
|
||||
TS_ASSERT(x == xx);
|
||||
TS_ASSERT(y == yy);
|
||||
TS_ASSERT(z == zz);
|
||||
}
|
||||
|
||||
void test_eulerZXZ() {
|
||||
Math::Angle x(20);
|
||||
Math::Angle y(30);
|
||||
Math::Angle z(40);
|
||||
Math::Angle xx, yy, zz;
|
||||
|
||||
// Test going to matrix and back
|
||||
Math::Matrix4 rotMat;
|
||||
rotMat.buildFromEuler(x, y, z, Math::EO_ZXZ);
|
||||
rotMat.getEuler(&xx, &yy, &zz, Math::EO_ZXZ);
|
||||
|
||||
TS_ASSERT(x == xx);
|
||||
TS_ASSERT(y == yy);
|
||||
TS_ASSERT(z == zz);
|
||||
}
|
||||
|
||||
void test_eulerZYX() {
|
||||
Math::Angle x(20);
|
||||
Math::Angle y(30);
|
||||
Math::Angle z(40);
|
||||
Math::Angle xx, yy, zz;
|
||||
|
||||
// Test going to matrix and back
|
||||
Math::Matrix4 rotMat;
|
||||
rotMat.buildFromEuler(x, y, z, Math::EO_ZYX);
|
||||
rotMat.getEuler(&xx, &yy, &zz, Math::EO_ZYX);
|
||||
|
||||
TS_ASSERT(x == xx);
|
||||
TS_ASSERT(y == yy);
|
||||
TS_ASSERT(z == zz);
|
||||
}
|
||||
|
||||
void test_eulerZYZ() {
|
||||
Math::Angle x(20);
|
||||
Math::Angle y(30);
|
||||
Math::Angle z(40);
|
||||
Math::Angle xx, yy, zz;
|
||||
|
||||
// Test going to matrix and back
|
||||
Math::Matrix4 rotMat;
|
||||
rotMat.buildFromEuler(x, y, z, Math::EO_ZYZ);
|
||||
rotMat.getEuler(&xx, &yy, &zz, Math::EO_ZYZ);
|
||||
|
||||
TS_ASSERT(x == xx);
|
||||
TS_ASSERT(y == yy);
|
||||
TS_ASSERT(z == zz);
|
||||
}
|
||||
};
|
||||
35
test/math/utils.h
Normal file
35
test/math/utils.h
Normal file
@@ -0,0 +1,35 @@
|
||||
#include <cxxtest/TestSuite.h>
|
||||
|
||||
#include "math/utils.h"
|
||||
|
||||
const float MAX_ERROR_FLT = 1e-7f;
|
||||
const double MAX_ERROR_DBL = 1e-15;
|
||||
class MathUtilsTestSuite : public CxxTest::TestSuite
|
||||
{
|
||||
public:
|
||||
void test_rad2deg() {
|
||||
//float verion
|
||||
TS_ASSERT_DELTA(Math::rad2deg(0), 0, MAX_ERROR_FLT);
|
||||
TS_ASSERT_DELTA(Math::rad2deg(M_PI), 180.0, 180.0 * MAX_ERROR_FLT);
|
||||
TS_ASSERT_DELTA(Math::rad2deg(2.0 * M_PI), 360.0, 360.0 * MAX_ERROR_FLT);
|
||||
TS_ASSERT_DELTA(Math::rad2deg(M_PI / 2.0), 90.0, 90.0 * MAX_ERROR_FLT);
|
||||
//double version
|
||||
TS_ASSERT_DELTA(Math::rad2deg<double>(0), 0, MAX_ERROR_DBL);
|
||||
TS_ASSERT_DELTA(Math::rad2deg<double>(M_PI), 180.0, 180.0 * MAX_ERROR_DBL);
|
||||
TS_ASSERT_DELTA(Math::rad2deg<double>(2.0 * M_PI), 360.0, 360.0 * MAX_ERROR_DBL);
|
||||
TS_ASSERT_DELTA(Math::rad2deg<double>(M_PI / 2.0), 90.0, 90.0 * MAX_ERROR_DBL);
|
||||
}
|
||||
|
||||
void test_deg2rad() {
|
||||
//float verion
|
||||
TS_ASSERT_DELTA(Math::deg2rad(0), 0, MAX_ERROR_FLT);
|
||||
TS_ASSERT_DELTA(Math::deg2rad(180.0), M_PI, M_PI * MAX_ERROR_FLT);
|
||||
TS_ASSERT_DELTA(Math::deg2rad(360.0), 2.0 * M_PI, 2.0 * M_PI * MAX_ERROR_FLT);
|
||||
TS_ASSERT_DELTA(Math::deg2rad(90.0), M_PI / 2.0, M_PI / 2.0 * MAX_ERROR_FLT);
|
||||
//double version
|
||||
TS_ASSERT_DELTA(Math::deg2rad<double>(0), 0, MAX_ERROR_DBL);
|
||||
TS_ASSERT_DELTA(Math::deg2rad<double>(180.0), M_PI, M_PI * MAX_ERROR_DBL);
|
||||
TS_ASSERT_DELTA(Math::deg2rad<double>(360.0), 2.0 * M_PI, 2.0 * M_PI * MAX_ERROR_DBL);
|
||||
TS_ASSERT_DELTA(Math::deg2rad<double>(90.0), M_PI / 2.0, M_PI / 2.0 * MAX_ERROR_DBL);
|
||||
}
|
||||
};
|
||||
144
test/math/vector3d.h
Normal file
144
test/math/vector3d.h
Normal file
@@ -0,0 +1,144 @@
|
||||
#include <cxxtest/TestSuite.h>
|
||||
|
||||
#include "math/vector3d.h"
|
||||
|
||||
class Vector3dTestSuite : public CxxTest::TestSuite {
|
||||
public:
|
||||
// Test Constructors
|
||||
void test_Vector3d() {
|
||||
Math::Vector3d v;
|
||||
|
||||
TS_ASSERT(v.x() == 0.0f);
|
||||
TS_ASSERT(v.y() == 0.0f);
|
||||
TS_ASSERT(v.z() == 0.0f);
|
||||
|
||||
Math::Vector3d v2(3, 2.25, 1);
|
||||
|
||||
TS_ASSERT(v2.x() == 3.0f);
|
||||
TS_ASSERT(v2.y() == 2.25f);
|
||||
TS_ASSERT(v2.z() == 1.0f);
|
||||
|
||||
Math::Vector3d v3(v2);
|
||||
|
||||
TS_ASSERT(v3.x() == 3.0f);
|
||||
TS_ASSERT(v3.y() == 2.25f);
|
||||
TS_ASSERT(v3.z() == 1.0f);
|
||||
}
|
||||
|
||||
void test_set() {
|
||||
Math::Vector3d v(2, 4, 6);
|
||||
v.set(1, 2, 3);
|
||||
|
||||
TS_ASSERT(v.x() == 1.0f);
|
||||
TS_ASSERT(v.y() == 2.0f);
|
||||
TS_ASSERT(v.z() == 3.0f);
|
||||
}
|
||||
|
||||
void test_crossProduct() {
|
||||
Math::Vector3d v1(1, 0, 0);
|
||||
Math::Vector3d v2(0, 1, 0);
|
||||
|
||||
Math::Vector3d c12 = Math::Vector3d::crossProduct(v1, v2);
|
||||
Math::Vector3d c21 = Math::Vector3d::crossProduct(v2, v1);
|
||||
|
||||
TS_ASSERT(c12 == Math::Vector3d(0, 0, 1));
|
||||
TS_ASSERT(c21 == Math::Vector3d(0, 0, -1));
|
||||
}
|
||||
|
||||
void test_length() {
|
||||
Math::Vector3d v(1, 0, 1);
|
||||
TS_ASSERT_DELTA(v.length(), sqrt(2), 0.0001);
|
||||
|
||||
Math::Vector3d v2(2, 2, 2);
|
||||
TS_ASSERT_DELTA(v2.length(), sqrt(12), 0.0001);
|
||||
|
||||
// check static version too
|
||||
TS_ASSERT_DELTA(Math::Vector3d::length(v2), v2.length(), 0.0001);
|
||||
}
|
||||
|
||||
void test_interpolate() {
|
||||
Math::Vector3d v1(1, 0, 2);
|
||||
Math::Vector3d v2(0, 5, 3);
|
||||
|
||||
Math::Vector3d int1 = Math::Vector3d::interpolate(v1, v2, 0.1f);
|
||||
TS_ASSERT_DELTA(int1.x(), 0.9, 0.0001);
|
||||
TS_ASSERT_DELTA(int1.y(), 0.5, 0.0001);
|
||||
TS_ASSERT_DELTA(int1.z(), 2.1, 0.0001);
|
||||
}
|
||||
|
||||
/* all the below tests are for functions in Math::Vector, but add tests
|
||||
* here as we can't directly instantiate that */
|
||||
|
||||
void test_setValue() {
|
||||
Math::Vector3d v(3, 7, 9);
|
||||
|
||||
v.setValue(0, 1);
|
||||
TS_ASSERT(v.x() == 1.0f);
|
||||
TS_ASSERT(v.y() == 7.0f);
|
||||
TS_ASSERT(v.z() == 9.0f);
|
||||
|
||||
v.setValue(1, 3);
|
||||
v.setValue(2, 2);
|
||||
TS_ASSERT(v.x() == 1.0f);
|
||||
TS_ASSERT(v.y() == 3.0f);
|
||||
TS_ASSERT(v.z() == 2.0f);
|
||||
}
|
||||
|
||||
void test_getValue() {
|
||||
Math::Vector3d v(5, 6, 7);
|
||||
|
||||
TS_ASSERT(v.getValue(0) == 5.0f);
|
||||
TS_ASSERT(v.getValue(1) == 6.0f);
|
||||
TS_ASSERT(v.getValue(2) == 7.0f);
|
||||
}
|
||||
|
||||
void test_dotProduct() {
|
||||
Math::Vector3d v1(1, 2, 3);
|
||||
Math::Vector3d v2(6, 5, 4);
|
||||
|
||||
float result = v2.dotProduct(v1);
|
||||
|
||||
TS_ASSERT_DELTA(result, 28.0f, 0.0001f);
|
||||
}
|
||||
|
||||
void test_dotProductOrthogonal() {
|
||||
Math::Vector3d v1(6, 0, 0);
|
||||
Math::Vector3d v2(0, 9, 0);
|
||||
|
||||
float result = v2.dotProduct(v1);
|
||||
|
||||
TS_ASSERT_EQUALS(result, 0.0f);
|
||||
}
|
||||
|
||||
void test_normalizeTrivial() {
|
||||
Math::Vector3d v(0, 1, 0);
|
||||
|
||||
Math::Vector3d vn = v.getNormalized();
|
||||
|
||||
v.normalize();
|
||||
|
||||
TS_ASSERT_EQUALS(vn, v);
|
||||
TS_ASSERT(v.x() == 0);
|
||||
TS_ASSERT(v.y() == 1);
|
||||
TS_ASSERT(v.z() == 0);
|
||||
}
|
||||
|
||||
void test_normalize() {
|
||||
Math::Vector3d v(2, 4, 6);
|
||||
|
||||
Math::Vector3d vn = v.getNormalized();
|
||||
v.normalize();
|
||||
|
||||
TS_ASSERT_EQUALS(vn, v);
|
||||
TS_ASSERT_DELTA(v.x(), 2 / sqrt(56), 0.0001);
|
||||
TS_ASSERT_DELTA(v.y(), 4 / sqrt(56), 0.0001);
|
||||
TS_ASSERT_DELTA(v.z(), 6 / sqrt(56), 0.0001);
|
||||
}
|
||||
|
||||
void test_magnitude() {
|
||||
Math::Vector3d v(3, 2.5, 1);
|
||||
|
||||
TS_ASSERT_DELTA(v.getMagnitude(), sqrt(16.25), 0.0001);
|
||||
}
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user