fix(convertPathData): introducing isSafeToRemove#2164
Merged
Conversation
GreLI
reviewed
Aug 10, 2025
GreLI
reviewed
Aug 10, 2025
Member
|
It seems that this PR kills the optimization case when there is no stroke. Which was the goal at the first place. |
Collaborator
Author
What makes you say this? if (!maybeHasStroke) {
return true;
}literally means "if there is no stroke, it is always safe to optimize". All the previous test cases also pass. |
folknor
added a commit
to folknor/svgo
that referenced
this pull request
Feb 18, 2026
- Handle consecutive t commands properly (svg#2156) svg#2156 - Use relSubpoint for accurate post-rounding coordinates (svg#2157) svg#2157 - Introduce isSafeToRemove for smarter stroke-linecap handling (svg#2164) svg#2164 Note: reverted svg#2157's z-removal change (relSubpoint is already reset to pathBase when z is processed, making the comparison always true). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
Removing useless commands: a tricky and inconsistent business. SVGO currently uses two approaches:
!maybeHasStrokeAndLinecap for the purpose of removing useless line commands
This works decently. It allows for removing useless lines, while not removing dots.
Flaw: Even in a path with linecaps, if there are "dot" commands after the first move, they wouldn't render at all and should be removed. They currently aren't.
isSafeToUseZ for the purpose of removing useless
zcommandsisSafeToUseZ is defined as either having no stroke or having a all-round stroke. When that's true, a line home and a z command render the same way, and can be exchanged or removed.
Flaw: This works great when removing a redundant
zthat comes right after another command, but what if thezis the first move (for the purpose of creating a dot)? Then it's incorrectly removed. This is shown in convertPathData removes valid paths #2158 and old issue killing most content is back #2163.This PR introduces isSafeToRemove to help. It's worth reading through the code, but the TLDR is that it uses a more sane method, categorizing the path into non-stroked, stroked + first draw command, and stroked but non-first command, and using fitting behavior in each case.
Fixes #2158 and fixes #2163.