Switch from Nz prefix to namespace Nz

What a huge commit


Former-commit-id: 38ac5eebf70adc1180f571f6006192d28fb99897
This commit is contained in:
Lynix
2015-09-25 19:20:05 +02:00
parent c214251ecf
commit df8da275c4
609 changed files with 68265 additions and 66534 deletions

View File

@@ -5,17 +5,17 @@ TEST_CASE("Approach", "[MATH][ALGORITHM]" )
{
SECTION("Approach 8 with 5 by 2")
{
REQUIRE(NzApproach(5, 8, 2) == 7);
REQUIRE(Nz::Approach(5, 8, 2) == 7);
}
SECTION("Approach 5 with 8 by 2")
{
REQUIRE(NzApproach(8, 5, 2) == 6);
REQUIRE(Nz::Approach(8, 5, 2) == 6);
}
SECTION("Approach 8 with 8 by 2")
{
REQUIRE(NzApproach(8, 8, 2) == 8);
REQUIRE(Nz::Approach(8, 8, 2) == 8);
}
}
@@ -23,17 +23,17 @@ TEST_CASE("Clamp", "[ALGORITHM]" )
{
SECTION("Clamp 8 between 5 and 10")
{
REQUIRE(NzClamp(8, 5, 10) == 8);
REQUIRE(Nz::Clamp(8, 5, 10) == 8);
}
SECTION("Clamp 4 between 5 and 10")
{
REQUIRE(NzClamp(4, 5, 10) == 5);
REQUIRE(Nz::Clamp(4, 5, 10) == 5);
}
SECTION("Clamp 12 between 5 and 10")
{
REQUIRE(NzClamp(12, 5, 10) == 10);
REQUIRE(Nz::Clamp(12, 5, 10) == 10);
}
}
@@ -41,7 +41,7 @@ TEST_CASE("DegreeToRadian", "[ALGORITHM]" )
{
SECTION("Convert 45.f degree to radian")
{
REQUIRE(NzDegreeToRadian(45.f) == Approx(M_PI / 4));
REQUIRE(Nz::NzDegreeToRadian(45.f) == Approx(M_PI / 4));
}
}
@@ -49,12 +49,12 @@ TEST_CASE("GetNearestPowerOfTwo", "[ALGORITHM]" )
{
SECTION("Nearest power of two of 16 = 16")
{
REQUIRE(NzGetNearestPowerOfTwo(16) == 16);
REQUIRE(Nz::GetNearestPowerOfTwo(16) == 16);
}
SECTION("Nearest power of two of 17 = 32")
{
REQUIRE(NzGetNearestPowerOfTwo(17) == 32);
REQUIRE(Nz::GetNearestPowerOfTwo(17) == 32);
}
}
@@ -63,55 +63,55 @@ TEST_CASE("GetNumberLength", "[ALGORITHM]" )
SECTION("GetNumberLength of -127 signed char")
{
signed char minus127 = -127;
REQUIRE(NzGetNumberLength(minus127) == 4);
REQUIRE(Nz::GetNumberLength(minus127) == 4);
}
SECTION("GetNumberLength of 255 unsigned char")
{
unsigned char plus255 = 255;
REQUIRE(NzGetNumberLength(plus255) == 3);
REQUIRE(Nz::GetNumberLength(plus255) == 3);
}
SECTION("GetNumberLength of -1270 signed int")
{
signed int minus1270 = -1270;
REQUIRE(NzGetNumberLength(minus1270) == 5);
REQUIRE(Nz::GetNumberLength(minus1270) == 5);
}
SECTION("GetNumberLength of 2550 unsigned int")
{
unsigned int plus2550 = 2550;
REQUIRE(NzGetNumberLength(plus2550) == 4);
REQUIRE(Nz::GetNumberLength(plus2550) == 4);
}
SECTION("GetNumberLength of -1270 signed long long")
{
signed long long minus12700 = -12700;
REQUIRE(NzGetNumberLength(minus12700) == 6);
REQUIRE(Nz::GetNumberLength(minus12700) == 6);
}
SECTION("GetNumberLength of 2550 unsigned long long")
{
unsigned long long plus25500 = 25500;
REQUIRE(NzGetNumberLength(plus25500) == 5);
REQUIRE(Nz::GetNumberLength(plus25500) == 5);
}
SECTION("GetNumberLength of -2.456f float")
{
float minus2P456 = -2.456f;
REQUIRE(NzGetNumberLength(minus2P456, 3) == 6);
REQUIRE(Nz::GetNumberLength(minus2P456, 3) == 6);
}
SECTION("GetNumberLength of -2.456 double")
{
double minus2P456 = -2.456;
REQUIRE(NzGetNumberLength(minus2P456, 3) == 6);
REQUIRE(Nz::GetNumberLength(minus2P456, 3) == 6);
}
SECTION("GetNumberLength of -2.456 long double")
{
long double minus2P456 = -2.456L;
REQUIRE(NzGetNumberLength(minus2P456, 3) == 6);
REQUIRE(Nz::GetNumberLength(minus2P456, 3) == 6);
}
}
@@ -119,7 +119,7 @@ TEST_CASE("IntegralPow", "[ALGORITHM]" )
{
SECTION("2 to power 4")
{
REQUIRE(NzIntegralPow(2, 4) == 16);
REQUIRE(Nz::IntegralPow(2, 4) == 16);
}
}
@@ -127,7 +127,7 @@ TEST_CASE("Lerp", "[ALGORITHM]" )
{
SECTION("Lerp 2 to 6 with 0.5")
{
REQUIRE(NzLerp(2, 6, 0.5) == 4);
REQUIRE(Nz::Lerp(2, 6, 0.5) == 4);
}
}
@@ -135,7 +135,7 @@ TEST_CASE("MultiplyAdd", "[ALGORITHM]" )
{
SECTION("2 * 3 + 1")
{
REQUIRE(NzMultiplyAdd(2, 3, 1) == 7);
REQUIRE(Nz::MultiplyAdd(2, 3, 1) == 7);
}
}
@@ -143,12 +143,12 @@ TEST_CASE("NumberEquals", "[ALGORITHM]" )
{
SECTION("2.35 and 2.351 should be the same at 0.01")
{
CHECK(NzNumberEquals(2.35, 2.35, 0.01));
CHECK(Nz::NumberEquals(2.35, 2.35, 0.01));
}
SECTION("3 and 4 unsigned should be the same at 1")
{
CHECK(NzNumberEquals(3U, 4U, 1U));
CHECK(Nz::NumberEquals(3U, 4U, 1U));
}
}
@@ -156,17 +156,17 @@ TEST_CASE("NumberToString", "[ALGORITHM]" )
{
SECTION("235 to string")
{
REQUIRE(NzNumberToString(235) == "235");
REQUIRE(Nz::NumberToString(235) == "235");
}
SECTION("-235 to string")
{
REQUIRE(NzNumberToString(-235) == "-235");
REQUIRE(Nz::NumberToString(-235) == "-235");
}
SECTION("16 in base 16 to string")
{
REQUIRE(NzNumberToString(16, 16) == "10");
REQUIRE(Nz::NumberToString(16, 16) == "10");
}
}
@@ -174,7 +174,7 @@ TEST_CASE("RadianToDegree", "[ALGORITHM]" )
{
SECTION("PI / 4 to degree")
{
REQUIRE(NzRadianToDegree(M_PI / 4) == Approx(45.f));
REQUIRE(Nz::RadianToDegree(M_PI / 4) == Approx(45.f));
}
}
@@ -182,16 +182,16 @@ TEST_CASE("StringToNumber", "[ALGORITHM]" )
{
SECTION("235 in string")
{
REQUIRE(NzStringToNumber("235") == 235);
REQUIRE(Nz::StringToNumber("235") == 235);
}
SECTION("-235 in string")
{
REQUIRE(NzStringToNumber("-235") == -235);
REQUIRE(Nz::StringToNumber("-235") == -235);
}
SECTION("16 in base 16 in string")
{
REQUIRE(NzStringToNumber("10", 16) == 16);
REQUIRE(Nz::StringToNumber("10", 16) == 16);
}
}

View File

