Repository navigation
Fix smooth curve control points and zero-radius arcs in SVG paths - #1868
Merged
blikblum merged 3 commits intoNov 20, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The zero-radius fallback emits a line for coincident arc endpoints instead of omitting the arc as SVG requires, potentially producing a visible dot with round stroke caps.
1 open issue
What changed in this PR
This PR improves SVG path rendering in doc.path() by correcting smooth-curve control points and drawing zero-radius arcs as straight lines.
Changes:
- Track the previous command so smooth curves reflect control points only after compatible curve commands.
- Prevent arc calculations from overwriting curve state and add zero-radius handling.
- Add regression tests and document the fixes.
| File | Description |
|---|---|
| tests/unit/path.spec.js | Adds cases for smooth-curve transitions and zero-radius arcs. |
| lib/path.js | Corrects control-point reflection, isolates arc calculations, and handles zero radii. |
| CHANGELOG.md | Records the SVG path fixes under Unreleased. |
Review effort: Balanced
Comment on lines
+410
to
+411
| // an arc with a zero radius is a straight line | ||
| if (rx === 0 || ry === 0) { |
SVG spec section 9.5.1 says a zero-length arc (start == end) is a no-op. The zero-radius fallback introduced in the smooth-curve fix would emit a lineTo to the same point instead, which produces a visible dot with round stroke caps. Add the coincident endpoint check before the zero-radius check and add a regression test.
Contributor
Author
|
Done in |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

What kind of change does this PR introduce?
Bug fix in the SVG path parser (
doc.path()), three cases where the drawn curve differed from the SVG spec:Causes, in
lib/path.js:arcToSegments()assigned topxandpywithout declaring them, so it overwrote the module's last control point with its own intermediate values. AnSorTright after an arc reflected those.SandTdecided whether to reflect frompx === null, which only lines, moves and closes reset. The spec reflects only after a curve of the same kind (C/SforS,Q/TforT) and uses the current point otherwise. The runners now check the previous command instead, whichapply()records.rxorryof 0 divided by zero and produced no segments. The spec draws a straight line to the end point, whichsolveArc()now does. An arc that ends where it starts is still left out, as before and as the spec says.Checklist:
smooth curvesandarcs with a zero radiuscases intests/unit/path.spec.js. The 6 new cases fail before the change;yarn testpasses (661 tests), and eslint and prettier are clean.