%%
%% This is file `pgflibraryhobby.code.tex',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% hobby_code.dtx  (with options: `pgflibrary')
%% ----------------------------------------------------------------
%% hobby --- a TikZ/PGF library for drawing smooth(ish) curves using
%%           Hobby's algorithm (implemented in LaTeX3)
%% E-mail: loopspace@mathforge.org
%% Released under the LaTeX Project Public License v1.3c or later
%% See http://www.latex-project.org/lppl.txt
%% ----------------------------------------------------------------
%% 
\input{hobby.code.tex}
\pgfkeys{
  /pgf/hobby/.is family,
  /pgf/hobby/.cd,
  point/.code={%
    \hobby@parse@pt#1\relax}
}
\def\hobby@parse@pt#1,#2\relax{%
  \pgf@x=#1cm\relax
  \pgf@y=#2cm\relax
}
\pgfmathparse{atan2(0,1)}
\def\hobby@temp{0.0}
\ifx\pgfmathresult\hobby@temp
  \pgfmathdeclarefunction{hobbyatan2}{2}{%
    \pgfmathatantwo@{#1}{#2}%
  }
\else
  \pgfmathdeclarefunction{hobbyatan2}{2}{%
    \pgfmathatantwo@{#2}{#1}%
  }
\fi
\def\hobby@curveto#1#2#3{%
  \pgfpathcurveto{\hobby@topgf{#1}}{\hobby@topgf{#2}}{\hobby@topgf{#3}}%
}
\def\hobby@moveto#1#2#3{%
  \pgfpathmoveto{\hobby@topgf{#3}}%
}
\def\hobby@topgf#1{%
    \pgfqkeys{/pgf/hobby}{point={#1}}%
}
\def\hobby@close#1{%
  \pgfpathclose
}
\def\pgfpathhobby{%
  \pgfutil@ifnextchar\bgroup{\pgfpath@hobby}{\pgfpath@hobby{}}}
\def\pgfpath@hobby#1{%
  \hobbyinit\hobby@moveto\hobby@curveto\hobby@close
  \hobbysetparams{#1}%
  \pgfmathsetmacro\hobby@x{\the\pgf@path@lastx/1cm}%
  \pgfmathsetmacro\hobby@y{\the\pgf@path@lasty/1cm}%
  \hobbyaddpoint{point={\hobby@x, \hobby@y}}%
}
\def\pgfpathhobbypt#1{%
  #1%
  \pgfmathsetmacro\hobby@x{\the\pgf@x/1cm}%
  \pgfmathsetmacro\hobby@y{\the\pgf@y/1cm}%
  \pgfutil@ifnextchar\bgroup{\pgfpathhobbyptparams}{\pgfpathhobbyptparams{}}%
}
\def\pgfpathhobbyptparams#1{%
  \hobbyaddpoint{#1,point={\hobby@x, \hobby@y}}%
}
\def\pgfpathhobbyend{%
  \ifhobby@externalise
    \ifx\hobby@path@name\pgfutil@empty
      \hobbygenusepath
    \else
      \hobbygenuseifnecpath{\hobby@path@name}%
    \fi
  \else
    \hobbygenusepath
  \fi
  \ifx\hobby@path@name\pgfutil@empty
  \else
    \hobbysavepath{\hobby@path@name}%
  \fi
  \global\let\hobby@path@name=\pgfutil@empty
}
\def\pgfplothandlerhobby{%
  \def\pgf@plotstreamstart{%
    \hobbyinit\hobby@moveto\hobby@curveto\hobby@close
    \global\let\pgf@plotstreampoint=\pgf@plot@hobby@firstpt
    \global\let\pgf@plotstreamspecial=\pgfutil@gobble
    \gdef\pgf@plotstreamend{%
      \ifhobby@externalise
       \ifx\hobby@path@name\pgfutil@empty
        \hobbygenusepath
       \else
        \hobbygenuseifnecpath{\hobby@path@name}%
       \fi
      \else
       \hobbygenusepath
      \fi
      \ifx\hobby@path@name\pgfutil@empty
      \else
       \hobbysavepath{\hobby@path@name}%
      \fi
      \global\let\hobby@path@name=\pgfutil@empty
    }%
    \let\tikz@scan@point@options=\pgfutil@empty
  }
}
\def\pgfplothandlerclosedhobby{%
  \def\pgf@plotstreamstart{%
    \hobbyinit\hobby@moveto\hobby@curveto\hobby@close
    \hobbysetparams{closed=true,disjoint=true}%
    \global\let\pgf@plotstreampoint=\pgf@plot@hobby@firstpt
    \global\let\pgf@plotstreamspecial=\pgfutil@gobble
    \gdef\pgf@plotstreamend{%
      \ifhobby@externalise
       \ifx\hobby@path@name\pgfutil@empty
        \hobbygenusepath
       \else
        \hobbygenuseifnecpath{\hobby@path@name}%
       \fi
      \else
       \hobbygenusepath
      \fi
      \ifx\hobby@path@name\pgfutil@empty
      \else
       \hobbysavepath{\hobby@path@name}%
      \fi
      \global\let\hobby@path@name=\pgfutil@empty
    }%
  }
}
\def\pgf@plot@hobby@firstpt#1{%
  \pgf@plot@first@action{#1}%
  \pgf@plot@hobby@handler{#1}%
  \global\let\pgf@plotstreampoint=\pgf@plot@hobby@handler
}
\def\pgf@plot@hobby@handler#1{%
    #1%
    \pgfmathsetmacro\hobby@x{\the\pgf@x/1cm}%
    \pgfmathsetmacro\hobby@y{\the\pgf@y/1cm}%
    \hobbyaddpoint{point={\hobby@x, \hobby@y}}%
  }
\def\pgfplothandlerquickhobby{%
  \def\pgf@plotstreamstart{%
    \global\let\hobby@quick@curveto=\pgfpathcurveto
    \global\let\pgf@plotstreampoint=\pgf@plot@qhobby@firstpt
    \global\let\pgf@plotstreamspecial=\pgfutil@gobble
    \global\let\pgf@plotstreamend=\pgf@plot@qhobby@end
  }
}
\def\pgf@plot@qhobby@firstpt#1{%
  #1%
  \edef\hobby@temp{\noexpand\pgf@plot@first@action{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}}\hobby@temp%
  \xdef\hobby@qpoints{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}%
  \gdef\hobby@qpointa{}%
  \gdef\hobby@angle{}%
  \global\let\pgf@plotstreampoint=\pgf@plot@qhobby@secondpt
}
\def\pgf@plot@qhobby@secondpt#1{%
  #1%
  \xdef\hobby@qpointa{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}%
  \global\let\pgf@plotstreampoint=\pgf@plot@qhobby@handler
}
\def\pgf@plot@qhobby@handler#1{%
  #1
  \edef\hobby@temp{\noexpand\hobby@quick@compute{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}}\hobby@temp
  \global\let\hobby@qpointa=\hobby@qpointa
  \global\let\hobby@qpoints=\hobby@qpoints
  \global\let\hobby@angle=\hobby@angle
  \global\let\hobby@thetaone=\hobby@thetaone
  \global\let\hobby@phitwo=\hobby@phitwo
  \global\let\hobby@done=\hobby@done
  \global\let\hobby@omegaone=\hobby@omegaone
}
\def\pgf@plot@qhobby@end{%
  \hobby@quick@computeend
}
\pgfmathsetmacro\hobby@sf{10cm}
\def\hobby@quick@compute#1{%
  #1%
  \pgf@xb=\pgf@x
  \pgf@yb=\pgf@y
  \hobby@qpointa
  \pgf@xa=\pgf@x
  \pgf@ya=\pgf@y
  \advance\pgf@xb by -\pgf@xa
  \advance\pgf@yb by -\pgf@ya
  \pgfmathsetmacro\hobby@done{sqrt((\pgf@xb/\hobby@sf)^2 + (\pgf@yb/\hobby@sf)^2)}%
  \pgfmathsetmacro\hobby@omegaone{rad(hobbyatan2(\pgf@yb,\pgf@xb))}%
  \hobby@qpoints
  \advance\pgf@xa by -\pgf@x
  \advance\pgf@ya by -\pgf@y
  \pgfmathsetmacro\hobby@dzero{sqrt((\pgf@xa/\hobby@sf)^2 + (\pgf@ya/\hobby@sf)^2)}%
  \pgfmathsetmacro\hobby@omegazero{rad(hobbyatan2(\pgf@ya,\pgf@xa))}%
  \pgfmathsetmacro\hobby@psi{\hobby@omegaone - \hobby@omegazero}%
  \pgfmathsetmacro\hobby@psi{\hobby@psi > pi ? \hobby@psi - 2*pi : \hobby@psi}%
  \pgfmathsetmacro\hobby@psi{\hobby@psi < -pi ? \hobby@psi + 2*pi : \hobby@psi}%
  \ifx\hobby@angle\pgfutil@empty
  \pgfmathsetmacro\hobby@thetaone{-\hobby@psi * \hobby@done%
/(\hobby@done + \hobby@dzero)}%
  \pgfmathsetmacro\hobby@thetazero{-\hobby@psi - \hobby@thetaone}%
  \let\hobby@phione=\hobby@thetazero
  \let\hobby@phitwo=\hobby@thetaone
  \else
  \let\hobby@thetazero=\hobby@angle
  \pgfmathsetmacro\hobby@thetaone{%
  -(2 * \hobby@psi + \hobby@thetazero) * \hobby@done%
  / (2 * \hobby@done + \hobby@dzero)}%
  \pgfmathsetmacro\hobby@phione{-\hobby@psi - \hobby@thetaone}%
  \let\hobby@phitwo=\hobby@thetaone
  \fi
  \let\hobby@angle=\hobby@thetaone
  \hobby@quick@ctrlpts{\hobby@thetazero}{\hobby@phione}{\hobby@qpoints}{\hobby@qpointa}{\hobby@dzero}{\hobby@omegazero}%
  \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}}}%
