% Copyright 2006 by Till Tantau
%
% This file may be distributed and/or modified
%
% 1. under the LaTeX Project Public License and/or
% 2. under the GNU Public License.
%
% See the file doc/generic/pgf/licenses/LICENSE for more details.

\ProvidesFileRCS[v\pgfversion] $Header: /cvsroot/pgf/pgf/generic/pgf/libraries/pgflibraryshapes.code.tex,v 1.9 2006/10/11 15:22:26 tantau Exp $

\pgfdeclareshape{ellipse}
%
% Draws a circle around the text
%
{
  \savedanchor\centerpoint{%
    \pgf@x=.5\wd\pgfnodeparttextbox%
    \pgf@y=.5\ht\pgfnodeparttextbox%
    \advance\pgf@y by-.5\dp\pgfnodeparttextbox%
  }
  \savedanchor\radius{%
    % 
    % Caculate ``height radius''
    % 
    \pgf@y=.5\ht\pgfnodeparttextbox%
    \advance\pgf@y by.5\dp\pgfnodeparttextbox%
    \setlength\pgf@yb{\pgfshapeinnerysep}%
    \advance\pgf@y by\pgf@yb%
    % 
    % Caculate ``width radius''
    % 
    \pgf@x=.5\wd\pgfnodeparttextbox%
    \setlength\pgf@xb{\pgfshapeinnerxsep}%
    \advance\pgf@x by\pgf@xb%
    % 
    % Adjust
    % 
    \pgf@x=1.4142136\pgf@x%
    \pgf@y=1.4142136\pgf@y%
    % 
    % Adjust hieght, if necessary
    % 
    \setlength\pgf@yc{\pgfshapeminheight}%
    \ifdim\pgf@y<.5\pgf@yc%
      \pgf@y=.5\pgf@yc%
    \fi%
    % 
    % Adjust width, if necessary
    % 
    \setlength\pgf@xc{\pgfshapeminwidth}%
    \ifdim\pgf@x<.5\pgf@xc%
      \pgf@x=.5\pgf@xc%
    \fi%
    % 
    % Add outer sep
    % 
    \setlength{\pgf@xb}{\pgfshapeouterxsep}%  
    \setlength{\pgf@yb}{\pgfshapeouterysep}%  
    \advance\pgf@x by\pgf@xb%
    \advance\pgf@y by\pgf@yb%
  }

  %
  % Anchors
  % 
  \anchor{center}{\centerpoint}
  \anchor{mid}{\centerpoint\setlength\pgf@y{.5ex}}
  \anchor{base}{\centerpoint\pgf@y=0pt}
  \anchor{north}
  {
    \pgf@process{\radius}
    \pgf@ya=\pgf@y%
    \pgf@process{\centerpoint}
    \advance\pgf@y by\pgf@ya
  }
  \anchor{south}
  {
    \pgf@process{\radius}
    \pgf@ya=\pgf@y%
    \pgf@process{\centerpoint}
    \advance\pgf@y by-\pgf@ya
  }
  \anchor{west}
  {
    \pgf@process{\radius}
    \pgf@xa=\pgf@x%
    \pgf@process{\centerpoint}
    \advance\pgf@x by-\pgf@xa
  }
  \anchor{mid west}
  {%
    \pgf@process{\radius}
    \pgf@xa=\pgf@x%
    \pgf@process{\centerpoint}
    \advance\pgf@x by-\pgf@xa%
    \setlength\pgf@y{.5ex}
  }
  \anchor{base west}
  {%
    \pgf@process{\radius}
    \pgf@xa=\pgf@x%
    \pgf@process{\centerpoint}
    \advance\pgf@x by-\pgf@xa%
    \pgf@y=0pt
  }
  \anchor{north west}
  {
    \pgf@process{\radius}
    \pgf@xa=\pgf@x%
    \pgf@ya=\pgf@y%
    \pgf@process{\centerpoint}
    \advance\pgf@x by-0.707107\pgf@xa
    \advance\pgf@y by0.707107\pgf@ya
  }
  \anchor{south west}
  {
    \pgf@process{\radius}
    \pgf@xa=\pgf@x%
    \pgf@ya=\pgf@y%
    \pgf@process{\centerpoint}
    \advance\pgf@x by-0.707107\pgf@xa
    \advance\pgf@y by-0.707107\pgf@ya
  }
  \anchor{east}
  {%
    \pgf@process{\radius}
    \pgf@xa=\pgf@x%
    \pgf@process{\centerpoint}
    \advance\pgf@x by\pgf@xa
  }
  \anchor{mid east}
  {%
    \pgf@process{\radius}
    \pgf@xa=\pgf@x%
    \pgf@process{\centerpoint}
    \advance\pgf@x by\pgf@xa%
    \setlength\pgf@y{.5ex}
  }
  \anchor{base east}
  {%
    \pgf@process{\radius}
    \pgf@xa=\pgf@x%
    \pgf@process{\centerpoint}
    \advance\pgf@x by\pgf@xa%
    \pgf@y=0pt
  }
  \anchor{north east}
  {
    \pgf@process{\radius}
    \pgf@xa=\pgf@x%
    \pgf@ya=\pgf@y%
    \pgf@process{\centerpoint}
    \advance\pgf@x by0.707107\pgf@xa
    \advance\pgf@y by0.707107\pgf@ya
  }
  \anchor{south east}
  {
    \pgf@process{\radius}
    \pgf@xa=\pgf@x%
    \pgf@ya=\pgf@y%
    \pgf@process{\centerpoint}
    \advance\pgf@x by0.707107\pgf@xa
    \advance\pgf@y by-0.707107\pgf@ya
  }
  \anchorborder{
    \edef\pgf@marshal{%
      \noexpand\pgfpointborderellipse
      {\noexpand\pgfpoint{\the\pgf@x}{\the\pgf@y}}
      {\noexpand\radius}%
    }%
    \pgf@marshal%
    \pgf@xa=\pgf@x%
    \pgf@ya=\pgf@y%
    \centerpoint%
    \advance\pgf@x by\pgf@xa%
    \advance\pgf@y by\pgf@ya%
  }

  %
  % Background path
  %
  \backgroundpath
  {
    \pgf@process{\radius}%
    \@tempdima=\pgf@x%
    \@tempdimb=\pgf@y%
    \setlength{\pgf@xb}{\pgfshapeouterxsep}%  
    \setlength{\pgf@yb}{\pgfshapeouterysep}%  
    \advance\@tempdima by-\pgf@xb%
    \advance\@tempdimb by-\pgf@yb%
    \pgfpathellipse{\centerpoint}{\pgfpoint{\@tempdima}{0pt}}{\pgfpoint{0pt}{\@tempdimb}}%
  }
}




