# HG changeset patch # User Paul Boddie # Date 1390235003 -3600 # Node ID 76caf3d0387e775a97c9985dc2b00f4d78fd7ffa # Parent 3ecba6c800b0735b4c62f953432f29bbca9e6a5d Added a justify module in order to simplify some transformation code. diff -r 3ecba6c800b0 -r 76caf3d0387e cartridge.scad --- a/cartridge.scad Mon Jan 20 15:18:32 2014 +0100 +++ b/cartridge.scad Mon Jan 20 17:23:23 2014 +0100 @@ -19,10 +19,27 @@ } /* + Justify an object of the given dimensions, according to the given + factors (where 1 indicates moving the object to the positive side of an + axis, and -1 indicates moving it to the negative side of an axis). + + NOTE: child should eventually be replaced by children. + */ + module justify(width, depth, height, wdir, ddir, hdir) { + translate([ + wdir * width / 2, + ddir * depth / 2, + hdir * height / 2]) + child(); + } + + /* Make a cuboid of the given dimensions, justifying it according to the given - factors (where 1 indicates moving the cuboid to the positive side of the - axis, and -1 indicates moving it to the negative side of the axis), and - moving it to the specified coordinates. + factors, and moving it to the specified coordinates. + + NOTE: Usage of justify within this module will not work due to recursion + NOTE: limitations in openscad, potentially removed in more recent + NOTE: releases. Thus, the justify transform is merged in here. */ module cube_at(width, depth, height, wdir, ddir, hdir, x, y, z) { translate([ @@ -316,43 +333,47 @@ /* PCB supports. */ - translate([-edge_connector_cutout_back_width / 2 + - pcb_back_support_width / 2, - edge_connector_cutout_back_depth + - pcb_back_support_depth / 2, - -height / 2 + bottom + bottom_from_base + - pcb_back_support_height / 2]) - union() { - cube([pcb_back_support_width, pcb_back_support_depth, - pcb_back_support_height], center = true); - cube_at(pcb_back_support_bump_width, - pcb_back_support_bump_depth, - pcb_back_support_left_bump_height, - 0, -1, 1, - 0, - -pcb_back_support_depth / 2, - -pcb_back_support_height / 2 + - pcb_back_support_left_bump_offset_from_bottom); - } + translate([-edge_connector_cutout_back_width / 2, + edge_connector_cutout_back_depth, + -height / 2 + bottom + bottom_from_base]) + justify(pcb_back_support_width, + pcb_back_support_depth, + pcb_back_support_height, + 1, 1, 1) + union() { + cube([pcb_back_support_width, + pcb_back_support_depth, + pcb_back_support_height], center = true); + cube_at(pcb_back_support_bump_width, + pcb_back_support_bump_depth, + pcb_back_support_left_bump_height, + 0, -1, 1, + 0, + -pcb_back_support_depth / 2, + -pcb_back_support_height / 2 + + pcb_back_support_left_bump_offset_from_bottom); + } - translate([edge_connector_cutout_back_width / 2 - - pcb_back_support_width / 2, - edge_connector_cutout_back_depth + - pcb_back_support_depth / 2, - -height / 2 + bottom + bottom_from_base + - pcb_back_support_height / 2]) - union() { - cube([pcb_back_support_width, pcb_back_support_depth, - pcb_back_support_height], center = true); - cube_at(pcb_back_support_bump_width, - pcb_back_support_bump_depth, - pcb_back_support_right_bump_height, - 0, -1, 1, - 0, - -pcb_back_support_depth / 2, - -pcb_back_support_height / 2 + - pcb_back_support_right_bump_offset_from_bottom); - } + translate([edge_connector_cutout_back_width / 2, + edge_connector_cutout_back_depth, + -height / 2 + bottom + bottom_from_base]) + justify(pcb_back_support_width, + pcb_back_support_depth, + pcb_back_support_height, + -1, 1, 1) + union() { + cube([pcb_back_support_width, + pcb_back_support_depth, + pcb_back_support_height], center = true); + cube_at(pcb_back_support_bump_width, + pcb_back_support_bump_depth, + pcb_back_support_right_bump_height, + 0, -1, 1, + 0, + -pcb_back_support_depth / 2, + -pcb_back_support_height / 2 + + pcb_back_support_right_bump_offset_from_bottom); + } } /* Label insets. */