[NTG-context] What was that 'rounding paths' metafun(?) function again?
Gerben Wierda
gerben.wierda at rna.nl
Sun Apr 5 13:18:12 CEST 2020
Yes, I meant cornered.
But it turns out it works worse in my case, I get paths with hundreds of segments and a run that goes amok. But that made me find a mistake in my code and now I’m using my own again and it works fine:
vardef softenPath( expr hardPath) =
save softPath; path softPath;
save len; len := length hardPath;
save rounding; rounding := 5;
save i;
for i=0 upto len:
if (i=0):
% first pair
softPath := point i of hardPath;
elseif (i=len):
% lastpair
softPath := softPath -- point i of hardPath;
else:
% intermediate pair
save subOne; path subOne; subOne := subpath(i-1, i) of hardPath;
save subTwo; path subTwo; subTwo := subpath(i, i+1) of hardPath;
save lenOne; numeric lenOne; lenOne := arclength subOne;
save lenTwo; numeric lenTwo; lenTwo := arclength subTwo;
save pointOne, pointTwo; pair pointOne, pointTwo;
pointOne := point (arctime (lenOne-rounding) of subOne) of subOne;
pointTwo := point (arctime rounding of subTwo) of subTwo;
save dirOne, dirTwo; pair dirOne, dirTwo;
dirOne := direction (arctime (lenOne-rounding) of subOne) of subOne;
dirTwo := direction (arctime (rounding) of subTwo) of subTwo;
softPath := softPath -- pointOne{dirOne} .. {dirTwo}pointTwo;
fi
endfor;
softPath
enddef;
Fixed rounding of 5bp, but that is easy to change.
> On 5 Apr 2020, at 12:37, Wolfgang Schuster <wolfgang.schuster.lists at gmail.com> wrote:
>
> Gerben Wierda schrieb am 05.04.2020 um 12:31:
>> I think I saw a function in MetaFun somehwre that you could give a ‘hard’ path, i.e. (0,0) -- (0,1) — (1,1) and it would become a path with nicely rounded (part of a circle) corners (still straight lines), but I can’t find it anymore. I wrote my own, but it is giving me headaches so I’d like to find something that is better than what I produce.
>
> You you mean "cornered ..." or "smoothed ..."?
>
> Wolfgang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ntg.nl/pipermail/ntg-context/attachments/20200405/9f3eb063/attachment.htm>
More information about the ntg-context
mailing list