def l_slope (expr P,S)(text Q) = %show Q; T:=identity; numeric dirs[]; numeric lengths[]; for i=Q: dirs[redpart i]:=greenpart i; lengths[redpart i]:=bluepart i; endfor; li:=length(P); % last alw_perpendicular:=true; for i=0 upto li: if unknown dirs[i]: dirs[i]:=-1; else: if dirs[i]>-1: dirs[i]:=((90-dirs[i]) - angle(thdir(P,i))) mod 360; alw_perpendicular:=false; fi; fi; if unknown lengths[i]: lengths[i]:=-1; fi; endfor; %for i=0 upto li: show dirs[i]; endfor; ni:=0; % next pi:=0; % previous for i=0 upto li: d:=dirs[i]; if d=-1: if (i=0) or (i=li): dirs[i] := angle(thdir(P,i) rotated 90) mod 360; pi:=i; else: if ni<=i: for j=i upto li: ni:=j; exitif dirs[j]>-1; endfor; fi; w:=arclength(subpath(pi,i) of P) / arclength(subpath(pi,ni) of P); dirs[i]:=w[dirs[pi],dirs[ni]]; % if (dirs[i]-angle(thdir(P,i))) mod 360>180: % dirs[i]:=w[dirs[ni],dirs[pi]]; % message("*******"); % fi; fi; else: pi:=i; fi; endfor; %for i=0 upto li: show dirs[i]; endfor; ni:=0; % next pi:=0; % previous for i=0 upto li: l:=lengths[i]; if l=-1: if (i=0) or (i=li): lengths[i] := 1cm; % should never happen! thwarning("slope width at the end point not specified"); pi:=i; else: if ni<=i: for j=i+1 upto li: ni:=j; exitif lengths[j]>-1; endfor; fi; w:=arclength(subpath(pi,i) of P) / arclength(subpath(pi,ni) of P); lengths[i]:=w[lengths[pi],lengths[ni]]; pi:=i; fi; else: pi:=i; fi; endfor; % for i=0 upto li: show lengths[i]; endfor; T:=identity; boolean par; cas := 0.3u; krok := 0.7u; dlzka := (arclength P); if dlzka>3u: dlzka:=dlzka-0.6u fi; mojkrok:=adjust_step(dlzka,1.4u) / 5; pickup PenD; par := false; forever: t := arctime cas of P; if t mod 1>0: % not a key point w := (arclength(subpath(floor t,t) of P) / arclength(subpath(floor t,ceiling t) of P)); if alw_perpendicular: a := 90; else: a := w[dirs[floor t],dirs[ceiling t]]; fi; l := w[lengths[floor t],lengths[ceiling t]]; else: if alw_perpendicular: a := 90; else: a:= dirs[t]; fi; l:=lengths[t]; fi; a := a + angle(thdir(P,t)); thdraw (point t of P) -- ((point t of P) + if par: 0.333 * fi l * unitvector(dir(a))); cas := cas + mojkrok; par := not par; exitif cas > dlzka + .3u + (krok / 3); % for rounding errors endfor; if S = 1: pickup PenC; draw P fi; %pickup pencircle scaled 3pt; %for i=0 upto li: draw point i of P; endfor; enddef;
La ligne suivante a été modifiée:
mojkrok:=adjust_step(dlzka,1.4u) / 5;
La ligne Originale:
mojkrok:=adjust_step(dlzka,1.4u) / 2;