jscad / OpenJSCAD.org

JSCAD is an open source set of modular, browser and command line tools for creating parametric 2D and 3D designs with JavaScript code. It provides a quick, precise and reproducible method for generating 3D models, and is especially useful for 3D printing applications.
https://openjscad.xyz/
MIT License
2.66k stars 515 forks source link

SVG export creates unrelated paths #229

Closed matthijskooijman closed 7 years ago

matthijskooijman commented 7 years ago

I just tested the SVG export briefly and noticed that it seems to create separate paths instead of combined paths when the latter would be more appropriate. I'll explain using an example:

This code:

function main() {
    return CAG.circle({radius: 4}).subtract(CAG.circle({radius: 1}));
}

Creates this rendering:

selection_002

But when exporting this to SVG, it creates two separate paths, which both have a fill set:

selection_003

The left shows the SVG as exported, opened in inkscape. The right shows the same file, but with the fill replaced by a stroke. It also shows that the two paths are separate, each has its own selection box.

When both paths would be combined into a single path (as they are in the original, a single CAG), the filling would be appropriately applied to inside of the bigger circle, but outside of the smaller circle. If you do this in Inkscape by selecting both circles and clicking path->combine, then you get the expected result:

selection_004

The easiest way to implement this is probably to export a single CAG as a single path in the resulting SVG. A better way would be to only do this when needed and turn completely unrelated parts of a drawing into separate paths for easier editing later on. I think this would mean to divide all paths in the CAG into non-overlapping groups and exporting a path for each of these groups, but I'm not quite sure this is sufficient.

z3dev commented 7 years ago

This issue was moved to jscad/io#7