From 80007d45a22e9da07dc9a2be49fd725c07c8e0ec Mon Sep 17 00:00:00 2001 From: Justin Lin Date: Tue, 30 May 2017 15:15:58 +0800 Subject: [PATCH] refactored --- src/rounded_cube.scad | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/src/rounded_cube.scad b/src/rounded_cube.scad index 3a3feb34..2e5f5f85 100644 --- a/src/rounded_cube.scad +++ b/src/rounded_cube.scad @@ -35,23 +35,26 @@ module rounded_cube(size, corner_r, center = false) { half_cube_leng = size / 2; half_leng = half_cube_leng - edge_d; - translate(center ? [0, 0, 0] : [half_x, half_y, half_z]) hull() { - translate([-half_l, -half_w, half_h]) - sphere(corner_r, $fn = corner_frags); - translate([half_l, -half_w, half_h]) - sphere(corner_r, $fn = corner_frags); - translate([half_l, half_w, half_h]) - sphere(corner_r, $fn = corner_frags); - translate([-half_l, half_w, half_h]) - sphere(corner_r, $fn = corner_frags); + corners = [ + for(x = [-1, 1]) + for(y = [-1, 1]) + for(z = [-1, 1]) + [half_l * x, -half_w * y, half_h * z] + ]; - translate([-half_l, -half_w, -half_h]) - sphere(corner_r, $fn = corner_frags); - translate([half_l, -half_w, -half_h]) - sphere(corner_r, $fn = corner_frags); - translate([half_l, half_w, -half_h]) - sphere(corner_r, $fn = corner_frags); - translate([-half_l, half_w, -half_h]) - sphere(corner_r, $fn = corner_frags); + module corner(i) { + translate(corners[i]) + sphere(corner_r, $fn = corner_frags); + } + + translate(center ? [0, 0, 0] : [half_x, half_y, half_z]) hull() { + corner(0); + corner(1); + corner(2); + corner(3); + corner(4); + corner(5); + corner(6); + corner(7); } } \ No newline at end of file