Browse Source

Merge pull request #71343 from raulsntos/dotnet/is_zero_approx

Add `IsZeroApprox` to C# vectors
Yuri Sizov 2 years ago
parent
commit
bdb3543c2a

+ 1 - 1
doc/classes/@GlobalScope.xml

@@ -529,7 +529,7 @@
 			<return type="bool" />
 			<param index="0" name="x" type="float" />
 			<description>
-				Returns [code]true[/code] if [param x] is zero or almost zero.
+				Returns [code]true[/code] if [param x] is zero or almost zero. The comparison is done using a tolerance calculation with a small internal epsilon.
 				This function is faster than using [method is_equal_approx] with one value as zero.
 			</description>
 		</method>

+ 3 - 2
modules/mono/glue/GodotSharp/GodotSharp/Core/Mathf.cs

@@ -460,10 +460,11 @@ namespace Godot
         }
 
         /// <summary>
-        /// Returns <see langword="true"/> if <paramref name="s"/> is approximately zero.
+        /// Returns <see langword="true"/> if <paramref name="s"/> is zero or almost zero.
         /// The comparison is done using a tolerance calculation with <see cref="Epsilon"/>.
         ///
-        /// This method is faster than using <see cref="IsEqualApprox(real_t, real_t)"/> with one value as zero.
+        /// This method is faster than using <see cref="IsEqualApprox(real_t, real_t)"/> with
+        /// one value as zero.
         /// </summary>
         /// <param name="s">The value to check.</param>
         /// <returns>A <see langword="bool"/> for whether or not the value is nearly zero.</returns>

+ 12 - 0
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);
         }
 
+        /// <summary>
+        /// Returns <see langword="true"/> if this vector's values are approximately zero,
+        /// by running <see cref="Mathf.IsZeroApprox(real_t)"/> on each component.
+        /// This method is faster than using <see cref="IsEqualApprox"/> with one value
+        /// as a zero vector.
+        /// </summary>
+        /// <returns>Whether or not the vector is approximately zero.</returns>
+        public readonly bool IsZeroApprox()
+        {
+            return Mathf.IsZeroApprox(x) && Mathf.IsZeroApprox(y);
+        }
+
         /// <summary>
         /// Serves as the hash function for <see cref="Vector2"/>.
         /// </summary>

+ 12 - 0
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);
         }
 
+        /// <summary>
+        /// Returns <see langword="true"/> if this vector's values are approximately zero,
+        /// by running <see cref="Mathf.IsZeroApprox(real_t)"/> on each component.
+        /// This method is faster than using <see cref="IsEqualApprox"/> with one value
+        /// as a zero vector.
+        /// </summary>
+        /// <returns>Whether or not the vector is approximately zero.</returns>
+        public readonly bool IsZeroApprox()
+        {
+            return Mathf.IsZeroApprox(x) && Mathf.IsZeroApprox(y) && Mathf.IsZeroApprox(z);
+        }
+
         /// <summary>
         /// Serves as the hash function for <see cref="Vector3"/>.
         /// </summary>

+ 12 - 0
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);
         }
 
+        /// <summary>
+        /// Returns <see langword="true"/> if this vector's values are approximately zero,
+        /// by running <see cref="Mathf.IsZeroApprox(real_t)"/> on each component.
+        /// This method is faster than using <see cref="IsEqualApprox"/> with one value
+        /// as a zero vector.
+        /// </summary>
+        /// <returns>Whether or not the vector is approximately zero.</returns>
+        public readonly bool IsZeroApprox()
+        {
+            return Mathf.IsZeroApprox(x) && Mathf.IsZeroApprox(y) && Mathf.IsZeroApprox(z) && Mathf.IsZeroApprox(w);
+        }
+
         /// <summary>
         /// Serves as the hash function for <see cref="Vector4"/>.
         /// </summary>