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)