Package-level declarations

The constraint tier: operations that solve for the motion satisfying a geometric relation and return the shape already moved. The dual verbs coerceOut and coerceIn keep a polygon out of — respectively inside — an oriented solid region, in the standard library's coerce posture: an already-valid receiver comes back untouched, a violating one minimally moved — generic over the receiver's type, so a Polygon subclass comes back as its own class. coerceOn, the equality constraint beside them, rests a polygon against the region: where the two inequality verbs accept every pose that does not violate, coerceOn accepts exactly the touching ones — resolved through collide when the subject overlaps the region and through gap when it lies apart.

PairingResult
subject coerceOut collider (classic collider — an obstacle)the subject nudged out along the shallowest push-out, or untouched when they don't overlap
subject coerceOut collider (inside-out collider — a wall)the subject retreated back inside the allowed interior, or untouched when it already lies inside
subject coerceIn boundary (classic boundary)the subject retreated back inside the boundary's bounded interior, or untouched when it already lies inside
subject coerceIn boundary (inside-out boundary)the subject nudged back into the complement of the boundary's loop, or untouched when it already lies there
subject coerceOn support (classic support)the subject rested against the loop from outside: pushed out along the shallowest push-out when overlapping, drawn in along its shortest gap when apart, or untouched when touching
subject coerceOn support (inside-out support)the subject rested against the loop's inner wall: retreated back inside when protruding, drawn out to the wall along its shortest gap when floating within, or untouched when touching

The two verbs are duals through negation: subject coerceIn boundary lands the subject where subject coerceOut -boundary does — staying inside a region is staying out of its complement — each resolving its own query, escape and collide respectively. The penetration contract of the queries package applies wholesale: convex loop on the queried polygon, one penetration resolved per call — several simultaneous violations converge by coercing again — and touching is not penetration. For coerceOn that contract binds the overlapping half alone — the separated half, through gap, asks no convexity of either operand. The resolution is the nudge: a translation along the penetration normal by the raw depth — or, for a separated coerceOn subject, the translation closing its gap. A resolution of the caller's own is spelled on the query itself — (subject collide collider) { penetration -> … } or (subject escape boundary) { … }.

Functions

Link copied to clipboard
infix fun <P : Polygon> P.coerceIn(boundary: Polygon): P

Polygon coerceIn Polygon => Polygon
Returns this polygon nudged back inside boundary's solid region, or this untouched when it already lies inside, boundary included.

Link copied to clipboard
infix fun <P : Polygon> P.coerceOn(support: Polygon): P

Polygon coerceOn Polygon => Polygon
Returns this polygon translated along the shortest straight path until it touches support, or this untouched when it already touches.

Link copied to clipboard
infix fun <P : Polygon> P.coerceOut(collider: Polygon): P

Polygon coerceOut Polygon => Polygon
Returns this polygon nudged clear of collider's solid region, or this untouched when it is already clear, touching included.