Skip to content

Fix #200: Improve outlines - prevent diagonal lines on coplanar polygons#245

Open
bertt wants to merge 7 commits intomasterfrom
fix/issue-200-improve-outlines
Open

Fix #200: Improve outlines - prevent diagonal lines on coplanar polygons#245
bertt wants to merge 7 commits intomasterfrom
fix/issue-200-improve-outlines

Conversation

@bertt
Copy link
Member

@bertt bertt commented Jan 30, 2026

  • Add AreCoplanar() method to Triangle class to check if two triangles share the same plane
  • Update BoundaryDetection.GetSharedPoints() to support optional coplanarity check
  • Enable coplanarity check in Adjacency.GetAdjacencyList() to exclude shared edges between coplanar triangles from outlines
  • Add comprehensive unit tests for coplanar and non-coplanar triangle scenarios
  • All 21 outline tests pass successfully

This fix ensures that shared edges between triangles with the same orientation are properly excluded from the outline, eliminating unwanted diagonal lines on flat surfaces.

- Add AreCoplanar() method to Triangle class to check if two triangles share the same plane
- Update BoundaryDetection.GetSharedPoints() to support optional coplanarity check
- Enable coplanarity check in Adjacency.GetAdjacencyList() to exclude shared edges between coplanar triangles from outlines
- Add comprehensive unit tests for coplanar and non-coplanar triangle scenarios
- All 21 outline tests pass successfully

This fix ensures that shared edges between triangles with the same orientation are properly excluded from the outline, eliminating unwanted diagonal lines on flat surfaces.
@bertt
Copy link
Member Author

bertt commented Jan 30, 2026

Summary

This PR fixes issue #200 by preventing diagonal lines from appearing on polygons with the same orientation (coplanar triangles).

Problem

The outline detection algorithm was drawing unwanted lines between triangles that share an edge and are on the same plane. This created visual artifacts where internal edges of flat surfaces were being included in the outline.

Solution

Added coplanarity checking to the adjacency detection logic:

  1. Triangle.cs — Added AreCoplanar() method that compares triangle normals using dot product
  2. BoundaryDetection.cs — Enhanced GetSharedPoints() with optional coplanarity check
  3. Adjacency.cs — Enabled coplanarity checking to properly exclude shared edges between coplanar triangles
  4. Tests — Added 4 new unit tests covering coplanar and non-coplanar scenarios

Changes Made

  • ✅ Added Triangle.AreCoplanar() method using normal vector comparison
  • ✅ Updated GetSharedPoints() to optionally check if triangles are coplanar
  • ✅ Modified GetAdjacencyList() to pass checkCoplanar: true
  • ✅ Plumbed normalTolerance parameter through outline detection pipeline
  • ✅ Added comprehensive unit tests

Testing

  • All 21 existing outline tests pass ✅
  • 4 new unit tests added for coplanarity checking ✅
  • Entire solution builds successfully ✅

Technical Details

The fix implements the suggestion from @mittermichal in the issue comments — adding a check to GetSharedPoints that triangles can't be on the same plane. Shared edges between coplanar triangles (dot product ≈ 1.0) are now properly excluded from outlines, while edges between non-coplanar triangles are correctly preserved.

Closes #200

@bertt
Copy link
Member Author

bertt commented Feb 2, 2026

@copilot this is not the fix, the issue occurs when several parts in the geometry are coplanar but they do not follow each other in the geometric order.

For example:

Consider this wkt of 3 triangles:

MULTIPOLYGON Z(
  (
    (
      121346 487295 5,
      121446 487295 5,
      121396 487381.603 5,
      121346 487295 5
    )
  ),
  (
    (
      121446 487295 5,
      121396 487381.603 5,
      121346 487295 100,
      121446 487295 5
    )
  ),
  (
    (
      121346 487295 5,
      121446 487295 5,
      121396 487208.397 5,
      121346 487295 5
    )
  )
)

Triangle 1 and 3 are coplanar and adjacent, so there must NOT be an outline on the shared line. But currently an outline is drawn here.

Triangle 1 and 2 are not coplanar but are adjacent, so currently correctly an outline is drawn on the shared line.

Revert all changes in this pr and correctly fix this issue, make sure the performance of creating the outlines is roughly the same as current implementation if possible. Make unit tests to prove the fix.

Copy link
Contributor

Copilot AI commented Feb 2, 2026

@bertt I've opened a new pull request, #246, to work on those changes. Once the pull request is ready, I'll request review from you.

Copilot AI and others added 4 commits February 2, 2026 16:05
… changes

Co-authored-by: bertt <538812+bertt@users.noreply.github.com>
Co-authored-by: bertt <538812+bertt@users.noreply.github.com>
Co-authored-by: bertt <538812+bertt@users.noreply.github.com>
Co-authored-by: bertt <538812+bertt@users.noreply.github.com>
@bertt bertt closed this Feb 2, 2026
@bertt bertt reopened this Feb 2, 2026
Fix #200: Exclude shared edges between coplanar triangles from outlines
@bertt
Copy link
Member Author

bertt commented Feb 2, 2026

this works better but is too slow now 3 seconds versus 3 minutes.

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