From 4edd189db776961821b5aa88540a545754d6162c Mon Sep 17 00:00:00 2001 From: Justin Lin Date: Mon, 29 May 2017 18:22:35 +0800 Subject: [PATCH] refactored --- src/hexagons.scad | 24 +++++++++++++++++++----- src/unittest.scad | 2 +- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/hexagons.scad b/src/hexagons.scad index 911e0c0b..d5b9de7a 100644 --- a/src/hexagons.scad +++ b/src/hexagons.scad @@ -24,6 +24,17 @@ module hexagons(radius, spacing, levels) { circle(r_hexagon, $fn = 6); } + function hexagons_pts(hex_datum) = + let( + tx = hex_datum[0][0], + ty = hex_datum[0][1], + n = hex_datum[1], + offset_xs = [for(i = [0:n - 1]) i * offset_step + center_offset] + ) + [ + for(x = offset_xs) [x + tx, ty, 0] + ]; + module line_hexagons(hex_datum) { tx = hex_datum[0][0]; ty = hex_datum[0][1]; @@ -34,9 +45,6 @@ module hexagons(radius, spacing, levels) { p = [x + tx, ty, 0]; translate(p) hexagon(); - - // hook for testing - test_each_hexagon(r_hexagon, p); } } @@ -63,11 +71,17 @@ module hexagons(radius, spacing, levels) { ); for(hex_datum = total_hex_data) { - line_hexagons(hex_datum); + pts = hexagons_pts(hex_datum); + for(pt = pts) { + translate(pt) + hexagon(); + } + + } } // override it to test -module test_each_hexagon(hex_r, pt) { +module test_each_hexagon(hex_r, pts) { } \ No newline at end of file diff --git a/src/unittest.scad b/src/unittest.scad index 8f469020..00177789 100644 --- a/src/unittest.scad +++ b/src/unittest.scad @@ -29,7 +29,7 @@ function shift_to_int(point, digits) = [round(pt[0]), round(pt[1])] : [round(pt[0]), round(pt[1]), round(pt[2])]; -function all_shift_to_int(points, digits) = +function round_pts(points, digits) = [for(pt = points) shift_to_int(pt, digits) / digits]; module assertEqualPoint(expected, actual) {