\hobby@temp
  \global\let\hobby@qpoints=\hobby@qpointa
  #1
  \xdef\hobby@qpointa{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}%
  \global\let\hobby@angle=\hobby@angle
  \global\let\hobby@phitwo=\hobby@phitwo
  \global\let\hobby@thetaone=\hobby@thetaone
\global\let\hobby@done=\hobby@done
\global\let\hobby@omegaone=\hobby@omegaone
}
\def\hobby@quick@computeend{%
  \hobby@quick@ctrlpts{\hobby@thetaone}{\hobby@phitwo}{\hobby@qpoints}{\hobby@qpointa}{\hobby@done}{\hobby@omegaone}%
  \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}}}%
\hobby@temp
}%
\def\hobby@quick@ctrlpts#1#2#3#4#5#6{%
  \pgfmathsetmacro\hobby@alpha{%
    sqrt(2) * (sin(#1 r) - 1/16 * sin(#2 r))%
* (sin(#2 r) - 1/16 * sin(#1 r))%
 * (cos(#1 r) - cos(#2 r))}%
  \pgfmathsetmacro\hobby@rho{%
    (2 + \hobby@alpha)/(1 + (1 - (3 - sqrt(5))/2)%
 * cos(#1 r) + (3 - sqrt(5))/2 * cos(#2 r))}%
  \pgfmathsetmacro\hobby@sigma{%
    (2 - \hobby@alpha)/(1 + (1 - (3 - sqrt(5))/2)%
  * cos(#2 r) +  (3 - sqrt(5))/2 * cos(#1 r))}%
  #3%
  \pgf@xa=\pgf@x
  \pgf@ya=\pgf@y
  \pgfmathsetlength\pgf@xa{%
    \pgf@xa + #5 * \hobby@rho%
  * cos((#1 + #6) r)/3*\hobby@sf}%
  \pgfmathsetlength\pgf@ya{%
    \pgf@ya + #5 * \hobby@rho%
  * sin((#1 + #6) r)/3*\hobby@sf}%
  #4%
  \pgf@xb=\pgf@x
  \pgf@yb=\pgf@y
  \pgfmathsetlength\pgf@xb{%
    \pgf@xb - #5 * \hobby@sigma%
  * cos((-#2 + #6) r)/3*\hobby@sf}%
  \pgfmathsetlength\pgf@yb{%
    \pgf@yb - #5 * \hobby@sigma%
  * sin((-#2 + #6) r)/3*\hobby@sf}%
  #4%
}
%% 
%% Copyright (C) 2012-2021 by Andrew Stacey <loopspace@mathforge.org>
%% 
%% This file may be distributed and/or modified under the conditions
%% of the LaTeX Project Public License, either version 1.3 of this
%% license or (at your option) any later version.
%% The latest version of this license is in:
%% 
%%    http://www.latex-project.org/lppl.txt
%% 
%% and version 1.3 or later is part of all distributions of LaTeX
%% version 2005/12/01 or later.
%% 
%% This work is "maintained" (as per LPPL maintenance status) by
%% Andrew Stacey.
%% 
%% This work consists of the files  hobby_code.dtx
%%                                  hobby.tex
%% and the derived files            hobby.code.tex
%%                                  pgflibraryhobby.code.tex
%%                                  tikzlibraryhobby.code.tex
%%                                  pml3array.sty
%%                                  hobby-l3draw.sty
%%                                  hobby.ins
%%                                  hobby.pdf
%%                                  hobby_code.pdf
%%                                  README.txt
%% 
%%
%% End of file `pgflibraryhobby.code.tex'.
