Skip to content

Commit d950ac0

Browse files
Merge pull request #1897 from adrianVmariano/master
don't allow anchor and center together
2 parents 3fde690 + 63e7cbf commit d950ac0

File tree

1 file changed

+49
-23
lines changed

1 file changed

+49
-23
lines changed

shapes3d.scad

Lines changed: 49 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use <builtins.scad>
2929
// Usage: As Module (as in native OpenSCAD)
3030
// cube(size, [center]);
3131
// Usage: With BOSL2 Attachment extensions
32-
// cube(size, [center], [anchor=], [spin=], [orient=]) [ATTACHMENTS];
32+
// cube(size, [center|anchor=], [spin=], [orient=]) [ATTACHMENTS];
3333
// Usage: As Function (BOSL2 extension)
3434
// vnf = cube(size, ...);
3535
// Description:
@@ -38,7 +38,7 @@ use <builtins.scad>
3838
// When called as a function, returns a [VNF](vnf.scad) for a cube.
3939
// Arguments:
4040
// size = The size of the cube.
41-
// center = If given, overrides `anchor`. A true value sets `anchor=CENTER`, false sets `anchor=FRONT+LEFT+BOTTOM`.
41+
// center = A true value sets `anchor=CENTER`, false sets `anchor=FRONT+LEFT+BOTTOM`. Default: `anchor=CENTER`
4242
// ---
4343
// anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#subsection-anchor). Default: `CENTER`
4444
// spin = Rotate this many degrees around the Z axis after anchor. See [spin](attachments.scad#subsection-spin). Default: `0`
@@ -61,6 +61,7 @@ use <builtins.scad>
6161

