From 3a3de806aedd5b96db5189fa259a30ebecc808b1 Mon Sep 17 00:00:00 2001 From: Jonathan Neuhauser Date: Thu, 10 Feb 2022 20:06:34 +0100 Subject: [PATCH] fix reverse of move command --- inkex/paths.py | 4 ++-- tests/test_inkex_paths.py | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/inkex/paths.py b/inkex/paths.py index 301b740b..39059017 100644 --- a/inkex/paths.py +++ b/inkex/paths.py @@ -419,7 +419,7 @@ class Move(AbsolutePathCommand): raise ValueError("Move segments can not be changed into curves.") def reverse(self, first, prev): - return Move(first.x, first.y) + return Move(prev.x, prev.y) class move(RelativePathCommand): # pylint: disable=invalid-name @@ -440,7 +440,7 @@ class move(RelativePathCommand): # pylint: disable=invalid-name return Move(prev.x + self.dx, prev.y + self.dy) def reverse(self, first, prev): - return move(first.x, first.y) + return move(prev.x - first.x, prev.y - first.y) class ZoneClose(AbsolutePathCommand): diff --git a/tests/test_inkex_paths.py b/tests/test_inkex_paths.py index 7c962029..3bbb8bce 100644 --- a/tests/test_inkex_paths.py +++ b/tests/test_inkex_paths.py @@ -749,6 +749,26 @@ class PathTest(TestCase): ret = ret.reverse() self._assertPath(ret, "M 500 500 q -150 -150 -400 -250") + def test_reverse_multiple_subpaths(self): + """Test for https://gitlab.com/inkscape/extensions/-/issues/445. First two + examples are from the issue""" + ret = Path("M 128,64 L 128,128 M 128,196 L 128,256").reverse() + self._assertPath(ret, "M 128 256 L 128 196 M 128 128 L 128 64") + + ret = Path("M 128,64 L 128,128 m 128,196 L 128,256").reverse() + self._assertPath(ret, "M 128 256 L 256 324 m -128 -196 L 128 64") + + # More complex example with absolute and relative move commands + ret = Path( + "m 58,88 c -10,2 3,13 10,4 z M 32,67 c 14,-5 23,-3 35,7 m 2,-21 c" + "10,11 20,19 34,11 M 24,43 c 23,-14 18,-5 39,4" + ).reverse() + self._assertPath( + ret, + "m 63 47 c -21 -9 -16 -18 -39 -4 M 103 64 c -14 8 -24 0 -34 -11 " + "m -2 21 c -12 -10 -21 -12 -35 -7 M 58 88 l 10 4 c -7 9 -20 -2 -10 -4", + ) + class SuperPathTest(TestCase): """Super path tests for testing the super path class""" -- GitLab