Skip to content

Fixed: Correctly wires neighbors after K2 flips#191

Merged
acgetchell merged 2 commits intomainfrom
refactor/wire-cavity-neighbors
Feb 8, 2026
Merged

Fixed: Correctly wires neighbors after K2 flips#191
acgetchell merged 2 commits intomainfrom
refactor/wire-cavity-neighbors

Conversation

@acgetchell
Copy link
Owner

Fixes an issue where external neighbors across the cavity boundary were not being correctly rewired after a K2 flip.

Introduces external_facets_for_boundary to collect the set of external facets that are shared with the flip cavity boundary, and then uses these to correctly wire up neighbors.

Adds a test case to verify that external neighbors are correctly rewired after the flip, ensuring that the triangulation remains valid and consistent.
Refs: refactor/wire-cavity-neighbors

Fixes an issue where external neighbors across the cavity
boundary were not being correctly rewired after a K2 flip.

Introduces `external_facets_for_boundary` to collect the set
of external facets that are shared with the flip cavity boundary,
and then uses these to correctly wire up neighbors.

Adds a test case to verify that external neighbors are correctly
rewired after the flip, ensuring that the triangulation remains
valid and consistent.
Refs: refactor/wire-cavity-neighbors
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 8, 2026

Walkthrough

Introduces boundary-aware neighbor wiring: extract the cavity boundary, derive external boundary facets, and pass those facets into the neighbor-wiring step so newly inserted cells are wired to the correct external neighbors across the cavity boundary.

Changes

Cohort / File(s) Summary
Flip wiring refactor
src/core/algorithms/flips.rs
After k-moves, extract cavity boundary (extract_cavity_boundary), compute external facets, and call wire_cavity_neighbors with those external facets. Added tests and helpers (e.g., facet_index_for_edge_2d, facet_index_for_face_3d) validating boundary-aware rewiring and neighbor symmetry.
Core wiring API update
src/core/algorithms/incremental_insertion.rs
Changed wire_cavity_neighbors signature to accept external_facets: IntoIterator<Item = FacetHandle>. Added external_facets_for_boundary to find external facets matching a cavity boundary and updated wiring logic to use a facet-hash incident map, wiring only facets with two incidents. Added debug instrumentation and updated tests to exercise the new flow and error paths.
Triangulation integration
src/core/triangulation.rs
Replaced direct wiring calls with a two-step pattern: compute external_facets_for_boundary for the conflict boundary, then invoke wire_cavity_neighbors with the external facets iterator (and original conflict cell set) in both interior cavity fill and hull/extension paths.

Sequence Diagram(s)

sequenceDiagram
    participant Inserter
    participant CavityBoundary
    participant ExternalFinder
    participant Wirer
    participant Tds

    Inserter->>CavityBoundary: identify internal conflict cells & boundary_facets
    CavityBoundary->>ExternalFinder: provide internal cells + boundary_facets
    ExternalFinder->>Tds: scan neighbor candidates, collect external facet handles
    ExternalFinder-->>Inserter: return external_facets
    Inserter->>Wirer: call wire_cavity_neighbors(new_cells, external_facets, conflict_cells)
    Wirer->>Tds: build facet incident map, create wiring pairs, attach new↔external neighbors
    Wirer-->>Inserter: success / FlipError::NeighborWiring on failure
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • Feature/bistellar flips #172: Modifies flips and neighbor-wiring codepaths; directly overlaps the flip wiring changes in this PR.
  • Feat/locate and insert #132: Refactors incremental insertion and wiring; intersects with the new external_facets_for_boundary insertion flow.
  • Refactor/phase 3 #90: Changes boundary-facet discovery and wiring behavior similar to the external-facet discovery used here.

Poem

🐰 I hopped the cavity round and round,
Found edges that whispered, softly bound,
Collected facets, matched each glue,
Wired neighbors true—no pointers askew.
A tiny hop, topology sound.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Fixed: Correctly wires neighbors after K2 flips' directly relates to the main change—fixing neighbor rewiring after K2 (and K3) flips by introducing boundary-aware wiring logic.
Description check ✅ Passed The description accurately explains the fix for external neighbor rewiring after K2 flips, mentions the new external_facets_for_boundary helper, and notes the addition of test cases.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch refactor/wire-cavity-neighbors

No actionable comments were generated in the recent review. 🎉

🧹 Recent nitpick comments
src/core/algorithms/flips.rs (1)

4090-4127: Test helpers facet_index_for_edge_2d and facet_index_for_face_3d are dimension-specific; consider a generic version.

These two functions are structurally identical (iterate facets, check containment, return index) but are specialized for D=2 and D=3 respectively. If more dimension-specific rewiring tests are added later, a single generic helper parameterized on D and accepting a slice of face vertex keys would reduce duplication.

That said, for two tests this is perfectly acceptable as-is.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai bot added bug Something isn't working geometry Geometry-related issues rust Pull requests that update rust code topology labels Feb 8, 2026
@codecov
Copy link

codecov bot commented Feb 8, 2026

Codecov Report

❌ Patch coverage is 55.55556% with 60 lines in your changes missing coverage. Please review.
✅ Project coverage is 63.06%. Comparing base (bee065b) to head (b0a3e5c).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/core/algorithms/incremental_insertion.rs 60.18% 43 Missing ⚠️
src/core/triangulation.rs 31.25% 11 Missing ⚠️
src/core/algorithms/flips.rs 45.45% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #191      +/-   ##
==========================================
- Coverage   63.07%   63.06%   -0.01%     
==========================================
  Files          46       46              
  Lines       10031    10118      +87     
==========================================
+ Hits         6327     6381      +54     
- Misses       3704     3737      +33     
Flag Coverage Δ
unittests 63.06% <55.55%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@codacy-production
Copy link

codacy-production bot commented Feb 8, 2026

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
-0.01% (target: -1.00%) 55.56%
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (bee065b) 10038 6328 63.04%
Head commit (b0a3e5c) 10125 (+87) 6382 (+54) 63.03% (-0.01%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#191) 135 75 55.56%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

Adds a test to verify correct rewiring of external neighbors
after a k=3 flip. This validates the boundary handling and
neighbor update logic in the bistellar flip implementation.

This test constructs an explicit k=3 ridge-flip fixture and
checks neighbor rewiring.
@acgetchell acgetchell merged commit 5ab686c into main Feb 8, 2026
11 of 12 checks passed
@acgetchell acgetchell deleted the refactor/wire-cavity-neighbors branch February 8, 2026 03:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working geometry Geometry-related issues rust Pull requests that update rust code topology

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant