Cost for Boolean Operators with One Operand

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Cost for Boolean Operators with One Operand

ClintGoss
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 <[hidden email]>
--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
-- Clint Goss <clint@goss.com>
Reply | Threaded
Open this post in threaded view
|

Re: Cost for Boolean Operators with One Operand

doug.moen
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 <[hidden email]> 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 &[hidden email]&gt;
--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Cost for Boolean Operators with One Operand

ClintGoss
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;[hidden email]&gt;
--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
-- Clint Goss <clint@goss.com>
Reply | Threaded
Open this post in threaded view
|

Re: Cost for Boolean Operators with One Operand

RevarBat
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 <[hidden email]> 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;[hidden email]&gt;
> --
> Sent from: http://forum.openscad.org/
>
> _______________________________________________
> OpenSCAD mailing list
> [hidden email]
> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org