escape
Polygon escape Polygon => Penetration?
Returns the penetration where this polygon reaches out of boundary's solid region, or null when it lies within, touching included.
The boundary's orientation decides which side is solid, and with it how the violated face is picked:
A classic boundary — counter-clockwise, Polygon.isInsideOut
false— is a container: its solid region is the loop's bounded interior, which the subject may not leave. Every face must be satisfied to be in, so the answer is the face with the deepest protrusion — resolving it retreats the subject the whole way back inside.An inside-out boundary — clockwise — keeps the subject out of its loop: its solid region is everything outside the loop, and leaving it is reaching into the bounded interior. Clearing one face is enough to be out again, so the answer is the face with the shallowest push-out — the nearest single-face way clear.
collide is the dual query, related through negation: subject escape -polygon and subject collide 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 back into 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 boundary or a face of the subject on a vertex of the boundary.
Sound for a convex loop on boundary only — a concave loop yields an arbitrary face pick, not an error. Against a classic boundary the subject may be any polygon: it contributes only its vertices, and within a convex region a polygon lies inside exactly when its vertices do. Against an inside-out boundary the subject must be convex too — a concave subject may be reported clear while its body still reaches into the loop — and faces for the pick come from boundary 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 boundary's solid region.
Return
The resolved penetration, or null when this polygon lies within boundary's solid region at the SCALE quantum, boundary touches included.
Parameters
The polygon whose oriented solid region the subject may not leave.