Skip to main content

Module validation

Module validation 

Source
Expand description

Part validation matching polygon.move on-chain rules. All validation functions must produce identical results to the Move contract.

§Compactness is a boundary-level property, not a per-part property.

polygon.move calls validate_compactness in exactly two places (polygon.move::validate_multipart_topology, count==1 and count>=2 branches):

  • count == 1: on the single part’s (twice_area, L1 perimeter), which is the polygon’s outer boundary because the single part IS the boundary.
  • count >= 2: on the union’s outer boundary, computed by validate_boundary_graph (edges appearing exactly once) and the SUM of all per-part twice_areas.

Per-part checks in Move are strictly: convexity, validate_part_edges (min edge length), and max vertex count. There is NO per-part compactness check.

This module therefore provides:

  • validate_compactness: the isoperimetric check, to be applied to a polygon boundary (whole single part, or union boundary of a multipart polygon). Do NOT call this on an individual part of a multipart polygon.
  • validate_part: mirrors Move’s per-part rules — convex + edges + vertex count bounds. NO compactness here.

Rules (in order):

  1. is_convex: weakly convex (collinear runs OK, reflex turns rejected)
  2. validate_edge_lengths: all edges squared-length >= MIN_EDGE_LENGTH_SQUARED
  3. validate_compactness (boundary-level only): L1 perimeter^2 * MIN_COMPACTNESS_PPM <= 8_000_000 * twice_area
  4. validate_part: structural per-part checks (1 + 2 + vertex-count bounds)

Structs§

CompactnessOutcome
Outcome of the isoperimetric compactness check.

Functions§

check_compactness
Core compactness check matching polygon.move::validate_compactness.
is_convex
True if the polygon vertices form a weakly convex polygon.
perimeter_l1
Compute the L1 (Manhattan) perimeter of a polygon. Uses |dx| + |dy| per edge — matches polygon.move’s perimeter formula. MUST use L1, NOT Euclidean (matching on-chain compactness check).
validate_compactness
Validate compactness using the isoperimetric ratio, returning a string error on failure. Thin wrapper around check_compactness for callers that want a human-readable message instead of a structured TopologyError.
validate_edge_lengths
Validate all edges have squared length >= MIN_EDGE_LENGTH_SQUARED. Returns None if valid, Some(error message) if any edge is too short. Matches polygon.move::validate_part_edges().
validate_part
Validate a polygon part against the per-part on-chain rules.