More Math cleanup

This commit is contained in:
SirLynix
2022-12-18 16:33:05 +01:00
parent a1e62adb71
commit 5ca7b398c2
15 changed files with 104 additions and 454 deletions

View File

@@ -119,7 +119,7 @@ SCENARIO("Serialization", "[CORE][SERIALIZATION]")
Nz::OrientedBoxf zeroOBB = Nz::OrientedBoxf::Zero();
Nz::OrientedBoxf copy(zeroOBB);
REQUIRE(Serialize(context, zeroOBB));
zeroOBB = Nz::OrientedBoxf(1, 1, 1, 1, 1, 1); // Random values
zeroOBB = Nz::OrientedBoxf(Nz::Boxf(1, 1, 1, 1, 1, 1)); // Random values
REQUIRE(zeroOBB != copy);
context.stream->SetCursorPos(0);
REQUIRE(Unserialize(context, &zeroOBB));

View File

@@ -26,26 +26,6 @@ SCENARIO("BoundingVolume", "[MATH][BOUNDINGVOLUME]")
}
}
WHEN("If we multiply them")
{
THEN("They should still be different")
{
nullVolume *= 5.f;
infiniteVolume = infiniteVolume * 0.5f;
REQUIRE(nullVolume != infiniteVolume);
AND_WHEN("We ask for the characteristic (infinite and null)")
{
THEN("They should still be respectively null and infinite")
{
CHECK(nullVolume.IsNull());
CHECK(infiniteVolume.IsInfinite());
}
}
}
}
WHEN("We compare two null or two infinite")
{
THEN("Everything should be ok")
@@ -58,8 +38,8 @@ SCENARIO("BoundingVolume", "[MATH][BOUNDINGVOLUME]")
GIVEN("Two same bounding volume with different constructor")
{
Nz::BoundingVolumef firstCenterAndUnit(0.f, 0.f, 0.f, 1.f, 1.f, 1.f);
Nz::BoundingVolumef secondCenterAndUnit(Nz::Vector3f::Zero(), Nz::Vector3f::Unit());
Nz::BoundingVolumef firstCenterAndUnit(Nz::Boxf(0.f, 0.f, 0.f, 1.f, 1.f, 1.f));
Nz::BoundingVolumef secondCenterAndUnit{ Nz::Boxf(Nz::Vector3f::Unit()) };
firstCenterAndUnit.Update(Nz::Matrix4f::Identity());
secondCenterAndUnit.Update(Nz::Matrix4f::Identity());
@@ -105,11 +85,11 @@ SCENARIO("BoundingVolume", "[MATH][BOUNDINGVOLUME]")
{
THEN("Compilation should be fine")
{
Nz::BoundingVolumef nullBoundingVolume = Nz::BoundingVolumef(Nz::Vector3f::Zero(), Nz::Vector3f::Zero());
Nz::BoundingVolumef nullBoundingVolume = Nz::BoundingVolumef(Nz::Boxf::Zero());
Nz::BoundingVolumef centerAndUnit = firstCenterAndUnit;
nullBoundingVolume.Update(Nz::Matrix4f::Identity());
centerAndUnit.Update(Nz::Matrix4f::Identity());
Nz::BoundingVolumef result(Nz::Vector3f::Zero(), Nz::Vector3f::Unit() * 0.5f);
Nz::BoundingVolumef result(Nz::Boxf(Nz::Vector3f::Zero(), Nz::Vector3f::Unit() * 0.5f));
result.Update(Nz::Matrix4f::Identity());
REQUIRE(Nz::BoundingVolumef::Lerp(nullBoundingVolume, centerAndUnit, 0.5f) == result);
@@ -118,7 +98,7 @@ SCENARIO("BoundingVolume", "[MATH][BOUNDINGVOLUME]")
WHEN("We lerp with special cases")
{
Nz::OrientedBoxf centerAndUnitOBB(0.f, 0.f, 0.f, 1.f, 1.f, 1.f);
Nz::OrientedBoxf centerAndUnitOBB(Nz::Boxf(0.f, 0.f, 0.f, 1.f, 1.f, 1.f));
centerAndUnitOBB.Update(Nz::Matrix4f::Identity());
Nz::BoundingVolumef centerAndUnit(centerAndUnitOBB);
@@ -128,7 +108,7 @@ SCENARIO("BoundingVolume", "[MATH][BOUNDINGVOLUME]")
THEN("Normal to null should give a smaller volume")
{
Nz::BoundingVolumef result(Nz::Vector3f::Zero(), Nz::Vector3f::Unit() * 0.5f);
Nz::BoundingVolumef result(Nz::Boxf(Nz::Vector3f::Zero(), Nz::Vector3f::Unit() * 0.5f));
result.Update(Nz::Matrix4f::Identity());
REQUIRE(Nz::BoundingVolumef::Lerp(centerAndUnit, nullBoundingVolume, 0.5f) == result);
@@ -141,7 +121,7 @@ SCENARIO("BoundingVolume", "[MATH][BOUNDINGVOLUME]")
THEN("Null to normal should give a small volume")
{
Nz::BoundingVolumef result(Nz::Vector3f::Zero(), Nz::Vector3f::Unit() * 0.5f);
Nz::BoundingVolumef result(Nz::Boxf(Nz::Vector3f::Zero(), Nz::Vector3f::Unit() * 0.5f));
result.Update(Nz::Matrix4f::Identity());
REQUIRE(Nz::BoundingVolumef::Lerp(nullBoundingVolume, centerAndUnit, 0.5f) == result);

View File

@@ -9,10 +9,10 @@ SCENARIO("Box", "[MATH][BOX]")
Nz::Boxf firstZero(Nz::Boxf::Zero());
Nz::Boxf secondZero(Nz::Vector3f::Zero(), Nz::Vector3f::Zero());
WHEN("We multiply them")
WHEN("We scale them")
{
firstZero = firstZero * 1.f;
secondZero = secondZero * Nz::Vector3f::Unit() * 3.f;
firstZero.Scale(1.f);
secondZero.Scale(Nz::Vector3f::Unit() * 3.f);
THEN("They should stay the same")
{
@@ -91,8 +91,8 @@ SCENARIO("Box", "[MATH][BOX]")
GIVEN("Two wrong box (negative width, height and depth")
{
Nz::Boxf firstWrongBox(-Nz::Vector3f::Unit());
Nz::Boxf secondWrongBox(-Nz::Vector3f::Unit());
Nz::Boxf firstWrongBox = Nz::Boxf::Invalid();
Nz::Boxf secondWrongBox = Nz::Boxf::Invalid();
WHEN("We check if valid")
{

View File

@@ -12,11 +12,11 @@ SCENARIO("Frustum", "[MATH][FRUSTUM]")
{
THEN("These results are expected")
{
Nz::BoundingVolumef bv(Nz::Vector3f::Zero(), Nz::Vector3f::Unit());
Nz::BoundingVolumef bv(Nz::Boxf(Nz::Vector3f::Zero(), Nz::Vector3f::Unit()));
bv.Update(Nz::Matrix4f::Identity());
REQUIRE(Nz::IntersectionSide::Outside == frustum.Intersect(bv));
REQUIRE(Nz::IntersectionSide::Outside == frustum.Intersect(Nz::Boxf(Nz::Vector3f::Zero(), Nz::Vector3f::Unit() * 0.9f)));
Nz::OrientedBoxf obb(Nz::Vector3f::Zero(), Nz::Vector3f::Unit() * 0.9f);
Nz::OrientedBoxf obb(Nz::Boxf(Nz::Vector3f::Zero(), Nz::Vector3f::Unit() * 0.9f));
obb.Update(Nz::Matrix4f::Identity());
REQUIRE(Nz::IntersectionSide::Outside == frustum.Intersect(obb));
REQUIRE(Nz::IntersectionSide::Outside == frustum.Intersect(Nz::Spheref(Nz::Vector3f::Zero(), 0.5f)));
@@ -31,12 +31,12 @@ SCENARIO("Frustum", "[MATH][FRUSTUM]")
{
THEN("These results are expected")
{
Nz::BoundingVolumef bv(500.f, -0.5f, -0.5f, 1.f, 1.f, 1.f);
Nz::BoundingVolumef bv(Nz::Boxf(500.f, -0.5f, -0.5f, 1.f, 1.f, 1.f));
bv.Update(Nz::Matrix4f::Identity());
REQUIRE(Nz::IntersectionSide::Inside == frustum.Intersect(bv));
REQUIRE(Nz::IntersectionSide::Inside == frustum.Intersect(Nz::Boxf(Nz::Vector3f::UnitX() * 500.f, Nz::Vector3f::Unit())));
Nz::OrientedBoxf obb(Nz::Vector3f::UnitX() * 100.f, Nz::Vector3f::Unit());
Nz::OrientedBoxf obb(Nz::Boxf(Nz::Vector3f::UnitX() * 100.f, Nz::Vector3f::Unit()));
obb.Update(Nz::Matrix4f::Identity());
REQUIRE(Nz::IntersectionSide::Inside == frustum.Intersect(obb));
REQUIRE(Nz::IntersectionSide::Inside == frustum.Intersect(Nz::Spheref(Nz::Vector3f::UnitX() * 100.f, 0.5f)));
@@ -49,11 +49,11 @@ SCENARIO("Frustum", "[MATH][FRUSTUM]")
{
THEN("These results are expected")
{
Nz::BoundingVolumef bv(0.f, -0.25f, -0.25f, 0.5f, 0.5f, 0.5f);
Nz::BoundingVolumef bv(Nz::Boxf(0.f, -0.25f, -0.25f, 0.5f, 0.5f, 0.5f));
bv.Update(Nz::Matrix4f::Identity());
CHECK(!frustum.Contains(bv));
CHECK(!frustum.Contains(Nz::Boxf(0.f, -0.25f, -0.25f, 0.5f, 0.5f, 0.5f)));
Nz::OrientedBoxf obb(0.f, -0.25f, -0.25f, 0.5f, 0.5f, 0.5f);
Nz::OrientedBoxf obb(Nz::Boxf(0.f, -0.25f, -0.25f, 0.5f, 0.5f, 0.5f));
obb.Update(Nz::Matrix4f::Identity());
CHECK(!frustum.Contains(obb));
CHECK(!frustum.Contains(Nz::Spheref(Nz::Vector3f::Zero(), 0.5f)));
@@ -66,11 +66,11 @@ SCENARIO("Frustum", "[MATH][FRUSTUM]")
{
THEN("These results are expected")
{
Nz::BoundingVolumef bv(500.f, -0.5f, -0.5f, 1.f, 1.f, 1.f);
Nz::BoundingVolumef bv(Nz::Boxf(500.f, -0.5f, -0.5f, 1.f, 1.f, 1.f));
bv.Update(Nz::Matrix4f::Identity());
CHECK(frustum.Contains(bv));
CHECK(frustum.Contains(Nz::Boxf(500.f, -0.5f, -0.5f, 1.f, 1.f, 1.f)));
Nz::OrientedBoxf obb(500.f, -0.5f, -0.5f, 1.f, 1.f, 1.f);
Nz::OrientedBoxf obb(Nz::Boxf(500.f, -0.5f, -0.5f, 1.f, 1.f, 1.f));
obb.Update(Nz::Matrix4f::Identity());
CHECK(frustum.Contains(obb));
CHECK(frustum.Contains(Nz::Spheref(Nz::Vector3f::UnitX() * 500.f, 1.f)));

View File

@@ -6,8 +6,8 @@ SCENARIO("OrientedBox", "[MATH][ORIENTEDBOX]")
{
GIVEN("Two center and unit oriented boxes")
{
Nz::OrientedBoxf firstCenterAndUnit(0.f, 0.f, 0.f, 1.f, 1.f, 1.f);
Nz::OrientedBoxf secondCenterAndUnit(Nz::OrientedBox<int>(Nz::Vector3i::Zero(), Nz::Vector3i::Unit()));
Nz::OrientedBoxf firstCenterAndUnit(Nz::Boxf(0.f, 0.f, 0.f, 1.f, 1.f, 1.f));
Nz::OrientedBoxf secondCenterAndUnit(Nz::OrientedBox<int>(Nz::Boxi(Nz::Vector3i::Zero(), Nz::Vector3i::Unit())));
firstCenterAndUnit.Update(Nz::Matrix4f::Identity());
secondCenterAndUnit.Update(Nz::Matrix4f::Identity());
@@ -33,7 +33,7 @@ SCENARIO("OrientedBox", "[MATH][ORIENTEDBOX]")
{
THEN("Results are different between operator * and update(ScaleMatrix) but corners are the same")
{
firstCenterAndUnit *= 2.f;
firstCenterAndUnit.localBox.Scale(2.f);
firstCenterAndUnit.Update(Nz::Matrix4f::Identity());
secondCenterAndUnit.Update(Nz::Matrix4f::Scale(Nz::Vector3f::Unit() * 2.f));
@@ -53,7 +53,7 @@ SCENARIO("OrientedBox", "[MATH][ORIENTEDBOX]")
Nz::OrientedBoxf centerAndUnit = firstCenterAndUnit;
nullOrientedBox.Update(Nz::Matrix4f::Identity());
centerAndUnit.Update(Nz::Matrix4f::Identity());
Nz::OrientedBoxf result(Nz::Vector3f::Zero(), Nz::Vector3f::Unit() * 0.5f);
Nz::OrientedBoxf result(Nz::Boxf(Nz::Vector3f::Zero(), Nz::Vector3f::Unit() * 0.5f));
result.Update(Nz::Matrix4f::Identity());
REQUIRE(Nz::OrientedBoxf::Lerp(nullOrientedBox, centerAndUnit, 0.5f) == result);

View File

@@ -70,14 +70,14 @@ SCENARIO("Ray", "[MATH][RAY]")
float tmpClosest;
float tmpFurthest;
Nz::OrientedBoxf obb(-0.5f, 1.f, -0.5f, 1.f, 1.f, 1.f);
Nz::OrientedBoxf obb(Nz::Boxf(-0.5f, 1.f, -0.5f, 1.f, 1.f, 1.f));
obb.Update(Nz::Matrix4f::Rotate(Nz::EulerAnglesf(0.f, 90.f, 0.f).ToQuaternion()));
CHECK(ray.Intersect(obb, &tmpClosest, &tmpFurthest));
REQUIRE(ray.GetPoint(tmpClosest) == Nz::Vector3f::UnitY());
REQUIRE(ray.GetPoint(tmpFurthest) == (Nz::Vector3f::UnitY() * 2.f));
obb = Nz::OrientedBoxf(-10.f, 1.f, -10.f, 1.f, 1.f, 1.f);
obb = Nz::OrientedBoxf(Nz::Boxf(-10.f, 1.f, -10.f, 1.f, 1.f, 1.f));
obb.Update(Nz::Matrix4f::Rotate(Nz::EulerAnglesf(0.f, 0.f, 90.f).ToQuaternion()));
CHECK(!ray.Intersect(obb, &tmpClosest, &tmpFurthest));
}

View File

@@ -36,7 +36,7 @@ SCENARIO("Rect", "[MATH][RECT]")
{
THEN("It's not valid")
{
CHECK(!(firstCenterAndUnit * 0.f).IsValid());
CHECK(!(firstCenterAndUnit.Scale(0.f)).IsValid());
}
}