diff --git a/plugins/convertPathData.js b/plugins/convertPathData.js
index 1f032b3e9..c950340ec 100644
--- a/plugins/convertPathData.js
+++ b/plugins/convertPathData.js
@@ -600,6 +600,7 @@ function filters(
// to get closer to absolute coordinates. Sum of rounded value remains same:
// l .25 3 .25 2 .25 3 .25 2 -> l .3 3 .2 2 .3 3 .2 2
if (precision !== false) {
+ // Correct for accumulated error
if (
command === 'm' ||
command === 'l' ||
@@ -624,6 +625,21 @@ function filters(
// @ts-expect-error
data[6] += item.base[1] - relSubpoint[1];
}
+ // Correct l commands heading home
+ if (
+ command == 'l' &&
+ prev.command != 'M' &&
+ prev.command != 'm' &&
+ // @ts-expect-error
+ Math.abs(item.coords[0] - pathBase[0]) < error &&
+ // @ts-expect-error
+ Math.abs(item.coords[1] - pathBase[1]) < error
+ ) {
+ // @ts-expect-error
+ data[0] = pathBase[0] - item.base[0];
+ // @ts-expect-error
+ data[1] = pathBase[1] - item.base[1];
+ }
roundData(data);
if (command == 'h') {
@@ -877,10 +893,8 @@ function filters(
(command === 'l' || command === 'h' || command === 'v')
) {
if (
- // @ts-expect-error
- Math.abs(pathBase[0] - item.coords[0]) < error &&
- // @ts-expect-error
- Math.abs(pathBase[1] - item.coords[1]) < error
+ Math.abs(pathBase[0] - relSubpoint[0]) < error &&
+ Math.abs(pathBase[1] - relSubpoint[1]) < error
) {
command = 'z';
data = [];
@@ -918,7 +932,7 @@ function filters(
prevQControlPoint = reflectPoint(qControlPoint, item.base);
} else {
// @ts-expect-error
- prevQControlPoint = item.coords;
+ prevQControlPoint = relSubpoint.slice();
}
} else {
prevQControlPoint = undefined;
diff --git a/test/plugins/convertPathData.39.svg.txt b/test/plugins/convertPathData.39.svg.txt
new file mode 100644
index 000000000..bec5ca274
--- /dev/null
+++ b/test/plugins/convertPathData.39.svg.txt
@@ -0,0 +1,17 @@
+Proper, post-rounding coordinate system (1, 1), not pre-rounding (0.8, 0.8), should be used when converting going home to z
+
+===
+
+
+
+@@@
+
+
+
+@@@
+
+{ "floatPrecision": 0 }