Syntriax.Engine/Engine.Physics2D/Primitives/LineEquation.cs

22 lines
950 B
C#
Raw Normal View History

2024-01-24 12:42:18 +03:00
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;
2024-01-23 19:16:31 +03:00
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);
}