using Syntriax.Engine.Core; namespace Syntriax.Engine.Physics2D.Primitives; /// /// Represents a line equation in the form y = mx + b. /// /// The slope of the line. /// The y-intercept of the line. /// /// Initializes a new instance of the struct with the specified slope and y-intercept. /// [System.Diagnostics.DebuggerDisplay("y = {Slope}x + {OffsetY}")] public readonly struct LineEquation(float slope, float offsetY) { /// /// The slope of the line equation. /// public readonly float Slope = slope; /// /// The y-intercept of the line equation. /// public readonly float OffsetY = offsetY; /// /// Resolves the y-coordinate for a given x-coordinate using the line equation. /// /// The line equation to resolve. /// The x-coordinate for which to resolve the y-coordinate. /// The y-coordinate resolved using the line equation. public static float Resolve(LineEquation lineEquation, float x) => lineEquation.Slope * x + lineEquation.OffsetY; // y = mx + b /// /// Checks if two line equations are approximately equal. /// /// The first line equation to compare. /// The second line equation to compare. /// True if the line equations are approximately equal; otherwise, false. public static bool ApproximatelyEquals(LineEquation left, LineEquation right) => left.Slope.ApproximatelyEquals(right.Slope) && left.OffsetY.ApproximatelyEquals(right.OffsetY); } /// /// Provides extension methods for the LineEquation struct. /// public static class LineEquationExtensions { /// /// Resolves the y-coordinate for a given x-coordinate using the line equation. /// /// The line equation to resolve. /// The x-coordinate for which to resolve the y-coordinate. /// The y-coordinate resolved using the line equation. public static float Resolve(this LineEquation lineEquation, float x) => LineEquation.Resolve(lineEquation, x); /// /// Checks if two line equations are approximately equal. /// /// The first line equation to compare. /// The second line equation to compare. /// True if the line equations are approximately equal; otherwise, false. public static bool ApproximatelyEquals(this LineEquation left, LineEquation right) => LineEquation.ApproximatelyEquals(left, right); }