Debian Codegraph @

texmf-dist/metapost/metauml/metauml_paths.mp

raw
1 % Copyright 2005 2015 Ovidiu Gheorghies
2 % Licensed under the Apache License, Version 2.0.
3
4 if known _metauml_paths_mp:
5 expandafter endinput
6 fi;
7 _metauml_paths_mp:=1;
8
9 def pathDirect(expr pA,pB) =
10 pA--pB
11 enddef;
12
13 vardef pathManhattanX(text twoParams) =
14 pair pointA__, pointB__;
15 string paramA_str__, paramB_str__;
16 boolean paramA_isObject__, paramB_isObject__;
17
18 paramA_isObject__ := true;
19 paramB_isObject__ := true;
20
21 boolean isFirstParam__;
22 isFirstParam__ := true;
23
24 %string twoParams;
25 %twoParams := "";
26
27 %twoParams := str paramA & ", " & str paramB;
28 %%includeonce% show "the two params are: " & twoParams;
29
30 forsuffixes param__ = twoParams:
31
32 if isFirstParam__:
33 isFirstParam__ := false;
34 paramA_str__ := str param__;
35 %includeonce% show "paramA_str__ <-- " & paramA_str__;
36
37 if not known (scantokens (paramA_str__ & ".className")):
38 %includeonce% show "paramA is not an object";
39 paramA_isObject__ := false;
40 fi;
41 else:
42 paramB_str__ := str param__;
43 %includeonce% show "paramB_str__ <-- " & paramB_str__;
44
45 if not known (scantokens (paramB_str__ & ".className")):
46 %includeonce% show "paramB is not an object";
47 paramB_isObject__ := false;
48 fi;
49 fi;
50 endfor;
51
52 %includeonce% show paramA_str__;
53 %includeonce% show paramA_isObject__;
54
55 %includeonce% show paramB_str__;
56 %includeonce% show paramB_isObject__;
57
58 string stringPath__;
59 stringPath__ := "(0,0)--(50,50)";
60
61 if (not paramA_isObject__) and (not paramB_isObject__):
62 %includeonce% show "Both are points!";
63
64
65 stringPath__ := paramA_str__ & "--(xpart " & paramB_str__ & ", ypart " & paramA_str__ & ") -- " & paramB_str__;
66 %includeonce% show stringPath__;
67 else:
68 pair refPointA__, refPointB__;
69 if paramA_isObject__:
70 refPointA__ := scantokens (paramA_str__ & ".c");
71 else:
72 refPointA__ := scantokens paramA_str__;
73 fi;
74 if paramB_isObject__:
75 refPointB__ := scantokens (paramB_str__ & ".c");
76 else:
77 refPointB__ := scantokens paramB_str__;
78 fi;
79
80 %includeonce% show "Reference point A: ";
81 %includeonce% show refPointA__;
82 %includeonce% show "Reference point B: ";
83 %includeonce% show refPointB__;
84
85 numeric dx__, dy__;
86 dx__ := xpart refPointB__ - xpart refPointA__;
87 dy__ := ypart refPointB__ - ypart refPointA__;
88
89 string addornmentA__;
90 addornmentA__ := "";
91 string addornmentB__;
92 addornmentB__ := "";
93
94 if (paramA_isObject__):
95 if (dx__ > 0):
96 addornmentA__ := ".e";
97 else:
98 addornmentA__ := ".w";
99 fi;
100 fi;
101
102 if (paramB_isObject__):
103 if (dy__ > 0):
104 addornmentB__ := ".s";
105 else:
106 addornmentB__ := ".n";
107 fi;
108 fi;
109 stringPath__ := "pathManhattanX(" & paramA_str__ & addornmentA__ & ", " & paramB_str__ & addornmentB__ & ")";
110
111 %includeonce% show stringPath;
112 %includeonce% show "-------------------> recursive call";
113 fi;
114
115 scantokens stringPath__
116 enddef;
117
118 vardef rpathManhattanX(text twoParams) =
119 reverse pathManhattanX(twoParams)
120 enddef;
121
122 vardef pathManhattanY(expr pA,pB) =
123 pA--(xpart(pA), ypart(pB))--pB
124 enddef;
125
126 vardef rpathManhattanY(expr pA,pB) =
127 pB--(xpart(pA), ypart(pB))--pA
128 enddef;
129
130 vardef pathStepX(expr pA,pB, deltax) =
131 pA--(pA+(deltax, 0))--(((xpart pA)+deltax), ypart(pB))--pB
132 enddef;
133
134 vardef rpathStepX(expr pA,pB, deltax) =
135 pB--(((xpart pA)+deltax), ypart(pB))--(pA+(deltax, 0))--pA
136 enddef;
137
138 vardef pathStepY(expr pA,pB, deltay) =
139 pA--(pA+(0, deltay))--(xpart(pB), ((ypart pA)+deltay))--pB
140 enddef;
141
142 vardef rpathStepY(expr pA,pB, deltay) =
143 pB--(xpart(pB), ((ypart pA)+deltay))--(pA+(0, deltay))--pA
144 enddef;
145
146 vardef pathHorizontal(expr pA, untilX) =
147 pA--(untilX,ypart(pA))
148 enddef;
149
150 vardef rpathHorizontal(expr pA, untilX) =
151 (untilX,ypart(pA))--pA
152 enddef;
153
154 vardef pathVertical(expr pA, untilY) =
155 pA--(xpart(pA), untilY)
156 enddef;
157
158 vardef rpathVertical(expr pA, untilY) =
159 (xpart(pA), untilY)--pA
160 enddef;
161
162 % Cuts path thePath so that it won't intersect the objects
163 % objectA and objectB. The border of the objects is obtained
164 % by invoking the method "_border".
165 %
166 vardef pathCut(suffix objectA, objectB)(expr thePath)=
167 save timeA, timeB;
168
169 timeA = xpart (thePath intersectiontimes objectBorder(objectA));
170 timeB = xpart (thePath intersectiontimes objectBorder(objectB));
171
172 subpath (timeA, timeB) of thePath
173 enddef;