Browse Source

Add `IsFinite` to C# Variants

Raul Santos 2 years ago
parent
commit
f852004cf5

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

@@ -494,7 +494,7 @@
 			<return type="bool" />
 			<param index="0" name="x" type="float" />
 			<description>
-				Returns whether [code]x[/code] is a finite value, i.e. it is not [constant @GDScript.NAN], positive infinity, or negative infinity.
+				Returns whether [param x] is a finite value, i.e. it is not [constant @GDScript.NAN], positive infinity, or negative infinity.
 			</description>
 		</method>
 		<method name="is_inf">

+ 10 - 0
modules/mono/glue/GodotSharp/GodotSharp/Core/AABB.cs

@@ -585,6 +585,16 @@ namespace Godot
             return true;
         }
 
+        /// <summary>
+        /// Returns <see langword="true"/> if this <see cref="AABB"/> is finite, by calling
+        /// <see cref="Mathf.IsFinite"/> on each component.
+        /// </summary>
+        /// <returns>Whether this vector is finite or not.</returns>
+        public readonly bool IsFinite()
+        {
+            return _position.IsFinite() && _size.IsFinite();
+        }
+
         /// <summary>
         /// Returns a larger <see cref="AABB"/> that contains this <see cref="AABB"/> and <paramref name="with"/>.
         /// </summary>

+ 10 - 0
modules/mono/glue/GodotSharp/GodotSharp/Core/Basis.cs

@@ -709,6 +709,16 @@ namespace Godot
             );
         }
 
+        /// <summary>
+        /// Returns <see langword="true"/> if this basis is finite, by calling
+        /// <see cref="Mathf.IsFinite"/> on each component.
+        /// </summary>
+        /// <returns>Whether this vector is finite or not.</returns>
+        public readonly bool IsFinite()
+        {
+            return Row0.IsFinite() && Row1.IsFinite() && Row2.IsFinite();
+        }
+
         internal readonly Basis Lerp(Basis to, real_t weight)
         {
             Basis b = this;

+ 11 - 0
modules/mono/glue/GodotSharp/GodotSharp/Core/Mathf.cs

@@ -439,6 +439,17 @@ namespace Godot
             return Abs(a - b) < tolerance;
         }
 
+        /// <summary>
+        /// Returns whether <paramref name="s"/> is a finite value, i.e. it is not
+        /// <see cref="NaN"/>, positive infinite, or negative infinity.
+        /// </summary>
+        /// <param name="s">The value to check.</param>
+        /// <returns>A <see langword="bool"/> for whether or not the value is a finite value.</returns>
+        public static bool IsFinite(real_t s)
+        {
+            return real_t.IsFinite(s);
+        }
+
         /// <summary>
         /// Returns whether <paramref name="s"/> is an infinity value (either positive infinity or negative infinity).
         /// </summary>

+ 10 - 0
modules/mono/glue/GodotSharp/GodotSharp/Core/Plane.cs

@@ -204,6 +204,16 @@ namespace Godot
             return begin - (segment * dist);
         }
 
+        /// <summary>
+        /// Returns <see langword="true"/> if this plane is finite, by calling
+        /// <see cref="Mathf.IsFinite"/> on each component.
+        /// </summary>
+        /// <returns>Whether this vector is finite or not.</returns>
+        public readonly bool IsFinite()
+        {
+            return _normal.IsFinite() && Mathf.IsFinite(D);
+        }
+
         /// <summary>
         /// Returns <see langword="true"/> if <paramref name="point"/> is located above the plane.
         /// </summary>

+ 10 - 0
modules/mono/glue/GodotSharp/GodotSharp/Core/Quaternion.cs

@@ -339,6 +339,16 @@ namespace Godot
             return new Quaternion(-x, -y, -z, w);
         }
 
+        /// <summary>
+        /// Returns <see langword="true"/> if this quaternion is finite, by calling
+        /// <see cref="Mathf.IsFinite"/> on each component.
+        /// </summary>
+        /// <returns>Whether this vector is finite or not.</returns>
+        public readonly bool IsFinite()
+        {
+            return Mathf.IsFinite(x) && Mathf.IsFinite(y) && Mathf.IsFinite(z) && Mathf.IsFinite(w);
+        }
+
         /// <summary>
         /// Returns whether the quaternion is normalized or not.
         /// </summary>

+ 10 - 0
modules/mono/glue/GodotSharp/GodotSharp/Core/Rect2.cs

