From 634191b3379af5542be7f69640ddd2a50ad3da10 Mon Sep 17 00:00:00 2001 From: Dennis Kugelmann Date: Mon, 11 Nov 2024 21:20:12 +0000 Subject: [PATCH 1/2] fix(removeOffCanvasPaths): Invalid removal when line path starts with relative move --- .gitignore | 2 ++ plugins/_path.js | 12 ++++++++++-- test/plugins/removeOffCanvasPaths.07.svg.txt | 13 +++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 test/plugins/removeOffCanvasPaths.07.svg.txt diff --git a/.gitignore b/.gitignore index 81235e16d..8f753a3bd 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,5 @@ package-lock.json [._]s[a-rt-v][a-z] [._]ss[a-gi-z] [._]sw[a-p] + +.idea/ diff --git a/plugins/_path.js b/plugins/_path.js index d02c46523..30d3eba3e 100644 --- a/plugins/_path.js +++ b/plugins/_path.js @@ -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 diff --git a/test/plugins/removeOffCanvasPaths.07.svg.txt b/test/plugins/removeOffCanvasPaths.07.svg.txt new file mode 100644 index 000000000..26782d6d7 --- /dev/null +++ b/test/plugins/removeOffCanvasPaths.07.svg.txt @@ -0,0 +1,13 @@ +Should not throw when path starts with relative move and is within the view box + +=== + + + + + +@@@ + + + + From 0cfb4eef9ce35681471cbc29f6f7d7fe6379f19e Mon Sep 17 00:00:00 2001 From: Dennis Kugelmann Date: Mon, 11 Nov 2024 21:25:46 +0000 Subject: [PATCH 2/2] Update .gitignore --- .gitignore | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 8f753a3bd..71ca9f95d 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ test/cli/output coverage .DS_Store .vscode +.idea *.log package-lock.json @@ -24,5 +25,3 @@ package-lock.json [._]s[a-rt-v][a-z] [._]ss[a-gi-z] [._]sw[a-p] - -.idea/