% Set the recommended shape aspect ratio
%
% #1 = aspect ratio
%
% Example:
%
% \pgfsetshapeminwidth{1.5}

\def\pgfsetshapeaspect#1{%
  \def\pgfshapeaspect{#1}%
  % Invert
  \@tempdima=#1pt%
  \@tempdima=.125\@tempdima%
  \c@pgf@counta=\@tempdima\relax% 8192*determinant
  \@tempdima=8192pt%
  \divide\@tempdima by\c@pgf@counta%
  \edef\pgfshapeaspectinverse{\pgf@sys@tonumber{\@tempdima}}
}
\pgfsetshapeaspect{1}



\pgfdeclareshape{diamond}
{
  \savedanchor\outernortheast{%
    %
    % Calculate width and height of the inner rectangle
    %
    \pgf@xa=.5\wd\pgfnodeparttextbox%
    \setlength\pgf@xc{\pgfshapeinnerxsep}%
    \advance\pgf@xa by\pgf@xc%
    \pgf@ya=.5\ht\pgfnodeparttextbox%
    \advance\pgf@ya by.5\dp\pgfnodeparttextbox%
    \setlength\pgf@yc{\pgfshapeinnerysep}%
    \advance\pgf@ya by\pgf@yc%
    %
    % Calculate width and height of diamond
    %
    \pgf@x=\pgf@xa%
    \advance\pgf@x by\pgfshapeaspect\pgf@ya%
    \pgf@y=\pgfshapeaspectinverse\pgf@xa%
    \advance\pgf@y by\pgf@ya%
    %
    % Check against minimum height/width
    %
    \setlength\pgf@xb{\pgfshapeminwidth}%
    \ifdim\pgf@x<\pgf@xb%
      % yes, too small. Enlarge...
      \pgf@x=\pgf@xb%
    \fi%
    \setlength\pgf@yb{\pgfshapeminheight}%
    \ifdim\pgf@y<\pgf@yb%
      % yes, too small. Enlarge...
      \pgf@y=\pgf@yb%
    \fi%
    %
    % Add outer border
    %
    \setlength\pgf@xa{\pgfshapeouterxsep}%
    \advance\pgf@x by\pgf@xa%
    \setlength\pgf@ya{\pgfshapeouterysep}%
    \advance\pgf@y by\pgf@ya%
  }
  \savedanchor\text{%
    \pgf@x=-.5\wd\pgfnodeparttextbox%
    \pgf@y=-.5\ht\pgfnodeparttextbox%
    \advance\pgf@y by.5\dp\pgfnodeparttextbox%
  }

  %
  % Anchors
  %
  \anchor{text}{\text}%
  \anchor{center}{\pgfpointorigin}%
  \anchor{mid}{%
    \pgf@process{\text}%
    \pgf@x=0pt%
    \setlength\pgf@ya{.5ex}
    \advance\pgf@y by\pgf@ya%
  }
  \anchor{base}{\pgf@process{\text}\pgf@x=0pt  }
  \anchor{north}{\pgf@process{\outernortheast}\pgf@x=0pt}
  \anchor{south}{\pgf@process{\outernortheast}\pgf@x=0pt\pgf@y=-\pgf@y}
  \anchor{west}{\pgf@process{\outernortheast}\pgf@x=-\pgf@x\pgf@y=0pt}
  \anchor{north west}{\pgf@process{\outernortheast}\pgf@x=-.5\pgf@x\pgf@y=.5\pgf@y}
  \anchor{south west}{\pgf@process{\outernortheast}\pgf@x=-.5\pgf@x\pgf@y=-.5\pgf@y}
  \anchor{east}{\pgf@process{\outernortheast}\pgf@y=0pt}
  \anchor{north east}{\pgf@process{\outernortheast}\pgf@x=.5\pgf@x\pgf@y=.5\pgf@y}
  \anchor{south east}{\pgf@process{\outernortheast}\pgf@x=.5\pgf@x\pgf@y=-.5\pgf@y}
  \anchorborder{%
    \pgf@xa=\pgf@x%
    \pgf@ya=\pgf@y%
    \pgf@process{\outernortheast}%
    \ifdim\pgf@xa>0pt%
    \else%
      \pgf@x=-\pgf@x%
    \fi%
    \ifdim\pgf@ya>0pt%
    \else%
      \pgf@y=-\pgf@y%
    \fi%
    \edef\pgf@marshal{%
      \noexpand\pgfpointintersectionoflines
      {\noexpand\pgfpointorigin}
      {\noexpand\pgfpoint{\the\pgf@xa}{\the\pgf@ya}}
      {\noexpand\pgfpoint{\the\pgf@x}{0pt}}
      {\noexpand\pgfpoint{0pt}{\the\pgf@y}}%
    }%
    \pgf@process{\pgf@marshal}%
  }

  %
  % Background path
  %
  \backgroundpath{
    \pgf@process{\outernortheast}%
    \pgf@xc=\pgf@x%
    \pgf@yc=\pgf@y%
    \setlength{\pgf@xa}{\pgfshapeouterxsep}%
    \setlength{\pgf@ya}{\pgfshapeouterysep}%
    \advance\pgf@xc by-1.414213\pgf@xa%
    \advance\pgf@yc by-1.414213\pgf@ya%
    \pgfpathmoveto{\pgfpoint{\pgf@xc}{0pt}}%
    \pgfpathlineto{\pgfpoint{0pt}{\pgf@yc}}%
    \pgfpathlineto{\pgfpoint{-\pgf@xc}{0pt}}%
    \pgfpathlineto{\pgfpoint{0pt}{-\pgf@yc}}%
    \pgfpathclose%
  }
}



