From e2808192aaf57bb8ddc4b8317fe185114d413b5a Mon Sep 17 00:00:00 2001 From: SirLynix Date: Sun, 30 Jul 2023 19:46:01 +0200 Subject: [PATCH] Minor fixes --- .github/workflows/msys2-build.yml | 1 + examples/DeferredShading/main.cpp | 3 --- include/Nazara/Core/Modules.inl | 8 ++++---- include/Nazara/Math/Sphere.hpp | 6 +++--- include/Nazara/Math/Sphere.inl | 12 ++++++------ tests/ComputeParticlesTest/main.cpp | 4 ---- tests/UnitTests/Engine/Math/Matrix4Test.cpp | 2 +- tests/UnitTests/Engine/Math/PlaneTest.cpp | 4 ++-- tests/UnitTests/Engine/Math/QuaternionTest.cpp | 4 ++-- tests/UnitTests/Engine/Math/RayTest.cpp | 2 +- tests/UnitTests/Engine/Math/Vector2Test.cpp | 2 +- tests/UnitTests/Engine/Math/Vector3Test.cpp | 2 +- 12 files changed, 22 insertions(+), 28 deletions(-) diff --git a/.github/workflows/msys2-build.yml b/.github/workflows/msys2-build.yml index ac64d38e1..795881001 100644 --- a/.github/workflows/msys2-build.yml +++ b/.github/workflows/msys2-build.yml @@ -102,6 +102,7 @@ jobs: # Run unit tests - name: Run unit tests + if: matrix.mode != 'releasedbg run: xmake run UnitTests # Setup installation configuration diff --git a/examples/DeferredShading/main.cpp b/examples/DeferredShading/main.cpp index dd1b665c7..b29f3fb46 100644 --- a/examples/DeferredShading/main.cpp +++ b/examples/DeferredShading/main.cpp @@ -234,9 +234,6 @@ int main(int argc, char* argv[]) for (std::size_t i = 0; i < planeModel.GetSubMeshCount(); ++i) planeModel.SetMaterial(i, planeMat); - Nz::PredefinedInstanceData instanceUboOffsets = Nz::PredefinedInstanceData::GetOffsets(); - Nz::PredefinedViewerData viewerUboOffsets = Nz::PredefinedViewerData::GetOffsets(); - Nz::Vector2ui windowSize = window.GetSize(); Nz::ViewerInstance viewerInstance; diff --git a/include/Nazara/Core/Modules.inl b/include/Nazara/Core/Modules.inl index b87ad6a62..6d039f392 100644 --- a/include/Nazara/Core/Modules.inl +++ b/include/Nazara/Core/Modules.inl @@ -16,7 +16,7 @@ namespace Nz struct ModuleConfigHasOverride().Override(std::declval()))>> : std::true_type {}; template - auto OverrideModuleConfig(T&& module, const CommandLineParameters& params) + decltype(auto) OverrideModuleConfig(T&& module, const CommandLineParameters& params) { if constexpr (!std::is_const_v && ModuleConfigHasOverride::value) module.Override(params); @@ -28,7 +28,7 @@ namespace Nz struct Pick { template - static auto Get(First&& first, Args&&... args) + static decltype(auto) Get(First&& first, Args&&... args) { if constexpr (std::is_same_v>) return std::forward(first); @@ -40,7 +40,7 @@ namespace Nz } template - static auto Get(const CommandLineParameters& parameters, First&& first, Args&&... args) + static decltype(auto) Get(const CommandLineParameters& parameters, First&& first, Args&&... args) { if constexpr (std::is_same_v>) return OverrideModuleConfig(first, parameters); @@ -51,7 +51,7 @@ namespace Nz } } - static auto Get() + static T Get() { return T{}; } diff --git a/include/Nazara/Math/Sphere.hpp b/include/Nazara/Math/Sphere.hpp index 7872ec0a2..62ebdde3f 100644 --- a/include/Nazara/Math/Sphere.hpp +++ b/include/Nazara/Math/Sphere.hpp @@ -31,9 +31,9 @@ namespace Nz constexpr bool ApproxEqual(const Sphere& sphere, T maxDifference = std::numeric_limits::epsilon()) const; - constexpr bool Contains(T X, T Y, T Z) const; - constexpr bool Contains(const Box& box) const; - constexpr bool Contains(const Vector3& point) const; + constexpr bool Contains(T X, T Y, T Z, T epsilon = std::numeric_limits::epsilon()) const; + constexpr bool Contains(const Box& box, T epsilon = std::numeric_limits::epsilon()) const; + constexpr bool Contains(const Vector3& point, T epsilon = std::numeric_limits::epsilon()) const; T Distance(T X, T Y, T Z) const; T Distance(const Vector3& point) const; diff --git a/include/Nazara/Math/Sphere.inl b/include/Nazara/Math/Sphere.inl index 8108f76fb..f77956b30 100644 --- a/include/Nazara/Math/Sphere.inl +++ b/include/Nazara/Math/Sphere.inl @@ -95,9 +95,9 @@ namespace Nz * \see Contains */ template - constexpr bool Sphere::Contains(T X, T Y, T Z) const + constexpr bool Sphere::Contains(T X, T Y, T Z, T epsilon) const { - return Contains(Vector3(X, Y, Z)); + return Contains(Vector3(X, Y, Z), epsilon); } /*! @@ -109,9 +109,9 @@ namespace Nz * \see Contains */ template - constexpr bool Sphere::Contains(const Box& box) const + constexpr bool Sphere::Contains(const Box& box, T epsilon) const { - if (Contains(box.GetMinimum()) && Contains(box.GetMaximum())) + if (Contains(box.GetMinimum(), epsilon) && Contains(box.GetMaximum(), epsilon)) return true; return false; @@ -124,9 +124,9 @@ namespace Nz * \param point Position of the point */ template - constexpr bool Sphere::Contains(const Vector3& point) const + constexpr bool Sphere::Contains(const Vector3& point, T epsilon) const { - return GetPosition().SquaredDistance(point) <= radius * radius; + return (GetPosition().SquaredDistance(point) - radius * radius) <= epsilon; } /*! diff --git a/tests/ComputeParticlesTest/main.cpp b/tests/ComputeParticlesTest/main.cpp index 1808fdc3a..f1b9f4e87 100644 --- a/tests/ComputeParticlesTest/main.cpp +++ b/tests/ComputeParticlesTest/main.cpp @@ -258,11 +258,7 @@ int main() Nz::SparsePtr particleVelPtr(particleBasePtr + particleVelOffset, particleSize); for (std::size_t i = 0; i < particleCount; ++i) - { - auto&& [pos, color] = logoParticles[i]; - particleVelPtr[i] = Nz::Vector2f(velDis(rand), velDis(rand)); - } particleBuffer->Unmap(); }); diff --git a/tests/UnitTests/Engine/Math/Matrix4Test.cpp b/tests/UnitTests/Engine/Math/Matrix4Test.cpp index 24948200f..58c05a6ed 100644 --- a/tests/UnitTests/Engine/Math/Matrix4Test.cpp +++ b/tests/UnitTests/Engine/Math/Matrix4Test.cpp @@ -208,7 +208,7 @@ SCENARIO("Matrix4", "[MATH][MATRIX4]") THEN("We should retrieve it") { - CHECK(identity.GetScale() == scale); + CHECK(identity.GetScale().ApproxEqual(scale)); CHECK(identity.GetSquaredScale() == squaredScale); } diff --git a/tests/UnitTests/Engine/Math/PlaneTest.cpp b/tests/UnitTests/Engine/Math/PlaneTest.cpp index 3bcd50fdb..f1c54de62 100644 --- a/tests/UnitTests/Engine/Math/PlaneTest.cpp +++ b/tests/UnitTests/Engine/Math/PlaneTest.cpp @@ -68,7 +68,7 @@ SCENARIO("Plane", "[MATH][PLANE]") THEN("It must be equal to XZ distance 1") { - REQUIRE(xy == Nz::Planef(Nz::Vector3f::UnitY(), -1.f)); + REQUIRE(xy.ApproxEqual(Nz::Planef(Nz::Vector3f::UnitY(), -1.f))); } } @@ -77,7 +77,7 @@ SCENARIO("Plane", "[MATH][PLANE]") 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 == Nz::Planef(-Nz::Vector3f::UnitY(), 1.f)); + REQUIRE(xy.ApproxEqual(Nz::Planef(-Nz::Vector3f::UnitY(), 1.f))); } } } diff --git a/tests/UnitTests/Engine/Math/QuaternionTest.cpp b/tests/UnitTests/Engine/Math/QuaternionTest.cpp index 766ec674a..15bac2e75 100644 --- a/tests/UnitTests/Engine/Math/QuaternionTest.cpp +++ b/tests/UnitTests/Engine/Math/QuaternionTest.cpp @@ -14,7 +14,7 @@ SCENARIO("Quaternion", "[MATH][QUATERNION]") THEN("They are the same and the proprieties of quaternions are respected") { REQUIRE(firstQuaternion.ApproxEqual(secondQuaternion)); - REQUIRE(firstQuaternion.ComputeW() == secondQuaternion.Normalize()); + REQUIRE(firstQuaternion.ComputeW().ApproxEqual(secondQuaternion.Normalize())); REQUIRE(firstQuaternion.Conjugate() == secondQuaternion.Inverse()); REQUIRE(firstQuaternion.DotProduct(secondQuaternion) == Catch::Approx(1.f)); } @@ -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).ApproxEqual(extremity)); + REQUIRE((rotation * origin).ApproxEqual(extremity, 0.0001f)); } } } diff --git a/tests/UnitTests/Engine/Math/RayTest.cpp b/tests/UnitTests/Engine/Math/RayTest.cpp index 6f8a2ae08..5d9fc84ec 100644 --- a/tests/UnitTests/Engine/Math/RayTest.cpp +++ b/tests/UnitTests/Engine/Math/RayTest.cpp @@ -75,7 +75,7 @@ SCENARIO("Ray", "[MATH][RAY]") Nz::BoundingVolumef infiniteVolume(Nz::Extent::Infinite); CHECK(ray.Intersect(infiniteVolume, &tmpClosest, &tmpFurthest)); CHECK(tmpClosest == Catch::Approx(0.f)); - CHECK(tmpFurthest == std::numeric_limits::infinity()); + CHECK(std::isinf(tmpFurthest)); } THEN("For the triangle collision's") diff --git a/tests/UnitTests/Engine/Math/Vector2Test.cpp b/tests/UnitTests/Engine/Math/Vector2Test.cpp index ae66cc972..66da78bcc 100644 --- a/tests/UnitTests/Engine/Math/Vector2Test.cpp +++ b/tests/UnitTests/Engine/Math/Vector2Test.cpp @@ -56,7 +56,7 @@ SCENARIO("Vector2", "[MATH][VECTOR2]") THEN("For normal cases should be normal") { Nz::Vector2f normalized = firstUnit.GetNormal(&ratio); - REQUIRE(normalized == (Nz::Vector2f::Unit() / std::sqrt(2.f))); + REQUIRE(normalized.ApproxEqual(Nz::Vector2f::Unit() / std::sqrt(2.f))); REQUIRE(ratio == Catch::Approx(std::sqrt(2.f))); } diff --git a/tests/UnitTests/Engine/Math/Vector3Test.cpp b/tests/UnitTests/Engine/Math/Vector3Test.cpp index 0fb4490e5..c5c748fab 100644 --- a/tests/UnitTests/Engine/Math/Vector3Test.cpp +++ b/tests/UnitTests/Engine/Math/Vector3Test.cpp @@ -28,7 +28,7 @@ SCENARIO("Vector3", "[MATH][VECTOR3]") REQUIRE(firstUnit.AbsDotProduct(tmp) == Catch::Approx(2.f)); REQUIRE(firstUnit.DotProduct(tmp) == Catch::Approx(0.f)); REQUIRE(firstUnit.AngleBetween(tmp).ApproxEqual(Nz::DegreeAnglef(90.f))); - REQUIRE(firstUnit.AngleBetween(-firstUnit).ApproxEqual(Nz::DegreeAnglef(180.f))); + REQUIRE(firstUnit.AngleBetween(-firstUnit).ApproxEqual(Nz::DegreeAnglef(180.f), 0.001f)); } }