From ab05a891754bdf1ad56e63074607885afe71e9ad Mon Sep 17 00:00:00 2001 From: Syntriax Date: Sat, 18 Oct 2025 14:43:00 +0300 Subject: [PATCH] feat: line 2D to line 2D equation implicit operator added --- Engine.Core/Primitives/Line2D.cs | 10 +--------- Engine.Core/Primitives/Line2DEquation.cs | 10 ++++++++++ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/Engine.Core/Primitives/Line2D.cs b/Engine.Core/Primitives/Line2D.cs index 753027b..0bfe645 100644 --- a/Engine.Core/Primitives/Line2D.cs +++ b/Engine.Core/Primitives/Line2D.cs @@ -50,15 +50,7 @@ public readonly struct Line2D(Vector2D from, Vector2D to) : IEquatable /// /// The equation of the defined by this segment. /// - public static Line2DEquation GetLineEquation(Line2D line) - { - Vector2D slopeVector = line.From.FromTo(line.To); - float slope = slopeVector.Y / slopeVector.X; - - float yOffset = line.From.Y - (slope * line.From.X); - - return new Line2DEquation(slope, yOffset); - } + public static Line2DEquation GetLineEquation(Line2D line) => line; /// /// Determines whether the specified lies on the . diff --git a/Engine.Core/Primitives/Line2DEquation.cs b/Engine.Core/Primitives/Line2DEquation.cs index fc06e2a..02dc492 100644 --- a/Engine.Core/Primitives/Line2DEquation.cs +++ b/Engine.Core/Primitives/Line2DEquation.cs @@ -26,6 +26,16 @@ public readonly struct Line2DEquation(float slope, float offsetY) : IEquatable left.Slope == right.Slope && left.OffsetY == right.OffsetY; public static bool operator !=(Line2DEquation left, Line2DEquation right) => left.Slope != right.Slope || left.OffsetY != right.OffsetY; + public static implicit operator Line2DEquation(Line2D line) + { + Vector2D slopeVector = line.From.FromTo(line.To); + float slope = slopeVector.Y / slopeVector.X; + + float yOffset = line.From.Y - (slope * line.From.X); + + return new Line2DEquation(slope, yOffset); + } + /// /// Resolves the Y coordinate for a given X coordinate using the . ///