collide
Polygon collide Polygon => Penetration?
Returns the penetration where this polygon reaches into collider's solid region, or null when the two are clear of each other, touching included.
The collider's orientation decides which side is solid, and with it how the violated face is picked:
A classic collider — counter-clockwise, Polygon.isInsideOut
false— is an obstacle: its solid region is the loop's bounded interior. Clearing one face is enough to be out, so the answer is the face with the shallowest push-out — the nearest single-face way clear.An inside-out collider — clockwise — is a wall: its solid region is everything outside the loop, the bounded interior the allowed region. Every face must be cleared to be in, so the answer is the face with the deepest protrusion — resolving it retreats the subject the whole way back inside.
escape is the dual query, related through negation: subject collide -polygon and subject escape polygon agree on depth and normal and report the same face — as the negated polygon's edge here, as the polygon's own edge there. Penetration.depth is the raw Euclidean distance past the picked face; Penetration.normal is that face carrier's unit normal pointed out of the solid region. Touching is not penetration: existence rounds at the SCALE quantum, so a subject exactly on the solid region's boundary returns null — whether a vertex of the subject rests on a face of the collider or a face of the subject on a vertex of the collider.
Sound for a convex loop on collider only — a concave loop yields an arbitrary face pick, not an error. Against an inside-out collider the subject may be any polygon: it contributes only its vertices, and within a convex allowed region a polygon lies inside exactly when its vertices do. Against a classic collider the subject must be convex too — a concave subject may be reported clear while its body still overlaps the collider — and faces for the pick come from collider alone, so a deep corner-on-corner overlap may pick a face that is not the shortest way out.
Receiver
The subject polygon to test against collider's solid region.
Return
The resolved penetration, or null when this polygon is clear of collider's solid region at the SCALE quantum, boundary touches included.
Parameters
The polygon whose oriented solid region the subject may not reach into.