the fair gds editor RandomBoxArray
Please Sign in

Random Box Array

The macro generates an array of box. The boxes are scrambled. Boxes are check for overlapping with other boxes.

Download: randomArray.layout

random-box-array.png

   1 #!/usr/bin/layout
   2 #name=random array
   3 #help=generates a random array of boxes
   4 
   5 int main(){
   6 //++++++++++++++++++++++++++++++++++++++
   7 // enter values here:
   8   int sizeX=1000;
   9   int sizeY=1000;
  10   int width=12;
  11   int height=16;
  12   int count=1000;
  13   int layer =11;
  14   int space=5;
  15 //++++++++++++++++++++++++++++++++++++++
  16 // the macro requires a empty cell to find the nearest element correctly
  17   layout->drawing->newCell();
  18   int wh=width/2+space;
  19   int hh=height/2+space;
  20   int i;
  21   for ( i=count;i>0;i--){
  22    bool found=false;
  23    int x;
  24    int y;
  25    int try=0;
  26    while (!found){
  27     try++;
  28     x=stdlib::rand()%sizeX;
  29     y=stdlib::rand()%sizeY;
  30     point p; p.set(x,y);
  31     elementList *e=layout->drawing->currentCell->nearestElement(p);
  32     if (e==NULL) found=true;
  33     else {
  34       // checks, if conflicts with existing box
  35       pointArray pa=e->thisElement->getPoints();
  36       if (pa.point(0).x()>(x+wh)) found=true;
  37       else if (pa.point(1).x()<(x-wh)) found=true;
  38       else if (pa.point(0).y()<(y-hh)) found=true;
  39       else if (pa.point(1).y()>(y+hh)) found=true;
  40     }
  41      // no free space found
  42      if (try>1000) return 1;
  43     }
  44     layout->drawing->currentCell->addBox(x-width/2,y-height/2,width,height,layer);
  45   }
  46  layout->drawing->scaleFull();
  47 }

See also


CategoryMacro


RandomBoxArray (last edited 2011-03-31 17:44:42 by dslb-088-064-003-217)