6262
module cube(size=1, center, anchor, spin=0, orient=UP)
6363
{
64+
dummy = assert(num_defined([center,anchor])<2, "\nCannot give both center and anchor");
6465
anchor = get_anchor(anchor, center, -[1,1,1], -[1,1,1]);
6566
size = force_list(size,3); // Native cube prints a warning and gives a unit cube when parameters are bogus
6667
attachable(anchor,spin,orient, size=is_vector(size,3)?size:[1,1,1]) {
@@ -73,6 +74,8 @@ function cube(size=1, center, anchor, spin=0, orient=UP) =
7374
let(
7475
size = force_list(size,3)
7576
)
77+
assert(is_undef(center) || is_bool(center), "\ncenter must be boolean.")
78+
assert(num_defined([center,anchor])<2, "\nCannot give both center and anchor")
7679
assert(is_vector(size,3), "\nSize parameter cannot be converted to a 3-vector.")
7780
assert(all_positive(size), "\nAll size components must be positive.")
7881
let(
@@ -835,7 +838,7 @@ function prismoid(
835838
// Topics: Textures, Rounding, Chamfers, Shapes (3D), Attachable
836839
// See Also: cyl(), rounded_prism(), texture(), linear_sweep(), EDGE(), FACE()
837840
// Usage: Normal prisms
838-
// regular_prism(n, h|l=|height=|length=, r, [center=], [realign=]) [ATTACHMENTS];
841+
// regular_prism(n, h|l=|height=|length=, r, [center=|anchor=], [realign=]) [ATTACHMENTS];
839842
// regular_prism(n, h|l=|height=|length=, d=|id=|od=|ir=|or=|side=, ...) [ATTACHMENTS];
840843
// regular_prism(n, h|l=|height=|length=, r1=|d1=|id1=|od1=|ir1=|or1=|side1=,r2=|d2=|id2=|od2=|ir2=|or2=|side2=, ...) [ATTACHMENTS];
841844
// Usage: Chamferred end prisms
@@ -889,7 +892,7 @@ function prismoid(
889892
// Arguments:
890893
// l / h / length / height = Length of prism
891894
// r = Outer radius of prism.
892-
// center = If given, overrides `anchor`. A true value sets `anchor=CENTER`, false sets `anchor=DOWN`.
895+
// center = A true value sets `anchor=CENTER`, false sets `anchor=DOWN`. Default is `anchor=CENTER`.
893896
// ---
894897
// r1/or1 = Outer radius of the bottom of prism
895898
// r2/or2 = Outer radius of the top end of prism
@@ -1025,6 +1028,8 @@ function regular_prism(n,
10251028
anchor, spin=0, orient=UP,_return_anchors=false
10261029
) =
10271030
assert(is_integer(n) && n>2, "\nn must be an integer 3 or greater.")
1031+
assert(is_undef(center) || is_bool(center), "\ncenter must be boolean.")
1032+
assert(num_defined([anchor,center])<2, "\nCannot give both anchor and center")
10281033
let(
10291034
style = default(style,"min_edge"),
10301035
tex_depth = default(tex_depth,1),
@@ -1501,9 +1506,9 @@ function textured_tile(
15011506
// Topics: Shapes (3D), Attachable, VNF Generators
15021507
// See Also: tube()
15031508
// Usage: Typical Rectangular Tubes
1504-
// rect_tube(h, size, isize, [center], [shift]);
1505-
// rect_tube(h, size, wall=, [center=]);
1506-
// rect_tube(h, isize=, wall=, [center=]);
1509+
// rect_tube(h, size, isize, [center|anchor=], [shift]);
1510+
// rect_tube(h, size, wall=, [center=|anchor=]);
1511+
// rect_tube(h, isize=, wall=, [center=|anchor=]);
15071512
// Usage: Tapering Rectangular Tubes
15081513
// rect_tube(h, size1=, size2=, wall=, ...);
15091514
// rect_tube(h, isize1=, isize2=, wall=, ...);
@@ -1548,7 +1553,7 @@ function textured_tile(
15481553
// h/l/height/length = The height or length of the rectangular tube. Default: 1
15491554
// size = The outer [X,Y] size of the rectangular tube.
15501555
// isize = The inner [X,Y] size of the rectangular tube.
1551-
// center = If given, overrides `anchor`. A true value sets `anchor=CENTER`, false sets `anchor=UP`.
1556+
// center = A true value sets `anchor=CENTER`, false sets `anchor=DOWN`. Default is `anchor=CENTER`.
15521557
// shift = [X,Y] amount to shift the center of the top end with respect to the center of the bottom end.
15531558
// ---
15541559
// wall = The thickness of the rectangular tube wall.
@@ -1660,6 +1665,8 @@ module rect_tube(
16601665
) {
16611666
h = one_defined([h,l,length,height],"h,l,length,height");
16621667
checks =
1668+
assert(is_undef(center) || is_bool(center), "\ncenter must be boolean.")
1669+
assert(num_defined([anchor,center])<2, "\nCannot give both center and anchor")
16631670
assert(is_num(h), "\nl or h argument required.")
16641671
assert(is_vector(shift,2));
16651672
s1 = is_num(size1)? [size1, size1] :
@@ -1791,9 +1798,9 @@ function rect_tube(
17911798
// Topics: Shapes (3D), Attachable, VNF Generators
17921799
// See also: prismoid(), rounded_prism(), pie_slice()
17931800
// Usage: As Module
1794-
// wedge(size, [center], ...) [ATTACHMENTS];
1801+
// wedge(size, [center|anchor=], ...) [ATTACHMENTS];
17951802
// Usage: As Function
1796-
// vnf = wedge(size, [center], ...);
1803+
// vnf = wedge(size, [center|anchor=], ...);
17971804
//
17981805
// Description:
17991806
// When called as a module, creates a 3D triangular wedge with the hypotenuse in the X+Z+ quadrant.
@@ -1804,7 +1811,7 @@ function rect_tube(
18041811
//
18051812
// Arguments:
18061813
// size = [width, thickness, height]. Default: [1,1,1]
1807-
// center = If given, overrides `anchor`. A true value sets `anchor=CENTER`, false sets `anchor=UP`.
1814+
// center = A true value sets `anchor=CENTER`, false sets `anchor=FRONT+LEFT+BOTTOM`. Default: anchor = `FRONT+LEFT+BOTTOM`
18081815
// ---
18091816
// anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#subsection-anchor). Default: `FRONT+LEFT+BOTTOM`
18101817
// spin = Rotate this many degrees around the Z axis after anchor. See [spin](attachments.scad#subsection-spin). Default: `0`
@@ -1837,7 +1844,9 @@ function rect_tube(
18371844
module wedge(size=[1, 1, 1], center, anchor, spin=0, orient=UP)
18381845
{
18391846
size = force_list(size,3);
1840-
check=assert(is_vector(size,3) && all_positive(size), "\nsize must be a positive scalar or 3-vector.");
1847+
check=assert(is_vector(size,3) && all_positive(size), "\nsize must be a positive scalar or 3-vector.")
1848+
assert(is_undef(center) || is_bool(center), "\ncenter must be boolean.")
1849+
assert(num_defined([anchor,center])<2, "\nCannot give both anchor and center");
18411850
anchor = get_anchor(anchor, center, -[1,1,1], -[1,1,1]);
18421851
vnf = wedge(size, anchor="origin");
18431852
spindir = unit([0,-size.y,size.z]);
@@ -1955,8 +1964,8 @@ function octahedron(size=1, anchor=CENTER, spin=0, orient=UP) =
19551964
// cylinder(h, r=/d=, [center=]);
19561965
// cylinder(h, r1/d1=, r2/d2=, [center=]);
19571966
// Usage: With BOSL2 anchoring and attachment extensions
1958-
// cylinder(h, r=/d=, [center=], [anchor=], [spin=], [orient=]) [ATTACHMENTS];
1959-
// cylinder(h, r1/d1=, r2/d2=, [center=], [anchor=], [spin=], [orient=]) [ATTACHMENTS];
1967+
// cylinder(h, r=/d=, [center=|anchor=], [spin=], [orient=]) [ATTACHMENTS];
1968+
// cylinder(h, r1/d1=, r2/d2=, [center=|anchor=], [spin=], [orient=]) [ATTACHMENTS];
19601969
// Usage: As Function (BOSL2 extension)
19611970
// vnf = cylinder(h, r=/d=, ...);
19621971
// vnf = cylinder(h, r1/d1=, r2/d2=, ...);
@@ -1968,13 +1977,13 @@ function octahedron(size=1, anchor=CENTER, spin=0, orient=UP) =
19681977
// h = The height of the cylinder.
19691978
// r1 = The bottom radius of the cylinder. (Before orientation.)
19701979
// r2 = The top radius of the cylinder. (Before orientation.)
1971-
// center = If given, overrides `anchor`. A true value sets `anchor=CENTER`, false sets `anchor=BOTTOM`. Default: false
1980+
// center = A true value sets `anchor=CENTER`, false sets `anchor=BOTTOM`. Default: false (`anchor=BOTTOM`)
19721981
// ---
19731982
// d1 = The bottom diameter of the cylinder. (Before orientation.)
19741983
// d2 = The top diameter of the cylinder. (Before orientation.)
19751984
// r = The radius of the cylinder.
19761985
// d = The diameter of the cylinder.
1977-
// anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#subsection-anchor). Default: `CENTER`
1986+
// anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#subsection-anchor). Default: `BOTTOM`
19781987
// spin = Rotate this many degrees around the Z axis after anchor. See [spin](attachments.scad#subsection-spin). Default: `0`
19791988
// orient = Vector to rotate top toward, after spin. See [orient](attachments.scad#subsection-orient). Default: `UP`
19801989
// Example: By Radius
@@ -2001,6 +2010,7 @@ function octahedron(size=1, anchor=CENTER, spin=0, orient=UP) =
20012010

20022011
module cylinder(h, r1, r2, center, r, d, d1, d2, anchor, spin=0, orient=UP)
20032012
{
2013+
dummy = assert(num_defined([anchor,center])<2, "\nCannot give both center and anchor.");
20042014
anchor = get_anchor(anchor, center, BOTTOM, BOTTOM);
20052015
r1 = get_radius(r1=r1, r=r, d1=d1, d=d, dflt=1);
20062016
r2 = get_radius(r1=r2, r=r, d1=d2, d=d, dflt=1);
@@ -2012,6 +2022,8 @@ module cylinder(h, r1, r2, center, r, d, d1, d2, anchor, spin=0, orient=UP)
20122022
}
20132023

20142024
function cylinder(h, r1, r2, center, r, d, d1, d2, anchor, spin=0, orient=UP) =
2025+
assert(is_undef(center) || is_bool(center), "\ncenter must be boolean.")
2026+
assert(num_defined([anchor,center])<2, "\nCannot give both center and anchor.")
20152027
let(
20162028
anchor = get_anchor(anchor, center, BOTTOM, BOTTOM),
20172029
r1 = get_radius(r1=r1, r=r, d1=d1, d=d, dflt=1),
@@ -2038,7 +2050,7 @@ function cylinder(h, r1, r2, center, r, d, d1, d2, anchor, spin=0, orient=UP) =
20382050
// Topics: Cylinders, Textures, Rounding, Chamfers
20392051
// See Also: regular_prism(), texture(), rotate_sweep(), cylinder()
20402052
// Usage: Normal Cylinders
2041-
// cyl(l|h|length|height, r, [center], [circum=], [realign=]) [ATTACHMENTS];
2053+
// cyl(l|h|length|height, r, [center|anchor=], [circum=], [realign=]) [ATTACHMENTS];
20422054
// cyl(l|h|length|height, d=, ...) [ATTACHMENTS];
20432055
// cyl(l|h|length|height, r1=, r2=, ...) [ATTACHMENTS];
20442056
// cyl(l|h|length|height, d1=, d2=, ...) [ATTACHMENTS];
@@ -2114,7 +2126,7 @@ function cylinder(h, r1, r2, center, r, d, d1, d2, anchor, spin=0, orient=UP) =
21142126
// Arguments:
21152127
// l / h / length / height = Length of cylinder along oriented axis. Default: 1
21162128
// r = Radius of cylinder. Default: 1
2117-
// center = If given, overrides `anchor`. A true value sets `anchor=CENTER`, false sets `anchor=DOWN`.
2129+
// center = A true value sets `anchor=CENTER`, false sets `anchor=DOWN`.
21182130
// ---
21192131
// r1 = Radius of the negative (X-, Y-, Z-) end of cylinder.
21202132
// r2 = Radius of the positive (X+, Y+, Z+) end of cylinder.
@@ -2383,6 +2395,8 @@ function cyl(
23832395
extra, extra1, extra2,
23842396
anchor, spin=0, orient=UP
23852397
) =
2398+
assert(is_undef(center) || is_bool(center), "\ncenter must be boolean.")
2399+
assert(num_defined([center,anchor])<2, "\nCannot give both center and anchor")
23862400
assert(num_defined([style,tex_style])<2, "\nIn cyl() the 'tex_style' parameter has been replaced by 'style'. You cannot give both.")
23872401
assert(num_defined([tex_reps,tex_counts])<2, "\nIn cyl() the 'tex_counts' parameter has been replaced by 'tex_reps'. You cannot give both.")
23882402
assert(num_defined([tex_scale,tex_depth])<2, "\nIn cyl() the 'tex_scale' parameter has been replaced by 'tex_depth'. You cannot give both.")
@@ -2502,6 +2516,8 @@ module cyl(
25022516
anchor, spin=0, orient=UP
25032517
) {
25042518
dummy=
2519+
assert(num_defined([anchor,center])<2, "\nCannot give both `anchor` and `center` to cyl()")
2520+
assert(is_undef(center) || is_bool(center), "\ncenter must be boolean")
25052521
assert(num_defined([style,tex_style])<2, "\nIn cyl() the 'tex_style' parameters has been replaced by 'style'. You cannot give both.")
25062522
assert(num_defined([tex_reps,tex_counts])<2, "\nIn cyl() the 'tex_counts' parameters has been replaced by 'tex_reps'. You cannot give both.")
25072523
assert(num_defined([tex_scale,tex_depth])<2, "\nIn cyl() the 'tex_scale' parameter has been replaced by 'tex_depth'. You cannot give both.");
@@ -2901,7 +2917,7 @@ module zcyl(
29012917
// If you need to anchor to the inside of a tube, use {{attach_part()}} with the part name "inside"
29022918
// to switch goeomtry to the inside.
29032919
// Usage: Basic cylindrical tube, specifying inner and outer radius or diameter
2904-
// tube(h|l, or, ir, [center], [realign=], [anchor=], [spin=],[orient=]) [ATTACHMENTS];
2920+
// tube(h|l, or, ir, [center|anchor=], [realign=], [spin=],[orient=]) [ATTACHMENTS];
29052921
// tube(h|l, od=, id=, ...) [ATTACHMENTS];
29062922
// Usage: Specify wall thickness
29072923
// tube(h|l, or|od=|ir=|id=, wall=, ...) [ATTACHMENTS];
@@ -2917,7 +2933,7 @@ module zcyl(
29172933
// h / l / height / length = height of tube. Default: 1
29182934
// or = Outer radius of tube. Default: 1
29192935
// ir = Inner radius of tube.
2920-
// center = If given, overrides `anchor`. A true value sets `anchor=CENTER`, false sets `anchor=DOWN`.
2936+
// center = A true value sets `anchor=CENTER`, false sets `anchor=DOWN`. Default: `anchor=CENTER`
29212937
// ---
29222938
// od = Outer diameter of tube.
29232939
// id = Inner diameter of tube.
@@ -3042,6 +3058,8 @@ module tube(
30423058
ir1 = default(irr1, u_sub(orr1,wall));
30433059
ir2 = default(irr2, u_sub(orr2,wall));
30443060
checks =
3061+
assert(is_undef(center) || is_bool(center), "\ncenter must be boolean.")
3062+
assert(num_defined([anchor,center])<2, "\nCannot give both anchor and center.")
30453063
assert(is_vector(shift,2), "\n'shift' must be a 2D vector.")
30463064
assert(all_defined([r1, r2, ir1, ir2]), "\nMust specify two of inner radius/diam, outer radius/diam, and wall width.")
30473065
assert(num_defined([rounding,chamfer])<2, "\nCannot give both rounding and chamfer.")
@@ -3153,7 +3171,7 @@ module tube(
31533171
// h / l / height / length = height of pie slice.
31543172
// r = radius of pie slice.
31553173
// ang = pie slice angle in degrees.
3156-
// center = If given, overrides `anchor`. A true value sets `anchor=CENTER`, false sets `anchor=UP`.
3174+
// center = A true value sets `anchor=CENTER`, false sets `anchor=DOWN`. Default: `anchor=CENTER`
31573175
// ---
31583176
// r1 = bottom radius of pie slice.
31593177
// r2 = top radius of pie slice.
@@ -3179,6 +3197,9 @@ module pie_slice(
31793197
r1, r2, d, d1, d2, l, length, height,
31803198
anchor, spin=0, orient=UP
31813199
) {
3200+
dummy =
3201+
assert(is_undef(center) || is_bool(center), "\ncenter must be boolean.")
3202+
assert(num_defined([anchor,center])<2,"\nCannot give both anchor and center.");
31823203
l = one_defined([l, h,height,length],"l,h,height,length",dflt=1);
31833204
r1 = get_radius(r1=r1, r=r, d1=d1, d=d, dflt=10);
31843205
r2 = get_radius(r1=r2, r=r, d1=d2, d=d, dflt=10);
@@ -3787,7 +3808,7 @@ function spheroid(r, style="aligned", d, circum=false, anchor=CENTER, spin=0, or
37873808
// Arguments:
37883809
// r_maj = major radius of torus ring. (use with 'r_min', or 'd_min')
37893810
// r_min = minor radius of torus ring. (use with 'r_maj', or 'd_maj')
3790-
// center = If given, overrides `anchor`. A true value sets `anchor=CENTER`, false sets `anchor=DOWN`.
3811+
// center = A true value sets `anchor=CENTER`, false sets `anchor=DOWN`. Default: `anchor=CENTER`
37913812
// ---
37923813
// d_maj = major diameter of torus ring. (use with 'r_min', or 'd_min')
37933814
// d_min = minor diameter of torus ring. (use with 'r_maj', or 'd_maj')
@@ -3818,6 +3839,9 @@ module torus(
38183839
or, od, ir, id,
38193840
anchor, spin=0, orient=UP
38203841
) {
3842+
dummy =
3843+
assert(is_undef(center) || is_bool(center), "\ncenter must be boolean.")
3844+
assert(num_defined([anchor,center])<2,"\nCannot give both anchor and center");
38213845
_or = get_radius(r=or, d=od, dflt=undef);
38223846
_ir = get_radius(r=ir, d=id, dflt=undef);
38233847
_r_maj = get_radius(r=r_maj, d=d_maj, dflt=undef);
@@ -3848,7 +3872,9 @@ function torus(
38483872
d_maj, d_min,
38493873
or, od, ir, id,
38503874
anchor, spin=0, orient=UP
3851-
) = let(
3875+
) = assert(num_defined([anchor,center])<2,"\nCannot give both anchor and center")
3876+
assert(is_undef(center) || is_bool(center), "\ncenter must be boolean.")
3877+
let(
38523878
_or = get_radius(r=or, d=od, dflt=undef),
38533879
_ir = get_radius(r=ir, d=id, dflt=undef),
38543880
_r_maj = get_radius(r=r_maj, d=d_maj, dflt=undef),

0 commit comments

Comments
 (0)