Skip to content

Implement additive boundary-based polygon splines for non-convex shapes and conforming partitions - #10

Merged
QL-UoHull merged 5 commits into
mainfrom
copilot/corrective-spline-implementation
Jul 16, 2026
Merged

QL-UoHull merged 5 commits into
mainfrom
copilot/corrective-spline-implementation

Conversation

Copilot AI commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

The current Section 7 and Section 9 implementations diverged from the Li–Tian construction: non-convex polygons were evaluated via signed distance / convex-piece composition, and partition cells were normalized post hoc instead of using the additive boundary formulation. This change restores the intended arbitrary-polygon spline behavior so direct evaluation matches convex decomposition and internal decomposition edges do not introduce seams.

  • Core spline construction

    • Replace the public arbitrary-polygon path in imp_spline_2d with a boundary-based additive evaluator assembled from oriented edge contributions.
    • Add decomposition evaluation that cancels artificial internal edges exactly before evaluation, so
      B(whole polygon) == Σ B(convex cells) up to floating-point error.
    • Keep the convex product form available as a low-level legacy helper (convex_product_spline_2d) instead of treating it as the general polygon algorithm.
  • Geometry correctness

    • Tighten polygon normalization and validation:
      • repeated closing vertex handled safely
      • np.allclose(..., rtol=0, atol=...) for geometric tolerance checks
      • separate duplicate-removal and degenerate-edge tolerances
      • detect proper crossings, collinear overlaps, and invalid touching
    • Make triangulate_polygon explicitly require boundary-ordered vertices and fail if ear clipping cannot complete or does not return exactly m - 2 triangles.
  • Section 7 demo/content

    • Replace the L-shape/signed-distance presentation with two paper-style non-convex control polygons in CCW boundary order.
    • Render dashed control polygons, vertex markers, and the spline iso-contour in the intended paper style.
    • Evaluate each polygon both directly and through convex decomposition using the same additive construction.
  • Section 9 partition construction

    • Replace the strip/trapezoid-style partition with a genuine conforming irregular convex-cell partition.
    • Add reusable partition validation for:
      • CCW / positive area
      • shared-edge incidence and endpoint matching
      • no overlaps / gaps / invalid T-junctions
      • outer-domain area coverage
    • Use additive partition fields (partition_basis_fields) so the partition identity is expressed as the sum of polygon bases, not by normalizing arbitrary positive fields.
  • Regression coverage

    • Add focused tests for:
      • Section 7 point inclusion/exclusion on both paper-style polygons
      • direct vs decomposition equality
      • equality across multiple decompositions
      • absence of internal-edge seams
      • repeated closing vertex handling
      • partition topology and additive identity
      • PR Fix imp_spline_2d for non-convex polygons via signed-distance construction #9 review defects around tolerances, triangulation guarantees, and plotting safety

Example of the corrected decomposition path:

from implicit_spline.core import imp_spline_2d, triangulate_polygon, convex_decomp_field

P = ...  # CCW non-convex polygon in boundary order
tris = triangulate_polygon(P)

direct = imp_spline_2d(X, Y, P, delta=0.22, n=2)
decomp = convex_decomp_field(X, Y, tris, delta=0.22, n=2)

# direct and decomposition evaluation now match because internal edges cancel

Copilot AI changed the title [WIP] Fix implementation bugs in piecewise algebraic spline behavior Implement additive boundary-based polygon splines for non-convex shapes and conforming partitions Jul 16, 2026
Copilot AI requested a review from QL-UoHull July 16, 2026 19:58
@QL-UoHull
QL-UoHull marked this pull request as ready for review July 16, 2026 20:07
Copilot AI review requested due to automatic review settings July 16, 2026 20:07
@QL-UoHull
QL-UoHull merged commit 4e50177 into main Jul 16, 2026
1 check passed
@QL-UoHull
QL-UoHull deleted the copilot/corrective-spline-implementation branch July 16, 2026 20:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Restores the Li–Tian intended behavior for non-convex polygons and conforming partitions by switching the public polygon evaluator to an additive, boundary-integral-based construction where internal edges cancel under decomposition, eliminating seams and making direct evaluation match decomposition.

Changes:

  • Replaces imp_spline_2d’s arbitrary-polygon path with an oriented-edge additive evaluator; keeps the convex product form as convex_product_spline_2d.
  • Adds edge cancellation for decomposition evaluation and introduces partition additive basis fields + partition topology validation.
  • Updates demos/tests to use paper-style Section 7 polygons and a conforming Section 9 partition, with regression coverage.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/test_implicit_spline.py Replaces prior signed-distance/normalized-sum tests with additive construction regressions for Section 7/9.
python/implicit_spline/core.py Implements additive boundary-based imp_spline_2d, edge cancellation for decompositions, additive partition fields, and partition validation utilities.
python/implicit_spline/visualization.py Updates partition surface visualization to plot additive sums (partition_basis_fields).
python/implicit_spline/paper_examples.py Adds shared reference polygons/partitions used by demos and tests.
python/implicit_spline/init.py Exposes new public APIs (cancel_internal_edges, convex_product_spline_2d, partition_basis_fields, validate_partition).
examples/README.md Updates documentation to describe the corrected additive demo outputs and topology requirements.
examples/demo.py Rewrites demo around additive construction, paper-style Section 7 examples, and conforming Section 9 partition identity.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +549 to +553
edge_map = {}
for idx, P in enumerate(cells):
for p0, p1 in _polygon_edges(P):
key = _canonical_edge_key(p0, p1)
edge_map.setdefault(key, []).append((idx, np.asarray(p0), np.asarray(p1)))
raise ValueError(
f"validate_partition: total cell area {total_area} does not match outer area {outer_area}."
)
outer_edges = {_canonical_edge_key(a, b) for a, b in _polygon_edges(outer)}
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.

3 participants