@@ -5,8 +5,8 @@ SCENARIO("BoundingVolume", "[MATH][BOUNDINGVOLUME]")
{
GIVEN("With a null bounding volume and an infinite")
{
NzBoundingVolumef nullVolume = NzBoundingVolumef::Null();
NzBoundingVolumef infiniteVolume = NzBoundingVolumef::Infinite();
Nz::BoundingVolumef nullVolume = Nz::BoundingVolumef::Null();
Nz::BoundingVolumef infiniteVolume = Nz::BoundingVolumef::Infinite();
WHEN("We compare them")
{
@@ -49,18 +49,18 @@ SCENARIO("BoundingVolume", "[MATH][BOUNDINGVOLUME]")
{
THEN("Everything should be ok")
{
REQUIRE(NzBoundingVolumef::Null() == NzBoundingVolumef::Null());
REQUIRE(NzBoundingVolumef::Infinite() == NzBoundingVolumef::Infinite());
REQUIRE(Nz::BoundingVolumef::Null() == Nz::BoundingVolumef::Null());
REQUIRE(Nz::BoundingVolumef::Infinite() == Nz::BoundingVolumef::Infinite());
}
}
}
GIVEN("Two same bounding volume with different constructor")
{
NzBoundingVolumef firstCenterAndUnit(0.f, 0.f, 0.f, 1.f, 1.f, 1.f);
NzBoundingVolumef secondCenterAndUnit(NzVector3f::Zero(), NzVector3f::Unit());
firstCenterAndUnit.Update(NzMatrix4f::Identity());
secondCenterAndUnit.Update(NzMatrix4f::Identity());
Nz::BoundingVolumef firstCenterAndUnit(0.f, 0.f, 0.f, 1.f, 1.f, 1.f);
Nz::BoundingVolumef secondCenterAndUnit(Nz::Vector3f::Zero(), Nz::Vector3f::Unit());
firstCenterAndUnit.Update(Nz::Matrix4f::Identity());
secondCenterAndUnit.Update(Nz::Matrix4f::Identity());
WHEN("We compare them")
{
@@ -83,15 +83,15 @@ SCENARIO("BoundingVolume", "[MATH][BOUNDINGVOLUME]")
{
THEN("There's no problem")
{
NzBoundingVolume<int> intVolumeCenterAndUnit(NzBoxi(NzVector3i::Zero(), NzVector3i::Unit()));
NzBoundingVolumef thirdCenterAndUnit(intVolumeCenterAndUnit);
Nz::BoundingVolume<int> intVolumeCenterAndUnit(Nz::Boxi(Nz::Vector3i::Zero(), Nz::Vector3i::Unit()));
Nz::BoundingVolumef thirdCenterAndUnit(intVolumeCenterAndUnit);
REQUIRE(thirdCenterAndUnit == secondCenterAndUnit);
}
}
WHEN("We make one twice bigger with a matrix")
{
firstCenterAndUnit.Update(NzMatrix4f::Scale(NzVector3f::Unit() * 2.f));
firstCenterAndUnit.Update(Nz::Matrix4f::Scale(Nz::Vector3f::Unit() * 2.f));
THEN("The local box should be the same but the aabb different")
{

View File

@@ -5,13 +5,13 @@ SCENARIO("Box", "[MATH][BOX]")
{
GIVEN("Two zero boxes")
{
NzBoxf firstZero(NzBoxf::Zero());
NzBoxf secondZero(NzVector3f::Zero(), NzVector3f::Zero());
Nz::Boxf firstZero(Nz::Boxf::Zero());
Nz::Boxf secondZero(Nz::Vector3f::Zero(), Nz::Vector3f::Zero());
WHEN("We multiply them")
{
firstZero = firstZero * 1.f;
secondZero = secondZero * NzVector3f::Unit() * 3.f;
secondZero = secondZero * Nz::Vector3f::Unit() * 3.f;
THEN("They should stay the same")
{
@@ -24,24 +24,24 @@ SCENARIO("Box", "[MATH][BOX]")
GIVEN("Two unit and center boxes")
{
NzBoxf firstCenterAndUnit(NzRectf(NzVector2f::Zero(), NzVector2f::Unit()));
NzBoxf secondCenterAndUnit(1.f, 1.f, 1.f);
Nz::Boxf firstCenterAndUnit(Nz::Rectf(Nz::Vector2f::Zero(), Nz::Vector2f::Unit()));
Nz::Boxf secondCenterAndUnit(1.f, 1.f, 1.f);
WHEN("We ask for some informations")
{
THEN("These results are expected")
{
REQUIRE(firstCenterAndUnit.GetBoundingSphere() == NzSpheref(NzVector3f::Unit() * 0.5f, std::sqrt(3.f * 0.5f * 0.5f)));
REQUIRE(firstCenterAndUnit.GetCenter() == (NzVector3f::Unit() * 0.5f));
REQUIRE(firstCenterAndUnit.GetCorner(nzBoxCorner_FarLeftTop) == NzVector3f::UnitY());
REQUIRE(firstCenterAndUnit.GetLengths() == NzVector3f::Unit());
REQUIRE(firstCenterAndUnit.GetMaximum() == NzVector3f::Unit());
REQUIRE(firstCenterAndUnit.GetMinimum() == NzVector3f::Zero());
REQUIRE(firstCenterAndUnit.GetNegativeVertex(NzVector3f::Unit()) == NzVector3f::Zero());
REQUIRE(firstCenterAndUnit.GetPosition() == NzVector3f::Zero());
REQUIRE(firstCenterAndUnit.GetPositiveVertex(NzVector3f::Unit()) == NzVector3f::Unit());
REQUIRE(firstCenterAndUnit.GetBoundingSphere() == Nz::Spheref(Nz::Vector3f::Unit() * 0.5f, std::sqrt(3.f * 0.5f * 0.5f)));
REQUIRE(firstCenterAndUnit.GetCenter() == (Nz::Vector3f::Unit() * 0.5f));
REQUIRE(firstCenterAndUnit.GetCorner(Nz::BoxCorner_FarLeftTop) == Nz::Vector3f::UnitY());
REQUIRE(firstCenterAndUnit.GetLengths() == Nz::Vector3f::Unit());
REQUIRE(firstCenterAndUnit.GetMaximum() == Nz::Vector3f::Unit());
REQUIRE(firstCenterAndUnit.GetMinimum() == Nz::Vector3f::Zero());
REQUIRE(firstCenterAndUnit.GetNegativeVertex(Nz::Vector3f::Unit()) == Nz::Vector3f::Zero());
REQUIRE(firstCenterAndUnit.GetPosition() == Nz::Vector3f::Zero());
REQUIRE(firstCenterAndUnit.GetPositiveVertex(Nz::Vector3f::Unit()) == Nz::Vector3f::Unit());
REQUIRE(firstCenterAndUnit.GetRadius() == Approx(std::sqrt(3.f * 0.5f * 0.5f)));
REQUIRE(firstCenterAndUnit.GetSquaredBoundingSphere() == NzSpheref(NzVector3f::Unit() * 0.5f, 3.f * 0.5f * 0.5f));
REQUIRE(firstCenterAndUnit.GetSquaredBoundingSphere() == Nz::Spheref(Nz::Vector3f::Unit() * 0.5f, 3.f * 0.5f * 0.5f));
REQUIRE(firstCenterAndUnit.GetSquaredRadius() == Approx(3.f * 0.5f * 0.5f));
}
}
@@ -50,7 +50,7 @@ SCENARIO("Box", "[MATH][BOX]")
{
THEN("We should have a center and unit")
{
NzBoxf thirdCenterAndUnit;
Nz::Boxf thirdCenterAndUnit;
CHECK(firstCenterAndUnit.Intersect(secondCenterAndUnit, &thirdCenterAndUnit));
REQUIRE(firstCenterAndUnit == secondCenterAndUnit);
}
@@ -60,7 +60,7 @@ SCENARIO("Box", "[MATH][BOX]")
{
THEN("Shouldn't be a problem")
{
NzBoxf tmp(NzBoxi(0, 0, 0, 1, 1, 1));
Nz::Boxf tmp(Nz::Boxi(0, 0, 0, 1, 1, 1));
REQUIRE(tmp == firstCenterAndUnit);
}
}
@@ -68,8 +68,8 @@ SCENARIO("Box", "[MATH][BOX]")
GIVEN("Two wrong box (negative width, height and depth")
{
NzBoxf firstWrongBox(-NzVector3f::Unit());
NzBoxf secondWrongBox(-NzVector3f::Unit());
Nz::Boxf firstWrongBox(-Nz::Vector3f::Unit());
Nz::Boxf secondWrongBox(-Nz::Vector3f::Unit());
WHEN("We check if valid")
{
@@ -82,8 +82,8 @@ SCENARIO("Box", "[MATH][BOX]")
WHEN("We correct them")
{
firstWrongBox.ExtendTo(NzVector3f::Unit());
secondWrongBox.Transform(NzMatrix4f::Scale(-NzVector3f::Unit()));
firstWrongBox.ExtendTo(Nz::Vector3f::Unit());
secondWrongBox.Transform(Nz::Matrix4f::Scale(-Nz::Vector3f::Unit()));
THEN("They should be valid")
{
@@ -98,13 +98,13 @@ SCENARIO("Box", "[MATH][BOX]")
CHECK(firstWrongBox.Contains(0.f, 0.f, 0.f));
CHECK(secondWrongBox.Contains(0.f, 0.f, 0.f));
secondWrongBox = secondWrongBox.Lerp(NzBoxf::Zero(), secondWrongBox, 0.f); // Zeroed
secondWrongBox.ExtendTo(NzBoxf(NzVector3f(0.1f, 0.1f, 0.1f), NzVector3f(0.9f, 0.9f, 0.9f)));
secondWrongBox.Translate(NzVector3f(0.05f, 0.05f, 0.05f)); // Box 0.15 to 0.95
secondWrongBox = secondWrongBox.Lerp(Nz::Boxf::Zero(), secondWrongBox, 0.f); // Zeroed
secondWrongBox.ExtendTo(Nz::Boxf(Nz::Vector3f(0.1f, 0.1f, 0.1f), Nz::Vector3f(0.9f, 0.9f, 0.9f)));
secondWrongBox.Translate(Nz::Vector3f(0.05f, 0.05f, 0.05f)); // Box 0.15 to 0.95
CHECK(firstWrongBox.Contains(secondWrongBox));
NzBoxf test(1.f, -500.f, -500.f, 1000.f, 1000.f, 1000.f);
CHECK(test.Contains(NzBoxf(500.f, -0.5f, -0.5f, 1.f, 1.f, 1.f)));
Nz::Boxf test(1.f, -500.f, -500.f, 1000.f, 1000.f, 1000.f);
CHECK(test.Contains(Nz::Boxf(500.f, -0.5f, -0.5f, 1.f, 1.f, 1.f)));
CHECK(test.Contains(500.f, 0.f, 0.f));
}
}

View File

@@ -5,8 +5,8 @@ SCENARIO("EulerAngles", "[MATH][EULERANGLES]")
{
GIVEN("Two zero euler angles")
{
NzEulerAnglesf firstZero(0.f, 0.f, 0.f);
NzEulerAnglesf secondZero(NzEulerAngles<int>::Zero());
Nz::EulerAnglesf firstZero(0.f, 0.f, 0.f);
Nz::EulerAnglesf secondZero(Nz::EulerAngles<int>::Zero());
THEN("They should be equal")
{
@@ -15,12 +15,12 @@ SCENARIO("EulerAngles", "[MATH][EULERANGLES]")
WHEN("We do some operations")
{
NzEulerAnglesf euler90(90.f, 90.f, 90.f);
NzEulerAnglesf euler270(270.f, 270.f, 270.f);
Nz::EulerAnglesf euler90(90.f, 90.f, 90.f);
Nz::EulerAnglesf euler270(270.f, 270.f, 270.f);
NzEulerAnglesf euler360 = euler90 + euler270;
Nz::EulerAnglesf euler360 = euler90 + euler270;
euler360.Normalize();
NzEulerAnglesf euler0 = euler270 - euler90;
Nz::EulerAnglesf euler0 = euler270 - euler90;
euler0 -= euler90;
euler0 -= euler90;
@@ -36,8 +36,8 @@ SCENARIO("EulerAngles", "[MATH][EULERANGLES]")
THEN("They are the same")
{
REQUIRE(firstZero.ToQuaternion() == secondZero.ToQuaternion());
REQUIRE(firstZero.ToQuaternion() == NzEulerAnglesf(NzQuaternionf(1.f, 0.f, 0.f, 0.f)));
REQUIRE(secondZero.ToQuaternion() == NzEulerAnglesf(NzQuaternionf(1.f, 0.f, 0.f, 0.f)));
REQUIRE(firstZero.ToQuaternion() == Nz::EulerAnglesf(Nz::Quaternionf(1.f, 0.f, 0.f, 0.f)));
REQUIRE(secondZero.ToQuaternion() == Nz::EulerAnglesf(Nz::Quaternionf(1.f, 0.f, 0.f, 0.f)));
}
}
}
@@ -48,32 +48,32 @@ SCENARIO("EulerAngles", "[MATH][EULERANGLES]")
{
THEN("These results are expected")
{
REQUIRE(NzEulerAngles<int>(NzFromDegrees(45.f), 0.f, 0.f) == NzEulerAngles<int>(NzQuaternionf(0.923879504204f, 0.382683455944f, 0.f, 0.f).ToEulerAngles()));
REQUIRE(NzEulerAngles<int>(0.f, NzFromDegrees(45.f), 0.f) == NzEulerAngles<int>(NzQuaternionf(0.923879504204f, 0.f, 0.382683455944f, 0.f).ToEulerAngles()));
REQUIRE(NzEulerAngles<int>(0.f, 0.f, NzFromDegrees(45.f)) == NzEulerAngles<int>(NzQuaternionf(0.923879504204f, 0.f, 0.f, 0.382683455944f).ToEulerAngles()));
REQUIRE(Nz::EulerAngles<int>(Nz::FromDegrees(45.f), 0.f, 0.f) == Nz::EulerAngles<int>(Nz::Quaternionf(0.923879504204f, 0.382683455944f, 0.f, 0.f).ToEulerAngles()));
REQUIRE(Nz::EulerAngles<int>(0.f, Nz::FromDegrees(45.f), 0.f) == Nz::EulerAngles<int>(Nz::Quaternionf(0.923879504204f, 0.f, 0.382683455944f, 0.f).ToEulerAngles()));
REQUIRE(Nz::EulerAngles<int>(0.f, 0.f, Nz::FromDegrees(45.f)) == Nz::EulerAngles<int>(Nz::Quaternionf(0.923879504204f, 0.f, 0.f, 0.382683455944f).ToEulerAngles()));
}
}
}
GIVEN("Three euler angles: (0, 22.5, 22.5), (90, 90, 0) and (30, 0, 30)")
{
NzEulerAnglesf euler45(NzFromDegrees(0.f), NzFromDegrees(22.5f), NzFromDegrees(22.5f));
NzEulerAnglesf euler90(NzFromDegrees(90.f), NzFromDegrees(90.f), NzFromDegrees(0.f));
NzEulerAnglesf euler30(NzFromDegrees(30.f), NzFromDegrees(0.f), NzFromDegrees(30.f));
Nz::EulerAnglesf euler45(Nz::FromDegrees(0.f), Nz::FromDegrees(22.5f), Nz::FromDegrees(22.5f));
Nz::EulerAnglesf euler90(Nz::FromDegrees(90.f), Nz::FromDegrees(90.f), Nz::FromDegrees(0.f));
Nz::EulerAnglesf euler30(Nz::FromDegrees(30.f), Nz::FromDegrees(0.f), Nz::FromDegrees(30.f));
WHEN("We convert them to quaternion")
{
THEN("And then convert to euler angles, we have identity")
{
NzEulerAnglesf tmp = NzQuaternionf(euler45.ToQuaternion()).ToEulerAngles();
Nz::EulerAnglesf tmp = Nz::Quaternionf(euler45.ToQuaternion()).ToEulerAngles();
REQUIRE(tmp.pitch == Approx(0.f));
REQUIRE(tmp.yaw == Approx(22.5f));
REQUIRE(tmp.roll == Approx(22.5f));
tmp = NzQuaternionf(euler90.ToQuaternion()).ToEulerAngles();
tmp = Nz::Quaternionf(euler90.ToQuaternion()).ToEulerAngles();
REQUIRE(tmp.pitch == Approx(90.f));
REQUIRE(tmp.yaw == Approx(90.f));
REQUIRE(tmp.roll == Approx(0.f));
tmp = NzQuaternionf(euler30.ToQuaternion()).ToEulerAngles();
tmp = Nz::Quaternionf(euler30.ToQuaternion()).ToEulerAngles();
REQUIRE(tmp.pitch == Approx(30.f));
REQUIRE(tmp.yaw == Approx(0.f));
REQUIRE(tmp.roll == Approx(30.f));

View File

@@ -5,25 +5,25 @@ SCENARIO("Frustum", "[MATH][FRUSTUM]")
{
GIVEN("One frustum (90, 1, 1, 1000, (0, 0, 0), (1, 0, 0))")
{
NzFrustumf frustum;
frustum.Build(NzFromDegrees(90.f), 1.f, 1.f, 1000.f, NzVector3f::Zero(), NzVector3f::UnitX());
Nz::Frustumf frustum;
frustum.Build(Nz::FromDegrees(90.f), 1.f, 1.f, 1000.f, Nz::Vector3f::Zero(), Nz::Vector3f::UnitX());
WHEN("We ask for intersection with objects outside the frustum")
{
THEN("These results are expected")
{
NzBoundingVolumef bv(NzVector3f::Zero(), NzVector3f::Unit());
bv.Update(NzMatrix4f::Identity());
REQUIRE(nzIntersectionSide_Outside == frustum.Intersect(bv));
REQUIRE(nzIntersectionSide_Outside == frustum.Intersect(NzBoxf(NzVector3f::Zero(), NzVector3f::Unit() * 0.9f)));
NzOrientedBoxf obb(NzVector3f::Zero(), NzVector3f::Unit() * 0.9f);
obb.Update(NzMatrix4f::Identity());
REQUIRE(nzIntersectionSide_Outside == frustum.Intersect(obb));
REQUIRE(nzIntersectionSide_Outside == frustum.Intersect(NzSpheref(NzVector3f::Zero(), 0.5f)));
NzVector3f tmp = NzVector3f::Zero();
REQUIRE(nzIntersectionSide_Outside == frustum.Intersect(&tmp, 1));
tmp = NzVector3f::UnitX() * -10.f;
REQUIRE(nzIntersectionSide_Outside == frustum.Intersect(&tmp, 1));
Nz::BoundingVolumef bv(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);
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)));
Nz::Vector3f tmp = Nz::Vector3f::Zero();
REQUIRE(Nz::IntersectionSide_Outside == frustum.Intersect(&tmp, 1));
tmp = Nz::Vector3f::UnitX() * -10.f;
REQUIRE(Nz::IntersectionSide_Outside == frustum.Intersect(&tmp, 1));
}
}
@@ -31,17 +31,17 @@ SCENARIO("Frustum", "[MATH][FRUSTUM]")
{
THEN("These results are expected")
{
NzBoundingVolumef bv(500.f, -0.5f, -0.5f, 1.f, 1.f, 1.f);
bv.Update(NzMatrix4f::Identity());
Nz::BoundingVolumef bv(500.f, -0.5f, -0.5f, 1.f, 1.f, 1.f);
bv.Update(Nz::Matrix4f::Identity());
REQUIRE(nzIntersectionSide_Inside == frustum.Intersect(bv));
REQUIRE(nzIntersectionSide_Inside == frustum.Intersect(NzBoxf(NzVector3f::UnitX() * 500.f, NzVector3f::Unit())));
NzOrientedBoxf obb(NzVector3f::UnitX() * 100.f, NzVector3f::Unit());
obb.Update(NzMatrix4f::Identity());
REQUIRE(nzIntersectionSide_Inside == frustum.Intersect(obb));
REQUIRE(nzIntersectionSide_Inside == frustum.Intersect(NzSpheref(NzVector3f::UnitX() * 100.f, 0.5f)));
NzVector3f tmp = NzVector3f::UnitX() * 100.f;
REQUIRE(nzIntersectionSide_Inside == frustum.Intersect(&tmp, 1));
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());
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)));
Nz::Vector3f tmp = Nz::Vector3f::UnitX() * 100.f;
REQUIRE(Nz::IntersectionSide_Inside == frustum.Intersect(&tmp, 1));
}
}
@@ -49,15 +49,15 @@ SCENARIO("Frustum", "[MATH][FRUSTUM]")
{
THEN("These results are expected")
{
NzBoundingVolumef bv(0.f, -0.25f, -0.25f, 0.5f, 0.5f, 0.5f);
bv.Update(NzMatrix4f::Identity());
Nz::BoundingVolumef bv(0.f, -0.25f, -0.25f, 0.5f, 0.5f, 0.5f);
bv.Update(Nz::Matrix4f::Identity());
CHECK(!frustum.Contains(bv));
CHECK(!frustum.Contains(NzBoxf(0.f, -0.25f, -0.25f, 0.5f, 0.5f, 0.5f)));
NzOrientedBoxf obb(0.f, -0.25f, -0.25f, 0.5f, 0.5f, 0.5f);
obb.Update(NzMatrix4f::Identity());
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);
obb.Update(Nz::Matrix4f::Identity());
CHECK(!frustum.Contains(obb));
CHECK(!frustum.Contains(NzSpheref(NzVector3f::Zero(), 0.5f)));
NzVector3f tmp = NzVector3f::Zero();
CHECK(!frustum.Contains(Nz::Spheref(Nz::Vector3f::Zero(), 0.5f)));
Nz::Vector3f tmp = Nz::Vector3f::Zero();
CHECK(!frustum.Contains(&tmp, 1));
}
}
@@ -66,15 +66,15 @@ SCENARIO("Frustum", "[MATH][FRUSTUM]")
{
THEN("These results are expected")
{
NzBoundingVolumef bv(500.f, -0.5f, -0.5f, 1.f, 1.f, 1.f);
bv.Update(NzMatrix4f::Identity());
Nz::BoundingVolumef bv(500.f, -0.5f, -0.5f, 1.f, 1.f, 1.f);
bv.Update(Nz::Matrix4f::Identity());
CHECK(frustum.Contains(bv));
CHECK(frustum.Contains(NzBoxf(500.f, -0.5f, -0.5f, 1.f, 1.f, 1.f)));
NzOrientedBoxf obb(500.f, -0.5f, -0.5f, 1.f, 1.f, 1.f);
obb.Update(NzMatrix4f::Identity());
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);
obb.Update(Nz::Matrix4f::Identity());
CHECK(frustum.Contains(obb));
CHECK(frustum.Contains(NzSpheref(NzVector3f::UnitX() * 500.f, 1.f)));
NzVector3f tmp = NzVector3f::UnitX() * 500.f;
CHECK(frustum.Contains(Nz::Spheref(Nz::Vector3f::UnitX() * 500.f, 1.f)));
Nz::Vector3f tmp = Nz::Vector3f::UnitX() * 500.f;
CHECK(frustum.Contains(&tmp, 1));
}
}

View File

@@ -1,12 +1,12 @@
#include <Nazara/Math/Matrix4.hpp>
#include <Catch/catch.hpp>
SCENARIO("Matrix4", "[MATH][MATRIX4]")
SCENARIO("Matrix4", "[MATH][Matrix4]")
{
GIVEN("Two identity matrix")
{
NzMatrix4f firstIdentity(NzMatrix4<int>::Identity());
NzMatrix4f secondIdentity(1.f, 0.f, 0.f, 0.f, 0.f, 1.f, 0.f, 0.f, 0.f, 0.f, 1.f, 0.f, 0.f, 0.f, 0.f, 1.f);
Nz::Matrix4f firstIdentity(Nz::Matrix4<int>::Identity());
Nz::Matrix4f secondIdentity(1.f, 0.f, 0.f, 0.f, 0.f, 1.f, 0.f, 0.f, 0.f, 0.f, 1.f, 0.f, 0.f, 0.f, 0.f, 1.f);
WHEN("We compare them")
{
@@ -16,13 +16,13 @@ SCENARIO("Matrix4", "[MATH][MATRIX4]")
}
}
WHEN("We multiply the first with a vector")
WHEN("We multiply the first with a Nz::Vector")
{
THEN("Vector stay the same")
THEN("Nz::Vector stay the same")
{
REQUIRE(firstIdentity.Transform(NzVector2f::Unit()) == NzVector2f::Unit());
REQUIRE(firstIdentity.Transform(NzVector3f::Unit()) == NzVector3f::Unit());
REQUIRE(firstIdentity.Transform(NzVector4f(1.f, 1.f, 1.f, 1.f)) == NzVector4f(1.f, 1.f, 1.f, 1.f));
REQUIRE(firstIdentity.Transform(Nz::Vector2f::Unit()) == Nz::Vector2f::Unit());
REQUIRE(firstIdentity.Transform(Nz::Vector3f::Unit()) == Nz::Vector3f::Unit());
REQUIRE(firstIdentity.Transform(Nz::Vector4f(1.f, 1.f, 1.f, 1.f)) == Nz::Vector4f(1.f, 1.f, 1.f, 1.f));
}
}
@@ -41,12 +41,12 @@ SCENARIO("Matrix4", "[MATH][MATRIX4]")
GIVEN("Two different matrix")
{
NzMatrix4f matrix1(1.0f, 0.0f, 0.0f, 0.0f,
Nz::Matrix4f matrix1(1.0f, 0.0f, 0.0f, 0.0f,
7.0f, 2.0f, 0.0f, 0.0f,
1.0f, 5.0f, 3.0f, 0.0f,
8.0f, 9.0f, 2.0f, 4.0f);
NzMatrix4f matrix2(1.0f, 1.0f, 2.0f, -1.0f,
Nz::Matrix4f matrix2(1.0f, 1.0f, 2.0f, -1.0f,
-2.0f, -1.0f, -2.0f, 2.0f,
4.0f, 2.0f, 5.0f, -4.0f,
5.0f, -3.0f, -7.0f, -6.0f);
@@ -62,71 +62,71 @@ SCENARIO("Matrix4", "[MATH][MATRIX4]")
WHEN("We multiply the matrix and its inverse")
{
NzMatrix4f invMatrix1;
Nz::Matrix4f invMatrix1;
matrix1.GetInverse(&invMatrix1);
NzMatrix4f invMatrix2;
Nz::Matrix4f invMatrix2;
matrix2.GetInverse(&invMatrix2);
THEN("We get the identity")
{
NzMatrix4f tmp = matrix1 * invMatrix1;
Nz::Matrix4f tmp = matrix1 * invMatrix1;
REQUIRE(tmp.m32 == Approx(0.f));
REQUIRE(tmp.m42 == Approx(0.f));
tmp.m32 = 0.f;
tmp.m42 = 0.f;
REQUIRE(tmp == NzMatrix4f::Identity());
REQUIRE((matrix2 * invMatrix2) == NzMatrix4f::Identity());
REQUIRE(tmp == Nz::Matrix4f::Identity());
REQUIRE((matrix2 * invMatrix2) == Nz::Matrix4f::Identity());
}
}
}
GIVEN("One transformed matrix from rotation 45 and translation 0")
{
NzMatrix4f transformedMatrix = NzMatrix4f::Transform(NzVector3f::Zero(), NzQuaternionf::Identity());
REQUIRE(transformedMatrix == NzMatrix4f::Identity());
Nz::Matrix4f transformedMatrix = Nz::Matrix4f::Transform(Nz::Vector3f::Zero(), Nz::Quaternionf::Identity());
REQUIRE(transformedMatrix == Nz::Matrix4f::Identity());
WHEN("We compare with the right matrix")
{
THEN("Rotation around X")
{
transformedMatrix.MakeTransform(NzVector3f::Zero(), NzEulerAnglesf(NzFromDegrees(45.f), 0.f, 0.f).ToQuaternion());
NzMatrix4f rotation45X(1.f, 0.f, 0.f, 0.f,
transformedMatrix.MakeTransform(Nz::Vector3f::Zero(), Nz::EulerAnglesf(Nz::FromDegrees(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);
REQUIRE(transformedMatrix == rotation45X);
transformedMatrix.MakeTransform(NzVector3f::Unit(), NzEulerAnglesf(NzFromDegrees(45.f), 0.f, 0.f).ToQuaternion());
rotation45X.ApplyTranslation(NzVector3f::Unit());
transformedMatrix.MakeTransform(Nz::Vector3f::Unit(), Nz::EulerAnglesf(Nz::FromDegrees(45.f), 0.f, 0.f).ToQuaternion());
rotation45X.ApplyTranslation(Nz::Vector3f::Unit());
REQUIRE(transformedMatrix == rotation45X);
}
THEN("Rotation around Y")
{
transformedMatrix.MakeTransform(NzVector3f::Zero(), NzEulerAnglesf(0.f, NzFromDegrees(45.f), 0.f).ToQuaternion());
NzMatrix4f rotation45Y(std::sqrt(2.f) / 2.f, 0.f, -std::sqrt(2.f) / 2.f, 0.f,
transformedMatrix.MakeTransform(Nz::Vector3f::Zero(), Nz::EulerAnglesf(0.f, Nz::FromDegrees(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);
REQUIRE(transformedMatrix == rotation45Y);
transformedMatrix.MakeTransform(NzVector3f::Unit(), NzEulerAnglesf(0.f, NzFromDegrees(45.f), 0.f).ToQuaternion());
rotation45Y.ApplyTranslation(NzVector3f::Unit());
transformedMatrix.MakeTransform(Nz::Vector3f::Unit(), Nz::EulerAnglesf(0.f, Nz::FromDegrees(45.f), 0.f).ToQuaternion());
rotation45Y.ApplyTranslation(Nz::Vector3f::Unit());
REQUIRE(transformedMatrix == rotation45Y);
}
THEN("Rotation around Z")
{
transformedMatrix.MakeTransform(NzVector3f::Zero(), NzEulerAnglesf(0.f, 0.f, NzFromDegrees(45.f)).ToQuaternion());
NzMatrix4f rotation45Z( std::sqrt(2.f) / 2.f, std::sqrt(2.f) / 2.f, 0.f, 0.f,
transformedMatrix.MakeTransform(Nz::Vector3f::Zero(), Nz::EulerAnglesf(0.f, 0.f, Nz::FromDegrees(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);
REQUIRE(transformedMatrix == rotation45Z);
transformedMatrix.MakeTransform(NzVector3f::Unit(), NzEulerAnglesf(NzEulerAnglesf(0.f, 0.f, NzFromDegrees(45.f)).ToQuaternion()));
rotation45Z.ApplyTranslation(NzVector3f::Unit());
transformedMatrix.MakeTransform(Nz::Vector3f::Unit(), Nz::EulerAnglesf(Nz::EulerAnglesf(0.f, 0.f, Nz::FromDegrees(45.f)).ToQuaternion()));
rotation45Z.ApplyTranslation(Nz::Vector3f::Unit());
REQUIRE(transformedMatrix == rotation45Z);
}
}

View File

@@ -5,11 +5,11 @@ SCENARIO("OrientedBox", "[MATH][ORIENTEDBOX]")
{
GIVEN("Two center and unit oriented boxes")
{
NzOrientedBoxf firstCenterAndUnit(0.f, 0.f, 0.f, 1.f, 1.f, 1.f);
NzOrientedBoxf secondCenterAndUnit(NzOrientedBox<int>(NzVector3i::Zero(), NzVector3i::Unit()));
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()));
firstCenterAndUnit.Update(NzMatrix4f::Identity());
secondCenterAndUnit.Update(NzMatrix4f::Identity());
firstCenterAndUnit.Update(Nz::Matrix4f::Identity());
secondCenterAndUnit.Update(Nz::Matrix4f::Identity());
WHEN("We compare them")
{
@@ -33,11 +33,11 @@ SCENARIO("OrientedBox", "[MATH][ORIENTEDBOX]")
THEN("Results are different between operator * and update(ScaleMatrix) but corners are the same")
{
firstCenterAndUnit *= 2.f;
firstCenterAndUnit.Update(NzMatrix4f::Identity());
secondCenterAndUnit.Update(NzMatrix4f::Scale(NzVector3f::Unit() * 2.f));
firstCenterAndUnit.Update(Nz::Matrix4f::Identity());
secondCenterAndUnit.Update(Nz::Matrix4f::Scale(Nz::Vector3f::Unit() * 2.f));
REQUIRE(firstCenterAndUnit != secondCenterAndUnit);
for (unsigned int i = 0; i <= nzBoxCorner_Max; ++i)
for (unsigned int i = 0; i <= Nz::BoxCorner_Max; ++i)
{
REQUIRE(firstCenterAndUnit(i) == secondCenterAndUnit(i));
}

View File

@@ -5,8 +5,8 @@ SCENARIO("Plane", "[MATH][PLANE]")
{
GIVEN("Two planes normal(1, 1, 1), distance 1")
{
NzPlanef firstPlane(NzVector3f::Unit().Normalize(), 1.f);
NzPlanef secondPlane(NzPlaned(NzVector3d::Unit().Normalize(), 1.0));
Nz::Planef firstPlane(Nz::Vector3f::Unit().Normalize(), 1.f);
Nz::Planef secondPlane(Nz::Planed(Nz::Vector3d::Unit().Normalize(), 1.0));
WHEN("We compare them")
{
@@ -17,36 +17,36 @@ SCENARIO("Plane", "[MATH][PLANE]")
AND_THEN("We compare with normal(-1, -1, -1), distance -1")
{
REQUIRE(firstPlane == NzPlanef(-NzVector3f::Unit().Normalize(), -1.f));
REQUIRE(firstPlane == Nz::Planef(-Nz::Vector3f::Unit().Normalize(), -1.f));
}
AND_THEN("They have the same distance from the same point")
{
NzVector3f point(-2.f, 3.f, 1.f);
Nz::Vector3f point(-2.f, 3.f, 1.f);
REQUIRE(firstPlane.Distance(point) == Approx(secondPlane.Distance(point)));
REQUIRE(firstPlane.Distance(-2.f, 3.f, 1.f) == Approx(0.1547f));
}
AND_THEN("Distance between Plane (0, 1, 0), distance 1 and point (0, 2, 0) should be 1")
{
REQUIRE(NzPlanef(NzVector3f::UnitY(), 1.f).Distance(NzVector3f::UnitY() * 2.f) == Approx(1.f));
REQUIRE(Nz::Planef(Nz::Vector3f::UnitY(), 1.f).Distance(Nz::Vector3f::UnitY() * 2.f) == Approx(1.f));
}
AND_THEN("Distance between Plane (0, 1, 0), distance 5 and point (0, 2, 0) should be -3")
{
REQUIRE(NzPlanef(NzVector3f::UnitY(), 5.f).Distance(NzVector3f::UnitY() * 2.f) == Approx(-3.f));
REQUIRE(Nz::Planef(Nz::Vector3f::UnitY(), 5.f).Distance(Nz::Vector3f::UnitY() * 2.f) == Approx(-3.f));
}
AND_THEN("Distance between Plane (0, 1, 0), distance 1000 and point (0, 500, 0) and (0, 1500, 0)")
{
REQUIRE(NzPlanef(NzVector3f::UnitY(), 1000.f).Distance(NzVector3f::UnitY() * 500.f) == Approx(-500.f));
REQUIRE(NzPlanef(NzVector3f::UnitY(), 1000.f).Distance(NzVector3f::UnitY() * 1500.f) == Approx(500.f));
REQUIRE(Nz::Planef(Nz::Vector3f::UnitY(), 1000.f).Distance(Nz::Vector3f::UnitY() * 500.f) == Approx(-500.f));
REQUIRE(Nz::Planef(Nz::Vector3f::UnitY(), 1000.f).Distance(Nz::Vector3f::UnitY() * 1500.f) == Approx(500.f));
}
AND_THEN("Distance between Plane (0, -1, 0), distance -1000 and point (0, 500, 0) and (0, 1500, 0)")
{
REQUIRE(NzPlanef(-NzVector3f::UnitY(), -1000.f).Distance(NzVector3f::UnitY() * 500.f) == Approx(500.f));
REQUIRE(NzPlanef(-NzVector3f::UnitY(), -1000.f).Distance(NzVector3f::UnitY() * 1500.f) == Approx(-500.f));
REQUIRE(Nz::Planef(-Nz::Vector3f::UnitY(), -1000.f).Distance(Nz::Vector3f::UnitY() * 500.f) == Approx(500.f));
REQUIRE(Nz::Planef(-Nz::Vector3f::UnitY(), -1000.f).Distance(Nz::Vector3f::UnitY() * 1500.f) == Approx(-500.f));
}
}
}
@@ -55,20 +55,20 @@ SCENARIO("Plane", "[MATH][PLANE]")
{
WHEN("We do a positive plane")
{
NzPlanef xy(NzVector3f(2.f, 1.f, 0.f), NzVector3f(-1.f, 1.f, -1.f), NzVector3f(-1.f, 1.f, 0.f));
Nz::Planef xy(Nz::Vector3f(2.f, 1.f, 0.f), Nz::Vector3f(-1.f, 1.f, -1.f), Nz::Vector3f(-1.f, 1.f, 0.f));
THEN("It must be equal to XZ distance 1")
{
REQUIRE(xy == NzPlanef(NzVector3f::UnitY(), 1.f));
REQUIRE(xy == Nz::Planef(Nz::Vector3f::UnitY(), 1.f));
}
}
WHEN("We do a negative plane")
{
NzPlanef xy(NzVector3f(0.f, 1.f, 0.f), NzVector3f(1.f, 1.f, 1.f), NzVector3f(-1.f, 1.f, 0.f));
Nz::Planef xy(Nz::Vector3f(0.f, 1.f, 0.f), Nz::Vector3f(1.f, 1.f, 1.f), Nz::Vector3f(-1.f, 1.f, 0.f));
THEN("It must be equal to XZ distance 1")
{
REQUIRE(xy == NzPlanef(-NzVector3f::UnitY(), -1.f));
REQUIRE(xy == Nz::Planef(-Nz::Vector3f::UnitY(), -1.f));
}
}
}

View File

@@ -5,8 +5,8 @@ SCENARIO("Quaternion", "[MATH][QUATERNION]")
{
GIVEN("Two quaternions (0, 1, 0, 0)")
{
NzQuaternionf firstQuaternion(NzFromDegrees(180.f), NzVector3f::UnitX());
NzQuaternionf secondQuaternion(0.f, 1.f, 0.f, 0.f);
Nz::Quaternionf firstQuaternion(Nz::FromDegrees(180.f), Nz::Vector3f::UnitX());
Nz::Quaternionf secondQuaternion(0.f, 1.f, 0.f, 0.f);
WHEN("We compare them")
{
@@ -23,25 +23,25 @@ SCENARIO("Quaternion", "[MATH][QUATERNION]")
{
THEN("Multiply with a vectorX is identity")
{
REQUIRE((firstQuaternion * NzVector3f::UnitX()) == NzVector3f::UnitX());
REQUIRE((firstQuaternion * Nz::Vector3f::UnitX()) == Nz::Vector3f::UnitX());
}
AND_THEN("Multiply with a vectorY or Z is opposite")
{
REQUIRE((firstQuaternion * NzVector3f::UnitY()) == -NzVector3f::UnitY());
REQUIRE((firstQuaternion * NzVector3f::UnitZ()) == -NzVector3f::UnitZ());
REQUIRE((firstQuaternion * Nz::Vector3f::UnitY()) == -Nz::Vector3f::UnitY());
REQUIRE((firstQuaternion * Nz::Vector3f::UnitZ()) == -Nz::Vector3f::UnitZ());
}
}
}
GIVEN("The four unit quaternions")
{
NzQuaternionf w(1.f, 0.f, 0.f, 0.f);
NzQuaternionf x(0.f, 1.f, 0.f, 0.f);
NzQuaternionf y(0.f, 0.f, 1.f, 0.f);
NzQuaternionf z(0.f, 0.f, 0.f, 1.f);
Nz::Quaternionf w(1.f, 0.f, 0.f, 0.f);
Nz::Quaternionf x(0.f, 1.f, 0.f, 0.f);
Nz::Quaternionf y(0.f, 0.f, 1.f, 0.f);
Nz::Quaternionf z(0.f, 0.f, 0.f, 1.f);
NzQuaternionf xyzw = x * y * z * w;
Nz::Quaternionf xyzw = x * y * z * w;
WHEN("We ask for the norm")
{
@@ -59,10 +59,10 @@ SCENARIO("Quaternion", "[MATH][QUATERNION]")
{
THEN("Results shoud follow")
{
NzQuaternionf oppositeOfW(-1.f, 0.f, 0.f, 0.f);
NzQuaternionf oppositeOfX = x.GetConjugate();
NzQuaternionf oppositeOfY = y.GetConjugate();
NzQuaternionf oppositeOfZ = z.GetConjugate();
Nz::Quaternionf oppositeOfW(-1.f, 0.f, 0.f, 0.f);
Nz::Quaternionf oppositeOfX = x.GetConjugate();
Nz::Quaternionf oppositeOfY = y.GetConjugate();
Nz::Quaternionf oppositeOfZ = z.GetConjugate();
REQUIRE((x * x) == oppositeOfW);
REQUIRE((y * y) == oppositeOfW);
@@ -81,32 +81,32 @@ SCENARIO("Quaternion", "[MATH][QUATERNION]")
GIVEN("Two different quaternions (10, (1, 0, 0) and (20, (1, 0, 0))")
{
NzQuaternionf x10 = NzQuaternionf(NzFromDegrees(10.f), NzVector3f::UnitX());
NzQuaternionf x20 = x10 * x10;
Nz::Quaternionf x10 = Nz::Quaternionf(Nz::FromDegrees(10.f), Nz::Vector3f::UnitX());
Nz::Quaternionf x20 = x10 * x10;
NzQuaternionf x30a = x10 * x20;
NzQuaternionf x30b = x20 * x10;
Nz::Quaternionf x30a = x10 * x20;
Nz::Quaternionf x30b = x20 * x10;
WHEN("We multiply them")
{
THEN("These results are expected")
{
REQUIRE(x20 == NzQuaternionf(NzFromDegrees(20.f), NzVector3f::UnitX()));
REQUIRE(x20 == Nz::Quaternionf(Nz::FromDegrees(20.f), Nz::Vector3f::UnitX()));
REQUIRE(x30a == x30b);
}
}
WHEN("Convert euler to quaternion")
{
NzQuaternionf X45(NzEulerAnglesf(NzFromDegrees(45.f), 0.f, 0.f));
NzQuaternionf Y45(NzEulerAnglesf(0.f, NzFromDegrees(45.f), 0.f));
NzQuaternionf Z45(NzEulerAnglesf(0.f, 0.f, NzFromDegrees(45.f)));
Nz::Quaternionf X45(Nz::EulerAnglesf(Nz::FromDegrees(45.f), 0.f, 0.f));
Nz::Quaternionf Y45(Nz::EulerAnglesf(0.f, Nz::FromDegrees(45.f), 0.f));
Nz::Quaternionf Z45(Nz::EulerAnglesf(0.f, 0.f, Nz::FromDegrees(45.f)));
THEN("They must be equal")
{
REQUIRE(X45 == NzQuaternionf(0.9238795f, 0.38268346f, 0.f, 0.f));
REQUIRE(Y45 == NzQuaternionf(0.9238795f, 0.f, 0.38268346f, 0.f));
REQUIRE(Z45 == NzQuaternionf(0.9238795f, 0.f, 0.f, 0.38268346f));
REQUIRE(X45 == Nz::Quaternionf(0.9238795f, 0.38268346f, 0.f, 0.f));
REQUIRE(Y45 == Nz::Quaternionf(0.9238795f, 0.f, 0.38268346f, 0.f));
REQUIRE(Z45 == Nz::Quaternionf(0.9238795f, 0.f, 0.f, 0.38268346f));
}
}
@@ -117,7 +117,7 @@ SCENARIO("Quaternion", "[MATH][QUATERNION]")
REQUIRE(x30a.ToEulerAngles() == x30b.ToEulerAngles());
REQUIRE(x30a.ToEulerAngles().ToQuaternion() == x30b.ToEulerAngles().ToQuaternion());
NzQuaternionf tmp(1.f, 1.f, 0.f, 0.f);
Nz::Quaternionf tmp(1.f, 1.f, 0.f, 0.f);
tmp.Normalize();
REQUIRE(tmp == tmp.ToEulerAngles().ToQuaternion());
}
@@ -127,27 +127,27 @@ SCENARIO("Quaternion", "[MATH][QUATERNION]")
{
THEN("The half of 10 and 30 is 20")
{
NzQuaternionf slerpx10x30a = NzQuaternionf::Slerp(x10, x30a, 0.5f);
Nz::Quaternionf slerpx10x30a = Nz::Quaternionf::Slerp(x10, x30a, 0.5f);
REQUIRE(slerpx10x30a.w == Approx(x20.w));
REQUIRE(slerpx10x30a.x == Approx(x20.x));
REQUIRE(slerpx10x30a.y == Approx(x20.y));
REQUIRE(slerpx10x30a.z == Approx(x20.z));
NzQuaternionf slerpx10x30b = NzQuaternionf::Slerp(x10, x30b, 0.5f);
Nz::Quaternionf slerpx10x30b = Nz::Quaternionf::Slerp(x10, x30b, 0.5f);
REQUIRE(slerpx10x30b.w == Approx(x20.w));
REQUIRE(slerpx10x30b.x == Approx(x20.x));
REQUIRE(slerpx10x30b.y == Approx(x20.y));
REQUIRE(slerpx10x30b.z == Approx(x20.z));
REQUIRE(NzQuaternionf::Slerp(x10, x30a, 0.f) == x10);
REQUIRE(NzQuaternionf::Slerp(x10, x30a, 1.f) == x30a);
REQUIRE(Nz::Quaternionf::Slerp(x10, x30a, 0.f) == x10);
REQUIRE(Nz::Quaternionf::Slerp(x10, x30a, 1.f) == x30a);
}
AND_THEN("The half of 45 is 22.5")
{
NzQuaternionf quaterionA(NzFromDegrees(0.f), NzVector3f::UnitZ());
NzQuaternionf quaterionB(NzFromDegrees(45.f), NzVector3f::UnitZ());
NzQuaternionf quaternionC = NzQuaternionf::Slerp(quaterionA, quaterionB, 0.5f);
Nz::Quaternionf quaterionA(Nz::FromDegrees(0.f), Nz::Vector3f::UnitZ());
Nz::Quaternionf quaterionB(Nz::FromDegrees(45.f), Nz::Vector3f::UnitZ());
Nz::Quaternionf quaternionC = Nz::Quaternionf::Slerp(quaterionA, quaterionB, 0.5f);
NzQuaternionf unitZ225(NzFromDegrees(22.5f), NzVector3f::UnitZ());
Nz::Quaternionf unitZ225(Nz::FromDegrees(22.5f), Nz::Vector3f::UnitZ());
REQUIRE(quaternionC.w == Approx(unitZ225.w));
REQUIRE(quaternionC.x == Approx(unitZ225.x));
REQUIRE(quaternionC.y == Approx(unitZ225.y));

View File

@@ -1,27 +1,27 @@
#include <Nazara/Math/Ray.hpp>
#include <Catch/catch.hpp>
SCENARIO("Ray", "[RAY]")
SCENARIO("Ray", "[MATH][RAY]")
{
GIVEN("Two same rays (0, 0, 0) -> (0, 1, 0)")
GIVEN("Two same Rays (0, 0, 0) -> (0, 1, 0)")
{
NzRayf firstRay(NzRay<int>(NzPlane<int>::XY(), NzPlane<int>::YZ()));
NzRayf secondRay(0.f, 0.f, 0.f, 0.f, 1.f, 0.f);
Nz::Rayf ray(Nz::Ray<int>(Nz::Plane<int>::XY(), Nz::Plane<int>::YZ()));
Nz::Rayf secondRay(0.f, 0.f, 0.f, 0.f, 1.f, 0.f);
WHEN("We compare them")
{
THEN("They are the same and Y axis")
{
REQUIRE(firstRay == secondRay);
REQUIRE(firstRay == NzRayf::AxisY());
REQUIRE(ray == secondRay);
REQUIRE(ray == Nz::Rayf::AxisY());
}
}
WHEN("We ask for the closest point")
{
THEN("The point that is multiple on the ray, is at multiple")
THEN("The point that is multiple on the Nz::Ray, is at multiple")
{
REQUIRE(firstRay.ClosestPoint(secondRay.GetPoint(1.f)) == Approx(1.f));
REQUIRE(ray.ClosestPoint(secondRay.GetPoint(1.f)) == Approx(1.f));
}
}
@@ -32,24 +32,24 @@ SCENARIO("Ray", "[RAY]")
float tmpClosest;
float tmpFurthest;
CHECK(firstRay.Intersect(NzBoxf(-0.5f, 1.f, -0.5f, 1.f, 1.f, 1.f), &tmpClosest, &tmpFurthest));
REQUIRE(firstRay.GetPoint(tmpClosest) == NzVector3f::UnitY());
REQUIRE(firstRay.GetPoint(tmpFurthest) == (NzVector3f::UnitY() * 2.f));
CHECK(!firstRay.Intersect(NzBoxf(-10.f, 1.f, -10.f, 1.f, 1.f, 1.f), &tmpClosest, &tmpFurthest));
CHECK(ray.Intersect(Nz::Boxf(-0.5f, 1.f, -0.5f, 1.f, 1.f, 1.f), &tmpClosest, &tmpFurthest));
REQUIRE(ray.GetPoint(tmpClosest) == Nz::Vector3f::UnitY());
REQUIRE(ray.GetPoint(tmpFurthest) == (Nz::Vector3f::UnitY() * 2.f));
CHECK(!ray.Intersect(Nz::Boxf(-10.f, 1.f, -10.f, 1.f, 1.f, 1.f), &tmpClosest, &tmpFurthest));
}
THEN("For the Plane collision's")
THEN("For the Nz::Plane collision's")
{
float tmpHit;
CHECK(firstRay.Intersect(NzPlanef(NzVector3f::UnitY(), 1.f), &tmpHit));
REQUIRE(firstRay.GetPoint(tmpHit) == NzVector3f::UnitY());
CHECK(firstRay.Intersect(NzPlanef::XZ(), &tmpHit));
REQUIRE(firstRay.GetPoint(tmpHit) == NzVector3f::Zero());
CHECK(firstRay.Intersect(NzPlanef(NzVector3f::UnitY(), 2.f), &tmpHit));
REQUIRE(firstRay.GetPoint(tmpHit) == 2.f * NzVector3f::UnitY());
CHECK(ray.Intersect(Nz::Planef(Nz::Vector3f::UnitY(), 1.f), &tmpHit));
REQUIRE(ray.GetPoint(tmpHit) == Nz::Vector3f::UnitY());
CHECK(ray.Intersect(Nz::Planef::XZ(), &tmpHit));
REQUIRE(ray.GetPoint(tmpHit) == Nz::Vector3f::Zero());
CHECK(ray.Intersect(Nz::Planef(Nz::Vector3f::UnitY(), 2.f), &tmpHit));
REQUIRE(ray.GetPoint(tmpHit) == 2.f * Nz::Vector3f::UnitY());
CHECK(!firstRay.Intersect(NzPlanef(NzVector3f::UnitX(), 1.f)));
CHECK(!ray.Intersect(Nz::Planef(Nz::Vector3f::UnitX(), 1.f)));
}
THEN("For the Sphere collision's")
@@ -57,11 +57,11 @@ SCENARIO("Ray", "[RAY]")
float tmpClosest;
float tmpFurthest;
CHECK(firstRay.Intersect(NzSpheref(NzVector3f::UnitY(), 0.1f), &tmpClosest, &tmpFurthest));
REQUIRE(firstRay.GetPoint(tmpClosest) == NzVector3f::UnitY() * 0.9f);
REQUIRE(firstRay.GetPoint(tmpFurthest) == (NzVector3f::UnitY() * 1.1f));
CHECK(ray.Intersect(Nz::Spheref(Nz::Vector3f::UnitY(), 0.1f), &tmpClosest, &tmpFurthest));
REQUIRE(ray.GetPoint(tmpClosest) == Nz::Vector3f::UnitY() * 0.9f);
REQUIRE(ray.GetPoint(tmpFurthest) == (Nz::Vector3f::UnitY() * 1.1f));
CHECK(!firstRay.Intersect(NzSpheref(NzVector3f::UnitX(), 0.9f)));
CHECK(!ray.Intersect(Nz::Spheref(Nz::Vector3f::UnitX(), 0.9f)));
}
THEN("For the OBB collision's")
@@ -69,25 +69,25 @@ SCENARIO("Ray", "[RAY]")
float tmpClosest;
float tmpFurthest;
NzOrientedBoxf obb(-0.5f, 1.f, -0.5f, 1.f, 1.f, 1.f);
obb.Update(NzMatrix4f::Rotate(NzEulerAnglesf(0.f, 90.f, 0.f).ToQuaternion()));
Nz::OrientedBoxf obb(-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(firstRay.Intersect(obb, &tmpClosest, &tmpFurthest));
REQUIRE(firstRay.GetPoint(tmpClosest) == NzVector3f::UnitY());
REQUIRE(firstRay.GetPoint(tmpFurthest) == (NzVector3f::UnitY() * 2.f));
CHECK(ray.Intersect(obb, &tmpClosest, &tmpFurthest));
REQUIRE(ray.GetPoint(tmpClosest) == Nz::Vector3f::UnitY());
REQUIRE(ray.GetPoint(tmpFurthest) == (Nz::Vector3f::UnitY() * 2.f));
obb = NzOrientedBoxf(-10.f, 1.f, -10.f, 1.f, 1.f, 1.f);
obb.Update(NzMatrix4f::Rotate(NzEulerAnglesf(0.f, 0.f, 90.f).ToQuaternion()));
CHECK(!firstRay.Intersect(obb, &tmpClosest, &tmpFurthest));
obb = Nz::OrientedBoxf(-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));
}
THEN("For the bounding volume collision's")
{
NzBoundingVolumef nullVolume(nzExtend_Null);
CHECK(!firstRay.Intersect(nullVolume));
Nz::BoundingVolumef nullVolume(Nz::Extend_Null);
CHECK(!ray.Intersect(nullVolume));
NzBoundingVolumef infiniteVolume(nzExtend_Infinite);
CHECK(firstRay.Intersect(infiniteVolume));
Nz::BoundingVolumef infiniteVolume(Nz::Extend_Infinite);
CHECK(ray.Intersect(infiniteVolume));
}
}

View File

@@ -3,10 +3,10 @@
SCENARIO("Rect", "[MATH][RECT]")
{
GIVEN("Two same rectangles center and unit lengths")
GIVEN("Two same Nz::Rectangles center and unit lengths")
{
NzRectf firstCenterAndUnit(0.f, 0.f, 1.f, 1.f);
NzRectf secondCenterAndUnit(NzRecti(NzVector2i::Unit(), NzVector2i::Zero()));
Nz::Rectf firstCenterAndUnit(0.f, 0.f, 1.f, 1.f);
Nz::Rectf secondCenterAndUnit(Nz::Recti(Nz::Vector2i::Unit(), Nz::Vector2i::Zero()));
WHEN("We ask if they are the same")
{
@@ -14,20 +14,20 @@ SCENARIO("Rect", "[MATH][RECT]")
{
REQUIRE(firstCenterAndUnit == secondCenterAndUnit);
REQUIRE(firstCenterAndUnit.GetCenter() == secondCenterAndUnit.GetCenter());
REQUIRE(firstCenterAndUnit.GetCorner(nzRectCorner_LeftBottom) == secondCenterAndUnit.GetCorner(nzRectCorner_LeftBottom));
REQUIRE(firstCenterAndUnit.GetCorner(Nz::RectCorner_LeftBottom) == secondCenterAndUnit.GetCorner(Nz::RectCorner_LeftBottom));
CHECK(firstCenterAndUnit.IsValid());
}
}
WHEN("We move one from (0.5, 0.5)")
{
firstCenterAndUnit.Translate(NzVector2f(0.5f, 0.5f));
firstCenterAndUnit.Translate(Nz::Vector2f(0.5f, 0.5f));
THEN("The collision should be (0.5, 0.5) -> (0.5, 0.5)")
{
NzRectf tmp;
Nz::Rectf tmp;
CHECK(firstCenterAndUnit.Intersect(secondCenterAndUnit, &tmp));
REQUIRE(tmp == NzRectf(0.5f, 0.5f, 0.5f, 0.5f));
REQUIRE(tmp == Nz::Rectf(0.5f, 0.5f, 0.5f, 0.5f));
}
}
@@ -43,12 +43,12 @@ SCENARIO("Rect", "[MATH][RECT]")
{
THEN("These results are expected")
{
REQUIRE(firstCenterAndUnit.GetLengths() == NzVector2f::Unit());
REQUIRE(firstCenterAndUnit.GetMaximum() == NzVector2f::Unit());
REQUIRE(firstCenterAndUnit.GetMinimum() == NzVector2f::Zero());
REQUIRE(firstCenterAndUnit.GetNegativeVertex(NzVector2f::Unit()) == NzVector2f::Zero());
REQUIRE(firstCenterAndUnit.GetPosition() == NzVector2f::Zero());
REQUIRE(firstCenterAndUnit.GetPositiveVertex(NzVector2f::Unit()) == NzVector2f::Unit());
REQUIRE(firstCenterAndUnit.GetLengths() == Nz::Vector2f::Unit());
REQUIRE(firstCenterAndUnit.GetMaximum() == Nz::Vector2f::Unit());
REQUIRE(firstCenterAndUnit.GetMinimum() == Nz::Vector2f::Zero());
REQUIRE(firstCenterAndUnit.GetNegativeVertex(Nz::Vector2f::Unit()) == Nz::Vector2f::Zero());
REQUIRE(firstCenterAndUnit.GetPosition() == Nz::Vector2f::Zero());
REQUIRE(firstCenterAndUnit.GetPositiveVertex(Nz::Vector2f::Unit()) == Nz::Vector2f::Unit());
}
}

View File

@@ -5,8 +5,8 @@ SCENARIO("Sphere", "[MATH][SPHERE]")
{
GIVEN("Two same sphere center and unit")
{
NzSpheref firstCenterAndUnit(0.f, 0.f, 0.f, 1.f);
NzSpheref secondCenterAndUnit(NzSphere<int>(NzVector3i::Zero(), 1));
Nz::Spheref firstCenterAndUnit(0.f, 0.f, 0.f, 1.f);
Nz::Spheref secondCenterAndUnit(Nz::Sphere<int>(Nz::Vector3i::Zero(), 1));
WHEN("We compare them")
{
@@ -21,19 +21,19 @@ SCENARIO("Sphere", "[MATH][SPHERE]")
THEN("These results are expected for Contains")
{
CHECK(firstCenterAndUnit.Contains(0.5f, 0.5f, 0.5f));
CHECK(firstCenterAndUnit.Contains(NzBoxf(NzVector3f::Zero(), NzVector3f::Unit() * 0.5f)));
CHECK(!firstCenterAndUnit.Contains(NzBoxf(NzVector3f::Zero(), NzVector3f::Unit() * 5.f)));
CHECK(firstCenterAndUnit.Contains(Nz::Boxf(Nz::Vector3f::Zero(), Nz::Vector3f::Unit() * 0.5f)));
CHECK(!firstCenterAndUnit.Contains(Nz::Boxf(Nz::Vector3f::Zero(), Nz::Vector3f::Unit() * 5.f)));
}
THEN("There are for Intersect")
{
CHECK(firstCenterAndUnit.Intersect(NzBoxf(NzVector3f::Zero(), NzVector3f::Unit() * 0.5f)));
CHECK(firstCenterAndUnit.Intersect(NzBoxf(NzVector3f::Zero(), NzVector3f::Unit() * 5.f)));
CHECK(!firstCenterAndUnit.Intersect(NzBoxf(NzVector3f::Unit() * 5.f, NzVector3f::Unit())));
CHECK(firstCenterAndUnit.Intersect(Nz::Boxf(Nz::Vector3f::Zero(), Nz::Vector3f::Unit() * 0.5f)));
CHECK(firstCenterAndUnit.Intersect(Nz::Boxf(Nz::Vector3f::Zero(), Nz::Vector3f::Unit() * 5.f)));
CHECK(!firstCenterAndUnit.Intersect(Nz::Boxf(Nz::Vector3f::Unit() * 5.f, Nz::Vector3f::Unit())));
CHECK(firstCenterAndUnit.Intersect(NzSpheref(NzVector3f::Zero(), 0.5f)));
CHECK(firstCenterAndUnit.Intersect(NzSpheref(NzVector3f::Zero(), 5.f)));
CHECK(!firstCenterAndUnit.Intersect(NzSpheref(NzVector3f::Unit() * 5.f, 1.f)));
CHECK(firstCenterAndUnit.Intersect(Nz::Spheref(Nz::Vector3f::Zero(), 0.5f)));
CHECK(firstCenterAndUnit.Intersect(Nz::Spheref(Nz::Vector3f::Zero(), 5.f)));
CHECK(!firstCenterAndUnit.Intersect(Nz::Spheref(Nz::Vector3f::Unit() * 5.f, 1.f)));
}
}
@@ -41,22 +41,22 @@ SCENARIO("Sphere", "[MATH][SPHERE]")
{
THEN("These results are expected")
{
REQUIRE(firstCenterAndUnit.Distance(NzVector3f::UnitX()) == Approx(1.f));
REQUIRE(firstCenterAndUnit.SquaredDistance(NzVector3f::UnitX()) == Approx(1.f));
REQUIRE(firstCenterAndUnit.Distance(Nz::Vector3f::UnitX()) == Approx(1.f));
REQUIRE(firstCenterAndUnit.SquaredDistance(Nz::Vector3f::UnitX()) == Approx(1.f));
NzSpheref tmp(NzVector3f::UnitX(), 1.f);
REQUIRE(tmp.Distance(NzVector3f::UnitX() * 4.f) == Approx(3.f));
REQUIRE(tmp.SquaredDistance(NzVector3f::UnitX() * 4.f) == Approx(9.f));
Nz::Spheref tmp(Nz::Vector3f::UnitX(), 1.f);
REQUIRE(tmp.Distance(Nz::Vector3f::UnitX() * 4.f) == Approx(3.f));
REQUIRE(tmp.SquaredDistance(Nz::Vector3f::UnitX() * 4.f) == Approx(9.f));
}
}
WHEN("We get sphere from box unit and center")
{
NzBoxf centerUnitBox(NzVector3f::Unit() * -0.5f, NzVector3f::Unit() * 0.5f);
Nz::Boxf centerUnitBox(Nz::Vector3f::Unit() * -0.5f, Nz::Vector3f::Unit() * 0.5f);
THEN("This is equal to sphere center and radius 0.75")
{
REQUIRE(centerUnitBox.GetSquaredBoundingSphere() == NzSpheref(NzVector3f::Zero(), 0.75f));
REQUIRE(centerUnitBox.GetSquaredBoundingSphere() == Nz::Spheref(Nz::Vector3f::Zero(), 0.75f));
}
}
}

View File

@@ -7,8 +7,8 @@ SCENARIO("Vector2", "[MATH][VECTOR2]")
{
GIVEN("Two same vectors (1, 1)")
{
NzVector2f firstUnit(1.f);
NzVector2f secondUnit(NzVector2i(NzVector4i(1, 1, 3, 5)));
Nz::Vector2f firstUnit(1.f);
Nz::Vector2f secondUnit(Nz::Vector2i(Nz::Vector4i(1, 1, 3, 5)));
WHEN("We compare them")
{
@@ -20,7 +20,7 @@ SCENARIO("Vector2", "[MATH][VECTOR2]")
WHEN("We test the dot product")
{
NzVector2f tmp(-1.f, 1.f);
Nz::Vector2f tmp(-1.f, 1.f);
THEN("These results are expected")
{
@@ -32,8 +32,8 @@ SCENARIO("Vector2", "[MATH][VECTOR2]")
WHEN("We ask for distance from (-2, -3)")
{
NzVector2f tmp(-2.f, -3.f);
NzVector2f tmp2(-1.f, -1.f);
Nz::Vector2f tmp(-2.f, -3.f);
Nz::Vector2f tmp2(-1.f, -1.f);
THEN("These are expected")
{

View File

@@ -7,8 +7,8 @@ SCENARIO("Vector3", "[MATH][VECTOR3]")
{
GIVEN("Two same unit vector")
{
NzVector3f firstUnit(1.f, 1.f, 1.f);
NzVector3f secondUnit(NzVector3i(NzVector4i(1, 1, 1, 5)));
Nz::Vector3f firstUnit(1.f, 1.f, 1.f);
Nz::Vector3f secondUnit(Nz::Vector3i(Nz::Vector4i(1, 1, 1, 5)));
WHEN("We compare them")
{
@@ -20,7 +20,7 @@ SCENARIO("Vector3", "[MATH][VECTOR3]")
WHEN("We test the dot product")
{
NzVector3f tmp(-1.f, 0.f, 1.f);
Nz::Vector3f tmp(-1.f, 0.f, 1.f);
THEN("These results are expected")
{
@@ -34,14 +34,14 @@ SCENARIO("Vector3", "[MATH][VECTOR3]")
{
THEN("These results are expected")
{
REQUIRE(NzVector3f::CrossProduct(NzVector3f::UnitX(), NzVector3f::UnitY()) == NzVector3f::UnitZ());
REQUIRE(NzVector3f::CrossProduct(NzVector3f(1.f, 2.f, 3.f), NzVector3f(3.f, 2.f, 1.f)) == NzVector3f(-4.f, 8.f, -4.f));
REQUIRE(Nz::Vector3f::CrossProduct(Nz::Vector3f::UnitX(), Nz::Vector3f::UnitY()) == Nz::Vector3f::UnitZ());
REQUIRE(Nz::Vector3f::CrossProduct(Nz::Vector3f(1.f, 2.f, 3.f), Nz::Vector3f(3.f, 2.f, 1.f)) == Nz::Vector3f(-4.f, 8.f, -4.f));
}
}
WHEN("We ask for distance")
{
NzVector3f tmp(-1.f, -5.f, -8.f);
Nz::Vector3f tmp(-1.f, -5.f, -8.f);
THEN("These are expected")
{

View File

@@ -7,8 +7,8 @@ SCENARIO("Vector4", "[MATH][VECTOR4]")
{
GIVEN("Two same unit vector")
{
NzVector4f firstUnit(1.f, 1.f, 1.f);
NzVector4f secondUnit(NzVector4i(1, 1, 1, 1));
Nz::Vector4f firstUnit(1.f, 1.f, 1.f);
Nz::Vector4f secondUnit(Nz::Vector4i(1, 1, 1, 1));
WHEN("We compare them")
{
@@ -20,7 +20,7 @@ SCENARIO("Vector4", "[MATH][VECTOR4]")
WHEN("We test the dot product")
{
NzVector4f tmp(-1.f, 0.f, 1.f, 0.f);
Nz::Vector4f tmp(-1.f, 0.f, 1.f, 0.f);
THEN("These results are expected")
{
@@ -31,12 +31,12 @@ SCENARIO("Vector4", "[MATH][VECTOR4]")
WHEN("We normalize")
{
NzVector4f tmp(1.f, 1.f, 1.f, 3.f);
Nz::Vector4f tmp(1.f, 1.f, 1.f, 3.f);
THEN("These results are expected")
{
REQUIRE(firstUnit.Normalize() == NzVector4f(1.f, NzVector3f::Unit()));
REQUIRE(tmp.Normalize() == NzVector4f(NzVector3f::Unit() * (1.f / 3.f), 1.f));
REQUIRE(firstUnit.Normalize() == Nz::Vector4f(1.f, Nz::Vector3f::Unit()));
REQUIRE(tmp.Normalize() == Nz::Vector4f(Nz::Vector3f::Unit() * (1.f / 3.f), 1.f));
}
}
}