From 204a1d6d767c1135b44359772c4185b22c80054f Mon Sep 17 00:00:00 2001 From: Natalia Quinones-Olvera Date: Mon, 20 May 2024 19:23:18 -0400 Subject: [PATCH 1/3] Fix TypeError in _process_path for curved elements simplification Refactored the line simplification in _process_path to avoid the numpy TypeError caused by changing data-type for an object array. Replaced np.array(LineString(line).simplify(tolerance=quantization)) with separate LineString simplification and conversion of its coordinates to a numpy array. This ensures the correct handling. --- vpype/io.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/vpype/io.py b/vpype/io.py index 7bf0e97e..d1e3ded1 100644 --- a/vpype/io.py +++ b/vpype/io.py @@ -336,7 +336,8 @@ def _process_path(path): line = seg.npoint(np.linspace(0, 1, step)) if simplify: - line = np.array(LineString(line).simplify(tolerance=quantization)) + line = LineString(line).simplify(tolerance=quantization) + line = np.array(line.coords, dtype=float) line = line.view(dtype=complex).reshape(len(line)) From 78336eab5c3551bf1d24ab6cfa10151f74e06d3d Mon Sep 17 00:00:00 2001 From: Antoine Beyeler Date: Mon, 3 Jun 2024 10:40:31 +0200 Subject: [PATCH 2/3] update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 70898614..629c31d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,7 @@ Release date: UNRELEASED ### Bug fixes -* ... +* Fixed a crash when reading SVG with simplify active (via the `read --simplify` command or the read APIs with `simplify=True`) (thanks to @nataquinones) (#732) ## 1.14 From f4c9f0490e70ccf2f0d984ebf4b5a921852bd9c9 Mon Sep 17 00:00:00 2001 From: Antoine Beyeler Date: Mon, 3 Jun 2024 10:42:20 +0200 Subject: [PATCH 3/3] added test --- tests/test_commands.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_commands.py b/tests/test_commands.py index 4fa7fe13..25cc2f9e 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -43,6 +43,7 @@ class Command: Command("circle 0 0 1"), Command("ellipse 0 0 2 4"), Command(f"read '{EXAMPLE_SVG}'", preserves_metadata=False), + Command(f"read -s '{EXAMPLE_SVG}'", preserves_metadata=False), Command(f"read -m '{EXAMPLE_SVG}'", preserves_metadata=False), Command(f"read -a stroke '{EXAMPLE_SVG}'", preserves_metadata=False), Command("write -f svg -"),