SolidCode / SolidPython

A python frontend for solid modelling that compiles to OpenSCAD
1.11k stars 173 forks source link

avoid union, intersection and difference repetitions #75

Closed larchuto closed 1 year ago

larchuto commented 7 years ago

Avoid useless repetition of unions/differences or intersections.

test code (union case):

part  = union()
for i in range(1,4,1):
    part += cube(i)

scad_render_to_file(part, "part.scad")

output code without fix:

union() {
    union() {
        union() {
            union();
            cube(size = 1);
        }
        cube(size = 2);
    }
    cube(size = 3);
}

output code with fix:

union() {
    cube(size = 1);
    cube(size = 2);
    cube(size = 3);
}
larchuto commented 7 years ago

Ok, found out that since I was using the version that comes with pip I fixed something partially fixed by #65… (my apologize) But my PR may not be as useless as it seems because in cases like a = b + c where c is a union but not b there is still a uselless union() repetition with the actual code base.

example:

part  = union() (cube(1), cube(2))
final_part = cylinder(d=5,h=10) + part

scad_render_to_file(final_part, "cylinder_pusher(generated).scad")

output code:

union() {
    cylinder(d = 5, h = 10);
    union() {
        cube(size = 1);
        cube(size = 2);
    }
}