From ba7a7b5500b86182ba05e51cb28084148b50ce53 Mon Sep 17 00:00:00 2001 From: Max Cahill <1bardesign@gmail.com> Date: Thu, 8 Dec 2022 13:36:29 +1100 Subject: [PATCH] fixed intersection tests with zero radius shapes (treated as points generally) --- intersect.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/intersect.lua b/intersect.lua index 7c5cff8..9bf955b 100644 --- a/intersect.lua +++ b/intersect.lua @@ -29,12 +29,12 @@ local COLLIDE_EPS = 1e-6 -- circles function intersect.circle_point_overlap(pos, rad, v) - return pos:distance_squared(v) < rad * rad + return pos:distance_squared(v) <= rad * rad end function intersect.circle_circle_overlap(a_pos, a_rad, b_pos, b_rad) local rad = a_rad + b_rad - return a_pos:distance_squared(b_pos) < rad * rad + return a_pos:distance_squared(b_pos) <= rad * rad end function intersect.circle_circle_collide(a_pos, a_rad, b_pos, b_rad, into) @@ -46,7 +46,7 @@ function intersect.circle_circle_collide(a_pos, a_rad, b_pos, b_rad, into) local rad = a_rad + b_rad local dist = delta:length_squared() local res = false - if dist < rad * rad then + if dist <= rad * rad then if dist == 0 then --singular case; just resolve vertically dist = 1 @@ -278,7 +278,7 @@ function intersect.aabb_point_overlap(pos, hs, v) :pooled_copy() :vector_sub_inplace(v) :abs_inplace() - local overlap = delta.x < hs.x and delta.y < hs.y + local overlap = delta.x <= hs.x and delta.y <= hs.y delta:release() return overlap end @@ -320,7 +320,7 @@ function intersect.aabb_aabb_overlap(a_pos, a_hs, b_pos, b_hs) local total_size = a_hs :pooled_copy() :vector_add_inplace(b_hs) - local overlap = delta.x < total_size.x and delta.y < total_size.y + local overlap = delta.x <= total_size.x and delta.y <= total_size.y vec2.release(delta, total_size) return overlap end @@ -375,7 +375,7 @@ function intersect.aabb_circle_overlap(a_pos, a_hs, b_pos, b_rad) local clamped = intersect.aabb_point_clamp(a_pos, a_hs, b_pos, vec2:pooled()) local edge_distance_squared = clamped:distance_squared(b_pos) clamped:release() - return edge_distance_squared < (b_rad * b_rad) + return edge_distance_squared <= (b_rad * b_rad) end -- return msv on collision, false otherwise