SolidCode / SolidPython

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

merged operations for +-* #65

Closed scifuentes closed 7 years ago

scifuentes commented 7 years ago

Consecutive sums/subtractions/multiplications are merged into the same transformation instead of nested as independent ones eg: cube(1)+cube(2)+cube(3)

current, nested:

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

proposed, merged:

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

While it do not seems to have any notable impact on the render time at OpenScad for the difference and intersection transforms it have a considerable impact for the unions: On the simple case below it cut the render time to a third, on other cases the nested code just hanged there for many minutes -till patience run out actually- while it took ~1min for the merged code to render

Simple test case, render time: union :

scene = cube(2)
for i in range(100):
    scene += translate([i,i,0])(cube(2))

OpenScad console output ...

evandrone commented 7 years ago

That's a really interesting optimization! It may take me a few days to take a look at this as deeply as it deserves, but congratulations for speeding things up so much!

evandrone commented 7 years ago

Sorry I left this for so long. This is great!

etjones commented 7 years ago

Don't know if you're getting notified there, @conorpp, but I opened Issue #79 to handle this. Haven't been able to duplicate this problem yet, but would appreciate input over at #79 if you can help with bug duplication. Cheers!

conorpp commented 7 years ago

Hey @etjones, sorry, looks like I missed a step. This should duplicate the bug (tested this time).

    r = cube(10)

    r -= cube(1)  # missed step

    p = cube(10)
    p = r * p

    r -= p

    scad_render(r)