feat: added approximately equals methods to projection 1D and ray 2D

This commit is contained in:
Syntriax 2025-06-27 11:44:52 +03:00
parent 0c096d39db
commit fa1614f238
2 changed files with 26 additions and 0 deletions

View File

@ -71,6 +71,16 @@ public readonly struct Projection1D(float min, float max)
return false;
}
/// <summary>
/// Checks if two <see cref="Projection1D"/>s are approximately equal within a specified epsilon range.
/// </summary>
/// <param name="left">The first <see cref="Projection1D"/>.</param>
/// <param name="right">The second <see cref="Projection1D"/>.</param>
/// <param name="epsilon">The epsilon range.</param>
/// <returns><see cref="true"/> if the <see cref="Projection1D"/>s are approximately equal; otherwise, <see cref="false"/>.</returns>
public static bool ApproximatelyEquals(Projection1D left, Projection1D right, float epsilon = float.Epsilon)
=> left.Min.ApproximatelyEquals(right.Min, epsilon) && left.Max.ApproximatelyEquals(right.Max, epsilon);
/// <summary>
/// Determines whether the specified object is equal to the current <see cref="Projection1D"/>.
/// </summary>
@ -101,4 +111,7 @@ public static class Projection1DExtensions
/// <inheritdoc cref="Projection1D.Overlaps(Projection1D, Projection1D, out float)" />
public static bool Overlaps(this Projection1D left, Projection1D right, out float depth) => Projection1D.Overlaps(left, right, out depth);
/// <inheritdoc cref="Projection1D.ApproximatelyEquals(Projection1D, Projection1D, float)" />
public static bool ApproximatelyEquals(this Projection1D left, Projection1D right, float epsilon = float.Epsilon) => Projection1D.ApproximatelyEquals(left, right, epsilon);
}

View File

@ -56,6 +56,16 @@ public readonly struct Ray2D(Vector2D Origin, Vector2D Direction)
return ray.Origin + ray.Direction * dot;
}
/// <summary>
/// Checks if two <see cref="Ray2D"/>s are approximately equal within a specified epsilon range.
/// </summary>
/// <param name="left">The first <see cref="Ray2D"/>.</param>
/// <param name="right">The second <see cref="Ray2D"/>.</param>
/// <param name="epsilon">The epsilon range.</param>
/// <returns><see cref="true"/> if the <see cref="Ray2D"/>s are approximately equal; otherwise, <see cref="false"/>.</returns>
public static bool ApproximatelyEquals(Ray2D left, Ray2D right, float epsilon = float.Epsilon)
=> left.Origin.ApproximatelyEquals(right.Origin, epsilon) && left.Direction.ApproximatelyEquals(right.Direction, epsilon);
/// <summary>
/// Determines whether the specified object is equal to the current <see cref="Ray2D"/>.
/// </summary>
@ -89,4 +99,7 @@ public static class Ray2DExtensions
/// <inheritdoc cref="Ray2D.ClosestPointTo(Ray2D, Vector2D) />
public static Vector2D ClosestPointTo(this Ray2D ray, Vector2D point) => Ray2D.ClosestPointTo(ray, point);
/// <inheritdoc cref="Ray2D.ApproximatelyEquals(Ray2D, Ray2D, float)" />
public static bool ApproximatelyEquals(this Ray2D left, Ray2D right, float epsilon = float.Epsilon) => Ray2D.ApproximatelyEquals(left, right, epsilon);
}