Skip to content

Regenerate ground-truth expected files from C# output; remove C++-mimicking implementation artifacts#3

Merged
MichaConrad merged 3 commits intomainfrom
copilot/refactor-unit-test-structure
Feb 22, 2026
Merged

Regenerate ground-truth expected files from C# output; remove C++-mimicking implementation artifacts#3
MichaConrad merged 3 commits intomainfrom
copilot/refactor-unit-test-structure

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 22, 2026

The test suite used expected files generated from the C++ CDT implementation. 90/990 tests failed due to tie-breaking divergence in degenerate cases — correct Delaunay output, wrong C++ parity. The fix: C# expected files generated from C# output, and removal of code that existed solely to match C++ internals.

Expected files

  • All 550 .expected files regenerated from the C# triangulation
  • Removed 3 orphaned files (154_*.txt) not referenced by any test assertion
  • Float and double share expected files for type-independent inputs; typed inputs have separate f32_/f64_ files

Triangulation.cs — removed C++-mimicking implementations

  • LLVM nth_element port (~170 lines with goto): replaced with a 20-line Lomuto quickselect
  • SplitMix64 PRNG: removed entirely
    • InsertVertices_Randomized shuffle → Random.Shared Fisher-Yates
    • WalkTriangles edge offset → guard % 3
  • Type-dispatch section (~120 lines, 5 wrapper methods using Unsafe.As): deleted; using static CDT.TriangleUtils added so all 17 call sites are unchanged

TriangleUtils.cs — collapsed duplicate overloads

Replaced 8 type-specific double/float overload pairs with 4 generic methods. A single private Orient2D<T> helper centralises the one unavoidable Unsafe.As dispatch (needed because Predicates has fundamentally different adaptive-precision implementations for each type). IntersectionPosition<T> now uses generic T arithmetic with no unsafe casts:

// Before: two identical bodies differing only in double vs float
public static V2d<double> IntersectionPosition(V2d<double> a, ...) { ... }
public static V2d<float>  IntersectionPosition(V2d<float>  a, ...) { ... }

// After: one generic method, Lerp expressed via T arithmetic
public static V2d<T> IntersectionPosition<T>(V2d<T> a, V2d<T> b, V2d<T> c, V2d<T> d)
    where T : unmanaged, IFloatingPoint<T>
{
    T acd = Orient2D(a, c, d);
    ...
    static T Lerp(T x, T y, T t) => (T.One - t) * x + t * y;
    return new V2d<T>(...);
}

Net: −586 / +261 lines. All 990 tests pass.


💡 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.

Copilot AI and others added 2 commits February 22, 2026 09:22
…xt files

Co-authored-by: MichaCo <5837539+MichaCo@users.noreply.github.com>
…ted files

Co-authored-by: MichaCo <5837539+MichaCo@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor unit tests for performance and maintainability Regenerate ground-truth expected files from C# output; remove C++-mimicking implementation artifacts Feb 22, 2026
Copilot AI requested a review from MichaConrad February 22, 2026 09:39
@MichaConrad MichaConrad marked this pull request as ready for review February 22, 2026 09:42
@MichaConrad MichaConrad merged commit 29cce4b into main Feb 22, 2026
@MichaConrad MichaConrad deleted the copilot/refactor-unit-test-structure branch February 22, 2026 09:42
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