Make RoundBox smarter to reduce code duplication

RoundBox now takes an xshrink and yzshrink argument, which tell it how
much to shrink the box from the Length, Width, and Height parameters.
They defaul to 0. The removes the need to translate the calls to
RoundBox or to repeatedly provide adjustments to its arguments that are
very similar. As a result, the MainBox module is now much simpler and
easier to understand.
This commit is contained in:
Joel Ebel 2018-05-18 00:24:54 -04:00
parent 300029c3d2
commit 3754009a43

View File

@ -160,16 +160,17 @@ LeftEdgeOfBoardWRTBPanel = RightEdgeMargin - (PanelGap/2);
Filet and Resolution parameters.
Arguments:
a: The length of the box. Defaults to "Length" parameter.
b: The width of the box. Defaults to the "Width" parameter.
c: The height of the box. Defaults to the "Height" parameter.
xshrink: the amount to reduce the length on one end compared to the full length
yzshrink: the amount to reduce the width or height on one edge compared to the full box
*/
module RoundBox($a=Length, $b=Width, $c=Height) {
rotate([90, 0, 90]) {
linear_extrude(height=$a) {
translate([Filet, Filet, 0]) {
offset(r=Filet, $fn=Resolution) {
square([$b - 2*Filet, $c - 2*Filet]);
module RoundBox(xshrink=0, yzshrink=0) {
translate([xshrink, yzshrink, yzshrink]) {
rotate([90, 0, 90]) {
linear_extrude(height=Length - xshrink*2) {
translate([Filet, Filet, 0]) {
offset(r=Filet, $fn=Resolution) {
square([Width - 2*yzshrink - 2*Filet, Height - 2*yzshrink - 2*Filet]);
}
}
}
}
@ -185,31 +186,23 @@ module RoundBox($a=Length, $b=Width, $c=Height) {
module MainBox() {
difference() {
union() {
difference() { // Makes a hollow box with walls of Thick thickness.
// Makes a hollow box with walls of Thick thickness.
difference() {
RoundBox();
translate([Thick, Thick, Thick]) {
RoundBox($a=(Length - Thick*2),
$b=(Width - Thick*2),
$c=(Height - Thick*2));
}
RoundBox(xshrink=Thick, yzshrink=Thick);
}
difference() { // Makes interior backing for panel
translate([Thick + PanelThick + PanelGap, Thick/2, Thick/2]) { // Rails
RoundBox($a=(Length - ((Thick + PanelThick + PanelGap)*2)),
$b=(Width - Thick),
$c=(Height - Thick));
}
translate([Thick*2 + PanelThick + PanelGap, 0, 0]) {
RoundBox($a=(Length - ((Thick*2 + PanelThick + PanelGap) * 2)));
}
// Makes interior backing for panel as a wall
difference() {
RoundBox(xshrink=(Thick + PanelThick + PanelGap), yzshrink=Thick/2);
RoundBox(xshrink=(Thick*2 + PanelThick + PanelGap));
}
} // /union
translate([-Thick, -Thick, Height/2]) { // Remove the top half
}
// Remove the top half
translate([-Thick, -Thick, Height/2]) {
cube([Length + Thick*2, Width + Thick*2, Height]);
}
translate([-Thick, Thick*2, Thick*2]) { // Remove the center for panel visibility.
RoundBox($a=(Length + Thick*2), $b=(Width - Thick*4), $c=(Height - Thick*4));
}
// Remove the center for panel visibility.
RoundBox(xshrink=-Thick, yzshrink=Thick*2);
}
}