Skip to content

Fix degenerate line-arc corner rounding#202

Open
laylagi wants to merge 1 commit intomainfrom
lgh/fix-line-arc-rounding
Open

Fix degenerate line-arc corner rounding#202
laylagi wants to merge 1 commit intomainfrom
lgh/fix-line-arc-rounding

Conversation

@laylagi
Copy link
Copy Markdown
Contributor

@laylagi laylagi commented Apr 15, 2026

Add guards in rounded_corner_segment_line_arc and rounded_corner_line_arc for three degenerate cases that crash during CurvilinearPolygon rounding:

  1. Fillet center coincides with arc center (norm(C_f - O) < atol), producing NaN from the direction vector division
  2. Tangent points collapse onto fillet center (fillet_r < atol), producing NaN from zero-length direction vectors
  3. Fillet sweep angle below min_angle, producing arcs too small for GMSH to distinguish from a line (I'm not sure if this is the best approach)

All three return nothing (skip rounding, leave corner sharp).

Add guards in rounded_corner_segment_line_arc and rounded_corner_line_arc for three degenerate cases that crash during CurvilinearPolygon rounding:
1. Fillet center coincides with arc center (norm(C_f - O) < atol), producing NaN from the direction vector division                                                                                     2. Tangent points collapse onto fillet center (fillet_r < atol),  producing NaN from zero-length direction vectors                                                                                     3. Fillet sweep angle below min_angle, producing arcs too small  for GMSH to distinguish from a line

All three return nothing (skip rounding, leave corner sharp).
@laylagi laylagi added the bug Something isn't working label Apr 15, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 15, 2026

Codecov Report

❌ Patch coverage is 81.81818% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/curvilinear.jl 77.77% 2 Missing ⚠️
src/solidmodels/render.jl 84.61% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown
Member

@gpeairs gpeairs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good, one small comment and a question about the TODO.

Comment thread src/solidmodels/render.jl
# When the fillet sweep angle is tiny, the arc sagitta
# (r·(1 - cos(dα/2))) is sub-nanometer — GMSH can't distinguish it from
# a line and rejects it. Skip rounding this corner.
# TODO: instead of skipping, fall through to line-line rounding
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this TODO needed? If I understand the geometry right, this should also be skipped for being below min_angle in line-line rounding (at least approximately).

Comment thread src/solidmodels/render.jl
Comment on lines +1720 to +1727
catch e
# Arc too small or degenerate for GMSH — fall back to straight line.
# This typically happens with fillet arcs at nearly-tangent corners
# where the sagitta is below GMSH's internal tolerance.
@debug "addCircleArc failed, falling back to line" p0 = seg.p0 r = seg.r α = seg.α α0 =
seg.α0
return k.add_line(endpoints[1], endpoints[2])
end
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I worry about hiding real changes to geometry under a @debug message. I'd suggest making sure it's not some other error:

catch e
    if contains(string(e), <substring of expected error message text>)
        @debug ...
        return k.add_line(endpoints[1], endpoints[2])
    end
    rethrow()
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants