diff --git a/shapes2d.scad b/shapes2d.scad index 9f72b68..9e1334c 100644 --- a/shapes2d.scad +++ b/shapes2d.scad @@ -580,7 +580,7 @@ function star(n, r, d, or, od, ir, id, step, realign=false, anchor=CENTER, spin= count = num_defined([ir,id,step]), stepOK = is_undef(step) || (step>1 && stepindex+2 && !is_string(commands[index+2]) ? 3 : + // For these, the first arg is required, second arg is present if it is not a string + in_list(commands[index], one_or_two_arg) && len(commands)>index+2 && !is_string(commands[index+2]) ? 3 : is_string(commands[index+1])? 1 : // If 2nd item is a string it's must be a new command 2; // Otherwise we have command and arg @@ -806,7 +806,7 @@ function _turtle_command(command, parm, parm2, state, index) = step=1, angle=2, parm = !is_string(parm) ? parm : undef, - parm2 = !is_string(parm2) ? parm2 : undef, + parm2 = !is_string(parm2) ? parm2 : undef, needvec = ["jump"], neednum = ["untilx","untily","xjump","yjump","angle","length","scale","addlength"], needeither = ["setdir"], @@ -853,18 +853,27 @@ function _turtle_command(command, parm, parm2, state, index) = command=="length" ? list_set(state, step, parm*normalize(state[step])) : command=="scale" ? list_set(state, step, parm*state[step]) : command=="addlength" ? list_set(state, step, state[step]+normalize(state[step])*parm) : - command=="arcleft" || command=="arcright" ? - let( myangle = default(parm2,state[angle]), - lrsign = command=="arcleft" ? 1 : -1, - radius = parm, - center = lastpt + lrsign*radius*line_normal([0,0],state[step]), - arcpath = myangle == 0 ? [] : - arc(segs(radius), points = [lastpt, rot(cp=center, p=lastpt, a=lrsign*myangle/2), - rot(cp=center, p=lastpt, a=lrsign*myangle)]) - ) - list_set(state, [path,step], - [ concat(state[path],slice(arcpath,1,-1)), - rot(lrsign * myangle,p=state[step],planar=true) ]) : + command=="arcleft" || command=="arcright" ? + let( + myangle = default(parm2,state[angle]), + lrsign = command=="arcleft" ? 1 : -1, + radius = parm, + center = lastpt + lrsign*radius*line_normal([0,0],state[step]), + arcpath = myangle == 0 ? [] : arc( + segs(radius), + points = [ + lastpt, + rot(cp=center, p=lastpt, a=lrsign*myangle/2), + rot(cp=center, p=lastpt, a=lrsign*myangle) + ] + ) + ) + list_set( + state, [path,step], [ + concat(state[path], slice(arcpath,1,-1)), + rot(lrsign * myangle,p=state[step],planar=true) + ] + ) : assert(false,str("Unknown turtle command \"",command,"\" at index",index)) [];