summaryrefslogtreecommitdiff
path: root/graphics/pgf/contrib/tikz-ext/tikzlibrarypaths.ortho.code.tex
blob: 8f322fbd35c8af32ef66f062ce6809054937c42f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
% Copyright 2022 by Qrrbrbirlbel
%
% This file may be distributed and/or modified
%
% 1. under the LaTeX Project Public License and/or
% 2. under the GNU Free Documentation License.
%

%% For the operators r-lr, r-rl, r-ud and r-du we need to check after TikZ found r
\let\tikz@orig@rect\tikz@rect
\def\tikz@rect{\pgfutil@ifnextchar e\tikz@orig@rect\qrr@tikz@r}
\def\qrr@tikz@r -{%
  \pgfutil@ifnextchar l\qrr@tikz@lr@lineto{%
    \pgfutil@ifnextchar r\qrr@tikz@rl@lineto{%
      \pgfutil@ifnextchar u\qrr@tikz@ud@lineto{%
        \pgfutil@ifnextchar d\qrr@tikz@du@lineto\tikz@expand
      }%
    }%
  }%
}
%% For the operator |-| we need to check after TikZ found |-
\let\tikz@orig@vh@lineto@next\tikz@vh@lineto@next
\def\tikz@vh@lineto@next{%
  \pgfutil@ifnextchar|{\expandafter\qrr@tikz@vhv@lineto\pgfutil@gobble}%
    {\pgfutil@ifnextchar\tikz@activebar{\expandafter\qrr@tikz@vhv@lineto\pgfutil@gobble}%
      {\tikz@orig@vh@lineto@next}}}
%% For the operator -|- we need to check after TikZ found -|
\let\tikz@orig@hv@lineto\tikz@hv@lineto
\def\tikz@hv@lineto{%
  \pgfutil@ifnextchar-{\expandafter\qrr@tikz@hvh@lineto\pgfutil@gobble}%
    {\tikz@orig@hv@lineto}}

