70 function _polygon_turtle_path_p_line_p
76 ) = is_undef( wc ) ? [t]
93 function _polygon_turtle_path_p_repeat
111 rest = _polygon_turtle_path_p_repeat( sub_s, n-1, next_p0, next_h, _p0_g )
113 [ concat( pts, rest[0] ), rest[1] ];
606 oper =
first( step ),
607 argv =
tailn( step ),
608 argc = is_undef( argv ) ? 0 : is_list( argv ) ? len( argv ) : 1,
625 is_oneof( oper, [
"turn_left",
"tl"] ) && (argc > 0) ?
631 :
is_oneof( oper, [
"turn_right",
"tr"] ) && (argc > 0) ?
637 :
is_oneof( oper, [
"close",
"cl"] ) ?
644 [ _polygon_turtle_path_p_line_p( p0=p0, t=g, wc=wc, fn=fn ), h ]
649 :
is_oneof( oper, [
"goto_xy",
"gxy"] ) && (argc > 1) ?
650 let( t = [a1, a2], wc = a3, fn = a4 )
651 [ _polygon_turtle_path_p_line_p( p0=p0, t=t, wc=wc, fn=fn ), h ]
653 :
is_oneof( oper, [
"goto_x",
"gx"] ) && (argc > 0) ?
654 let( t = [a1, p0.y], wc = a2, fn = a3 )
655 [ _polygon_turtle_path_p_line_p( p0=p0, t=t, wc=wc, fn=fn ), h ]
657 :
is_oneof( oper, [
"goto_y",
"gy"] ) && (argc > 0) ?
658 let( t = [p0.x, a1], wc = a2, fn = a3 )
659 [ _polygon_turtle_path_p_line_p( p0=p0, t=t, wc=wc, fn=fn ), h ]
664 :
is_oneof( oper, [
"delta_xy",
"dxy"] ) && (argc > 1) ?
665 let( t = p0 + [a1, a2], wc = a3, fn = a4 )
666 [ _polygon_turtle_path_p_line_p( p0=p0, t=t, wc=wc, fn=fn ), h ]
668 :
is_oneof( oper, [
"delta_x",
"dx"] ) && (argc > 0) ?
669 let( t = p0 + [a1, 0], wc = a2, fn = a3 )
670 [ _polygon_turtle_path_p_line_p( p0=p0, t=t, wc=wc, fn=fn ), h ]
672 :
is_oneof( oper, [
"delta_y",
"dy"] ) && (argc > 0) ?
673 let( t = p0 + [0, a1], wc = a2, fn = a3 )
674 [ _polygon_turtle_path_p_line_p( p0=p0, t=t, wc=wc, fn=fn ), h ]
679 :
is_oneof( oper, [
"delta_xa",
"dxa"] ) && (argc > 1) ?
680 let( t = p0 + [a1, a1 * tan(a2)], wc = a3, fn = a4 )
681 [ _polygon_turtle_path_p_line_p( p0=p0, t=t, wc=wc, fn=fn ), h ]
683 :
is_oneof( oper, [
"delta_ya",
"dya"] ) && (argc > 1) ?
684 let( t = p0 + [a1 / tan(a2), a1], wc = a3, fn = a4 )
685 [ _polygon_turtle_path_p_line_p( p0=p0, t=t, wc=wc, fn=fn ), h ]
690 :
is_oneof( oper, [
"move_ar",
"mar"] ) && (argc > 1) ?
692 [ _polygon_turtle_path_p_line_p( p0=p0, t=t, wc=wc, fn=fn ), h ]
697 :
is_oneof( oper, [
"move_rr",
"mrr"] ) && (argc > 1) ?
699 [ _polygon_turtle_path_p_line_p( p0=p0, t=t, wc=wc, fn=fn ), h ]
704 :
is_oneof( oper, [
"move_fw",
"mfw"] ) && (argc > 0) ?
706 [ _polygon_turtle_path_p_line_p( p0=p0, t=t, wc=wc, fn=fn ), h ]
711 :
is_oneof( oper, [
"arc_fw",
"afw"] ) && (argc > 1) ?
721 perp_sign = (a >= 0) ? 1 : -1,
722 h_perp = h + perp_sign * 90,
723 c_arc = p0 + r * [cos(h_perp), sin(h_perp)],
726 a_start = h + perp_sign * (-90),
740 out_h = upd ? h + a : h
747 :
is_oneof( oper, [
"arc_pv",
"apv"] ) && (argc > 2) ?
748 let( v2 = is_list(a2) ? [a1, a2] : a2 )
757 :
is_oneof( oper, [
"arc_vv",
"avv"] ) && (argc > 2) ?
761 v2 = is_list(a2) ? [b1, a2] : a2
771 :
is_oneof( oper, [
"arc_blend",
"ab"] ) && (argc > 2) ?
780 :
is_oneof( oper, [
"bezier",
"bz"] ) && (argc > 0) ?
787 pts = pre ? concat( [p0], ctrl_pts ) : ctrl_pts
794 :
is_oneof( oper, [
"spline",
"spl"] ) && (argc > 0) ?
802 pts = pre ? concat( [p0], knots ) : knots
809 :
is_oneof( oper, [
"repeat",
"rpt"] ) && (argc > 0) ?
814 result = _polygon_turtle_path_p_repeat( sub_s, n, p0, h, _p0_g )
821 :
is_oneof( oper, [
"repeat_mx",
"rptmx"] ) && (argc > 0) ?
838 ax_o = [ p0.x, p0.y + axis ],
841 mir_p0 = ms ?
mirror_p( [p0], [0,1], ax_o )[0]
842 :
mirror_p( [fwd_p0_end], [0,1], ax_o )[0],
848 mir =
mirror_p( mir_raw[0], [0,1], ax_o ),
849 mir_out = rev ? list_reverse(mir) : mir,
852 out_h = kh ? fwd_h : h
854 [ concat( fwd, mir_out ), out_h ]
859 :
is_oneof( oper, [
"repeat_my",
"rptmy"] ) && (argc > 0) ?
876 ax_o = [ p0.x + axis, p0.y ],
879 mir_p0 = ms ?
mirror_p( [p0], [1,0], ax_o )[0]
880 :
mirror_p( [fwd_p0_end], [1,0], ax_o )[0],
886 mir =
mirror_p( mir_raw[0], [1,0], ax_o ),
887 mir_out = rev ? list_reverse(mir) : mir,
890 out_h = kh ? fwd_h : h
892 [ concat( fwd, mir_out ), out_h ]
897 :
is_oneof( oper, [
"transform",
"xfrm"] ) && (argc > 1) ?
913 xfmd =
transform_p( c=sub_r[0], m=mn, a=r, t=t, o=p0 ),
916 out_h = upd_h ? sub_h + r : h
923 :
is_oneof( oper, [
"path_p",
"pp"] ) && (argc > 0) ?
934 "ERROR: p0=", p0,
", h=", h,
", _s_n=", _s_n,
", _p0_g=", _p0_g,
935 ", operation=", oper,
", argv=", argv,
", argc=", argc
954 is_oneof( oper, [
"transform",
"xfrm"] ) ?
960 next_h =
is_oneof( oper, [
"transform",
"xfrm"] ) ?
980 result = term ? p : concat( p, rest[0] ),
981 final_h = term ? next_h : rest[1]
983 m == 1 ? [result, final_h] : result;
origin2d
<point-2d> The origin point coordinate in 2d Euclidean space.
empty_lst
<list> A list with no values (the empty list).
function line_tp(l)
Return the terminal point of a line or vector.
function line2d_new(m=1, a=0, p1=origin2d, p2, v)
Construct a 2 dimensional directed line.
function distance_pp(p1, p2)
Compute the distance between two points.
function defined_eonb_or(v, i, d)
Returns the list element or scalar numeric or boolean value if defined, otherwise returns the default...
function defined_e_or(v, i, d)
Returns an element from an iterable if it exists, or a default value if not.
function last(v)
Return the last element of an iterable value.
function second(v)
Return the second element of an iterable value.
function first(v)
Return the first element of an iterable value.
function tailn(v, n=1)
Return a list containing all but the first n elements of an iterable value.
function is_oneof(v, cv)
Test if a value equals one of the comparison values.
function is_empty(v)
Test if an iterable value is empty.
function strl(v)
Convert a list of values to a concatenated string.
function defined_or(v, d)
Return given value, if defined, or a secondary value, if primary is not defined.
function mirror_p(c, m, o)
Mirror all coordinates about a plane or line defined by a normal vector.
function transform_p(c, m, a, av, center=false, o, t)
Apply an optional mirror, rotation, and translation to a list of 2D or 3D coordinates.
function polygon_arc_sweep_p(r=1, o=origin2d, v1=x_axis2d_uv, v2=x_axis2d_uv, fn, cw=true)
Compute coordinates of an arc with constant radius between two vectors in 2D.
function polygon_bezier_p(c, fn, cw=true)
Compute coordinates for a degree-n Bézier curve in 2D.
function polygon_spline_p(c, fn, closed=false, cw=true)
Compute coordinates for a Catmull-Rom spline through a list of knot points in 2D.
function polygon_line_wave_p(p1=origin2d, p2=x_axis2d_uv, p=1, a=1, w=1, m=0, t, fn)
Generate 2D coordinate points along a line with periodic waveform lateral displacement.
function polygon_arc_blend_p(p1, p2, p3, r=1, fn, cw=true)
Compute coordinates for a circular arc blend between two line segments in 2D.