From 923b25e26e6d4695d4da4e70a90c7fd15a7231fb Mon Sep 17 00:00:00 2001 From: Syntriax Date: Sat, 5 Oct 2024 22:37:07 +0300 Subject: [PATCH] feat: Missing Line Extension Methods --- Engine.Physics2D/Primitives/Line.cs | 34 +++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/Engine.Physics2D/Primitives/Line.cs b/Engine.Physics2D/Primitives/Line.cs index 10d5df7..61558d2 100644 --- a/Engine.Physics2D/Primitives/Line.cs +++ b/Engine.Physics2D/Primitives/Line.cs @@ -202,6 +202,40 @@ public readonly struct Line(Vector2D from, Vector2D to) /// public static class LineExtensions { + /// + /// Linearly interpolates between the two endpoints of the segment using parameter 't'. + /// + public static Vector2D Lerp(this Line line, float t) => Line.Lerp(line, t); + + + /// + /// The equation of the defined by this segment. + /// + public static LineEquation ToLineEquation(this Line line) => Line.GetLineEquation(line); + + + /// + /// Determines whether the specified lies on the . + /// + public static bool Intersects(this Line line, Vector2D point) => Line.Intersects(line, point); + + /// + /// Calculates the parameter 't' representing the point's position on the segment. + /// + public static float GetT(this Line line, Vector2D point) => Line.GetT(line, point); + + + /// + /// Checks if the segment intersects with another segment. + /// + public static bool Intersects(this Line left, Line right) => Line.Intersects(left, right); + + + /// + /// Determines whether two segments intersect. + /// + public static bool Intersects(this Line left, Line right, [NotNullWhen(returnValue: true)] out Vector2D? point) => Line.Intersects(left, right, out point); + /// /// Checks if two s are approximately equal. ///