%% |-|[<opts>] and -|-[<opts>] are allowed
\def\qrr@tikz@vhv@lineto{\pgfutil@ifnextchar[{\qrr@tikz@collect@hvvh@options\qrr@tikz@vhv@lineto@next}{\qrr@tikz@collect@hvvh@options\qrr@tikz@vhv@lineto@next[]}}
\def\qrr@tikz@hvh@lineto{\pgfutil@ifnextchar[{\qrr@tikz@collect@hvvh@options\qrr@tikz@hvh@lineto@next}{\qrr@tikz@collect@hvvh@options\qrr@tikz@hvh@lineto@next[]}}

%% r-rl[<opts>], r-lr[<opts>], etc.
\def\qrr@tikz@rl@lineto rl{\pgfutil@ifnextchar[{\qrr@tikz@collect@hvvh@options\qrr@tikz@rl@lineto@next}{\qrr@tikz@collect@hvvh@options\qrr@tikz@rl@lineto@next[]}}
\def\qrr@tikz@lr@lineto lr{\pgfutil@ifnextchar[{\qrr@tikz@collect@hvvh@options\qrr@tikz@lr@lineto@next}{\qrr@tikz@collect@hvvh@options\qrr@tikz@lr@lineto@next[]}}
\def\qrr@tikz@du@lineto du{\pgfutil@ifnextchar[{\qrr@tikz@collect@hvvh@options\qrr@tikz@du@lineto@next}{\qrr@tikz@collect@hvvh@options\qrr@tikz@du@lineto@next[]}}
\def\qrr@tikz@ud@lineto ud{\pgfutil@ifnextchar[{\qrr@tikz@collect@hvvh@options\qrr@tikz@ud@lineto@next}{\qrr@tikz@collect@hvvh@options\qrr@tikz@ud@lineto@next[]}}

%% TikZ interjects are done, the rest is independent:
\input tikzlibrarypaths.ortho.tex

%% a few nice to haves, use with to or edge operator
\let\tikz@origtotarget\pgfutil@empty
\tikzset{
  node as new start/.is if=tikz@ortho@preflush,
  node as new start,
  horizontal vertical/.style={to path={-| (\tikztotarget) \tikztonodes}},
  vertical horizontal/.style={to path={|- (\tikztotarget) \tikztonodes}},
  horizontal vertical horizontal/.style={to path={-|- (\tikztotarget) \tikztonodes}},
  vertical horizontal vertical/.style={to path={|-| (\tikztotarget) \tikztonodes}},
  only vertical second/.style={to path={
    \pgfextra
      \let\tikz@ortho@anchor\pgfutil@empty
      \let\tikz@origtotarget\pgfutil@empty
      \tikz@scan@one@point\pgfutil@firstofone(\tikztostart)\relax
      \iftikz@shapeborder
        \tikz@scan@one@point\pgfutil@firstofone(\tikztotarget)\relax
        \ifdim\pgf@y>\tikz@lasty\relax
          \edef\tikztostart{\tikztostart.north}%
          \iftikz@shapeborder\def\tikz@ortho@anchor{.south}\fi
        \else
          \edef\tikztostart{\tikztostart.south}%
          \iftikz@shapeborder\def\tikz@ortho@anchor{.north}\fi
        \fi
      \fi
      \def\tikz@tempa{#1}%
      \ifx\tikz@tempa\pgfutil@empty\else
        \let\tikz@origtotarget\tikztotarget
        \edef\tikztotarget{[xshift={#1}]\tikztotarget\tikz@ortho@anchor}%
      \fi
    \endpgfextra
    [insert path/.expanded={
      (perpendicular cs: horizontal line through={(\tikztostart)},
                         vertical line through={(\tikztotarget)}) -- (\tikztotarget)}] \tikztonodes
      \pgfextra
        \ifx\tikz@origtotarget\pgfutil@empty\else
          \iftikz@ortho@preflush(\tikz@origtotarget)\fi\fi\endpgfextra}},
  only vertical second/.default=,
  only horizontal second/.style={to path={
    \pgfextra
      \let\tikz@ortho@anchor\pgfutil@empty
      \let\tikz@origtotarget\pgfutil@empty
      \tikz@scan@one@point\pgfutil@firstofone(\tikztostart)\relax
      \iftikz@shapeborder
        \tikz@scan@one@point\pgfutil@firstofone(\tikztotarget)\relax
        \ifdim\pgf@x>\tikz@lastx\relax
          \edef\tikztostart{\tikztostart.east}%
          \iftikz@shapeborder\def\tikz@ortho@anchor{.west}\fi
        \else
          \edef\tikztostart{\tikztostart.west}%
          \iftikz@shapeborder\def\tikz@ortho@anchor{.east}\fi
        \fi
      \fi
      \def\tikz@tempa{#1}%
      \ifx\tikz@tempa\pgfutil@empty\else
        \let\tikz@origtotarget\tikztotarget
        \edef\tikztotarget{[yshift={#1}]\tikztotarget\tikz@ortho@anchor}%
      \fi
    \endpgfextra
    [insert path/.expanded={
      (perpendicular cs: vertical line through={(\tikztostart)},
                         horizontal line through={(\tikztotarget)}) -- (\tikztotarget)}] \tikztonodes
    \pgfextra
      \ifx\tikz@origtotarget\pgfutil@empty\else
        \iftikz@ortho@preflush(\tikz@origtotarget)\fi\fi\endpgfextra}},
  only horizontal second/.default=,
  only vertical first/.style={to path={
    \pgfextra
      \let\tikz@ortho@anchor\pgfutil@empty
      \let\tikz@origtotarget\pgfutil@empty
      \tikz@scan@one@point\pgfutil@firstofone(\tikztotarget)\relax
      \iftikz@shapeborder
        \let\tikz@origtotarget\tikztotarget
        \tikz@scan@one@point\pgfutil@firstofone(\tikztostart)\relax
        \ifdim\pgf@y>\tikz@lasty\relax
          \edef\tikztotarget{\tikztotarget.south}%
          \iftikz@shapeborder\def\tikz@ortho@anchor{.north}\fi
        \else
          \edef\tikztotarget{\tikztotarget.north}%
          \iftikz@shapeborder\def\tikz@ortho@anchor{.south}\fi
        \fi
      \fi
      \def\tikz@tempa{#1}%
      \ifx\tikz@tempa\pgfutil@empty\else
        \edef\tikztostart{[xshift={#1}]\tikztostart\tikz@ortho@anchor}%
      \fi
    \endpgfextra
    [insert path/.expanded={(\tikztostart)}] 
    -- (perpendicular cs: vertical line through/.expanded={(\tikztostart)},
                        horizontal line through={(\tikztotarget)})
    \tikztonodes
    \pgfextra
      \ifx\tikz@origtotarget\pgfutil@empty\else
        \iftikz@ortho@preflush(\tikz@origtotarget)\fi\fi\endpgfextra}},
  only vertical first/.default=,
  only horizontal first/.style={to path={
    \pgfextra
      \let\tikz@ortho@anchor\pgfutil@empty
      \let\tikz@origtotarget\pgfutil@empty
      \tikz@scan@one@point\pgfutil@firstofone(\tikztotarget)\relax
      \iftikz@shapeborder
        \let\tikz@origtotarget\tikztotarget
        \tikz@scan@one@point\pgfutil@firstofone(\tikztostart)\relax
        \ifdim\pgf@x>\tikz@lastx\relax
          \edef\tikztotarget{\tikztotarget.west}%
          \iftikz@shapeborder\def\tikz@ortho@anchor{.east}\fi
        \else
          \edef\tikztotarget{\tikztotarget.east}%
          \iftikz@shapeborder\def\tikz@ortho@anchor{.west}\fi
        \fi
      \fi
      \def\tikz@tempa{#1}%
      \ifx\tikz@tempa\pgfutil@empty\else
        \edef\tikztostart{[yshift={#1}]\tikztostart\tikz@ortho@anchor}%
      \fi
    \endpgfextra
    [insert path/.expanded={(\tikztostart)}]
      -- (perpendicular cs: horizontal line through/.expanded={(\tikztostart)},
                              vertical line through={(\tikztotarget)})
    \tikztonodes \pgfextra
      \ifx\tikz@origtotarget\pgfutil@empty\else
        \iftikz@ortho@preflush(\tikz@origtotarget)\fi\fi\endpgfextra}},
  only horizontal first/.default=,
  only vertical first to center/.style={to path={
      \pgfextra
        \let\tikz@origtotarget\tikztotarget
      \endpgfextra
    (\tikztostart) -- (perpendicular cs: vertical line through={(\tikztostart)},
                                         horizontal line through={(\tikztotarget)})
    \tikztonodes \ifx\tikz@origtotarget\pgfutil@empty\else\iftikz@ortho@preflush(\tikz@origtotarget)\fi\fi}},
  only horizontal first to center/.style={to path={
      \pgfextra
        \let\tikz@origtotarget\tikztotarget
      \endpgfextra
    (\tikztostart) -- (perpendicular cs: horizontal line through={(\tikztostart)},
                                         vertical line through={(\tikztotarget)})
    \tikztonodes \ifx\tikz@origtotarget\pgfutil@empty\else\iftikz@ortho@preflush(\tikz@origtotarget)\fi\fi}}%
}
\endinput