Skip to content

cvc::planar: the Boost.Polygon medial axis (P3a, part 3) - #1164

Merged
transfix merged 25 commits into
masterfrom
p3a/planar-medial-axis
Nov 15, 2026
Merged

transfix merged 25 commits into
masterfrom
p3a/planar-medial-axis

Conversation

@transfix

@transfix transfix commented Nov 12, 2026 •

Copy link
Copy Markdown
Owner

Phase P3a of the VolumeRover ports plan (docs/roadmap/VOLROVER-LIBRARY-PORTS-ROADMAP.md §3, §7), part 3 of 3. Stacked on #1158 and #1162: review only the last commit (cvc::planar: the Boost.Polygon medial axis).

What lands

  • medial_axis(polygon, params). It stands where ContourTiler had CGAL's GPL straight skeleton (§1.2: no permissive C++ straight skeleton exists).
    • It takes the edges of Boost.Polygon's Voronoi diagram of the polygon's edges that lie inside the polygon. It leaves out the secondary edges, which run along the normals at reflex vertices.
    • Boost.Polygon builds the diagram exactly from int32 endpoints, the grid's range since part 1. Boost is header-only and already a dependency, so there's no new package.
    • Parabolic arcs (a reflex vertex facing an edge) are sampled until no chord strays more than tolerance.
    • Each vertex carries its clearance (its distance to the boundary).
    • The graph also comes as polylines between branch points and ends, and as a closed loop around each hole.
    • Pure, no statics: GCC -O2 emits no writable data for any cvc::planar object, Boost.Polygon's and CDT's headers included.
  • Tests, added to planar_test:
    • known shapes: a rectangle's axis exactly, and a regular polygon's spokes meeting at its inradius;
    • an L whose axis curves round the reflex vertex without touching it, sampled more finely at a finer tolerance;
    • on random polygons, with and without holes, checked by brute force: every vertex's clearance, its two or more nearest boundary points, and the graph's topology (one piece, one loop per hole);
    • bad input, and a two-thread run (T6).
  • A/B against CGAL (T16). create_interior_straight_skeleton_2's bisectors against the medial axis, by Hausdorff distance.
  • THIRD_PARTY_NOTICES.md: Boost.Polygon's Voronoi headers, now compiled into libcvc.

What the A/B found (locally: Windows, MSVC 19.44, CGAL 6.0.1)

  • Convex polygons (asserted): the medial axis is the straight skeleton. The Hausdorff distance is 1e-9 to 2e-8 grid units, with the same branch points.
  • Stars and dense contours (INFO, different by design):
    • every point of the medial axis lies within 1.7–7.4% of the polygon's size of the skeleton;
    • the skeleton's bisectors into reflex vertices, which the medial axis curves round, lie up to 18–27% away.
  • Speed: about 14× CGAL's.

As #1162 found, ContourTiler's live untiled-region fill uses a convex partition rather than the straight skeleton. So this medial axis serves the port's straight-skeleton-shaped uses (the dead triangulate_to_medial_axis, any later medial-axis fill) and doesn't decide parity.

Checked locally

  • planar_test: 42/42 natively and as wasm-mt under node.
  • cgal_ab_test: 0 failures.

macOS: built there too, as in #1158 (master's #1165).

P3a as a whole

Part PR What
1 #1158 the grid, exact predicates, polygons, Clipper2 Booleans, offset, wavefront_offset (the skeleton's offset), minkowski_sum
2 #1162 CDT triangulations, the Hertel–Mehlhorn partition, Sibson coordinates
3 this the Boost.Polygon medial axis

pycvc: §3 asks for pycvc bindings of the tiler (pycvc.tile_contours, P3b), not of the planar module, which is the tiler's internal layer. None are added here.

…offsets (P3a, part 1)

The planar-geometry module the ContourTiler port sits on (VOLROVER-LIBRARY-PORTS-ROADMAP.md §3,
P3a), replacing the GPL CGAL packages ContourTiler used with permissive ones:

- inc/cvc/geometry/planar.h, src/cvc/geometry/planar/: integer points on a snapping grid
  (grid::fit picks a power-of-two unit and an origin from a box, so a grid point's world
  position is exact), Shewchuk's orient2d and incircle, rings and polygons with holes (area,
  orientation, simplicity, point location, clean-up, nesting as arrange_polygons did), Clipper2
  Booleans and resolve(), one-pass offsets, and minkowski_sum.
