Improve math module (#396)
* Improve math module - Mark almost everything constexpr - Equality (a == b) is now exact, down to the bit level. If you want approximate equality use the new ApproxEqual method/static method - Rename Nz::Extend to Nz::Extent - Removed Make[] and Set[] methods in favor of their static counterpart and operator=
This commit is contained in:
@@ -196,7 +196,7 @@ SCENARIO("Angle", "[MATH][ANGLE]")
|
||||
{
|
||||
Nz::RadianAnglef expectedResult(Nz::Pi<float>);
|
||||
|
||||
CHECK(angle == expectedResult);
|
||||
CHECK(angle.ApproxEqual(expectedResult));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -213,7 +213,7 @@ SCENARIO("Angle", "[MATH][ANGLE]")
|
||||
{
|
||||
Nz::RadianAnglef expectedResult(0.f);
|
||||
|
||||
CHECK(angle == expectedResult);
|
||||
CHECK(angle.ApproxEqual(expectedResult));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -230,7 +230,7 @@ SCENARIO("Angle", "[MATH][ANGLE]")
|
||||
{
|
||||
Nz::TurnAnglef expectedResult(0.5f);
|
||||
|
||||
CHECK(angle == expectedResult);
|
||||
CHECK(angle.ApproxEqual(expectedResult));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,8 +65,10 @@ SCENARIO("BoundingVolume", "[MATH][BOUNDINGVOLUME]")
|
||||
THEN("There's no problem")
|
||||
{
|
||||
Nz::BoundingVolume<int> intVolumeCenterAndUnit(Nz::Boxi(Nz::Vector3i::Zero(), Nz::Vector3i::Unit()));
|
||||
intVolumeCenterAndUnit.Update(Nz::Vector3i::Zero());
|
||||
|
||||
Nz::BoundingVolumef thirdCenterAndUnit(intVolumeCenterAndUnit);
|
||||
REQUIRE(thirdCenterAndUnit == secondCenterAndUnit);
|
||||
REQUIRE(thirdCenterAndUnit.ApproxEqual(secondCenterAndUnit));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,7 +94,10 @@ SCENARIO("BoundingVolume", "[MATH][BOUNDINGVOLUME]")
|
||||
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);
|
||||
Nz::BoundingVolumef lerpVolume = Nz::BoundingVolumef::Lerp(nullBoundingVolume, centerAndUnit, 0.5f);
|
||||
lerpVolume.Update(Nz::Matrix4f::Identity());
|
||||
|
||||
REQUIRE(Nz::BoundingVolumef::ApproxEqual(lerpVolume, result));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,20 +108,23 @@ SCENARIO("BoundingVolume", "[MATH][BOUNDINGVOLUME]")
|
||||
|
||||
Nz::BoundingVolumef centerAndUnit(centerAndUnitOBB);
|
||||
|
||||
Nz::BoundingVolumef nullBoundingVolume(Nz::Extend::Null);
|
||||
Nz::BoundingVolumef infiniteBoundingVolume(Nz::Extend::Infinite);
|
||||
Nz::BoundingVolumef nullBoundingVolume(Nz::Extent::Null);
|
||||
Nz::BoundingVolumef infiniteBoundingVolume(Nz::Extent::Infinite);
|
||||
|
||||
THEN("Normal to null should give a smaller volume")
|
||||
{
|
||||
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);
|
||||
Nz::BoundingVolumef lerpVolume = Nz::BoundingVolumef::Lerp(centerAndUnit, nullBoundingVolume, 0.5f);
|
||||
lerpVolume.Update(Nz::Matrix4f::Identity());
|
||||
|
||||
REQUIRE(lerpVolume.ApproxEqual(result));
|
||||
}
|
||||
|
||||
THEN("Normal to infinite should give an infinite volume")
|
||||
{
|
||||
REQUIRE(Nz::BoundingVolumef::Lerp(centerAndUnit, infiniteBoundingVolume, 0.5f) == infiniteBoundingVolume);
|
||||
REQUIRE(Nz::BoundingVolumef::Lerp(centerAndUnit, infiniteBoundingVolume, 0.5f).ApproxEqual(infiniteBoundingVolume));
|
||||
}
|
||||
|
||||
THEN("Null to normal should give a small volume")
|
||||
@@ -124,7 +132,10 @@ SCENARIO("BoundingVolume", "[MATH][BOUNDINGVOLUME]")
|
||||
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);
|
||||
Nz::BoundingVolumef lerpVolume = Nz::BoundingVolumef::Lerp(nullBoundingVolume, centerAndUnit, 0.5f);
|
||||
lerpVolume.Update(Nz::Matrix4f::Identity());
|
||||
|
||||
REQUIRE(lerpVolume.ApproxEqual(result));
|
||||
}
|
||||
|
||||
THEN("Infinite to normal should give an infinite volume")
|
||||
|
||||
@@ -58,9 +58,9 @@ SCENARIO("EulerAngles", "[MATH][EULERANGLES]")
|
||||
Nz::Vector3f rotation90Y = euler90Y.ToQuaternion() * Nz::Vector3f::UnitZ();
|
||||
Nz::Vector3f rotation90R = euler90R.ToQuaternion() * Nz::Vector3f::UnitX();
|
||||
|
||||
CHECK(rotation90P == Nz::Vector3f::UnitZ());
|
||||
CHECK(rotation90Y == Nz::Vector3f::UnitX());
|
||||
CHECK(rotation90R == Nz::Vector3f::UnitY());
|
||||
CHECK(rotation90P.ApproxEqual(Nz::Vector3f::UnitZ()));
|
||||
CHECK(rotation90Y.ApproxEqual(Nz::Vector3f::UnitX()));
|
||||
CHECK(rotation90R.ApproxEqual(Nz::Vector3f::UnitY()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -71,9 +71,9 @@ SCENARIO("EulerAngles", "[MATH][EULERANGLES]")
|
||||
{
|
||||
THEN("These results are expected")
|
||||
{
|
||||
CHECK(Nz::EulerAnglesf(Nz::DegreeAnglef(45.f), 0.f, 0.f) == Nz::EulerAnglesf(Nz::Quaternionf(0.923879504204f, 0.382683455944f, 0.f, 0.f).ToEulerAngles()));
|
||||
CHECK(Nz::EulerAnglesf(0.f, Nz::DegreeAnglef(45.f), 0.f) == Nz::EulerAnglesf(Nz::Quaternionf(0.923879504204f, 0.f, 0.382683455944f, 0.f).ToEulerAngles()));
|
||||
CHECK(Nz::EulerAnglesf(0.f, 0.f, Nz::DegreeAnglef(45.f)) == Nz::EulerAnglesf(Nz::Quaternionf(0.923879504204f, 0.f, 0.f, 0.382683455944f).ToEulerAngles()));
|
||||
CHECK(Nz::EulerAnglesf(Nz::DegreeAnglef(45.f), 0.f, 0.f).ApproxEqual(Nz::EulerAnglesf(Nz::Quaternionf(0.923879504204f, 0.382683455944f, 0.f, 0.f).ToEulerAngles()), 0.0001f));
|
||||
CHECK(Nz::EulerAnglesf(0.f, Nz::DegreeAnglef(45.f), 0.f).ApproxEqual(Nz::EulerAnglesf(Nz::Quaternionf(0.923879504204f, 0.f, 0.382683455944f, 0.f).ToEulerAngles()), 0.0001f));
|
||||
CHECK(Nz::EulerAnglesf(0.f, 0.f, Nz::DegreeAnglef(45.f)).ApproxEqual(Nz::EulerAnglesf(Nz::Quaternionf(0.923879504204f, 0.f, 0.f, 0.382683455944f).ToEulerAngles()), 0.0001f));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,44 +103,44 @@ SCENARIO("Matrix4", "[MATH][MATRIX4]")
|
||||
{
|
||||
THEN("Rotation around X")
|
||||
{
|
||||
transformedMatrix.MakeTransform(Nz::Vector3f::Zero(), Nz::EulerAnglesf(Nz::DegreeAnglef(45.f), 0.f, 0.f).ToQuaternion());
|
||||
transformedMatrix = Nz::Matrix4f::Transform(Nz::Vector3f::Zero(), Nz::EulerAnglesf(Nz::DegreeAnglef(45.f), 0.f, 0.f).ToQuaternion());
|
||||
Nz::Matrix4f rotation45X(1.f, 0.f, 0.f, 0.f,
|
||||
0.f, std::sqrt(2.f) / 2.f, std::sqrt(2.f) / 2.f, 0.f,
|
||||
0.f, -std::sqrt(2.f) / 2.f, std::sqrt(2.f) / 2.f, 0.f,
|
||||
0.f, 0.f, 0.f, 1.f);
|
||||
|
||||
CHECK(transformedMatrix == rotation45X);
|
||||
transformedMatrix.MakeTransform(Nz::Vector3f::Unit(), Nz::EulerAnglesf(Nz::DegreeAnglef(45.f), 0.f, 0.f).ToQuaternion());
|
||||
CHECK(transformedMatrix.ApproxEqual(rotation45X));
|
||||
transformedMatrix = Nz::Matrix4f::Transform(Nz::Vector3f::Unit(), Nz::EulerAnglesf(Nz::DegreeAnglef(45.f), 0.f, 0.f).ToQuaternion());
|
||||
rotation45X.ApplyTranslation(Nz::Vector3f::Unit());
|
||||
CHECK(transformedMatrix == rotation45X);
|
||||
CHECK(transformedMatrix.ApproxEqual(rotation45X));
|
||||
}
|
||||
|
||||
THEN("Rotation around Y")
|
||||
{
|
||||
transformedMatrix.MakeTransform(Nz::Vector3f::Zero(), Nz::EulerAnglesf(0.f, Nz::DegreeAnglef(45.f), 0.f).ToQuaternion());
|
||||
transformedMatrix = Nz::Matrix4f::Transform(Nz::Vector3f::Zero(), Nz::EulerAnglesf(0.f, Nz::DegreeAnglef(45.f), 0.f).ToQuaternion());
|
||||
Nz::Matrix4f rotation45Y(std::sqrt(2.f) / 2.f, 0.f, -std::sqrt(2.f) / 2.f, 0.f,
|
||||
0.f, 1.f, 0.f, 0.f,
|
||||
std::sqrt(2.f) / 2.f, 0.f, std::sqrt(2.f) / 2.f, 0.f,
|
||||
0.f, 0.f, 0.f, 1.f);
|
||||
|
||||
CHECK(transformedMatrix == rotation45Y);
|
||||
transformedMatrix.MakeTransform(Nz::Vector3f::Unit(), Nz::EulerAnglesf(0.f, Nz::DegreeAnglef(45.f), 0.f).ToQuaternion());
|
||||
CHECK(transformedMatrix.ApproxEqual(rotation45Y));
|
||||
transformedMatrix = Nz::Matrix4f::Transform(Nz::Vector3f::Unit(), Nz::EulerAnglesf(0.f, Nz::DegreeAnglef(45.f), 0.f).ToQuaternion());
|
||||
rotation45Y.ApplyTranslation(Nz::Vector3f::Unit());
|
||||
CHECK(transformedMatrix == rotation45Y);
|
||||
CHECK(transformedMatrix.ApproxEqual(rotation45Y));
|
||||
}
|
||||
|
||||
THEN("Rotation around Z")
|
||||
{
|
||||
transformedMatrix.MakeTransform(Nz::Vector3f::Zero(), Nz::EulerAnglesf(0.f, 0.f, Nz::DegreeAnglef(45.f)).ToQuaternion());
|
||||
transformedMatrix = Nz::Matrix4f::Transform(Nz::Vector3f::Zero(), Nz::EulerAnglesf(0.f, 0.f, Nz::DegreeAnglef(45.f)).ToQuaternion());
|
||||
Nz::Matrix4f rotation45Z( std::sqrt(2.f) / 2.f, std::sqrt(2.f) / 2.f, 0.f, 0.f,
|
||||
-std::sqrt(2.f) / 2.f, std::sqrt(2.f) / 2.f, 0.f, 0.f,
|
||||
0.f, 0.f, 1.f, 0.f,
|
||||
0.f, 0.f, 0.f, 1.f);
|
||||
|
||||
CHECK(transformedMatrix == rotation45Z);
|
||||
transformedMatrix.MakeTransform(Nz::Vector3f::Unit(), Nz::EulerAnglesf(Nz::EulerAnglesf(0.f, 0.f, Nz::DegreeAnglef(45.f)).ToQuaternion()));
|
||||
CHECK(transformedMatrix.ApproxEqual(rotation45Z));
|
||||
transformedMatrix = Nz::Matrix4f::Transform(Nz::Vector3f::Unit(), Nz::EulerAnglesf(Nz::EulerAnglesf(0.f, 0.f, Nz::DegreeAnglef(45.f)).ToQuaternion()));
|
||||
rotation45Z.ApplyTranslation(Nz::Vector3f::Unit());
|
||||
CHECK(transformedMatrix == rotation45Z);
|
||||
CHECK(transformedMatrix.ApproxEqual(rotation45Z));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -196,7 +196,7 @@ SCENARIO("Matrix4", "[MATH][MATRIX4]")
|
||||
|
||||
THEN("We should retrieve it")
|
||||
{
|
||||
REQUIRE(identity.GetRotation() == rotation);
|
||||
REQUIRE(identity.GetRotation().ApproxEqual(rotation));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -56,7 +56,10 @@ SCENARIO("OrientedBox", "[MATH][ORIENTEDBOX]")
|
||||
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);
|
||||
Nz::OrientedBoxf lerpObb = Nz::OrientedBoxf::Lerp(nullOrientedBox, centerAndUnit, 0.5f);
|
||||
lerpObb.Update(Nz::Vector3f::Zero());
|
||||
|
||||
REQUIRE(lerpObb.ApproxEqual(result));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,11 +16,6 @@ SCENARIO("Plane", "[MATH][PLANE]")
|
||||
REQUIRE(firstPlane == secondPlane);
|
||||
}
|
||||
|
||||
AND_THEN("We compare with normal(-1, -1, -1), distance -1")
|
||||
{
|
||||
REQUIRE(firstPlane == Nz::Planef(-Nz::Vector3f::Unit().Normalize(), -1.f));
|
||||
}
|
||||
|
||||
AND_THEN("They have the same distance from the same point")
|
||||
{
|
||||
Nz::Vector3f point(-2.f, 3.f, 1.f);
|
||||
|
||||
@@ -13,7 +13,7 @@ SCENARIO("Quaternion", "[MATH][QUATERNION]")
|
||||
{
|
||||
THEN("They are the same and the proprieties of quaternions are respected")
|
||||
{
|
||||
REQUIRE(firstQuaternion == secondQuaternion);
|
||||
REQUIRE(firstQuaternion.ApproxEqual(secondQuaternion));
|
||||
REQUIRE(firstQuaternion.ComputeW() == secondQuaternion.Normalize());
|
||||
REQUIRE(firstQuaternion.Conjugate() == secondQuaternion.Inverse());
|
||||
REQUIRE(firstQuaternion.DotProduct(secondQuaternion) == Catch::Approx(1.f));
|
||||
@@ -24,13 +24,13 @@ SCENARIO("Quaternion", "[MATH][QUATERNION]")
|
||||
{
|
||||
THEN("Multiply with a vectorX is identity")
|
||||
{
|
||||
REQUIRE((firstQuaternion * Nz::Vector3f::UnitX()) == Nz::Vector3f::UnitX());
|
||||
REQUIRE((firstQuaternion * Nz::Vector3f::UnitX()).ApproxEqual(Nz::Vector3f::UnitX()));
|
||||
}
|
||||
|
||||
AND_THEN("Multiply with a vectorY or Z is opposite")
|
||||
{
|
||||
REQUIRE((firstQuaternion * Nz::Vector3f::UnitY()) == -Nz::Vector3f::UnitY());
|
||||
REQUIRE((firstQuaternion * Nz::Vector3f::UnitZ()) == -Nz::Vector3f::UnitZ());
|
||||
REQUIRE((firstQuaternion * Nz::Vector3f::UnitY()).ApproxEqual(-Nz::Vector3f::UnitY()));
|
||||
REQUIRE((firstQuaternion * Nz::Vector3f::UnitZ()).ApproxEqual(-Nz::Vector3f::UnitZ()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ SCENARIO("Quaternion", "[MATH][QUATERNION]")
|
||||
{
|
||||
THEN("These results are expected")
|
||||
{
|
||||
REQUIRE(x20 == Nz::Quaternionf(Nz::DegreeAnglef(20.f), Nz::Vector3f::UnitX()));
|
||||
REQUIRE(x20.ApproxEqual(Nz::Quaternionf(Nz::DegreeAnglef(20.f), Nz::Vector3f::UnitX())));
|
||||
REQUIRE(x30a == x30b);
|
||||
}
|
||||
}
|
||||
@@ -136,7 +136,7 @@ SCENARIO("Quaternion", "[MATH][QUATERNION]")
|
||||
|
||||
Nz::Quaternionf tmp(1.f, 1.f, 0.f, 0.f);
|
||||
tmp.Normalize();
|
||||
REQUIRE(tmp == tmp.ToEulerAngles().ToQuaternion());
|
||||
REQUIRE(tmp.ApproxEqual(tmp.ToEulerAngles().ToQuaternion()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,8 +154,8 @@ SCENARIO("Quaternion", "[MATH][QUATERNION]")
|
||||
REQUIRE(slerpx10x30b.x == Catch::Approx(x20.x));
|
||||
REQUIRE(slerpx10x30b.y == Catch::Approx(x20.y));
|
||||
REQUIRE(slerpx10x30b.z == Catch::Approx(x20.z));
|
||||
REQUIRE(Nz::Quaternionf::Slerp(x10, x30a, 0.f) == x10);
|
||||
REQUIRE(Nz::Quaternionf::Slerp(x10, x30a, 1.f) == x30a);
|
||||
REQUIRE(Nz::Quaternionf::Slerp(x10, x30a, 0.f).ApproxEqual(x10));
|
||||
REQUIRE(Nz::Quaternionf::Slerp(x10, x30a, 1.f).ApproxEqual(x30a));
|
||||
}
|
||||
|
||||
AND_THEN("The half of 45 is 22.5")
|
||||
@@ -178,21 +178,21 @@ SCENARIO("Quaternion", "[MATH][QUATERNION]")
|
||||
{
|
||||
Nz::Quaternionf rotationBetweenXY = Nz::Quaternionf::RotationBetween(Nz::Vector3f::UnitX(), Nz::Vector3f::UnitY());
|
||||
Nz::Quaternionf rotation90Z(Nz::DegreeAnglef(90.f), Nz::Vector3f::UnitZ());
|
||||
REQUIRE(rotation90Z == rotationBetweenXY);
|
||||
REQUIRE(rotation90Z.ApproxEqual(rotationBetweenXY));
|
||||
}
|
||||
|
||||
THEN("The rotation in right-handed is 90 degree on y")
|
||||
{
|
||||
Nz::Quaternionf rotationBetweenXZ = Nz::Quaternionf::RotationBetween(Nz::Vector3f::UnitX(), Nz::Vector3f::UnitZ());
|
||||
Nz::Quaternionf rotation90Y(Nz::DegreeAnglef(-90.f), Nz::Vector3f::UnitY());
|
||||
REQUIRE(rotation90Y == rotationBetweenXZ);
|
||||
REQUIRE(rotation90Y.ApproxEqual(rotationBetweenXZ));
|
||||
}
|
||||
|
||||
THEN("The rotation in right-handed is 90 degree on x")
|
||||
{
|
||||
Nz::Quaternionf rotationBetweenYZ = Nz::Quaternionf::RotationBetween(Nz::Vector3f::UnitY(), Nz::Vector3f::UnitZ());
|
||||
Nz::Quaternionf rotation90X(Nz::DegreeAnglef(90.f), Nz::Vector3f::UnitX());
|
||||
REQUIRE(rotation90X == rotationBetweenYZ);
|
||||
REQUIRE(rotation90X.ApproxEqual(rotationBetweenYZ));
|
||||
}
|
||||
|
||||
THEN("The rotation in right-handed is 90 degree on y with non-unit vectors")
|
||||
@@ -200,7 +200,7 @@ SCENARIO("Quaternion", "[MATH][QUATERNION]")
|
||||
Nz::Vector3f origin(1.f, 0.f, 1.f);
|
||||
Nz::Vector3f extremity(-1.f, 0.f, 1.f);
|
||||
Nz::Quaternionf rotation = Nz::Quaternionf::RotationBetween(origin, extremity);
|
||||
REQUIRE(rotation * origin == extremity);
|
||||
REQUIRE((rotation * origin).ApproxEqual(extremity));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -229,9 +229,9 @@ SCENARIO("Quaternion", "[MATH][QUATERNION]")
|
||||
CHECK(Nz::NumberEquals(rotation90Y.ToEulerAngles().yaw.ToDegrees(), 90.f, 0.1f));
|
||||
CHECK(Nz::NumberEquals(rotation90Z.ToEulerAngles().roll.ToDegrees(), 90.f, 0.1f));
|
||||
|
||||
CHECK(rotation180X == Nz::EulerAnglesf(180.f, 0.f, 0.f));
|
||||
CHECK(rotation180Y == Nz::EulerAnglesf(0.f, 180.f, 0.f));
|
||||
CHECK(rotation180Z == Nz::EulerAnglesf(0.f, 0.f, 180.f));
|
||||
CHECK(rotation180X.ApproxEqual(Nz::EulerAnglesf(180.f, 0.f, 0.f)));
|
||||
CHECK(rotation180Y.ApproxEqual(Nz::EulerAnglesf(0.f, 180.f, 0.f)));
|
||||
CHECK(rotation180Z.ApproxEqual(Nz::EulerAnglesf(0.f, 0.f, 180.f)));
|
||||
|
||||
CHECK(Nz::NumberEquals(rotation270X.ToEulerAngles().pitch.ToDegrees(), -90.f, 0.1f));
|
||||
CHECK(Nz::NumberEquals(rotation270Y.ToEulerAngles().yaw.ToDegrees(), -90.f, 0.1f));
|
||||
|
||||
@@ -67,12 +67,12 @@ SCENARIO("Ray", "[MATH][RAY]")
|
||||
|
||||
THEN("For the bounding volume collision's")
|
||||
{
|
||||
Nz::BoundingVolumef nullVolume(Nz::Extend::Null);
|
||||
Nz::BoundingVolumef nullVolume(Nz::Extent::Null);
|
||||
CHECK(!ray.Intersect(nullVolume));
|
||||
|
||||
float tmpClosest = -1.f;
|
||||
float tmpFurthest = -1.f;
|
||||
Nz::BoundingVolumef infiniteVolume(Nz::Extend::Infinite);
|
||||
Nz::BoundingVolumef infiniteVolume(Nz::Extent::Infinite);
|
||||
CHECK(ray.Intersect(infiniteVolume, &tmpClosest, &tmpFurthest));
|
||||
CHECK(tmpClosest == Catch::Approx(0.f));
|
||||
CHECK(tmpFurthest == std::numeric_limits<float>::infinity());
|
||||
|
||||
@@ -28,9 +28,9 @@ SCENARIO("Vector2", "[MATH][VECTOR2]")
|
||||
{
|
||||
REQUIRE(firstUnit.AbsDotProduct(tmp) == Catch::Approx(2.f));
|
||||
REQUIRE(firstUnit.DotProduct(tmp) == Catch::Approx(0.f));
|
||||
REQUIRE(firstUnit.AngleBetween(tmp) == Nz::DegreeAnglef(90.f));
|
||||
REQUIRE(firstUnit.AngleBetween(tmp).ApproxEqual(Nz::DegreeAnglef(90.f)));
|
||||
Nz::Vector2f negativeUnitX = -Nz::Vector2f::UnitX();
|
||||
REQUIRE(negativeUnitX.AngleBetween(negativeUnitX + Nz::Vector2f(0, 0.0000001f)) == Nz::DegreeAnglef(360.f));
|
||||
REQUIRE(negativeUnitX.AngleBetween(negativeUnitX + Nz::Vector2f(0, 0.0000001f)).ApproxEqual(Nz::DegreeAnglef(360.f)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,8 +27,8 @@ SCENARIO("Vector3", "[MATH][VECTOR3]")
|
||||
{
|
||||
REQUIRE(firstUnit.AbsDotProduct(tmp) == Catch::Approx(2.f));
|
||||
REQUIRE(firstUnit.DotProduct(tmp) == Catch::Approx(0.f));
|
||||
REQUIRE(firstUnit.AngleBetween(tmp) == Nz::DegreeAnglef(90.f));
|
||||
REQUIRE(firstUnit.AngleBetween(-firstUnit) == Nz::DegreeAnglef(180.f));
|
||||
REQUIRE(firstUnit.AngleBetween(tmp).ApproxEqual(Nz::DegreeAnglef(90.f)));
|
||||
REQUIRE(firstUnit.AngleBetween(-firstUnit).ApproxEqual(Nz::DegreeAnglef(180.f)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ SCENARIO("Vector3", "[MATH][VECTOR3]")
|
||||
THEN("For normal cases should be normal")
|
||||
{
|
||||
Nz::Vector3f normalized = firstUnit.GetNormal(&ratio);
|
||||
REQUIRE(normalized == (Nz::Vector3f::Unit() / std::sqrt(3.f)));
|
||||
REQUIRE(normalized.ApproxEqual(Nz::Vector3f::Unit() / std::sqrt(3.f)));
|
||||
REQUIRE(ratio == Catch::Approx(std::sqrt(3.f)));
|
||||
}
|
||||
|
||||
|
||||
@@ -181,15 +181,15 @@ SCENARIO("RigidBody2D", "[PHYSICS2D][RIGIDBODY2D]")
|
||||
{
|
||||
CHECK(body.GetAngularVelocity() == angularSpeed);
|
||||
CHECK(body.GetRotation() == angularSpeed);
|
||||
CHECK(body.GetAABB().ApproxEquals(Nz::Rectf(-6.f, 3.f, 2.f, 1.f), 0.00001f));
|
||||
CHECK(body.GetAABB().ApproxEqual(Nz::Rectf(-6.f, 3.f, 2.f, 1.f), 0.00001f));
|
||||
|
||||
world.Step(Nz::Time::Second());
|
||||
CHECK(body.GetRotation() == 2.f * angularSpeed);
|
||||
CHECK(body.GetAABB().ApproxEquals(Nz::Rectf(-4.f, -6.f, 1.f, 2.f), 0.00001f));
|
||||
CHECK(body.GetAABB().ApproxEqual(Nz::Rectf(-4.f, -6.f, 1.f, 2.f), 0.00001f));
|
||||
|
||||
world.Step(Nz::Time::Second());
|
||||
CHECK(body.GetRotation() == 3.f * angularSpeed);
|
||||
CHECK(body.GetAABB().ApproxEquals(Nz::Rectf(4.f, -4.f, 2.f, 1.f), 0.00001f));
|
||||
CHECK(body.GetAABB().ApproxEqual(Nz::Rectf(4.f, -4.f, 2.f, 1.f), 0.00001f));
|
||||
|
||||
world.Step(Nz::Time::Second());
|
||||
CHECK(body.GetRotation() == 4.f * angularSpeed);
|
||||
|
||||
Reference in New Issue
Block a user