\newbox\pgfnodepartlowerbox

%
% A circle that is split in the middle into an upper and a lower part.
%
% This node consists of two parts: The upper (main) part is shown in
% the upper half of the circle. The second part is the (optional)
% lower part.
%
% Parts: text, lower

\pgfdeclareshape{circle split}
{
  %
  % Node parts
  %
  \nodeparts{text,lower}

  %
  % Anchors
  %
  \savedanchor\centerpoint{%
    \pgf@x=.5\wd\pgfnodeparttextbox%
    \setlength{\pgf@y}{\pgfshapeinnerysep}%
    \pgf@y=-\pgf@y%
    \advance\pgf@y by-\dp\pgfnodeparttextbox%
    \advance\pgf@y by-.5\pgflinewidth%
  }%
  \savedanchor\loweranchor{%
    \pgf@x=-.5\wd\pgfnodepartlowerbox%
    \advance\pgf@x by.5\wd\pgfnodeparttextbox%
    \setlength{\pgf@y}{\pgfshapeinnerysep}%
    \pgf@y=-2\pgf@y%
    \advance\pgf@y by-\ht\pgfnodepartlowerbox%
    \advance\pgf@y by-.5\pgflinewidth%
    \advance\pgf@y by-\dp\pgfnodeparttextbox%
    \advance\pgf@y by-.5\pgflinewidth%
  }
    
  \saveddimen\radius{%
    % 
    % Caculate ``height radius''
    % 
    \pgf@ya=.5\ht\pgfnodeparttextbox%
    \advance\pgf@ya by.5\dp\pgfnodeparttextbox%
    \advance\pgf@ya by.5\ht\pgfnodepartlowerbox%
    \advance\pgf@ya by.5\dp\pgfnodepartlowerbox%
    \advance\pgf@ya by.5\pgflinewidth%
    \setlength\pgf@yb{\pgfshapeinnerysep}%
    \advance\pgf@ya by2\pgf@yb%
    % 
    % Caculate ``width radius''
    % 
    \pgf@xa=.5\wd\pgfnodeparttextbox%
    \ifdim\pgf@xa<.5\wd\pgfnodepartlowerbox%
      \pgf@xa=.5\wd\pgfnodepartlowerbox%
    \fi%
    \setlength\pgf@xb{\pgfshapeinnerxsep}%
    \advance\pgf@xa by\pgf@xb%
    % 
    % Calculate length of radius vector:
    % 
    \pgf@process{\pgfpointnormalised{\pgfpoint{\pgf@xa}{\pgf@ya}}}%
    \ifdim\pgf@x>\pgf@y%
        \c@pgf@counta=\pgf@x%
        \ifnum\c@pgf@counta=0\relax%
        \else%
          \divide\c@pgf@counta by 255\relax%
          \pgf@xa=16\pgf@xa\relax%
          \divide\pgf@xa by\c@pgf@counta%
          \pgf@xa=16\pgf@xa\relax%
        \fi%
      \else%
        \c@pgf@counta=\pgf@y%
        \ifnum\c@pgf@counta=0\relax%
        \else%
          \divide\c@pgf@counta by 255\relax%
          \pgf@ya=16\pgf@ya\relax%
          \divide\pgf@ya by\c@pgf@counta%
          \pgf@xa=16\pgf@ya\relax%
        \fi%
    \fi%
    \pgf@x=\pgf@xa%
    % 
    % If necessary, adjust radius so that the size requirements are
    % met: 
    % 
    \setlength{\pgf@xb}{\pgfshapeminwidth}%  
    \setlength{\pgf@yb}{\pgfshapeminheight}%  
    \ifdim\pgf@x<.5\pgf@xb%
        \pgf@x=.5\pgf@xb%
    \fi%
    \ifdim\pgf@x<.5\pgf@yb%
        \pgf@x=.5\pgf@yb%
    \fi%
    % 
    % Now, add larger of outer sepearations.
    % 
    \setlength{\pgf@xb}{\pgfshapeouterxsep}%  
    \setlength{\pgf@yb}{\pgfshapeouterysep}%  
    \ifdim\pgf@xb<\pgf@yb%
      \advance\pgf@x by\pgf@yb%
    \else%
      \advance\pgf@x by\pgf@xb%
    \fi%
  }

  %
  % Anchors
  % 
  \inheritanchorborder[from=circle]
  \inheritanchor[from=circle]{north}
  \inheritanchor[from=circle]{north west}
  \inheritanchor[from=circle]{north east}
  \inheritanchor[from=circle]{center}
  \inheritanchor[from=circle]{west}
  \inheritanchor[from=circle]{east}
  \inheritanchor[from=circle]{mid}
  \inheritanchor[from=circle]{mid west}
  \inheritanchor[from=circle]{mid east}
  \inheritanchor[from=circle]{base}
  \inheritanchor[from=circle]{base west}
  \inheritanchor[from=circle]{base east}
  \inheritanchor[from=circle]{south}
  \inheritanchor[from=circle]{south west}
  \inheritanchor[from=circle]{south east}
  \anchor{lower}{\loweranchor}

  %
  % Background path
  %
  \inheritbackgroundpath[from=circle]
  \beforebackgroundpath{
    \@tempdima=\radius%
    \setlength{\pgf@xb}{\pgfshapeouterxsep}%  
    \setlength{\pgf@yb}{\pgfshapeouterysep}%  
    \ifdim\pgf@xb<\pgf@yb%
      \advance\@tempdima by-\pgf@yb%
    \else%
      \advance\@tempdima by-\pgf@xb%
    \fi%
    \advance\@tempdima by-.5\pgflinewidth%  
    \pgfsetshortenstart{0pt}%
    \pgfsetshortenend{0pt}%
    \pgfsetarrows{-}%  
    \pgfpathmoveto{\pgfpointadd{\centerpoint}{\pgfpoint{-\@tempdima}{0pt}}}%
    \pgfpathlineto{\pgfpointadd{\centerpoint}{\pgfpoint{\@tempdima}{0pt}}}%
    \pgfusepath{stroke}%
  }
}



