+function Rectangle_corners(c0, sz) =
+ // returns the corners of a rectangle from c0 to c0+sz
+ // if sz is positive, the corners are anticlockwise starting with c0
+ [ c0 + [ 0, 0 ],
+ c0 + [ sz[0], 0 ],
+ c0 + [ sz[0], sz[1] ],
+ c0 + [ 0, sz[1] ] ];
+
+function Rectangle_corners2posts(c) =
+ [ c[0] + thehd_tr,
+ c[1] + thehd_tl,
+ c[2] + thehd_bl,
+ c[3] + thehd_br ];
+
+m4_dnl R_EDGE(c,ix)
+m4_dnl c is from Rectangle_corners and
+m4_dnl ix is a corner number
+m4_dnl expands to two comma-separated corners:
+m4_dnl that denoted by ix, and the next one anticlockwise
+m4_define(`R_EDGE',`$1[$2],$1[(($2)+1)%4]')
+
+module Tile02(){ ////toplevel
+ sz = [100,170];
+ c0 = -sz;
+ c = Rectangle_corners(c0, sz);
+ posts = Rectangle_corners2posts(c);
+ rcs = [c[0], c[1]];
+ difference(){
+ union(){
+ TileBase(c[0], c[2]);
+ Posts(posts);
+ RoundEdge(R_EDGE(c,0));
+ RoundEdge(R_EDGE(c,3));
+ InterlockEdge(R_EDGE(c,2), 0);
+ }
+ InterlockEdge(R_EDGE(c,1), 1);
+ RoundCornerCut(rcs);
+ }
+ RoundCornerAdd(rcs);
+}
+
+module Tile12(){ ////toplevel
+ sz = [100,250];
+ c0 = [-sz[0], 0];
+ c = Rectangle_corners(c0, sz);
+ posts = Rectangle_corners2posts(c);
+ rcs = [c[3], c[0]];
+ difference(){
+ union(){
+ TileBase(c[0], c[2]);
+ RoundEdge(R_EDGE(c,2));
+ RoundEdge(R_EDGE(c,3));
+ Posts(posts);
+ }
+ InterlockEdge(R_EDGE(c,0), 1);
+ InterlockEdge(R_EDGE(c,1), 1);
+ RoundCornerCut(rcs);
+ }
+ RoundCornerAdd(rcs);
+}
+
+module Demo(){ ////toplevel
+ translate(demo_slop*[-2,1]) color("blue") Tile12();
+ translate(demo_slop*[-2,0]) color("red") Tile02();
+}
+