Skip to content

Guard all mutating public API methods against post-finalization calls#16

Merged
MichaConrad merged 2 commits intomainfrom
copilot/add-finalized-check-to-api
Feb 24, 2026
Merged

Guard all mutating public API methods against post-finalization calls#16
MichaConrad merged 2 commits intomainfrom
copilot/add-finalized-check-to-api

Conversation

Copy link
Contributor

Copilot AI commented Feb 24, 2026

After any Erase* method is called, the triangulation is finalized and further mutation (vertex/edge insertion or additional erase calls) leads to silent index-out-of-range errors rather than a clear failure. This adds early, explicit rejection for all affected methods.

Changes

Triangulation.cs

  • Added TriangulationFinalizedException (derives from TriangulationException) with a descriptive message
  • Added IsFinalized guard at the top of every mutating public method: InsertVertices, InsertEdges, ConformToEdges, EraseSuperTriangle, EraseOuterTriangles, EraseOuterTrianglesAndHoles

TriangulationTests.cs

  • Added one test per guarded method verifying TriangulationFinalizedException is thrown post-finalization (runs for both float and double via the shared base class)

Example

var cdt = new Triangulation<double>();
cdt.InsertVertices([...]);
cdt.EraseSuperTriangle(); // finalizes

// Previously: silent IndexOutOfRangeException or corrupt state
// Now: immediate, meaningful exception
cdt.InsertVertices([...]); // throws TriangulationFinalizedException
cdt.InsertEdges([...]);    // throws TriangulationFinalizedException
cdt.EraseSuperTriangle();  // throws TriangulationFinalizedException

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…n + unit tests

Co-authored-by: MichaCo <5837539+MichaCo@users.noreply.github.com>
Copilot AI changed the title [WIP] Add check for finalized state in Triangulation API Guard all mutating public API methods against post-finalization calls Feb 24, 2026
Copilot AI requested a review from MichaConrad February 24, 2026 09:52
@MichaConrad MichaConrad marked this pull request as ready for review February 24, 2026 10:37
@github-actions
Copy link

Summary

Summary
Generated on: 2/24/2026 - 10:39:11 AM
Coverage date: 2/24/2026 - 10:39:08 AM
Parser: Cobertura
Assemblies: 1
Classes: 18
Files: 7
Line coverage: 85.1% (1333 of 1566)
Covered lines: 1333
Uncovered lines: 233
Coverable lines: 1566
Total lines: 3877
Branch coverage: 79.6% (640 of 804)
Covered branches: 640
Total branches: 804
Method coverage: Feature is only available for sponsors
Tag: 98_22345529175

Coverage

CDT.Core - 85.1%
Name Line Branch
CDT.Core 85.1% 79.6%
CDT.Box2d`1 73.6% 100%
CDT.CdtUtils 83.1% 72.8%
CDT.CovariantReadOnlyDictionary`3 18.1% 50%
CDT.DictionaryExtensions 100% 100%
CDT.DuplicatesInfo 100%
CDT.DuplicateVertexException 66.6%
CDT.Edge 75% 66.6%
CDT.IntersectingConstraintsException 0%
CDT.KdTree`1 72.7% 65%
CDT.LayerDepth 0%
CDT.Predicates.PredicatesAdaptive 92.6% 83.3%
CDT.Predicates.PredicatesExact 35.3% 100%
CDT.TopologyVerifier 77.2% 63.8%
CDT.Triangle 66.6% 71.4%
CDT.Triangulation`1 93.8% 84.8%
CDT.TriangulationException 100%
CDT.TriangulationFinalizedException 100%
CDT.V2d`1 44.4% 25%

@MichaConrad MichaConrad merged commit ca9bf15 into main Feb 24, 2026
3 checks passed
@MichaConrad MichaConrad deleted the copilot/add-finalized-check-to-api branch February 24, 2026 10:40
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.

2 participants