Skip to content

Commit 86d5040

Browse files
authoredNov 28, 2023
fix(convertPathData): account for error in z conversions (#1842)
1 parent 3f2bcb4 commit 86d5040

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed
 

‎plugins/convertPathData.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -685,8 +685,12 @@ function filters(
685685
(isSafeToUseZ || next?.command === 'Z' || next?.command === 'z') &&
686686
(command === 'l' || command === 'h' || command === 'v')
687687
) {
688-
// @ts-ignore
689-
if (pathBase[0] === item.coords[0] && pathBase[1] === item.coords[1]) {
688+
if (
689+
// @ts-ignore
690+
Math.abs(pathBase[0] - item.coords[0]) < error &&
691+
// @ts-ignore
692+
Math.abs(pathBase[1] - item.coords[1]) < error
693+
) {
690694
command = 'z';
691695
data = [];
692696
}
@@ -839,9 +843,9 @@ function filters(
839843
params.removeUseless &&
840844
isSafeToUseZ &&
841845
// @ts-ignore
842-
item.base[0] === item.coords[0] &&
846+
Math.abs(item.base[0] - item.coords[0]) < error / 10 &&
843847
// @ts-ignore
844-
item.base[1] === item.coords[1]
848+
Math.abs(item.base[1] - item.coords[1]) < error / 10
845849
)
846850
return false;
847851

‎test/coa/testSvg/test.1.svg

+1-1
Loading

‎test/coa/testSvg/test.svg

+1-1
Loading

‎test/plugins/convertPathData.28.svg

+9
Loading

0 commit comments

Comments
 (0)
Please sign in to comment.