From 80c44f3436c04089c3b31d5c3cd9f1dd6796f2be Mon Sep 17 00:00:00 2001 From: Max Cahill <1bardesign@gmail.com> Date: Thu, 13 May 2021 12:24:45 +1000 Subject: [PATCH] [added] `intersect.line_circle_overlap` for checking boolean overlap circles vs lines --- intersect.lua | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/intersect.lua b/intersect.lua index 73fbff3..aff416a 100644 --- a/intersect.lua +++ b/intersect.lua @@ -85,11 +85,13 @@ function intersect.nearest_point_on_line(a_start, a_end, b_pos, into) return into end +--internal --vector from line seg to point function intersect._line_to_point(a_start, a_end, b_pos, into) return intersect.nearest_point_on_line(a_start, a_end, b_pos, into):vsubi(b_pos) end +--internal --line displacement vector from separation vector function intersect._line_displacement_to_sep(a_start, a_end, separation, total_rad) local distance = separation:normalisei_len() @@ -106,6 +108,14 @@ function intersect._line_displacement_to_sep(a_start, a_end, separation, total_r return false end +--overlap a line segment with a circle +function intersect.line_circle_overlap(a_start, a_end, a_rad, b_pos, b_rad) + local nearest = intersect._line_to_point(a_start, a_end, b_pos, vec2:pooled()) + local overlapped = intersect.circle_point_overlap(b_pos, a_rad + b_rad, nearest) + nearest:release() + return overlapped +end + --collide a line segment with a circle function intersect.line_circle_collide(a_start, a_end, a_rad, b_pos, b_rad, into) into = intersect._line_to_point(a_start, a_end, b_pos, into)