catch case where endcaps are too long for path in stroke()

make rect() default to centered
This commit is contained in:
Adrian Mariano 2021-11-11 22:43:19 -05:00
parent 4ddc340fd5
commit 5b62f2859a
2 changed files with 3 additions and 2 deletions

View file

@ -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];

View file

@ -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));
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)),
complex = rounding!=0 || chamfer!=0
)
(rounding==0 && chamfer==0)? let(