| 1 |
% Copyright 2006 2015 Ovidiu Gheorghies, Radu-George Radulescu |
| 2 |
% Licensed under the Apache License, Version 2.0. |
| 3 |
|
| 4 |
if known _metauml_base_mp: |
| 5 |
expandafter endinput |
| 6 |
fi; |
| 7 |
_metauml_base_mp:=1; |
| 8 |
|
| 9 |
% Sadly, this copy of the macro is needed to prevent multiple file loads being shown by MetaPost. |
| 10 |
% The guard values (such as _metauml_mp) do ensure that the file isn't loaded multiple times, |
| 11 |
% but this macro makes sure that MetaPost won't try to load the file and display a message for that. |
| 12 |
def inputonce text libraryFile= |
| 13 |
if not known scantokens ("_" & str libraryFile & "_mp"): |
| 14 |
%includeonce% show "Loading " & str libraryFile; |
| 15 |
scantokens ("input " & str libraryFile); |
| 16 |
else: |
| 17 |
%includeonce% show str libraryFile & " already loaded."; |
| 18 |
fi; |
| 19 |
enddef; |
| 20 |
|
| 21 |
inputonce util_log; |
| 22 |
|
| 23 |
vardef markPoint(text p)(text color) = |
| 24 |
draw p withpen pencircle scaled 1 withcolor color; |
| 25 |
enddef; |
| 26 |
|
| 27 |
vardef drawLine(text pA)(text pB)(text base) = |
| 28 |
draw pA--pB; |
| 29 |
enddef; |
| 30 |
|
| 31 |
vardef drawArrow(text pA)(text pB)(text base) = |
| 32 |
numeric dx, dy; |
| 33 |
dx = xpart(pB - pA); |
| 34 |
dy = ypart(pB - pA); |
| 35 |
|
| 36 |
numeric alfa; |
| 37 |
alfa = angle(dx, dy); |
| 38 |
|
| 39 |
pair pC, pD; |
| 40 |
pC := (0, base/2); |
| 41 |
pC := pC rotated (alfa) shifted pA; |
| 42 |
pD := (0, base/2); |
| 43 |
pD := pD rotated (180+alfa) shifted pA; |
| 44 |
|
| 45 |
%fill pA--pC--pB--pD--cycle withcolor .8white; |
| 46 |
|
| 47 |
draw pA--pB; |
| 48 |
draw pB--pC; |
| 49 |
draw pB--pD; |
| 50 |
enddef; |
| 51 |
|
| 52 |
vardef drawTriangle(text pA)(text pB)(text base) = |
| 53 |
numeric dx, dy; |
| 54 |
dx = xpart(pB - pA); |
| 55 |
dy = ypart(pB - pA); |
| 56 |
|
| 57 |
numeric alfa; |
| 58 |
alfa = angle(dx, dy); |
| 59 |
pair pC, pD; |
| 60 |
pC := (0, base/2); |
| 61 |
pC := pC rotated (alfa) shifted pA; |
| 62 |
pD := (0, base/2); |
| 63 |
pD := pD rotated (180+alfa) shifted pA; |
| 64 |
|
| 65 |
fill pA--pC--pB--pD--cycle withcolor white; |
| 66 |
|
| 67 |
draw pA--pC;% withcolor red; |
| 68 |
draw pA--pD;% withcolor green; |
| 69 |
draw pB--pC;% withcolor blue; |
| 70 |
draw pB--pD; |
| 71 |
enddef; |
| 72 |
|
| 73 |
vardef drawDiamond(text pA)(text pB)(text height) = |
| 74 |
numeric dx, dy; |
| 75 |
dx = xpart(pB - pA); |
| 76 |
dy = ypart(pB - pA); |
| 77 |
|
| 78 |
numeric alfa; |
| 79 |
alfa = angle(dx, dy); |
| 80 |
|
| 81 |
numeric width; |
| 82 |
width = _length(pA)(pB); |
| 83 |
|
| 84 |
path diamond; |
| 85 |
diamond = (0,0)--(width/2, height/2)--(width, 0)--(width/2, -height/2)--cycle; |
| 86 |
|
| 87 |
fill diamond rotated alfa shifted pA withcolor white; |
| 88 |
draw diamond rotated alfa shifted pA; |
| 89 |
enddef; |
| 90 |
|
| 91 |
vardef drawDiamondBlack(text pA)(text pB)(text height) = |
| 92 |
numeric dx, dy; |
| 93 |
dx = xpart(pB - pA); |
| 94 |
dy = ypart(pB - pA); |
| 95 |
|
| 96 |
numeric alfa; |
| 97 |
alfa = angle(dx, dy); |
| 98 |
|
| 99 |
numeric width; |
| 100 |
width = _length(pA)(pB); |
| 101 |
|
| 102 |
path diamond; |
| 103 |
diamond = (0,0)--(width/2, height/2)--(width, 0)--(width/2, -height/2)--cycle; |
| 104 |
|
| 105 |
fill diamond rotated alfa shifted pA; |
| 106 |
enddef; |
| 107 |
|
| 108 |
vardef drawCrossedCircle(text pA)(text pB)(text height) = |
| 109 |
numeric dx, dy; |
| 110 |
dx = xpart(pB - pA); |
| 111 |
dy = ypart(pB - pA); |
| 112 |
|
| 113 |
numeric alfa; |
| 114 |
alfa = angle(dx, dy); |
| 115 |
|
| 116 |
numeric width; |
| 117 |
width = _length(pA)(pB); |
| 118 |
|
| 119 |
pair pC, pD; |
| 120 |
pC := (width/2, height/2 + 1); |
| 121 |
pC := pC rotated (alfa) shifted pA; |
| 122 |
pD := (width/2, -height/2 - 1); |
| 123 |
pD := pD rotated (alfa) shifted pA; |
| 124 |
|
| 125 |
fill pA..pB..pA -- cycle withcolor white; |
| 126 |
|
| 127 |
draw pA -- pB; |
| 128 |
draw pC -- pD; |
| 129 |
draw pA .. pB .. pA; |
| 130 |
enddef; |
| 131 |
|
| 132 |
vardef drawSemiCircle(text pA)(text pB)(text height) = |
| 133 |
numeric dx, dy; |
| 134 |
dx = xpart(pB - pA); |
| 135 |
dy = ypart(pB - pA); |
| 136 |
|
| 137 |
numeric alfa; |
| 138 |
alfa = angle(dx, dy); |
| 139 |
|
| 140 |
numeric width; |
| 141 |
width = _length(pA)(pB); |
| 142 |
|
| 143 |
pair pC, pD; |
| 144 |
pC := (width/2 + 5, height/2 + 1); |
| 145 |
pC := pC rotated (alfa) shifted pB; |
| 146 |
pD := (width/2 + 5, -height/2 - 1); |
| 147 |
pD := pD rotated (alfa) shifted pB; |
| 148 |
|
| 149 |
draw pC .. pA .. pD; |
| 150 |
enddef; |
| 151 |
|
| 152 |
vardef drawCircle(text pA)(text pB)(text height) = |
| 153 |
fill pA..pB..pA -- cycle withcolor white; |
| 154 |
|
| 155 |
draw pA .. pB .. pA; |
| 156 |
enddef; |
| 157 |
|
| 158 |
vardef drawLine(expr my_path) = |
| 159 |
draw my_path; |
| 160 |
enddef; |
| 161 |
|
| 162 |
vardef drawLineDashed(expr my_path) = |
| 163 |
draw my_path dashed evenly; |
| 164 |
enddef; |
| 165 |
|
| 166 |
vardef drawNothing(text pA)(text pB)(text base) = |
| 167 |
enddef; |
| 168 |
|
| 169 |
def shorterLineEndPoint(text pA)(text pB)(text delta) = |
| 170 |
(xpart(pA) + _dx(pA)(pB)*(1 - delta/_length(pA)(pB)), ypart(pA) + _dy(pA)(pB) * (1 - delta/_length(pA)(pB)) ) |
| 171 |
enddef; |