vardef extended(expr p) =
-42 unitvector(direction 0 of p) shifted point 0 of p .. p ..
+42 unitvector(direction 1 of p) shifted point 1 of p
enddef;
vardef chopper expr t of p =
(up--down) scaled 42
rotated 1/2(angle direction t-eps of p + angle direction t+eps of p)
shifted point t of p
enddef;
vardef beside(expr p, d) =
save n, a, b, aa, bb; numeric n; n = length p;
pair a, b, aa, bb; path _part[];
for i = 1 upto n:
aa := postcontrol i-1 of p - point i-1 of p;
bb := point i of p - precontrol i of p;
a := unitvector(aa) rotated -90 scaled d;
b := unitvector(bb) rotated -90 scaled d;
_part[i] = extended(
point i-1 of p shifted a {aa} .. point i of p shifted b {bb}
) cutbefore chopper i-1 of p cutafter chopper i of p;
endfor
_part[1] for i=2 upto n: .. _part[i] endfor if cycle p: .. cycle fi
enddef;
beginfig(1);