abey79 / vpype

The Swiss-Army-knife command-line tool for plotter vector graphics.
https://vpype.readthedocs.io/
MIT License
685 stars 61 forks source link

Simplification fails in my installation (vpype read -s <svg_file>) #729

Open nataquinones opened 3 months ago

nataquinones commented 3 months ago

Problem: The following command fails in my installation: vpype read -s scale_test.svg

I get the following error:

Traceback (most recent call last):
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nquinones/miniforge3/envs/vsketch/lib/python3.12/site-packages/vpype/io.py", line 343, in _process_path
    line = line.view(dtype=complex).reshape(len(line))
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nquinones/miniforge3/envs/vsketch/lib/python3.12/site-packages/numpy/core/_internal.py", line 551, in _view_is_safe
    raise TypeError("Cannot change data-type for object array.")
TypeError: Cannot change data-type for object array.

Solution: I tried to fix it by modifying the following line: https://github.com/abey79/vpype/blob/3d82012cc7afa219cea25570703cd7d82321e931/vpype/io.py#L339 to:

line = LineString(line).simplify(tolerance=quantization)
line = np.array(line.coords, dtype=float)

and that seems to work.

Additional info: I'm using the following versions on a MacOS Ventura 13.6

numpy=1.26.4
vpype==1.14.0
shapely==2.0.4
abey79 commented 3 months ago

This very much looks like a bug–thanks for reporting. Your fix seems correct to me. Could you open a PR?