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

fix(removeOffCanvasPaths): Invalid removal when line path starts with relative move #2086

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ test/cli/output
coverage
.DS_Store
.vscode
.idea
*.log
package-lock.json

Expand Down
12 changes: 10 additions & 2 deletions plugins/_path.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,18 @@ export const intersects = function (path1, path2) {

// Check intersection of every subpath of the first path with every subpath of the second.
return hullNest1.some(function (hull1) {
if (hull1.list.length < 3) return false;
if (hull1.list.length < 3) {
// When there are only two points in the convex hull, add the first point to close the polygon.
// This can happen when the path is only a line.
hull1.list.push(hull1.list[0]);
}

return hullNest2.some(function (hull2) {
if (hull2.list.length < 3) return false;
if (hull2.list.length < 3) {
// When there are only two points in the convex hull, add the first point to close the polygon.
// This can happen when the path is only a line.
hull2.list.push(hull2.list[0]);
}

var simplex = [getSupport(hull1, hull2, [1, 0])], // create the initial simplex
direction = minus(simplex[0]); // set the direction to point towards the origin
Expand Down
13 changes: 13 additions & 0 deletions test/plugins/removeOffCanvasPaths.07.svg.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Should not throw when path starts with relative move and is within the view box

===

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16">
<path d="m10 5-5 5" stroke="#000"></path>
</svg>

@@@

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16">
<path d="m10 5-5 5" stroke="#000"/>
</svg>