% Copyright 2007 by Till Tantau and Mark Wibrow
%
% 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.multipart.code.tex,v 1.7 2008/01/15 15:41:18 vibrovski Exp $

\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%
    \pgfmathsetlength{\pgf@y}{\pgfkeysvalueof{/pgf/inner ysep}}%
    \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%
    \pgfmathsetlength{\pgf@y}{\pgfkeysvalueof{/pgf/inner ysep}}%
    \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%
		%
		% MW: Suggested correction for above calculation:	Use the tallest box * 2.
		%
		\pgf@ya=.5\ht\pgfnodeparttextbox%
		\advance\pgf@ya by.5\dp\pgfnodeparttextbox%
		\pgf@yb=.5\ht\pgfnodepartlowerbox%
		\advance\pgf@yb by.5\dp\pgfnodepartlowerbox%
		\ifdim\pgf@ya>\pgf@yb\relax%
			\pgf@ya2.0\pgf@ya\relax%
		\else%
			\pgf@ya2.0\pgf@yb\relax%
		\fi%
		\advance\pgf@ya by.5\pgflinewidth%
    \pgfmathsetlength\pgf@yb{\pgfkeysvalueof{/pgf/inner ysep}}%
    \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%
    \pgfmathsetlength\pgf@xb{\pgfkeysvalueof{/pgf/inner xsep}}%
    \advance\pgf@xa by\pgf@xb%
    % 
    % Calculate length of radius vector:
    % 
    \pgf@process{\pgfpointnormalised{\pgfqpoint{\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: 
    % 
    \pgfmathsetlength{\pgf@xb}{\pgfkeysvalueof{/pgf/minimum width}}%  
    \pgfmathsetlength{\pgf@yb}{\pgfkeysvalueof{/pgf/minimum height}}%  
    \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.
    % 
    \pgfmathsetlength{\pgf@xb}{\pgfkeysvalueof{/pgf/outer xsep}}%  
    \pgfmathsetlength{\pgf@yb}{\pgfkeysvalueof{/pgf/outer ysep}}%  
    \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{
    \pgfutil@tempdima=\radius%
    \pgfmathsetlength{\pgf@xb}{\pgfkeysvalueof{/pgf/outer xsep}}%  
    \pgfmathsetlength{\pgf@yb}{\pgfkeysvalueof{/pgf/outer ysep}}%  
    \ifdim\pgf@xb<\pgf@yb%
      \advance\pgfutil@tempdima by-\pgf@yb%
    \else%
      \advance\pgfutil@tempdima by-\pgf@xb%
    \fi%
    \advance\pgfutil@tempdima by-.5\pgflinewidth%  
    \pgfsetshortenstart{0pt}%
    \pgfsetshortenend{0pt}%
    \pgfsetarrows{-}%  
    \pgfpathmoveto{\pgfpointadd{\centerpoint}{\pgfqpoint{-1\pgfutil@tempdima}{0pt}}}%
    \pgfpathlineto{\pgfpointadd{\centerpoint}{\pgfqpoint{\pgfutil@tempdima}{0pt}}}%
    \pgfusepath{stroke}%
  }
}





% (Most) keys for shape rectangle split.
%
% /pgf/rectangle split parts             : Set the number of rectangles to split into.
% /pgf/rectangle split part align        : Align the for the boxes in each part
%                                          (also keys for each part)
% /pgf/rectangle split use custom fill   : Use a custom (behindbackground path) fill.
% /pgf/rectangle split part fill         : Custom fill for ech part.
%                                          (also keys for each part)
% /pgf/rectangle split draw splits       : Draw the line between node parts.
% /pgf/rectangle split empty part height : Set the default height for empty boxes.


\newif\ifpgfrectanglesplitdrawsplits
\pgfrectanglesplitdrawsplitstrue

\newif\ifpgfrectanglesplitusecustomfill
\pgfrectanglesplitusecustomfillfalse

\pgfkeys{/pgf/.cd,
	rectangle split parts/.initial=4,
	rectangle split empty part height/.initial=1ex,
	rectangle split draw splits/.is if=pgfrectanglesplitdrawsplits,
	%
	rectangle split part align/.code=\pgf@lib@shapes@rectanglesplit@assigntoparts{#1}{align},
	rectangle split text part align/.initial=center,
	rectangle split second part align/.initial=center,
	rectangle split third part align/.initial=center,
	rectangle split fourth part align/.initial=center,
	%
	rectangle split use custom fill/.is if=pgfrectanglesplitusecustomfill,
	rectangle split part fill/.code={%
		\pgfrectanglesplitusecustomfilltrue%
		\pgf@lib@shapes@rectanglesplit@assigntoparts{#1}{fill}%
	},
	rectangle split text part fill/.initial=white,
	rectangle split second part fill/.initial=white,
	rectangle split third part fill/.initial=white,
	rectangle split fourth part fill/.initial=white
}

% Internal macros for the rectangle split shape.
%
\def\pgf@lib@shapes@rectanglesplit@left{left}
\def\pgf@lib@shapes@rectanglesplit@right{right}

\def\pgf@lib@shapes@rectanglesplit@assigntoparts#1#2{%
	\expandafter\pgf@lib@shapes@rectanglesplit@@assigntoparts#1,\@@,\@@,\@@,\@@,\pgf@lib#2\pgf@lib}
\def\pgf@lib@shapes@rectanglesplit@@assigntoparts#1,#2,#3,#4,#5\pgf@lib#6\pgf@lib{%
	\pgfkeys{/pgf/.cd,%
		rectangle split text part #6=#1,
		rectangle split second part #6=#1,
		rectangle split third part #6=#1,
		rectangle split fourth part #6=#1
	}%
	\ifx#2\@@\else%
	\pgfkeys{/pgf/.cd,%
			rectangle split second part #6=#2,
			rectangle split third part #6=#2,
			rectangle split fourth part #6=#2
		}%
	\fi%
	\ifx#3\@@\else%
		\pgfkeys{/pgf/.cd,%
			rectangle split third part #6=#3,
			rectangle split fourth part #6=#3
		}%
	\fi%
	\ifx#4\@@\else%
		\pgfkeys{/pgf/rectangle split fourth part #6=#4}%
	\fi%
}%

\newbox\pgfnodepartsecondbox
\newbox\pgfnodepartthirdbox
\newbox\pgfnodepartfourthbox

\pgfdeclareshape{rectangle split}{%
	\nodeparts{text,second,third,fourth}
	\savedmacro\getrectanglesplitparameters{%
		%
		% If the height+depth of any box is 0pt use the default empty height.
		%
		\pgfmathsetlength\pgfutil@tempdima{\pgfkeysvalueof{/pgf/rectangle split empty part height}}
		\pgf@y\ht\pgfnodeparttextbox%
		\advance\pgf@y\dp\pgfnodeparttextbox%
		\ifdim\pgf@y=0pt\relax%
			\setbox\pgfnodeparttextbox=\hbox{%				
				\vrule width0pt height\the\pgfutil@tempdima depth0pt%
			}%
		\fi%
		\pgf@y\ht\pgfnodepartsecondbox%
		\advance\pgf@y\dp\pgfnodepartsecondbox%
		\ifdim\pgf@y=0pt\relax%
			\setbox\pgfnodepartsecondbox=\hbox{%
				\vrule width0pt height\the\pgfutil@tempdima depth0pt%
			}%
		\fi%
		\pgf@y\ht\pgfnodepartthirdbox%
		\advance\pgf@y\dp\pgfnodepartthirdbox%
		\ifdim\pgf@y=0pt\relax%
			\setbox\pgfnodepartthirdbox=\hbox{%
				\vrule width0pt height\the\pgfutil@tempdima depth0pt%
			}%
		\fi%
		\pgf@y\ht\pgfnodepartfourthbox%
		\advance\pgf@y\dp\pgfnodepartfourthbox%
		\ifdim\pgf@y=0pt\relax%
			\setbox\pgfnodepartfourthbox=\hbox{%
					\vrule width0pt height\the\pgfutil@tempdima depth0pt%
			}%
		\fi%
		%
		% Empty boxes (without voiding them) if they are not used.
		%
		\pgfmathtruncatemacro\parts{\pgfkeysvalueof{/pgf/rectangle split parts}}%
	  \addtosavedmacro{\parts}%
	  \ifnum\parts<2\relax%
	  	\setbox\pgfnodepartsecondbox=\hbox{}%
	  \fi%
	  \ifnum\parts<3\relax%
	  	\setbox\pgfnodepartthirdbox=\hbox{}%
	  \fi%
	  \ifnum\parts<4\relax%
	  	\setbox\pgfnodepartfourthbox=\hbox{}%
	  \fi%	  
	  %
		% Save the line width.
		%
		\pgfmathsetlength\pgf@x{\pgflinewidth}
		\edef\linewidth{\the\pgf@x}%
	  \addtosavedmacro{\linewidth}%
	  %
	  \pgfmathsetlength\pgf@y{\pgfkeysvalueof{/pgf/inner ysep}}%
  	\edef\innerysep{\the\pgf@y}%
  	%
	  \pgfmathsetlength\pgf@x{\pgfkeysvalueof{/pgf/inner xsep}}%
  	\edef\innerxsep{\the\pgf@x}%
  	%
  	% Get the widths.
  	%
  	\pgf@x.5\wd\pgfnodeparttextbox%
  	\pgf@xa.5\wd\pgfnodepartsecondbox%
  	\pgf@xb.5\wd\pgfnodepartthirdbox%
  	\pgf@xc.5\wd\pgfnodepartfourthbox%
  	%
  	% Find the maximum width%
  	%
  	\pgfutil@tempdima\pgf@x%
  	\ifdim\pgfutil@tempdima<\pgf@xa%
  		\pgfutil@tempdima\pgf@xa%
  	\fi%
  	\ifdim\pgfutil@tempdima<\pgf@xb%
  		\pgfutil@tempdima\pgf@xb%
  	\fi%
  	\ifdim\pgfutil@tempdima<\pgf@xc%
  		\pgfutil@tempdima\pgf@xc%
  	\fi%
  	%
  	% Adjust for alignment.
	  %
	  \edef\pgf@lib@temp{\pgfkeysvalueof{/pgf/rectangle split text part align}}%
	  \ifx\pgf@lib@temp\pgf@lib@shapes@rectanglesplit@left%
  		\pgf@x-\pgfutil@tempdima%
	  \else%
	  	\ifx\pgf@lib@temp\pgf@lib@shapes@rectanglesplit@right%
	  		\pgf@x-2.0\pgf@x%
  			\advance\pgf@x\pgfutil@tempdima%	  		
	  	\else%
	  		\pgf@x-\pgf@x%
  		\fi%
	  \fi%
  	%
  	\edef\pgf@lib@temp{\pgfkeysvalueof{/pgf/rectangle split second part align}}%
  	\ifx\pgf@lib@temp\pgf@lib@shapes@rectanglesplit@left%
  		\pgf@xa-\pgfutil@tempdima%
	  \else%
	  	\ifx\pgf@lib@temp\pgf@lib@shapes@rectanglesplit@right%
	  		\pgf@xa-2.0\pgf@xa%
  			\advance\pgf@xa\pgfutil@tempdima%
	  	\else%
  			\pgf@xa-\pgf@xa%
  		\fi%
	  \fi%
  	%
  	\edef\pgf@lib@temp{\pgfkeysvalueof{/pgf/rectangle split third part align}}%
  	\ifx\pgf@lib@temp\pgf@lib@shapes@rectanglesplit@left%
  		\pgf@xb-\pgfutil@tempdima%
	  \else%
	  	\ifx\pgf@lib@temp\pgf@lib@shapes@rectanglesplit@right%
	  		\pgf@xb-2.0\pgf@xb%
	  		\advance\pgf@xb\pgfutil@tempdima%
	  	\else%
	  		\pgf@xb-\pgf@xb%
	  	\fi%
	  \fi%
  	%
  	\edef\pgf@lib@temp{\pgfkeysvalueof{/pgf/rectangle split fourth part align}}%
  	\ifx\pgf@lib@temp\pgf@lib@shapes@rectanglesplit@left%
  		\pgf@xc-\pgfutil@tempdima%
	  \else%
	  	\ifx\pgf@lib@temp\pgf@lib@shapes@rectanglesplit@right%
	  		\pgf@xc-2.0\pgf@xc%
	  		\advance\pgf@xc\pgfutil@tempdima%
	  	\else%
	  		\pgf@xc-\pgf@xc%
	  	\fi%
	  \fi%
  	%
  	% Make relative to x.
  	%
  	\advance\pgf@xa-\pgf@x%
  	\advance\pgf@xb-\pgf@x%
  	\advance\pgf@xc-\pgf@x%
  	\pgf@x0pt%
  	%
  	% Find the minimum.
  	%
  	\pgfutil@tempdimb\pgf@x%
  	\ifdim\pgfutil@tempdimb>\pgf@xa%
  		\pgfutil@tempdimb\pgf@xa%
  	\fi%
  	\ifdim\pgfutil@tempdimb>\pgf@xb%
  		\pgfutil@tempdimb\pgf@xb%
  	\fi%
  	\ifdim\pgfutil@tempdimb>\pgf@xc%
  		\pgfutil@tempdimb\pgf@xc%
  	\fi%
  	%
  	% Anchor for the text box is (0pt, 0pt)
  	%
  	\pgfsavepgf@process\textanchor{\pgfqpoint{0pt}{0pt}}%
  	%
  	% Anchor for second box.
  	%
  	\pgfsavepgf@process\lowestanchor{\pgfqpoint{0pt}{0pt}}%
  	\let\lowestbox\pgfnodeparttextbox%
  	\ifnum\parts>1\relax%
  	  \pgfsavepgf@process\secondanchor{%
  	  	\pgf@x\pgf@xa%
	  		\pgf@y-\dp\pgfnodeparttextbox%
	  		\advance\pgf@y-\innerysep\relax%
	  		\advance\pgf@y-\pgflinewidth%
	  		\advance\pgf@y-\innerysep\relax%
	  		\advance\pgf@y-\ht\pgfnodepartsecondbox%
	  	}%
	  	\let\lowestanchor\secondanchor%
	  	\let\lowestbox\pgfnodepartsecondbox%
  	\else%
  		\let\secondanchor\textanchor%
  	\fi%
  	%
  	% Anchor for third box.
  	%
  	\ifnum\parts>2\relax%
  	  \pgfsavepgf@process\thirdanchor{%
  	  	\lowestanchor%
  	  	\pgf@x\pgf@xb%
	  		\advance\pgf@y-\dp\pgfnodepartsecondbox%
	  		\advance\pgf@y-\innerysep\relax%
	  		\advance\pgf@y-\pgflinewidth%
	  		\advance\pgf@y-\innerysep\relax%
	  		\advance\pgf@y-\ht\pgfnodepartthirdbox%
	  	}%
	  	\let\lowestanchor\thirdanchor%
	  	\let\lowestbox\pgfnodepartthirdbox%
  	\else%
  		\let\thirdanchor\secondanchor%
  	\fi%
  	%
  	% Anchor for fourth box.
  	%
  	\ifnum\parts>3\relax%
  		\pgfsavepgf@process\fourthanchor{%
  			\lowestanchor%
  	  	\pgf@x\pgf@xc%
  	  	\advance\pgf@y-\dp\lowestbox%
	  		\advance\pgf@y-\innerysep\relax%
	  		\advance\pgf@y-\pgflinewidth%
	  		\advance\pgf@y-\innerysep\relax%
	  		\advance\pgf@y-\ht\pgfnodepartfourthbox%
	  	}%
	  	\let\lowestanchor\fourthanchor%
	  	\let\lowestbox\pgfnodepartfourthbox%
	  \else%
  		\let\fourthanchor\thirdanchor%
  	\fi%
  	%
  	\addtosavedmacro{\textanchor}%
	  \addtosavedmacro{\secondanchor}%
	  \addtosavedmacro{\thirdanchor}%
	  \addtosavedmacro{\fourthanchor}%
	  %
	  % Adjust the boxwidth for minimum width
	  %
	  \pgfmathaddtolength\pgfutil@tempdima{\pgfkeysvalueof{/pgf/inner xsep}}%
  	\pgfmathsetlength\pgf@x{\pgfkeysvalueof{/pgf/minimum width}}%
  	\ifdim\pgfutil@tempdima<.5\pgf@x%
  		\pgfutil@tempdima.5\pgf@x%
  	\fi%
  	\pgfmathaddtolength\pgfutil@tempdima{-\pgfkeysvalueof{/pgf/inner xsep}}%
  	%
  	% Get some important points.
  	%
  	\pgfsavepgf@process\southwest{%
  		\lowestanchor%
  		\pgf@x\pgfutil@tempdimb%
  		\pgfmathaddtolength\pgf@x{-\pgfkeysvalueof{/pgf/inner xsep}}%
  		\pgfmathaddtolength\pgf@x{-\pgfkeysvalueof{/pgf/outer xsep}}%
  		\pgf@ya\linewidth\relax%
  		\advance\pgf@x-.5\pgf@ya%
  		\advance\pgf@y-\dp\lowestbox%
  		\advance\pgf@y-.5\pgf@ya%
  		\pgfmathaddtolength\pgf@y{-\pgfkeysvalueof{/pgf/inner ysep}}%
  		\pgfmathaddtolength\pgf@y{-\pgfkeysvalueof{/pgf/outer ysep}}%
  	}%
  	\pgfsavepgf@process\northeast{%
  		\pgf@x\pgfutil@tempdimb%
  		\advance\pgf@x2.0\pgfutil@tempdima%
  		\pgfmathaddtolength\pgf@x{\pgfkeysvalueof{/pgf/inner xsep}}%
  		\pgfmathaddtolength\pgf@x{\pgfkeysvalueof{/pgf/outer xsep}}%
  		\pgf@ya\linewidth\relax%
  		\advance\pgf@x.5\pgf@ya%
  		\pgf@y\ht\pgfnodeparttextbox%
  		\advance\pgf@y.5\pgf@ya%
  		\pgfmathaddtolength\pgf@y{\pgfkeysvalueof{/pgf/inner ysep}}%
  		\pgfmathaddtolength\pgf@y{\pgfkeysvalueof{/pgf/outer ysep}}%
  	}%
  	\addtosavedmacro{\northeast}%
  	\addtosavedmacro{\southwest}%  	
  	\pgfsavepgf@process\centerpoint{%
  	  \pgfpointadd{\southwest}{%
  			\pgfpointdiff{\southwest}{\northeast}%
  			\pgf@x.5\pgf@x%
  			\pgf@y.5\pgf@y%
  		}%
  	}%
  	\addtosavedmacro{\centerpoint}%  
  	\pgfsavepgf@process\south{%
  		\centerpoint%
  		\pgf@xa\pgf@x%
  		\southwest%
  		\pgf@x\pgf@xa%
  	}%
  	%
  	% Get the split points.
  	%
  	\let\lastsplit\south%
  	\ifnum\parts>1\relax%
	  	\pgfsavepgf@process\textsplit{%
	  		\pgf@x\pgfutil@tempdimb%
	  		\advance\pgf@x\pgfutil@tempdima%
	  		\pgf@y-\dp\pgfnodeparttextbox%
	  		\advance\pgf@y-\innerysep%
	  		\advance\pgf@y-.5\pgflinewidth%
	  	}%
	  \else%
	  	\let\textsplit\south%
	  \fi%
  	\addtosavedmacro{\textsplit}%
  	\pgfsavepgf@process\textspliteast{%
  		\textsplit%
  		\pgf@ya\pgf@y%
  		\northeast%
  		\pgf@y\pgf@ya%
  	}%
  	\addtosavedmacro{\textspliteast}%
  	\pgfsavepgf@process\textsplitwest{%
  		\textsplit%
  		\pgf@ya\pgf@y%
  		\southwest%
  		\pgf@y\pgf@ya%
  	}%
  	\addtosavedmacro{\textsplitwest}%
  	\ifnum\parts>2\relax%
  		\pgfsavepgf@process\secondsplit{%
  		  \secondanchor%
  			\pgf@x\pgfutil@tempdimb%
  			\advance\pgf@x\pgfutil@tempdima%
  			\advance\pgf@y-\dp\pgfnodepartsecondbox%
  			\advance\pgf@y-\innerysep%
  			\advance\pgf@y-.5\pgflinewidth%
  		}%
  	\else%
  		\let\secondsplit\south%
  	\fi%
  	\addtosavedmacro{\secondsplit}%
  	\pgfsavepgf@process\secondspliteast{%
  		\secondsplit%
  		\pgf@ya\pgf@y%
  		\northeast%
  		\pgf@y\pgf@ya%
  	}%
  	\addtosavedmacro{\secondspliteast}%
  	\pgfsavepgf@process\secondsplitwest{%
  		\secondsplit%
  		\pgf@ya\pgf@y%
  		\southwest%
  		\pgf@y\pgf@ya%
  	}%
  	\addtosavedmacro{\secondsplitwest}%
  	\ifnum\parts>3\relax%
  		\pgfsavepgf@process\thirdsplit{%
  		  \thirdanchor%
  			\pgf@x\pgfutil@tempdimb%
  			\advance\pgf@x\pgfutil@tempdima%
  			\advance\pgf@y-\dp\pgfnodepartthirdbox%
  			\advance\pgf@y-\innerysep%
  			\advance\pgf@y-.5\pgflinewidth%
  		}%
  		\let\lastsplit\thirdsplit%
  	\else%
  		\let\thirdsplit\south%
  	\fi%
  	\addtosavedmacro{\thirdsplit}%
  	\pgfsavepgf@process\thirdspliteast{%
  		\thirdsplit%
  		\pgf@ya\pgf@y%
  		\northeast%
  		\pgf@y\pgf@ya%
  	}%
  	\addtosavedmacro{\thirdspliteast}%
  	\pgfsavepgf@process\thirdsplitwest{%
  		\thirdsplit%
  		\pgf@ya\pgf@y%
  		\southwest%
  		\pgf@y\pgf@ya%
  	}%
  	\addtosavedmacro{\thirdsplitwest}%
	}%
	\savedanchor\basepoint{%
		\pgfmathsetlength\pgf@x{+.5\wd\pgfnodeparttextbox}%
		\pgfmathsetlength\pgf@y{+.5\ht\pgfnodeparttextbox}%
		\pgf@y0pt\relax%
	}%
	\savedanchor\midpoint{%
		\pgfmathsetlength\pgf@x{+.5\wd\pgfnodeparttextbox}%
		\pgfmathsetlength\pgf@y{+.5ex}%
	}%
	\anchor{center}{\getrectanglesplitparameters\centerpoint}%
	\anchor{base}{\basepoint}%
	\anchor{mid}{\midpoint}%
	\anchor{second}{\getrectanglesplitparameters\secondanchor}%
	\anchor{third}{\getrectanglesplitparameters\thirdanchor}%
	\anchor{fourth}{\getrectanglesplitparameters\fourthanchor}%
	\anchor{north east}{\getrectanglesplitparameters\northeast}
	\anchor{south west}{\getrectanglesplitparameters\southwest}
	\anchor{south east}{%
		\getrectanglesplitparameters%
		\northeast%
		\pgf@xa\pgf@x%
		\southwest%
		\pgf@x\pgf@xa}
	\anchor{north west}{%
		\getrectanglesplitparameters%
		\northeast%
		\pgf@ya\pgf@y%
		\southwest%
		\pgf@y\pgf@ya}
	\anchor{south}{%
		\getrectanglesplitparameters%
		\centerpoint%
		\pgf@xa\pgf@x%
		\southwest%
		\pgf@x\pgf@xa}
	\anchor{north}{%
		\getrectanglesplitparameters%
		\centerpoint%
		\pgf@xa\pgf@x%
		\northeast%
		\pgf@x\pgf@xa}
	\anchor{west}{%
		\getrectanglesplitparameters%
		\centerpoint%
		\pgf@ya\pgf@y%
		\southwest%
		\pgf@y\pgf@ya}
	\anchor{east}{%
		\getrectanglesplitparameters%
		\centerpoint%
		\pgf@ya\pgf@y%
		\northeast%
		\pgf@y\pgf@ya}
	\anchor{text split}{\getrectanglesplitparameters\textsplit}
	\anchor{text split east}{\getrectanglesplitparameters\textspliteast}
	\anchor{text split west}{\getrectanglesplitparameters\textsplitwest}
	\anchor{second split}{\getrectanglesplitparameters\secondsplit}
	\anchor{second split east}{\getrectanglesplitparameters\secondspliteast}
	\anchor{second split west}{\getrectanglesplitparameters\secondsplitwest}
	\anchor{third split}{\getrectanglesplitparameters\thirdsplit}
	\anchor{third split east}{\getrectanglesplitparameters\thirdspliteast}
	\anchor{third split west}{\getrectanglesplitparameters\thirdsplitwest}	
	\anchor{text east}{%
		\getrectanglesplitparameters%
		\ifnum\parts>1\relax%
			\textsplit%
			\pgf@ya\pgf@y
			\northeast%
			\advance\pgf@y\pgf@ya%
			\pgf@y.5\pgf@y%
			\pgf@ya\linewidth\relax%
			\advance\pgf@y-.25\pgf@ya%
		\else%
			\centerpoint%
			\pgf@ya\pgf@y%
			\northeast%
			\pgf@y\pgf@ya%
		\fi%
	}
	\anchor{text west}{%
		\getrectanglesplitparameters%
		\ifnum\parts>1\relax%
			\textsplit%
			\pgf@ya\pgf@y
			\southwest%
			\pgf@xa\pgf@x%
			\northeast%
			\pgf@x\pgf@xa%
			\advance\pgf@y\pgf@ya%
			\pgf@y.5\pgf@y%
			\pgf@ya\linewidth\relax%
			\advance\pgf@y-.25\pgf@ya%
		\else%
			\centerpoint%
			\pgf@ya\pgf@y%
			\southwest%
			\pgf@y\pgf@ya%
		\fi%
	}
	\anchor{second east}{%
		\getrectanglesplitparameters%
		\ifnum\parts>1\relax%
			\northeast%
			\pgf@xa\pgf@x%
			\secondsplit%
			\pgf@ya\pgf@y
			\textsplit%
			\advance\pgf@y\pgf@ya%
			\pgf@y.5\pgf@y%
			\pgf@x\pgf@xa%
		\else%
			\southwest%
			\pgf@ya\pgf@y%
			\northeast%
			\pgf@y\pgf@ya%
		\fi%
	}
	\anchor{second west}{%
		\getrectanglesplitparameters%
		\ifnum\parts>1\relax%
			\southwest%
			\pgf@xa\pgf@x%
			\secondsplit%
			\pgf@ya\pgf@y
			\textsplit%
			\advance\pgf@y\pgf@ya%
			\pgf@y.5\pgf@y%
			\pgf@x\pgf@xa%
		\else%
			\southwest%
		\fi%
	}
	\anchor{third east}{%
		\getrectanglesplitparameters%
		\ifnum\parts>2\relax%
			\northeast%
			\pgf@xa\pgf@x%
			\thirdsplit%
			\pgf@ya\pgf@y
			\secondsplit%
			\advance\pgf@y\pgf@ya%
			\pgf@y.5\pgf@y%
			\pgf@x\pgf@xa%
		\else%
			\southwest%
			\pgf@ya\pgf@y%
			\northeast%
			\pgf@y\pgf@ya%
		\fi%
	}
	\anchor{third west}{%
		\getrectanglesplitparameters%
		\ifnum\parts>2\relax%
			\southwest%
			\pgf@xa\pgf@x%
			\thirdsplit%
			\pgf@ya\pgf@y
			\secondsplit%
			\advance\pgf@y\pgf@ya%
			\pgf@y.5\pgf@y%
			\pgf@x\pgf@xa%
		\else%
			\southwest
		\fi%
	}
	\anchor{fourth east}{%
		\getrectanglesplitparameters%
		\ifnum\parts>3\relax%
			\northeast%
			\pgf@xa\pgf@x%
			\southwest%
			\pgf@ya\linewidth\relax%
			\pgf@ya.5\pgf@ya%
			\advance\pgf@ya\pgf@y%
			\thirdsplit%
			\advance\pgf@y\pgf@ya%
			\pgf@y.5\pgf@y%
			\pgf@x\pgf@xa%
		\else%
			\northeast%
			\pgf@xa\pgf@x%
			\southwest%
			\pgf@x\pgf@xa%
		\fi%
	}
	\anchor{fourth west}{%
		\getrectanglesplitparameters%
		\ifnum\parts>3\relax%
			\southwest%
			\pgf@xa\pgf@x%
			\pgf@ya\linewidth\relax%
			\pgf@ya.5\pgf@ya%
			\advance\pgf@ya\pgf@y%
			\thirdsplit%
			\advance\pgf@y\pgf@ya%
			\pgf@y.5\pgf@y%
			\pgf@x\pgf@xa%
		\else%
			\southwest%
		\fi%
	}
	\backgroundpath{%
		\getrectanglesplitparameters%
		%
		% Remove outer sep.
		%
		\pgfsavepgf@process\southwest{%
			\southwest%
  		\pgfmathaddtolength\pgf@x{\pgfkeysvalueof{/pgf/outer xsep}}%
  		\pgfmathaddtolength\pgf@y{\pgfkeysvalueof{/pgf/outer ysep}}%
  	}%
  	\pgfsavepgf@process\northeast{%
			\northeast%
  		\pgfmathaddtolength\pgf@x{-\pgfkeysvalueof{/pgf/outer xsep}}%
  		\pgfmathaddtolength\pgf@y{-\pgfkeysvalueof{/pgf/outer ysep}}%
  	}%
  	\pgfsavepgf@process\textsplit{%
			\textsplit%
  		\pgfmathaddtolength\pgf@x{\pgfkeysvalueof{/pgf/outer xsep}}%
  	}%
  	\pgfsavepgf@process\secondsplit{%
			\secondsplit%
  		\pgfmathaddtolength\pgf@x{-\pgfkeysvalueof{/pgf/outer xsep}}%
  	}%
  	\pgfsavepgf@process\thirdsplit{%
			\thirdsplit%
  		\pgfmathaddtolength\pgf@x{\pgfkeysvalueof{/pgf/outer xsep}}%
  	}%
  	\pgfpathrectangle{\southwest}{\pgfpointdiff{\southwest}{\northeast}}%
  	{%
  		\pgfsetcornersarced{\pgfqpoint{0pt}{0pt}}%
  		\ifnum\parts>1\relax%
  			\pgfpathmoveto{\textsplit\pgf@ya\pgf@y\southwest\pgf@y\pgf@ya}%
  			\pgfpathlineto{\textsplit\pgf@ya\pgf@y\northeast\pgf@y\pgf@ya}%
  		\fi%
  		\ifnum\parts>2\relax%
  			\pgfpathmoveto{\secondsplit\pgf@ya\pgf@y\southwest\pgf@y\pgf@ya}%
  			\pgfpathlineto{\secondsplit\pgf@ya\pgf@y\northeast\pgf@y\pgf@ya}%
  		\fi%
  		\ifnum\parts>3\relax%
  			\pgfpathmoveto{\thirdsplit\pgf@ya\pgf@y\southwest\pgf@y\pgf@ya}%
  			\pgfpathlineto{\thirdsplit\pgf@ya\pgf@y\northeast\pgf@y\pgf@ya}%
  		\fi%
  	}%
  }
  \behindbackgroundpath{%
  	\ifpgfrectanglesplitusecustomfill%
  		%
			% Remove outer sep.
			%
			\getrectanglesplitparameters%
			\pgfsavepgf@process\southwest{%
				\southwest%
	  		\pgfmathaddtolength\pgf@x{\pgfkeysvalueof{/pgf/outer xsep}}%
	  		\pgfmathaddtolength\pgf@y{\pgfkeysvalueof{/pgf/outer ysep}}%
	  	}%
	  	\pgfsavepgf@process\northeast{%
				\northeast%
	  		\pgfmathaddtolength\pgf@x{-\pgfkeysvalueof{/pgf/outer xsep}}%
	  		\pgfmathaddtolength\pgf@y{-\pgfkeysvalueof{/pgf/outer ysep}}%
	  	}%
	  	\pgfsavepgf@process\textspliteast{%
				\textspliteast%
	  		\pgfmathaddtolength\pgf@x{-\pgfkeysvalueof{/pgf/outer xsep}}%
	  	}%
	  	\pgfsavepgf@process\textsplitwest{%
				\textsplitwest%
	  		\pgfmathaddtolength\pgf@x{\pgfkeysvalueof{/pgf/outer xsep}}%
	  	}%
	  	\pgfsavepgf@process\secondspliteast{%
				\secondspliteast%
	  		\pgfmathaddtolength\pgf@x{-\pgfkeysvalueof{/pgf/outer xsep}}%
	  	}%
	  	\pgfsavepgf@process\secondsplitwest{%
				\secondsplitwest%
	  		\pgfmathaddtolength\pgf@x{\pgfkeysvalueof{/pgf/outer xsep}}%
	  	}%
	  	\pgfsavepgf@process\thirdspliteast{%
				\thirdspliteast%
	  		\pgfmathaddtolength\pgf@x{-\pgfkeysvalueof{/pgf/outer xsep}}%
	  	}%
	  	\pgfsavepgf@process\thirdsplitwest{%
				\thirdsplitwest%
	  		\pgfmathaddtolength\pgf@x{\pgfkeysvalueof{/pgf/outer xsep}}%
	  	}%
	  	%
  		% Always fill the text box.
  		%
  		\pgfpathmoveto{\textsplitwest}%
  		\pgfpathlineto{\northeast\pgf@ya\pgf@y\southwest\pgf@y\pgf@ya}%
  		\pgfpathlineto{\northeast}%
  		\ifnum\parts>1\relax%
  			\bgroup%
  				\pgfsetcornersarced{\pgfqpoint{0pt}{0pt}}%
  		\fi%  		
  		\pgfpathlineto{\textspliteast}%
  		\pgfpathclose%
  		\ifnum\parts>1\relax%
  			\egroup%
  		\fi% 
  		\pgfsetfillcolor{\pgfkeysvalueof{/pgf/rectangle split text part fill}}%
  		\pgfusepath{fill}%
  		%
  		% Second box.
  		%
  		\ifnum\parts>1\relax%
  			\bgroup%
  				\pgfsetcornersarced{\pgfqpoint{0pt}{0pt}}%
  				\pgfpathmoveto{\textsplitwest}%
  				\pgfpathlineto{\textspliteast}%
	  			\ifnum\parts=2\relax%
	  				\egroup%
	  			\fi%
  				\pgfpathlineto{\secondspliteast}%
  				\pgfpathlineto{\secondsplitwest}%
  				\ifnum\parts=2\relax%
	  				\bgroup%
	  				\pgfsetcornersarced{\pgfqpoint{0pt}{0pt}}%
	  			\fi%
  				\pgfpathclose%
  				\pgfsetfillcolor{\pgfkeysvalueof{/pgf/rectangle split second part fill}}%
  				\pgfusepath{fill}%
  			\egroup%
  		\fi%
  		%
  		% Third box.
  		%
  		\ifnum\parts>2\relax%
  			\bgroup%
  				\pgfsetcornersarced{\pgfqpoint{0pt}{0pt}}%
  				\pgfpathmoveto{\secondsplitwest}%
  				\pgfpathlineto{\secondspliteast}%
  				\ifnum\parts=3\relax%
  					\egroup%
  				\fi%
  				\pgfpathlineto{\thirdspliteast}%
  				\pgfpathlineto{\thirdsplitwest}%
  				\ifnum\parts=3\relax%
  					\bgroup%
  					\pgfsetcornersarced{\pgfqpoint{0pt}{0pt}}%
  				\fi%
  				\pgfpathclose%
  				\pgfsetfillcolor{\pgfkeysvalueof{/pgf/rectangle split third part fill}}%
  				\pgfusepath{fill}%
  			\egroup%
  		\fi%
	  	%
			% And the fourth box.
			%
			\ifnum\parts>3\relax%
				\pgfpathmoveto{\thirdsplitwest}%
				\pgfpathlineto{\southwest}%
				\pgfpathlineto{\southwest\pgf@ya\pgf@y\northeast\pgf@y\pgf@ya}%
				\bgroup%
						\pgfsetcornersarced{\pgfqpoint{0pt}{0pt}}%
						\pgfpathlineto{\thirdspliteast}%
					\pgfpathclose%
				\egroup%
				\pgfsetfillcolor{\pgfkeysvalueof{/pgf/rectangle split fourth part fill}}%
				\pgfusepath{fill}%
			\fi%
		\fi%
  }
  \anchorborder{%
  	\pgfutil@tempdima\pgf@x%
  	\pgfutil@tempdimb\pgf@y%
  	\getrectanglesplitparameters%
  	\pgfpointdiff{\southwest}{\northeast}%
  	\pgf@x.5\pgf@x%
  	\pgf@y.5\pgf@y%
  	\edef\pgf@marshall{%
  		\noexpand\pgfpointborderrectangle{%
  				\noexpand\pgfqpoint{\the\pgfutil@tempdima}{\the\pgfutil@tempdimb}%
  			}%
      	{%
      		\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}%
      	}%
    }%
    \pgf@marshall%
    \pgf@xa\pgf@x%
    \pgf@ya\pgf@y%
    \centerpoint%
    \advance\pgf@x\pgf@xa%
    \advance\pgf@y\pgf@ya%
   }%
}


% Shape: ellipse split.
%
\pgfdeclareshape{ellipse split}{%
	\nodeparts{text,lower}
	\savedanchor\radii{%
		\pgfmathsetlength\pgf@x{\pgfkeysvalueof{/pgf/inner xsep}}%
		\pgfmathsetlength\pgf@y{\pgfkeysvalueof{/pgf/inner ysep}}%
		\pgf@y2.0\pgf@y%
		\advance\pgf@y.5\pgflinewidth%
		\pgf@xa.5\wd\pgfnodeparttextbox%
		\pgf@xb.5\wd\pgfnodepartlowerbox%
		\advance\pgf@xa\pgf@x%
		\advance\pgf@xb\pgf@x%
		\pgf@ya\ht\pgfnodeparttextbox%
		\advance\pgf@ya\dp\pgfnodeparttextbox%
		\pgf@yb\ht\pgfnodepartlowerbox%
		\advance\pgf@yb\dp\pgfnodepartlowerbox%
		\advance\pgf@ya\pgf@y%
		\advance\pgf@yb\pgf@y%
		\ifdim\pgf@xa>\pgf@xb%
			\pgf@x1.414213\pgf@xa%
		\else%
			\pgf@x1.414213\pgf@xb%
		\fi%
		\ifdim\pgf@ya>\pgf@yb%
			\pgf@y1.414213\pgf@ya%
		\else%
			\pgf@y1.414213\pgf@yb%
		\fi%
		\pgfmathsetlength\pgf@xa{\pgfkeysvalueof{/pgf/minimum width}}%
		\pgfmathsetlength\pgf@ya{\pgfkeysvalueof{/pgf/minimum height}}%
		\ifdim\pgf@x<.5\pgf@xa%
			\pgf@x.5\pgf@xa%
		\fi%
		\ifdim\pgf@y<.5\pgf@ya%
			\pgf@y.5\pgf@ya%
		\fi%
		\pgfmathaddtolength\pgf@x{\pgfkeysvalueof{/pgf/outer xsep}}%
		\pgfmathaddtolength\pgf@y{\pgfkeysvalueof{/pgf/outer ysep}}%
	}
	\savedanchor\lower{%
		\pgf@x-.5\wd\pgfnodepartlowerbox%
		\advance\pgf@x.5\wd\pgfnodeparttextbox%
		\pgfmathsetlength\pgf@y{\pgfkeysvalueof{/pgf/inner ysep}}%
		\pgf@y-2.0\pgf@y%
		\advance\pgf@y-\pgflinewidth%
		\advance\pgf@y-\dp\pgfnodeparttextbox%
		\advance\pgf@y-\ht\pgfnodepartlowerbox%
	}
	\savedanchor\centerpoint{%
		\pgf@x.5\wd\pgfnodeparttextbox%
		\pgfmathsetlength\pgf@y{-\pgfkeysvalueof{/pgf/inner ysep}}%
		\advance\pgf@y-\dp\pgfnodeparttextbox%
		\advance\pgf@y-.5\pgflinewidth%
	}%
	\savedanchor\basepoint{%
		\pgf@x.5\wd\pgfnodeparttextbox%
		\pgf@y0pt\relax%
	}%
	\savedanchor\midpoint{%
		\pgf@x.5\wd\pgfnodeparttextbox%
		\pgfmathsetlength\pgf@y{.5ex}%
	}%
	\anchor{center}{\centerpoint}
	\anchor{lower}{\lower}
	\anchor{mid}{\midpoint}
	\anchor{mid east}{\radii\pgf@xa\pgf@x\midpoint\advance\pgf@x\pgf@xa}
	\anchor{mid west}{\radii\pgf@xa\pgf@x\midpoint\advance\pgf@x-\pgf@xa}
	\anchor{base}{\basepoint}
	\anchor{base east}{\radii\pgf@xa\pgf@x\basepoint\advance\pgf@x\pgf@xa}
	\anchor{base west}{\radii\pgf@xa\pgf@x\basepoint\advance\pgf@x-\pgf@xa}
	\anchor{north}{\pgfpointadd{\centerpoint}{\radii\pgf@x0pt}}%
	\anchor{south}{\pgfpointadd{\centerpoint}{\radii\pgf@x0pt\pgf@y-\pgf@y}}%
	\anchor{east}{\pgfpointadd{\centerpoint}{\radii\pgf@y0pt}}%
	\anchor{west}{\pgfpointadd{\centerpoint}{\radii\pgf@x-\pgf@x\pgf@y0pt}}%	
	\anchor{north west}{\pgfpointadd{\centerpoint}{\radii\pgf@x-0.707106\pgf@x\pgf@y0.707106\pgf@y}}%
	\anchor{south west}{\pgfpointadd{\centerpoint}{\radii\pgf@x-0.707106\pgf@x\pgf@y-0.707106\pgf@y}}%
	\anchor{north east}{\pgfpointadd{\centerpoint}{\radii\pgf@x0.707106\pgf@x\pgf@y0.707106\pgf@y}}%
	\anchor{south east}{\pgfpointadd{\centerpoint}{\radii\pgf@x0.707106\pgf@x\pgf@y-0.707106\pgf@y}}%
	\backgroundpath{%
		\radii%
		\pgfmathaddtolength\pgf@x{-\pgfkeysvalueof{/pgf/outer xsep}}%
		\pgfmathaddtolength\pgf@y{-\pgfkeysvalueof{/pgf/outer ysep}}%
		\pgfutil@tempdima\pgf@x%
		\pgfutil@tempdimb\pgf@y%
		\pgfpathellipse{\centerpoint}{\pgfqpoint{\the\pgfutil@tempdima}{0pt}}{\pgfqpoint{0pt}{\the\pgfutil@tempdimb}}%
		\pgfpathmoveto{\centerpoint\advance\pgf@x-\pgfutil@tempdima}%
		\pgfpathlineto{\centerpoint\advance\pgf@x\pgfutil@tempdima}%
	}
	\anchorborder{%
  	\pgfextract@process\externalpoint{}%
  	\radii%
  	\edef\pgf@marshal{%
   		\noexpand\pgfpointadd{\noexpand\pgfpointborderellipse{\noexpand\externalpoint}%
   			{\noexpand\pgfpoint{\the\pgf@x}{\the\pgf@y}}}{\noexpand\centerpoint}%
   	}%  
   	\pgf@marshal%		
  }%
}

\endinput
