chiark / gitweb /
knifeblock: Holes refactor: move holeoffx/y into HexGrid (nfc)
[reprap-play.git] / knifeblock.scad
index 4cee4c889426bdcdba0dc41a09407c18fa327228..603336a9ff432d196aca79156c14a7286bc43713 100644 (file)
@@ -133,7 +133,7 @@ module AtSides(){
 }
 
 module BlockPegSlot(){
-  translate([recessblockwidth/2, pegrecess - 0.5*peglen, -height]){
+  translate([recessblockwidth/2, pegrecess - peglen, -height]){
     rotate([-90,0,0]) linear_extrude(height=totaldepth){
       PegTemplate(peghead/2 * 1.2);
     }
@@ -214,15 +214,6 @@ module CoverPegSlot(coverlen){
   }
 }
 
-module HoleRow(){
-  imax = ceil(coverlonglen / holepitch);
-  echo("Holes Y count ", imax);
-  for (i=[0:imax]) {
-    translate([0, (i+0.5)*holepitch, -20])
-      cylinder(r=holesize/2, h=40, $fn=40);
-  }
-}
-
 module HolesScope(){
   intersection_for (dx=[-1,+1]) {
     intersection_for (dy=[-1,+1]) {
@@ -233,19 +224,33 @@ module HolesScope(){
   }
 }
 
-module Holes(){
-  imin = ceil((maxx-minx)/(sqrt(3)*holepitch));
-  echo("Holes X count 2 x", imin);
-  intersection(){
-    translate([holeoffx * holepitch, holeoffy * holepitch, 0]) {
-      for (i=[-imin:2]) {
-       translate([i * sqrt(3) * holepitch, 0, 0]) {
-         HoleRow();
-         translate([sqrt(3)/2 * holepitch, -0.5 * holepitch, 0])
-           HoleRow();
-       }
+module HexGrid(imin,imax,jmin,jmax) {
+  for (i=[imin:imax]) {
+    for (j=[jmin:jmax]) {
+      translate([(j * sqrt(3) + holeoffx) * holepitch,
+                (i +     0.5 + holeoffy) * holepitch,
+                0]) {
+       child();
+       translate([sqrt(3)/2 * holepitch, -0.5 * holepitch, 0])
+         child();
       }
     }
+  }
+}
+
+module Hole(){
+  cylinder(r=holesize/2, h=40, $fn=40);
+}
+
+module Holes(){
+  imax = ceil(coverlonglen / holepitch);
+  echo("Holes Y count ", imax);
+  jmin = ceil((maxx-minx)/(sqrt(3)*holepitch));
+  echo("Holes X count 2 x", jmin);
+  intersection(){
+    translate([0, 0, -20])
+      HexGrid(0,imax,-jmin,2)
+      Hole();
     HolesScope();
   }
 }