diff --git a/Engine.Core/Primitives/AABB.cs b/Engine.Core/Primitives/AABB.cs index cbf60a5..7e6e3c8 100644 --- a/Engine.Core/Primitives/AABB.cs +++ b/Engine.Core/Primitives/AABB.cs @@ -75,8 +75,8 @@ public readonly struct AABB(Vector2D lowerBoundary, Vector2D upperBoundary) /// The first . /// The second . /// if the s are approximately equal; otherwise, . - public static bool ApproximatelyEquals(AABB left, AABB right) - => left.LowerBoundary.ApproximatelyEquals(right.LowerBoundary) && left.UpperBoundary.ApproximatelyEquals(right.UpperBoundary); + public static bool ApproximatelyEquals(AABB left, AABB right, float epsilon = float.Epsilon) + => left.LowerBoundary.ApproximatelyEquals(right.LowerBoundary, epsilon) && left.UpperBoundary.ApproximatelyEquals(right.UpperBoundary, epsilon); } /// @@ -91,11 +91,5 @@ public static class AABBExtensions /// An that bounds all the s. public static AABB ToAABB(this IEnumerable vectors) => AABB.FromVectors(vectors); - /// - /// Checks if two s are approximately equal. - /// - /// The first . - /// The second . - /// if the s are approximately equal; otherwise, . - public static bool ApproximatelyEquals(this AABB left, AABB right) => AABB.ApproximatelyEquals(left, right); + public static bool ApproximatelyEquals(this AABB left, AABB right, float epsilon = float.Epsilon) => AABB.ApproximatelyEquals(left, right, epsilon); } diff --git a/Engine.Core/Primitives/Circle.cs b/Engine.Core/Primitives/Circle.cs index 1833a65..780fd64 100644 --- a/Engine.Core/Primitives/Circle.cs +++ b/Engine.Core/Primitives/Circle.cs @@ -72,8 +72,8 @@ public readonly struct Circle(Vector2D center, float radius) /// /// Checks if two s are approximately equal. /// - public static bool ApproximatelyEquals(Circle left, Circle right) - => left.Center.ApproximatelyEquals(right.Center) && left.Radius.ApproximatelyEquals(right.Radius); + public static bool ApproximatelyEquals(Circle left, Circle right, float epsilon = float.Epsilon) + => left.Center.ApproximatelyEquals(right.Center, epsilon) && left.Radius.ApproximatelyEquals(right.Radius, epsilon); } /// @@ -106,8 +106,5 @@ public static class CircleExtensions /// public static Circle TransformCircle(this ITransform transform, Circle circle) => Circle.TransformCircle(transform, circle); - /// - /// Checks if two s are approximately equal. - /// - public static bool ApproximatelyEquals(this Circle left, Circle right) => Circle.ApproximatelyEquals(left, right); + public static bool ApproximatelyEquals(this Circle left, Circle right, float epsilon = float.Epsilon) => Circle.ApproximatelyEquals(left, right, epsilon); } diff --git a/Engine.Core/Primitives/Line2D.cs b/Engine.Core/Primitives/Line2D.cs index 0a11de2..d2b776c 100644 --- a/Engine.Core/Primitives/Line2D.cs +++ b/Engine.Core/Primitives/Line2D.cs @@ -184,8 +184,8 @@ public readonly struct Line2D(Vector2D from, Vector2D to) /// /// Checks if two segments are approximately equal. /// - public static bool ApproximatelyEquals(Line2D left, Line2D right) - => left.From.ApproximatelyEquals(right.From) && left.To.ApproximatelyEquals(right.To); + public static bool ApproximatelyEquals(Line2D left, Line2D right, float epsilon = float.Epsilon) + => left.From.ApproximatelyEquals(right.From, epsilon) && left.To.ApproximatelyEquals(right.To, epsilon); } /// @@ -223,8 +223,5 @@ public static class Line2DExtensions /// public static bool Intersects(this Line2D left, Line2D right, [NotNullWhen(returnValue: true)] out Vector2D? point) => Line2D.Intersects(left, right, out point); - /// - /// Checks if two s are approximately equal. - /// - public static bool ApproximatelyEquals(this Line2D left, Line2D right) => Line2D.ApproximatelyEquals(left, right); + public static bool ApproximatelyEquals(this Line2D left, Line2D right, float epsilon = float.Epsilon) => Line2D.ApproximatelyEquals(left, right, epsilon); } diff --git a/Engine.Core/Primitives/Line2DEquation.cs b/Engine.Core/Primitives/Line2DEquation.cs index 20d33ab..24479e3 100644 --- a/Engine.Core/Primitives/Line2DEquation.cs +++ b/Engine.Core/Primitives/Line2DEquation.cs @@ -34,9 +34,10 @@ public readonly struct Line2DEquation(float slope, float offsetY) /// /// The first line equation to compare. /// The second line equation to compare. + /// The epsilon range. /// True if the line equations are approximately equal; otherwise, false. - public static bool ApproximatelyEquals(Line2DEquation left, Line2DEquation right) - => left.Slope.ApproximatelyEquals(right.Slope) && left.OffsetY.ApproximatelyEquals(right.OffsetY); + public static bool ApproximatelyEquals(Line2DEquation left, Line2DEquation right, float epsilon = float.Epsilon) + => left.Slope.ApproximatelyEquals(right.Slope, epsilon) && left.OffsetY.ApproximatelyEquals(right.OffsetY, epsilon); } /// @@ -52,11 +53,5 @@ public static class Line2DEquationExtensions /// The y-coordinate resolved using the line equation. public static float Resolve(this Line2DEquation lineEquation, float x) => Line2DEquation.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 Line2DEquation left, Line2DEquation right) => Line2DEquation.ApproximatelyEquals(left, right); + public static bool ApproximatelyEquals(this Line2DEquation left, Line2DEquation right, float epsilon = float.Epsilon) => Line2DEquation.ApproximatelyEquals(left, right, epsilon); } diff --git a/Engine.Core/Primitives/Shape2D.cs b/Engine.Core/Primitives/Shape2D.cs index 95d94df..a2c5433 100644 --- a/Engine.Core/Primitives/Shape2D.cs +++ b/Engine.Core/Primitives/Shape2D.cs @@ -198,13 +198,13 @@ public readonly struct Shape2D(List vertices) : IEnumerable /// The first shape to compare. /// The second shape to compare. /// true if the shapes are approximately equal; otherwise, false. - public static bool ApproximatelyEquals(Shape2D left, Shape2D right) + public static bool ApproximatelyEquals(Shape2D left, Shape2D right, float epsilon = float.Epsilon) { if (left.Vertices.Count != right.Vertices.Count) return false; for (int i = 0; i < left.Vertices.Count; i++) - if (!left.Vertices[i].ApproximatelyEquals(right.Vertices[i])) + if (!left.Vertices[i].ApproximatelyEquals(right.Vertices[i], epsilon)) return false; return true; @@ -282,11 +282,5 @@ public static class Shape2DExtensions /// The transformed shape. public static void TransformShape(this ITransform transform, Shape2D from, ref Shape2D to) => Shape2D.TransformShape(from, transform, ref to); - /// - /// Determines whether two shapes are approximately equal. - /// - /// The first shape to compare. - /// The second shape to compare. - /// true if the shapes are approximately equal; otherwise, false. - public static bool ApproximatelyEquals(this Shape2D left, Shape2D right) => Shape2D.ApproximatelyEquals(left, right); + public static bool ApproximatelyEquals(this Shape2D left, Shape2D right, float epsilon = float.Epsilon) => Shape2D.ApproximatelyEquals(left, right, epsilon); } diff --git a/Engine.Core/Primitives/Triangle.cs b/Engine.Core/Primitives/Triangle.cs index 8e3ce88..1dfbf2f 100644 --- a/Engine.Core/Primitives/Triangle.cs +++ b/Engine.Core/Primitives/Triangle.cs @@ -37,11 +37,11 @@ public readonly struct Triangle(Vector2D A, Vector2D B, Vector2D C) return new(center, Vector2D.Distance(center, triangle.A)); } - public static bool ApproximatelyEquals(Triangle left, Triangle right) - => left.A.ApproximatelyEquals(right.A) && left.B.ApproximatelyEquals(right.B) && left.C.ApproximatelyEquals(right.C); + public static bool ApproximatelyEquals(Triangle left, Triangle right, float epsilon = float.Epsilon) + => left.A.ApproximatelyEquals(right.A, epsilon) && left.B.ApproximatelyEquals(right.B, epsilon) && left.C.ApproximatelyEquals(right.C, epsilon); } public static class TriangleExtensions { - public static bool ApproximatelyEquals(this Triangle left, Triangle right) => Triangle.ApproximatelyEquals(left, right); + public static bool ApproximatelyEquals(this Triangle left, Triangle right, float epsilon = float.Epsilon) => Triangle.ApproximatelyEquals(left, right, epsilon); }