refactor: LineEquation

This commit is contained in:
Syntriax 2024-01-23 19:16:31 +03:00
parent 6a5d10980a
commit 3b299c947c
1 changed files with 10 additions and 3 deletions

View File

@ -2,7 +2,14 @@ namespace Syntriax.Engine.Physics2D.Primitives;
public record LineEquation(float Slope, float OffsetY) public record LineEquation(float Slope, float OffsetY)
{ {
public float Resolve(float x) => Slope * x + OffsetY; // y = mx + b public static float Resolve(LineEquation lineEquation, float x) => lineEquation.Slope * x + lineEquation.OffsetY; // y = mx + b
public bool ApproximatelyEquals(LineEquation other)
=> Slope.ApproximatelyEquals(other.Slope) && OffsetY.ApproximatelyEquals(other.OffsetY); 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);
} }