Skip to content

cvc::planar: CDT triangulations, Hertel-Mehlhorn partitions, Sibson coordinates (P3a, part 2) - #1162

Closed
transfix wants to merge 17 commits into
masterfrom
p3a/planar-triangulation
Closed

transfix wants to merge 17 commits into
masterfrom
p3a/planar-triangulation

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 2 of 3. Stacked on #1158: review only the last commit (cvc::planar: CDT triangulations, ...). Once #1158 merges, this PR's diff shrinks to that commit.

What lands

  • Triangulations on CDT (cvcpkg cdt, MPL-2.0), replacing CGAL's GPL 2D triangulations:
    • delaunay, constrained_delaunay, and triangulate, which triangulates a polygon's inside, holes included.
    • Triangles are counterclockwise and come with a neighbour table.
    • Duplicate points map to their first copy, collinear input gives no triangles, a constraint through a point is split there, and crossing constraints throw planar_error.
    • CDT's randomised steps use a generator local to each call, seeded with 0, so a result is the same on every run and there are no statics.
  • 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). The query point is found by a visibility walk.
  • Tests (T2, T6), added to planar_test:
    • every circumcircle empty, and in the constrained case a point inside one only if a constraint hides it;
    • exact triangle areas against the convex hull's or the polygon's;
    • the neighbour table, and the degenerate inputs;
    • partitions that tile the polygon, checked by sampling, within Hertel–Mehlhorn's 2r+1 bound;
    • Sibson weights against Voronoi cells built by half-plane clipping, to 1e-7;
    • linear functions reproduced exactly;
    • two threads give what each gives alone.
  • A/B against CGAL (T16), more rows in cgal_ab_planar.cpp:
    • Delaunay_triangulation_2;
    • Constrained_Delaunay_triangulation_2's faces inside the polygon (ContourTiler's use);
    • approx_convex_partition_2, plus Greene's, ContourTiler's fallback;
    • natural_neighbor_coordinates_2 with linear_interpolation.

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

  • Triangulations: identical to CGAL's. Delaunay on uniform points up to 32k (about a third of CGAL's speed). Polygon triangulations on stars, dense contours and a contour with two holes (1.5× CGAL's speed).
  • Sibson: weights and interpolated values within 1e-14 of CGAL's over 1,500 queries, and the same queries inside and outside the hull. About 5 µs a query, against CGAL's ~1.4 µs.
  • Partitions: every one passes CGAL's own convex_partition_is_valid_2, but none equals CGAL's piece for piece. Hertel–Mehlhorn on CDT's Delaunay triangulation gives 15–45% fewer pieces than approx_convex_partition_2, which runs it on a constrained triangulation that is not Delaunay. On the dense contours that is 50–206 pieces against CGAL's 82–300.

A parity finding for P3b and §9 item 2

ContourTiler's live untiled-region code does not use the straight skeleton.

  • What it does. medial_axis_stable (skeleton.cpp, called from tiler_operations.cpp:1509) splits each untiled region into convex pieces with approx_convex_partition_2 (Greene's as the fallback). It puts a vertex at each piece's centroid and one on each diagonal between pieces, then lifts them off the slice planes by natural-neighbour interpolation.
  • What it doesn't. The straight-skeleton fill, triangulate_to_medial_axis, is never called.
  • What that means. The fill moves with the partition, not with the medial axis. A port on cvc::planar will place different interior vertices in untiled regions; region boundaries and tiles outside untiled regions need not change.

The roadmap's §3 and §9 item 2 now say this. The recommendation (topology plus a Hausdorff tolerance) still stands. Exact parity in untiled regions would mean reproducing CGAL's own non-Delaunay constrained triangulation.

Checked locally

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

…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.
transfix added a commit that referenced this pull request Nov 15, 2026
…and the Boost.Polygon medial axis (P3a, #1158, #1162) (#1164)

Squash of #1164, which is stacked on #1162 and #1158 and carries all of both:

- #1158 (P3a, part 1): the grid, exact predicates, polygons, Clipper2 Booleans and offsets.
- #1162 (P3a, part 2): CDT triangulations, Hertel-Mehlhorn partitions, Sibson coordinates.
- #1164 (P3a, part 3): the Boost.Polygon medial axis.

#1164's required checks passed on the combined tree.
@transfix

Copy link
Copy Markdown
Owner Author

Landed in #1164's squash commit 187f701. #1164 was stacked on this PR and carried all of it, and #1164's required checks passed on the combined tree. Master now has this PR's changes, in the form #1164 left them.

@transfix transfix closed this Nov 15, 2026
@transfix
transfix deleted the p3a/planar-triangulation branch November 15, 2026 04:55
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