From 06ca04bde71b44fc4111a7b12a042baead18b049 Mon Sep 17 00:00:00 2001 From: Aweptimum <40273116+Aweptimum@users.noreply.github.com> Date: Mon, 10 May 2021 11:55:51 -0400 Subject: [PATCH] Added aabb_circle_overlap When the distance between the circle's center and the closest point on the aabb is less than the circle radius, returns true. --- intersect.lua | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/intersect.lua b/intersect.lua index 314d75e..609e1a0 100644 --- a/intersect.lua +++ b/intersect.lua @@ -428,6 +428,15 @@ local function aabb_clamp(pos, hs, v) return _v_clamp.x, _v_clamp.y end +-- return true on overlap, false otherwise +local _a_b_closest = vec2:zero() +local _a_b_delta = vec2:zero() -- Delta vec for minimum distance between aabb and circle +function intersect.aabb_circle_overlap(apos, ahs, bpos, brad) + _a_b_closest:sset(aabb_clamp(apos, ahs, bpos)) + _a_b_delta:vset(bpos):vsubi(_a_b_closest) + return _a_b_delta:dot(_a_b_delta) < (brad*brad) + COLLIDE_EPS -- Pythag theorem +end + --check if a point is in a polygon --point is the point to test --poly is a list of points in order