- wavefront_offset: the straight skeleton's offset (what offset_polygon.cpp took from CGAL),
  as mitred Clipper2 passes stepped from one wavefront event to the next on a grid 2^20 times
  finer, rounded once at the end.
- Built only with Clipper2, CDT and Shewchuk's predicates (then cvc exports CVC_WITH_PLANAR);
  macOS has no bundles of those yet, so it is off there.
- planar_test (T2 against brute force, T6 on two threads), in CVC_PORT_TESTS and the sanitizer
  lanes; the ports lane installs the geometry packages and checks the configure enabled it.
- cgal_ab_planar.cpp (T16): cvc::planar against Polygon_set_2, the straight-skeleton offsets
  and minkowski_sum_2. A single mitred pass differs from the skeleton in 2 of 50 offset cases
  (0.4% and 7.4% of the area, past an edge event that leaves a reflex join);
  wavefront_offset agrees in all 50, and the Booleans in all 32.
…oordinates (P3a, part 2)

The second part of the ContourTiler port's planar module (VOLROVER-LIBRARY-PORTS-ROADMAP.md §3,
P3a), on top of part 1:

- delaunay, constrained_delaunay and triangulate (a polygon's inside, holes included) on CDT,
  replacing Delaunay_triangulation_2 and Constrained_Delaunay_triangulation_2. Triangles are
  counterclockwise with a neighbour table; duplicates and collinear input are handled; crossing
  constraints throw.
- convex_partition: Hertel-Mehlhorn on triangulate()'s triangles, replacing
  approx_convex_partition_2.
- sibson_coordinates and sibson_interpolate on a Delaunay triangulation, replacing
  natural_neighbor_coordinates_2 and linear_interpolation (ContourTiler's interp.cpp).
- planar_test: empty circumcircles (and, constrained, hidden only behind a constraint), exact
  areas, the neighbour table, partitions that tile the polygon within Hertel-Mehlhorn's bound,
  and Sibson weights against Voronoi cells built by half-plane clipping.
- cgal_ab rows: the triangulations are CGAL's exactly and the Sibson weights equal CGAL's to
  1e-14. The partitions are valid but never CGAL's: 15-45% fewer pieces, because CGAL's
  Hertel-Mehlhorn runs on a triangulation that is not Delaunay.
- The roadmap records what that means for parity: ContourTiler's live untiled-region fill
  (medial_axis_stable) partitions into convex pieces and interpolates their centroids; the
  straight-skeleton fill is never called, so the partition, not the medial axis, is where the
  port's fills will differ.
The last part of the ContourTiler port's planar module (VOLROVER-LIBRARY-PORTS-ROADMAP.md §3,
P3a), on top of parts 1 and 2:

- medial_axis(polygon): the edges of Boost.Polygon's Voronoi diagram of the polygon's edges that
  lie inside it, without the secondary edges along the normals at reflex vertices; parabolic
  arcs sampled within a tolerance; each vertex's clearance; the graph also as polylines between
  branch points and ends. It stands where ContourTiler had CGAL's GPL straight skeleton.
- planar_test: the rectangle's and a regular polygon's known axes, an L's arc round its reflex
  vertex, and on random polygons with and without holes every vertex's clearance, its two
  nearest boundary points and the graph's topology (one piece, a loop per hole), by brute force.
- cgal_ab rows against create_interior_straight_skeleton_2: the same as the skeleton on convex
  polygons (Hausdorff distance 1e-9 to 2e-8 grid units, the same branch points), within 1.7-7.4%
  of a polygon's size of it on stars and dense contours, at about 14x CGAL's speed.
- THIRD_PARTY_NOTICES: Boost.Polygon's Voronoi headers, now compiled into libcvc.
# Conflicts:
#	.github/workflows/ci.yml
#	src/cvc/tests/port_tests.cmake
@transfix
transfix merged commit 187f701 into master Nov 15, 2026
28 checks passed
@transfix
transfix deleted the p3a/planar-medial-axis branch November 15, 2026 04:54
transfix added a commit that referenced this pull request Nov 15, 2026
- ci.yml: the sanitizer list keeps this branch's tests (stream_test, net_ws_client_test,
  ariadne_host_test) and master's planar_test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant