[OpenSCAD] sumUp() to Replace Difference() (in most cases)

nop head nop.head at gmail.com
Fri Oct 7 04:14:37 EDT 2016


Interesting approach. Here is a more concise version noting that
children([0:$children-1]) is the same as children() and children already
come unioned:

module sumUp(showRemovedOnly=false)
{
    $summingUp=true;
    if(!showRemovedOnly)
    {
        difference()
        {
            for($beforeRemoving=true)
                children();

            for($removing = true)
                children();
        }
        children();
    }
    if(showRemovedOnly)
        for($removing = true)
            children();
}

I think the reason it is slower is that all the negative objects get
unioned and passed as a single argument to difference whereas with the
normally coded version difference can have lots of subtrahends that don't
get pre unioned. I would think that for the same reason for loops will be
slower than repetitions when used in a subtrahend.

Perhaps there could be a simple tree optimisation after compilation and
before rendering that looks for redundant groups and unions under
difference nodes and where it is the subtrahend remove them and hoist the
children upwards.

On 7 October 2016 at 01:57, MichaelAtOz <oz.at.michael at gmail.com> wrote:

> Peter, interesting approach, will be a useful technique elsewhere too.
> Thanks
> for sharing.
>
> You should add a licence to github, difficult to use a library if you don't
> know the copyright implications.
> (I recently found http://www.wtfpl.net/, otherwise  cc0
> <https://creativecommons.org/share-your-work/public-domain/cc0/ >   or
> CC-BY etc <https://creativecommons.org/licenses/>  )
>
>
>
> -----
> Admin - PM me if you need anything, or if I've done something stupid...
>
> Unless specifically shown otherwise above, my contribution is in the
> Public Domain; to the extent possible under law, I have waived all
> copyright and related or neighbouring rights to this work. Obviously
> inclusion of works of previous authors is not included in the above.
>
> The TPP is no simple “trade agreement.”   Fight it!
> http://www.ourfairdeal.org/   time is running out!
> --
> View this message in context: http://forum.openscad.org/
> sumUp-to-Replace-Difference-in-most-cases-tp18580p18589.html
> Sent from the OpenSCAD mailing list archive at Nabble.com.
>
> _______________________________________________
> OpenSCAD mailing list
> Discuss at lists.openscad.org
> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscad.org/pipermail/discuss_lists.openscad.org/attachments/20161007/80a034f7/attachment-0002.html>


More information about the Discuss mailing list