From cbb74f539dbe60a579ebf6e9990e9b7234cba9c7 Mon Sep 17 00:00:00 2001 From: Juhani Haapala Date: Wed, 15 Nov 2023 13:36:27 +0200 Subject: [PATCH 1/2] Fix rounding issue in intersection calculation --- src/Handlers/IntersectionHandler.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Handlers/IntersectionHandler.php b/src/Handlers/IntersectionHandler.php index 134154f..4b7df29 100644 --- a/src/Handlers/IntersectionHandler.php +++ b/src/Handlers/IntersectionHandler.php @@ -41,10 +41,10 @@ private static function isRectangleIntersected(Item $firstItem, Item $secondItem $secondCx = $secondItem->getPosition()[$xAxis] + $secondDimension[$xAxis] / 2; $secondCy = $secondItem->getPosition()[$yAxis] + $secondDimension[$yAxis] / 2; - $ix = max($firstCx, $secondCx) - min($firstCx, $secondCx); - $iy = max($firstCy, $secondCy) - min($firstCy, $secondCy); + $ix = round(max($firstCx, $secondCx) - min($firstCx, $secondCx)); + $iy = round(max($firstCy, $secondCy) - min($firstCy, $secondCy)); - return $ix < ($firstDimension[$xAxis] + $secondDimension[$xAxis]) / 2 && $iy < ($firstDimension[$yAxis] + $secondDimension[$yAxis]) / 2; + return $ix < round(($firstDimension[$xAxis] + $secondDimension[$xAxis]) / 2) && $iy < ($firstDimension[$yAxis] + $secondDimension[$yAxis]) / 2; } /** From fe012cddbb0fce5854a15b25c5aae75fb3e97b6e Mon Sep 17 00:00:00 2001 From: Juhani Haapala Date: Wed, 15 Nov 2023 13:47:16 +0200 Subject: [PATCH 2/2] And rounding also to $iy calculation --- src/Handlers/IntersectionHandler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Handlers/IntersectionHandler.php b/src/Handlers/IntersectionHandler.php index 4b7df29..8c18cd0 100644 --- a/src/Handlers/IntersectionHandler.php +++ b/src/Handlers/IntersectionHandler.php @@ -44,7 +44,7 @@ private static function isRectangleIntersected(Item $firstItem, Item $secondItem $ix = round(max($firstCx, $secondCx) - min($firstCx, $secondCx)); $iy = round(max($firstCy, $secondCy) - min($firstCy, $secondCy)); - return $ix < round(($firstDimension[$xAxis] + $secondDimension[$xAxis]) / 2) && $iy < ($firstDimension[$yAxis] + $secondDimension[$yAxis]) / 2; + return $ix < round(($firstDimension[$xAxis] + $secondDimension[$xAxis]) / 2) && $iy < round(($firstDimension[$yAxis] + $secondDimension[$yAxis]) / 2); } /**