\pgfdeclareshape{cross out}
{
  \inheritsavedanchors[from=rectangle] % this is nearly a rectangle
  \inheritanchorborder[from=rectangle]
  \inheritanchor[from=rectangle]{north}
  \inheritanchor[from=rectangle]{north west}
  \inheritanchor[from=rectangle]{north east}
  \inheritanchor[from=rectangle]{center}
  \inheritanchor[from=rectangle]{west}
  \inheritanchor[from=rectangle]{east}
  \inheritanchor[from=rectangle]{mid}
  \inheritanchor[from=rectangle]{mid west}
  \inheritanchor[from=rectangle]{mid east}
  \inheritanchor[from=rectangle]{base}
  \inheritanchor[from=rectangle]{base west}
  \inheritanchor[from=rectangle]{base east}
  \inheritanchor[from=rectangle]{south}
  \inheritanchor[from=rectangle]{south west}
  \inheritanchor[from=rectangle]{south east}
  \foregroundpath{
    % store lower right in xa/ya and upper right in xb/yb
    \southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
    \northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
    \pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
    \pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yb}}
    \pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@yb}}
    \pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@ya}}
 }
}


\pgfdeclareshape{strike out}
{
  \inheritsavedanchors[from=rectangle] % this is nearly a rectangle
  \inheritanchorborder[from=rectangle]
  \inheritanchor[from=rectangle]{north}
  \inheritanchor[from=rectangle]{north west}
  \inheritanchor[from=rectangle]{north east}
  \inheritanchor[from=rectangle]{center}
  \inheritanchor[from=rectangle]{west}
  \inheritanchor[from=rectangle]{east}
  \inheritanchor[from=rectangle]{mid}
  \inheritanchor[from=rectangle]{mid west}
  \inheritanchor[from=rectangle]{mid east}
  \inheritanchor[from=rectangle]{base}
  \inheritanchor[from=rectangle]{base west}
  \inheritanchor[from=rectangle]{base east}
  \inheritanchor[from=rectangle]{south}
  \inheritanchor[from=rectangle]{south west}
  \inheritanchor[from=rectangle]{south east}
  \foregroundpath{
    \pgfpathmoveto{\southwest}
    \pgfpathlineto{\northeast}
 }
}


