From 5ca7b398c213ff626ed04d809388a137f677d106 Mon Sep 17 00:00:00 2001 From: SirLynix Date: Sun, 18 Dec 2022 16:33:05 +0100 Subject: [PATCH] More Math cleanup --- include/Nazara/Math/BoundingVolume.hpp | 13 -- include/Nazara/Math/BoundingVolume.inl | 241 +++-------------------- include/Nazara/Math/Box.hpp | 6 +- include/Nazara/Math/Box.inl | 13 ++ include/Nazara/Math/OrientedBox.hpp | 20 +- include/Nazara/Math/OrientedBox.inl | 169 +--------------- include/Nazara/Math/Rect.hpp | 8 +- include/Nazara/Math/Rect.inl | 12 ++ tests/Engine/Core/SerializationTest.cpp | 2 +- tests/Engine/Math/BoundingVolumeTest.cpp | 34 +--- tests/Engine/Math/BoxTest.cpp | 10 +- tests/Engine/Math/FrustumTest.cpp | 16 +- tests/Engine/Math/OrientedBoxTest.cpp | 8 +- tests/Engine/Math/RayTest.cpp | 4 +- tests/Engine/Math/RectTest.cpp | 2 +- 15 files changed, 104 insertions(+), 454 deletions(-) diff --git a/include/Nazara/Math/BoundingVolume.hpp b/include/Nazara/Math/BoundingVolume.hpp index 6271f36a2..2c67d184e 100644 --- a/include/Nazara/Math/BoundingVolume.hpp +++ b/include/Nazara/Math/BoundingVolume.hpp @@ -24,10 +24,8 @@ namespace Nz public: BoundingVolume(); BoundingVolume(Extend Extend); - BoundingVolume(T X, T Y, T Z, T Width, T Height, T Depth); BoundingVolume(const Box& box); BoundingVolume(const OrientedBox& orientedBox); - BoundingVolume(const Vector3& vec1, const Vector3& vec2); template explicit BoundingVolume(const BoundingVolume& volume); BoundingVolume(const BoundingVolume& volume) = default; ~BoundingVolume() = default; @@ -40,17 +38,6 @@ namespace Nz bool IsInfinite() const; bool IsNull() const; - BoundingVolume& MakeInfinite(); - BoundingVolume& MakeNull(); - - BoundingVolume& Set(Extend Extend); - BoundingVolume& Set(T X, T Y, T Z, T Width, T Height, T Depth); - BoundingVolume& Set(const BoundingVolume& volume); - BoundingVolume& Set(const Box& box); - BoundingVolume& Set(const OrientedBox& orientedBox); - BoundingVolume& Set(const Vector3& vec1, const Vector3& vec2); - template BoundingVolume& Set(const BoundingVolume& volume); - std::string ToString() const; void Update(const Matrix4& transformMatrix); diff --git a/include/Nazara/Math/BoundingVolume.inl b/include/Nazara/Math/BoundingVolume.inl index a87b366de..f5eed7091 100644 --- a/include/Nazara/Math/BoundingVolume.inl +++ b/include/Nazara/Math/BoundingVolume.inl @@ -42,28 +42,9 @@ namespace Nz */ template - BoundingVolume::BoundingVolume(Extend Extend) + BoundingVolume::BoundingVolume(Extend Extend) : + extend(Extend) { - Set(Extend); - } - - /*! - * \brief Constructs a BoundingVolume object from its position and sizes - * - * \param X X component of position - * \param Y Y component of position - * \param Z Z component of position - * \param Width Width of the box (following X) - * \param Height Height of the box (following Y) - * \param Depth Depth of the box (following Z) - * - * \remark Aabb is uninitialized - */ - - template - BoundingVolume::BoundingVolume(T X, T Y, T Z, T Width, T Height, T Depth) - { - Set(X, Y, Z, Width, Height, Depth); } /*! @@ -75,9 +56,10 @@ namespace Nz */ template - BoundingVolume::BoundingVolume(const Box& box) + BoundingVolume::BoundingVolume(const Box& box) : + extend(Extend::Finite), + obb(box) { - Set(box); } /*! @@ -89,25 +71,10 @@ namespace Nz */ template - BoundingVolume::BoundingVolume(const OrientedBox& orientedBox) + BoundingVolume::BoundingVolume(const OrientedBox& orientedBox) : + extend(Extend::Finite), + obb(orientedBox) { - Set(orientedBox); - } - - /*! - * \brief Constructs a BoundingVolume object from two vectors representing point of the space - * (X, Y, Z) will be the components minimum of the two vectors and the (width, height, depth) will be the components maximum - minimum - * - * \param vec1 First point - * \param vec2 Second point - * - * \remark Aabb is uninitialized - */ - - template - BoundingVolume::BoundingVolume(const Vector3& vec1, const Vector3& vec2) - { - Set(vec1, vec2); } /*! @@ -118,12 +85,13 @@ namespace Nz template template - BoundingVolume::BoundingVolume(const BoundingVolume& volume) + BoundingVolume::BoundingVolume(const BoundingVolume& volume) : + extend(volume.extend), + aabb(volume.aabb), + obb(volume.obb) { - Set(volume); } - /*! * \brief Extends the bounding volume to contain another bounding volume * \return A reference to the the bounding volume @@ -149,7 +117,7 @@ namespace Nz } case Extend::Infinite: - MakeInfinite(); + extend = Extend::Infinite; break; case Extend::Null: @@ -219,156 +187,6 @@ namespace Nz return extend == Extend::Null; } - /*! - * \brief Makes the bounding volume infinite - * \return A reference to this bounding volume with Extend::Infinite for extend - * - * \see Infinite - */ - - template - BoundingVolume& BoundingVolume::MakeInfinite() - { - extend = Extend::Infinite; - - return *this; - } - - /*! - * \brief Makes the bounding volume null - * \return A reference to this bounding volume with Extend::Null for extend - * - * \see Null - */ - - template - BoundingVolume& BoundingVolume::MakeNull() - { - extend = Extend::Null; - - return *this; - } - - /*! - * \brief Sets the extend of the bounding volume from Extend - * \return A reference to this bounding volume - * - * \param Extend New extend - * - * \remark This method is meant to be called with Extend::Infinite or Extend::Null - */ - - template - BoundingVolume& BoundingVolume::Set(Extend Extend) - { - extend = Extend; - - return *this; - } - - /*! - * \brief Sets the components of the bounding volume - * \return A reference to this bounding volume - * - * \param X X position - * \param Y Y position - * \param Z Z position - * \param Width Width of the oriented box (following X) - * \param Height Height of the oriented box (following Y) - * \param Depth Depth of the oriented box (following Z) - */ - - template - BoundingVolume& BoundingVolume::Set(T X, T Y, T Z, T Width, T Height, T Depth) - { - obb.Set(X, Y, Z, Width, Height, Depth); - extend = Extend::Finite; - - return *this; - } - - /*! - * \brief Sets the components of the bounding volume from another bounding volume - * \return A reference to this bounding volume - * - * \param volume The other bounding volume - */ - - template - BoundingVolume& BoundingVolume::Set(const BoundingVolume& volume) - { - obb.Set(volume.obb); // Only OBB is important for the moment - extend = volume.extend; - - return *this; - } - - /*! - * \brief Sets the components of the bounding volume from a box - * \return A reference to this bounding volume - * - * \param box Box object - */ - - template - BoundingVolume& BoundingVolume::Set(const Box& box) - { - obb.Set(box); - extend = Extend::Finite; - - return *this; - } - - /*! - * \brief Sets the components of the bounding volume from an oriented box - * \return A reference to this bounding volume - * - * \param orientedBox OrientedBox object - */ - - template - BoundingVolume& BoundingVolume::Set(const OrientedBox& orientedBox) - { - obb.Set(orientedBox); - extend = Extend::Finite; - - return *this; - } - - /*! - * \brief Sets a BoundingVolume object from two vectors representing point of the space - * (X, Y, Z) will be the components minimum of the two vectors and the (width, height, depth) will be the components maximum - minimum - * - * \param vec1 First point - * \param vec2 Second point - */ - - template - BoundingVolume& BoundingVolume::Set(const Vector3& vec1, const Vector3& vec2) - { - obb.Set(vec1, vec2); - extend = Extend::Finite; - - return *this; - } - - /*! - * \brief Sets the components of the bounding volume from another type of BoundingVolume - * \return A reference to this bounding volume - * - * \param volume BoundingVolume of type U to convert its components - */ - - template - template - BoundingVolume& BoundingVolume::Set(const BoundingVolume& volume) - { - obb.Set(volume.obb); - extend = volume.extend; - - return *this; - } - /*! * \brief Gives a string representation * \return A string representation of the object: "BoundingVolume(localBox="")" if finite, or "BoundingVolume(Infinite)" or "BoundingVolume(Null)" @@ -491,7 +309,7 @@ namespace Nz BoundingVolume BoundingVolume::Infinite() { BoundingVolume volume; - volume.MakeInfinite(); + volume.extend = Extend::Infinite; return volume; } @@ -514,14 +332,6 @@ namespace Nz template BoundingVolume BoundingVolume::Lerp(const BoundingVolume& from, const BoundingVolume& to, T interpolation) { - #ifdef NAZARA_DEBUG - if (interpolation < T(0.0) || interpolation > T(1.0)) - { - NazaraError("Interpolation must be in range [0..1] (Got " + NumberToString(interpolation) + ')'); - return Null(); - } - #endif - if (NumberEquals(interpolation, T(0.0))) return from; @@ -535,18 +345,18 @@ namespace Nz switch (from.extend) { case Extend::Finite: - { - BoundingVolume volume; - volume.Set(OrientedBox::Lerp(from.obb, to.obb, interpolation)); - - return volume; - } + return BoundingVolume{ OrientedBox::Lerp(from.obb, to.obb, interpolation) }; case Extend::Infinite: return Infinite(); case Extend::Null: - return to.obb * interpolation; + { + Box destBox = to.obb.localBox; + destBox.Scale(interpolation); + + return { destBox }; + } } // If we arrive here, the extend is invalid @@ -562,7 +372,12 @@ namespace Nz switch (from.extend) { case Extend::Finite: - return from.obb * (T(1.0) - interpolation); + { + Box fromBox = from.obb.localBox; + fromBox.Scale(T(1.0) - interpolation); + + return { fromBox }; + } case Extend::Infinite: return Infinite(); @@ -593,7 +408,7 @@ namespace Nz BoundingVolume BoundingVolume::Null() { BoundingVolume volume; - volume.MakeNull(); + volume.extend = Extend::Null; return volume; } diff --git a/include/Nazara/Math/Box.hpp b/include/Nazara/Math/Box.hpp index b70ded60d..73e3dd781 100644 --- a/include/Nazara/Math/Box.hpp +++ b/include/Nazara/Math/Box.hpp @@ -26,9 +26,11 @@ namespace Nz Box(T Width, T Height, T Depth); Box(T X, T Y, T Z, T Width, T Height, T Depth); Box(const Rect& rect); + explicit Box(const Vector3& lengths); explicit Box(const Vector3& pos, const Vector3& lengths); template explicit Box(const Box& box); - Box(const Box& box) = default; + Box(const Box&) = default; + Box(Box&&) noexcept = default; ~Box() = default; bool Contains(T X, T Y, T Z) const; @@ -69,7 +71,7 @@ namespace Nz const T& operator[](std::size_t i) const; Box& operator=(const Box&) = default; - Box& operator=(Box&&) = default; + Box& operator=(Box&&) noexcept = default; bool operator==(const Box& box) const; bool operator!=(const Box& box) const; diff --git a/include/Nazara/Math/Box.inl b/include/Nazara/Math/Box.inl index a47b858a9..434b57c38 100644 --- a/include/Nazara/Math/Box.inl +++ b/include/Nazara/Math/Box.inl @@ -78,6 +78,19 @@ namespace Nz { } + /*! + * \brief Constructs a Rect object from a vector representing its length + * The position will be set to zero + * + * \param pos (X, Y, Z) of the box + * \param lengths (Width, Height, Depth) of the box + */ + template + Box::Box(const Vector3& lengths) : + Box(Vector3::Zero(), lengths) + { + } + /*! * \brief Constructs a Box object from two vector representing position and lengths * diff --git a/include/Nazara/Math/OrientedBox.hpp b/include/Nazara/Math/OrientedBox.hpp index 71bcb0ef2..e75eb8bc2 100644 --- a/include/Nazara/Math/OrientedBox.hpp +++ b/include/Nazara/Math/OrientedBox.hpp @@ -22,11 +22,10 @@ namespace Nz { public: OrientedBox() = default; - OrientedBox(T X, T Y, T Z, T Width, T Height, T Depth); OrientedBox(const Box& box); - OrientedBox(const Vector3& vec1, const Vector3& vec2); template explicit OrientedBox(const OrientedBox& orientedBox); - OrientedBox(const OrientedBox& orientedBox) = default; + OrientedBox(const OrientedBox&) = default; + OrientedBox(OrientedBox&&) noexcept = default; ~OrientedBox() = default; const Vector3& GetCorner(BoxCorner corner) const; @@ -34,25 +33,16 @@ namespace Nz bool IsValid() const; - OrientedBox& MakeZero(); - - OrientedBox& Set(T X, T Y, T Z, T Width, T Height, T Depth); - OrientedBox& Set(const Box& box); - OrientedBox& Set(const Vector3& vec1, const Vector3& vec2); - template OrientedBox& Set(const OrientedBox& orientedBox); - std::string ToString() const; void Update(const Matrix4& transformMatrix); void Update(const Vector3& transformMatrix); Vector3& operator()(unsigned int i); - Vector3 operator()(unsigned int i) const; + const Vector3& operator()(unsigned int i) const; - OrientedBox operator*(T scalar) const; - OrientedBox& operator=(const OrientedBox& other) = default; - - OrientedBox& operator*=(T scalar); + OrientedBox& operator=(const OrientedBox&) = default; + OrientedBox& operator=(OrientedBox&&) noexcept = default; bool operator==(const OrientedBox& box) const; bool operator!=(const OrientedBox& box) const; diff --git a/include/Nazara/Math/OrientedBox.inl b/include/Nazara/Math/OrientedBox.inl index 22dc13f70..8072b1f26 100644 --- a/include/Nazara/Math/OrientedBox.inl +++ b/include/Nazara/Math/OrientedBox.inl @@ -21,23 +21,6 @@ namespace Nz * \remark You need to call Update not to have undefined behaviour */ - /*! - * \brief Constructs a OrientedBox object from its position and sizes - * - * \param X X component of position - * \param Y Y component of position - * \param Z Z component of position - * \param Width Width of the box (following X) - * \param Height Height of the box (following Y) - * \param Depth Depth of the box (following Z) - */ - - template - OrientedBox::OrientedBox(T X, T Y, T Z, T Width, T Height, T Depth) - { - Set(X, Y, Z, Width, Height, Depth); - } - /*! * \brief Constructs a OrientedBox object from a box * @@ -45,23 +28,9 @@ namespace Nz */ template - OrientedBox::OrientedBox(const Box& box) + OrientedBox::OrientedBox(const Box& box) : + localBox(box) { - Set(box); - } - - /*! - * \brief Constructs a OrientedBox object from two vectors representing point of the space - * (X, Y, Z) will be the components minimum of the two vectors and the (width, height, depth) will be the components maximum - minimum - * - * \param vec1 First point - * \param vec2 Second point - */ - - template - OrientedBox::OrientedBox(const Vector3& vec1, const Vector3& vec2) - { - Set(vec1, vec2); } /*! @@ -72,9 +41,11 @@ namespace Nz template template - OrientedBox::OrientedBox(const OrientedBox& orientedBox) + OrientedBox::OrientedBox(const OrientedBox& orientedBox) : + localBox(orientedBox.localBox) { - Set(orientedBox); + for (unsigned int i = 0; i < BoxCornerCount; ++i) + m_corners[i] = Vector3(orientedBox(i)); } /*! @@ -119,91 +90,6 @@ namespace Nz return localBox.IsValid(); } - /*! - * \brief Makes the oriented box position (0, 0, 0) and lengths (0, 0, 0) - * \return A reference to this oriented box with position (0, 0, 0) and lengths (0, 0, 0) - * - * \see Zero - */ - - template - OrientedBox& OrientedBox::MakeZero() - { - localBox.MakeZero(); - - return *this; - } - - /*! - * \brief Sets the components of the oriented box - * \return A reference to this oriented box - * - * \param X X position - * \param Y Y position - * \param Z Z position - * \param Width Width of the oriented box (following X) - * \param Height Height of the oriented box (following Y) - * \param Depth Depth of the oriented box (following Z) - */ - - template - OrientedBox& OrientedBox::Set(T X, T Y, T Z, T Width, T Height, T Depth) - { - localBox.Set(X, Y, Z, Width, Height, Depth); - - return *this; - } - - /*! - * \brief Sets the components of the oriented box from a box - * \return A reference to this oriented box - * - * \param box Box object - */ - - template - OrientedBox& OrientedBox::Set(const Box& box) - { - localBox = box; - - return *this; - } - - /*! - * \brief Sets a OrientedBox object from two vectors representing point of the space - * (X, Y, Z) will be the components minimum of the two vectors and the (width, height, depth) will be the components maximum - minimum - * - * \param vec1 First point - * \param vec2 Second point - */ - - template - OrientedBox& OrientedBox::Set(const Vector3& vec1, const Vector3& vec2) - { - localBox.Set(vec1, vec2); - - return *this; - } - - /*! - * \brief Sets the components of the orientedBox from another type of OrientedBox - * \return A reference to this orientedBox - * - * \param orientedBox OrientedBox of type U to convert its components - */ - - template - template - OrientedBox& OrientedBox::Set(const OrientedBox& orientedBox) - { - for (unsigned int i = 0; i < BoxCornerCount; ++i) - m_corners[i].Set(orientedBox(i)); - - localBox.Set(orientedBox.localBox); - - return *this; - } - /*! * \brief Gives a string representation * \return A string representation of the object: "OrientedBox(...)" @@ -278,7 +164,7 @@ namespace Nz */ template - Vector3 OrientedBox::operator()(unsigned int i) const + const Vector3& OrientedBox::operator()(unsigned int i) const { #if NAZARA_MATH_SAFE if (i >= BoxCornerCount) @@ -294,37 +180,6 @@ namespace Nz return m_corners[i]; } - /*! - * \brief Multiplies the lengths with the scalar - * \return A OrientedBox where the position is the same and width, height and depth are the product of the old width, height and depth and the scalar - * - * \param scalar The scalar to multiply width, height and depth with - */ - - template - OrientedBox OrientedBox::operator*(T scalar) const - { - OrientedBox box(*this); - box *= scalar; - - return box; - } - - /*! - * \brief Multiplies the lengths of this oriented box with the scalar - * \return A reference to this oriented box where lengths are the product of these lengths and the scalar - * - * \param scalar The scalar to multiply width, height and depth with - */ - - template - OrientedBox& OrientedBox::operator*=(T scalar) - { - localBox *= scalar; - - return *this; - } - /*! * \brief Compares the oriented box to other one * \return true if the two oriented boxes are the same @@ -368,10 +223,7 @@ namespace Nz template OrientedBox OrientedBox::Lerp(const OrientedBox& from, const OrientedBox& to, T interpolation) { - OrientedBox orientedBox; - orientedBox.Set(Box::Lerp(from.localBox, to.localBox, interpolation)); - - return orientedBox; + return OrientedBox{ Box::Lerp(from.localBox, to.localBox, interpolation) }; } /*! @@ -384,10 +236,7 @@ namespace Nz template OrientedBox OrientedBox::Zero() { - OrientedBox orientedBox; - orientedBox.MakeZero(); - - return orientedBox; + return OrientedBox{ Box::Zero() }; } /*! diff --git a/include/Nazara/Math/Rect.hpp b/include/Nazara/Math/Rect.hpp index 39b231a55..04936b1cc 100644 --- a/include/Nazara/Math/Rect.hpp +++ b/include/Nazara/Math/Rect.hpp @@ -22,9 +22,11 @@ namespace Nz Rect() = default; Rect(T Width, T Height); Rect(T X, T Y, T Width, T Height); - explicit Rect(const Vector2& vec1, const Vector2& vec2); + explicit Rect(const Vector2& lengths); + explicit Rect(const Vector2& pos, const Vector2& lengths); template explicit Rect(const Rect& rect); - Rect(const Rect& rect) = default; + Rect(const Rect&) = default; + Rect(Rect&&) noexcept = default; ~Rect() = default; bool Contains(T X, T Y) const; @@ -62,7 +64,7 @@ namespace Nz const T& operator[](std::size_t i) const; Rect& operator=(const Rect&) = default; - Rect& operator=(Rect&&) = default; + Rect& operator=(Rect&&) noexcept = default; bool operator==(const Rect& rect) const; bool operator!=(const Rect& rect) const; diff --git a/include/Nazara/Math/Rect.inl b/include/Nazara/Math/Rect.inl index b9b79323a..275b68b06 100644 --- a/include/Nazara/Math/Rect.inl +++ b/include/Nazara/Math/Rect.inl @@ -55,6 +55,18 @@ namespace Nz { } + /*! + * \brief Constructs a Rect object from a vector representing its length + * The position will be set to zero + * + * \param lengths (Width, Height) of the rect + */ + template + Rect::Rect(const Vector2& lengths) : + Rect(Vector2::Zero(), lengths) + { + } + /*! * \brief Constructs a Rect object from two vector representing position and lengths * diff --git a/tests/Engine/Core/SerializationTest.cpp b/tests/Engine/Core/SerializationTest.cpp index 95548dbac..90f163b8f 100644 --- a/tests/Engine/Core/SerializationTest.cpp +++ b/tests/Engine/Core/SerializationTest.cpp @@ -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)); diff --git a/tests/Engine/Math/BoundingVolumeTest.cpp b/tests/Engine/Math/BoundingVolumeTest.cpp index 8d4b9c2ac..0dcb94c66 100644 --- a/tests/Engine/Math/BoundingVolumeTest.cpp +++ b/tests/Engine/Math/BoundingVolumeTest.cpp @@ -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); diff --git a/tests/Engine/Math/BoxTest.cpp b/tests/Engine/Math/BoxTest.cpp index db2f3f777..0cea64c66 100644 --- a/tests/Engine/Math/BoxTest.cpp +++ b/tests/Engine/Math/BoxTest.cpp @@ -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") { diff --git a/tests/Engine/Math/FrustumTest.cpp b/tests/Engine/Math/FrustumTest.cpp index d8a813161..0a066bbd0 100644 --- a/tests/Engine/Math/FrustumTest.cpp +++ b/tests/Engine/Math/FrustumTest.cpp @@ -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))); diff --git a/tests/Engine/Math/OrientedBoxTest.cpp b/tests/Engine/Math/OrientedBoxTest.cpp index 01a31b8d9..be4536888 100644 --- a/tests/Engine/Math/OrientedBoxTest.cpp +++ b/tests/Engine/Math/OrientedBoxTest.cpp @@ -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(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(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); diff --git a/tests/Engine/Math/RayTest.cpp b/tests/Engine/Math/RayTest.cpp index 3aee70762..2783a1f6b 100644 --- a/tests/Engine/Math/RayTest.cpp +++ b/tests/Engine/Math/RayTest.cpp @@ -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)); } diff --git a/tests/Engine/Math/RectTest.cpp b/tests/Engine/Math/RectTest.cpp index cf2533f79..2fad69e6b 100644 --- a/tests/Engine/Math/RectTest.cpp +++ b/tests/Engine/Math/RectTest.cpp @@ -36,7 +36,7 @@ SCENARIO("Rect", "[MATH][RECT]") { THEN("It's not valid") { - CHECK(!(firstCenterAndUnit * 0.f).IsValid()); + CHECK(!(firstCenterAndUnit.Scale(0.f)).IsValid()); } }