scottbez1 / splitflap

DIY split-flap display
https://scottbez1.github.io/splitflap
Other
3.09k stars 257 forks source link

The duplicate svg line removal code has a problem #115

Open trapgate opened 3 years ago

trapgate commented 3 years ago

The code that removes duplicate lines from svg paths in 3d/scripts/svg_processor.py has a problem. When I run generate_2d.py, the output in combined.svg looks like this:

Screenshot from 2021-01-05 01-42-08

The diagonal lines cutting across some of the parts are caused by trimming lines immediately preceding Close elements from some of the paths. When the svg.path package parses an svg path and returns a representation, Close elements are returned with a start and end point, just like a Line element. But the XML representation of Close is just a Z, which is interpreted by svg editors as, 'draw a line from the current point to the location of the most recent Move element in this path.' As a result, even though the path removal code was updating the start or end points for the Close element after it removed the preceding line, those points were just being ignored when svg.path regenerated the XML for the altered path.

I have a fix for this problem, which is just to turn all Close elements into Line elements when processing paths. The resulting .svg files have worked fine in both svg editors (inkscape and Affinity Design, at least), and when used to drive my Glowforge. I'll submit a PR with those changes in a few minutes.

dmadison commented 3 years ago

I think this is caused by a version mismatch for the svg_path package dependency. The repository is still using version 2.2 of svg_path (3d/scripts/requirements.txt), which doesn't have this issue.

Looking at the project history on PyPi it looks like support for Move commands was added in version 3.0. I'm not sure if there are any other reasons to stay on the old package, but you'd have to update the dependency version in your PR for the build to complete.

trapgate commented 3 years ago

I think that's right - it makes some sense that without move support, the svg library would probably have been translating Close into Line, though I'd have to trace through the code with the old library installed to be sure.

I took a slightly nonstandard route to get here - I ported everything to python3, and completely forgot to check for the older version of svg.path once I had that working.