discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Cost for Boolean Operators with One Operand

C
ClintGoss
Thu, Jun 14, 2018 11:56 AM

I am concerned that there is a cost to using a Boolean operator with a single
operand ...

My model is large and complex (pushing 10,000 lines) and I often use
switches for testing and optional components. I have a lot of:

union-difference-intersection () {
A();
if (switchVariable) B();
}

Would there be a rendering speed cost? (it's slow enough already)

Is there added complexity in the generated STL?  (it's big enough already)

I could change to:

if (switchVariable)
union-difference-intersection () { A(); B(); }
} else {
A();
}

... but that would make the code far less readable  (it's dense enough
already).

Thanks for any feedback or even musings on this ...


-- Clint Goss <clint@goss.com>

Sent from: http://forum.openscad.org/

I am concerned that there is a cost to using a Boolean operator with a single operand ... My model is large and complex (pushing 10,000 lines) and I often use switches for testing and optional components. I have a lot of: union-difference-intersection () { A(); if (switchVariable) B(); } Would there be a rendering speed cost? (it's slow enough already) Is there added complexity in the generated STL? (it's big enough already) I could change to: if (switchVariable) union-difference-intersection () { A(); B(); } } else { A(); } ... but that would make the code far less readable (it's dense enough already). Thanks for any feedback or even musings on this ... ----- -- Clint Goss &lt;clint@goss.com&gt; -- Sent from: http://forum.openscad.org/
DM
doug moen
Thu, Jun 14, 2018 12:14 PM

I just looked at the source code. The function
GeometryEvaluator::applyToChildren3D

contains the following:

// Only one child -> this is a noop

if (children.size() == 1) return ResultObject(children.front().second);

So I would say that union, intersection and difference with a single shape
argument are optimized to just return the shape.

On 14 June 2018 at 07:56, ClintGoss clint@goss.com wrote:

I am concerned that there is a cost to using a Boolean operator with a
single
operand ...

My model is large and complex (pushing 10,000 lines) and I often use
switches for testing and optional components. I have a lot of:

union-difference-intersection () {
A();
if (switchVariable) B();
}

Would there be a rendering speed cost? (it's slow enough already)

Is there added complexity in the generated STL?  (it's big enough already)

I could change to:

if (switchVariable)
union-difference-intersection () { A(); B(); }
} else {
A();
}

... but that would make the code far less readable  (it's dense enough
already).

Thanks for any feedback or even musings on this ...


-- Clint Goss <clint@goss.com>

Sent from: http://forum.openscad.org/


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

I just looked at the source code. The function GeometryEvaluator::applyToChildren3D contains the following: // Only one child -> this is a noop if (children.size() == 1) return ResultObject(children.front().second); So I would say that union, intersection and difference with a single shape argument are optimized to just return the shape. On 14 June 2018 at 07:56, ClintGoss <clint@goss.com> wrote: > I am concerned that there is a cost to using a Boolean operator with a > single > operand ... > > My model is large and complex (pushing 10,000 lines) and I often use > switches for testing and optional components. I have a lot of: > > union-difference-intersection () { > A(); > if (switchVariable) B(); > } > > Would there be a rendering speed cost? (it's slow enough already) > > Is there added complexity in the generated STL? (it's big enough already) > > I could change to: > > if (switchVariable) > union-difference-intersection () { A(); B(); } > } else { > A(); > } > > ... but that would make the code far less readable (it's dense enough > already). > > Thanks for any feedback or even musings on this ... > > > > > ----- > -- Clint Goss &lt;clint@goss.com&gt; > -- > Sent from: http://forum.openscad.org/ > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >
C
ClintGoss
Thu, Jun 14, 2018 1:34 PM

Thank you so much Doug!

You've not on answered the question, but made me realize that (of course!) I
could simply read the source code (Of Course!). Guess years of using closed
apps will make you forget that.


-- Clint Goss <clint@goss.com>

Sent from: http://forum.openscad.org/

Thank you so much Doug! You've not on answered the question, but made me realize that (of course!) I could simply read the source code (Of Course!). Guess years of using closed apps will make you forget that. ----- -- Clint Goss &lt;clint@goss.com&gt; -- Sent from: http://forum.openscad.org/
RD
Revar Desmera
Fri, Jun 15, 2018 6:30 AM

The if() statement, when its test evaluates false, returns an empty object. So you actually are passing two objects.  Really, union(), difference(), and intersection() should all have shortcuts for that too.

  • Revar

On Jun 14, 2018, at 6:34 AM, ClintGoss clint@goss.com wrote:

Thank you so much Doug!

You've not on answered the question, but made me realize that (of course!) I
could simply read the source code (Of Course!). Guess years of using closed
apps will make you forget that.


-- Clint Goss <clint@goss.com>

Sent from: http://forum.openscad.org/


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

The if() statement, when its test evaluates false, returns an empty object. So you actually are passing two objects. Really, union(), difference(), and intersection() should all have shortcuts for that too. - Revar > On Jun 14, 2018, at 6:34 AM, ClintGoss <clint@goss.com> wrote: > > Thank you so much Doug! > > You've not on answered the question, but made me realize that (of course!) I > could simply read the source code (Of Course!). Guess years of using closed > apps will make you forget that. > > > > ----- > -- Clint Goss &lt;clint@goss.com&gt; > -- > Sent from: http://forum.openscad.org/ > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org