From 387e8d1dd9bd0eefbbfb820275a7c6aebe569329 Mon Sep 17 00:00:00 2001 From: Ari Vuollet Date: Sun, 4 Aug 2024 20:15:12 +0300 Subject: [PATCH] Use larger epsilon in `Vector` `IsNormalized` checks --- Source/Engine/Core/Math/Double2.cs | 2 +- Source/Engine/Core/Math/Double3.cs | 2 +- Source/Engine/Core/Math/Double4.cs | 2 +- Source/Engine/Core/Math/Float2.cs | 2 +- Source/Engine/Core/Math/Float3.cs | 2 +- Source/Engine/Core/Math/Float4.cs | 2 +- Source/Engine/Core/Math/Quaternion.cs | 2 +- Source/Engine/Core/Math/Quaternion.h | 2 +- Source/Engine/Core/Math/Vector2.cs | 2 +- Source/Engine/Core/Math/Vector2.h | 2 +- Source/Engine/Core/Math/Vector3.cs | 2 +- Source/Engine/Core/Math/Vector3.h | 2 +- Source/Engine/Core/Math/Vector4.cs | 2 +- 13 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Source/Engine/Core/Math/Double2.cs b/Source/Engine/Core/Math/Double2.cs index 2b6c71282..d3df12898 100644 --- a/Source/Engine/Core/Math/Double2.cs +++ b/Source/Engine/Core/Math/Double2.cs @@ -179,7 +179,7 @@ namespace FlaxEngine /// /// Gets a value indicting whether this instance is normalized. /// - public bool IsNormalized => Mathd.IsOne(X * X + Y * Y); + public bool IsNormalized => Mathd.Abs((X * X + Y * Y) - 1.0f) < 1e-4f; /// /// Gets a value indicting whether this vector is zero diff --git a/Source/Engine/Core/Math/Double3.cs b/Source/Engine/Core/Math/Double3.cs index aba7345a0..c84c9a935 100644 --- a/Source/Engine/Core/Math/Double3.cs +++ b/Source/Engine/Core/Math/Double3.cs @@ -234,7 +234,7 @@ namespace FlaxEngine /// /// Gets a value indicting whether this instance is normalized. /// - public bool IsNormalized => Mathd.IsOne(X * X + Y * Y + Z * Z); + public bool IsNormalized => Mathd.Abs((X * X + Y * Y + Z * Z) - 1.0f) < 1e-4f; /// /// Gets the normalized vector. Returned vector has length equal 1. diff --git a/Source/Engine/Core/Math/Double4.cs b/Source/Engine/Core/Math/Double4.cs index 504c4fcce..1e115c3ae 100644 --- a/Source/Engine/Core/Math/Double4.cs +++ b/Source/Engine/Core/Math/Double4.cs @@ -220,7 +220,7 @@ namespace FlaxEngine /// /// Gets a value indicting whether this instance is normalized. /// - public bool IsNormalized => Mathd.IsOne(X * X + Y * Y + Z * Z + W * W); + public bool IsNormalized => Mathd.Abs((X * X + Y * Y + Z * Z + W * W) - 1.0f) < 1e-4f; /// /// Gets a value indicting whether this vector is zero diff --git a/Source/Engine/Core/Math/Float2.cs b/Source/Engine/Core/Math/Float2.cs index 9c3909214..adbe61508 100644 --- a/Source/Engine/Core/Math/Float2.cs +++ b/Source/Engine/Core/Math/Float2.cs @@ -184,7 +184,7 @@ namespace FlaxEngine /// /// Gets a value indicting whether this instance is normalized. /// - public bool IsNormalized => Mathf.IsOne(X * X + Y * Y); + public bool IsNormalized => Mathf.Abs((X * X + Y * Y) - 1.0f) < 1e-4f; /// /// Gets a value indicting whether this vector is zero diff --git a/Source/Engine/Core/Math/Float3.cs b/Source/Engine/Core/Math/Float3.cs index 46814c2e8..beb35d541 100644 --- a/Source/Engine/Core/Math/Float3.cs +++ b/Source/Engine/Core/Math/Float3.cs @@ -228,7 +228,7 @@ namespace FlaxEngine /// /// Gets a value indicting whether this instance is normalized. /// - public bool IsNormalized => Mathf.IsOne(X * X + Y * Y + Z * Z); + public bool IsNormalized => Mathf.Abs((X * X + Y * Y + Z * Z) - 1.0f) < 1e-4f; /// /// Gets the normalized vector. Returned vector has length equal 1. diff --git a/Source/Engine/Core/Math/Float4.cs b/Source/Engine/Core/Math/Float4.cs index 6742ca34d..7b9a81b84 100644 --- a/Source/Engine/Core/Math/Float4.cs +++ b/Source/Engine/Core/Math/Float4.cs @@ -202,7 +202,7 @@ namespace FlaxEngine /// /// Gets a value indicting whether this instance is normalized. /// - public bool IsNormalized => Mathf.IsOne(X * X + Y * Y + Z * Z + W * W); + public bool IsNormalized => Mathf.Abs((X * X + Y * Y + Z * Z + W * W) - 1.0f) < 1e-4f; /// /// Gets a value indicting whether this vector is zero diff --git a/Source/Engine/Core/Math/Quaternion.cs b/Source/Engine/Core/Math/Quaternion.cs index d4d0fe96c..e50795221 100644 --- a/Source/Engine/Core/Math/Quaternion.cs +++ b/Source/Engine/Core/Math/Quaternion.cs @@ -163,7 +163,7 @@ namespace FlaxEngine /// /// Gets a value indicting whether this instance is normalized. /// - public bool IsNormalized => Mathf.IsOne(X * X + Y * Y + Z * Z + W * W); + public bool IsNormalized => Mathf.Abs((X * X + Y * Y + Z * Z + W * W) - 1.0f) < 1e-4f; /// /// Gets the euler angle (pitch, yaw, roll) in degrees. diff --git a/Source/Engine/Core/Math/Quaternion.h b/Source/Engine/Core/Math/Quaternion.h index 0790dcbfb..45605a674 100644 --- a/Source/Engine/Core/Math/Quaternion.h +++ b/Source/Engine/Core/Math/Quaternion.h @@ -107,7 +107,7 @@ public: /// bool IsNormalized() const { - return Math::IsOne(X * X + Y * Y + Z * Z + W * W); + return Math::Abs((X * X + Y * Y + Z * Z + W * W) - 1.0f) < 1e-4f; } /// diff --git a/Source/Engine/Core/Math/Vector2.cs b/Source/Engine/Core/Math/Vector2.cs index 29628c1fb..4570ad2e9 100644 --- a/Source/Engine/Core/Math/Vector2.cs +++ b/Source/Engine/Core/Math/Vector2.cs @@ -207,7 +207,7 @@ namespace FlaxEngine /// /// Gets a value indicting whether this instance is normalized. /// - public bool IsNormalized => Mathr.IsOne(X * X + Y * Y); + public bool IsNormalized => Mathr.Abs((X * X + Y * Y) - 1.0f) < 1e-4f; /// /// Gets a value indicting whether this vector is zero diff --git a/Source/Engine/Core/Math/Vector2.h b/Source/Engine/Core/Math/Vector2.h index 9854b472e..f36249025 100644 --- a/Source/Engine/Core/Math/Vector2.h +++ b/Source/Engine/Core/Math/Vector2.h @@ -105,7 +105,7 @@ public: // Gets a value indicting whether this instance is normalized. bool IsNormalized() const { - return Math::IsOne(X * X + Y * Y); + return Math::Abs((X * X + Y * Y) - 1.0f) < 1e-4f; } // Gets a value indicting whether this vector is zero. diff --git a/Source/Engine/Core/Math/Vector3.cs b/Source/Engine/Core/Math/Vector3.cs index 848a3b532..738a9bad8 100644 --- a/Source/Engine/Core/Math/Vector3.cs +++ b/Source/Engine/Core/Math/Vector3.cs @@ -256,7 +256,7 @@ namespace FlaxEngine /// /// Gets a value indicting whether this instance is normalized. /// - public bool IsNormalized => Mathr.IsOne(X * X + Y * Y + Z * Z); + public bool IsNormalized => Mathr.Abs((X * X + Y * Y + Z * Z) - 1.0f) < 1e-4f; /// /// Gets the normalized vector. Returned vector has length equal 1. diff --git a/Source/Engine/Core/Math/Vector3.h b/Source/Engine/Core/Math/Vector3.h index 950d730c5..619fcfc12 100644 --- a/Source/Engine/Core/Math/Vector3.h +++ b/Source/Engine/Core/Math/Vector3.h @@ -136,7 +136,7 @@ public: // Gets a value indicting whether this instance is normalized. bool IsNormalized() const { - return Math::IsOne(X * X + Y * Y + Z * Z); + return Math::Abs((X * X + Y * Y + Z * Z) - 1.0f) < 1e-4f; } // Gets a value indicting whether this vector is zero. diff --git a/Source/Engine/Core/Math/Vector4.cs b/Source/Engine/Core/Math/Vector4.cs index 64487e3c7..e859938bf 100644 --- a/Source/Engine/Core/Math/Vector4.cs +++ b/Source/Engine/Core/Math/Vector4.cs @@ -258,7 +258,7 @@ namespace FlaxEngine /// /// Gets a value indicting whether this instance is normalized. /// - public bool IsNormalized => Mathr.IsOne(X * X + Y * Y + Z * Z + W * W); + public bool IsNormalized => Mathr.Abs((X * X + Y * Y + Z * Z + W * W) - 1.0f) < 1e-4f; /// /// Gets a value indicting whether this vector is zero