From 7ef2a823bd35b010d5e3dfa0ef0f66a51bbfa2bd Mon Sep 17 00:00:00 2001 From: LmeSzinc <37934724+LmeSzinc@users.noreply.github.com> Date: Sun, 1 Jan 2023 16:48:33 +0800 Subject: [PATCH] Fix: area_cross_area() (#1954, #1978) --- module/base/utils.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/module/base/utils.py b/module/base/utils.py index 971ab002e..66266d18f 100644 --- a/module/base/utils.py +++ b/module/base/utils.py @@ -323,10 +323,11 @@ def area_cross_area(area1, area2, threshold=5): Returns: bool: """ - return point_in_area((area1[0], area1[1]), area2, threshold=threshold) \ - or point_in_area((area1[2], area1[1]), area2, threshold=threshold) \ - or point_in_area((area1[0], area1[3]), area2, threshold=threshold) \ - or point_in_area((area1[2], area1[3]), area2, threshold=threshold) + # https://www.yiiven.cn/rect-is-intersection.html + xa1, ya1, xa2, ya2 = area1 + xb1, yb1, xb2, yb2 = area2 + return abs(xb2 + xb1 - xa2 - xa1) <= xa2 - xa1 + xb2 - xb1 + threshold * 2 \ + and abs(yb2 + yb1 - ya2 - ya1) <= ya2 - ya1 + yb2 - yb1 + threshold * 2 def float2str(n, decimal=3):