\pgfdeclareshape{forbidden sign}
{
  \inheritsavedanchors[from=circle] % this is nearly a circle
  \inheritanchorborder[from=circle]
  \inheritanchor[from=circle]{north}
  \inheritanchor[from=circle]{north west}
  \inheritanchor[from=circle]{north east}
  \inheritanchor[from=circle]{center}
  \inheritanchor[from=circle]{west}
  \inheritanchor[from=circle]{east}
  \inheritanchor[from=circle]{mid}
  \inheritanchor[from=circle]{mid west}
  \inheritanchor[from=circle]{mid east}
  \inheritanchor[from=circle]{base}
  \inheritanchor[from=circle]{base west}
  \inheritanchor[from=circle]{base east}
  \inheritanchor[from=circle]{south}
  \inheritanchor[from=circle]{south west}
  \inheritanchor[from=circle]{south east}
  \inheritbackgroundpath[from=circle]
  \foregroundpath{
    \centerpoint%
    \pgf@xc=\pgf@x%
    \pgf@yc=\pgf@y%
    \@tempdima=\radius%
    \setlength{\pgf@xb}{\pgfshapeouterxsep}%  
    \setlength{\pgf@yb}{\pgfshapeouterysep}%  
    \ifdim\pgf@xb<\pgf@yb%
      \advance\@tempdima by-\pgf@yb%
    \else%
      \advance\@tempdima by-\pgf@xb%
    \fi%
    \pgfpathmoveto{\pgfpointadd{\pgfpoint{\pgf@xc}{\pgf@yc}}{\pgfpoint{-0.707107\@tempdima}{-0.707107\@tempdima}}}
    \pgfpathlineto{\pgfpointadd{\pgfpoint{\pgf@xc}{\pgf@yc}}{\pgfpoint{0.707107\@tempdima}{0.707107\@tempdima}}}
  }
}


\endinput
