| 1 |
% Copyright 2020 by Till Tantau |
| 2 |
% |
| 3 |
% This file may be distributed and/or modified |
| 4 |
% |
| 5 |
% 1. under the LaTeX Project Public License and/or |
| 6 |
% 2. under the GNU Public License. |
| 7 |
% |
| 8 |
% See the file doc/generic/pgf/licenses/LICENSE for more details. |
| 9 |
|
| 10 |
\ProvidesFileRCS{tikzlibrarytopaths.code.tex} |
| 11 |
|
| 12 |
|
| 13 |
% Move to |
| 14 |
|
| 15 |
\tikzset{move to/.style= {to path={(\tikztotarget) \tikztonodes}}} |
| 16 |
|
| 17 |
|
| 18 |
% Straight to |
| 19 |
|
| 20 |
\tikzset{line to/.style= {to path={-- (\tikztotarget) \tikztonodes}}} |
| 21 |
|
| 22 |
|
| 23 |
% Curved to |
| 24 |
|
| 25 |
\tikzset{every curve to/.style= {}} |
| 26 |
\tikzset{curve to/.style= {to path=\tikz@to@curve@path}} |
| 27 |
|
| 28 |
\tikzoption{bend angle}{\pgfmathsetmacro\tikz@to@bend{#1}} |
| 29 |
|
| 30 |
\tikzoption{bend left}[]{% |
| 31 |
\def\pgf@temp{#1}% |
| 32 |
\ifx\pgf@temp\pgfutil@empty% |
| 33 |
\else% |
| 34 |
\pgfmathsetmacro\tikz@to@bend{#1}% |
| 35 |
\fi% |
| 36 |
\let\tikz@to@out=\tikz@to@bend% |
| 37 |
\pgfmathsetmacro\tikz@to@in{180-(\tikz@to@out)}% |
| 38 |
\tikz@to@switch@on% |
| 39 |
\tikz@to@relativetrue% |
| 40 |
} |
| 41 |
|
| 42 |
\tikzoption{bend right}[]{% |
| 43 |
\def\pgf@temp{#1}% |
| 44 |
\ifx\pgf@temp\pgfutil@empty% |
| 45 |
\else% |
| 46 |
\pgfmathsetmacro\tikz@to@bend{#1}% |
| 47 |
\fi% |
| 48 |
% Now, negate |
| 49 |
\pgfmathsetmacro\tikz@to@out{-(\tikz@to@bend)} |
| 50 |
\pgfmathsetmacro\tikz@to@in{180-(\tikz@to@out)} |
| 51 |
\tikz@to@switch@on% |
| 52 |
\tikz@to@relativetrue% |
| 53 |
} |
| 54 |
|
| 55 |
\tikzoption{relative}[true]{\csname tikz@to@relative#1\endcsname} |
| 56 |
\newif\iftikz@to@relative |
| 57 |
\tikz@to@relativefalse |
| 58 |
|
| 59 |
\tikzoption{in}{\def\tikz@to@in{#1}\tikz@to@switch@on} |
| 60 |
\tikzoption{out}{\def\tikz@to@out{#1}\tikz@to@switch@on} |
| 61 |
|
| 62 |
\tikzoption{in looseness}{\tikz@to@set@in@looseness{#1}} |
| 63 |
\tikzoption{out looseness}{\tikz@to@set@out@looseness{#1}} |
| 64 |
\tikzoption{looseness}{\tikz@to@set@in@looseness{#1}\tikz@to@set@out@looseness{#1}} |
| 65 |
|
| 66 |
\tikzoption{in control}{\tikz@to@set@in@control{#1}} |
| 67 |
\tikzoption{out control}{\tikz@to@set@out@control{#1}} |
| 68 |
\tikzoption{controls}{\tikz@to@parse@controls#1\pgf@stop} |
| 69 |
|
| 70 |
\tikzoption{in min distance}{\tikz@to@set@distances{#1}{}{}{}} |
| 71 |
\tikzoption{in max distance}{\tikz@to@set@distances{}{#1}{}{}} |
| 72 |
\tikzoption{in distance}{\tikz@to@set@distances{#1}{#1}{}{}} |
| 73 |
\tikzoption{out min distance}{\tikz@to@set@distances{}{}{#1}{}} |
| 74 |
\tikzoption{out max distance}{\tikz@to@set@distances{}{}{}{#1}} |
| 75 |
\tikzoption{out distance}{\tikz@to@set@distances{}{}{#1}{#1}} |
| 76 |
\tikzoption{min distance}{\tikz@to@set@distances{#1}{}{#1}{}} |
| 77 |
\tikzoption{max distance}{\tikz@to@set@distances{}{#1}{}{#1}} |
| 78 |
\tikzoption{distance}{\tikz@to@set@distances{#1}{#1}{#1}{#1}} |
| 79 |
|
| 80 |
\def\tikz@to@set@distances#1#2#3#4{% |
| 81 |
\tikz@to@setifnotempy{#1}{\tikz@to@in@min}{\let\tikz@to@end@compute=\tikz@to@end@compute@looseness}% |
| 82 |
\tikz@to@setifnotempy{#2}{\tikz@to@in@max}{\let\tikz@to@end@compute=\tikz@to@end@compute@looseness}% |
| 83 |
\tikz@to@setifnotempy{#3}{\tikz@to@out@min}{\let\tikz@to@start@compute=\tikz@to@start@compute@looseness}% |
| 84 |
\tikz@to@setifnotempy{#4}{\tikz@to@out@max}{\let\tikz@to@start@compute=\tikz@to@start@compute@looseness}% |
| 85 |
\tikz@to@switch@on% |
| 86 |
} |
| 87 |
|
| 88 |
\def\tikz@to@setifnotempy#1#2#3{% |
| 89 |
\def\pgf@temp{#1}% |
| 90 |
\ifx\pgf@temp\pgfutil@empty\else\def#2{#1}#3\fi% |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
\def\tikz@to@set@in@looseness#1{% |
| 95 |
\pgfmathsetmacro\tikz@to@in@looseness{#1}% |
| 96 |
\let\tikz@to@end@compute=\tikz@to@end@compute@looseness% |
| 97 |
\tikz@to@switch@on% |
| 98 |
} |
| 99 |
\def\tikz@to@set@out@looseness#1{% |
| 100 |
\pgfmathsetmacro\tikz@to@out@looseness{#1}% |
| 101 |
\let\tikz@to@start@compute=\tikz@to@start@compute@looseness% |
| 102 |
\tikz@to@switch@on% |
| 103 |
} |
| 104 |
|
| 105 |
\def\tikz@to@parse@controls#1and#2\pgf@stop{\tikz@to@set@in@control{#2}\tikz@to@set@out@control{#1}} |
| 106 |
|
| 107 |
\def\tikz@to@set@in@control#1{% |
| 108 |
\def\tikz@to@in@control{#1}% |
| 109 |
\let\tikz@to@end@compute=\tikz@to@end@compute@control% |
| 110 |
\tikz@to@switch@on% |
| 111 |
} |
| 112 |
\def\tikz@to@set@out@control#1{% |
| 113 |
\def\tikz@to@out@control{#1}% |
| 114 |
\let\tikz@to@start@compute=\tikz@to@start@compute@control% |
| 115 |
\tikz@to@switch@on% |
| 116 |
} |
| 117 |
|
| 118 |
|
| 119 |
\def\tikz@to@bend{30} |
| 120 |
|
| 121 |
\def\tikz@to@out{45} |
| 122 |
\def\tikz@to@in{135} |
| 123 |
|
| 124 |
\def\tikz@to@out@looseness{1} |
| 125 |
\def\tikz@to@in@looseness{1} |
| 126 |
|
| 127 |
\def\tikz@to@in@min{0pt} |
| 128 |
\def\tikz@to@in@max{10000pt} |
| 129 |
\def\tikz@to@out@min{0pt} |
| 130 |
\def\tikz@to@out@max{10000pt} |
| 131 |
|
| 132 |
\def\tikz@to@switch@on{\let\tikz@to@path=\tikz@to@curve@path} |
| 133 |
|
| 134 |
\def\tikz@to@curve@path{% |
| 135 |
[every curve to] |
| 136 |
\pgfextra{\iftikz@to@relative\tikz@to@compute@relative\else\tikz@to@compute\fi} |
| 137 |
\tikz@computed@path |
| 138 |
\pgfextra{\tikz@updatenexttrue\tikz@updatecurrenttrue}% |
| 139 |
\tikztonodes% |
| 140 |
} |
| 141 |
|
| 142 |
\def\tikz@to@modify#1#2{% |
| 143 |
\pgfutil@ifundefined{pgf@sh@ns@#1} |
| 144 |
{}% |
| 145 |
{\edef#1{#1.#2}} |
| 146 |
}% |
| 147 |
|
| 148 |
\def\tikz@to@compute{% |
| 149 |
\let\tikz@tofrom=\tikztostart% |
| 150 |
\let\tikz@toto=\tikztotarget% |
| 151 |
\tikz@to@modify\tikz@tofrom\tikz@to@out% |
| 152 |
\tikz@to@modify\tikz@toto\tikz@to@in% |
| 153 |
\ifx\tikz@to@start@compute\tikz@to@start@compute@looseness% |
| 154 |
\tikz@to@compute@distance% |
| 155 |
\else% |
| 156 |
\ifx\tikz@from@start@compute\tikz@to@start@compute@looseness% |
| 157 |
\tikz@to@compute@distance% |
| 158 |
\fi% |
| 159 |
\fi% |
| 160 |
\tikz@to@start@compute% |
| 161 |
\tikz@to@end@compute% |
| 162 |
\edef\tikz@computed@path{.. controls \tikz@computed@start and \tikz@computed@end .. (\tikztotarget)} |
| 163 |
} |
| 164 |
|
| 165 |
\def\tikz@to@compute@distance{\tikz@scan@one@point\tikz@@to@compute@distance(\tikz@tofrom)} |
| 166 |
\def\tikz@@to@compute@distance#1{% |
| 167 |
\def\tikz@first@point{#1}% |
| 168 |
\tikz@scan@one@point\tikz@@@to@compute@distance(\tikz@toto)} |
| 169 |
\def\tikz@@@to@compute@distance#1{% |
| 170 |
\iftikz@updatecurrent\else |
| 171 |
\tikz@updatenextfalse |
| 172 |
\fi |
| 173 |
\def\tikz@second@point{#1}% |
| 174 |
\tikz@to@compute@distance@main% |
| 175 |
} |
| 176 |
\def\tikz@to@compute@distance@main{% |
| 177 |
\pgf@process{\pgfpointdiff{\tikz@first@point}{\tikz@second@point}}% |
| 178 |
\ifdim\pgf@x<0pt\pgf@xa=-\pgf@x\else\pgf@xa=\pgf@x\fi% |
| 179 |
\ifdim\pgf@y<0pt\pgf@ya=-\pgf@y\else\pgf@ya=\pgf@y\fi% |
| 180 |
% |
| 181 |
% Calculate length of second to first vector: |
| 182 |
% |
| 183 |
\pgf@process{\pgfpointnormalised{\pgfqpoint{\pgf@xa}{\pgf@ya}}}% |
| 184 |
\ifdim\pgf@x>\pgf@y% |
| 185 |
\c@pgf@counta=\pgf@x% |
| 186 |
\ifnum\c@pgf@counta=0\relax% |
| 187 |
\else% |
| 188 |
\divide\c@pgf@counta by 255\relax% |
| 189 |
\pgf@xa=16\pgf@xa\relax% |
| 190 |
\divide\pgf@xa by\c@pgf@counta% |
| 191 |
\pgf@xa=16\pgf@xa\relax% |
| 192 |
\fi% |
| 193 |
\else% |
| 194 |
\c@pgf@counta=\pgf@y% |
| 195 |
\ifnum\c@pgf@counta=0\relax% |
| 196 |
\else% |
| 197 |
\divide\c@pgf@counta by 255\relax% |
| 198 |
\pgf@ya=16\pgf@ya\relax% |
| 199 |
\divide\pgf@ya by\c@pgf@counta% |
| 200 |
\pgf@xa=16\pgf@ya\relax% |
| 201 |
\fi% |
| 202 |
\fi% |
| 203 |
\pgf@x=0.3915\pgf@xa% |
| 204 |
\pgf@xa=\tikz@to@out@looseness\pgf@x% |
| 205 |
\pgf@xb=\tikz@to@in@looseness\pgf@x% |
| 206 |
% Adjust as necessary |
| 207 |
\pgfmathsetlength{\pgf@ya}{\tikz@to@out@min} |
| 208 |
\ifdim\pgf@xa<\pgf@ya% |
| 209 |
\pgf@xa=\pgf@ya% |
| 210 |
\fi% |
| 211 |
\pgfmathsetlength{\pgf@ya}{\tikz@to@out@max} |
| 212 |
\ifdim\pgf@xa>\pgf@ya% |
| 213 |
\pgf@xa=\pgf@ya% |
| 214 |
\fi% |
| 215 |
\pgfmathsetlength{\pgf@ya}{\tikz@to@in@min} |
| 216 |
\ifdim\pgf@xb<\pgf@ya% |
| 217 |
\pgf@xb=\pgf@ya% |
| 218 |
\fi% |
| 219 |
\pgfmathsetlength{\pgf@ya}{\tikz@to@in@max} |
| 220 |
\ifdim\pgf@xb>\pgf@ya% |
| 221 |
\pgf@xb=\pgf@ya% |
| 222 |
\fi% |
| 223 |
} |
| 224 |
|
| 225 |
\def\tikz@to@start@compute@looseness{% |
| 226 |
\edef\tikz@computed@start{([shift=({\tikz@to@out}:\the\pgf@xa)]\tikz@tofrom)}% |
| 227 |
} |
| 228 |
\def\tikz@to@end@compute@looseness{% |
| 229 |
\edef\tikz@computed@end{([shift=({\tikz@to@in}:\the\pgf@xb)]\tikz@toto)}% |
| 230 |
} |
| 231 |
\def\tikz@to@start@compute@control{% |
| 232 |
\let\tikz@computed@start=\tikz@to@out@control% |
| 233 |
} |
| 234 |
\def\tikz@to@end@compute@control{% |
| 235 |
\let\tikz@computed@end=\tikz@to@in@control% |
| 236 |
} |
| 237 |
|
| 238 |
\let\tikz@to@start@compute=\tikz@to@start@compute@looseness% |
| 239 |
\let\tikz@to@end@compute=\tikz@to@end@compute@looseness% |
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
% Relative curves |
| 245 |
|
| 246 |
\def\tikz@to@compute@relative{% |
| 247 |
\tikz@scan@one@point\tikz@@to@compute@relative(\tikztostart)% |
| 248 |
} |
| 249 |
\def\tikz@@to@compute@relative#1{% |
| 250 |
\def\tikz@tofrom{#1}% |
| 251 |
\tikz@scan@one@point\tikz@@@to@compute@relative(\tikztotarget)% |
| 252 |
} |
| 253 |
\def\tikz@@@to@compute@relative#1{% |
| 254 |
\def\tikz@toto{#1}% |
| 255 |
\begingroup |
| 256 |
% |
| 257 |
% Adjust start and target so that they lie on the border in the |
| 258 |
% rotated coordinate system. |
| 259 |
% |
| 260 |
\pgfutil@ifundefined{pgf@sh@ns@\tikztostart} |
| 261 |
{% |
| 262 |
\let\tikz@first@point=\tikz@tofrom% |
| 263 |
\let\tikz@tostart@tikz=\pgfutil@empty |
| 264 |
}% |
| 265 |
{% |
| 266 |
% Start computation of new start. |
| 267 |
{% |
| 268 |
\tikz@tofrom% |
| 269 |
\pgf@xc=\pgf@x% |
| 270 |
\pgf@yc=\pgf@y% |
| 271 |
{% |
| 272 |
\pgftransformreset% |
| 273 |
\pgftransformshift{\pgfqpoint{\pgf@xc}{\pgf@yc}}% |
| 274 |
\pgftransformrotate{\tikz@to@out}% |
| 275 |
\pgftransformshift{\pgfqpoint{-\pgf@xc}{-\pgf@yc}}% |
| 276 |
\pgf@process{\pgfpointtransformed{\tikz@toto}}% |
| 277 |
}% |
| 278 |
\pgf@xc=\pgf@x% |
| 279 |
\pgf@yc=\pgf@y% |
| 280 |
\pgfpointshapeborder{\tikztostart}{\pgfqpoint{\pgf@xc}{\pgf@yc}}% |
| 281 |
\xdef\tikz@tofrom@smuggle{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}} |
| 282 |
}% |
| 283 |
\let\tikz@first@point=\tikz@tofrom@smuggle% |
| 284 |
\tikz@first@point% |
| 285 |
\edef\tikz@tostart@tikz{(\the\pgf@x,\the\pgf@y)}% |
| 286 |
}% |
| 287 |
\pgfutil@ifundefined{pgf@sh@ns@\tikztotarget} |
| 288 |
{% |
| 289 |
\let\tikz@second@point=\tikz@toto% |
| 290 |
}% |
| 291 |
{% |
| 292 |
% Start computation of new target. |
| 293 |
{% |
| 294 |
\tikz@toto% |
| 295 |
\pgf@xc=\pgf@x% |
| 296 |
\pgf@yc=\pgf@y% |
| 297 |
{% |
| 298 |
\pgftransformreset% |
| 299 |
\pgftransformshift{\pgfqpoint{\pgf@xc}{\pgf@yc}}% |
| 300 |
\pgftransformrotate{180}% |
| 301 |
\pgftransformrotate{\tikz@to@in}% |
| 302 |
\pgftransformshift{\pgfqpoint{-\pgf@xc}{-\pgf@yc}}% |
| 303 |
\pgf@process{\pgfpointtransformed{\tikz@tofrom}}% |
| 304 |
}% |
| 305 |
\pgf@xc=\pgf@x% |
| 306 |
\pgf@yc=\pgf@y% |
| 307 |
\pgfpointshapeborder{\tikztotarget}{\pgfqpoint{\pgf@xc}{\pgf@yc}}% |
| 308 |
\xdef\tikz@toto@smuggle{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}} |
| 309 |
}% |
| 310 |
\let\tikz@second@point=\tikz@toto@smuggle% |
| 311 |
}% |
| 312 |
\tikz@second@point% |
| 313 |
\edef\tikz@totarget@tikz{(\the\pgf@x,\the\pgf@y)}% |
| 314 |
% |
| 315 |
% Compute distances |
| 316 |
% |
| 317 |
\tikz@to@compute@distance@main% |
| 318 |
\edef\tikz@to@first@distance{\the\pgf@xa}% |
| 319 |
\edef\tikz@to@second@distance{\the\pgf@xb}% |
| 320 |
% |
| 321 |
% Next step: Establish a transformed coordinate system so that the (modified) |
| 322 |
% start is at the origin and the (modified) target is at (1,0) |
| 323 |
% |
| 324 |
\pgftransformreset% |
| 325 |
\pgf@process{\tikz@first@point}% |
| 326 |
\pgf@xa=\pgf@x% |
| 327 |
\pgf@ya=\pgf@y% |
| 328 |
\pgf@process{\tikz@second@point}% |
| 329 |
\advance\pgf@x by-\pgf@xa% |
| 330 |
\advance\pgf@y by-\pgf@ya% |
| 331 |
\pgfpointnormalised{}% |
| 332 |
\pgf@xc=\pgf@x% |
| 333 |
\pgf@yc=\pgf@y% |
| 334 |
\pgf@xb=-\pgf@x% |
| 335 |
\pgf@yb=-\pgf@y% |
| 336 |
% |
| 337 |
% Now compute the control points. |
| 338 |
% |
| 339 |
{% |
| 340 |
\pgftransformshift{\tikz@first@point}% |
| 341 |
\pgftransformcm{\pgf@sys@tonumber\pgf@xc}{\pgf@sys@tonumber\pgf@yc}{\pgf@sys@tonumber\pgf@yb}{\pgf@sys@tonumber\pgf@xc}% |
| 342 |
{\pgfpointorigin}% |
| 343 |
\pgf@process{\pgfpointtransformed{\pgfpointpolar{\tikz@to@out}{\tikz@to@first@distance}}}% |
| 344 |
\xdef\tikz@computed@start{(\the\pgf@x,\the\pgf@y)}% |
| 345 |
} |
| 346 |
{% |
| 347 |
\pgftransformshift{\tikz@second@point}% |
| 348 |
\pgftransformcm{\pgf@sys@tonumber\pgf@xc}{\pgf@sys@tonumber\pgf@yc}{\pgf@sys@tonumber\pgf@yb}{\pgf@sys@tonumber\pgf@xc}% |
| 349 |
{\pgfpointorigin}% |
| 350 |
\pgf@process{\pgfpointtransformed{\pgfpointpolar{\tikz@to@in}{\tikz@to@second@distance}}}% |
| 351 |
\xdef\tikz@computed@end{(\the\pgf@x,\the\pgf@y)}% |
| 352 |
} |
| 353 |
\xdef\tikz@computed@path{ |
| 354 |
\tikz@tostart@tikz |
| 355 |
.. controls \tikz@computed@start and \tikz@computed@end .. |
| 356 |
\tikz@totarget@tikz}% |
| 357 |
\endgroup |
| 358 |
} |
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
% Loops |
| 363 |
|
| 364 |
\tikzset{loop/.style= {to path={ |
| 365 |
\pgfextra{\let\tikztotarget=\tikztostart} |
| 366 |
[looseness=8,min distance=5mm,every loop] |
| 367 |
\tikz@to@curve@path |
| 368 |
}}} |
| 369 |
|
| 370 |
\tikzset{every loop/.style= {->,shorten >=1pt}} |
| 371 |
|
| 372 |
\tikzset{loop right/.style= {right,out=15,in=-15,loop}} |
| 373 |
\tikzset{loop above/.style= {above,out=105,in=75,loop}} |
| 374 |
\tikzset{loop left/.style= {left,out=195,in=165,loop}} |
| 375 |
\tikzset{loop below/.style= {below,out=285,in=255,loop}} |
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
\endinput |