feat: Missing Line Extension Methods

This commit is contained in:
Syntriax 2024-10-05 22:37:07 +03:00
parent 2bcd1c5a89
commit 923b25e26e
1 changed files with 34 additions and 0 deletions

View File

@ -202,6 +202,40 @@ public readonly struct Line(Vector2D from, Vector2D to)
/// </summary> /// </summary>
public static class LineExtensions public static class LineExtensions
{ {
/// <summary>
/// Linearly interpolates between the two endpoints of the <see cref="Line"/> segment using parameter 't'.
/// </summary>
public static Vector2D Lerp(this Line line, float t) => Line.Lerp(line, t);
/// <summary>
/// The equation of the <see cref="Line"/> defined by this <see cref="Line"/> segment.
/// </summary>
public static LineEquation ToLineEquation(this Line line) => Line.GetLineEquation(line);
/// <summary>
/// Determines whether the specified <see cref="Vector2D"/> lies on the <see cref="Line"/>.
/// </summary>
public static bool Intersects(this Line line, Vector2D point) => Line.Intersects(line, point);
/// <summary>
/// Calculates the parameter 't' representing the point's position on the <see cref="Line"/> segment.
/// </summary>
public static float GetT(this Line line, Vector2D point) => Line.GetT(line, point);
/// <summary>
/// Checks if the <see cref="Line"/> segment intersects with another <see cref="Line"/> segment.
/// </summary>
public static bool Intersects(this Line left, Line right) => Line.Intersects(left, right);
/// <summary>
/// Determines whether two <see cref="Line"/> segments intersect.
/// </summary>
public static bool Intersects(this Line left, Line right, [NotNullWhen(returnValue: true)] out Vector2D? point) => Line.Intersects(left, right, out point);
/// <summary> /// <summary>
/// Checks if two <see cref="Line"/>s are approximately equal. /// Checks if two <see cref="Line"/>s are approximately equal.
/// </summary> /// </summary>