Added edges_except= to rounding(), chamfer(), and cuboid().

This commit is contained in:
Revar Desmera 2019-11-11 23:38:27 -08:00
parent 066bb190f9
commit a52412cabe
4 changed files with 96 additions and 27 deletions

View file

@ -32,7 +32,6 @@ function is_edge_array(v) = is_list(v) && is_vector(v[0]) && len(v)==3 && len(v[
// Takes an edge set descriptor and returns the edges array representing those edges.
// This function is useful for modules that take `edges` arguments, like `cuboid()`.
// An edge set descriptor can be any of:
// - A raw edges array.
// - A vector pointing towards an edge, indicating just that edge.
// - A vector pointing towards a face, indicating all edges surrounding that face.
// - A vector pointing towards a corner, indicating all edges that meet at that corner.
@ -41,6 +40,14 @@ function is_edge_array(v) = is_list(v) && is_vector(v[0]) && len(v)==3 && len(v[
// - The string `"Z"`, indicating all Z axis aligned edges.
// - The string `"ALL"`, indicating all edges.
// - The string `"NONE"`, indicating no edges at all.
// - A raw edges array, where each edge is represented by a 1 or a 0. The edge ordering is:
// ```
// [
// [Y-Z-, Y+Z-, Y-Z+, Y+Z+],
// [X-Z-, X+Z-, X-Z+, X+Z+],
// [X-Y-, X+Y-, X-Y+, X+Y+]
// ]
// ```
function edge_set(v) =
is_edge_array(v)? v : [
for (ax=[0:2]) [
@ -93,7 +100,6 @@ function normalize_edges(v) = [for (ax=v) [for (edge=ax) edge>0? 1 : 0]];
// from the returned edges array. If either argument only has a single edge
// set descriptor, you do not have to pass it in a list.
// Each edge set descriptor can be any of:
// - A raw edges array.
// - A vector pointing towards an edge.
// - A vector pointing towards a face, indicating all edges surrounding that face.
// - A vector pointing towards a corner, indicating all edges touching that corner.
@ -102,6 +108,80 @@ function normalize_edges(v) = [for (ax=v) [for (edge=ax) edge>0? 1 : 0]];
// - The string `"Z"`, indicating all Z axis aligned edges.
// - The string `"ALL"`, indicating all edges.
// - The string `"NONE"`, indicating no edges at all.
// - A raw edges array, where each edge is represented by a 1 or a 0. The edge ordering is:
// ```
// [
// [Y-Z-, Y+Z-, Y-Z+, Y+Z+],
// [X-Z-, X+Z-, X-Z+, X+Z+],
// [X-Y-, X+Y-, X-Y+, X+Y+]
// ]
// ```
// Figure(3DMedSpin): Face Vector Edge Sets
// module text3d(txt) {
// xrot(90)
// color("#000")
// linear_extrude(height=0.1) {
// text(text=txt, size=3, halign="center", valign="center");
// }
// }
// ydistribute(50) {
// ydistribute(10) {
// xdistribute(30) {
// text3d("RIGHT");
// text3d("BACK");
// text3d("TOP");
// }
// xdistribute(30) {
// cuboid(20,chamfer=3,edges=RIGHT);
// cuboid(20,chamfer=3,edges=BACK);
// cuboid(20,chamfer=3,edges=TOP);
// }
// }
// ydistribute(10) {
// xdistribute(30) {
// text3d("LEFT");
// text3d("FRONT");
// text3d("BTM");
// }
// xdistribute(30) {
// cuboid(20,chamfer=3,edges=LEFT);
// cuboid(20,chamfer=3,edges=FRONT);
// cuboid(20,chamfer=3,edges=BTM);
// }
// }
// }
// Figure(3DBig): Named Edge Sets
// module text3d(txt) {
// xrot(90)
// color("#000")
// linear_extrude(height=0.1) {
// text(text=txt, size=3.5, halign="center", valign="center");
// }
// }
// ydistribute(75) {
// ydistribute(10) {
// xdistribute(30) {
// text3d("\"X\"");
// text3d("\"Y\"");
// text3d("\"Z\"");
// }
// xdistribute(30) {
// cuboid(20,chamfer=3,edges="X");
// cuboid(20,chamfer=3,edges="Y");
// cuboid(20,chamfer=3,edges="Z");
// }
// }
// ydistribute(10) {
// xdistribute(30) {
// text3d("\"ALL\"");
// text3d("\"NONE\"");
// }
// xdistribute(30) {
// cuboid(20,chamfer=3,edges="ALL");
// cuboid(20,chamfer=3,edges="NONE");
// }
// }
// }
// Example: Just the front-top edge
// edges(FRONT+TOP)
// Example: All edges surrounding either the front or top faces

View file

@ -248,19 +248,12 @@ module chamfer_mask_z(l=1.0, chamfer=1.0, anchor=CENTER, spin=0) {
// Usage:
// chamfer(chamfer, size, [edges]) ...
// Description:
// Chamfers the edges of a cuboid region containing childrem, centered on the origin.
// Chamfers the edges of a cuboid region containing the given children, centered on the origin.
// Arguments:
// chamfer = Inset of the chamfer from the edge. (Default: 1)
// size = The size of the rectangular cuboid we want to chamfer.
// edges = Which edges to chamfer. Use of [`edges()`](edges.scad#edges) from [`edges.scad`](edges.scad) is recommend.
// Description:
// You should use [`edges()`](edges.scad#edges) from [`edges.scad`](edges.scad) with the `edge` argument.
// However, if you must handle it raw, the edge ordering is this:
// [
// [Y-Z-, Y+Z-, Y-Z+, Y+Z+],
// [X-Z-, X+Z-, X-Z+, X+Z+],
// [X-Y-, X+Y-, X-Y+, X+Y+]
// ]
// edges = Edges to chamfer. See the docs for [`edges()`](edges.scad#edges) to see acceptable values. Default: All edges.
// except_edges = Edges to explicitly NOT chamfer. See the docs for [`edges()`](edges.scad#edges) to see acceptable values. Default: No edges.
// Example(FR):
// chamfer(chamfer=2, size=[20,40,30]) {
// cube(size=[20,40,30], center=true);
@ -269,13 +262,13 @@ module chamfer_mask_z(l=1.0, chamfer=1.0, anchor=CENTER, spin=0) {
// chamfer(chamfer=2, size=[20,40,30], edges=edges([TOP,FRONT+RIGHT], except=TOP+LEFT)) {
// cube(size=[20,40,30], center=true);
// }
module chamfer(chamfer=1, size=[1,1,1], edges=EDGES_ALL)
module chamfer(chamfer=1, size=[1,1,1], edges=EDGES_ALL, except_edges=[])
{
difference() {
children();
difference() {
cube(size, center=true);
cuboid(size+[1,1,1]*0.02, chamfer=chamfer+0.01, edges=edges, trimcorners=true);
cuboid(size+[1,1,1]*0.02, chamfer=chamfer+0.01, edges=edges, except_edges=except_edges, trimcorners=true);
}
}
}
@ -541,15 +534,8 @@ module rounding_mask_z(l=1.0, r=undef, r1=undef, r2=undef, anchor=CENTER, spin=0
// Arguments:
// r = Radius of the rounding. (Default: 1)
// size = The size of the rectangular cuboid we want to chamfer.
// edges = Which edges to round. Use of [`edges()`](edges.scad#edges) from [`edges.scad`](edges.scad) is recommend.
// Description:
// You should use [`edges()`](edges.scad#edges) from [`edges.scad`](edges.scad) to generate the edge array for the `edge` argument.
// However, if you must handle it raw, the edge ordering is this:
// [
// [Y-Z-, Y+Z-, Y-Z+, Y+Z+],
// [X-Z-, X+Z-, X-Z+, X+Z+],
// [X-Y-, X+Y-, X-Y+, X+Y+]
// ]
// edges = Edges to round. See the docs for [`edges()`](edges.scad#edges) to see acceptable values. Default: All edges.
// except_edges = Edges to explicitly NOT round. See the docs for [`edges()`](edges.scad#edges) to see acceptable values. Default: No edges.
// Example(FR):
// rounding(r=10, size=[50,100,150], $fn=24) {
// cube(size=[50,100,150], center=true);
@ -558,13 +544,13 @@ module rounding_mask_z(l=1.0, r=undef, r1=undef, r2=undef, anchor=CENTER, spin=0
// rounding(r=10, size=[50,50,75], edges=edges([TOP,FRONT+RIGHT], except=TOP+LEFT), $fn=24) {
// cube(size=[50,50,75], center=true);
// }
module rounding(r=1, size=[1,1,1], edges=EDGES_ALL)
module rounding(r=1, size=[1,1,1], edges=EDGES_ALL, except_edges=[])
{
difference() {
children();
difference() {
cube(size, center=true);
cuboid(size+[1,1,1]*0.01, rounding=r, edges=edges, trimcorners=true);
cuboid(size+[1,1,1]*0.01, rounding=r, edges=edges, except_edges=except_edges, trimcorners=true);
}
}
}

View file

@ -22,7 +22,8 @@
// size = The size of the cube.
// chamfer = Size of chamfer, inset from sides. Default: No chamferring.
// rounding = Radius of the edge rounding. Default: No rounding.
// edges = Edges to chamfer/round. It's recommended to use [`edges()`](edges.scad#edges) from [`edges.scad`](edges.scad). Default: All edges.
// edges = Edges to chamfer/round. See the docs for [`edges()`](edges.scad#edges) to see acceptable values. Default: All edges.
// except_edges = Edges to explicitly NOT chamfer/round. See the docs for [`edges()`](edges.scad#edges) to see acceptable values. Default: No edges.
// trimcorners = If true, rounds or chamfers corners where three chamferred/rounded edges meet. Default: `true`
// p1 = Align the cuboid's corner at `p1`, if given. Forces `anchor=ALLNEG`.
// p2 = If given with `p1`, defines the cornerpoints of the cuboid.
@ -66,12 +67,14 @@ module cuboid(
chamfer=undef,
rounding=undef,
edges=EDGES_ALL,
except_edges=[],
trimcorners=true,
anchor=CENTER,
spin=0,
orient=UP
) {
size = scalar_vec3(size);
edges = edges(edges, except=except_edges);
if (!is_undef(p1)) {
if (!is_undef(p2)) {
translate(pointlist_bounds([p1,p2])[0]) {

View file

@ -8,7 +8,7 @@
//////////////////////////////////////////////////////////////////////
BOSL_VERSION = [2,0,30];
BOSL_VERSION = [2,0,31];
// Section: BOSL Library Version Functions