From 5c185a664c61b35759143ad9921958f6d080c134 Mon Sep 17 00:00:00 2001 From: Syntriax Date: Tue, 23 Jan 2024 19:13:51 +0300 Subject: [PATCH] refactor: AABB --- Engine.Physics2D/Primitives/AABB.cs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/Engine.Physics2D/Primitives/AABB.cs b/Engine.Physics2D/Primitives/AABB.cs index 96e1560..5ffef2b 100644 --- a/Engine.Physics2D/Primitives/AABB.cs +++ b/Engine.Physics2D/Primitives/AABB.cs @@ -4,14 +4,11 @@ namespace Syntriax.Engine.Physics2D.Primitives; public record AABB(Vector2D LowerBoundary, Vector2D UpperBoundary) { - public bool Overlaps(Vector2D point) - => point.X >= LowerBoundary.X && point.X <= UpperBoundary.X && - point.Y >= LowerBoundary.Y && point.Y <= UpperBoundary.Y; - - public bool Overlaps(AABB other) - => LowerBoundary.X <= other.UpperBoundary.X && UpperBoundary.X >= other.LowerBoundary.X && - LowerBoundary.Y <= other.UpperBoundary.Y && UpperBoundary.Y >= other.LowerBoundary.Y; - - public bool ApproximatelyEquals(AABB other) - => LowerBoundary.ApproximatelyEquals(other.LowerBoundary) && UpperBoundary.ApproximatelyEquals(other.UpperBoundary); + public static bool ApproximatelyEquals(AABB left, AABB right) + => left.LowerBoundary.ApproximatelyEquals(right.LowerBoundary) && left.UpperBoundary.ApproximatelyEquals(right.UpperBoundary); +} + +public static class AABBExtensions +{ + public static bool ApproximatelyEquals(this AABB left, AABB right) => AABB.ApproximatelyEquals(left, right); }