gfwilliams / svgtoeagle

Online SVG to Eagle CAD converter
MIT License
85 stars 26 forks source link

Do not allow polygon output with 3 points where the first and last points are the same #17

Closed EmbeddedMan closed 3 years ago

EmbeddedMan commented 4 years ago

Eagle considers this an error, and if you try to import a .scr with any lines which have 3 points where the first and last point are the same coordinates Eagle will generate an error message. This must be a new behavior with more recent version of Eagle because I don't think I saw this problem awhile back. It happens with Eagle 9.6.0 and some number of versions before that.

gfwilliams commented 4 years ago

Any news on the fix for this?

EmbeddedMan commented 4 years ago

In running some tests, a simple straight line in Inkscape (say from 0,0 to 2,0) will produce the following script output if the line has no fill:

polygon GND 0.1mm (-0.000000mm 0.132292mm) (2.000000mm 0.132292mm);

or if filled:

polygon GND 0.1mm (-0.000000mm 0.132292mm) (2.000000mm 0.132292mm) (-0.000000mm 0.132292mm);

In both cases, if you try to run the generated script in Eagle, it will generate the "You must enter at least 3 points to define a valid polygon" error. (If this type of line is generated as part of a longer script, the script import will fail at that point and only valid polygons up to that point will end up in the Eagle layer.)

OK, so what's the right thing to do in this case? The user has drawn a line. They want a line on their Eagle layer. But because we are using polygons, and because Eagle won't like a polygon with two or three (where the first and last points match) points, should the svgtoegale script special-case this and create a line (rather than a polygon)? That seems like a good thing to do, but I don't know if it's worth the extra code to detect and handle this special case.

For now, I suggest that any 2 or 3 point polygons should not be output to the canvas or the script output. This will surprise the user, since something they put in their SVG file won't show up in the resulting .scr output, but at least it won't generate an error in Eagle.

Of course, the workaround for the user is to turn the simple line into a path that traces around the outline of the original line (by using 'stroke-to-path' for example), which will then generate a true filled shape which svgtoeagle will handle just fine.

EmbeddedMan commented 4 years ago

Pull Request #22 submitted with fix.

gfwilliams commented 4 years ago

Sorry - just saw your post on this.

So what happened is someone else's pull request broke this by the look of it: https://github.com/gfwilliams/svgtoeagle/commit/9347745901fc299644badc9521810b1a4419773d#diff-eacf331f0ffc35d4b482f1d15a887d3bL314

It always used to produce wires for non-filled elements, and then that got removed and it just started filling everything. I've just asked about the change and we'll see whether it was intentional. I guess in most cases the SVG tool would enforce that there's no fill on simple lines, but it'd be an idea to check and remove the fill anyway