%%
%% This is file `tikzlibraryhobby.code.tex',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% hobby.dtx  (with options: `tikzlibrary')
%% ----------------------------------------------------------------
%% hobby --- a TikZ/PGF library for drawing smooth(ish) curves using
%%           Hobby's algorithm (implemented in LaTeX3)
%% E-mail: stacey@math.ntnu.no
%% Released under the LaTeX Project Public License v1.3c or later
%% See http://www.latex-project.org/lppl.txt
%% ----------------------------------------------------------------
%% 
\usepgflibrary{hobby}
\let\hobby@this@opts=\pgfutil@empty
\let\hobby@next@opts=\pgfutil@empty
\let\hobby@action=\pgfutil@empty
\let\hobby@path@name=\pgfutil@empty
\newif\ifhobby@externalise
\def\hobby@point@options{}%
\tikzset{
  curve through/.style={
    to path={
      \pgfextra{
        \expandafter\curvethrough\expandafter[\hobby@next@opts]{%
          (\tikztostart) .. #1 .. (\tikztotarget)%
        }
      }
    }
  },
  tension in/.code = {%
    \expandafter\gdef\expandafter\hobby@point@options\expandafter%
    {\hobby@point@options,tension in=#1}%
  },
  tension out/.code = {%
    \expandafter\gdef\expandafter\hobby@point@options\expandafter%
    {\hobby@point@options,tension out=#1}%
  },
  tension/.code = {%
    \expandafter\gdef\expandafter\hobby@point@options\expandafter%
    {\hobby@point@options,tension=#1}%
  },
  excess angle/.code = {%
    \expandafter\gdef\expandafter\hobby@point@options\expandafter%
    {\hobby@point@options,excess angle=#1}%
  },
  break/.code = {%
    \expandafter\gdef\expandafter\hobby@point@options\expandafter%
    {\hobby@point@options,break=#1}%
  },
  blank/.code = {%
    \expandafter\gdef\expandafter\hobby@point@options\expandafter%
    {\hobby@point@options,blank=#1}%
  },
  designated Hobby path/.initial={next},
  clear next Hobby path options/.code={%
    \gdef\hobby@next@opts{}%
  },
  clear this Hobby path options/.code={%
    \gdef\hobby@this@opts{}%
  },
  clear Hobby path options/.style={%
    clear \pgfkeysvalueof{/tikz/designated Hobby path} Hobby path options
  },
  add option to this Hobby path/.code={%
    \expandafter\gdef\expandafter\hobby@this@opts\expandafter{\hobby@this@opts#1,}%
  },
  add option to next Hobby path/.code={%
    \expandafter\gdef\expandafter\hobby@next@opts\expandafter{\hobby@next@opts#1,}%
  },
  add option to Hobby path/.style={%
    add option to \pgfkeysvalueof{/tikz/designated Hobby path} Hobby path={#1}%
  },
  closed/.style = {%
    add option to Hobby path={closed=#1,disjoint=#1}%
  },
  invert blank/.style = {%
    add option to Hobby path={invert blank=#1}%
  },
  closed/.default = true,
  blank/.default = true,
  break/.default = true,
  invert blank/.default = true,
  in angle/.code = {%
    \pgfmathparse{#1*pi/180}%
    \edef\@temp{in angle=\pgfmathresult,}%
    \pgfkeysalso{add option to Hobby path/.expand once=\@temp}%
  },
  out angle/.code = {%
    \pgfmathparse{#1*pi/180}%
    \edef\@temp{out angle=\pgfmathresult,}%
    \pgfkeysalso{add option to Hobby path/.expand once=\@temp}%
  },
  in curl/.style = {%
    add option to Hobby path={in curl=#1}%
  },
  out curl/.code = {%
    add option to Hobby path={out curl=#1}%
  },
  use Hobby shortcut/.code={%
    \let\tikz@curveto@auto=\hobby@curveto@override
    \global\let\hobby@curveto@delegate=\hobby@curveto@auto
  },
  use quick Hobby shortcut/.code={%
    \let\tikz@curveto@auto=\hobby@curveto@override
    \global\let\hobby@curveto@delegate=\hobby@qcurveto@auto
  },
  use previous Hobby path/.code={%
    \pgfextra{\hobbyusepath{#1}}
  },
  use previous Hobby path/.default={},%
  save Hobby path/.code={%
    \xdef\hobby@path@name{#1}%
  },
  restore Hobby path/.code={%
    \pgfextra{%
      \hobbyinit\hobby@moveto\hobby@curveto\hobby@close
      \hobbyrestorepath{#1}}
  },
  restore and use Hobby path/.code 2 args={%
    \pgfextra{%
      \hobbyinit\hobby@moveto\hobby@curveto\hobby@close
      \hobbyrestorepath{#1}%
      \hobbyusepath{#2}%
    }
  },
  show Hobby path/.code={%
    \pgfextra{\hobbyshowpath{#1}}
  },
  Hobby action/.code={%
    \expandafter\gdef\expandafter\hobby@action\expandafter{\hobby@action#1}%
  },
  Hobby finish/.style={%
    Hobby action=\hobby@finish%
  },
  Hobby externalise/.is if=hobby@externalise,
  Hobby externalize/.is if=hobby@externalise
}
\newcommand\curvethrough[2][]{%
  \hobbyinit\hobby@moveto\hobby@curveto\hobby@close
  \hobbysetparams{#1}%
  \tikzset{designated Hobby path=this}%
  \global\let\hobby@this@opts=\pgfutil@empty
  \global\let\hobby@next@opts=\pgfutil@empty
  \let\tikz@scan@point@options=\pgfutil@empty
  \def\hobby@point@options{}%
  \tikz@scan@one@point\hobby@processpt #2 \relax%
}
\newcommand\hobby@processpt[1]{%
  #1%
  \pgfmathsetmacro\hobby@x{\the\pgf@x/1cm}%
  \pgfmathsetmacro\hobby@y{\the\pgf@y/1cm}%
  \expandafter\hobbyaddpoint\expandafter{\hobby@point@options,%
    x = \hobby@x, y = \hobby@y}%
  \def\hobby@point@options{}%
  \let\tikz@scan@point@options=\pgfutil@empty
  \pgfutil@ifnextchar\relax{%
    \expandafter\hobbysetparams\expandafter{\hobby@this@opts}%
  \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
  }{%
    \pgfutil@ifnextchar.{%
      \hobby@swallowdots}{%
      \tikz@scan@one@point\hobby@processpt}}}
\def\hobby@swallowdots.{%
  \pgfutil@ifnextchar.{%
    \hobby@swallowdots}{%
    \tikz@scan@one@point\hobby@processpt}}
\def\hobby@curveto@override{%
  \hobby@curveto@delegate}
\def\hobby@curveto@auto{%
  \hobbyinit\hobby@moveto\hobby@curveto\hobby@close
  \pgfmathsetmacro\hobby@x{\the\tikz@lastx/1cm}%
  \pgfmathsetmacro\hobby@y{\the\tikz@lasty/1cm}%
  \expandafter\hobbysetparams\expandafter{\hobby@next@opts}%
  \expandafter\hobbyaddpoint\expandafter{\hobby@point@options,%
      x = \hobby@x, y = \hobby@y}%
  \hobby@init@tikz@commands
  \tikzset{designated Hobby path=this}%
  \let\tikz@scan@point@options=\pgfutil@empty
  \global\let\hobby@action=\pgfutil@empty
  \global\let\hobby@this@opts=\pgfutil@empty
  \global\let\hobby@next@opts=\pgfutil@empty
  \global\let\hobby@point@options=\pgfutil@empty
  \tikz@scan@one@point\hobby@addfromtikz}
\def\hobby@addfromtikz#1{%
  #1%
  \tikz@make@last@position{#1}%
  \pgfmathsetmacro\hobby@x{\the\pgf@x/1cm}%
  \pgfmathsetmacro\hobby@y{\the\pgf@y/1cm}%
  \expandafter\hobbysetparams\expandafter{\hobby@this@opts}%
  \expandafter\hobbyaddpoint\expandafter{\hobby@point@options,%
    x = \hobby@x, y = \hobby@y}%
  \hobby@action
  \global\let\hobby@this@opts=\pgfutil@empty
  \global\let\hobby@action=\pgfutil@empty
  \global\let\hobby@point@options=\pgfutil@empty
  \tikz@scan@next@command%
}
\def\hobby@init@tikz@commands{%
  \hobby@init@tikz@modcmd\tikz@movetoabs
  \hobby@init@tikz@modcmd\tikz@movetorel
  \hobby@init@tikz@modcmd\tikz@lineto
  \hobby@init@tikz@modcmd\tikz@rect
  \hobby@init@tikz@modcmd\tikz@cchar
  \hobby@init@tikz@modcmd\tikz@finish
  \hobby@init@tikz@modcmd\tikz@arcA
  \hobby@init@tikz@modcmd\tikz@e@char
  \hobby@init@tikz@modcmd\tikz@g@char
  \hobby@init@tikz@modcmd\tikz@schar
  \hobby@init@tikz@modcmd\tikz@vh@lineto
  \hobby@init@tikz@modcmd\tikz@pchar
  \hobby@init@tikz@modcmd\tikz@to
  \hobby@init@tikz@modcmd\pgf@stop
  \hobby@init@tikz@modcmd\tikz@decoration
  \global\let\hobby@curveto@delegate=\hobby@midcurveto@auto
}
\def\hobby@restore@tikz@commands{%
  \hobby@restore@tikz@modcmd\tikz@movetoabs
  \hobby@restore@tikz@modcmd\tikz@movetorel
  \hobby@restore@tikz@modcmd\tikz@lineto
  \hobby@restore@tikz@modcmd\tikz@rect
  \hobby@restore@tikz@modcmd\tikz@cchar
  \hobby@restore@tikz@modcmd\tikz@finish
  \hobby@restore@tikz@modcmd\tikz@arcA
  \hobby@restore@tikz@modcmd\tikz@e@char
  \hobby@restore@tikz@modcmd\tikz@g@char
  \hobby@restore@tikz@modcmd\tikz@schar
  \hobby@restore@tikz@modcmd\tikz@vh@lineto
  \hobby@restore@tikz@modcmd\tikz@pchar
  \hobby@restore@tikz@modcmd\tikz@to
  \hobby@restore@tikz@modcmd\pgf@stop
  \hobby@restore@tikz@modcmd\tikz@decoration
  \global\let\hobby@curveto@delegate=\hobby@curveto@auto
}
\def\hobby@init@tikz@modcmd#1{%
    \expandafter\global\expandafter\let\csname hobby@orig@\string#1\endcsname=#1%
    \gdef#1{\hobby@finish#1}%
}
\def\hobby@restore@tikz@modcmd#1{%
    \expandafter\global\expandafter\let\expandafter#1\csname hobby@orig@\string#1\endcsname%
}
\def\hobby@midcurveto@auto{%
  \let\tikz@scan@point@options=\pgfutil@empty
  \global\let\hobby@action=\pgfutil@empty
  \global\let\hobby@this@opts=\pgfutil@empty
  \global\let\hobby@point@options=\pgfutil@empty
  \tikz@scan@one@point\hobby@addfromtikz%
}
\def\hobby@finish{%
  \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
  \hobby@restore@tikz@commands
}
\tikzset{
  quick curve through/.style={%
    to path={%
      \pgfextra{%
        \let\hobby@next@qbreak=\relax
        \let\hobby@next@qblank=\relax
      \tikz@scan@one@point\pgfutil@firstofone(\tikztostart)%
        \tikz@make@last@position{\pgfqpoint{\the\pgf@x}{\the\pgf@y}}%
        \edef\hobby@qpoints{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}%
        \def\hobby@qpointa{}%
        \def\hobby@quick@path{}%
        \def\hobby@angle{}%
        \let\hobby@quick@curveto=\hobby@quick@makepath
        \tikz@scan@one@point\hobby@quickfirst #1 (\tikztotarget)\relax
      }
      \hobby@quick@path
    }
  },
  quick hobby/blank curve/.is choice,
  quick hobby/blank curve/true/.code={%
    \gdef\hobby@next@qblank{%
      \qhobby@blanktrue
      \global\let\hobby@next@qblank=\relax
    }%
  },
  quick hobby/blank curve/false/.code={%
    \gdef\hobby@next@qblank{%
      \qhobby@blankfalse
      \global\let\hobby@next@qblank=\relax
    }%
  },
  quick hobby/blank curve/once/.code={%
    \gdef\hobby@next@qblank{%
      \qhobby@blanktrue
      \gdef\hobby@next@qblank{%
        \qhobby@blankfalse
        \global\let\hobby@next@qblank=\relax
      }%
    }%
  },
  quick hobby/blank curve/.default=true,
  quick hobby/break curve/.is choice,
  quick hobby/break curve/true/.code={%
    \gdef\hobby@next@qbreak{%
      \qhobby@breaktrue
      \global\let\hobby@next@qbreak=\relax
    }%
  },
  quick hobby/break curve/false/.code={%
    \gdef\hobby@next@qbreak{%
      \qhobby@breakfalse
      \global\let\hobby@next@qbreak=\relax
    }%
  },
  quick hobby/break curve/once/.code={%
    \gdef\hobby@next@qbreak{%
      \qhobby@breaktrue
      \gdef\hobby@next@qbreak{%
        \qhobby@breakfalse
        \global\let\hobby@next@qbreak=\relax
      }%
    }%
  },
  quick hobby/break curve/.default=true,
}
\newif\ifqhobby@break
\newif\ifqhobby@blank
\tikzoption{hobby}[]{\let\tikz@plot@handler=\pgfplothandlerhobby}
\tikzoption{quick hobby}[]{\let\tikz@plot@handler=\pgfplothandlerquickhobby}
\tikzoption{closed hobby}[]{\let\tikz@plot@handler=\pgfplothandlerclosedhobby}
\def\hobby@quickfirst#1{%
  #1%
  \xdef\hobby@qpointa{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}%
  \tikz@make@last@position{\hobby@qpointa}%
  \pgfutil@ifnextchar\relax{%
    \xdef\hobby@quick@path{ -- (\the\pgf@x,\the\pgf@y)}%
  }{%
    \pgfutil@ifnextchar.{%
      \hobby@qswallowdots}{%
    \tikz@scan@one@point\hobby@quick}}}
\def\hobby@qswallowdots.{%
  \pgfutil@ifnextchar.{%
    \hobby@qswallowdots}{%
    \tikz@scan@one@point\hobby@quick}}
\def\hobby@quick#1{%
  \hobby@quick@compute{#1}%
  \tikz@make@last@position{\hobby@qpointa}%
  \pgfutil@ifnextchar\relax{%
    \hobby@quick@computeend%
  }{%
    \pgfutil@ifnextchar.{%
      \hobby@qswallowdots}{%
      \tikz@scan@one@point\hobby@quick}}}
\def\hobby@quick@makepath#1#2#3{%
  #1%
  \pgf@xa=\pgf@x\relax
  \pgf@ya=\pgf@y\relax
  #2%
  \pgf@xb=\pgf@x\relax
  \pgf@yb=\pgf@y\relax
  #3%
  \ifqhobby@blank
  \xdef\hobby@quick@path{\hobby@quick@path (\the\pgf@x,\the\pgf@y)}%
  \else
  \xdef\hobby@quick@path{\hobby@quick@path .. controls%
  (\the\pgf@xa,\the\pgf@ya) and (\the\pgf@xb,\the\pgf@yb) .. (\the\pgf@x,\the\pgf@y) }%
  \fi
  \ifqhobby@break
  \xdef\hobby@quick@path{\hobby@quick@path +(0,0)}%
  \fi
  \hobby@next@qbreak
  \hobby@next@qblank
}
\def\hobby@qcurveto@auto{%
  \global\let\hobby@next@qbreak=\relax
  \global\let\hobby@next@qblank=\relax
  \xdef\hobby@qpoints{\noexpand\pgfqpoint{\the\tikz@lastx}{\the\tikz@lasty}}%
  \gdef\hobby@qpointa{}%
  \gdef\hobby@quick@path{}%
  \gdef\hobby@angle{}%
  \global\let\hobby@quick@curveto=\hobby@quick@makepathauto
  \hobby@qinit@tikz@commands
  \let\tikz@scan@point@options=\pgfutil@empty
  \global\let\hobby@action=\pgfutil@empty
  \global\let\hobby@point@options=\pgfutil@empty
  \tikz@scan@one@point\hobby@qfirst@auto}
\def\hobby@qmidcurveto@auto{%
  \let\tikz@scan@point@options=\pgfutil@empty
  \global\let\hobby@action=\pgfutil@empty
  \global\let\hobby@point@options=\pgfutil@empty
  \tikz@scan@one@point\hobby@qaddfromtikz}
\def\hobby@qfirst@auto#1{%
  #1%
  \xdef\hobby@qpointa{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}%
  \tikz@make@last@position{\hobby@qpointa}%
  \tikz@scan@next@command%
}
\def\hobby@quick@makepathauto#1#2#3{%
  #1%
  \pgf@xa=\pgf@x\relax
  \pgf@ya=\pgf@y\relax
  #2%
  \pgf@xb=\pgf@x\relax
  \pgf@yb=\pgf@y\relax
  #3%
  \ifqhobby@blank
  \edef\hobby@temp{%
    \noexpand\pgfpathmoveto{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}%
  }%
  \hobby@temp
  \else
  \edef\hobby@temp{%
    \noexpand\pgfpathcurveto{\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
  \fi
  \ifqhobby@break
  #3%
  \edef\hobby@temp{%
    \noexpand\pgfpathmoveto{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}%
  }%
  \hobby@temp
  \fi
  \hobby@next@qbreak
  \hobby@next@qblank
}
\def\hobby@qaddfromtikz#1{%
  \hobby@quick@compute{#1}%
  \tikz@make@last@position{\hobby@qpointa}%
  \tikz@scan@next@command%
}
\def\hobby@qinit@tikz@commands{%
  \hobby@qinit@tikz@modcmd\tikz@movetoabs
  \hobby@qinit@tikz@modcmd\tikz@movetorel
  \hobby@qinit@tikz@modcmd\tikz@lineto
  \hobby@qinit@tikz@modcmd\tikz@rect
  \hobby@qinit@tikz@modcmd\tikz@cchar
  \hobby@qinit@tikz@modcmd\tikz@finish
  \hobby@qinit@tikz@modcmd\tikz@arcA
  \hobby@qinit@tikz@modcmd\tikz@e@char
  \hobby@qinit@tikz@modcmd\tikz@g@char
  \hobby@qinit@tikz@modcmd\tikz@schar
  \hobby@qinit@tikz@modcmd\tikz@vh@lineto
  \hobby@qinit@tikz@modcmd\tikz@pchar
  \hobby@qinit@tikz@modcmd\tikz@to
  \hobby@qinit@tikz@modcmd\pgf@stop
  \hobby@qinit@tikz@modcmd\tikz@decoration
  \global\let\hobby@curveto@delegate=\hobby@qmidcurveto@auto
}
\def\hobby@qrestore@tikz@commands{%
  \hobby@restore@tikz@modcmd\tikz@movetoabs
  \hobby@restore@tikz@modcmd\tikz@movetorel
  \hobby@restore@tikz@modcmd\tikz@lineto
  \hobby@restore@tikz@modcmd\tikz@rect
  \hobby@restore@tikz@modcmd\tikz@cchar
  \hobby@restore@tikz@modcmd\tikz@finish
  \hobby@restore@tikz@modcmd\tikz@arcA
  \hobby@restore@tikz@modcmd\tikz@e@char
  \hobby@restore@tikz@modcmd\tikz@g@char
  \hobby@restore@tikz@modcmd\tikz@schar
  \hobby@restore@tikz@modcmd\tikz@vh@lineto
  \hobby@restore@tikz@modcmd\tikz@pchar
  \hobby@restore@tikz@modcmd\tikz@to
  \hobby@restore@tikz@modcmd\pgf@stop
  \hobby@restore@tikz@modcmd\tikz@decoration
  \hobby@restore@tikz@modcmd\tikz@@close
  \global\let\hobby@curveto@delegate=\hobby@qcurveto@auto
}
\def\hobby@qinit@tikz@modcmd#1{%
    \expandafter\global\expandafter\let\csname hobby@orig@\string#1\endcsname=#1%
    \gdef#1{\hobby@qfinish#1}%
}
\def\hobby@qfinish{%
  \hobby@quick@computeend
  \hobby@qrestore@tikz@commands
}

%% 
%% Copyright (C) 2012 by Andrew Stacey <stacey@math.ntnu.no>
%% 
%% 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.dtx
%%                                  hobby_doc.tex
%% and the derived files            hobby.code.tex
%%                                  pgflibraryhobby.code.tex
%%                                  tikzlibraryhobby.code.tex
%%                                  hobby.ins
%%                                  hobby.pdf
%%                                  hobby_doc.pdf
%%                                  README.txt
%% 
%%
%% End of file `tikzlibraryhobby.code.tex'.
