Debian Codegraph @

texmf-dist/tex/latex/hobby/pgflibraryhobby.code.tex

raw
1 %%
2 %% This is file `pgflibraryhobby.code.tex',
3 %% generated with the docstrip utility.
4 %%
5 %% The original source files were:
6 %%
7 %% hobby_code.dtx (with options: `pgflibrary')
8 %% ----------------------------------------------------------------
9 %% hobby --- a TikZ/PGF library for drawing smooth(ish) curves using
10 %% Hobby's algorithm (implemented in LaTeX3)
11 %% E-mail: [email protected]
12 %% Released under the LaTeX Project Public License v1.3c or later
13 %% See http://www.latex-project.org/lppl.txt
14 %% ----------------------------------------------------------------
15 %%
16 \input{hobby.code.tex}
17 \pgfkeys{
18 /pgf/hobby/.is family,
19 /pgf/hobby/.cd,
20 point/.code={%
21 \hobby@parse@pt#1\relax}
22 }
23 \def\hobby@parse@pt#1,#2\relax{%
24 \pgf@x=#1cm\relax
25 \pgf@y=#2cm\relax
26 }
27 \pgfmathparse{atan2(0,1)}
28 \def\hobby@temp{0.0}
29 \ifx\pgfmathresult\hobby@temp
30 \pgfmathdeclarefunction{hobbyatan2}{2}{%
31 \pgfmathatantwo@{#1}{#2}%
32 }
33 \else
34 \pgfmathdeclarefunction{hobbyatan2}{2}{%
35 \pgfmathatantwo@{#2}{#1}%
36 }
37 \fi
38 \def\hobby@curveto#1#2#3{%
39 \pgfpathcurveto{\hobby@topgf{#1}}{\hobby@topgf{#2}}{\hobby@topgf{#3}}%
40 }
41 \def\hobby@moveto#1#2#3{%
42 \pgfpathmoveto{\hobby@topgf{#3}}%
43 }
44 \def\hobby@topgf#1{%
45 \pgfqkeys{/pgf/hobby}{point={#1}}%
46 }
47 \def\hobby@close#1{%
48 \pgfpathclose
49 }
50 \def\pgfpathhobby{%
51 \pgfutil@ifnextchar\bgroup{\pgfpath@hobby}{\pgfpath@hobby{}}}
52 \def\pgfpath@hobby#1{%
53 \hobbyinit\hobby@moveto\hobby@curveto\hobby@close
54 \hobbysetparams{#1}%
55 \pgfmathsetmacro\hobby@x{\the\pgf@path@lastx/1cm}%
56 \pgfmathsetmacro\hobby@y{\the\pgf@path@lasty/1cm}%
57 \hobbyaddpoint{point={\hobby@x, \hobby@y}}%
58 }
59 \def\pgfpathhobbypt#1{%
60 #1%
61 \pgfmathsetmacro\hobby@x{\the\pgf@x/1cm}%
62 \pgfmathsetmacro\hobby@y{\the\pgf@y/1cm}%
63 \pgfutil@ifnextchar\bgroup{\pgfpathhobbyptparams}{\pgfpathhobbyptparams{}}%
64 }
65 \def\pgfpathhobbyptparams#1{%
66 \hobbyaddpoint{#1,point={\hobby@x, \hobby@y}}%
67 }
68 \def\pgfpathhobbyend{%
69 \ifhobby@externalise
70 \ifx\hobby@path@name\pgfutil@empty
71 \hobbygenusepath
72 \else
73 \hobbygenuseifnecpath{\hobby@path@name}%
74 \fi
75 \else
76 \hobbygenusepath
77 \fi
78 \ifx\hobby@path@name\pgfutil@empty
79 \else
80 \hobbysavepath{\hobby@path@name}%
81 \fi
82 \global\let\hobby@path@name=\pgfutil@empty
83 }
84 \def\pgfplothandlerhobby{%
85 \def\pgf@plotstreamstart{%
86 \hobbyinit\hobby@moveto\hobby@curveto\hobby@close
87 \global\let\pgf@plotstreampoint=\pgf@plot@hobby@firstpt
88 \global\let\pgf@plotstreamspecial=\pgfutil@gobble
89 \gdef\pgf@plotstreamend{%
90 \ifhobby@externalise
91 \ifx\hobby@path@name\pgfutil@empty
92 \hobbygenusepath
93 \else
94 \hobbygenuseifnecpath{\hobby@path@name}%
95 \fi
96 \else
97 \hobbygenusepath
98 \fi
99 \ifx\hobby@path@name\pgfutil@empty
100 \else
101 \hobbysavepath{\hobby@path@name}%
102 \fi
103 \global\let\hobby@path@name=\pgfutil@empty
104 }%
105 \let\tikz@scan@point@options=\pgfutil@empty
106 }
107 }
108 \def\pgfplothandlerclosedhobby{%
109 \def\pgf@plotstreamstart{%
110 \hobbyinit\hobby@moveto\hobby@curveto\hobby@close
111 \hobbysetparams{closed=true,disjoint=true}%
112 \global\let\pgf@plotstreampoint=\pgf@plot@hobby@firstpt
113 \global\let\pgf@plotstreamspecial=\pgfutil@gobble
114 \gdef\pgf@plotstreamend{%
115 \ifhobby@externalise
116 \ifx\hobby@path@name\pgfutil@empty
117 \hobbygenusepath
118 \else
119 \hobbygenuseifnecpath{\hobby@path@name}%
120 \fi
121 \else
122 \hobbygenusepath
123 \fi
124 \ifx\hobby@path@name\pgfutil@empty
125 \else
126 \hobbysavepath{\hobby@path@name}%
127 \fi
128 \global\let\hobby@path@name=\pgfutil@empty
129 }%
130 }
131 }
132 \def\pgf@plot@hobby@firstpt#1{%
133 \pgf@plot@first@action{#1}%
134 \pgf@plot@hobby@handler{#1}%
135 \global\let\pgf@plotstreampoint=\pgf@plot@hobby@handler
136 }
137 \def\pgf@plot@hobby@handler#1{%
138 #1%
139 \pgfmathsetmacro\hobby@x{\the\pgf@x/1cm}%
140 \pgfmathsetmacro\hobby@y{\the\pgf@y/1cm}%
141 \hobbyaddpoint{point={\hobby@x, \hobby@y}}%
142 }
143 \def\pgfplothandlerquickhobby{%
144 \def\pgf@plotstreamstart{%
145 \global\let\hobby@quick@curveto=\pgfpathcurveto
146 \global\let\pgf@plotstreampoint=\pgf@plot@qhobby@firstpt
147 \global\let\pgf@plotstreamspecial=\pgfutil@gobble
148 \global\let\pgf@plotstreamend=\pgf@plot@qhobby@end
149 }
150 }
151 \def\pgf@plot@qhobby@firstpt#1{%
152 #1%
153 \edef\hobby@temp{\noexpand\pgf@plot@first@action{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}}\hobby@temp%
154 \xdef\hobby@qpoints{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}%
155 \gdef\hobby@qpointa{}%
156 \gdef\hobby@angle{}%
157 \global\let\pgf@plotstreampoint=\pgf@plot@qhobby@secondpt
158 }
159 \def\pgf@plot@qhobby@secondpt#1{%
160 #1%
161 \xdef\hobby@qpointa{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}%
162 \global\let\pgf@plotstreampoint=\pgf@plot@qhobby@handler
163 }
164 \def\pgf@plot@qhobby@handler#1{%
165 #1
166 \edef\hobby@temp{\noexpand\hobby@quick@compute{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}}\hobby@temp
167 \global\let\hobby@qpointa=\hobby@qpointa
168 \global\let\hobby@qpoints=\hobby@qpoints
169 \global\let\hobby@angle=\hobby@angle
170 \global\let\hobby@thetaone=\hobby@thetaone
171 \global\let\hobby@phitwo=\hobby@phitwo
172 \global\let\hobby@done=\hobby@done
173 \global\let\hobby@omegaone=\hobby@omegaone
174 }
175 \def\pgf@plot@qhobby@end{%
176 \hobby@quick@computeend
177 }
178 \pgfmathsetmacro\hobby@sf{10cm}
179 \def\hobby@quick@compute#1{%
180 #1%
181 \pgf@xb=\pgf@x
182 \pgf@yb=\pgf@y
183 \hobby@qpointa
184 \pgf@xa=\pgf@x
185 \pgf@ya=\pgf@y
186 \advance\pgf@xb by -\pgf@xa
187 \advance\pgf@yb by -\pgf@ya
188 \pgfmathsetmacro\hobby@done{sqrt((\pgf@xb/\hobby@sf)^2 + (\pgf@yb/\hobby@sf)^2)}%
189 \pgfmathsetmacro\hobby@omegaone{rad(hobbyatan2(\pgf@yb,\pgf@xb))}%
190 \hobby@qpoints
191 \advance\pgf@xa by -\pgf@x
192 \advance\pgf@ya by -\pgf@y
193 \pgfmathsetmacro\hobby@dzero{sqrt((\pgf@xa/\hobby@sf)^2 + (\pgf@ya/\hobby@sf)^2)}%
194 \pgfmathsetmacro\hobby@omegazero{rad(hobbyatan2(\pgf@ya,\pgf@xa))}%
195 \pgfmathsetmacro\hobby@psi{\hobby@omegaone - \hobby@omegazero}%
196 \pgfmathsetmacro\hobby@psi{\hobby@psi > pi ? \hobby@psi - 2*pi : \hobby@psi}%
197 \pgfmathsetmacro\hobby@psi{\hobby@psi < -pi ? \hobby@psi + 2*pi : \hobby@psi}%
198 \ifx\hobby@angle\pgfutil@empty
199 \pgfmathsetmacro\hobby@thetaone{-\hobby@psi * \hobby@done%
200 /(\hobby@done + \hobby@dzero)}%
201 \pgfmathsetmacro\hobby@thetazero{-\hobby@psi - \hobby@thetaone}%
202 \let\hobby@phione=\hobby@thetazero
203 \let\hobby@phitwo=\hobby@thetaone
204 \else
205 \let\hobby@thetazero=\hobby@angle
206 \pgfmathsetmacro\hobby@thetaone{%
207 -(2 * \hobby@psi + \hobby@thetazero) * \hobby@done%
208 / (2 * \hobby@done + \hobby@dzero)}%
209 \pgfmathsetmacro\hobby@phione{-\hobby@psi - \hobby@thetaone}%
210 \let\hobby@phitwo=\hobby@thetaone
211 \fi
212 \let\hobby@angle=\hobby@thetaone
213 \hobby@quick@ctrlpts{\hobby@thetazero}{\hobby@phione}{\hobby@qpoints}{\hobby@qpointa}{\hobby@dzero}{\hobby@omegazero}%
214 \edef\hobby@temp{\noexpand\hobby@quick@curveto{\noexpand\pgfqpoint{\the\pgf@xa}{\the\pgf@ya}}{\noexpand\pgfqpoint{\the\pgf@xb}{\the\pgf@yb}}{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}}%
215 \hobby@temp
216 \global\let\hobby@qpoints=\hobby@qpointa
217 #1
218 \xdef\hobby@qpointa{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}%
219 \global\let\hobby@angle=\hobby@angle
220 \global\let\hobby@phitwo=\hobby@phitwo
221 \global\let\hobby@thetaone=\hobby@thetaone
222 \global\let\hobby@done=\hobby@done
223 \global\let\hobby@omegaone=\hobby@omegaone
224 }
225 \def\hobby@quick@computeend{%
226 \hobby@quick@ctrlpts{\hobby@thetaone}{\hobby@phitwo}{\hobby@qpoints}{\hobby@qpointa}{\hobby@done}{\hobby@omegaone}%
227 \edef\hobby@temp{\noexpand\hobby@quick@curveto{\noexpand\pgfqpoint{\the\pgf@xa}{\the\pgf@ya}}{\noexpand\pgfqpoint{\the\pgf@xb}{\the\pgf@yb}}{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}}%
228 \hobby@temp
229 }%
230 \def\hobby@quick@ctrlpts#1#2#3#4#5#6{%
231 \pgfmathsetmacro\hobby@alpha{%
232 sqrt(2) * (sin(#1 r) - 1/16 * sin(#2 r))%
233 * (sin(#2 r) - 1/16 * sin(#1 r))%
234 * (cos(#1 r) - cos(#2 r))}%
235 \pgfmathsetmacro\hobby@rho{%
236 (2 + \hobby@alpha)/(1 + (1 - (3 - sqrt(5))/2)%
237 * cos(#1 r) + (3 - sqrt(5))/2 * cos(#2 r))}%
238 \pgfmathsetmacro\hobby@sigma{%
239 (2 - \hobby@alpha)/(1 + (1 - (3 - sqrt(5))/2)%
240 * cos(#2 r) + (3 - sqrt(5))/2 * cos(#1 r))}%
241 #3%
242 \pgf@xa=\pgf@x
243 \pgf@ya=\pgf@y
244 \pgfmathsetlength\pgf@xa{%
245 \pgf@xa + #5 * \hobby@rho%
246 * cos((#1 + #6) r)/3*\hobby@sf}%
247 \pgfmathsetlength\pgf@ya{%
248 \pgf@ya + #5 * \hobby@rho%
249 * sin((#1 + #6) r)/3*\hobby@sf}%
250 #4%
251 \pgf@xb=\pgf@x
252 \pgf@yb=\pgf@y
253 \pgfmathsetlength\pgf@xb{%
254 \pgf@xb - #5 * \hobby@sigma%
255 * cos((-#2 + #6) r)/3*\hobby@sf}%
256 \pgfmathsetlength\pgf@yb{%
257 \pgf@yb - #5 * \hobby@sigma%
258 * sin((-#2 + #6) r)/3*\hobby@sf}%
259 #4%
260 }
261 %%
262 %% Copyright (C) 2012-2021 by Andrew Stacey <[email protected]>
263 %%
264 %% This file may be distributed and/or modified under the conditions
265 %% of the LaTeX Project Public License, either version 1.3 of this
266 %% license or (at your option) any later version.
267 %% The latest version of this license is in:
268 %%
269 %% http://www.latex-project.org/lppl.txt
270 %%
271 %% and version 1.3 or later is part of all distributions of LaTeX
272 %% version 2005/12/01 or later.
273 %%
274 %% This work is "maintained" (as per LPPL maintenance status) by
275 %% Andrew Stacey.
276 %%
277 %% This work consists of the files hobby_code.dtx
278 %% hobby.tex
279 %% and the derived files hobby.code.tex
280 %% pgflibraryhobby.code.tex
281 %% tikzlibraryhobby.code.tex
282 %% pml3array.sty
283 %% hobby-l3draw.sty
284 %% hobby.ins
285 %% hobby.pdf
286 %% hobby_code.pdf
287 %% README.txt
288 %%
289 %%
290 %% End of file `pgflibraryhobby.code.tex'.