[Therion] Main route through a cave
Tarquin Wilton-Jones
tarquin.wilton-jones at ntlworld.com
Wed Jun 16 08:37:23 CEST 2021
> (I would love to understand why arclength / width gives eg. 5, but it
> will actually have enough space for 5 dots and 5 gaps, which should be
> 10 times the width, not 5. Is arclength half the actual length?)
Because "PenA scaled" is a multiplication factor, not an actual size.
And pen sizes change with the scale/basescale, so my formula worked only
by chance at the specific scale I was using. Oops.
This code should work correctly, by measuring the pen:
def l_u_route (expr P)=
begingroup;
save scale, multiplier, linewidth, dotwidth, len, steps, dotgap;
T:=identity;
multiplier:=5;
linewidth:=((xpart (lrcorner PenA)) - (xpart (llcorner PenA))) *
multiplier;
% If you make the dotwidth too small, MetaPost cannot perform the
% dashpattern calculations, and it gets the spacing wrong
% minimum limit is 0.0002
dotwidth:=0.001;
len:=arclength P;
% each dot needs space for the dot, and a gap at each end half
% as wide as the dot, so a total space of twice the line width
% short lines still need a dot
steps:=max(round(len / (2 * linewidth)), 1);
% the total amount of gap (with the wasted space for the dot
% removed) which will be split into a before half and after half
dotgap:=(len / steps) - dotwidth;
pickup PenA scaled multiplier;
thdraw P dashed dashpattern(off dotgap/2 on dotwidth off dotgap/2)
withcolor (0.9,0,1);
endgroup;
enddef;
initsymbol("l_u_route");
This uses the same basic approach as adjust_step, but uses rounding and
will always return at least 1 step, while adjust_step uses flooring and
will return at least 2 steps. It could be made to use adjust_step, and
risk overlaps for very short lines:
dotgap:=adjust_step(len, 2 * linewidth) - dotwidth;
More information about the Therion
mailing list