Debian Codegraph @

texmf-dist/tex/generic/tikz-ext/pgflibraryext.shapes.rectangleroundedcorners.code.tex

raw
1 % Copyright 2022 by Qrrbrbirlbel
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 Free Documentation License.
7 %
8 \unless\ifcsname pgfextset\endcsname
9 \input tikzext-util.tex
10 \fi
11
12 \pgfextset{
13 rectangle with rounded corners north west radius/.initial=.5\pgflinewidth,
14 rectangle with rounded corners north east radius/.initial=.5\pgflinewidth,
15 rectangle with rounded corners south west radius/.initial=.5\pgflinewidth,
16 rectangle with rounded corners south east radius/.initial=.5\pgflinewidth,
17 rectangle with rounded corners radius/.style={
18 /pgf/ext/rectangle with rounded corners north west radius={#1},
19 /pgf/ext/rectangle with rounded corners north east radius={#1},
20 /pgf/ext/rectangle with rounded corners south west radius={#1},
21 /pgf/ext/rectangle with rounded corners south east radius={#1}}
22 }%
23 \pgfdeclareshape{ext_rectangle with rounded corners}{%
24 \savedmacro\rectanglewithroundedcornersparameter{%
25 %
26 % width = max(text width + 2 * inner xseps, minimum width) + 2 * outer xseps
27 \pgf@x=\wd\pgfnodeparttextbox
28 \pgfmathsetlength\pgf@xc{\pgfkeysvalueof{/pgf/inner xsep}}%
29 \advance\pgf@x by 2\pgf@xc
30 \pgfmathsetlength\pgf@xc{\pgfkeysvalueof{/pgf/minimum width}}%
31 \ifdim\pgf@x<\pgf@xc
32 \pgf@x=\pgf@xc
33 \fi
34 %
35 \pgfmathsetlength\pgf@xc{\pgfkeysvalueof{/pgf/outer xsep}}%
36 \edef\outerxsep{\the\pgf@xc}%
37 \addtosavedmacro\outerxsep
38 \advance\pgf@x by 2\pgf@xc
39 \pgf@x=.5\pgf@x
40 \edef\halfwidth{\the\pgf@x}%
41 \addtosavedmacro\halfwidth
42 %
43 % height = max(text height + text depth + 2 * inner yseps, minimum height) + 2 * outer yseps
44 \pgf@y=\ht\pgfnodeparttextbox
45 \advance\pgf@y by \dp\pgfnodeparttextbox
46 \pgfmathsetlength\pgf@yc{\pgfkeysvalueof{/pgf/inner ysep}}%
47 \advance\pgf@y by 2\pgf@yc
48 \pgfmathsetlength\pgf@yc{\pgfkeysvalueof{/pgf/minimum height}}%
49 \ifdim\pgf@y<\pgf@yc
50 \pgf@y=\pgf@yc
51 \fi
52 %
53 \pgfmathsetlength\pgf@yc{\pgfkeysvalueof{/pgf/outer ysep}}%
54 \edef\outerysep{\the\pgf@yc}%
55 \addtosavedmacro\outerysep
56 \advance\pgf@y by 2\pgf@yc
57 \pgf@y=.5\pgf@y
58 \edef\halfheight{\the\pgf@y}%
59 \addtosavedmacro\halfheight
60 %
61 % \centerpoint
62 \pgf@x=.5\wd\pgfnodeparttextbox
63 \pgf@y=.5\ht\pgfnodeparttextbox
64 \advance\pgf@y by -.5\dp\pgfnodeparttextbox
65 \pgfextract@process\centerpoint{}%
66 \addtosavedmacro\centerpoint
67 %
68 \pgfmathsetlengthmacro\northwestradius{\pgfkeysvalueof{/pgf/ext/rectangle with rounded corners north west radius}}
69 \pgfmathsetlengthmacro\northeastradius{\pgfkeysvalueof{/pgf/ext/rectangle with rounded corners north east radius}}
70 \pgfmathsetlengthmacro\southwestradius{\pgfkeysvalueof{/pgf/ext/rectangle with rounded corners south west radius}}
71 \pgfmathsetlengthmacro\southeastradius{\pgfkeysvalueof{/pgf/ext/rectangle with rounded corners south east radius}}
72 \addtosavedmacro\northwestradius
73 \addtosavedmacro\northeastradius
74 \addtosavedmacro\southwestradius
75 \addtosavedmacro\southeastradius
76 }%
77 \anchor{center}{%
78 \rectanglewithroundedcornersparameter
79 \centerpoint
80 }
81 \anchor{west}{%
82 \rectanglewithroundedcornersparameter
83 \centerpoint
84 \advance\pgf@x by -\halfwidth
85 }
86 \anchor{east}{%
87 \rectanglewithroundedcornersparameter
88 \centerpoint
89 \advance\pgf@x by \halfwidth
90 }
91 \anchor{north}{%
92 \rectanglewithroundedcornersparameter
93 \centerpoint
94 \advance\pgf@y by \halfheight
95 }
96 \anchor{south}{%
97 \rectanglewithroundedcornersparameter
98 \centerpoint
99 \advance\pgf@y by -\halfheight
100 }
101 \anchor{mid}{%
102 \rectanglewithroundedcornersparameter
103 \centerpoint
104 \pgfmathsetlength\pgf@y{+.5ex}%
105 }
106 \anchor{mid west}{%
107 \csname pgf@anchor@ext_rectangle with rounded corners@west\endcsname
108 \pgfmathsetlength\pgf@y{+.5ex}%
109 }
110 \anchor{mid east}{%
111 \csname pgf@anchor@ext_rectangle with rounded corners@east\endcsname
112 \pgfmathsetlength\pgf@y{+.5ex}%
113 }
114 \anchor{base}{%
115 \rectanglewithroundedcornersparameter
116 \centerpoint
117 \pgf@y=0pt
118 }
119 \anchor{base west}{%
120 \csname pgf@anchor@ext_rectangle with rounded corners@west\endcsname
121 \pgf@y=0pt
122 }
123 \anchor{base east}{%
124 \csname pgf@anchor@ext_rectangle with rounded corners@east\endcsname
125 \pgf@y=0pt
126 }
127 \anchor{north west}{%
128 \csname pgf@anchor@ext_rectangle with rounded corners@north west center\endcsname
129 \ifdim\northwestradius=0pt
130 \else
131 \pgf@process{\pgfpointadd{}{\pgfpointpolar{135}{\northwestradius+\outerxsep and \northwestradius+\outerysep}}}%
132 \fi
133 }
134 \anchor{north west center}{%
135 \rectanglewithroundedcornersparameter
136 \pgf@x=-\halfwidth
137 \pgf@y=\halfheight
138 \ifdim\northwestradius=0pt
139 \else
140 \advance\pgf@x by \outerxsep
141 \advance\pgf@x by \northwestradius
142 \advance\pgf@y by -\outerysep
143 \advance\pgf@y by -\northwestradius
144 \fi
145 \pgf@process{\pgfpointadd{}{\centerpoint}}%
146 }
147 \anchor{north east}{%
148 \csname pgf@anchor@ext_rectangle with rounded corners@north east center\endcsname
149 \ifdim\northeastradius=0pt
150 \else
151 \pgf@process{\pgfpointadd{}{\pgfpointpolar{45}{\northeastradius+\outerxsep and \northeastradius+\outerysep}}}%
152 \fi
153 }
154 \anchor{north east center}{%
155 \rectanglewithroundedcornersparameter
156 \pgf@x=\halfwidth
157 \pgf@y=\halfheight
158 \ifdim\northeastradius=0pt
159 \else
160 \advance\pgf@x by -\outerxsep
161 \advance\pgf@x by -\northeastradius
162 \advance\pgf@y by -\outerysep
163 \advance\pgf@y by -\northeastradius
164 \fi
165 \pgf@process{\pgfpointadd{}{\centerpoint}}%
166 }
167 \anchor{south west}{%
168 \csname pgf@anchor@ext_rectangle with rounded corners@south west center\endcsname
169 \ifdim\southwestradius=0pt
170 \else
171 \pgf@process{\pgfpointadd{}{\pgfpointpolar{225}{\southwestradius+\outerxsep and \southwestradius+\outerysep}}}%
172 \fi
173 }
174 \anchor{south west center}{%
175 \rectanglewithroundedcornersparameter
176 \pgf@x=-\halfwidth
177 \pgf@y=-\halfheight
178 \ifdim\southwestradius=0pt
179 \else
180 \advance\pgf@x by \outerxsep
181 \advance\pgf@x by \southwestradius
182 \advance\pgf@y by \outerysep
183 \advance\pgf@y by \southwestradius
184 \fi
185 \pgf@process{\pgfpointadd{}{\centerpoint}}%
186 }
187 \anchor{south east}{%
188 \csname pgf@anchor@ext_rectangle with rounded corners@south east center\endcsname
189 \ifdim\southeastradius=0pt
190 \else
191 \pgf@process{\pgfpointadd{}{\pgfpointpolar{315}{\southeastradius+\outerxsep and \southeastradius+\outerysep}}}%
192 \fi
193 }
194 \anchor{south east center}{%
195 \rectanglewithroundedcornersparameter
196 \pgf@x=\halfwidth
197 \pgf@y=-\halfheight
198 \ifdim\southeastradius=0pt
199 \else
200 \advance\pgf@x by -\outerxsep
201 \advance\pgf@x by -\southeastradius
202 \advance\pgf@y by \outerysep
203 \advance\pgf@y by \southeastradius
204 \fi
205 \pgf@process{\pgfpointadd{}{\centerpoint}}%
206 }
207 \anchor{below north west}{%
208 \csname pgf@anchor@ext_rectangle with rounded corners@north west center\endcsname
209 \advance\pgf@x by -\northwestradius
210 \advance\pgf@x by -\outerxsep
211 }
212 \anchor{above south west}{%
213 \csname pgf@anchor@ext_rectangle with rounded corners@south west center\endcsname
214 \advance\pgf@x by -\southwestradius
215 \advance\pgf@x by -\outerxsep
216 }
217 \anchor{below north east}{%
218 \csname pgf@anchor@ext_rectangle with rounded corners@north east center\endcsname
219 \advance\pgf@x by \northeastradius
220 \advance\pgf@x by \outerxsep
221 }
222 \anchor{above south east}{%
223 \csname pgf@anchor@ext_rectangle with rounded corners@south east center\endcsname
224 \advance\pgf@x by \southeastradius
225 \advance\pgf@x by \outerxsep
226 }
227 \anchor{right north west}{%
228 \csname pgf@anchor@ext_rectangle with rounded corners@north west center\endcsname
229 \advance\pgf@y by \northwestradius
230 \advance\pgf@y by \outerysep
231 }
232 \anchor{right south west}{%
233 \csname pgf@anchor@ext_rectangle with rounded corners@south west center\endcsname
234 \advance\pgf@y by -\southwestradius
235 \advance\pgf@y by -\outerysep
236 }
237 \anchor{left north east}{%
238 \csname pgf@anchor@ext_rectangle with rounded corners@north east center\endcsname
239 \advance\pgf@y by \northeastradius
240 \advance\pgf@y by \outerysep
241 }
242 \anchor{left south east}{%
243 \csname pgf@anchor@ext_rectangle with rounded corners@south east center\endcsname
244 \advance\pgf@y by -\southeastradius
245 \advance\pgf@y by -\outerysep
246 }
247 \backgroundpath{%
248 \rectanglewithroundedcornersparameter
249 %
250 \pgf@xa=\halfwidth
251 \advance\pgf@xa by -\outerxsep
252 \edef\HalfWidth{\the\pgf@xa}%
253 %
254 \pgf@ya=\halfheight
255 \advance\pgf@ya by -\outerysep
256 \edef\HalfHeight{\the\pgf@ya}%
257 %
258 \pgftransformshift{\centerpoint}%
259 %
260 \pgfpathmoveto{\pgfqpoint{\HalfWidth}{0pt}}%
261 \pgfpathlineto{\pgfpoint {+\HalfWidth}{\HalfHeight-\northeastradius}}%
262 \pgfpatharc{0}{90}{\northeastradius}%
263 \pgfpathlineto{\pgfpoint{-\HalfWidth+\northwestradius}{+\HalfHeight}}
264 \pgfpatharc{90}{180}{\northwestradius}%
265 \pgfpathlineto{\pgfpoint{+-\HalfWidth}{-\HalfHeight+\southwestradius}}%
266 \pgfpatharc{180}{270}{\southwestradius}%
267 \pgfpathlineto{\pgfpoint{\HalfWidth-\southeastradius}{+-\HalfHeight}}%
268 \pgfpatharc{270}{360}{\southeastradius}%
269 \pgfpathclose
270 \pgftransformshift{\pgfqpointscale{-1}{\centerpoint}}%
271 }%
272 \anchorborder{%
273 \pgfextract@process\externalpoint{}%
274 \ifdim\pgf@x=0pt
275 \ifdim\pgf@y<0pt
276 \csname pgf@anchor@ext_rectangle with rounded corners@south\endcsname
277 \else
278 \csname pgf@anchor@ext_rectangle with rounded corners@north\endcsname
279 \fi
280 \else
281 \ifdim\pgf@y=0pt
282 \ifdim\pgf@x<0pt
283 \csname pgf@anchor@ext_rectangle with rounded corners@west\endcsname
284 \else
285 \csname pgf@anchor@ext_rectangle with rounded corners@east\endcsname
286 \fi
287 \else
288 \rectanglewithroundedcornersparameter
289 \pgfmathanglebetweenpoints{\pgfpointorigin}{\externalpoint}%
290 \let\angle\pgfmathresult
291 \pgf@xa=\pgf@x
292 \pgf@ya=\pgf@y
293 \pgfextract@process\externalPoint{\pgfpointadd{}{\centerpoint}}%
294 \ifdim\pgf@xa<0pt
295 \ifdim\pgf@ya<0pt
296 % south west
297 \pgfext@sh@rwrc@anchorborder{above south west}{right south west}{south west}{180}{270}{\southwestradius}%
298 \else
299 % north west
300 \pgfext@sh@rwrc@anchorborder{right north west}{below north west}{north west}{90}{180}{\northwestradius}%
301 \fi
302 \else
303 \ifdim\pgf@ya<0pt
304 % south east
305 \pgfext@sh@rwrc@anchorborder{left south east}{above south east}{south east}{270}{360}{\southeastradius}%
306 \else
307 % north east
308 \pgfext@sh@rwrc@anchorborder{below north east}{left north east}{north east}{0}{90}{\northeastradius}%
309 \fi
310 \fi
311 \fi
312 \fi
313 }
314 }
315 \def\pgfext@sh@rwrc@anchorborder#1#2#3#4#5#6{%
316 \pgfmathanglebetweenpoints{\centerpoint}{\csname pgf@anchor@ext_rectangle with rounded corners@#1\endcsname}%
317 \let\angleA\pgfmathresult
318 \pgfmathanglebetweenpoints{\centerpoint}{\csname pgf@anchor@ext_rectangle with rounded corners@#2\endcsname}%
319 \let\angleB\pgfmathresult
320 \if\ifdim\angle pt>\angleA pt 0\else1\fi\ifdim\angle pt<\angleB pt 0\else 2\fi
321 \pgfmathpointintersectionoflineandarc{\externalPoint}{\centerpoint}
322 {\csname pgf@anchor@ext_rectangle with rounded corners@#3 center\endcsname}
323 {#4}{#5}{#6+\outerxsep and #6+\outerysep}%
324 \else
325 \pgf@process{\pgfpointadd{\pgfpointborderrectangle{\externalpoint}{\pgfqpoint{\halfwidth}{\halfheight}}}{\centerpoint}}%
326 \fi
327 }
328 %%% Compatibility
329 \pgfkeysifdefined{/tikz/ext/compat/shapes/.@cmd}{}{\pgfextset{/tikz-ext/compat/add library={shapes}{pre 0.6}}}
330 \tikzextset{
331 compat/shapes/warn/.append style=/tikz/ext/compat/shapes.rectangleroundedcorners/warn,
332 compat/shapes/pre 0.6/.append style=/tikz/ext/compat/shapes.rectangleroundedcorners/pre 0.6,
333 compat/shapes.rectangleroundedcorners/warn/.code={%
334 \tikzextutil@compatwarning@key{shapes}{pre 0.6}{/pgf/rectangle with rounded corners radius}{/pgf/ext/rectangle with rounded corners radius}%
335 \tikzextutil@compatwarning@valuekey{shapes}{pre 0.6}{/pgf/rectangle with rounded corners north west radius}{/pgf/ext/rectangle with rounded corners north west radius}%
336 \tikzextutil@compatwarning@valuekey{shapes}{pre 0.6}{/pgf/rectangle with rounded corners north east radius}{/pgf/ext/rectangle with rounded corners north east radius}%
337 \tikzextutil@compatwarning@valuekey{shapes}{pre 0.6}{/pgf/rectangle with rounded corners south west radius}{/pgf/ext/rectangle with rounded corners south west radius}%
338 \tikzextutil@compatwarning@valuekey{shapes}{pre 0.6}{/pgf/rectangle with rounded corners south east radius}{/pgf/ext/rectangle with rounded corners south east radius}%
339 \tikzextutil@compat@cloneshape{rectangle with rounded corners}{text,north,north west,north east,center,west,east,mid,mid west,mid east,base,base west,base east,south,south west,south east,center,below north west,right north west,left north east,below north east,above south east,left south east,right south west,above south west,north west center,north east center,south east center,south west center}%
340 \def\tikzext@temp{\tikzextutil@compatmaybewarning{shape 'rectangle with rounded corners'}{'ext_rectangle with rounded corners'}{shapes = pre 0.6}}%
341 \expandafter\tikzextutil@prefix@macrotomacro\csname pgf@sh@s@rectangle with rounded corners\endcsname\tikzext@temp
342 },
343 compat/shapes.rectangleroundedcorners/pre 0.6/.code={%
344 \pgfkeysdef{/pgf/rectangle with rounded corners radius}{\pgfkeysvalueof{/pgf/ext/rectangle with rounded corners radius/.@cmd}##1\pgfeov}%
345 \pgfkeysdef{/pgf/rectangle with rounded corners north west radius}{\pgfkeyssetvalue{/pgf/ext/rectangle with rounded corners north west radius}{##1}}%
346 \pgfkeysdef{/pgf/rectangle with rounded corners north east radius}{\pgfkeyssetvalue{/pgf/ext/rectangle with rounded corners north east radius}{##1}}%
347 \pgfkeysdef{/pgf/rectangle with rounded corners south west radius}{\pgfkeyssetvalue{/pgf/ext/rectangle with rounded corners south west radius}{##1}}%
348 \pgfkeysdef{/pgf/rectangle with rounded corners south east radius}{\pgfkeyssetvalue{/pgf/ext/rectangle with rounded corners south east radius}{##1}}%
349 \pgfkeyssetvalue{/pgf/rectangle with rounded corners north west radius}{\pgfkeysvalueof{/pgf/ext/rectangle with rounded corners north west radius}}%
350 \pgfkeyssetvalue{/pgf/rectangle with rounded corners north east radius}{\pgfkeysvalueof{/pgf/ext/rectangle with rounded corners north east radius}}%
351 \pgfkeyssetvalue{/pgf/rectangle with rounded corners south west radius}{\pgfkeysvalueof{/pgf/ext/rectangle with rounded corners south west radius}}%
352 \pgfkeyssetvalue{/pgf/rectangle with rounded corners south east radius}{\pgfkeysvalueof{/pgf/ext/rectangle with rounded corners south east radius}}%
353 \tikzextutil@compat@cloneshape{rectangle with rounded corners}{text,north,north west,north east,center,west,east,mid,mid west,mid east,base,base west,base east,south,south west,south east,center,below north west,right north west,left north east,below north east,above south east,left south east,right south west,above south west,north west center,north east center,south east center,south west center}%
354 },
355 compat/shapes.rectangleroundedcorners/\pgfkeysvalueof{/tikz/ext/compat/shapes}%
356 }
357 \endinput