Typica is a free program for professional coffee roasters. https://typica.us
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

blockdraw.mp 8.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. %% blockdraw.mp
  2. %% Copyright 2006 Henrik Tidefelt
  3. %
  4. % This work may be distributed and/or modified under the
  5. % conditions of the LaTeX Project Public License, either version 1.3
  6. % of this license or (at your option) any later version.
  7. % The latest version of this license is in
  8. % http://www.latex-project.org/lppl.txt
  9. % and version 1.3 or later is part of all distributions of LaTeX
  10. % version 2005/12/01 or later.
  11. %
  12. % This work has the LPPL maintenance status `maintained´.
  13. %
  14. % The Current Maintainer of this work is Henrik Tidefelt,
  15. % tidefelt@isy.liu.se.
  16. %
  17. % This work, referred to as blockdraw.mp, consists of the files
  18. % shiftoff.mp
  19. % blockdraw.mp
  20. % bondgraph.mp
  21. % blockdraw_mp.pdf
  22. numeric longblockrx;
  23. numeric longblockry;
  24. numeric smallblockr;
  25. longblockrx := 0.7cm;
  26. longblockry := 0.4cm;
  27. smallblockr := 0.3cm;
  28. numeric connectionlw;
  29. numeric blocklw;
  30. connectionlw := 0.8pt;
  31. blocklw = connectionlw;
  32. numeric textscale;
  33. textscale := 1;
  34. boolean implicitdraw;
  35. implicitdraw := true;
  36. input shiftoff;
  37. def sizedblock(expr txt, z, rx, ry ) =
  38. begingroup
  39. save tmppic;
  40. picture tmppic;
  41. tmppic := nullpicture;
  42. addto tmppic also shiftoff( txt scaled textscale, to_center );
  43. addto tmppic doublepath (-rx,-ry)--(-rx,ry)--(rx,ry)--(rx,-ry)--cycle withpen pencircle scaled blocklw;
  44. tmppic := tmppic shifted z;
  45. if implicitdraw:
  46. draw tmppic;
  47. fi
  48. tmppic
  49. endgroup
  50. enddef;
  51. def longblock(expr txt, z ) =
  52. sizedblock( txt, z, longblockrx, longblockry )
  53. enddef;
  54. def squareblock(expr txt, z ) =
  55. sizedblock( txt, z, smallblockr, smallblockr )
  56. enddef;
  57. def roundblock(expr txt, z ) =
  58. begingroup
  59. save tmppic;
  60. picture tmppic;
  61. tmppic := nullpicture;
  62. addto tmppic also shiftoff( txt scaled textscale, to_center );
  63. addto tmppic doublepath (smallblockr,0)...(0,smallblockr)...(-smallblockr,0)...(0,-smallblockr)...cycle withpen pencircle scaled blocklw;
  64. tmppic := tmppic shifted z;
  65. if implicitdraw:
  66. draw tmppic;
  67. fi
  68. tmppic
  69. endgroup
  70. enddef;
  71. def splitdot(expr z ) =
  72. begingroup
  73. save tmppic;
  74. picture tmppic;
  75. tmppic := nullpicture;
  76. addto tmppic contour fullcircle scaled 2.5connectionlw shifted z;
  77. if implicitdraw:
  78. draw tmppic;
  79. fi
  80. tmppic
  81. endgroup
  82. enddef;
  83. def termcircle(expr z ) =
  84. begingroup
  85. save tmppic;
  86. picture tmppic;
  87. tmppic := nullpicture;
  88. addto tmppic doublepath fullcircle scaled 7connectionlw shifted z;
  89. if implicitdraw:
  90. draw tmppic;
  91. fi
  92. tmppic
  93. endgroup
  94. enddef;
  95. def pointpicture(expr z ) =
  96. begingroup
  97. save tmppic;
  98. picture tmppic;
  99. tmppic := nullpicture;
  100. addto tmppic contour fullcircle scaled 0 shifted z;
  101. tmppic
  102. endgroup
  103. enddef;
  104. def mspoint( expr pth, mediation, slide ) =
  105. (point (arctime mediation * arclength(pth) + slide of pth) of pth)
  106. enddef;
  107. def hhconnect(expr pa, pb, mediation, slide ) =
  108. begingroup
  109. save mid, respath;
  110. numeric mid;
  111. path respath;
  112. mid := (mediation)[ xpart pa, xpart pb ] + (if (xpart pb) > (xpart pa): 1 else: -1 fi) * slide;
  113. respath := pa--( mid, ypart pa )--( mid, ypart pb )--pb;
  114. if implicitdraw:
  115. drawarrow respath withpen pencircle scaled connectionlw;
  116. fi
  117. respath
  118. endgroup
  119. enddef;
  120. def vvconnect(expr pa, pb, mediation, slide ) =
  121. begingroup
  122. save mid, respath;
  123. numeric mid;
  124. path respath;
  125. mid := (mediation)[ ypart pa, ypart pb ] + (if (ypart pb) > (ypart pa): 1 else: -1 fi) * slide;
  126. respath := pa--( xpart pa, mid )--( xpart pb, mid )--pb;
  127. if implicitdraw:
  128. drawarrow respath withpen pencircle scaled connectionlw;
  129. fi
  130. respath
  131. endgroup
  132. enddef;
  133. def hvconnect(expr pa, pb ) =
  134. begingroup
  135. save respath;
  136. path respath;
  137. respath := pa--( xpart pb, ypart pa )--pb;
  138. if implicitdraw:
  139. drawarrow respath withpen pencircle scaled connectionlw;
  140. fi
  141. respath
  142. endgroup
  143. enddef;
  144. def vhconnect(expr pa, pb ) =
  145. begingroup
  146. save respath;
  147. path respath;
  148. respath := pa--( xpart pa, ypart pb )--pb;
  149. if implicitdraw:
  150. drawarrow respath withpen pencircle scaled connectionlw;
  151. fi
  152. respath
  153. endgroup
  154. enddef;
  155. def conlabel(expr shiftdir, txt, z ) =
  156. begingroup
  157. save tmppic;
  158. picture tmppic;
  159. tmppic := shiftoffwlm( txt scaled textscale, shiftdir ) shifted z;
  160. if implicitdraw:
  161. draw tmppic;
  162. fi
  163. tmppic
  164. endgroup
  165. enddef;
  166. def leftpoint(expr pic, n, i ) =
  167. (i/(n+1))[llcorner pic,ulcorner pic]
  168. enddef;
  169. def rightpoint(expr pic, n, i ) =
  170. (i/(n+1))[lrcorner pic,urcorner pic]
  171. enddef;
  172. def bottompoint(expr pic, n, i ) =
  173. (i/(n+1))[llcorner pic,lrcorner pic]
  174. enddef;
  175. def toppoint(expr pic, n, i ) =
  176. (i/(n+1))[ulcorner pic,urcorner pic]
  177. enddef;
  178. def llconnect(expr pica, picb, slide ) =
  179. begingroup
  180. hhconnect( leftpoint( pica, 1, 1 ), leftpoint( picb, 1, 1 ), 0.5, slide )
  181. endgroup
  182. enddef;
  183. def rrconnect(expr pica, picb, slide ) =
  184. begingroup
  185. hhconnect( rightpoint( pica, 1, 1 ), rightpoint( picb, 1, 1 ), 0.5, slide )
  186. endgroup
  187. enddef;
  188. def ttconnect(expr pica, picb, slide ) =
  189. begingroup
  190. vvconnect( toppoint( pica, 1, 1 ), toppoint( picb, 1, 1 ), 0.5, slide )
  191. endgroup
  192. enddef;
  193. def bbconnect(expr pica, picb, slide ) =
  194. begingroup
  195. vvconnect( bottompoint( pica, 1, 1 ), bottompoint( picb, 1, 1 ), 0.5, slide )
  196. endgroup
  197. enddef;
  198. def lrconnect(expr pica, picb ) =
  199. begingroup
  200. hhconnect( leftpoint( pica, 1, 1 ), rightpoint( picb, 1, 1 ), 0.5, 0 )
  201. endgroup
  202. enddef;
  203. def rlconnect(expr pica, picb ) =
  204. begingroup
  205. hhconnect( rightpoint( pica, 1, 1 ), leftpoint( picb, 1, 1 ), 0.5, 0 )
  206. endgroup
  207. enddef;
  208. def btconnect(expr pica, picb ) =
  209. begingroup
  210. vvconnect( bottompoint( pica, 1, 1 ), toppoint( picb, 1, 1 ), 0.5, 0 )
  211. endgroup
  212. enddef;
  213. def tbconnect(expr pica, picb ) =
  214. begingroup
  215. vvconnect( toppoint( pica, 1, 1 ), bottompoint( picb, 1, 1 ), 0.5, 0 )
  216. endgroup
  217. enddef;
  218. def ltconnect(expr pica, picb ) =
  219. begingroup
  220. hvconnect( leftpoint( pica, 1, 1 ), toppoint( picb, 1, 1 ) )
  221. endgroup
  222. enddef;
  223. def lbconnect(expr pica, picb ) =
  224. begingroup
  225. hvconnect( leftpoint( pica, 1, 1 ), bottompoint( picb, 1, 1 ) )
  226. endgroup
  227. enddef;
  228. def rtconnect(expr pica, picb ) =
  229. begingroup
  230. hvconnect( rightpoint( pica, 1, 1 ), toppoint( picb, 1, 1 ) )
  231. endgroup
  232. enddef;
  233. def rbconnect(expr pica, picb ) =
  234. begingroup
  235. hvconnect( rightpoint( pica, 1, 1 ), bottompoint( picb, 1, 1 ) )
  236. endgroup
  237. enddef;
  238. def tlconnect(expr pica, picb ) =
  239. begingroup
  240. vhconnect( toppoint( pica, 1, 1 ), leftpoint( picb, 1, 1 ) )
  241. endgroup
  242. enddef;
  243. def trconnect(expr pica, picb ) =
  244. begingroup
  245. vhconnect( toppoint( pica, 1, 1 ), rightpoint( picb, 1, 1 ) )
  246. endgroup
  247. enddef;
  248. def blconnect(expr pica, picb ) =
  249. begingroup
  250. vhconnect( bottompoint( pica, 1, 1 ), leftpoint( picb, 1, 1 ) )
  251. endgroup
  252. enddef;
  253. def brconnect(expr pica, picb ) =
  254. begingroup
  255. vhconnect( bottompoint( pica, 1, 1 ), rightpoint( picb, 1, 1 ) )
  256. endgroup
  257. enddef;
  258. def connect(expr pica, picb ) =
  259. begingroup
  260. save rxa, rya, rxb, ryb;
  261. numeric rxa;
  262. numeric rya;
  263. numeric rxb;
  264. numeric ryb;
  265. save ca, cb;
  266. pair ca;
  267. pair cb;
  268. rxa = 0.5 * ((xpart lrcorner pica) - (xpart llcorner pica));
  269. rya = 0.5 * ((ypart ulcorner pica) - (ypart llcorner pica));
  270. rxb = 0.5 * ((xpart lrcorner picb) - (xpart llcorner picb));
  271. ryb = 0.5 * ((ypart ulcorner picb) - (ypart llcorner picb));
  272. ca = center pica;
  273. cb = center picb;
  274. if (xpart ca) < (xpart cb) - ( rxa + rxb ):
  275. if (ypart ca) < (ypart cb) - ( rya + ryb ):
  276. rbconnect( pica, picb )
  277. elseif (ypart ca) > (ypart cb) + ( rya + ryb ):
  278. rtconnect( pica, picb )
  279. else:
  280. rlconnect( pica, picb )
  281. fi
  282. elseif (xpart ca) > (xpart cb) + ( rxa + rxb ):
  283. if (ypart ca) < (ypart cb) - ( rya + ryb ):
  284. lbconnect( pica, picb )
  285. elseif (ypart ca) > (ypart cb) + ( rya + ryb ):
  286. ltconnect( pica, picb )
  287. else:
  288. lrconnect( pica, picb )
  289. fi
  290. else:
  291. if (ypart ca) < (ypart cb) - ( rya + ryb ):
  292. tbconnect( pica, picb )
  293. elseif (ypart ca) > (ypart cb) + ( rya + ryb ):
  294. btconnect( pica, picb )
  295. else:
  296. hvconnect( center pica, center picb )
  297. fi
  298. fi
  299. endgroup
  300. enddef;