fix(convertPathData): introducing isSafeToRemove #2164
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
z
commandsisSafeToUseZ 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
z
that comes right after another command, but what if thez
is 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.