From 5b62f2859aa9c3d2d34f2acc21b7ae4cf6c1480b Mon Sep 17 00:00:00 2001 From: Adrian Mariano Date: Thu, 11 Nov 2021 22:43:19 -0500 Subject: [PATCH 1/4] catch case where endcaps are too long for path in stroke() make rect() default to centered --- drawing.scad | 1 + shapes2d.scad | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/drawing.scad b/drawing.scad index 7968a0a..78e0a02 100644 --- a/drawing.scad +++ b/drawing.scad @@ -302,6 +302,7 @@ module stroke( translate(path[0]) sphere(d=width[0]); } } else { + dummy=assert(trim1 Date: Thu, 11 Nov 2021 22:46:39 -0500 Subject: [PATCH 2/4] remove ALLPOS --- constants.scad | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/constants.scad b/constants.scad index dd8b4a1..499ac2f 100644 --- a/constants.scad +++ b/constants.scad @@ -107,7 +107,7 @@ INCH = 25.4; // Constant: LEFT // Topics: Constants, Vectors -// See Also: RIGHT, FRONT, BACK, UP, DOWN, CENTER, ALLPOS, ALLNEG +// See Also: RIGHT, FRONT, BACK, UP, DOWN, CENTER // Description: Vector pointing left. [-1,0,0] // Example(3D): Usage with `anchor` // cuboid(20, anchor=LEFT); @@ -115,7 +115,7 @@ LEFT = [-1, 0, 0]; // Constant: RIGHT // Topics: Constants, Vectors -// See Also: LEFT, FRONT, BACK, UP, DOWN, CENTER, ALLPOS, ALLNEG +// See Also: LEFT, FRONT, BACK, UP, DOWN, CENTER // Description: Vector pointing right. [1,0,0] // Example(3D): Usage with `anchor` // cuboid(20, anchor=RIGHT); @@ -124,7 +124,7 @@ RIGHT = [ 1, 0, 0]; // Constant: FRONT // Aliases: FWD, FORWARD // Topics: Constants, Vectors -// See Also: LEFT, RIGHT, BACK, UP, DOWN, CENTER, ALLPOS, ALLNEG +// See Also: LEFT, RIGHT, BACK, UP, DOWN, CENTER // Description: Vector pointing forward. [0,-1,0] // Example(3D): Usage with `anchor` // cuboid(20, anchor=FRONT); @@ -134,7 +134,7 @@ FORWARD = FRONT; // Constant: BACK // Topics: Constants, Vectors -// See Also: LEFT, RIGHT, FRONT, UP, DOWN, CENTER, ALLPOS, ALLNEG +// See Also: LEFT, RIGHT, FRONT, UP, DOWN, CENTER // Description: Vector pointing back. [0,1,0] // Example(3D): Usage with `anchor` // cuboid(20, anchor=BACK); @@ -143,7 +143,7 @@ BACK = [ 0, 1, 0]; // Constant: BOTTOM // Aliases: BOT, DOWN // Topics: Constants, Vectors -// See Also: LEFT, RIGHT, FRONT, BACK, UP, CENTER, ALLPOS, ALLNEG +// See Also: LEFT, RIGHT, FRONT, BACK, UP, CENTER // Description: Vector pointing down. [0,0,-1] // Example(3D): Usage with `anchor` // cuboid(20, anchor=BOTTOM); @@ -154,24 +154,16 @@ DOWN = BOTTOM; // Constant: TOP // Aliases: UP // Topics: Constants, Vectors -// See Also: LEFT, RIGHT, FRONT, BACK, DOWN, CENTER, ALLPOS, ALLNEG +// See Also: LEFT, RIGHT, FRONT, BACK, DOWN, CENTER // Description: Vector pointing up. [0,0,1] // Example(3D): Usage with `anchor` // cuboid(20, anchor=TOP); TOP = [ 0, 0, 1]; UP = TOP; -// Constant: ALLPOS -// Topics: Constants, Vectors -// See Also: LEFT, RIGHT, FRONT, BACK, UP, DOWN, CENTER, ALLNEG -// Description: Vector pointing right, back, and up. [1,1,1] -// Example(3D): Usage with `anchor` -// cuboid(20, anchor=ALLPOS); -ALLPOS = [ 1, 1, 1]; // Vector pointing X+,Y+,Z+. - // Constant: ALLNEG // Topics: Constants, Vectors -// See Also: LEFT, RIGHT, FRONT, BACK, UP, DOWN, CENTER, ALLPOS +// See Also: LEFT, RIGHT, FRONT, BACK, UP, DOWN, CENTER // Description: Vector pointing left, forwards, and down. [-1,-1,-1] // Example(3D): Usage with `anchor` // cuboid(20, anchor=ALLNEG); @@ -180,7 +172,7 @@ ALLNEG = [-1, -1, -1]; // Vector pointing X-,Y-,Z-. // Constant: CENTER // Aliases: CTR // Topics: Constants, Vectors -// See Also: LEFT, RIGHT, FRONT, BACK, UP, DOWN, ALLNEG, ALLPOS +// See Also: LEFT, RIGHT, FRONT, BACK, UP, DOWN // Description: Zero vector. Centered. [0,0,0] // Example(3D): Usage with `anchor` // cuboid(20, anchor=CENTER); From bc431016fc149face76baadaaab8976d6a606ff8 Mon Sep 17 00:00:00 2001 From: Adrian Mariano Date: Thu, 11 Nov 2021 22:55:03 -0500 Subject: [PATCH 3/4] remove ALLNEG and fix rect errors due to bad get_anchor default doc --- constants.scad | 8 -------- shapes2d.scad | 4 ++-- shapes3d.scad | 18 +++++++++--------- utility.scad | 2 +- 4 files changed, 12 insertions(+), 20 deletions(-) diff --git a/constants.scad b/constants.scad index 499ac2f..a1609f4 100644 --- a/constants.scad +++ b/constants.scad @@ -161,14 +161,6 @@ DOWN = BOTTOM; TOP = [ 0, 0, 1]; UP = TOP; -// Constant: ALLNEG -// Topics: Constants, Vectors -// See Also: LEFT, RIGHT, FRONT, BACK, UP, DOWN, CENTER -// Description: Vector pointing left, forwards, and down. [-1,-1,-1] -// Example(3D): Usage with `anchor` -// cuboid(20, anchor=ALLNEG); -ALLNEG = [-1, -1, -1]; // Vector pointing X-,Y-,Z-. - // Constant: CENTER // Aliases: CTR // Topics: Constants, Vectors diff --git a/shapes2d.scad b/shapes2d.scad index 1349dcf..872fdee 100644 --- a/shapes2d.scad +++ b/shapes2d.scad @@ -106,7 +106,7 @@ module square(size=1, center, anchor, spin) { // move_copies(path) color("blue") circle(d=2,$fn=8); module rect(size=1, center, rounding=0, chamfer=0, anchor, spin=0) { size = is_num(size)? [size,size] : point2d(size); - anchor = point2d(get_anchor(anchor, center)); + anchor = point2d(get_anchor(anchor, center, FRONT+LEFT, CENTER)); if (rounding==0 && chamfer==0) { attachable(anchor,spin, two_d=true, size=size) { square(size, center=true); @@ -128,7 +128,7 @@ function rect(size=1, center, rounding=0, chamfer=0, anchor, spin=0) = assert(is_num(rounding) || len(rounding)==4) let( size = is_num(size)? [size,size] : point2d(size), - anchor = point2d(get_anchor(anchor, center)), + anchor = point2d(get_anchor(anchor, center, FRONT+LEFT, CENTER)), complex = rounding!=0 || chamfer!=0 ) (rounding==0 && chamfer==0)? let( diff --git a/shapes3d.scad b/shapes3d.scad index 12101e8..422b3f8 100644 --- a/shapes3d.scad +++ b/shapes3d.scad @@ -29,7 +29,7 @@ use // When called as a function, returns a [VNF](vnf.scad) for a cube. // Arguments: // size = The size of the cube. -// center = If given, overrides `anchor`. A true value sets `anchor=CENTER`, false sets `anchor=ALLNEG`. +// center = If given, overrides `anchor`. A true value sets `anchor=CENTER`, false sets `anchor=FRONT+LEFT+BOTTOM`. // --- // anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#anchor). Default: `CENTER` // spin = Rotate this many degrees around the Z axis after anchor. See [spin](attachments.scad#spin). Default: `0` @@ -51,7 +51,7 @@ use // vnf_polyhedron(vnf); module cube(size=1, center, anchor, spin=0, orient=UP) { - anchor = get_anchor(anchor, center, ALLNEG, ALLNEG); + anchor = get_anchor(anchor, center, -[1,1,1], -[1,1,1]); size = scalar_vec3(size); attachable(anchor,spin,orient, size=size) { _cube(size, center=true); @@ -62,7 +62,7 @@ module cube(size=1, center, anchor, spin=0, orient=UP) function cube(size=1, center, anchor, spin=0, orient=UP) = let( siz = scalar_vec3(size), - anchor = get_anchor(anchor, center, ALLNEG, ALLNEG), + anchor = get_anchor(anchor, center, -[1,1,1], -[1,1,1]), unscaled = [ [-1,-1,-1],[1,-1,-1],[1,1,-1],[-1,1,-1], [-1,-1, 1],[1,-1, 1],[1,1, 1],[-1,1, 1], @@ -110,7 +110,7 @@ function cube(size=1, center, anchor, spin=0, orient=UP) = // edges = Edges to mask. See [Specifying Edges](edges.scad#section-specifying-edges). Default: all edges. // except = Edges to explicitly NOT mask. See [Specifying Edges](edges.scad#section-specifying-edges). Default: No edges. // trimcorners = If true, rounds or chamfers corners where three chamfered/rounded edges meet. Default: `true` -// p1 = Align the cuboid's corner at `p1`, if given. Forces `anchor=ALLNEG`. +// p1 = Align the cuboid's corner at `p1`, if given. Forces `anchor=FRONT+LEFT+BOTTOM`. // p2 = If given with `p1`, defines the cornerpoints of the cuboid. // anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#anchor). Default: `CENTER` // spin = Rotate this many degrees around the Z axis. See [spin](attachments.scad#spin). Default: `0` @@ -243,11 +243,11 @@ module cuboid( if (!is_undef(p1)) { if (!is_undef(p2)) { translate(pointlist_bounds([p1,p2])[0]) { - cuboid(size=v_abs(p2-p1), chamfer=chamfer, rounding=rounding, edges=edges, trimcorners=trimcorners, anchor=ALLNEG) children(); + cuboid(size=v_abs(p2-p1), chamfer=chamfer, rounding=rounding, edges=edges, trimcorners=trimcorners, anchor=-[1,1,1]) children(); } } else { translate(p1) { - cuboid(size=size, chamfer=chamfer, rounding=rounding, edges=edges, trimcorners=trimcorners, anchor=ALLNEG) children(); + cuboid(size=size, chamfer=chamfer, rounding=rounding, edges=edges, trimcorners=trimcorners, anchor=-[1,1,1]) children(); } } } else { @@ -895,7 +895,7 @@ function rect_tube( // size = [width, thickness, height] // center = If given, overrides `anchor`. A true value sets `anchor=CENTER`, false sets `anchor=UP`. // --- -// anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#anchor). Default: `ALLNEG` +// anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#anchor). Default: `FRONT+LEFT+BOTTOM` // spin = Rotate this many degrees around the Z axis after anchor. See [spin](attachments.scad#spin). Default: `0` // orient = Vector to rotate top towards, after spin. See [orient](attachments.scad#orient). Default: `UP` // @@ -908,7 +908,7 @@ function rect_tube( module wedge(size=[1, 1, 1], center, anchor, spin=0, orient=UP) { size = scalar_vec3(size); - anchor = get_anchor(anchor, center, ALLNEG, ALLNEG); + anchor = get_anchor(anchor, center, -[1,1,1], -[1,1,1]); vnf = wedge(size, center=true); attachable(anchor,spin,orient, size=size, size2=[size.x,0], shift=[0,-size.y/2]) { if (size.z > 0) { @@ -922,7 +922,7 @@ module wedge(size=[1, 1, 1], center, anchor, spin=0, orient=UP) function wedge(size=[1,1,1], center, anchor, spin=0, orient=UP) = let( size = scalar_vec3(size), - anchor = get_anchor(anchor, center, ALLNEG, ALLNEG), + anchor = get_anchor(anchor, center, -[1,1,1], -[1,1,1]), pts = [ [ 1,1,-1], [ 1,-1,-1], [ 1,-1,1], [-1,1,-1], [-1,-1,-1], [-1,-1,1], diff --git a/utility.scad b/utility.scad index 61219f9..9e9dadd 100644 --- a/utility.scad +++ b/utility.scad @@ -418,7 +418,7 @@ function all_defined(v,recursive=false) = // Arguments: // anchor = The anchor name or vector. // center = If not `undef`, this overrides the value of `anchor`. -// uncentered = The value to return if `center` is not `undef` and evaluates as false. Default: ALLNEG +// uncentered = The value to return if `center` is not `undef` and evaluates as false. Default: BOTTOM // dflt = The default value to return if both `anchor` and `center` are `undef`. Default: `CENTER` // Example: // anchr1 = get_anchor(undef, undef, BOTTOM, TOP); // Returns: [0, 0, 1] (TOP) From f605bafb0d8e94281a4a548f3f4d56208997fa0c Mon Sep 17 00:00:00 2001 From: Adrian Mariano Date: Fri, 12 Nov 2021 06:18:14 -0500 Subject: [PATCH 4/4] fix tests --- tests/test_geometry.scad | 2 +- tests/test_shapes2d.scad | 7 +++++-- tests/test_shapes3d.scad | 2 +- tests/test_utility.scad | 12 ++++++------ 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/tests/test_geometry.scad b/tests/test_geometry.scad index 4706c7f..e800c19 100644 --- a/tests/test_geometry.scad +++ b/tests/test_geometry.scad @@ -842,7 +842,7 @@ module test_centroid() { // VNFs assert_approx(centroid(cube(100, center=false)), [50,50,50]); assert_approx(centroid(cube(100, center=true)), [0,0,0]); - assert_approx(centroid(cube(100, anchor=ALLPOS)), [-50,-50,-50]); + assert_approx(centroid(cube(100, anchor=[1,1,1])), [-50,-50,-50]); assert_approx(centroid(cube(100, anchor=BOT)), [0,0,50]); assert_approx(centroid(cube(100, anchor=TOP)), [0,0,-50]); assert_approx(centroid(sphere(d=100, anchor=CENTER, $fn=36)), [0,0,0]); diff --git a/tests/test_shapes2d.scad b/tests/test_shapes2d.scad index 5260810..251d902 100644 --- a/tests/test_shapes2d.scad +++ b/tests/test_shapes2d.scad @@ -28,9 +28,12 @@ test_circle(); module test_rect() { assert_equal(rect(100,anchor=CENTER), [[50,-50],[-50,-50],[-50,50],[50,50]]); - assert_equal(rect(100), [[100,0],[0,0],[0,100],[100,100]]); - assert_equal(rect([100,80]), [[100,0],[0,0],[0,80],[100,80]]); + assert_equal(rect(100), [[50,-50],[-50,-50],[-50,50],[50,50]]); + assert_equal(rect(100,center=false), [[100,0],[0,0],[0,100],[100,100]]); + assert_equal(rect([100,80],center=false), [[100,0],[0,0],[0,80],[100,80]]); assert_equal(rect([100,80],anchor=CENTER), [[50,-40],[-50,-40],[-50,40],[50,40]]); + assert_equal(rect([100,80]), [[50,-40],[-50,-40],[-50,40],[50,40]]); + assert_equal(rect([100,80],center=true), [[50,-40],[-50,-40],[-50,40],[50,40]]); assert_equal(rect([100,80],anchor=FRONT+LEFT), [[100,0],[0,0],[0,80],[100,80]]); assert_equal(rect([100,80],anchor=BACK+RIGHT), [[0,-80],[-100,-80],[-100,0],[0,0]]); assert_approx(rect([100,80],rounding=10,anchor=CENTER,$fn=12), [[50,-30],[48.6602540378,-35],[45,-38.6602540378],[40,-40],[-40,-40],[-45,-38.6602540378],[-48.6602540378,-35],[-50,-30],[-50,30],[-48.6602540378,35],[-45,38.6602540378],[-40,40],[40,40],[45,38.6602540378],[48.6602540378,35],[50,30]]); diff --git a/tests/test_shapes3d.scad b/tests/test_shapes3d.scad index c102351..33b744b 100644 --- a/tests/test_shapes3d.scad +++ b/tests/test_shapes3d.scad @@ -8,7 +8,7 @@ module test_cube() { assert_equal(cube([60,80,100],anchor=CENTER), [[[-30,-40,-50],[30,-40,-50],[30,40,-50],[-30,40,-50],[-30,-40,50],[30,-40,50],[30,40,50],[-30,40,50]],[[0,1,2],[0,2,3],[0,4,5],[0,5,1],[1,5,6],[1,6,2],[2,6,7],[2,7,3],[3,7,4],[3,4,0],[6,4,7],[6,5,4]]]); assert_equal(cube([60,80,100],center=false), [[[0,0,0],[60,0,0],[60,80,0],[0,80,0],[0,0,100],[60,0,100],[60,80,100],[0,80,100]],[[0,1,2],[0,2,3],[0,4,5],[0,5,1],[1,5,6],[1,6,2],[2,6,7],[2,7,3],[3,7,4],[3,4,0],[6,4,7],[6,5,4]]]); assert_equal(cube([60,80,100]), [[[0,0,0],[60,0,0],[60,80,0],[0,80,0],[0,0,100],[60,0,100],[60,80,100],[0,80,100]],[[0,1,2],[0,2,3],[0,4,5],[0,5,1],[1,5,6],[1,6,2],[2,6,7],[2,7,3],[3,7,4],[3,4,0],[6,4,7],[6,5,4]]]); - assert_equal(cube([60,80,100],anchor=ALLNEG), [[[0,0,0],[60,0,0],[60,80,0],[0,80,0],[0,0,100],[60,0,100],[60,80,100],[0,80,100]],[[0,1,2],[0,2,3],[0,4,5],[0,5,1],[1,5,6],[1,6,2],[2,6,7],[2,7,3],[3,7,4],[3,4,0],[6,4,7],[6,5,4]]]); + assert_equal(cube([60,80,100],anchor=-[1,1,1]), [[[0,0,0],[60,0,0],[60,80,0],[0,80,0],[0,0,100],[60,0,100],[60,80,100],[0,80,100]],[[0,1,2],[0,2,3],[0,4,5],[0,5,1],[1,5,6],[1,6,2],[2,6,7],[2,7,3],[3,7,4],[3,4,0],[6,4,7],[6,5,4]]]); assert_equal(cube([60,80,100],anchor=TOP), [[[-30,-40,-100],[30,-40,-100],[30,40,-100],[-30,40,-100],[-30,-40,0],[30,-40,0],[30,40,0],[-30,40,0]],[[0,1,2],[0,2,3],[0,4,5],[0,5,1],[1,5,6],[1,6,2],[2,6,7],[2,7,3],[3,7,4],[3,4,0],[6,4,7],[6,5,4]]]); } test_cube(); diff --git a/tests/test_utility.scad b/tests/test_utility.scad index 0ceddb0..250c082 100644 --- a/tests/test_utility.scad +++ b/tests/test_utility.scad @@ -352,12 +352,12 @@ test_all_defined(); module test_get_anchor() { - assert_equal(get_anchor(UP,true,ALLNEG,BOT),CENTER); - assert_equal(get_anchor(UP,false,ALLNEG,BOT),ALLNEG); - assert_equal(get_anchor(UP,undef,ALLNEG,BOT),UP); - assert_equal(get_anchor(undef,true,ALLNEG,BOT),CENTER); - assert_equal(get_anchor(undef,false,ALLNEG,BOT),ALLNEG); - assert_equal(get_anchor(undef,undef,ALLNEG,BOT),BOT); + assert_equal(get_anchor(UP,true,-[1,1,1],BOT),CENTER); + assert_equal(get_anchor(UP,false,-[1,1,1],BOT),-[1,1,1]); + assert_equal(get_anchor(UP,undef,-[1,1,1],BOT),UP); + assert_equal(get_anchor(undef,true,-[1,1,1],BOT),CENTER); + assert_equal(get_anchor(undef,false,-[1,1,1],BOT),-[1,1,1]); + assert_equal(get_anchor(undef,undef,-[1,1,1],BOT),BOT); } test_get_anchor();