abey79 / vpype

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

optimization by --linemerge #34

Closed ithinkido closed 4 years ago

ithinkido commented 4 years ago

When using --linemerge to connect multiple line segments to one single line, the output still contains the old line nodes, and the result is one line, but with multiple nodes. when plotting a line like this the plotter slows down and speed up for each node and the result is a kind of 'ghost' line in the plot. Is it possible to output a mergerd line as a single line between a start and end node, creating the longest possibe single straight line? image image linetest.zip

abey79 commented 4 years ago

linemerge doesn't attempt to simplify lines. When two lines' endings are close together, they are concatenated and their endings replaced by the mean point, so two collinear 1-segment lines are converted to a single, 3-point line. You want to use linesimplify after linemerge to remove those spurious points.

(Note: the Axidraw isn't at all affected by spurious points -- I'm surprised it's the case for other plotters.)

ithinkido commented 4 years ago

Have I understood this correctly, linemerge will produce a 3- point line (start , mean, end), and linesimplify will remove the mean point and produce a 2-point line ( start and end)? Just tried with: vpype read 1.svg linemerge --tolerance 0.1mm linesimplify linesort write --layer-label Pen%d --page-format 191x272mm 1_opt.svg and I still have what looks like the mean point. Is there a way to output only start and end point lines?

abey79 commented 4 years ago

On second look, I'm seeing issues with linemerge on your file, apparently an issue in Shapely. I've pushed a quick fix that seems to address the situation.

This is what happens now:

vpype read 1.svg linemerge show -dac -u mm

image

vpype read 1.svg linemerge linesimplify show -dac -u mm

image

Side note: while looking into that, I got confused with what happens inside the windows, until I realised that there are overlapping lines there. Is that on purpose?

ithinkido commented 4 years ago

yes the double lines are wanted. I just tried out the new version and it is perfect. Thanks, this is going to be very helpfull

abey79 commented 4 years ago

https://github.com/Toblerity/Shapely/issues/911