-
Notifications
You must be signed in to change notification settings - Fork 11
Fix degenerate line-arc corner rounding #202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
laylagi
wants to merge
1
commit into
main
Choose a base branch
from
lgh/fix-line-arc-rounding
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -539,7 +539,11 @@ function rounded_corner_segment_line_arc( | |
| T_line = p_line + t_proj * v_line | ||
|
|
||
| # Tangent point on arc: point on arc in direction of fillet center | ||
| cf_dir = (C_f - O) / norm(C_f - O) | ||
| # When C_f ≈ O (fillet_r ≈ arc_r), the direction is undefined | ||
| # and the fillet geometry is degenerate — skip rounding this corner. | ||
| norm_cf_o = norm(C_f - O) | ||
| norm_cf_o < atol && return nothing | ||
| cf_dir = (C_f - O) / norm_cf_o | ||
| T_arc_pt = O + R * cf_dir | ||
|
|
||
| # Construct fillet Turn segment | ||
|
|
@@ -548,13 +552,26 @@ function rounded_corner_segment_line_arc( | |
| # arc_is_outgoing=false: ...arc → T_arc → [fillet] → T_line → line... | ||
| start_pt, end_pt = arc_is_outgoing ? (T_line, T_arc_pt) : (T_arc_pt, T_line) | ||
|
|
||
| d_start = (start_pt - C_f) / norm(start_pt - C_f) | ||
| d_end = (end_pt - C_f) / norm(end_pt - C_f) | ||
| # When tangent points coincide with C_f (fillet_r < atol), | ||
| # the direction vectors are undefined — skip rounding this corner. | ||
| norm_start = norm(start_pt - C_f) | ||
| norm_end = norm(end_pt - C_f) | ||
| (norm_start < atol || norm_end < atol) && return nothing | ||
| d_start = (start_pt - C_f) / norm_start | ||
| d_end = (end_pt - C_f) / norm_end | ||
|
|
||
| cross_val = d_start.x * d_end.y - d_start.y * d_end.x | ||
| dot_val = d_start.x * d_end.x + d_start.y * d_end.y | ||
| dα = atan(cross_val, dot_val) | ||
|
|
||
| # 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 | ||
| # (rounded_corner_segment) by treating the arc edge as a straight line. | ||
| # This requires restructuring the caller (round_to_curvilinearpolygon). | ||
| abs(dα) < min_angle && return nothing | ||
|
|
||
| # Tangent direction at start: perpendicular to radius, rotated by sweep direction | ||
| angle_start = atan(d_start.y, d_start.x) | ||
| α0 = angle_start + sign(dα) * π / 2 | ||
|
|
@@ -1698,7 +1715,16 @@ function _add_curve!(endpoints, seg::Paths.Turn, k::OpenCascade, z; kwargs...) | |
| return k.add_circle_arc.(tags[1:(end - 1)], cen, tags[2:end], -1) | ||
| end | ||
|
|
||
| return k.add_circle_arc(endpoints[1], cen, endpoints[2], -1) | ||
| try | ||
| return k.add_circle_arc(endpoints[1], cen, endpoints[2], -1) | ||
| 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 | ||
|
Comment on lines
+1720
to
+1727
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I worry about hiding real changes to geometry under a |
||
| end | ||
|
|
||
| # Exact *interpolating* cubic BSpline in OCC | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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_anglein line-line rounding (at least approximately).