% \iffalse
% --------------------------------------------------------------------
%<*hex>
% \fi
% 
% \subsubsection{Ridges}
% \label{sec:impl:hex:ridges}
%
% A hex can be decorated with up to 6 ridges --- one for each edge of
% the hexagon.  The first thing is to set up the graphics style to use
% for the ridges.  We use the \spec{wave} decoration. 
% 
%    \begin{macrocode}
\tikzset{%
  hex/ridges/.style={
    line cap=round,
    draw=pgfstrokecolor,
    rounded corners=.25cm,
    scale line widths,
    decoration={
      path has corners=true,
      pre=waves,
      post=waves,
      pre length=-.1cm,
      post length=0cm,
      waves,
      radius=.2cm,
      segment length=.2cm},
    decorate}}
%    \end{macrocode}
%
% To properly set up the ridges, we need to concatenate ridge paths in
% order.  To facilitate that, we define 6 \cs{if}s --- one for each
% edge.
% 
%    \begin{macrocode}
\newif\ifhex@r@ne
\newif\ifhex@r@n
\newif\ifhex@r@nw
\newif\ifhex@r@sw
\newif\ifhex@r@s
\newif\ifhex@r@se
%    \end{macrocode}
%
% Next is the keys for each edge.  These will set the above \cs{if}s
% to \spec{true}.  We put these into the family \spec{/hex/r} so that
% we can parse them separately. 
% 
%    \begin{macrocode}
\tikzset{%
  /hex/ridges/.search also={/tikz},
  /hex/ridges/.cd,
  north east/.is if=hex@r@ne,
  north/.is if=hex@r@n,
  north west/.is if=hex@r@nw,
  south west/.is if=hex@r@sw,
  south/.is if=hex@r@s,
  south east/.is if=hex@r@se,
  radius/.store in=\hex@r@r,
  NE/.is if=hex@r@ne,
  N/.is if=hex@r@n,
  NW/.is if=hex@r@nw,
  SW/.is if=hex@r@sw,
  S/.is if=hex@r@s,
  SE/.is if=hex@r@se,
  r/.store in=\hex@r@r,
}
%    \end{macrocode}
%
% \begin{Macro}{\hex@do@ridges}
%
%   This is the macro that actually generates the ridge.  We use the
%   same \textsc{pgf} filtered key parsing trick as above.   Note that
%   the routine below is handcrafted since it is relatively simple.
%   
%    \begin{macrocode}
\def\hex@do@ridges{%
  \edef\hex@r@tmp{[
    /hex/ridges/.cd,%
    radius=0.8,%
    /tikz/every hex ridges/.try,
    \hex@ridges]}
  \expandafter\scope\hex@r@tmp%
    \hex@dbg{3}{Ridges: `\meaning\hex@ridges', `\meaning\hex@r@tmp'
      ^^Jnorth east=\ifhex@r@ne yes\else no\fi
      ^^Jnorth     =\ifhex@r@n  yes\else no\fi
      ^^Jnorth west=\ifhex@r@nw yes\else no\fi
      ^^Jsouth west=\ifhex@r@sw yes\else no\fi
      ^^Jsouth     =\ifhex@r@s  yes\else no\fi
      ^^Jsouth east=\ifhex@r@se yes\else no\fi
      ^^Jradius    =\hex@r@r
    }
    \def\hex@r@p{}
    % Hand written algorithm
    \ifhex@r@ne
      \def\hex@r@p{(0:\hex@r@r)--(60:\hex@r@r)}
    \fi
    \ifhex@r@n
      \hex@dbg{4}{Ridge along north edge: `\hex@r@p'}
      \ifhex@r@ne\else
        \xdef\hex@r@p{\hex@r@p ( 60:\hex@r@r)}
      \fi
      \xdef\hex@r@p{\hex@r@p --(120:\hex@r@r)}
    \fi
    \ifhex@r@nw
      \ifhex@r@n\else
        \xdef\hex@r@p{\hex@r@p (120:\hex@r@r)}
      \fi
      \xdef\hex@r@p{\hex@r@p --(180:\hex@r@r)}
    \fi
    \ifhex@r@sw
      \ifhex@r@nw\else
        \xdef\hex@r@p{\hex@r@p (180:\hex@r@r)}
      \fi
      \xdef\hex@r@p{\hex@r@p --(240:\hex@r@r)}
    \fi
    \ifhex@r@s
      \ifhex@r@sw\else
        \xdef\hex@r@p{\hex@r@p (240:\hex@r@r)}
      \fi
      \xdef\hex@r@p{\hex@r@p --(300:\hex@r@r)}
    \fi
    \ifhex@r@se
      \ifhex@r@s\else
        \xdef\hex@r@p{\hex@r@p (300:\hex@r@r)}
      \fi
      \xdef\hex@r@p{\hex@r@p --(360:\hex@r@r)}
    \fi
    \hex@dbg{3}{ Ridges path: \hex@r@p}
    \draw[hex/ridges] \hex@r@p;
  \endscope% End of ridges scope 
}
%    \end{macrocode}
% \end{Macro}
% 
% \iffalse
%</hex>
% --------------------------------------------------------------------
% \fi 
