mirror of
https://github.com/BelfrySCAD/BOSL2.git
synced 2025-01-17 09:59:39 +00:00
Merge pull request #728 from adrianVmariano/master
rect center, stroke error message
This commit is contained in:
commit
647d327df5
9 changed files with 33 additions and 45 deletions
|
@ -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,33 +154,17 @@ 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
|
||||
// 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
|
||||
// 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);
|
||||
|
|
|
@ -302,6 +302,7 @@ module stroke(
|
|||
translate(path[0]) sphere(d=width[0]);
|
||||
}
|
||||
} else {
|
||||
dummy=assert(trim1<path_length(path)-trim2, "Path is too short for endcap(s). Try a smaller width, or set endcap_length to a smaller value.");
|
||||
pathcut = _path_cut_points(path, [trim1, path_length(path)-trim2], closed=false);
|
||||
pathcut_su = _cut_to_seg_u_form(pathcut,path);
|
||||
path2 = _path_cut_getpaths(path, pathcut, closed=false)[1];
|
||||
|
|
|
@ -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 = get_anchor(anchor, center, FRONT+LEFT, FRONT+LEFT);
|
||||
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, FRONT+LEFT, FRONT+LEFT)),
|
||||
anchor = point2d(get_anchor(anchor, center, FRONT+LEFT, CENTER)),
|
||||
complex = rounding!=0 || chamfer!=0
|
||||
)
|
||||
(rounding==0 && chamfer==0)? let(
|
||||
|
|
|
@ -29,7 +29,7 @@ use <builtins.scad>
|
|||
// 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 <builtins.scad>
|
|||
// 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],
|
||||
|
|
|
@ -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]);
|
||||
|
|
|
@ -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]]);
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue