Merge pull request #71343 from raulsntos/dotnet/is_zero_approx

Add `IsZeroApprox` to C# vectors
This commit is contained in:
Yuri Sizov 2023-01-13 23:31:24 +03:00 committed by GitHub
commit bdb3543c2a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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>