| 1 |
% This is |
| 2 |
% pkshorten.mf |
| 3 |
% |
| 4 |
% Copyright (C) 1989-92 by Elmar Bartel. |
| 5 |
% |
| 6 |
% This program is free software; you can redistribute it and/or modify |
| 7 |
% it under the terms of the GNU General Public License as published by |
| 8 |
% the Free Software Foundation; either version 1, or (at your option) |
| 9 |
% any later version. |
| 10 |
% |
| 11 |
% This program is distributed in the hope that it will be useful, |
| 12 |
% but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
% GNU General Public License for more details. |
| 15 |
% |
| 16 |
% You should have received a copy of the GNU General Public License |
| 17 |
% along with this program; if not, write to the Free Software |
| 18 |
% Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 19 |
% |
| 20 |
|
| 21 |
|
| 22 |
def Perpend(expr d,p,real) = |
| 23 |
begingroup |
| 24 |
save dd; pair dd; |
| 25 |
dd = d/length(d); |
| 26 |
(p+100*(dd rotated 90) -- p+100*(dd rotated -90)) shifted (dd*real) |
| 27 |
endgroup; |
| 28 |
enddef; |
| 29 |
def ShortenPath(expr p,real) = |
| 30 |
begingroup |
| 31 |
save pa,pe; path pa,pe; |
| 32 |
pa = Perpend(direction 0 of p,point 0 of p,real); |
| 33 |
pe = Perpend(-direction length(p) of p,point length(p) of p,real); |
| 34 |
subpath ( |
| 35 |
xpart(p intersectiontimes pa), |
| 36 |
xpart(p intersectiontimes pe)) of p |
| 37 |
endgroup |
| 38 |
enddef; |
| 39 |
def ShortenBegin(expr p,real) = |
| 40 |
begingroup |
| 41 |
save pa; path pa; |
| 42 |
pa = Perpend(direction 0 of p,point 0 of p,real); |
| 43 |
subpath (xpart(p intersectiontimes pa),length(p)) of p |
| 44 |
endgroup |
| 45 |
enddef; |
| 46 |
def ShortenEnd(expr p,real) = |
| 47 |
begingroup |
| 48 |
save pe; path pe; |
| 49 |
pe = Perpend(-direction length(p) of p,point length(p) of p,real); |
| 50 |
subpath (0, xpart(p intersectiontimes pe)) of p |
| 51 |
endgroup |
| 52 |
enddef; |
| 53 |
def LengthenBegin(expr p,real) = |
| 54 |
begingroup |
| 55 |
save dd; pair dd; |
| 56 |
dd= direction 0 of p; dd:= dd/length(dd); |
| 57 |
point 0 of p - real*dd -- p |
| 58 |
endgroup |
| 59 |
enddef; |
| 60 |
def LengthenEnd(expr p,real) = |
| 61 |
begingroup |
| 62 |
save dd; pair dd; |
| 63 |
dd= direction length(p) of p; dd:= dd/length(dd); |
| 64 |
p -- point length(p) of p + real*dd |
| 65 |
endgroup |
| 66 |
enddef; |
| 67 |
def Lengthen(expr p,real) = |
| 68 |
begingroup |
| 69 |
save db; pair db; |
| 70 |
save de; pair de; |
| 71 |
db= direction 0 of p; db:= db/length(db); |
| 72 |
de= direction length(p) of p; de:= de/length(de); |
| 73 |
point 0 of p - real*db -- p -- point length(p) of p + real*de |
| 74 |
endgroup |
| 75 |
enddef; |