From 46fe1c550cdd57cb6f0bbf6065616d016d095fcd Mon Sep 17 00:00:00 2001 From: SirLynix Date: Sun, 18 Dec 2022 17:08:03 +0100 Subject: [PATCH] Fixes unit tests --- include/Nazara/Math/Ray.hpp | 1 - include/Nazara/Math/Ray.inl | 38 --------------------- src/Nazara/Utility/GuillotineImageAtlas.cpp | 2 +- tests/Engine/Math/BoxTest.cpp | 16 +++++---- tests/Engine/Math/RayTest.cpp | 17 --------- tests/Engine/Math/RectTest.cpp | 6 ++-- tests/Engine/Math/SphereTest.cpp | 2 +- tests/Engine/Physics2D/RigidBody2DTest.cpp | 2 +- 8 files changed, 15 insertions(+), 69 deletions(-) diff --git a/include/Nazara/Math/Ray.hpp b/include/Nazara/Math/Ray.hpp index 35ba5f5bf..0ce84d33f 100644 --- a/include/Nazara/Math/Ray.hpp +++ b/include/Nazara/Math/Ray.hpp @@ -41,7 +41,6 @@ namespace Nz bool Intersect(const BoundingVolume& volume, T* closestHit = nullptr, T* furthestHit = nullptr) const; bool Intersect(const Box& box, T* closestHit = nullptr, T* furthestHit = nullptr) const; bool Intersect(const Box& box, const Matrix4& transform, T* closestHit = nullptr, T* furthestHit = nullptr) const; - bool Intersect(const OrientedBox& orientedBox, T* closestHit = nullptr, T* furthestHit = nullptr) const; bool Intersect(const Plane& plane, T* hit = nullptr) const; bool Intersect(const Sphere& sphere, T* closestHit = nullptr, T* furthestHit = nullptr) const; bool Intersect(const Vector3& firstPoint, const Vector3& secondPoint, const Vector3& thirdPoint, T* hit = nullptr) const; diff --git a/include/Nazara/Math/Ray.inl b/include/Nazara/Math/Ray.inl index 93a814f97..e59c705b5 100644 --- a/include/Nazara/Math/Ray.inl +++ b/include/Nazara/Math/Ray.inl @@ -308,44 +308,6 @@ namespace Nz return true; } - /*! - * \brief Checks whether or not this ray intersects with the OrientedBox - * \return true if it intersects - * - * \param orientedBox OrientedBox to check - * \param closestHit Optional argument to get the closest parameter where the intersection is only if it happened - * \param furthestHit Optional argument to get the furthest parameter where the intersection is only if it happened - * - * \see Intersect - */ - - template - bool Ray::Intersect(const OrientedBox& orientedBox, T* closestHit, T* furthestHit) const - { - Vector3 corner = orientedBox.GetCorner(BoxCorner::FarLeftBottom); - Vector3 oppositeCorner = orientedBox.GetCorner(BoxCorner::NearRightTop); - - Vector3 width = (orientedBox.GetCorner(BoxCorner::NearLeftBottom) - corner); - Vector3 height = (orientedBox.GetCorner(BoxCorner::FarLeftTop) - corner); - Vector3 depth = (orientedBox.GetCorner(BoxCorner::FarRightBottom) - corner); - - // Construction de la matrice de transformation de l'OBB - Matrix4 matrix(width.x, height.x, depth.x, corner.x, - width.y, height.y, depth.y, corner.y, - width.z, height.z, depth.z, corner.z, - T(0.0), T(0.0), T(0.0), T(1.0)); - - matrix.InverseTransform(); - - corner = matrix.Transform(corner); - oppositeCorner = matrix.Transform(oppositeCorner); - - Box tmpBox(corner, oppositeCorner); - Ray tmpRay(matrix.Transform(origin), matrix.Transform(direction)); - - return tmpRay.Intersect(tmpBox, closestHit, furthestHit); - } - /*! * \brief Checks whether or not this ray intersects with the plane * \return true if it intersects diff --git a/src/Nazara/Utility/GuillotineImageAtlas.cpp b/src/Nazara/Utility/GuillotineImageAtlas.cpp index bec43d6fb..90d1f40e9 100644 --- a/src/Nazara/Utility/GuillotineImageAtlas.cpp +++ b/src/Nazara/Utility/GuillotineImageAtlas.cpp @@ -175,7 +175,7 @@ namespace Nz { std::shared_ptr newImage = std::make_shared(ImageType::E2D, PixelFormat::A8, size.x, size.y); if (oldImage) - newImage->Copy(static_cast(*oldImage), Rectui(Vector2ui::Zero(), Vector2ui(oldImage->GetSize())), Vector2ui(0, 0)); // Copie des anciennes données + newImage->Copy(static_cast(*oldImage), Boxui(Vector3ui::Zero(), oldImage->GetSize()), Vector2ui(0, 0)); // Copie des anciennes données return newImage; } diff --git a/tests/Engine/Math/BoxTest.cpp b/tests/Engine/Math/BoxTest.cpp index 0cea64c66..c11b6ea7b 100644 --- a/tests/Engine/Math/BoxTest.cpp +++ b/tests/Engine/Math/BoxTest.cpp @@ -17,15 +17,17 @@ SCENARIO("Box", "[MATH][BOX]") THEN("They should stay the same") { REQUIRE(firstZero == secondZero); - CHECK(!firstZero.IsValid()); - CHECK(!secondZero.IsValid()); + CHECK(firstZero.IsValid()); + CHECK(firstZero.IsNull()); + CHECK(secondZero.IsValid()); + CHECK(secondZero.IsNull()); } } } GIVEN("Two unit and center boxes") { - Nz::Boxf firstCenterAndUnit(Nz::Rectf(Nz::Vector2f::Zero(), Nz::Vector2f::Unit())); + Nz::Boxf firstCenterAndUnit(Nz::Vector3f::Zero(), Nz::Vector3f::Unit()); Nz::Boxf secondCenterAndUnit(1.f, 1.f, 1.f); WHEN("We ask for some informations") @@ -91,8 +93,8 @@ SCENARIO("Box", "[MATH][BOX]") GIVEN("Two wrong box (negative width, height and depth") { - Nz::Boxf firstWrongBox = Nz::Boxf::Invalid(); - Nz::Boxf secondWrongBox = Nz::Boxf::Invalid(); + Nz::Boxf firstWrongBox(-Nz::Vector3f::Unit()); + Nz::Boxf secondWrongBox(-Nz::Vector3f::Unit()); WHEN("We check if valid") { @@ -121,8 +123,8 @@ 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(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 = Nz::Boxf::Lerp(Nz::Boxf::Zero(), secondWrongBox, 0.f); // Zeroed + secondWrongBox.ExtendTo(Nz::Boxf::FromExtends(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)); diff --git a/tests/Engine/Math/RayTest.cpp b/tests/Engine/Math/RayTest.cpp index 2783a1f6b..1ea9cdf45 100644 --- a/tests/Engine/Math/RayTest.cpp +++ b/tests/Engine/Math/RayTest.cpp @@ -65,23 +65,6 @@ SCENARIO("Ray", "[MATH][RAY]") CHECK(!ray.Intersect(Nz::Spheref(Nz::Vector3f::UnitX(), 0.9f))); } - THEN("For the OBB collision's") - { - float tmpClosest; - float tmpFurthest; - - 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(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)); - } - THEN("For the bounding volume collision's") { Nz::BoundingVolumef nullVolume(Nz::Extend::Null); diff --git a/tests/Engine/Math/RectTest.cpp b/tests/Engine/Math/RectTest.cpp index 2fad69e6b..3e28ed6f7 100644 --- a/tests/Engine/Math/RectTest.cpp +++ b/tests/Engine/Math/RectTest.cpp @@ -7,7 +7,7 @@ SCENARIO("Rect", "[MATH][RECT]") GIVEN("Two same Nz::Rectangles center and unit lengths") { Nz::Rectf firstCenterAndUnit(0.f, 0.f, 1.f, 1.f); - Nz::Rectf secondCenterAndUnit(Nz::Recti(Nz::Vector2i::Unit(), Nz::Vector2i::Zero())); + Nz::Rectf secondCenterAndUnit(Nz::Recti::FromExtends(Nz::Vector2i::Unit(), Nz::Vector2i::Zero())); WHEN("We ask if they are the same") { @@ -32,11 +32,11 @@ SCENARIO("Rect", "[MATH][RECT]") } } - WHEN("We make an empty") + WHEN("We make it empty") { THEN("It's not valid") { - CHECK(!(firstCenterAndUnit.Scale(0.f)).IsValid()); + CHECK(firstCenterAndUnit.Scale(0.f).IsNull()); } } diff --git a/tests/Engine/Math/SphereTest.cpp b/tests/Engine/Math/SphereTest.cpp index 48b1ed4bb..260176e4d 100644 --- a/tests/Engine/Math/SphereTest.cpp +++ b/tests/Engine/Math/SphereTest.cpp @@ -51,7 +51,7 @@ SCENARIO("Sphere", "[MATH][SPHERE]") WHEN("We get sphere from box unit and center") { - Nz::Boxf centerUnitBox(Nz::Vector3f::Unit() * -0.5f, Nz::Vector3f::Unit() * 0.5f); + Nz::Boxf centerUnitBox = Nz::Boxf::FromExtends(Nz::Vector3f::Unit() * -0.5f, Nz::Vector3f::Unit() * 0.5f); THEN("This is equal to sphere center and radius 0.75") { diff --git a/tests/Engine/Physics2D/RigidBody2DTest.cpp b/tests/Engine/Physics2D/RigidBody2DTest.cpp index fa8a25ad6..16f68c946 100644 --- a/tests/Engine/Physics2D/RigidBody2DTest.cpp +++ b/tests/Engine/Physics2D/RigidBody2DTest.cpp @@ -310,7 +310,7 @@ SCENARIO("RigidBody2D", "[PHYSICS2D][RIGIDBODY2D]") { THEN("We expect this to be true") { - Nz::Rectf segmentAABB(positionA, positionB); + Nz::Rectf segmentAABB = Nz::Rectf::FromExtends(positionA, positionB); REQUIRE(body.GetAABB() == segmentAABB); } }