From 14c16746f3c81719e061da43fb89ed1b744bd121 Mon Sep 17 00:00:00 2001 From: Raul Santos Date: Fri, 13 Jan 2023 18:49:13 +0100 Subject: Add `IsZeroApprox` to C# vectors --- modules/mono/glue/GodotSharp/GodotSharp/Core/Mathf.cs | 5 +++-- modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2.cs | 12 ++++++++++++ modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3.cs | 12 ++++++++++++ modules/mono/glue/GodotSharp/GodotSharp/Core/Vector4.cs | 12 ++++++++++++ 4 files changed, 39 insertions(+), 2 deletions(-) (limited to 'modules/mono') diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Mathf.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Mathf.cs index 3f9e986f62..cef31a7679 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Mathf.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Mathf.cs @@ -460,10 +460,11 @@ namespace Godot } /// - /// Returns if is approximately zero. + /// Returns if is zero or almost zero. /// The comparison is done using a tolerance calculation with . /// - /// This method is faster than using with one value as zero. + /// This method is faster than using with + /// one value as zero. /// /// The value to check. /// A for whether or not the value is nearly zero. diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2.cs index 4c60080ee9..0760f1668f 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2.cs @@ -988,6 +988,18 @@ namespace Godot return Mathf.IsEqualApprox(x, other.x) && Mathf.IsEqualApprox(y, other.y); } + /// + /// Returns if this vector's values are approximately zero, + /// by running on each component. + /// This method is faster than using with one value + /// as a zero vector. + /// + /// Whether or not the vector is approximately zero. + public readonly bool IsZeroApprox() + { + return Mathf.IsZeroApprox(x) && Mathf.IsZeroApprox(y); + } + /// /// Serves as the hash function for . /// diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3.cs index fefdee33a5..e000e3994d 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3.cs @@ -1059,6 +1059,18 @@ namespace Godot return Mathf.IsEqualApprox(x, other.x) && Mathf.IsEqualApprox(y, other.y) && Mathf.IsEqualApprox(z, other.z); } + /// + /// Returns if this vector's values are approximately zero, + /// by running on each component. + /// This method is faster than using with one value + /// as a zero vector. + /// + /// Whether or not the vector is approximately zero. + public readonly bool IsZeroApprox() + { + return Mathf.IsZeroApprox(x) && Mathf.IsZeroApprox(y) && Mathf.IsZeroApprox(z); + } + /// /// Serves as the hash function for . /// diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector4.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector4.cs index 3191e8adc0..dc2380c083 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector4.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector4.cs @@ -856,6 +856,18 @@ namespace Godot return Mathf.IsEqualApprox(x, other.x) && Mathf.IsEqualApprox(y, other.y) && Mathf.IsEqualApprox(z, other.z) && Mathf.IsEqualApprox(w, other.w); } + /// + /// Returns if this vector's values are approximately zero, + /// by running on each component. + /// This method is faster than using with one value + /// as a zero vector. + /// + /// Whether or not the vector is approximately zero. + public readonly bool IsZeroApprox() + { + return Mathf.IsZeroApprox(x) && Mathf.IsZeroApprox(y) && Mathf.IsZeroApprox(z) && Mathf.IsZeroApprox(w); + } + /// /// Serves as the hash function for . /// -- cgit v1.2.3