[Therion] metapost map-connection

bruce at tomo.co.nz bruce at tomo.co.nz
Thu Oct 9 20:35:40 CEST 2025


- Is it possible to modifiy in metapost the line which is dessined into 2 points map-connection ?: 

 

I took what maybe a simpler approach to that Tarquin describes, minimally altering the default metapost, but adding a clear start and end point to the map-connection line.



What I discovered when attempting this was that arrow heads are intimately connected, in the default metapost, to map-connection lines.

The example below is complicated by a change we made to refine the alignment of arrow heads when the incoming line is curved.

If you want I could dig out the code prior to the arrow head change, but you can probably extract that from your own installation.

 

Bruce

 

#ARROW and MAP-CONNECTION REDEFINITIONS

#--------------------------

#Edited Bruce Mutton Apr2018 Redefinition of map-connection line and arrow heads

code metapost

% Q = 0 -- none (no arrows)

%     1 -- end  (default)

%     2 -- begin

%     3 -- both

def l_arrow (expr P, Q) =

% Arrow heads rotated so that line path intersects middle of back of arrowhead.  Johnny Willis 3Jun2023

  T:=identity;

  pickup PenC;

  path Pcircle_s, Pcircle_e, ah_start, ah_end, p, P_mod, errcheck;

  pair sp, ep, int_start, int_end;

  numeric alength, c_diam;

 

ep = point 0 of P;

sp = point infinity of P;

alength = 0.5u;

c_diam = 2*alength;

Pcircle_s = fullcircle scaled c_diam shifted sp;

Pcircle_e = fullcircle scaled c_diam shifted ep;

 

p := (-0.1u,-alength)--(-0,0)--(.1u,-alength)--cycle;

 

errcheck = (ep) -- (sp);

 

if arclength(errcheck) < alength: %if end points P shorter than arrow head, don't trim P

int_end   = ep;

int_start = sp;

ah_end   = (sp) -- (ep);

ah_start = (ep) -- (sp);

 

else: %set up for trimming P at back of arrowheads

 

int_end   = Pcircle_e intersectionpoint P;

int_start = Pcircle_s intersectionpoint P;

ah_end   = (int_end) -- (ep);

ah_start = (int_start) -- (sp);

 

fi;

 

if Q = 0: % -head none

P_mod = P;

fi;

 

if Q = 1: %arrow at end of line -head end

draw p rotated (angle(thdir(ah_end,0))-90) shifted (point 0 of P);

fill p rotated (angle(thdir(ah_end,0))-90) shifted (point 0 of P);

 P_mod = P cutbefore int_end;

fi;

 

if Q = 2: %arrow at start of line -head begin

draw p rotated (angle(thdir(ah_start,0))-90) shifted (point infinity of P);

fill p rotated (angle(thdir(ah_start,0))-90) shifted (point infinity of P);

 P_mod = P cutafter int_start;

fi;

if Q = 3: %arrow at both ends of line -head both

draw p rotated (angle(thdir(ah_start,0))-90) shifted (point infinity of P);

fill p rotated (angle(thdir(ah_start,0))-90) shifted (point infinity of P);

draw p rotated (angle(thdir(ah_end,0))-90) shifted (point 0 of P);

fill p rotated (angle(thdir(ah_end,0))-90) shifted (point 0 of P);

 P_mod = (P cutbefore int_end) cutafter int_start;

fi;

 thdraw P_mod;

enddef;

 

def l_mapconnection (expr P) =

  thdrawoptions(dashed dashpattern(on 1bp off 2bp on 1bp off 2bp) 

                scaled (2 * optical_zoom) withpen PenA);

 

  %draw map-connection line with arrowhead at end

  l_arrow(P,1); %How to double or triple arrowhead size with this call?

  

  %draw dot at start of map-connection line

  thdraw point infinity of P withpen pencircle scaled 0.3u; 

  %Why infinity and not 0 for start??  

  %If point before arrow head, then point does not render in legend but does on map?? 

  

  thdrawoptions();

enddef;

endcode

 

# and if necessary in some other layout…

symbol-colour line map-connection [54 7 60] #purple

symbol-show line map-connection

 

#And then in th-config but outside of a layout…

text en "line map-connection"    "passage offset connection"

 

#END

 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.speleo.sk/pipermail/therion/attachments/20251010/3fbfa977/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.png
Type: image/png
Size: 96489 bytes
Desc: not available
URL: <http://mailman.speleo.sk/pipermail/therion/attachments/20251010/3fbfa977/attachment-0001.png>


More information about the Therion mailing list