isValidPiece function
Whether ring is a piece the engine stores (spec 08 D9; 07 D6's
invariant, per piece): at least three vertices, simple and anticlockwise
(isSimpleCcw), and, closed as the wall stores it, with a non-empty
triangulation (triangulationFor: the very check the engine's planner
makes on a generated region, so the app never generates one it refuses).
Implementation
bool isValidPiece(List<Vector2> ring) {
if (ring.length < 3 || !isSimpleCcw(ring)) return false;
final triangles = triangulationFor(
EntityKind.polyline, polylinePayload(ring, closed: true));
return triangles != null && triangles.isNotEmpty;
}