primitives.scad: rearrange order for readability
This commit is contained in:
@@ -1,26 +1,10 @@
|
|||||||
function _toRad(r=undef, d=undef) = (r != undef) ? r : d/2;
|
//! general-purpose "primitives" lacking from the OpenSCAD builtins
|
||||||
|
|
||||||
module translateIf(cond, amount) {
|
|
||||||
if (cond) {
|
|
||||||
translate(amount) children();
|
|
||||||
} else {
|
|
||||||
children();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// cylinder() where `center=false` behaves like for `cube(center=false)`,
|
|
||||||
/// i.e. circle center is not at (0, 0) but (r, r)
|
|
||||||
module cylinderZ(d=undef, r=undef, h=undef, center=false) {
|
|
||||||
translateIf(!center, [_toRad(r=r, d=d), _toRad(r=r, d=d), 0]) {
|
|
||||||
cylinder(d=d, r=r, h=h, center=center);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// cylinder() but with the axis on the x axis instead of the z axis.
|
/// cylinder() but with the axis on the x axis instead of the z axis.
|
||||||
/// and where `center=false` behaves like for `cube(center=false)`,
|
/// and where `center=false` behaves like for `cube(center=false)`,
|
||||||
/// i.e. circle center is not at (0, 0) but (r, r)
|
/// i.e. circle center is not at (0, 0) but (r, r)
|
||||||
module cylinderX(d=undef, r=undef, h=undef, center=false) {
|
module cylinderX(d=undef, r=undef, h=undef, center=false) {
|
||||||
translateIf(!center, [0, _toRad(r=r, d=d), _toRad(r=r, d=d)]) {
|
_translateIf(!center, [0, _toRad(r=r, d=d), _toRad(r=r, d=d)]) {
|
||||||
rotate(a=[0,-90,0]) cylinder(d=d, r=r, h=h, center=center);
|
rotate(a=[0,-90,0]) cylinder(d=d, r=r, h=h, center=center);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -29,8 +13,25 @@ module cylinderX(d=undef, r=undef, h=undef, center=false) {
|
|||||||
/// and where `center=false` behaves like for `cube(center=false)`,
|
/// and where `center=false` behaves like for `cube(center=false)`,
|
||||||
/// i.e. circle center is not at (0, 0) but (r, r)
|
/// i.e. circle center is not at (0, 0) but (r, r)
|
||||||
module cylinderY(d=undef, r=undef, h=undef, center=false) {
|
module cylinderY(d=undef, r=undef, h=undef, center=false) {
|
||||||
translateIf(!center, [_toRad(r=r, d=d), 0, _toRad(r=r, d=d)]) {
|
_translateIf(!center, [_toRad(r=r, d=d), 0, _toRad(r=r, d=d)]) {
|
||||||
rotate(a=[-90,0,0]) cylinder(d=d, r=r, h=h, center=center);
|
rotate(a=[-90,0,0]) cylinder(d=d, r=r, h=h, center=center);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// cylinder() where `center=false` behaves like for `cube(center=false)`,
|
||||||
|
/// i.e. circle center is not at (0, 0) but (r, r)
|
||||||
|
module cylinderZ(d=undef, r=undef, h=undef, center=false) {
|
||||||
|
_translateIf(!center, [_toRad(r=r, d=d), _toRad(r=r, d=d), 0]) {
|
||||||
|
cylinder(d=d, r=r, h=h, center=center);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function _toRad(r=undef, d=undef) = (r != undef) ? r : d/2;
|
||||||
|
|
||||||
|
module _translateIf(cond, amount) {
|
||||||
|
if (cond) {
|
||||||
|
translate(amount) children();
|
||||||
|
} else {
|
||||||
|
children();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user