Translated tests for Colliders/TrapazoidalPrismCollider
This commit is contained in:
parent
7675422264
commit
b77534a7a1
@ -29,6 +29,7 @@ add_executable(Tests
|
|||||||
Random__RandomInteger.cpp
|
Random__RandomInteger.cpp
|
||||||
Random__RandomRange.cpp
|
Random__RandomRange.cpp
|
||||||
Random_RandomIntRange.cpp
|
Random_RandomIntRange.cpp
|
||||||
|
TrapazoidalPrismCollider.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(Tests Eule)
|
target_link_libraries(Tests Eule)
|
||||||
|
@ -1,166 +1,164 @@
|
|||||||
#include "CppUnitTest.h"
|
#include "Catch2.h"
|
||||||
#include "../Eule/TrapazoidalPrismCollider.h"
|
#include <Eule/TrapazoidalPrismCollider.h>
|
||||||
#include "../Eule/Quaternion.h"
|
#include <Eule/Quaternion.h>
|
||||||
#include "../_TestingUtilities/HandyMacros.h"
|
|
||||||
#include <random>
|
#include <random>
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <sstream>
|
|
||||||
|
|
||||||
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
|
||||||
using namespace Eule;
|
using namespace Eule;
|
||||||
using TPC = TrapazoidalPrismCollider;
|
using TPC = TrapazoidalPrismCollider;
|
||||||
|
|
||||||
namespace Colliders
|
namespace {
|
||||||
{
|
static std::mt19937 rng = std::mt19937((std::random_device())());
|
||||||
TEST_CLASS(_TrapazoidalPrismCollider)
|
}
|
||||||
{
|
|
||||||
private:
|
// Tests that all vertices can be set individually, and at once
|
||||||
std::mt19937 rng;
|
TEST_CASE(__FILE__"/Can_Set_Each_Vertex", "[TrapazoidalPrismCollider][Collider]")
|
||||||
|
{
|
||||||
public:
|
// All vertex values are unique
|
||||||
// Constructor
|
TPC tpc;
|
||||||
_TrapazoidalPrismCollider()
|
tpc.SetVertex(TPC::FRONT | TPC::LEFT | TPC::BOTTOM, Vector3d(-1, -1, 1) * 1);
|
||||||
{
|
tpc.SetVertex(TPC::FRONT | TPC::LEFT | TPC::TOP, Vector3d(-1, 1, 1) * 2);
|
||||||
rng = std::mt19937((std::random_device())());
|
tpc.SetVertex(TPC::BACK | TPC::LEFT | TPC::BOTTOM, Vector3d(-1, -1, -1) * 3);
|
||||||
return;
|
tpc.SetVertex(TPC::BACK | TPC::LEFT | TPC::TOP, Vector3d(-1, 1, -1) * 4);
|
||||||
|
tpc.SetVertex(TPC::FRONT | TPC::RIGHT | TPC::BOTTOM, Vector3d(1, -1, 1) * 5);
|
||||||
}
|
tpc.SetVertex(TPC::FRONT | TPC::RIGHT | TPC::TOP, Vector3d(1, 1, 1) * 6);
|
||||||
|
tpc.SetVertex(TPC::BACK | TPC::RIGHT | TPC::BOTTOM, Vector3d(1, -1, -1) * 7);
|
||||||
// Tests that all vertices can be set individually, and at once
|
tpc.SetVertex(TPC::BACK | TPC::RIGHT | TPC::TOP, Vector3d(1, 1, -1) * 8);
|
||||||
TEST_METHOD(Can_Set_Each_Vertex)
|
|
||||||
{
|
INFO("FRONT|LEFT|BOTTOM");
|
||||||
// All vertex values are unique
|
REQUIRE(tpc.GetVertex(TPC::FRONT | TPC::LEFT | TPC::BOTTOM) == (Vector3d(-1, -1, 1) * 1));
|
||||||
TPC tpc;
|
|
||||||
tpc.SetVertex(TPC::FRONT | TPC::LEFT | TPC::BOTTOM, Vector3d(-1, -1, 1) * 1);
|
INFO("FRONT|LEFT|TOP");
|
||||||
tpc.SetVertex(TPC::FRONT | TPC::LEFT | TPC::TOP, Vector3d(-1, 1, 1) * 2);
|
REQUIRE(tpc.GetVertex(TPC::FRONT | TPC::LEFT | TPC::TOP) == (Vector3d(-1, 1, 1) * 2));
|
||||||
tpc.SetVertex(TPC::BACK | TPC::LEFT | TPC::BOTTOM, Vector3d(-1, -1, -1) * 3);
|
|
||||||
tpc.SetVertex(TPC::BACK | TPC::LEFT | TPC::TOP, Vector3d(-1, 1, -1) * 4);
|
INFO("BACK|LEFT|BOTTOM");
|
||||||
tpc.SetVertex(TPC::FRONT | TPC::RIGHT | TPC::BOTTOM, Vector3d(1, -1, 1) * 5);
|
REQUIRE(tpc.GetVertex(TPC::BACK | TPC::LEFT | TPC::BOTTOM) == (Vector3d(-1, -1, -1) * 3));
|
||||||
tpc.SetVertex(TPC::FRONT | TPC::RIGHT | TPC::TOP, Vector3d(1, 1, 1) * 6);
|
|
||||||
tpc.SetVertex(TPC::BACK | TPC::RIGHT | TPC::BOTTOM, Vector3d(1, -1, -1) * 7);
|
INFO("BACK|LEFT|TOP");
|
||||||
tpc.SetVertex(TPC::BACK | TPC::RIGHT | TPC::TOP, Vector3d(1, 1, -1) * 8);
|
REQUIRE(tpc.GetVertex(TPC::BACK | TPC::LEFT | TPC::TOP) == (Vector3d(-1, 1, -1) * 4));
|
||||||
|
|
||||||
Assert::IsTrue(tpc.GetVertex(TPC::FRONT | TPC::LEFT | TPC::BOTTOM) == (Vector3d(-1, -1, 1) * 1), L"FRONT|LEFT|BOTTOM");
|
INFO("FRONT|RIGHT|BOTTOM");
|
||||||
Assert::IsTrue(tpc.GetVertex(TPC::FRONT | TPC::LEFT | TPC::TOP) == (Vector3d(-1, 1, 1) * 2), L"FRONT|LEFT|TOP");
|
REQUIRE(tpc.GetVertex(TPC::FRONT | TPC::RIGHT | TPC::BOTTOM) == (Vector3d(1, -1, 1) * 5));
|
||||||
Assert::IsTrue(tpc.GetVertex(TPC::BACK | TPC::LEFT | TPC::BOTTOM) == (Vector3d(-1, -1, -1) * 3), L"BACK|LEFT|BOTTOM");
|
|
||||||
Assert::IsTrue(tpc.GetVertex(TPC::BACK | TPC::LEFT | TPC::TOP) == (Vector3d(-1, 1, -1) * 4), L"BACK|LEFT|TOP");
|
INFO("FRONT|RIGHT|TOP");
|
||||||
Assert::IsTrue(tpc.GetVertex(TPC::FRONT | TPC::RIGHT | TPC::BOTTOM) == (Vector3d(1, -1, 1) * 5), L"FRONT|RIGHT|BOTTOM");
|
REQUIRE(tpc.GetVertex(TPC::FRONT | TPC::RIGHT | TPC::TOP) == (Vector3d(1, 1, 1) * 6));
|
||||||
Assert::IsTrue(tpc.GetVertex(TPC::FRONT | TPC::RIGHT | TPC::TOP) == (Vector3d(1, 1, 1) * 6), L"FRONT|RIGHT|TOP");
|
|
||||||
Assert::IsTrue(tpc.GetVertex(TPC::BACK | TPC::RIGHT | TPC::BOTTOM) == (Vector3d(1, -1, -1) * 7), L"BACK|RIGHT|BOTTOM");
|
INFO("BACK|RIGHT|BOTTOM");
|
||||||
Assert::IsTrue(tpc.GetVertex(TPC::BACK | TPC::RIGHT | TPC::TOP) == (Vector3d(1, 1, -1) * 8), L"BACK|RIGHT|TOP");
|
REQUIRE(tpc.GetVertex(TPC::BACK | TPC::RIGHT | TPC::BOTTOM) == (Vector3d(1, -1, -1) * 7));
|
||||||
|
|
||||||
return;
|
INFO("BACK|RIGHT|TOP");
|
||||||
}
|
REQUIRE(tpc.GetVertex(TPC::BACK | TPC::RIGHT | TPC::TOP) == (Vector3d(1, 1, -1) * 8));
|
||||||
|
|
||||||
// Tests that points inside work.
|
return;
|
||||||
// For this, we define a few points around [0,0,0] and check if they are contained.
|
}
|
||||||
// We then rotate the collider, and check again
|
|
||||||
// Gets repeated for every possible rotation with a min-distance per axis of 2 deg
|
// Tests that points inside work.
|
||||||
TEST_METHOD(Points_Inside)
|
// For this, we define a few points around [0,0,0] and check if they are contained.
|
||||||
{
|
// We then rotate the collider, and check again
|
||||||
// Setup
|
// Gets repeated for every possible rotation with a min-distance per axis of 2 deg
|
||||||
// Define known-inside points
|
TEST_CASE(__FILE__"/Points_Inside", "[TrapazoidalPrismCollider][Collider]")
|
||||||
std::array<Vector3d, 9> knownInsides = {
|
{
|
||||||
Vector3d( 1,-1, 1),
|
// Setup
|
||||||
Vector3d(-1,-1, 1),
|
// Define known-inside points
|
||||||
Vector3d( 1, 1, 1),
|
std::array<Vector3d, 9> knownInsides = {
|
||||||
Vector3d(-1, 1, 1),
|
Vector3d( 1,-1, 1),
|
||||||
Vector3d( 1,-1,-1),
|
Vector3d(-1,-1, 1),
|
||||||
Vector3d(-1,-1,-1),
|
Vector3d( 1, 1, 1),
|
||||||
Vector3d( 1, 1,-1),
|
Vector3d(-1, 1, 1),
|
||||||
Vector3d(-1, 1,-1),
|
Vector3d( 1,-1,-1),
|
||||||
Vector3d( 0, 0, 0),
|
Vector3d(-1,-1,-1),
|
||||||
};
|
Vector3d( 1, 1,-1),
|
||||||
|
Vector3d(-1, 1,-1),
|
||||||
// Create collider, a cube of size 10^3 around the center
|
Vector3d( 0, 0, 0),
|
||||||
TPC tpc;
|
};
|
||||||
|
|
||||||
// Exercise
|
// Create collider, a cube of size 10^3 around the center
|
||||||
// Now check that these points are inside for all these possible angles
|
TPC tpc;
|
||||||
#ifndef _DEBUG
|
|
||||||
constexpr double stepSize = 2;
|
// Exercise
|
||||||
#else
|
// Now check that these points are inside for all these possible angles
|
||||||
constexpr double stepSize = 32;
|
#ifndef _DEBUG
|
||||||
#endif
|
constexpr double stepSize = 40;
|
||||||
for (double theta = 0; theta < 360.01; theta += stepSize)
|
#else
|
||||||
for (double phi = 0; phi < 360.01; phi += 2)
|
constexpr double stepSize = 32;
|
||||||
for (double alpha = 0; alpha < 360.01; alpha += stepSize)
|
#endif
|
||||||
{
|
for (double theta = 0; theta < 360.01; theta += stepSize)
|
||||||
// Rotate box
|
for (double phi = 0; phi < 360.01; phi += 2)
|
||||||
tpc.SetVertex(TPC::FRONT | TPC::LEFT | TPC::BOTTOM, Quaternion({theta, phi, alpha}) * (Vector3d(-1, -1, 1) * 10));
|
for (double alpha = 0; alpha < 360.01; alpha += stepSize)
|
||||||
tpc.SetVertex(TPC::FRONT | TPC::LEFT | TPC::TOP, Quaternion({theta, phi, alpha}) * (Vector3d(-1, 1, 1) * 10));
|
{
|
||||||
tpc.SetVertex(TPC::BACK | TPC::LEFT | TPC::BOTTOM, Quaternion({theta, phi, alpha}) * (Vector3d(-1, -1, -1) * 10));
|
// Rotate box
|
||||||
tpc.SetVertex(TPC::BACK | TPC::LEFT | TPC::TOP, Quaternion({theta, phi, alpha}) * (Vector3d(-1, 1, -1) * 10));
|
tpc.SetVertex(TPC::FRONT | TPC::LEFT | TPC::BOTTOM, Quaternion({theta, phi, alpha}) * (Vector3d(-1, -1, 1) * 10));
|
||||||
tpc.SetVertex(TPC::FRONT | TPC::RIGHT | TPC::BOTTOM, Quaternion({theta, phi, alpha}) * (Vector3d(1, -1, 1) * 10));
|
tpc.SetVertex(TPC::FRONT | TPC::LEFT | TPC::TOP, Quaternion({theta, phi, alpha}) * (Vector3d(-1, 1, 1) * 10));
|
||||||
tpc.SetVertex(TPC::FRONT | TPC::RIGHT | TPC::TOP, Quaternion({theta, phi, alpha}) * (Vector3d(1, 1, 1) * 10));
|
tpc.SetVertex(TPC::BACK | TPC::LEFT | TPC::BOTTOM, Quaternion({theta, phi, alpha}) * (Vector3d(-1, -1, -1) * 10));
|
||||||
tpc.SetVertex(TPC::BACK | TPC::RIGHT | TPC::BOTTOM, Quaternion({theta, phi, alpha}) * (Vector3d(1, -1, -1) * 10));
|
tpc.SetVertex(TPC::BACK | TPC::LEFT | TPC::TOP, Quaternion({theta, phi, alpha}) * (Vector3d(-1, 1, -1) * 10));
|
||||||
tpc.SetVertex(TPC::BACK | TPC::RIGHT | TPC::TOP, Quaternion({theta, phi, alpha}) * (Vector3d(1, 1, -1) * 10));
|
tpc.SetVertex(TPC::FRONT | TPC::RIGHT | TPC::BOTTOM, Quaternion({theta, phi, alpha}) * (Vector3d(1, -1, 1) * 10));
|
||||||
|
tpc.SetVertex(TPC::FRONT | TPC::RIGHT | TPC::TOP, Quaternion({theta, phi, alpha}) * (Vector3d(1, 1, 1) * 10));
|
||||||
// Verify
|
tpc.SetVertex(TPC::BACK | TPC::RIGHT | TPC::BOTTOM, Quaternion({theta, phi, alpha}) * (Vector3d(1, -1, -1) * 10));
|
||||||
// Verify that all are inside
|
tpc.SetVertex(TPC::BACK | TPC::RIGHT | TPC::TOP, Quaternion({theta, phi, alpha}) * (Vector3d(1, 1, -1) * 10));
|
||||||
for (const Vector3d& v : knownInsides)
|
|
||||||
Assert::IsTrue(tpc.Contains(v));
|
// Verify
|
||||||
}
|
// Verify that all are inside
|
||||||
|
for (const Vector3d& v : knownInsides)
|
||||||
return;
|
REQUIRE(tpc.Contains(v));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tests that points outside work.
|
return;
|
||||||
// For this, we define a few points that are definitely outside for various reasons and check if they are not contained.
|
}
|
||||||
// We then rotate the collider, and check again
|
|
||||||
// Gets repeated for every possible rotation with a min-distance per axis of 2 deg
|
// Tests that points outside work.
|
||||||
TEST_METHOD(Points_Outside)
|
// For this, we define a few points that are definitely outside for various reasons and check if they are not contained.
|
||||||
{
|
// We then rotate the collider, and check again
|
||||||
// Setup
|
// Gets repeated for every possible rotation with a min-distance per axis of 2 deg
|
||||||
// Define known-inside points
|
TEST_CASE(__FILE__"/Points_Outside", "[TrapazoidalPrismCollider][Collider]")
|
||||||
std::array<Vector3d, 14> knownOutsides = {
|
{
|
||||||
Vector3d(-199, 0, 0),
|
// Setup
|
||||||
Vector3d(0, -199, 0),
|
// Define known-inside points
|
||||||
Vector3d(0, 0, -199),
|
std::array<Vector3d, 14> knownOutsides = {
|
||||||
Vector3d(199, 0, 0),
|
Vector3d(-199, 0, 0),
|
||||||
Vector3d(0, 199, 0),
|
Vector3d(0, -199, 0),
|
||||||
Vector3d(0, 0, 199),
|
Vector3d(0, 0, -199),
|
||||||
Vector3d( 20, -20, 0),
|
Vector3d(199, 0, 0),
|
||||||
Vector3d(50, 50, 50),
|
Vector3d(0, 199, 0),
|
||||||
Vector3d(50, -50, 0),
|
Vector3d(0, 0, 199),
|
||||||
Vector3d( 0, 0, 29),
|
Vector3d( 20, -20, 0),
|
||||||
Vector3d( 2, 1, -18),
|
Vector3d(50, 50, 50),
|
||||||
Vector3d( -1, 29, -1),
|
Vector3d(50, -50, 0),
|
||||||
Vector3d( 0, -50, -50),
|
Vector3d( 0, 0, 29),
|
||||||
Vector3d( -50, -50, -50)
|
Vector3d( 2, 1, -18),
|
||||||
};
|
Vector3d( -1, 29, -1),
|
||||||
|
Vector3d( 0, -50, -50),
|
||||||
// Create collider, a cube of size 10^3 around the center
|
Vector3d( -50, -50, -50)
|
||||||
TPC tpc;
|
};
|
||||||
|
|
||||||
// Exercise
|
// Create collider, a cube of size 10^3 around the center
|
||||||
// Now check that these points are inside for all these possible angles
|
TPC tpc;
|
||||||
#ifndef _DEBUG
|
|
||||||
constexpr double stepSize = 2;
|
// Exercise
|
||||||
#else
|
// Now check that these points are inside for all these possible angles
|
||||||
constexpr double stepSize = 32;
|
#ifndef _DEBUG
|
||||||
#endif
|
constexpr double stepSize = 40;
|
||||||
for (double theta = 0; theta < 360.01; theta += stepSize)
|
#else
|
||||||
for (double phi = 0; phi < 360.01; phi += 2)
|
constexpr double stepSize = 32;
|
||||||
for (double alpha = 0; alpha < 360.01; alpha += stepSize)
|
#endif
|
||||||
{
|
for (double theta = 0; theta < 360.01; theta += stepSize)
|
||||||
// Rotate box
|
for (double phi = 0; phi < 360.01; phi += 2)
|
||||||
tpc.SetVertex(TPC::FRONT | TPC::LEFT | TPC::BOTTOM, Quaternion({ theta, phi, alpha }) * (Vector3d(-1, -1, 1) * 10));
|
for (double alpha = 0; alpha < 360.01; alpha += stepSize)
|
||||||
tpc.SetVertex(TPC::FRONT | TPC::LEFT | TPC::TOP, Quaternion({ theta, phi, alpha }) * (Vector3d(-1, 1, 1) * 10));
|
{
|
||||||
tpc.SetVertex(TPC::BACK | TPC::LEFT | TPC::BOTTOM, Quaternion({ theta, phi, alpha }) * (Vector3d(-1, -1, -1) * 10));
|
// Rotate box
|
||||||
tpc.SetVertex(TPC::BACK | TPC::LEFT | TPC::TOP, Quaternion({ theta, phi, alpha }) * (Vector3d(-1, 1, -1) * 10));
|
tpc.SetVertex(TPC::FRONT | TPC::LEFT | TPC::BOTTOM, Quaternion({ theta, phi, alpha }) * (Vector3d(-1, -1, 1) * 10));
|
||||||
tpc.SetVertex(TPC::FRONT | TPC::RIGHT | TPC::BOTTOM, Quaternion({ theta, phi, alpha }) * (Vector3d(1, -1, 1) * 10));
|
tpc.SetVertex(TPC::FRONT | TPC::LEFT | TPC::TOP, Quaternion({ theta, phi, alpha }) * (Vector3d(-1, 1, 1) * 10));
|
||||||
tpc.SetVertex(TPC::FRONT | TPC::RIGHT | TPC::TOP, Quaternion({ theta, phi, alpha }) * (Vector3d(1, 1, 1) * 10));
|
tpc.SetVertex(TPC::BACK | TPC::LEFT | TPC::BOTTOM, Quaternion({ theta, phi, alpha }) * (Vector3d(-1, -1, -1) * 10));
|
||||||
tpc.SetVertex(TPC::BACK | TPC::RIGHT | TPC::BOTTOM, Quaternion({ theta, phi, alpha }) * (Vector3d(1, -1, -1) * 10));
|
tpc.SetVertex(TPC::BACK | TPC::LEFT | TPC::TOP, Quaternion({ theta, phi, alpha }) * (Vector3d(-1, 1, -1) * 10));
|
||||||
tpc.SetVertex(TPC::BACK | TPC::RIGHT | TPC::TOP, Quaternion({ theta, phi, alpha }) * (Vector3d(1, 1, -1) * 10));
|
tpc.SetVertex(TPC::FRONT | TPC::RIGHT | TPC::BOTTOM, Quaternion({ theta, phi, alpha }) * (Vector3d(1, -1, 1) * 10));
|
||||||
|
tpc.SetVertex(TPC::FRONT | TPC::RIGHT | TPC::TOP, Quaternion({ theta, phi, alpha }) * (Vector3d(1, 1, 1) * 10));
|
||||||
// Verify
|
tpc.SetVertex(TPC::BACK | TPC::RIGHT | TPC::BOTTOM, Quaternion({ theta, phi, alpha }) * (Vector3d(1, -1, -1) * 10));
|
||||||
// Verify that all are inside
|
tpc.SetVertex(TPC::BACK | TPC::RIGHT | TPC::TOP, Quaternion({ theta, phi, alpha }) * (Vector3d(1, 1, -1) * 10));
|
||||||
for (const Vector3d& v : knownOutsides)
|
|
||||||
Assert::IsFalse(tpc.Contains(v));
|
// Verify
|
||||||
}
|
// Verify that all are inside
|
||||||
|
for (const Vector3d& v : knownOutsides)
|
||||||
return;
|
REQUIRE_FALSE(tpc.Contains(v));
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user