22 lines
950 B
C#
22 lines
950 B
C#
using Syntriax.Engine.Core;
|
|
|
|
namespace Syntriax.Engine.Physics2D.Primitives;
|
|
|
|
[System.Diagnostics.DebuggerDisplay("y = {Slope}x + {OffsetY}")]
|
|
public readonly struct LineEquation(float Slope, float OffsetY)
|
|
{
|
|
public readonly float Slope { get; init; } = Slope;
|
|
public readonly float OffsetY { get; init; } = OffsetY;
|
|
|
|
public static float Resolve(LineEquation lineEquation, float x) => lineEquation.Slope * x + lineEquation.OffsetY; // y = mx + b
|
|
|
|
public static bool ApproximatelyEquals(LineEquation left, LineEquation right)
|
|
=> left.Slope.ApproximatelyEquals(right.Slope) && left.OffsetY.ApproximatelyEquals(right.OffsetY);
|
|
}
|
|
|
|
public static class LineEquationExtensions
|
|
{
|
|
public static float Resolve(this LineEquation lineEquation, float x) => LineEquation.Resolve(lineEquation, x);
|
|
public static bool ApproximatelyEquals(this LineEquation left, LineEquation right) => LineEquation.ApproximatelyEquals(left, right);
|
|
}
|