[OpenSCAD] When modules are cached?

Ronaldo Persiano rcmpersiano at gmail.com
Fri Nov 1 14:12:12 EDT 2019


Thank you, Michael, for expending your time on that. I have not gotten any
crash with version 2019.01-RC4. I guess it will depend on the
available memory to display the CSG tree.

As we say in Portuguese,I have shot what I saw and hit what I haven't.
Besides, the code I have presented was a failed attempt to illustrate with
a small code the problem I am having in my original code. Here is a better
illustration although not as simple.

I have devised the following code to find the bounding box of a 2D object:

module bbox()
  intersection() {
    ext = pow(2,16);
    hull() {
      translate([ ext,    0]) children();
      translate([-ext,    0]) children();
    }
    hull() {
      translate([    0, ext]) children();
      translate([    0,-ext]) children();
    }
  }


It returns the bounding box (a rectangle) of 2D objects with points away
from the origin less than pow(2,15) (or something like that).

It is rather efficient even with complex 2D geometries:

n = 270;

text = S(n);
font = "Palatino Linotype:style=Italic";

// just a complex 2D model
module T() resize([100,0])
text(text,font=font,valign="center",halign="center");

// creates a string with n capital S
function S(n,s="") = n<=0? s: S(n-1,str(s,"S"));

T();

bbx() T();


But things get a bit convoluted when bbx() is called many times even over
the same object:

module complexbbx(p)
  intersection(){
    render() bbox() children();
    bbox() children();
    bbox() children();
    bbox() children();
    bbox() children();
    bbox() children();
    bbox() children();
    bbox() children();
    bbox() children();
  }

  complexbbx([1,1]) T();


This last code requires 18 sec on my machine while a simple call to bbx()
T() requires 2 sec.

In the next code,  bbox() children() is called just once but the
intersection of 9 squares is still done:

module complexbbx2(p)
  intersection(){
    render() bbox() children();
    square([100,10],center=true);
    square([100,10],center=true);
    square([100,10],center=true);
    square([100,10],center=true);
    square([100,10],center=true);
    square([100,10],center=true);
    square([100,10],center=true);
    square([100,10],center=true);
  }


Now,  complexbbx2([1,1]) T()  requires only 2 sec to run which shows 9
rectangle intersection is negligible when compared to bbox(). It also shows
that the bbox() children() in  complexbbx() is not being cached but instead
computed again and again.

So, the question in this   thread subject remains unanswered. Is there any
way I could enforce that bbox() children() in  complexbbx() be cached?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscad.org/pipermail/discuss_lists.openscad.org/attachments/20191101/d283cb2e/attachment.html>


More information about the Discuss mailing list