Skip to content
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

Near-circular arcs generate empty paths when rounding is used #38

Open
jasondavies opened this issue Oct 10, 2024 · 1 comment · May be fixed by #39
Open

Near-circular arcs generate empty paths when rounding is used #38

jasondavies opened this issue Oct 10, 2024 · 1 comment · May be fixed by #39

Comments

@jasondavies
Copy link

jasondavies commented Oct 10, 2024

I encountered this edge case when using d3-shape:

d3.arc().innerRadius(55).outerRadius(75).startAngle(0).endAngle(6.283179980513967)()
"M0,-75A75,75,0,1,1,0,-75L0,-55A55,55,0,1,0,0,-55Z"

Now, d3.arc uses digits(3) by default, which means it's using d3-path with rounding.

Since there's no ambiguity when using d3-path's arc for a complete or near-circle (unlike arcTo which is undefined for coincident start/end points), and complete circular arcs are supported, I think this is a bug in d3-path, rather than d3-shape.

I traced it back to the rounding used in d3-path: nothing special is done to check for coincident points after rounding when drawing arcs.

jasondavies added a commit to jasondavies/d3-path that referenced this issue Oct 10, 2024
When rounding is used, it's possible for `arc()` to generate empty arcs
in the case where the start and end points are almost coincident, and
become coincident after rounding is applied.

This adds a check for coincident points after rounding is applied, and
splits the arc into two if coincident points are detected.

Fixes d3#38.
jasondavies added a commit to jasondavies/d3-path that referenced this issue Oct 10, 2024
When rounding is used, it's possible for `arc()` to generate empty arcs
in the case where the start and end points are almost coincident, and
become coincident after rounding is applied.

This adds a check for coincident points after rounding is applied, and
splits the arc into two if coincident points are detected.

Fixes d3#38.
@jasondavies
Copy link
Author

Arguably it's simple enough to work around by disabling rounding for d3.arc, in which case it's probably fine for d3-path to rely on the 2π angle check and generate two arc commands as it does currently. However, rounding is on by default for d3.arc.

jasondavies added a commit to jasondavies/d3-shape that referenced this issue Oct 17, 2024
This is the edge case with endAngle close to 2π (with d3-arc's default
rounding of digits=3) that led to the fix to d3-path.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

1 participant