From 2243d0b1a75bab468f8f0c68610f7debe9976641 Mon Sep 17 00:00:00 2001 From: SirLynix Date: Thu, 29 Dec 2022 12:15:22 +0100 Subject: [PATCH] Move free operator overloads inside Nz namespace --- include/Nazara/Core/ParameterList.hpp | 4 +- include/Nazara/Math/Angle.hpp | 36 +++++----- include/Nazara/Math/Angle.inl | 98 +++++++++++++------------- include/Nazara/Math/BoundingVolume.hpp | 5 +- include/Nazara/Math/BoundingVolume.inl | 47 ++++++------ include/Nazara/Math/Box.hpp | 8 +-- include/Nazara/Math/Box.inl | 35 +++++---- include/Nazara/Math/EulerAngles.hpp | 4 +- include/Nazara/Math/EulerAngles.inl | 25 ++++--- include/Nazara/Math/Frustum.hpp | 5 +- include/Nazara/Math/Frustum.inl | 35 +++++---- include/Nazara/Math/Matrix4.hpp | 9 ++- include/Nazara/Math/Matrix4.inl | 62 ++++++++-------- include/Nazara/Math/OrientedBox.hpp | 5 +- include/Nazara/Math/OrientedBox.inl | 40 +++++------ include/Nazara/Math/Plane.hpp | 5 +- include/Nazara/Math/Plane.inl | 25 ++++--- include/Nazara/Math/Quaternion.hpp | 4 +- include/Nazara/Math/Quaternion.inl | 25 ++++--- include/Nazara/Math/Ray.hpp | 4 +- include/Nazara/Math/Ray.inl | 24 +++---- include/Nazara/Math/Rect.hpp | 7 +- include/Nazara/Math/Rect.inl | 34 +++++---- include/Nazara/Math/Sphere.hpp | 5 +- include/Nazara/Math/Sphere.inl | 25 ++++--- include/Nazara/Math/Vector2.hpp | 10 +-- include/Nazara/Math/Vector2.inl | 77 ++++++++++---------- include/Nazara/Math/Vector3.hpp | 10 +-- include/Nazara/Math/Vector3.inl | 71 +++++++++---------- include/Nazara/Math/Vector4.hpp | 10 +-- include/Nazara/Math/Vector4.inl | 72 +++++++++---------- src/Nazara/Core/ParameterList.cpp | 25 ++++--- 32 files changed, 419 insertions(+), 432 deletions(-) diff --git a/include/Nazara/Core/ParameterList.hpp b/include/Nazara/Core/ParameterList.hpp index 591f32369..192eb769e 100644 --- a/include/Nazara/Core/ParameterList.hpp +++ b/include/Nazara/Core/ParameterList.hpp @@ -114,9 +114,9 @@ namespace Nz using ParameterMap = std::unordered_map; ParameterMap m_parameters; }; -} -std::ostream& operator<<(std::ostream& out, const Nz::ParameterList& parameterList); + std::ostream& operator<<(std::ostream& out, const ParameterList& parameterList); +} #include diff --git a/include/Nazara/Math/Angle.hpp b/include/Nazara/Math/Angle.hpp index 3c1064bbb..6a81b5d66 100644 --- a/include/Nazara/Math/Angle.hpp +++ b/include/Nazara/Math/Angle.hpp @@ -30,6 +30,8 @@ namespace Nz constexpr Angle(T angle); template constexpr explicit Angle(const Angle& Angle); template constexpr Angle(const Angle& angle); + constexpr Angle(const Angle&) = default; + constexpr Angle(Angle&&) noexcept = default; ~Angle() = default; T GetCos() const; @@ -41,7 +43,7 @@ namespace Nz constexpr Angle& Normalize(); - constexpr Angle& Set(const Angle& ang); + constexpr Angle& Set(Angle ang); template constexpr Angle& Set(const Angle& ang); template T To() const; @@ -57,22 +59,23 @@ namespace Nz constexpr Angle ToTurnAngle() const; constexpr Angle& operator=(const Angle&) = default; + constexpr Angle& operator=(Angle&&) noexcept = default; - constexpr const Angle& operator+() const; + constexpr Angle operator+() const; constexpr Angle operator-() const; - constexpr Angle operator+(const Angle& other) const; - constexpr Angle operator-(const Angle& other) const; + constexpr Angle operator+(Angle other) const; + constexpr Angle operator-(Angle other) const; constexpr Angle operator*(T scalar) const; constexpr Angle operator/(T divider) const; - constexpr Angle& operator+=(const Angle& other); - constexpr Angle& operator-=(const Angle& other); + constexpr Angle& operator+=(Angle other); + constexpr Angle& operator-=(Angle other); constexpr Angle& operator*=(T scalar); constexpr Angle& operator/=(T divider); - constexpr bool operator==(const Angle& other) const; - constexpr bool operator!=(const Angle& other) const; + constexpr bool operator==(Angle other) const; + constexpr bool operator!=(Angle other) const; template static constexpr Angle From(T value); static constexpr Angle FromDegrees(T degrees); @@ -101,19 +104,16 @@ namespace Nz using TurnAngled = TurnAngle; using TurnAnglef = TurnAngle; - template bool Serialize(SerializationContext& context, const Angle& angle, TypeTag>); + template Angle operator*(T scale, Angle angle); + + template Angle operator/(T divider, Angle angle); + + template std::ostream& operator<<(std::ostream& out, Angle angle); + + template bool Serialize(SerializationContext& context, Angle angle, TypeTag>); template bool Unserialize(SerializationContext& context, Angle* angle, TypeTag>); } -template -Nz::Angle operator*(T scale, const Nz::Angle& angle); - -template -Nz::Angle operator/(T divider, const Nz::Angle& angle); - -template -std::ostream& operator<<(std::ostream& out, const Nz::Angle& angle); - #include #endif // NAZARA_MATH_ANGLE_HPP diff --git a/include/Nazara/Math/Angle.inl b/include/Nazara/Math/Angle.inl index 2bd29c217..fbd747f8d 100644 --- a/include/Nazara/Math/Angle.inl +++ b/include/Nazara/Math/Angle.inl @@ -175,7 +175,7 @@ namespace Nz } /*! * \ingroup math - * \class Nz::Angle + * \class Angle * \brief Math class that represents an angle */ @@ -291,7 +291,7 @@ namespace Nz * \param Angle Angle which will be copied */ template - constexpr Angle& Angle::Set(const Angle& ang) + constexpr Angle& Angle::Set(Angle ang) { value = ang.value; return *this; @@ -463,7 +463,7 @@ namespace Nz * \return A constant reference to this angle */ template - constexpr const Angle& Angle::operator+() const + constexpr Angle Angle::operator+() const { return *this; } @@ -485,7 +485,7 @@ namespace Nz * \param other Angle to add */ template - constexpr Angle Angle::operator+(const Angle& other) const + constexpr Angle Angle::operator+(Angle other) const { return Angle(value + other.value); } @@ -497,7 +497,7 @@ namespace Nz * \param other Angle to subtract */ template - constexpr Angle Angle::operator-(const Angle& other) const + constexpr Angle Angle::operator-(Angle other) const { return Angle(value - other.value); } @@ -533,7 +533,7 @@ namespace Nz * \param other Angle to add */ template - constexpr Angle& Angle::operator+=(const Angle& other) + constexpr Angle& Angle::operator+=(Angle other) { value += other.value; return *this; @@ -546,7 +546,7 @@ namespace Nz * \param other Angle to subtract */ template - constexpr Angle& Angle::operator-=(const Angle& other) + constexpr Angle& Angle::operator-=(Angle other) { value -= other.value; return *this; @@ -585,7 +585,7 @@ namespace Nz * \param other The other angle to compare to */ template - constexpr bool Angle::operator==(const Angle& other) const + constexpr bool Angle::operator==(Angle other) const { return NumberEquals(value, other.value, Detail::AngleUtils::template GetEpsilon()); } @@ -597,7 +597,7 @@ namespace Nz * \param other The other angle to compare to */ template - constexpr bool Angle::operator!=(const Angle& other) const + constexpr bool Angle::operator!=(Angle other) const { return !NumberEquals(value, other.value, Detail::AngleUtils::template GetEpsilon()); } @@ -664,6 +664,45 @@ namespace Nz return angle; } + /*! + * \brief Multiplication operator + * \return An angle corresponding to scale * angle + * + * \param scale Multiplier + * \param angle Angle + */ + template + Angle operator*(T scale, Angle angle) + { + return Angle(scale * angle.value); + } + + /*! + * \brief Division operator + * \return An angle corresponding to scale / angle + * + * \param scale Divisor + * \param angle Angle + */ + template + Angle operator/(T scale, Angle angle) + { + return Angle(scale / angle.value); + } + + /*! + * \brief Output operator + * \return The stream + * + * \param out The stream + * \param box The box to output + */ + template + std::ostream& operator<<(std::ostream& out, Angle angle) + { + return Detail::AngleUtils::ToString(out, angle.value); + } + /*! * \brief Serializes an Angle * \return true if successfully serialized @@ -672,7 +711,7 @@ namespace Nz * \param angle Input Angle */ template - bool Serialize(SerializationContext& context, const Angle& angle, TypeTag>) + bool Serialize(SerializationContext& context, Angle angle, TypeTag>) { if (!Serialize(context, angle.value)) return false; @@ -697,43 +736,4 @@ namespace Nz } } -/*! -* \brief Multiplication operator -* \return An angle corresponding to scale * angle -* -* \param scale Multiplier -* \param angle Angle -*/ -template -Nz::Angle operator*(T scale, const Nz::Angle& angle) -{ - return Nz::Angle(scale * angle.value); -} - -/*! -* \brief Division operator -* \return An angle corresponding to scale / angle -* -* \param scale Divisor -* \param angle Angle -*/ -template -Nz::Angle operator/(T scale, const Nz::Angle& angle) -{ - return Nz::Angle(scale / angle.value); -} - -/*! -* \brief Output operator -* \return The stream -* -* \param out The stream -* \param box The box to output -*/ -template -std::ostream& operator<<(std::ostream& out, const Nz::Angle& angle) -{ - return Nz::Detail::AngleUtils::ToString(out, angle.value); -} - #include diff --git a/include/Nazara/Math/BoundingVolume.hpp b/include/Nazara/Math/BoundingVolume.hpp index 2c67d184e..c36280950 100644 --- a/include/Nazara/Math/BoundingVolume.hpp +++ b/include/Nazara/Math/BoundingVolume.hpp @@ -65,10 +65,9 @@ namespace Nz template bool Serialize(SerializationContext& context, const BoundingVolume& boundingVolume, TypeTag>); template bool Unserialize(SerializationContext& context, BoundingVolume* boundingVolume, TypeTag>); -} -template -std::ostream& operator<<(std::ostream& out, const Nz::BoundingVolume& volume); + template std::ostream& operator<<(std::ostream& out, const Nz::BoundingVolume& volume); +} #include diff --git a/include/Nazara/Math/BoundingVolume.inl b/include/Nazara/Math/BoundingVolume.inl index f5eed7091..11b71a429 100644 --- a/include/Nazara/Math/BoundingVolume.inl +++ b/include/Nazara/Math/BoundingVolume.inl @@ -466,35 +466,34 @@ namespace Nz return true; } -} -/*! -* \brief Output operator -* \return The stream -* -* \param out The stream -* \param volume The bounding volume to output -*/ - -template -std::ostream& operator<<(std::ostream& out, const Nz::BoundingVolume& volume) -{ - switch (volume.extend) + /*! + * \brief Output operator + * \return The stream + * + * \param out The stream + * \param volume The bounding volume to output + */ + template + std::ostream& operator<<(std::ostream& out, const Nz::BoundingVolume& volume) { - case Nz::Extend::Finite: - out << "BoundingVolume(localBox=" << volume.obb.localBox << ')'; - break; + switch (volume.extend) + { + case Nz::Extend::Finite: + out << "BoundingVolume(localBox=" << volume.obb.localBox << ')'; + break; - case Nz::Extend::Infinite: - out << "BoundingVolume(Infinite)"; - break; + case Nz::Extend::Infinite: + out << "BoundingVolume(Infinite)"; + break; - case Nz::Extend::Null: - out << "BoundingVolume(Null)"; - break; + case Nz::Extend::Null: + out << "BoundingVolume(Null)"; + break; + } + + return out; } - - return out; } #include diff --git a/include/Nazara/Math/Box.hpp b/include/Nazara/Math/Box.hpp index 73e3dd781..89dd7b7dd 100644 --- a/include/Nazara/Math/Box.hpp +++ b/include/Nazara/Math/Box.hpp @@ -33,6 +33,8 @@ namespace Nz Box(Box&&) noexcept = default; ~Box() = default; + bool ApproxEquals(const Box& box, T maxDifference = 0) const; + bool Contains(T X, T Y, T Z) const; bool Contains(const Box& box) const; bool Contains(const Vector3& point) const; @@ -93,12 +95,10 @@ namespace Nz template bool Serialize(SerializationContext& context, const Box& box, TypeTag>); template bool Unserialize(SerializationContext& context, Box* box, TypeTag>); + + template std::ostream& operator<<(std::ostream& out, const Nz::Box& box); } -template -std::ostream& operator<<(std::ostream& out, const Nz::Box& box); - - #include #endif // NAZARA_MATH_BOX_HPP diff --git a/include/Nazara/Math/Box.inl b/include/Nazara/Math/Box.inl index 434b57c38..1616d562f 100644 --- a/include/Nazara/Math/Box.inl +++ b/include/Nazara/Math/Box.inl @@ -137,6 +137,13 @@ namespace Nz * \see Contains */ + template + bool Box::ApproxEquals(const Box& box, T maxDifference) const + { + return NumberEquals(x, box.x, maxDifference) && NumberEquals(y, box.y, maxDifference) && NumberEquals(z, box.z, maxDifference) && + NumberEquals(width, box.width, maxDifference) && NumberEquals(height, box.height, maxDifference) && NumberEquals(depth, box.depth, maxDifference); + } + template bool Box::Contains(T X, T Y, T Z) const { @@ -635,8 +642,7 @@ namespace Nz template bool Box::operator==(const Box& box) const { - return NumberEquals(x, box.x) && NumberEquals(y, box.y) && NumberEquals(z, box.z) && - NumberEquals(width, box.width) && NumberEquals(height, box.height) && NumberEquals(depth, box.depth); + return x == box.x && y == box.y && z == box.z && width == box.width && height == box.height && depth == box.depth; } /*! @@ -788,20 +794,19 @@ namespace Nz return true; } -} -/*! -* \brief Output operator -* \return The stream -* -* \param out The stream -* \param box The box to output -*/ - -template -std::ostream& operator<<(std::ostream& out, const Nz::Box& box) -{ - return out << "Box(" << box.x << ", " << box.y << ", " << box.z << ", " << box.width << ", " << box.height << ", " << box.depth << ')'; + /*! + * \brief Output operator + * \return The stream + * + * \param out The stream + * \param box The box to output + */ + template + std::ostream& operator<<(std::ostream& out, const Nz::Box& box) + { + return out << "Box(" << box.x << ", " << box.y << ", " << box.z << ", " << box.width << ", " << box.height << ", " << box.depth << ')'; + } } #include diff --git a/include/Nazara/Math/EulerAngles.hpp b/include/Nazara/Math/EulerAngles.hpp index 8c5ef5068..afdebf800 100644 --- a/include/Nazara/Math/EulerAngles.hpp +++ b/include/Nazara/Math/EulerAngles.hpp @@ -69,9 +69,9 @@ namespace Nz template bool Serialize(SerializationContext& context, const EulerAngles& eulerAngles, TypeTag>); template bool Unserialize(SerializationContext& context, EulerAngles* eulerAngles, TypeTag>); -} -template std::ostream& operator<<(std::ostream& out, const Nz::EulerAngles& angles); + template std::ostream& operator<<(std::ostream& out, const Nz::EulerAngles& angles); +} #include diff --git a/include/Nazara/Math/EulerAngles.inl b/include/Nazara/Math/EulerAngles.inl index 1c497cf87..786e3dba7 100644 --- a/include/Nazara/Math/EulerAngles.inl +++ b/include/Nazara/Math/EulerAngles.inl @@ -383,20 +383,19 @@ namespace Nz return true; } -} -/*! -* \brief Output operator -* \return The stream -* -* \param out The stream -* \param angles The euler angle to output -*/ - -template -std::ostream& operator<<(std::ostream& out, const Nz::EulerAngles& angles) -{ - return out << "EulerAngles(" << angles.pitch << ", " << angles.yaw << ", " << angles.roll << ')'; + /*! + * \brief Output operator + * \return The stream + * + * \param out The stream + * \param angles The euler angle to output + */ + template + std::ostream& operator<<(std::ostream& out, const EulerAngles& angles) + { + return out << "EulerAngles(" << angles.pitch << ", " << angles.yaw << ", " << angles.roll << ')'; + } } #include diff --git a/include/Nazara/Math/Frustum.hpp b/include/Nazara/Math/Frustum.hpp index ab459eb36..a6da797d7 100644 --- a/include/Nazara/Math/Frustum.hpp +++ b/include/Nazara/Math/Frustum.hpp @@ -68,10 +68,9 @@ namespace Nz using Frustumd = Frustum; using Frustumf = Frustum; -} -template -std::ostream& operator<<(std::ostream& out, const Nz::Frustum& frustum); + template std::ostream& operator<<(std::ostream& out, const Nz::Frustum& frustum); +} #include diff --git a/include/Nazara/Math/Frustum.inl b/include/Nazara/Math/Frustum.inl index 849474201..0e500d9ee 100644 --- a/include/Nazara/Math/Frustum.inl +++ b/include/Nazara/Math/Frustum.inl @@ -587,25 +587,24 @@ namespace Nz return true; } -} -/*! -* \brief Output operator -* \return The stream -* -* \param out The stream -* \param frustum The frustum to output -*/ - -template -std::ostream& operator<<(std::ostream& out, const Nz::Frustum& frustum) -{ - return out << "Frustum(Bottom: " << frustum.GetPlane(Nz::FrustumPlane::Bottom) << ",\n" - << " Far: " << frustum.GetPlane(Nz::FrustumPlane::Far) << ",\n" - << " Left: " << frustum.GetPlane(Nz::FrustumPlane::Left) << ",\n" - << " Near: " << frustum.GetPlane(Nz::FrustumPlane::Near) << ",\n" - << " Right: " << frustum.GetPlane(Nz::FrustumPlane::Right) << ",\n" - << " Top: " << frustum.GetPlane(Nz::FrustumPlane::Top) << ")\n"; + /*! + * \brief Output operator + * \return The stream + * + * \param out The stream + * \param frustum The frustum to output + */ + template + std::ostream& operator<<(std::ostream& out, const Nz::Frustum& frustum) + { + return out << "Frustum(Bottom: " << frustum.GetPlane(Nz::FrustumPlane::Bottom) << ",\n" + << " Far: " << frustum.GetPlane(Nz::FrustumPlane::Far) << ",\n" + << " Left: " << frustum.GetPlane(Nz::FrustumPlane::Left) << ",\n" + << " Near: " << frustum.GetPlane(Nz::FrustumPlane::Near) << ",\n" + << " Right: " << frustum.GetPlane(Nz::FrustumPlane::Right) << ",\n" + << " Top: " << frustum.GetPlane(Nz::FrustumPlane::Top) << ")\n"; + } } #include diff --git a/include/Nazara/Math/Matrix4.hpp b/include/Nazara/Math/Matrix4.hpp index 0b59dbae2..8c8ab4dae 100644 --- a/include/Nazara/Math/Matrix4.hpp +++ b/include/Nazara/Math/Matrix4.hpp @@ -146,13 +146,12 @@ namespace Nz template bool Serialize(SerializationContext& context, const Matrix4& matrix, TypeTag>); template bool Unserialize(SerializationContext& context, Matrix4* matrix, TypeTag>); + + template std::ostream& operator<<(std::ostream& out, const Matrix4& matrix); + + template Matrix4 operator*(T scale, const Matrix4& matrix); } -template std::ostream& operator<<(std::ostream& out, const Nz::Matrix4& matrix); - -template Nz::Matrix4 operator*(T scale, const Nz::Matrix4& matrix); - - #include #endif // NAZARA_MATH_MATRIX4_HPP diff --git a/include/Nazara/Math/Matrix4.inl b/include/Nazara/Math/Matrix4.inl index a3cb38af8..32f13f1fc 100644 --- a/include/Nazara/Math/Matrix4.inl +++ b/include/Nazara/Math/Matrix4.inl @@ -1769,38 +1769,38 @@ namespace Nz return true; } + + /*! + * \brief Output operator + * \return The stream + * + * \param out The stream + * \param matrix The matrix to output + */ + + template + std::ostream& operator<<(std::ostream& out, const Matrix4& matrix) + { + return out << "Matrix4(" << matrix.m11 << ", " << matrix.m12 << ", " << matrix.m13 << ", " << matrix.m14 << ",\n" + << " " << matrix.m21 << ", " << matrix.m22 << ", " << matrix.m23 << ", " << matrix.m24 << ",\n" + << " " << matrix.m31 << ", " << matrix.m32 << ", " << matrix.m33 << ", " << matrix.m34 << ",\n" + << " " << matrix.m41 << ", " << matrix.m42 << ", " << matrix.m43 << ", " << matrix.m44 << ')'; + } + + /*! + * \brief Multiplies the components of the matrix with a scalar + * \return A Matrix4 where components are the product of matrix'components and the scalar + * + * \param scale The scalar to multiply the matrix'components with + * \param matrix Matrix to multiply with + */ + template + Matrix4 operator*(T scale, const Matrix4& matrix) + { + return matrix * scale; + } } -/*! -* \brief Output operator -* \return The stream -* -* \param out The stream -* \param matrix The matrix to output -*/ - -template -std::ostream& operator<<(std::ostream& out, const Nz::Matrix4& matrix) -{ - return out << "Matrix4(" << matrix.m11 << ", " << matrix.m12 << ", " << matrix.m13 << ", " << matrix.m14 << ",\n" - << " " << matrix.m21 << ", " << matrix.m22 << ", " << matrix.m23 << ", " << matrix.m24 << ",\n" - << " " << matrix.m31 << ", " << matrix.m32 << ", " << matrix.m33 << ", " << matrix.m34 << ",\n" - << " " << matrix.m41 << ", " << matrix.m42 << ", " << matrix.m43 << ", " << matrix.m44 << ')'; -} - -/*! -* \brief Multiplies the components of the matrix with a scalar -* \return A Matrix4 where components are the product of matrix'components and the scalar -* -* \param scale The scalar to multiply the matrix'components with -* \param matrix Matrix to multiply with -*/ - -template -Nz::Matrix4 operator*(T scale, const Nz::Matrix4& matrix) -{ - return matrix * scale; -} #include -#include "Matrix4.hpp" + diff --git a/include/Nazara/Math/OrientedBox.hpp b/include/Nazara/Math/OrientedBox.hpp index e75eb8bc2..1020f0a44 100644 --- a/include/Nazara/Math/OrientedBox.hpp +++ b/include/Nazara/Math/OrientedBox.hpp @@ -61,10 +61,9 @@ namespace Nz template bool Serialize(SerializationContext& context, const OrientedBox& obb, TypeTag>); template bool Unserialize(SerializationContext& context, OrientedBox* obb, TypeTag>); -} -template -std::ostream& operator<<(std::ostream& out, const Nz::OrientedBox& orientedBox); + template std::ostream& operator<<(std::ostream& out, const Nz::OrientedBox& orientedBox); +} #include diff --git a/include/Nazara/Math/OrientedBox.inl b/include/Nazara/Math/OrientedBox.inl index 8072b1f26..6a8c7b454 100644 --- a/include/Nazara/Math/OrientedBox.inl +++ b/include/Nazara/Math/OrientedBox.inl @@ -274,28 +274,26 @@ namespace Nz return true; } -} -/*! -* \brief Output operator -* \return The stream -* -* \param out The stream -* \param orientedBox The orientedBox to output -*/ - -template -std::ostream& operator<<(std::ostream& out, const Nz::OrientedBox& orientedBox) -{ - return out << "OrientedBox(FLB: " << orientedBox.GetCorner(Nz::BoxCorner::FarLeftBottom) << ",\n" - << " FLT: " << orientedBox.GetCorner(Nz::BoxCorner::FarLeftTop) << ",\n" - << " FRB: " << orientedBox.GetCorner(Nz::BoxCorner::FarRightBottom) << ",\n" - << " FRT: " << orientedBox.GetCorner(Nz::BoxCorner::FarRightTop) << ",\n" - << " NLB: " << orientedBox.GetCorner(Nz::BoxCorner::NearLeftBottom) << ",\n" - << " NLT: " << orientedBox.GetCorner(Nz::BoxCorner::NearLeftTop) << ",\n" - << " NRB: " << orientedBox.GetCorner(Nz::BoxCorner::NearRightBottom) << ",\n" - << " NRT: " << orientedBox.GetCorner(Nz::BoxCorner::NearRightTop) << ")\n"; + /*! + * \brief Output operator + * \return The stream + * + * \param out The stream + * \param orientedBox The orientedBox to output + */ + template + std::ostream& operator<<(std::ostream& out, const Nz::OrientedBox& orientedBox) + { + return out << "OrientedBox(FLB: " << orientedBox.GetCorner(Nz::BoxCorner::FarLeftBottom) << ",\n" + << " FLT: " << orientedBox.GetCorner(Nz::BoxCorner::FarLeftTop) << ",\n" + << " FRB: " << orientedBox.GetCorner(Nz::BoxCorner::FarRightBottom) << ",\n" + << " FRT: " << orientedBox.GetCorner(Nz::BoxCorner::FarRightTop) << ",\n" + << " NLB: " << orientedBox.GetCorner(Nz::BoxCorner::NearLeftBottom) << ",\n" + << " NLT: " << orientedBox.GetCorner(Nz::BoxCorner::NearLeftTop) << ",\n" + << " NRB: " << orientedBox.GetCorner(Nz::BoxCorner::NearRightBottom) << ",\n" + << " NRT: " << orientedBox.GetCorner(Nz::BoxCorner::NearRightTop) << ")\n"; + } } #include -#include "OrientedBox.hpp" diff --git a/include/Nazara/Math/Plane.hpp b/include/Nazara/Math/Plane.hpp index 19493f51f..253d2b381 100644 --- a/include/Nazara/Math/Plane.hpp +++ b/include/Nazara/Math/Plane.hpp @@ -64,10 +64,9 @@ namespace Nz template bool Serialize(SerializationContext& context, const Plane& plane, TypeTag>); template bool Unserialize(SerializationContext& context, Plane* plane, TypeTag>); -} -template -std::ostream& operator<<(std::ostream& out, const Nz::Plane& plane); + template std::ostream& operator<<(std::ostream& out, const Nz::Plane& plane); +} #include diff --git a/include/Nazara/Math/Plane.inl b/include/Nazara/Math/Plane.inl index 62f3bb752..22495ed8a 100644 --- a/include/Nazara/Math/Plane.inl +++ b/include/Nazara/Math/Plane.inl @@ -469,20 +469,19 @@ namespace Nz return true; } -} -/*! -* \brief Output operator -* \return The stream -* -* \param out The stream -* \param plane The plane to output -*/ - -template -std::ostream& operator<<(std::ostream& out, const Nz::Plane& plane) -{ - return out << "Plane(Normal: " << plane.normal << "; Distance: " << plane.distance << ')'; + /*! + * \brief Output operator + * \return The stream + * + * \param out The stream + * \param plane The plane to output + */ + template + std::ostream& operator<<(std::ostream& out, const Nz::Plane& plane) + { + return out << "Plane(Normal: " << plane.normal << "; Distance: " << plane.distance << ')'; + } } #include diff --git a/include/Nazara/Math/Quaternion.hpp b/include/Nazara/Math/Quaternion.hpp index e24662208..6f19c68c7 100644 --- a/include/Nazara/Math/Quaternion.hpp +++ b/include/Nazara/Math/Quaternion.hpp @@ -98,9 +98,9 @@ namespace Nz template bool Serialize(SerializationContext& context, const Quaternion& quat, TypeTag>); template bool Unserialize(SerializationContext& context, Quaternion* quat, TypeTag>); -} -template std::ostream& operator<<(std::ostream& out, const Nz::Quaternion& quat); + template std::ostream& operator<<(std::ostream& out, const Nz::Quaternion& quat); +} #include diff --git a/include/Nazara/Math/Quaternion.inl b/include/Nazara/Math/Quaternion.inl index de239bf5b..48e4dc5ed 100644 --- a/include/Nazara/Math/Quaternion.inl +++ b/include/Nazara/Math/Quaternion.inl @@ -927,20 +927,19 @@ namespace Nz return true; } -} -/*! -* \brief Output operator -* \return The stream -* -* \param out The stream -* \param quat The quaternion to output -*/ - -template -std::ostream& operator<<(std::ostream& out, const Nz::Quaternion& quat) -{ - return out << "Quaternion(" << quat.w << " | " << quat.x << ", " << quat.y << ", " << quat.z << ')'; + /*! + * \brief Output operator + * \return The stream + * + * \param out The stream + * \param quat The quaternion to output + */ + template + std::ostream& operator<<(std::ostream& out, const Nz::Quaternion& quat) + { + return out << "Quaternion(" << quat.w << " | " << quat.x << ", " << quat.y << ", " << quat.z << ')'; + } } #include diff --git a/include/Nazara/Math/Ray.hpp b/include/Nazara/Math/Ray.hpp index 0ce84d33f..d7fc4ea0d 100644 --- a/include/Nazara/Math/Ray.hpp +++ b/include/Nazara/Math/Ray.hpp @@ -77,9 +77,9 @@ namespace Nz template bool Serialize(SerializationContext& context, const Ray& ray, TypeTag>); template bool Unserialize(SerializationContext& context, Ray* ray, TypeTag>); -} -template std::ostream& operator<<(std::ostream& out, const Nz::Ray& vec); + template std::ostream& operator<<(std::ostream& out, const Nz::Ray& vec); +} #include diff --git a/include/Nazara/Math/Ray.inl b/include/Nazara/Math/Ray.inl index e59c705b5..4726c6f5b 100644 --- a/include/Nazara/Math/Ray.inl +++ b/include/Nazara/Math/Ray.inl @@ -748,20 +748,20 @@ namespace Nz return true; } -} -/*! -* \brief Output operator -* \return The stream -* -* \param out The stream -* \param ray The ray to output -*/ + /*! + * \brief Output operator + * \return The stream + * + * \param out The stream + * \param ray The ray to output + */ -template -std::ostream& operator<<(std::ostream& out, const Nz::Ray& ray) -{ - return out << "Ray(origin: " << ray.origin << ", direction: " << ray.direction << ")"; + template + std::ostream& operator<<(std::ostream& out, const Nz::Ray& ray) + { + return out << "Ray(origin: " << ray.origin << ", direction: " << ray.direction << ")"; + } } #include diff --git a/include/Nazara/Math/Rect.hpp b/include/Nazara/Math/Rect.hpp index 04936b1cc..11d4fdd6e 100644 --- a/include/Nazara/Math/Rect.hpp +++ b/include/Nazara/Math/Rect.hpp @@ -29,6 +29,8 @@ namespace Nz Rect(Rect&&) noexcept = default; ~Rect() = default; + bool ApproxEquals(const Rect& rect, T maxDifference = 0) const; + bool Contains(T X, T Y) const; bool Contains(const Rect& rect) const; bool Contains(const Vector2& point) const; @@ -88,10 +90,9 @@ namespace Nz template bool Serialize(SerializationContext& context, const Rect& rect, TypeTag>); template bool Unserialize(SerializationContext& context, Rect* rect, TypeTag>); -} -template -std::ostream& operator<<(std::ostream& out, const Nz::Rect& rect); + template std::ostream& operator<<(std::ostream& out, const Nz::Rect& rect); +} #include diff --git a/include/Nazara/Math/Rect.inl b/include/Nazara/Math/Rect.inl index 275b68b06..e288fd214 100644 --- a/include/Nazara/Math/Rect.inl +++ b/include/Nazara/Math/Rect.inl @@ -97,6 +97,13 @@ namespace Nz { } + template + bool Rect::ApproxEquals(const Rect& rect, T maxDifference) const + { + return NumberEquals(x, rect.x, maxDifference) && NumberEquals(y, rect.y, maxDifference) && + NumberEquals(width, rect.width, maxDifference) && NumberEquals(height, rect.height, maxDifference); + } + /*! * \brief Tests whether the rectangle contains the provided point inclusive of the edge of the rectangle * \return true if inclusive @@ -517,8 +524,7 @@ namespace Nz template bool Rect::operator==(const Rect& rect) const { - return NumberEquals(x, rect.x) && NumberEquals(y, rect.y) && - NumberEquals(width, rect.width) && NumberEquals(height, rect.height); + return x == rect.x && y == rect.y && width == rect.width && height == rect.height; } /*! @@ -649,20 +655,20 @@ namespace Nz return true; } -} -/*! -* \brief Output operator -* \return The stream -* -* \param out The stream -* \param rect The rectangle to output -*/ + /*! + * \brief Output operator + * \return The stream + * + * \param out The stream + * \param rect The rectangle to output + */ -template -std::ostream& operator<<(std::ostream& out, const Nz::Rect& rect) -{ - return out << "Rect(" << rect.x << ", " << rect.y << ", " << rect.width << ", " << rect.height << ')'; + template + std::ostream& operator<<(std::ostream& out, const Nz::Rect& rect) + { + return out << "Rect(" << rect.x << ", " << rect.y << ", " << rect.width << ", " << rect.height << ')'; + } } #include diff --git a/include/Nazara/Math/Sphere.hpp b/include/Nazara/Math/Sphere.hpp index 8e593fc2b..5b2d87ced 100644 --- a/include/Nazara/Math/Sphere.hpp +++ b/include/Nazara/Math/Sphere.hpp @@ -82,10 +82,9 @@ namespace Nz template bool Serialize(SerializationContext& context, const Sphere& sphere, TypeTag>); template bool Unserialize(SerializationContext& context, Sphere* sphere, TypeTag>); -} -template -std::ostream& operator<<(std::ostream& out, const Nz::Sphere& sphere); + template std::ostream& operator<<(std::ostream& out, const Nz::Sphere& sphere); +} #include diff --git a/include/Nazara/Math/Sphere.inl b/include/Nazara/Math/Sphere.inl index 1306def29..65fa0e805 100644 --- a/include/Nazara/Math/Sphere.inl +++ b/include/Nazara/Math/Sphere.inl @@ -649,20 +649,19 @@ namespace Nz return true; } -} -/*! -* \brief Output operator -* \return The stream -* -* \param out The stream -* \param sphere The sphere to output -*/ - -template -std::ostream& operator<<(std::ostream& out, const Nz::Sphere& sphere) -{ - return out << "Sphere(" << sphere.x << ", " << sphere.y << ", " << sphere.z << "; " << sphere.radius << ')'; + /*! + * \brief Output operator + * \return The stream + * + * \param out The stream + * \param sphere The sphere to output + */ + template + std::ostream& operator<<(std::ostream& out, const Nz::Sphere& sphere) + { + return out << "Sphere(" << sphere.x << ", " << sphere.y << ", " << sphere.z << "; " << sphere.radius << ')'; + } } #include diff --git a/include/Nazara/Math/Vector2.hpp b/include/Nazara/Math/Vector2.hpp index dca904618..d1f3a9b5f 100644 --- a/include/Nazara/Math/Vector2.hpp +++ b/include/Nazara/Math/Vector2.hpp @@ -117,13 +117,13 @@ namespace Nz template bool Serialize(SerializationContext& context, const Vector2& vector, TypeTag>); template bool Unserialize(SerializationContext& context, Vector2* vector, TypeTag>); + + template std::ostream& operator<<(std::ostream& out, const Vector2& vec); + + template Vector2 operator*(T scale, const Nz::Vector2& vec); + template Vector2 operator/(T scale, const Nz::Vector2& vec); } -template std::ostream& operator<<(std::ostream& out, const Nz::Vector2& vec); - -template Nz::Vector2 operator*(T scale, const Nz::Vector2& vec); -template Nz::Vector2 operator/(T scale, const Nz::Vector2& vec); - namespace std { template struct hash>; diff --git a/include/Nazara/Math/Vector2.inl b/include/Nazara/Math/Vector2.inl index 94f1a6ca3..26f8fedd1 100644 --- a/include/Nazara/Math/Vector2.inl +++ b/include/Nazara/Math/Vector2.inl @@ -885,6 +885,43 @@ namespace Nz return vector; } + /*! + * \brief Output operator + * \return The stream + * + * \param out The stream + * \param vec The vector to output + */ + template + std::ostream& operator<<(std::ostream& out, const Vector2& vec) + { + return out << "Vector2(" << vec.x << ", " << vec.y << ')'; + } + + /*! + * \brief Multiplies the components of the vector with a scalar + * \return A vector where components are the product of this vector and the scalar + * + * \param scale The scalar to multiply components with + */ + template + Vector2 operator*(T scale, const Vector2& vec) + { + return Vector2(scale * vec.x, scale * vec.y); + } + + /*! + * \brief Divides the components of the vector with a scalar + * \return A vector where components are the quotient of this vector and the scalar + * + * \param scale The scalar to divide components with + */ + template + Vector2 operator/(T scale, const Vector2& vec) + { + return Vector2(scale / vec.x, scale / vec.y); + } + /*! * \brief Serializes a Vector2 * \return true if successfully serialized @@ -924,46 +961,6 @@ namespace Nz } } -/*! -* \brief Output operator -* \return The stream -* -* \param out The stream -* \param vec The vector to output -*/ - -template -std::ostream& operator<<(std::ostream& out, const Nz::Vector2& vec) -{ - return out << "Vector2(" << vec.x << ", " << vec.y << ')'; -} - -/*! -* \brief Multiplies the components of the vector with a scalar -* \return A vector where components are the product of this vector and the scalar -* -* \param scale The scalar to multiply components with -*/ - -template -Nz::Vector2 operator*(T scale, const Nz::Vector2& vec) -{ - return Nz::Vector2(scale * vec.x, scale * vec.y); -} - -/*! -* \brief Divides the components of the vector with a scalar -* \return A vector where components are the quotient of this vector and the scalar -* -* \param scale The scalar to divide components with -*/ - -template -Nz::Vector2 operator/(T scale, const Nz::Vector2& vec) -{ - return Nz::Vector2(scale / vec.x, scale / vec.y); -} - namespace std { template diff --git a/include/Nazara/Math/Vector3.hpp b/include/Nazara/Math/Vector3.hpp index 6e0db6665..62d8135a8 100644 --- a/include/Nazara/Math/Vector3.hpp +++ b/include/Nazara/Math/Vector3.hpp @@ -137,13 +137,13 @@ namespace Nz template bool Serialize(SerializationContext& context, const Vector3& vector, TypeTag>); template bool Unserialize(SerializationContext& context, Vector3* vector, TypeTag>); + + template std::ostream& operator<<(std::ostream& out, const Vector3& vec); + + template Vector3 operator*(T scale, const Vector3& vec); + template Vector3 operator/(T scale, const Vector3& vec); } -template std::ostream& operator<<(std::ostream& out, const Nz::Vector3& vec); - -template Nz::Vector3 operator*(T scale, const Nz::Vector3& vec); -template Nz::Vector3 operator/(T scale, const Nz::Vector3& vec); - namespace std { template struct hash>; diff --git a/include/Nazara/Math/Vector3.inl b/include/Nazara/Math/Vector3.inl index 1a8f3d5a7..342dcb180 100644 --- a/include/Nazara/Math/Vector3.inl +++ b/include/Nazara/Math/Vector3.inl @@ -1188,46 +1188,43 @@ namespace Nz return true; } -} -/*! -* \brief Output operator -* \return The stream -* -* \param out The stream -* \param vec The vector to output -*/ + /*! + * \brief Output operator + * \return The stream + * + * \param out The stream + * \param vec The vector to output + */ + template + std::ostream& operator<<(std::ostream& out, const Vector3& vec) + { + return out << "Vector3(" << vec.x << ", " << vec.y << ", " << vec.z << ')'; + } -template -std::ostream& operator<<(std::ostream& out, const Nz::Vector3& vec) -{ - return out << "Vector3(" << vec.x << ", " << vec.y << ", " << vec.z << ')'; -} + /*! + * \brief Multiplies the components of the vector with a scalar + * \return A vector where components are the product of this vector and the scalar + * + * \param scale The scalar to multiply components with + */ + template + Vector3 operator*(T scale, const Vector3& vec) + { + return Vector3(scale * vec.x, scale * vec.y, scale * vec.z); + } -/*! -* \brief Multiplies the components of the vector with a scalar -* \return A vector where components are the product of this vector and the scalar -* -* \param scale The scalar to multiply components with -*/ - -template -Nz::Vector3 operator*(T scale, const Nz::Vector3& vec) -{ - return Nz::Vector3(scale * vec.x, scale * vec.y, scale * vec.z); -} - -/*! -* \brief Divides the components of the vector with a scalar -* \return A vector where components are the quotient of this vector and the scalar -* -* \param scale The scalar to divide components with -*/ - -template -Nz::Vector3 operator/(T scale, const Nz::Vector3& vec) -{ - return Nz::Vector3(scale / vec.x, scale / vec.y, scale / vec.z); + /*! + * \brief Divides the components of the vector with a scalar + * \return A vector where components are the quotient of this vector and the scalar + * + * \param scale The scalar to divide components with + */ + template + Vector3 operator/(T scale, const Vector3& vec) + { + return Vector3(scale / vec.x, scale / vec.y, scale / vec.z); + } } namespace std diff --git a/include/Nazara/Math/Vector4.hpp b/include/Nazara/Math/Vector4.hpp index 945b062df..15e0011dd 100644 --- a/include/Nazara/Math/Vector4.hpp +++ b/include/Nazara/Math/Vector4.hpp @@ -113,13 +113,13 @@ namespace Nz template bool Serialize(SerializationContext& context, const Vector4& vector, TypeTag>); template bool Unserialize(SerializationContext& context, Vector4* vector, TypeTag>); + + template std::ostream& operator<<(std::ostream& out, const Vector4& vec); + + template Vector4 operator*(T scale, const Vector4& vec); + template Vector4 operator/(T scale, const Vector4& vec); } -template std::ostream& operator<<(std::ostream& out, const Nz::Vector4& vec); - -template Nz::Vector4 operator*(T scale, const Nz::Vector4& vec); -template Nz::Vector4 operator/(T scale, const Nz::Vector4& vec); - namespace std { template struct hash>; diff --git a/include/Nazara/Math/Vector4.inl b/include/Nazara/Math/Vector4.inl index afb9fa80e..8a5efeebe 100644 --- a/include/Nazara/Math/Vector4.inl +++ b/include/Nazara/Math/Vector4.inl @@ -997,47 +997,43 @@ namespace Nz return true; } -} -/*! -* \brief Output operator -* \return The stream -* -* \param out The stream -* \param vec The vector to output -*/ + /*! + * \brief Output operator + * \return The stream + * + * \param out The stream + * \param vec The vector to output + */ + template + std::ostream& operator<<(std::ostream& out, const Vector4& vec) + { + return out << "Vector4(" << vec.x << ", " << vec.y << ", " << vec.z << ", " << vec.w << ')'; + } -template -std::ostream& operator<<(std::ostream& out, const Nz::Vector4& vec) -{ - return out << "Vector4(" << vec.x << ", " << vec.y << ", " << vec.z << ", " << vec.w << ')'; -} + /*! + * \brief Multiplies the components of the vector with a scalar + * \return A vector where components are the product of this vector and the scalar + * + * \param scale The scalar to multiply components with + */ + template + Vector4 operator*(T scale, const Vector4& vec) + { + return Nz::Vector4(scale * vec.x, scale * vec.y, scale * vec.z, scale * vec.w); + } -/*! -* \brief Multiplies the components of the vector with a scalar -* \return A vector where components are the product of this vector and the scalar -* -* \param scale The scalar to multiply components with -*/ - - -template -Nz::Vector4 operator*(T scale, const Nz::Vector4& vec) -{ - return Nz::Vector4(scale * vec.x, scale * vec.y, scale * vec.z, scale * vec.w); -} - -/*! -* \brief Divides the components of the vector with a scalar -* \return A vector where components are the quotient of this vector and the scalar -* -* \param scale The scalar to divide components with -*/ - -template -Nz::Vector4 operator/(T scale, const Nz::Vector4& vec) -{ - return Nz::Vector4(scale / vec.x, scale / vec.y, scale / vec.z, scale / vec.w); + /*! + * \brief Divides the components of the vector with a scalar + * \return A vector where components are the quotient of this vector and the scalar + * + * \param scale The scalar to divide components with + */ + template + Vector4 operator/(T scale, const Vector4& vec) + { + return Nz::Vector4(scale / vec.x, scale / vec.y, scale / vec.z, scale / vec.w); + } } namespace std diff --git a/src/Nazara/Core/ParameterList.cpp b/src/Nazara/Core/ParameterList.cpp index d6ca9ae0d..cff088b19 100644 --- a/src/Nazara/Core/ParameterList.cpp +++ b/src/Nazara/Core/ParameterList.cpp @@ -769,18 +769,17 @@ namespace Nz break; } } -} -/*! -* \brief Output operator -* \return The stream -* -* \param out The stream -* \param parameterList The ParameterList to output -*/ - -std::ostream& operator<<(std::ostream& out, const Nz::ParameterList& parameterList) -{ - out << parameterList.ToString(); - return out; + /*! + * \brief Output operator + * \return The stream + * + * \param out The stream + * \param parameterList The ParameterList to output + */ + std::ostream& operator<<(std::ostream& out, const Nz::ParameterList& parameterList) + { + out << parameterList.ToString(); + return out; + } }