diff --git a/include/omath/Vector2.h b/include/omath/Vector2.h index 0bb73e9..1ad0341 100644 --- a/include/omath/Vector2.h +++ b/include/omath/Vector2.h @@ -114,11 +114,29 @@ namespace omath return x * vOther.x + y * vOther.y; } +#ifndef _MSC_VER [[nodiscard]] constexpr float Length() const { return std::hypot(x, y); } + [[nodiscard]] constexpr Vector2 Normalized() const + { + const float len = Length(); + return len > 0.f ? *this / len : *this; + } +#else + [[nodiscard]] float Length() const + { + return std::hypot(x, y); + } + + [[nodiscard]] Vector2 Normalized() const + { + const float len = Length(); + return len > 0.f ? *this / len : *this; + } +#endif [[nodiscard]] constexpr float LengthSqr() const { return x * x + y * y; @@ -169,13 +187,6 @@ namespace omath return {x / fl, y / fl}; } - // Normalize the vector - [[nodiscard]] constexpr Vector2 Normalized() const - { - const float len = Length(); - return len > 0.f ? *this / len : *this; - } - // Sum of elements [[nodiscard]] constexpr float Sum() const { diff --git a/include/omath/Vector3.h b/include/omath/Vector3.h index 1b75d39..53ea6ac 100644 --- a/include/omath/Vector3.h +++ b/include/omath/Vector3.h @@ -92,11 +92,6 @@ namespace omath return *this; } - [[nodiscard]] constexpr float DistTo(const Vector3& vOther) const - { - return (*this - vOther).Length(); - } - constexpr Vector3& Abs() { Vector2::Abs(); @@ -115,20 +110,55 @@ namespace omath return Vector2::Dot(vOther) + z * vOther.z; } +#ifndef _MSC_VER [[nodiscard]] constexpr float Length() const { return std::hypot(x, y, z); } - [[nodiscard]] constexpr float LengthSqr() const - { - return Vector2::LengthSqr() + z * z; - } - [[nodiscard]] constexpr float Length2D() const { return Vector2::Length(); } + [[nodiscard]] float DistTo(const Vector3& vOther) const + { + return (*this - vOther).Length(); + } + [[nodiscard]] constexpr Vector3 Normalized() const + { + const float length = this->Length(); + + return length != 0 ? *this / length : *this; + } +#else + [[nodiscard]] float Length() const + { + return std::hypot(x, y, z); + } + + [[nodiscard]] Vector3 Normalized() const + { + const float length = this->Length(); + + return length != 0 ? *this / length : *this; + } + + [[nodiscard]] float Length2D() const + { + return Vector2::Length(); + } + + [[nodiscard]] float DistTo(const Vector3& vOther) const + { + return (*this - vOther).Length(); + } +#endif + + + [[nodiscard]] constexpr float LengthSqr() const + { + return Vector2::LengthSqr() + z * z; + } [[nodiscard]] constexpr Vector3 operator-() const { @@ -190,14 +220,6 @@ namespace omath [[nodiscard]] static Vector3 RightVector(float pitch, float yaw, float roll); [[nodiscard]] static Vector3 UpVector(float pitch, float yaw, float roll); - - [[nodiscard]] constexpr Vector3 Normalized() const - { - const float length = this->Length(); - - return length != 0 ? *this / length : *this; - } - [[nodiscard]] std::tuple AsTuple() const { return std::make_tuple(x, y, z);