Add IsZeroApprox to C# vectors

This commit is contained in:
Raul Santos 2023-01-13 18:49:13 +01:00
parent 3c9bf4bc21
commit 14c16746f3
No known key found for this signature in database
GPG Key ID: B532473AE3A803E4
5 changed files with 40 additions and 3 deletions

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>