Simplifies a Contour using the Ramer-Douglas-Peucker algorithm.
Marching squares emits one vertex per pixel-edge crossing, which is far
more than Box2D b2ChainShape can stably consume (manifold bugs above
~16 vertices per chain, plus collinear-vertex degeneracies). RDP
removes interior points that lie within epsilon of the chord between
their kept neighbors. Default-tuned epsilon ≈ 1.0 pixel typically
achieves ≥ 80% vertex reduction on circle contours with no visible
loss.
Closed contours
A closed contour is split at the vertex farthest from points[0] so
RDP has two stable endpoints to anchor each half-polyline. The two
simplified halves are then re-joined and the original "closure" is
preserved. If simplification would reduce a closed contour below 3
vertices (e.g. degenerate / collinear inputs), the original is
returned unchanged so consumers can keep treating it as a polygon.
Determinism
For identical inputs and the same epsilon, the algorithm produces
bitwise-identical output. (The architecture doc § Determinism flags
this as the "residual non-determinism source" only across hardware
platforms with floating-point divergence; same-architecture replay is
reliable.)
Simplifies a Contour using the Ramer-Douglas-Peucker algorithm.
Marching squares emits one vertex per pixel-edge crossing, which is far more than Box2D
b2ChainShapecan stably consume (manifold bugs above ~16 vertices per chain, plus collinear-vertex degeneracies). RDP removes interior points that lie withinepsilonof the chord between their kept neighbors. Default-tunedepsilon ≈ 1.0pixel typically achieves ≥ 80% vertex reduction on circle contours with no visible loss.Closed contours
A closed contour is split at the vertex farthest from
points[0]so RDP has two stable endpoints to anchor each half-polyline. The two simplified halves are then re-joined and the original "closure" is preserved. If simplification would reduce a closed contour below 3 vertices (e.g. degenerate / collinear inputs), the original is returned unchanged so consumers can keep treating it as a polygon.Determinism
For identical inputs and the same epsilon, the algorithm produces bitwise-identical output. (The architecture doc § Determinism flags this as the "residual non-determinism source" only across hardware platforms with floating-point divergence; same-architecture replay is reliable.)