Skip to content

Commit

Permalink
fix(removeOffCanvasPaths): Invalid removal when line path starts with…
Browse files Browse the repository at this point in the history
… relative move
  • Loading branch information
IchordeDionysos committed Nov 11, 2024
1 parent c372b36 commit 634191b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ package-lock.json
[._]s[a-rt-v][a-z]
[._]ss[a-gi-z]
[._]sw[a-p]

.idea/
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>

0 comments on commit 634191b

Please sign in to comment.