feat: line 2D to line 2D equation implicit operator added
This commit is contained in:
@@ -50,15 +50,7 @@ public readonly struct Line2D(Vector2D from, Vector2D to) : IEquatable<Line2D>
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The equation of the <see cref="Line2D"/> defined by this <see cref="Line2D"/> segment.
|
/// The equation of the <see cref="Line2D"/> defined by this <see cref="Line2D"/> segment.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static Line2DEquation GetLineEquation(Line2D line)
|
public static Line2DEquation GetLineEquation(Line2D line) => 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>
|
/// <summary>
|
||||||
/// Determines whether the specified <see cref="Vector2D"/> lies on the <see cref="Line2D"/>.
|
/// Determines whether the specified <see cref="Vector2D"/> lies on the <see cref="Line2D"/>.
|
||||||
|
@@ -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 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>
|
/// <summary>
|
||||||
/// Resolves the Y coordinate for a given X coordinate using the <see cref="Line2DEquation"/>.
|
/// Resolves the Y coordinate for a given X coordinate using the <see cref="Line2DEquation"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
Reference in New Issue
Block a user