From fea49658890f27ced33b47c2d3968d11864dae49 Mon Sep 17 00:00:00 2001 From: JonKazama-Hellion Date: Sun, 3 May 2026 21:56:39 +0200 Subject: [PATCH] fix(util): correct AABB overlap test in MathUtil.HasOverlap MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The previous implementation nested a ValueInRange helper that used strict inequalities at both ends. That dropped identical rectangles and shared-edge cases as false negatives — two rectangles with a.X == b.X would miss the overlap on the X axis even when they clearly overlapped. Replaced with the standard AABB test: rectangles overlap iff they overlap on both axes (a.Min < b.Max && a.Max > b.Min per axis). Pre-existing upstream issue (CodeRabbit critical finding); fixed in v1.0.0 standalone cut where we own the codebase. --- HellionChat/Util/MathUtil.cs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/HellionChat/Util/MathUtil.cs b/HellionChat/Util/MathUtil.cs index ab286ab..080fd28 100644 --- a/HellionChat/Util/MathUtil.cs +++ b/HellionChat/Util/MathUtil.cs @@ -31,7 +31,6 @@ public static class MathUtil => $"X: {X} Y: {Y} Width: {Width} Height: {Height}"; } - // From: https://stackoverflow.com/a/306379 /// /// Checks if two rectangles overlap at any point. /// @@ -40,12 +39,11 @@ public static class MathUtil /// True if overlapping public static bool HasOverlap(this Rectangle a, Rectangle b) { - bool ValueInRange(int value, int min, int max) - => value > min && value < max; - - var xOverlap = ValueInRange(a.X, b.X, b.X + b.Width) || ValueInRange(b.X, a.X, a.X + a.Width); - var yOverlap = ValueInRange(a.Y, b.Y, b.Y + b.Height) || ValueInRange(b.Y, a.Y, a.Y + a.Height); - - return xOverlap && yOverlap; + // Standard AABB overlap test: two rectangles overlap iff they + // overlap on both axes. The previous nested ValueInRange approach + // used strict inequalities at both ends, which dropped identical + // rectangles and shared-edge cases as false negatives. + return a.X < b.X + b.Width && a.X + a.Width > b.X && + a.Y < b.Y + b.Height && a.Y + a.Height > b.Y; } } \ No newline at end of file