--!native --!optimize 2 -- Compiled with roblox-ts v3.0.0 local DetectingTools2D = {} do local _container = DetectingTools2D --*@see https://stackoverflow.com/questions/10962379/how-to-check-intersection-between-2-rotated-rectangles local function ArePolygonsIntersecting(a, b) for _, polygon in { a, b } do for i1 = 0, #polygon - 1 do local i2 = (i1 + 1) % #polygon local p1 = polygon[i1 + 1] local p2 = polygon[i2 + 1] local normal = Vector2.new(p2.Y - p1.Y, p1.X - p2.X) local min_a = nil local max_a = nil for _1, p in a do local projected = normal.X * p.X + normal.Y * p.Y if min_a == nil or projected < min_a then min_a = projected end if max_a == nil or projected > max_a then max_a = projected end end local min_b = nil local max_b = nil for _1, p in b do local projected = normal.X * p.X + normal.Y * p.Y if min_a == nil or projected < min_a then min_b = projected end if max_a == nil or projected > max_a then max_b = projected end end if max_a < min_b or max_b < min_a then return false end end end return true end _container.ArePolygonsIntersecting = ArePolygonsIntersecting local function IsPointInPolygon(point, polygon) local nvert = #polygon local c = false do local i = 0 local j = nvert - 1 local _shouldIncrement = false while true do if _shouldIncrement then local _original = i i += 1 j = _original else _shouldIncrement = true end if not (i < nvert) then break end if polygon[i + 1].Y > point.Y ~= (polygon[j + 1].Y > point.Y) and point.X < ((polygon[j + 1].X - polygon[i + 1].X) * (point.Y - polygon[i + 1].Y)) / (polygon[j + 1].Y - polygon[i + 1].Y) + polygon[i + 1].X then c = not c end end end return c end _container.IsPointInPolygon = IsPointInPolygon local function GetLineIntersection(p0, p1, p2, p3) local _p1 = p1 local _p0 = p0 local s1 = _p1 - _p0 local _p3 = p3 local _p2 = p2 local s2 = _p3 - _p2 local s = (-s1.Y * (p0.X - p2.X) + s1.X * (p0.Y - p2.Y)) / (-s2.X * s1.Y + s1.X * s2.Y) local t = (s2.X * (p0.Y - p2.Y) - s2.Y * (p0.X - p2.X)) / (-s2.X * s1.Y + s1.X * s2.Y) if s >= 0 and s <= 1 and t >= 0 and t <= 1 then return Vector2.new(p0.X + t * s1.X, p0.Y + t * s1.Y) end end _container.GetLineIntersection = GetLineIntersection local function IsFullyContained(polygon_parent, polygon_contained) local min_parent = polygon_parent[1]:Min(polygon_parent) local max_parent = polygon_parent[1]:Max(polygon_parent) local min_contained = polygon_contained[1]:Min(polygon_contained) local max_contained = polygon_contained[1]:Max(polygon_contained) return min_contained.X >= min_parent.X and min_contained.Y >= min_parent.Y and max_contained.X <= max_parent.X and max_contained.Y <= max_parent.Y end _container.IsFullyContained = IsFullyContained local function IsPointInRect(point, rect) return point.X >= rect.Min.X and point.Y >= rect.Min.Y and point.X <= rect.Max.X and point.Y <= rect.Max.Y end _container.IsPointInRect = IsPointInRect end return { DetectingTools2D = DetectingTools2D, }