@@ -100,6 +100,16 @@ namespace Godot
             return newRect;
         }
 
+        /// <summary>
+        /// Returns <see langword="true"/> if this <see cref="Rect2"/> is finite, by calling
+        /// <see cref="Mathf.IsFinite"/> on each component.
+        /// </summary>
+        /// <returns>Whether this vector is finite or not.</returns>
+        public bool IsFinite()
+        {
+            return _position.IsFinite() && _size.IsFinite();
+        }
+
         /// <summary>
         /// Returns <see langword="true"/> if this <see cref="Rect2"/> completely encloses another one.
         /// </summary>

+ 10 - 0
modules/mono/glue/GodotSharp/GodotSharp/Core/Transform2D.cs

@@ -270,6 +270,16 @@ namespace Godot
             return inv;
         }
 
+        /// <summary>
+        /// Returns <see langword="true"/> if this transform is finite, by calling
+        /// <see cref="Mathf.IsFinite"/> on each component.
+        /// </summary>
+        /// <returns>Whether this vector is finite or not.</returns>
+        public readonly bool IsFinite()
+        {
+            return x.IsFinite() && y.IsFinite() && origin.IsFinite();
+        }
+
         /// <summary>
         /// Returns the transform with the basis orthogonal (90 degrees),
         /// and normalized axis vectors (scale of 1 or -1).

+ 10 - 0
modules/mono/glue/GodotSharp/GodotSharp/Core/Transform3D.cs

@@ -139,6 +139,16 @@ namespace Godot
             return new Transform3D(basisTr, basisTr * -origin);
         }
 
+        /// <summary>
+        /// Returns <see langword="true"/> if this transform is finite, by calling
+        /// <see cref="Mathf.IsFinite"/> on each component.
+        /// </summary>
+        /// <returns>Whether this vector is finite or not.</returns>
+        public readonly bool IsFinite()
+        {
+            return basis.IsFinite() && origin.IsFinite();
+        }
+
         /// <summary>
         /// Returns a copy of the transform rotated such that its
         /// -Z axis (forward) points towards the <paramref name="target"/> position.

+ 10 - 0
modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2.cs

@@ -333,6 +333,16 @@ namespace Godot
             return new Vector2(1 / x, 1 / y);
         }
 
+        /// <summary>
+        /// Returns <see langword="true"/> if this vector is finite, by calling
+        /// <see cref="Mathf.IsFinite"/> on each component.
+        /// </summary>
+        /// <returns>Whether this vector is finite or not.</returns>
+        public readonly bool IsFinite()
+        {
+            return Mathf.IsFinite(x) && Mathf.IsFinite(y);
+        }
+
         /// <summary>
         /// Returns <see langword="true"/> if the vector is normalized, and <see langword="false"/> otherwise.
         /// </summary>

+ 10 - 0
modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3.cs

@@ -330,6 +330,16 @@ namespace Godot
             return new Vector3(1 / x, 1 / y, 1 / z);
         }
 
+        /// <summary>
+        /// Returns <see langword="true"/> if this vector is finite, by calling
+        /// <see cref="Mathf.IsFinite"/> on each component.
+        /// </summary>
+        /// <returns>Whether this vector is finite or not.</returns>
+        public readonly bool IsFinite()
+        {
+            return Mathf.IsFinite(x) && Mathf.IsFinite(y) && Mathf.IsFinite(z);
+        }
+
         /// <summary>
         /// Returns <see langword="true"/> if the vector is normalized, and <see langword="false"/> otherwise.
         /// </summary>

+ 10 - 0
modules/mono/glue/GodotSharp/GodotSharp/Core/Vector4.cs

@@ -279,6 +279,16 @@ namespace Godot
             return new Vector4(1 / x, 1 / y, 1 / z, 1 / w);
         }
 
+        /// <summary>
+        /// Returns <see langword="true"/> if this vector is finite, by calling
+        /// <see cref="Mathf.IsFinite"/> on each component.
+        /// </summary>
+        /// <returns>Whether this vector is finite or not.</returns>
+        public readonly bool IsFinite()
+        {
+            return Mathf.IsFinite(x) && Mathf.IsFinite(y) && Mathf.IsFinite(z) && Mathf.IsFinite(w);
+        }
+
         /// <summary>
         /// Returns <see langword="true"/> if the vector is normalized, and <see langword="false"/> otherwise.
         /// </summary>