Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 16, 2025

sliceIntoLayers fails to detect intersections when triangle edges are nearly parallel to the slice plane (< 1° angle), causing 0.6-5.8mm gaps in generated segments. This breaks path closure in 3D printing slicers like polyslice on geometries like Benchy.

Root Cause

Exact floating-point equality checks skip edges with distances like 1e-15:

continue if startDist is 0 and endDist is 0  # Misses near-zero values
if startDist is 0  # Never true for 1e-15

Changes

Angle-aware adaptive epsilon

  • Calculate edge-plane angle via dot product with plane normal
  • Scale epsilon by 100x when dotWithNormal < 0.02 (~1° threshold)
  • Base epsilon scales with edge length: max(1e-10, length * 1e-9)

Replace exact comparisons

# Before
if startDist is 0

# After  
absStartDist = Math.abs(startDist)
if absStartDist < epsilon  # epsilon adapts to edge angle

Fix parameter validation

  • Allow minZ == maxZ for single-plane slicing (was incorrectly rejected)

Test Coverage

Added 4 cases: near-parallel edges (2e-7 tolerance), tiny distances (1e-10), long edges (200+ units), duplicate prevention.

Example from new tests:

# Edge with vertex 2e-7 from plane now generates segment
vertices = [-1, -1, 0.2,  1, -1, 0.4999998,  1, 1, 0.7]  # V1 ≈ Z=0.5
layers = sliceIntoLayers(mesh, 0.1, 0.5, 0.5)
expect(layers[0].length).toBe(2)  # ✓ Passes with fix

All 507 tests pass (503 existing + 4 new).


References

  • polyslice PR #69 analysis identifying triangle 198780 with missing near-parallel edge
  • See NEAR_PARALLEL_EDGE_FIX.md for detailed technical explanation

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/repos/jgphilpott/polyslice/pulls/69
    • Triggering command: curl -s REDACTED (http block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

We made some good progress upgrading the sliceIntoLayers method with #38 but we still have more work to do. To understand the problem we are trying to fix you can take a look at this PR jgphilpott/polyslice#69 but specifically this comment jgphilpott/polyslice#69 (comment)

You can also read the documents POLYTREE_PERFORMANCE_REPORT.md (https://github.com/jgphilpott/polyslice/pull/69/files#diff-17de4e77d834f0c1469ea64aad91bbf81a8bc2b7e035d037e6b96485b3c8dafa) and BENCHMARK_SUMMARY.md (https://github.com/jgphilpott/polyslice/pull/69/files#diff-7dd895eb123e2b8e6a021e643890496ff59ff174405d6e7e8b65ff3bff72a456).

Do you think you can investigate the issue and apply the recommended fixes for me?


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 3 commits November 16, 2025 17:00
Co-authored-by: jgphilpott <4128208+jgphilpott@users.noreply.github.com>
Co-authored-by: jgphilpott <4128208+jgphilpott@users.noreply.github.com>
Co-authored-by: jgphilpott <4128208+jgphilpott@users.noreply.github.com>
Copilot AI changed the title [WIP] Investigate and fix issues with sliceIntoLayers method Fix sliceIntoLayers missing segments for near-parallel edges Nov 16, 2025
Copilot AI requested a review from jgphilpott November 16, 2025 17:13
Copilot finished work on behalf of jgphilpott November 16, 2025 17:13
@jgphilpott jgphilpott marked this pull request as ready for review November 17, 2025 05:04
@jgphilpott jgphilpott merged commit d79e1de into polytree Nov 17, 2025
1 check passed
@jgphilpott jgphilpott deleted the copilot/investigate-slice-into-layers-issue branch November 17, 2025 05:06
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