| 1 |
%% xysmart.tex from $Id: xysmart.doc,v 3.6 2011/03/14 20:14:00 krisrose Exp $ |
| 2 |
%% |
| 3 |
%% Xy-pic ``Smart Path feature'' option. |
| 4 |
%% Copyright (c) 1998 George C. Necula <[email protected]> |
| 5 |
%% |
| 6 |
%% This file is part of the Xy-pic package for graphs and diagrams in TeX. |
| 7 |
%% See the companion README and INSTALL files for further information. |
| 8 |
%% Copyright (c) 1991-2011 Kristoffer H. Rose <[email protected]> |
| 9 |
%% |
| 10 |
%% The Xy-pic package is free software; you can redistribute it and/or modify |
| 11 |
%% it under the terms of the GNU General Public License as published by the |
| 12 |
%% Free Software Foundation; either version 2 of the License, or (at your |
| 13 |
%% option) any later version. |
| 14 |
%% |
| 15 |
%% The Xy-pic package is distributed in the hope that it will be useful, but |
| 16 |
%% WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 17 |
%% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 18 |
%% for more details. |
| 19 |
%% |
| 20 |
%% You should have received a copy of the GNU General Public License along |
| 21 |
%% with this package; if not, see http://www.gnu.org/licenses/. |
| 22 |
%% |
| 23 |
\ifx\xyloaded\undefined \input xy \fi |
| 24 |
\xyprovide{smart}{Smart Path option}{\stripRCS$Revision: 3.6 $}% |
| 25 |
{George C. Necula}{[email protected]}% |
| 26 |
{School of Computer Science, |
| 27 |
Carnegie Mellon University, |
| 28 |
5000 Forbes Avenue, |
| 29 |
Pittsburgh, PA 15213-3891, USA} |
| 30 |
\xyrequire{arrow}\xycatcodes |
| 31 |
\let\origPATHturn@=\PATHturn@ |
| 32 |
\def\PATHturn@{% |
| 33 |
\ifx \space@\next \expandafter\DN@\space{\xyFN@\PATHturn@}% |
| 34 |
\else\ifx s\next |
| 35 |
\let\origPATHturn@i=\PATHturn@i\let\PATHturn@i=\PATHsmartturn@i |
| 36 |
\let\origPATHturn@cir=\PATHturn@cir\let\PATHturn@cir=\PATHsmartturn@cir |
| 37 |
\DN@ s{\xyFN@\origPATHturn@}% |
| 38 |
\else |
| 39 |
\DN@{\origPATHturn@}% |
| 40 |
\fi\fi |
| 41 |
\next@} |
| 42 |
\xydef@\PATHsmartturn@cir{% |
| 43 |
\edef\next@{{\CIRin@@}{\expandafter\noexpand\CIRorient@@}{\CIRout@@}}% |
| 44 |
\expandafter\PATHturn@i\next@} |
| 45 |
\xydef@\PATHsmartturn@i#1#2#3{% |
| 46 |
\DN@##1{% |
| 47 |
\def\PATHinit@@{% |
| 48 |
\xy@@{% |
| 49 |
\def\sm@CIRin{#1}\def\sm@CIRout{#3}% |
| 50 |
\ifx\sm@CIRout\empty |
| 51 |
\let\sm@CIRout=\sm@CIRin |
| 52 |
\let\sm@CIRin=\PATHlastout@@ |
| 53 |
\fi |
| 54 |
##1\relax}% |
| 55 |
\xy@@{\enter@{\basefromthebase@}}% |
| 56 |
\xy@@{\sm@conn}% |
| 57 |
\xy@@{\X@p=\X@c \Y@p=\Y@c \czeroEdge@% Save the start of the segment |
| 58 |
\count@=\sm@CIRout\count@=\the\count@% Move forward a dash to |
| 59 |
\dimen@=\xydashl@ \ABfromdiag@ \advance\X@c\A@ \advance\Y@c\B@ |
| 60 |
\edef\PATHpostpos@@{\X@c=\the\X@c \Y@c=\the\Y@c \noexpand\czeroEdge@ |
| 61 |
\noexpand\PATHomitslide@@true}}% |
| 62 |
\xy@@{\leave@ |
| 63 |
\edef\PATHlastout@@{\sm@CIRout}% |
| 64 |
\count@=\sm@CIRout \dimen@=\xydashl@ \Directionfromdiag@}}}% |
| 65 |
\expandafter\next@\expandafter{\the\toks@}\toks@={}% |
| 66 |
\let\PATHextra@@=\empty |
| 67 |
\def\PATHpost@@{\xy@@\PATHpostpos@@}% |
| 68 |
\let\PATHlabelsextra@@=\relax |
| 69 |
\let\PATHturn@i=\origPATHturn@i |
| 70 |
\let\PATHturn@cir=\origPATHturn@cir |
| 71 |
\xyFN@\PATHturn@ii} |
| 72 |
\xydef@\sm@nil{} |
| 73 |
\xydef@\sm@nnil{\sm@nil} |
| 74 |
\xydef@\sm@maxcost{1000mm}% |
| 75 |
\xydef@\sm@conn{ |
| 76 |
\enter@{\cfromthec@ \DirectionfromtheDirection@}\cfromp@% Adjust p |
| 77 |
\count@=\sm@CIRin\count@=\the\count@ |
| 78 |
\dimen@=\xydashl@ \ABfromdiag@ \advance\X@p\A@\advance\Y@p\B@ |
| 79 |
\setupDirection@ \the\Edge@c\z@ \czeroEdge@ |
| 80 |
\pfromc@ |
| 81 |
\reverseDirection@ |
| 82 |
\count@=\sm@CIRin\count@=\the\count@ |
| 83 |
\dimen@=\xydashl@ \ABfromdiag@ |
| 84 |
\edef\tmp@{\noexpand\dir\artail@@}\expandafter\sm@drop@\tmp@ |
| 85 |
\X@c=\X@p\advance\X@c\A@ \Y@c=\Y@p\advance\Y@c\B@ \czeroEdge@ |
| 86 |
\sm@stri |
| 87 |
\X@p=\X@c \Y@p=\Y@c |
| 88 |
\leave@ |
| 89 |
\enter@{\pfromthep@ \DirectionfromtheDirection@}\pfromc@% Adjust c |
| 90 |
\count@=\sm@CIRout\count@=\the\count@ |
| 91 |
\dimen@=\xydashl@ \ABfromdiag@ \advance\X@p-\A@\advance\Y@p-\B@ |
| 92 |
\setupDirection@ \the\Edge@c\z@ |
| 93 |
\advance\X@c-\A@\advance\Y@c-\B@% Leave room for a dash to terminate the seg |
| 94 |
\czeroEdge@ |
| 95 |
\def\PATHlabelsnext@@{}% |
| 96 |
\leave@ |
| 97 |
\R@=\turnradius@ |
| 98 |
\cirrestrict@@%Adjust the radius to fit the circles |
| 99 |
\let\sm@circles=\sm@nil |
| 100 |
\edef\sm@bestcost{\sm@maxcost}% |
| 101 |
\sm@trycircles 1%Try counter clockwise first |
| 102 |
\sm@trycircles{-1}% |
| 103 |
\ifdim\sm@bestcost<\sm@maxcost |
| 104 |
\cfromp@ |
| 105 |
\expandafter\sm@conndraw\sm@bestconn |
| 106 |
\else |
| 107 |
\xyerror@{Cannot draw the smart connector}{}% |
| 108 |
\fi |
| 109 |
} |
| 110 |
\xydef@\sm@trycircles#1{% |
| 111 |
\ifnum #1>0% Compute the opposite orientation |
| 112 |
\def\sm@CIRorienti{-1}% |
| 113 |
\else |
| 114 |
\def\sm@CIRorienti{1}% |
| 115 |
\fi |
| 116 |
\edef\tmp@{{{\sm@CIRin}{#1}{\sm@CIRout}}}% |
| 117 |
\expandafter\sm@trycirclelist\expandafter{\tmp@\sm@nil}% |
| 118 |
\count@@=\sm@CIRin\count@@=\the\count@@\count@=\count@@ |
| 119 |
\sm@roundcount@{#1}% |
| 120 |
\edef\sm@savecount@{\the\count@}% |
| 121 |
\ifnum\the\count@=\the\count@@ \else |
| 122 |
\edef\tmp@{{{\sm@CIRin}{#1}{\the\count@}}% |
| 123 |
{{\the\count@}{\sm@CIRorienti}{\sm@CIRout}}}% |
| 124 |
\expandafter\sm@trycirclelist\expandafter{\tmp@\sm@nil}% |
| 125 |
\fi |
| 126 |
\count@=\sm@savecount@\count@=\the\count@ |
| 127 |
\sm@advancecount@ 2{#1}\edef\sm@savecount@{\the\count@}% |
| 128 |
\edef\tmp@{{{\sm@CIRin}{#1}{\the\count@}}% |
| 129 |
{{\the\count@}{\sm@CIRorienti}{\sm@CIRout}}}% |
| 130 |
\expandafter\sm@trycirclelist\expandafter{\tmp@\sm@nil}% |
| 131 |
\count@=\sm@savecount@\count@=\the\count@ |
| 132 |
\sm@advancecount@ 2{#1}\edef\sm@savecount@{\the\count@}% |
| 133 |
\edef\tmp@{{{\sm@CIRin}{#1}{\the\count@}}% |
| 134 |
{{\the\count@}{\sm@CIRorienti}{\sm@CIRout}}}% |
| 135 |
\expandafter\sm@trycirclelist\expandafter{\tmp@\sm@nil}% |
| 136 |
\count@=\sm@savecount@\count@=\the\count@ |
| 137 |
\sm@advancecount@ 2{#1}\edef\sm@savecount@{\the\count@}% |
| 138 |
\edef\tmp@{{{\sm@CIRin}{#1}{\the\count@}}% |
| 139 |
{{\the\count@}{\sm@CIRorienti}{\sm@CIRout}}}% |
| 140 |
\expandafter\sm@trycirclelist\expandafter{\tmp@\sm@nil}% |
| 141 |
} |
| 142 |
\xydef@\sm@advancecount@#1#2{% |
| 143 |
\ifnum #2>0 |
| 144 |
\edef\tmp@{#1}% |
| 145 |
\else |
| 146 |
\edef\tmp@{-#1}% |
| 147 |
\fi |
| 148 |
\advance\count@\tmp@\count@=\the\count@ |
| 149 |
\ifnum\the\count@<0 \advance\count@ 8\fi |
| 150 |
\ifnum\the\count@>7 \advance\count@ -8\fi |
| 151 |
\count@=\the\count@ |
| 152 |
} |
| 153 |
\xydef@\sm@roundcount@#1{% |
| 154 |
\ifcase\the\count@ |
| 155 |
\advance\count@ #1\or |
| 156 |
\or \advance\count@ #1\or |
| 157 |
\or \advance\count@ #1\or |
| 158 |
\or \advance\count@ #1\fi |
| 159 |
\count@=\the\count@ |
| 160 |
\ifnum\the\count@<0 \advance\count@ 8\fi |
| 161 |
\ifnum\the\count@>7 \advance\count@ -7\fi |
| 162 |
\count@=\the\count@ |
| 163 |
} |
| 164 |
\newif\ifsm@firstseg |
| 165 |
\newif\ifsm@acceptable |
| 166 |
\xydef@\sm@trycirclelist#1{% |
| 167 |
\R@p=\z@\U@p=\R@p% Clear the deltas |
| 168 |
\def\sm@exthp{0}\def\sm@exthm{0}% |
| 169 |
\def\sm@extvp{0}\def\sm@extvm{0}% |
| 170 |
\def\sm@dxp{0pt}\def\sm@dxm{0pt}% |
| 171 |
\def\sm@dyp{0pt}\def\sm@dym{0pt}% |
| 172 |
\def\sm@segs{}% |
| 173 |
\sm@firstsegtrue |
| 174 |
\def\sm@connlen{0pt}% |
| 175 |
\let\sm@tryclcont=\sm@trycirclelist@i |
| 176 |
\sm@trycirclelist@i #1%Strip {} to expose the list elements |
| 177 |
\count@@=\sm@CIRout\count@@=\the\count@\count@=\the\count@ |
| 178 |
\sm@roundcount@{1}% |
| 179 |
\ifnum\count@=\count@@ |
| 180 |
\edef\sm@segs{\sm@segs{{\the\count@}{1}{\the\count@}}}% |
| 181 |
\fi |
| 182 |
\A@=\X@p\advance\A@\R@p\advance\A@ -\X@c\A@=-\A@ |
| 183 |
\B@=\Y@p\advance\B@\U@p\advance\B@ -\Y@c\B@=-\B@ |
| 184 |
\sm@acceptabletrue |
| 185 |
\ifdim\A@>0pt |
| 186 |
\ifnum\sm@exthp>0 \dimen@=\A@ \divide\dimen@\sm@exthp |
| 187 |
\edef\sm@dxp{\the\dimen@}% |
| 188 |
\else \sm@acceptablefalse\fi\fi |
| 189 |
\ifdim\A@<0pt |
| 190 |
\ifnum\sm@exthm>0 \dimen@=\A@ \divide\dimen@\sm@exthm |
| 191 |
\edef\sm@dxm{\the\dimen@}% |
| 192 |
\else \sm@acceptablefalse\fi |
| 193 |
\A@=-\A@%Make it positive |
| 194 |
\fi |
| 195 |
\ifdim\B@>0pt |
| 196 |
\ifnum\sm@extvp>0 \dimen@=\B@ \divide\dimen@\sm@extvp |
| 197 |
\edef\sm@dyp{\the\dimen@}% |
| 198 |
\else \sm@acceptablefalse\fi\fi |
| 199 |
\ifdim\B@<0pt |
| 200 |
\ifnum\sm@extvm>0 \dimen@=\B@ \divide\dimen@\sm@extvm |
| 201 |
\edef\sm@dym{\the\dimen@}% |
| 202 |
\else \sm@acceptablefalse\fi |
| 203 |
\B@=-\B@ |
| 204 |
\fi |
| 205 |
\ifsm@acceptable |
| 206 |
\dimen@=\sm@connlen\advance\dimen@\A@\advance\dimen@\B@ |
| 207 |
\ifdim\dimen@<\sm@bestcost |
| 208 |
\edef\sm@bestcost{\the\dimen@}% |
| 209 |
\edef\sm@bestconn{{\sm@dxp}{\sm@dxm}{\sm@dyp}{\sm@dym}{\sm@segs}}% |
| 210 |
\fi |
| 211 |
\fi |
| 212 |
} |
| 213 |
\xydef@\sm@showext#1{% |
| 214 |
\W@{#1\space hp=\sm@exthp,hm=\sm@exthm,vp=\sm@extvp |
| 215 |
,vm=\sm@extvm,len=\sm@connlen}} |
| 216 |
\xydef@\sm@trycirclelist@i#1{% |
| 217 |
\def\@tmp{#1}% |
| 218 |
\ifx \@tmp\sm@nnil \let\sm@tryclcont=\relax\else |
| 219 |
\expandafter\sm@tryclcar\@tmp \fi |
| 220 |
\sm@tryclcont} |
| 221 |
\xydef@\sm@tryclcar#1#2#3{% |
| 222 |
\dimen@=\ifnum #2<0 -\fi\R@ |
| 223 |
\count@=#1\count@=\the\count@ \ABfromdiag@ |
| 224 |
\advance\R@p -\B@ \advance\U@p \A@ |
| 225 |
\count@=#3\count@=\the\count@ \ABfromdiag@ |
| 226 |
\advance\R@p \B@ \advance\U@p -\A@ |
| 227 |
\sm@computeext{#1}{#2}{#3}% |
| 228 |
} |
| 229 |
\xydef@\sm@computeext#1#2#3{% |
| 230 |
\ifsm@firstseg |
| 231 |
\sm@accumext#1% |
| 232 |
\sm@firstsegfalse |
| 233 |
\fi |
| 234 |
\count@@=#1\count@@=\the\count@@\count@=\count@@ |
| 235 |
\dimen@=\sm@connlen |
| 236 |
\sm@roundcount@{#2}% |
| 237 |
\ifnum \count@=\count@@ |
| 238 |
\sm@advancecount@ 1{#2}% |
| 239 |
\advance\dimen@ 0.7854\R@% It was incremented with 1/8 circle |
| 240 |
\ifnum \count@=#3% Check if done |
| 241 |
\else |
| 242 |
\sm@advancecount@ 1{#2}% |
| 243 |
\advance\dimen@ 0.7854\R@% It was incremented with 1/8 circle |
| 244 |
\fi |
| 245 |
\else |
| 246 |
\advance\dimen@ 0.7854\R@% It was incremented with 1/8 circle |
| 247 |
\fi |
| 248 |
\edef\sm@connlen{\the\dimen@}% |
| 249 |
\sm@accumext{\the\count@}% |
| 250 |
\edef\sm@segs{\sm@segs{{#1}{#2}{\the\count@}}}% |
| 251 |
\ifnum\the\count@=#3 \else |
| 252 |
\edef\tmp@{{\the\count@}{#2}{#3}}% |
| 253 |
\expandafter\sm@computeext\tmp@ |
| 254 |
\fi |
| 255 |
} |
| 256 |
\xydef@\sm@accumext#1{% |
| 257 |
\ifcase #1% |
| 258 |
\or \count@@=\sm@extvm\advance\count@@ by1% |
| 259 |
\edef\sm@extvm{\the\count@@}% |
| 260 |
\or\or \count@@=\sm@exthp\advance\count@@ by1% |
| 261 |
\edef\sm@exthp{\the\count@@}% |
| 262 |
\or\or \count@@=\sm@extvp\advance\count@@ by1% |
| 263 |
\edef\sm@extvp{\the\count@@}% |
| 264 |
\or\or \count@@=\sm@exthm\advance\count@@ by1% |
| 265 |
\edef\sm@exthm{\the\count@@}% |
| 266 |
\fi |
| 267 |
} |
| 268 |
\xydef@\sm@conndraw#1#2#3#4#5{% |
| 269 |
\def\sm@contlist{\sm@drawseglist}% |
| 270 |
\edef\sm@dxp{#1}% |
| 271 |
\edef\sm@dxm{#2}% |
| 272 |
\edef\sm@dyp{#3}% |
| 273 |
\edef\sm@dym{#4}% |
| 274 |
\sm@drawseglist #5\sm@nil} |
| 275 |
\xydef@\sm@drawseglist#1{% |
| 276 |
\ifx #1\sm@nil \def\sm@contlist{}\else |
| 277 |
\sm@drawseg #1\fi |
| 278 |
\sm@contlist} |
| 279 |
\xydef@\sm@drawseg#1#2#3{% |
| 280 |
\def\CIRin@@{#1}\def\CIRout@@{#3}% |
| 281 |
\sm@straight%See if a straight line is needed here. Insert it and |
| 282 |
\ifnum\CIRin@@=\CIRout@@ \else |
| 283 |
\count@=\CIRin@@ |
| 284 |
\dimen@=\ifnum #2<0 -\fi\R@ |
| 285 |
\ABfromdiag@ |
| 286 |
\advance\X@c -\B@ \advance\Y@c \A@ |
| 287 |
\ifnum #2>0 \def\CIRorient@@{\CIRacw@}% |
| 288 |
\else \def\CIRorient@@{\CIRcw@}\fi |
| 289 |
\drop@\literal@{\hbox\bgroup\cir@i}% |
| 290 |
\dimen@=\ifnum #2<0 -\fi\R@ |
| 291 |
\count@=\CIRout@@\count@=\count@%Wierd. If I remove this last assignm |
| 292 |
\ABfromdiag@ |
| 293 |
\advance\X@c\B@ \advance\Y@c-\A@ |
| 294 |
\fi |
| 295 |
} |
| 296 |
\xydef@\sm@straight{% |
| 297 |
\U@c=\z@\D@c=\U@c\L@c=\U@c\R@c=\U@c |
| 298 |
\pfromc@ |
| 299 |
\ifcase \CIRin@@ \or% 1 is V- |
| 300 |
\A@=\sm@dym\advance \Y@c\A@ |
| 301 |
\or\or |
| 302 |
\A@=\sm@dxp\advance \X@c\A@ |
| 303 |
\or\or |
| 304 |
\A@=\sm@dyp\advance \Y@c\A@ |
| 305 |
\or\or |
| 306 |
\A@=\sm@dxm\advance \X@c\A@ \fi |
| 307 |
\ifdim\X@c=\X@p\ifdim\Y@c=\Y@p\else \sm@stri \fi\else \sm@stri \fi |
| 308 |
} |
| 309 |
\xydef@\sm@stri{% |
| 310 |
\edef\tmp@{\expandafter\noexpand\arstemprefix@@\arstem@@}% |
| 311 |
\expandafter\sm@connect@\tmp@} |
| 312 |
\xydef@\sm@connect@#1#{% |
| 313 |
\DN@##1{\connect@{#1}{##1}}\next@} |
| 314 |
\xydef@\sm@drop@#1#{% |
| 315 |
\DN@##1{\drop@{#1}{##1}}\next@} |
| 316 |
\xydef@\smconn#1#2#3{% |
| 317 |
\edef\sm@CIRin{#1}\edef\sm@CIRout{#2}% |
| 318 |
\R@=#3\R@=\the\R@ |
| 319 |
\sm@conn} |
| 320 |
\xyendinput |