feat: line 2D to line 2D equation implicit operator added

This commit is contained in:
2025-10-18 14:43:00 +03:00
parent dbd15cbbc2
commit ab05a89175
2 changed files with 11 additions and 9 deletions

View File

@@ -50,15 +50,7 @@ public readonly struct Line2D(Vector2D from, Vector2D to) : IEquatable<Line2D>
/// <summary>
/// The equation of the <see cref="Line2D"/> defined by this <see cref="Line2D"/> segment.
/// </summary>
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;
/// <summary>
/// Determines whether the specified <see cref="Vector2D"/> lies on the <see cref="Line2D"/>.

View File

@@ -26,6 +26,16 @@ public readonly struct Line2DEquation(float slope, float offsetY) : IEquatable<L
public static bool operator ==(Line2DEquation left, Line2DEquation right) => 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);
}
/// <summary>
/// Resolves the Y coordinate for a given X coordinate using the <see cref="Line2DEquation"/>.
/// </summary>