[added] intersect.line_circle_overlap for checking boolean overlap circles vs lines

This commit is contained in:
Max Cahill 2021-05-13 12:24:45 +10:00
parent af961ab2b8
commit 80c44f3436

View File

@ -85,11 +85,13 @@ function intersect.nearest_point_on_line(a_start, a_end, b_pos, into)
return into return into
end end
--internal
--vector from line seg to point --vector from line seg to point
function intersect._line_to_point(a_start, a_end, b_pos, into) 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) return intersect.nearest_point_on_line(a_start, a_end, b_pos, into):vsubi(b_pos)
end end
--internal
--line displacement vector from separation vector --line displacement vector from separation vector
function intersect._line_displacement_to_sep(a_start, a_end, separation, total_rad) function intersect._line_displacement_to_sep(a_start, a_end, separation, total_rad)
local distance = separation:normalisei_len() local distance = separation:normalisei_len()
@ -106,6 +108,14 @@ function intersect._line_displacement_to_sep(a_start, a_end, separation, total_r
return false return false
end 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 --collide a line segment with a circle
function intersect.line_circle_collide(a_start, a_end, a_rad, b_pos, b_rad, into) 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) into = intersect._line_to_point(a_start, a_end, b_pos, into)