% 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.misc.code.tex,v 1.10 2008/02/12 18:02:25 tantau Exp $


\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{\pgfqpoint{\pgf@xa}{\pgf@ya}}
    \pgfpathlineto{\pgfqpoint{\pgf@xb}{\pgf@yb}}
    \pgfpathmoveto{\pgfqpoint{\pgf@xa}{\pgf@yb}}
    \pgfpathlineto{\pgfqpoint{\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}
 }
}

\pgfkeys{/pgf/.cd,
	rounded rectangle west arc/.initial=convex,
	rounded rectangle east arc/.initial=convex,
	rounded rectangle left arc/.style={/pgf/rounded rectangle west arc=#1},%
	rounded rectangle right arc/.code={/pgf/rounded rectangle east arc=#1},%
	rounded rectangle arc length/.initial=180%
}%

\def\pgf@lib@shapes@roundedrectangle@concave{concave}%
\def\pgf@lib@shapes@roundedrectangle@convex{convex}%

\pgfdeclareshape{rounded rectangle}{
	\savedmacro\leftarc{%
		\edef\leftarc{\pgfkeysvalueof{/pgf/rounded rectangle west arc}}%
	}
	\savedmacro\rightarc{%
		\edef\rightarc{\pgfkeysvalueof{/pgf/rounded rectangle east arc}}%
	}
	\savedmacro\roundedrectanglepoints{%
		%
		% Get half the arc angle.
		%
		\pgfmathsetlength\pgf@x{\pgfkeysvalueof{/pgf/rounded rectangle arc length}}%
		\pgf@x.5\pgf@x%
		\edef\halfarcangle{\pgfmath@tonumber{\pgf@x}}%
		\addtosavedmacro\halfarcangle%		
		%
		% Get the (half) node dimensions x & y.
		%
		\pgfmathsetlength\pgf@x{\pgfkeysvalueof{/pgf/inner xsep}}%
		\advance\pgf@x.5\wd\pgfnodeparttextbox%
		\pgfmathsetlength\pgf@y{\pgfkeysvalueof{/pgf/inner ysep}}%
		\advance\pgf@y.5\ht\pgfnodeparttextbox%
		\advance\pgf@y.5\dp\pgfnodeparttextbox%
                %
                % Adjust for minimum height
                %
		%
		\pgfmathsetlength\pgf@yb{\pgfkeysvalueof{/pgf/minimum height}}%
		\ifdim\pgf@y<.5\pgf@yb%
		  \pgf@y.5\pgf@yb%
		\fi%
		%
		% Calculate the radii xa & ya of the arc ends.
		%
		\pgfmathsetlength\pgfutil@tempdima{\pgfkeysvalueof{/pgf/rounded rectangle arc length}}%
		\pgfutil@tempdima.5\pgfutil@tempdima%
		\pgfmathcosec@{\pgfmath@tonumber{\pgfutil@tempdima}}%
		\pgf@ya\pgfmathresult\pgf@y%
		\pgf@xa\pgf@ya%
		%
		% Calculate the width of the arc end.
		%
		\pgfmathcos@{\pgfmath@tonumber{\pgfutil@tempdima}}%
		\pgf@xb-\pgfmathresult\pgf@xa%
		\advance\pgf@xb\pgf@xa\relax%
		\edef\arcwidth{\the\pgf@xb}%
		\addtosavedmacro{\arcwidth}%
		%
		% Adjust for minimum width
		%
		\pgfmathsetlength\pgf@xb{\pgfkeysvalueof{/pgf/minimum width}}%
		\advance\pgf@x\arcwidth\relax%
		\ifdim\pgf@x<.5\pgf@xb%
			\pgf@x.5\pgf@xb%
		\fi%
		\advance\pgf@x-\arcwidth\relax%
		%
		% Get the outer sep.
		%
		\pgfmathsetlength\pgf@xb{\pgfkeysvalueof{/pgf/outer xsep}}%
		\pgfmathsetlength\pgf@yb{\pgfkeysvalueof{/pgf/outer ysep}}%
		\edef\outerxsep{\the\pgf@xb}%
		\edef\outerysep{\the\pgf@yb}%
		\addtosavedmacro\outerxsep%
		\addtosavedmacro\outerysep%
		%
		\edef\xpathradius{\the\pgf@xa}%
		\edef\ypathradius{\the\pgf@ya}%
		\addtosavedmacro\xpathradius%
		\addtosavedmacro\ypathradius%
		%
		\advance\pgf@xa\pgf@xb%
		\advance\pgf@ya\pgf@yb%
		\edef\xradius{\the\pgf@xa}%
		\edef\yradius{\the\pgf@ya}%
		\addtosavedmacro\xradius%
		\addtosavedmacro\yradius%
		%
		\advance\pgf@xa-2.0\pgf@xb%
		\advance\pgf@ya-2.0\pgf@yb%
		\edef\xinnerradius{\the\pgf@xa}%
		\edef\yinnerradius{\the\pgf@ya}%
		\addtosavedmacro\xinnerradius%
		\addtosavedmacro\yinnerradius%		
		%
		\pgfextract@process\pathcornernoarc{}%
		\addtosavedmacro\pathcornernoarc%
		%
		\pgfextract@process\pathcornerconvexarc{%
			\pathcornernoarc%
			\pgf@xc\arcwidth\relax%
			\advance\pgf@x-.707106\pgf@xc
		}%
		\addtosavedmacro\pathcornerconvexarc%
		%
		\pgfextract@process\pathcornerconcavearc{%
			\pathcornernoarc%
			\advance\pgf@x\arcwidth\relax%
		}%
		\addtosavedmacro\pathcornerconcavearc%
		%
		\pgfextract@process\anchorcornernoarc{%
			\pathcornernoarc%
			\advance\pgf@x\pgf@xb%
			\advance\pgf@y\pgf@yb%
		}%
		\addtosavedmacro\anchorcornernoarc%
		%
		\pgfextract@process\anchorcornerconvexarc{%
			\pathcornerconvexarc%
			\ifdim\halfarcangle pt=90pt\relax%
			\else%
				\pgfmathsin@{\halfarcangle}%
				\pgf@xa\xpathradius\relax%
				\pgf@xa\pgfmathresult\pgf@xa%
				\pgfmathcos@{\halfarcangle}%
				\pgf@ya\ypathradius\relax%
				\pgf@ya\pgfmathresult\pgf@ya%
				%
				\pgfmathdivide@{\pgfmath@tonumber{\pgf@ya}}{\pgfmath@tonumber{\pgf@xa}}%
				\pgfmathatan@{\pgfmathresult}%
				\let\angle\pgfmathresult%				
				\pgfmathadd@{90}{\angle}%
				\pgfmathcosec@{\pgfmathresult}%
				\pgf@xb\pgfmathresult\pgf@xb%
				\pgfmathadd@{90}{\halfarcangle}%
				\pgfmathdivide@{\pgfmathresult}{2}%
				\pgfmathcos@{\pgfmathresult}%
				\advance\pgf@x\pgfmathresult\pgf@xb%
			\fi%
			\advance\pgf@y\pgf@yb%
		}%
		\addtosavedmacro\anchorcornerconvexarc%
		%
		\pgfextract@process\anchorcornerconcavearc{%
			\pathcornerconcavearc%
			\ifdim\halfarcangle pt=90pt\relax%
			\else%
				\pgfmathsin@{\halfarcangle}%
				\pgf@xa\xpathradius\relax%
				\pgf@xa\pgfmathresult\pgf@xa%
				\pgfmathcos@{\halfarcangle}%
				\pgf@ya\ypathradius\relax%
				\pgf@ya\pgfmathresult\pgf@ya%
				%
				\pgfmathdivide@{\pgfmath@tonumber{\pgf@ya}}{\pgfmath@tonumber{\pgf@xa}}%
				\pgfmathatan@{\pgfmathresult}%
				\pgfmathdivide@{\pgfmathresult}{2}%
				\let\angle\pgfmathresult%
				\pgfmathcosec@{\pgfmathresult}%
				\pgf@xb\pgfmathresult\pgf@xb%
				\pgfmathcos@{\angle}%
				\advance\pgf@x\pgfmathresult\pgf@xb%
			\fi%
			\advance\pgf@y\pgf@yb%
		}%
		\addtosavedmacro\anchorcornerconcavearc%
		%	
	}%
	\saveddimen\halflinewidth{\pgf@x.5\pgflinewidth}%
	\savedanchor\centerpoint{%
		\pgf@x.5\wd\pgfnodeparttextbox%
		\pgf@y.5\ht\pgfnodeparttextbox%
		\advance\pgf@y-.5\dp\pgfnodeparttextbox%		
	}	
	\savedanchor\midpoint{%
		\pgf@x.5\wd\pgfnodeparttextbox%
		\pgfmathsetlength\pgf@y{+0.5ex}%	
	}	
	\savedanchor\basepoint{%
		\pgf@x.5\wd\pgfnodeparttextbox%
		\pgf@y0pt\relax%
	}	
	\anchor{center}{\centerpoint}%
	\anchor{mid}{\midpoint}%
	\anchor{mid east}{%
		\roundedrectanglepoints%
		\ifx\rightarc\pgf@lib@shapes@roundedrectangle@convex%
			\csname pgf@anchor@rounded rectangle@east\endcsname%
		\else%
			\csname pgf@anchor@rounded rectangle@south east\endcsname%
		\fi%
		\pgf@xa\pgf@x%
		\midpoint%
		\pgf@x\pgf@xa%
	}%
	\anchor{mid west}{%
		\roundedrectanglepoints%
		\ifx\rightarc\pgf@lib@shapes@roundedrectangle@convex%
			\csname pgf@anchor@rounded rectangle@west\endcsname%
		\else%
			\csname pgf@anchor@rounded rectangle@south west\endcsname%
		\fi%
		\pgf@xa\pgf@x%
		\midpoint%
		\pgf@x\pgf@xa%
	}%
	\anchor{base}{\basepoint}%
	\anchor{base east}{%
		\roundedrectanglepoints%
		\ifx\rightarc\pgf@lib@shapes@roundedrectangle@convex%
			\csname pgf@anchor@rounded rectangle@east\endcsname%
		\else%
			\csname pgf@anchor@rounded rectangle@south east\endcsname%
		\fi%
		\pgf@y0pt%
	}%
	\anchor{base west}{%
		\roundedrectanglepoints%
		\ifx\rightarc\pgf@lib@shapes@roundedrectangle@convex%
			\csname pgf@anchor@rounded rectangle@west\endcsname%
		\else%
			\csname pgf@anchor@rounded rectangle@south west\endcsname%
		\fi%
		\pgf@y0pt%
	}%
	\anchor{north}{%
		\pgfpointadd{\centerpoint}{%
			\roundedrectanglepoints%
			\anchorcornernoarc%
			\pgf@x0pt%
		}%
	}%
	\anchor{east}{%
		\pgfpointadd{\centerpoint}{%
			\roundedrectanglepoints%
			\ifx\rightarc\pgf@lib@shapes@roundedrectangle@convex%
				\pathcornerconvexarc%
				\advance\pgf@x\arcwidth\relax%
				\advance\pgf@x\outerxsep\relax%
			\else%
				\ifx\rightarc\pgf@lib@shapes@roundedrectangle@concave%
					\pathcornerconcavearc%
					\advance\pgf@x-\arcwidth\relax%
					\advance\pgf@x\outerxsep\relax%
				\else%
					\anchorcornernoarc%
				\fi%
			\fi%	
			\pgf@y0pt\relax%	
		}%
	}%
	\anchor{west}{%
		\pgfpointadd{\centerpoint}{%
			\roundedrectanglepoints%
			\ifx\leftarc\pgf@lib@shapes@roundedrectangle@convex%
				\pathcornerconvexarc%
				\advance\pgf@x\arcwidth\relax%
				\advance\pgf@x\outerxsep\relax%
			\else%
				\ifx\leftarc\pgf@lib@shapes@roundedrectangle@concave%
					\pathcornerconcavearc%
					\advance\pgf@x-\arcwidth\relax%
					\advance\pgf@x\outerxsep\relax%
				\else%
					\anchorcornernoarc%
				\fi%
			\fi%	
			\pgf@x-\pgf@x%
			\pgf@y0pt\relax%	
		}%
	}%
	\anchor{south}{%
		\pgfpointadd{\centerpoint}{%
			\roundedrectanglepoints%
			\anchorcornernoarc%
			\pgf@x0pt%
			\pgf@y-\pgf@y
		}%
	}%
	\anchor{north east}{%
		\pgfpointadd{\centerpoint}{%
			\roundedrectanglepoints%
			\ifx\rightarc\pgf@lib@shapes@roundedrectangle@convex%
				\anchorcornerconvexarc%
			\else%
				\ifx\rightarc\pgf@lib@shapes@roundedrectangle@concave%
					\anchorcornerconcavearc%
				\else%
					\anchorcornernoarc%
				\fi%
			\fi%		
		}%
	}%
	\anchor{north west}{%
		\pgfpointadd{\centerpoint}{%
			\roundedrectanglepoints%
			\ifx\leftarc\pgf@lib@shapes@roundedrectangle@convex%
				\anchorcornerconvexarc%
			\else%
				\ifx\leftarc\pgf@lib@shapes@roundedrectangle@concave%
					\anchorcornerconcavearc%
				\else%
					\anchorcornernoarc%
				\fi%
			\fi%
			\pgf@x-\pgf@x%		
		}%
	}%
	\anchor{south west}{%
		\pgfpointadd{\centerpoint}{%
			\roundedrectanglepoints%
			\ifx\leftarc\pgf@lib@shapes@roundedrectangle@convex%
				\anchorcornerconvexarc%
			\else%
				\ifx\leftarc\pgf@lib@shapes@roundedrectangle@concave%
					\anchorcornerconcavearc%
				\else%
					\anchorcornernoarc%
				\fi%
			\fi%
			\pgf@x-\pgf@x%
			\pgf@y-\pgf@y%		
		}%
	}%
	\anchor{south east}{%
		\pgfpointadd{\centerpoint}{%
			\roundedrectanglepoints%
			\ifx\rightarc\pgf@lib@shapes@roundedrectangle@convex%
				\anchorcornerconvexarc%
			\else%
				\ifx\rightarc\pgf@lib@shapes@roundedrectangle@concave%
					\anchorcornerconcavearc%
				\else%
					\anchorcornernoarc%
				\fi%
			\fi%
			\pgf@y-\pgf@y%		
		}%
	}%
	\anchor{shape center}{%
		\roundedrectanglepoints%
		\pgfpointadd{\centerpoint}{%
			\pgfpointadd{%
				\ifx\rightarc\pgf@lib@shapes@roundedrectangle@convex%
					\pathcornerconvexarc%
				\else%
					\ifx\rightarc\pgf@lib@shapes@roundedrectangle@concave%
						\pathcornerconcavearc%
					\else%
						\pathcornernoarc%
					\fi%
				\fi}%
			{%
				\pgfpointadd{%
					\ifx\rightarc\pgf@lib@shapes@roundedrectangle@convex%
						\pathcornerconvexarc%
					\else%
						\ifx\rightarc\pgf@lib@shapes@roundedrectangle@concave%
							\pathcornerconcavearc%
						\else%
							\pathcornernoarc%
						\fi%
					\fi
					\pgf@x-\pgf@x}%
				{%
					\pgfpointadd{%
						\ifx\leftarc\pgf@lib@shapes@roundedrectangle@convex%
							\pathcornerconvexarc%
						\else%
							\ifx\leftarc\pgf@lib@shapes@roundedrectangle@concave%
								\pathcornerconcavearc%
							\else%
								\pathcornernoarc%
							\fi%
						\fi
						\pgf@x-\pgf@x%
						\pgf@y-\pgf@y}% 
					{%
						\ifx\rightarc\pgf@lib@shapes@roundedrectangle@convex%
							\pathcornerconvexarc%
						\else%
							\ifx\rightarc\pgf@lib@shapes@roundedrectangle@concave%
								\pathcornerconcavearc%
							\else%
								\pathcornernoarc%
							\fi%
						\fi
						\pgf@y-\pgf@y%
					}%
				}%
			}%
			\divide\pgf@x4\relax%
			\divide\pgf@y4\relax%
		}%
	}%
	\backgroundpath{%
		{%
			\pgftransformshift{\centerpoint}%
			\roundedrectanglepoints%
			%
			\pgf@x\xradius\relax%
			\pgf@y\yradius\relax%
			\advance\pgf@x-\outerxsep\relax%
			\advance\pgf@y-\outerysep\relax%
			\edef\xradius{\the\pgf@x}%
			\edef\yradius{\the\pgf@y}%
			%
			\pgfpathmoveto{%
				\ifx\rightarc\pgf@lib@shapes@roundedrectangle@convex%
					\pathcornerconvexarc%
				\else%
					\ifx\rightarc\pgf@lib@shapes@roundedrectangle@concave%
						\pathcornerconcavearc%
					\else%
						\pathcornernoarc%
					\fi%
				\fi%			
			}%
			\ifx\rightarc\pgf@lib@shapes@roundedrectangle@convex%
				\pgfpatharc{\halfarcangle}{-\halfarcangle}{\xradius and \yradius}%
			\else%
				\ifx\rightarc\pgf@lib@shapes@roundedrectangle@concave%
					\pgfpatharc{180-\halfarcangle}{180+\halfarcangle}{\xradius and \yradius}%
				\else%
					\pgfpathlineto{\pathcornernoarc\pgf@y-\pgf@y}%
				\fi%
			\fi%
			\pgfpathlineto{%
				\ifx\leftarc\pgf@lib@shapes@roundedrectangle@convex%
					\pathcornerconvexarc%
				\else%
					\ifx\leftarc\pgf@lib@shapes@roundedrectangle@concave%
						\pathcornerconcavearc%
					\else%
						\pathcornernoarc%
					\fi%
				\fi%	
				\pgf@x-\pgf@x%
				\pgf@y-\pgf@y%		
			}%
			\ifx\leftarc\pgf@lib@shapes@roundedrectangle@convex%
				\pgfpatharc{180+\halfarcangle}{180-\halfarcangle}{\xradius and \yradius}%
			\else%
				\ifx\leftarc\pgf@lib@shapes@roundedrectangle@concave%
					\pgfpatharc{-\halfarcangle}{\halfarcangle}{\xradius and \yradius}%
				\else%
					\pgfpathlineto{\pathcornernoarc\pgf@x-\pgf@x}%
				\fi%
			\fi%
			\pgfpathclose%
		}%
	}
	\anchorborder{%
		\pgfextract@process\externalpoint{%
			\pgfextract@process\externalpoint{}%
			\pgfpointadd{\centerpoint}{\externalpoint}%
		}%
		\roundedrectanglepoints%
		%
		\pgfmathanglebetweenpoints{\centerpoint}{\externalpoint}%
		\let\externalangle\pgfmathresult%
		%
		\pgfmathanglebetweenpoints{\centerpoint}{\csname pgf@anchor@rounded rectangle@west\endcsname}%
		\ifdim\externalangle pt<\pgfmathresult pt\relax%
			\pgfmathanglebetweenpoints{\centerpoint}{\csname pgf@anchor@rounded rectangle@north\endcsname}%
			\ifdim\externalangle pt<\pgfmathresult pt\relax%
				\pgfmathanglebetweenpoints{\centerpoint}{\csname pgf@anchor@rounded rectangle@north east\endcsname}%
				\ifdim\externalangle pt<\pgfmathresult pt\relax%
					\ifx\rightarc\pgf@lib@shapes@roundedrectangle@convex%
						\pgfmathpointintersectionoflineandarc{\externalpoint}{\centerpoint}%
						{%
							\csname pgf@anchor@rounded rectangle@east\endcsname%
							\advance\pgf@x-\xradius\relax%
						}%
						{0}{\halfarcangle}{\xradius and \yradius}%
					\else%
						\ifx\rightarc\pgf@lib@shapes@roundedrectangle@concave%
							\pgfmathpointintersectionoflineandarc{\centerpoint}{\externalpoint}%
							{%
								\centerpoint%
								\pgf@xa\pgf@x%
								\pgf@ya\pgf@y%
								\pathcornernoarc%
								\advance\pgf@x\pgf@xa%
								\pgf@y\pgf@ya%
								\advance\pgf@x\xpathradius\relax%
							}%
							{180-\halfarcangle}{180}{\xinnerradius and \yinnerradius}%
						\else%
						\pgfpointintersectionoflines{\centerpoint}{\externalpoint}%
							{\csname pgf@anchor@rounded rectangle@north east\endcsname}%
							{\csname pgf@anchor@rounded rectangle@south east\endcsname}%
						\fi%
					\fi%
				\else%
					\pgfpointintersectionoflines{\centerpoint}{\externalpoint}%
						{\csname pgf@anchor@rounded rectangle@north east\endcsname}%
						{\csname pgf@anchor@rounded rectangle@north west\endcsname}%
				\fi%
			\else%
				\pgfmathanglebetweenpoints{\centerpoint}{\csname pgf@anchor@rounded rectangle@north west\endcsname}%
				\ifdim\externalangle pt<\pgfmathresult pt\relax%
					\pgfpointintersectionoflines{\centerpoint}{\externalpoint}%
						{\csname pgf@anchor@rounded rectangle@north east\endcsname}%
						{\csname pgf@anchor@rounded rectangle@north west\endcsname}%
				\else%
					\ifx\leftarc\pgf@lib@shapes@roundedrectangle@convex%
							\pgfmathpointintersectionoflineandarc{\externalpoint}{\centerpoint}%
							{%
								\csname pgf@anchor@rounded rectangle@west\endcsname%
								\advance\pgf@x\xradius\relax%
							}%
							{180-\halfarcangle}{180}{\xradius and \yradius}%
					\else%
						\ifx\leftarc\pgf@lib@shapes@roundedrectangle@concave%
							\pgfmathpointintersectionoflineandarc{\centerpoint}{\externalpoint}%
								{%
									\centerpoint%
									\pgf@xa\pgf@x%
									\pgf@ya\pgf@y%
									\pathcornernoarc%
									\pgf@x-\pgf@x%
									\advance\pgf@x\pgf@xa%
									\pgf@y\pgf@ya%
									\advance\pgf@x-\xpathradius\relax%
								}%
								{0}{\halfarcangle}{\xinnerradius and \yinnerradius}%
						\else%
							\pgfpointintersectionoflines{\centerpoint}{\externalpoint}%
								{\csname pgf@anchor@rounded rectangle@north west\endcsname}%
								{\csname pgf@anchor@rounded rectangle@south west\endcsname}%
						\fi%
					\fi%
				\fi%
			\fi%
		\else%
			\pgfmathanglebetweenpoints{\centerpoint}{\csname pgf@anchor@rounded rectangle@south\endcsname}%
			\ifdim\externalangle pt<\pgfmathresult pt\relax%
				\pgfmathanglebetweenpoints{\centerpoint}{\csname pgf@anchor@rounded rectangle@south west\endcsname}%
				\ifdim\externalangle pt<\pgfmathresult pt\relax%
					\ifx\leftarc\pgf@lib@shapes@roundedrectangle@convex%
						\pgfmathpointintersectionoflineandarc{\externalpoint}{\centerpoint}%
						{%
							\csname pgf@anchor@rounded rectangle@west\endcsname%
							\advance\pgf@x\xradius\relax%
						}%
						{180}{180+\halfarcangle}{\xradius and \yradius}%
					\else%
						\ifx\leftarc\pgf@lib@shapes@roundedrectangle@concave%
							\pgfmathpointintersectionoflineandarc{\centerpoint}{\externalpoint}%
								{%
									\centerpoint%
									\pgf@xa\pgf@x%
									\pgf@ya\pgf@y%
									\pathcornernoarc%
									\pgf@x-\pgf@x%
									\advance\pgf@x\pgf@xa%
									\pgf@y\pgf@ya%
									\advance\pgf@x-\xpathradius\relax%
								}%
								{360-\halfarcangle}{360}{\xinnerradius and \yinnerradius}%
						\else%
							\pgfpointintersectionoflines{\centerpoint}{\externalpoint}%
								{\csname pgf@anchor@rounded rectangle@north west\endcsname}%
								{\csname pgf@anchor@rounded rectangle@south west\endcsname}%
						\fi%
					\fi%
				\else%
					\pgfpointintersectionoflines{\centerpoint}{\externalpoint}%
						{\csname pgf@anchor@rounded rectangle@south west\endcsname}%
						{\csname pgf@anchor@rounded rectangle@south east\endcsname}%
				\fi%
			\else%
				\pgfmathanglebetweenpoints{\centerpoint}{\csname pgf@anchor@rounded rectangle@south east\endcsname}%
				\ifdim\externalangle pt<\pgfmathresult pt\relax%
					\pgfpointintersectionoflines{\centerpoint}{\externalpoint}%
						{\csname pgf@anchor@rounded rectangle@south west\endcsname}%
						{\csname pgf@anchor@rounded rectangle@south east\endcsname}%
				\else%
					\ifx\rightarc\pgf@lib@shapes@roundedrectangle@convex%
						\pgfmathpointintersectionoflineandarc{\externalpoint}{\centerpoint}%
						{%
							\csname pgf@anchor@rounded rectangle@east\endcsname%
							\advance\pgf@x-\xradius\relax%
						}%
						{360-\halfarcangle}{360}{\xradius and \yradius}%
					\else%
						\ifx\rightarc\pgf@lib@shapes@roundedrectangle@concave%
							\pgfmathpointintersectionoflineandarc{\centerpoint}{\externalpoint}%
								{%
									\centerpoint%
									\pgf@xa\pgf@x%
									\pgf@ya\pgf@y%
									\pathcornernoarc%
									\advance\pgf@x\pgf@xa%
									\pgf@y\pgf@ya%
									\advance\pgf@x\xpathradius\relax%
								}%
								{180}{180+\halfarcangle}{\xinnerradius and \yinnerradius}%
						\else%
							\pgfpointintersectionoflines{\centerpoint}{\externalpoint}%
								{\csname pgf@anchor@rounded rectangle@south east\endcsname}%
								{\csname pgf@anchor@rounded rectangle@north east\endcsname}%
						\fi%
					\fi%
				\fi%
			\fi%
		\fi%
	}%
}




% Keys for chamfered rectangle
%
% /pgf/chamfered rectangle corners : specify the corners to chamfer.
% /pgf/chamfered rectangle angle   : set the angle of the chamfer.
% /pgf/chamfered rectangle xsep    : set the extent of the x chamferling.
% /pgf/chamfered rectangle ysep    : set the extent of the y chamferling.

\pgfkeys{/pgf/chamfered rectangle corners/.store in=\pgf@chamferedrectangle@corners}
\pgfkeys{/tikz/chamfered rectangle corners/.store in=\pgf@chamferedrectangle@corners}

\def\pgf@chamferedrectangle@chamferall{chamfer all}%
\def\pgf@chamferedrectangle@chamfer{chamfer}
\let\pgf@chamferedrectangle@corners\pgf@chamferedrectangle@chamferall


\def\pgf@chamferedrectangle@getcorners{%
	\let\northeastcorner\pgfutil@empty%
	\let\southeastcorner\pgfutil@empty%
	\let\southwestcorner\pgfutil@empty%
	\let\northwestcorner\pgfutil@empty%
	\expandafter\pgfutil@in@\expandafter{\pgf@chamferedrectangle@corners}{chamfer all}%
	\ifpgfutil@in@%
		\let\northeastcorner\pgf@chamferedrectangle@round%
		\let\southeastcorner\pgf@chamferedrectangle@round%
		\let\southwestcorner\pgf@chamferedrectangle@round%
		\let\northwestcorner\pgf@chamferedrectangle@round%
		\let\pgf@next\relax%
	\else%	
		\let\pgf@next\pgf@chamferedrectangle@parsecorners%
	\fi%
	\pgf@next}

\def\pgf@chamferedrectangle@parsecorners{%
	\expandafter\pgf@@chamferedrectangle@parsecorners\pgf@chamferedrectangle@corners,\pgf@stop,%
}
		
\def\pgf@@chamferedrectangle@parsecorners#1,{%
	\ifx#1\pgf@stop%
		\let\pgf@next\relax%
	\else%
		\pgfutil@in@{@#1@}{@north east@@top left@}%
		\ifpgfutil@in@%
			\let\northeastcorner\pgf@chamferedrectangle@chamfer%
		\else%
			\pgfutil@in@{@#1@}{@south east@@bottom right@}%
			\ifpgfutil@in@%
				\let\southeastcorner\pgf@chamferedrectangle@chamfer%
			\else%
				\pgfutil@in@{@#1@}{@south west@@bottom left@}%
				\ifpgfutil@in@%
					\let\southwestcorner\pgf@chamferedrectangle@chamfer%
				\else%
					\pgfutil@in@{@#1@}{@north west@@top right@}%
					\ifpgfutil@in@%
						\let\southeastcorner\pgf@chamferedrectangle@round%
					\fi%
				\fi%
			\fi%
		\fi%
		\let\pgf@next\pgf@@@chamferedrectangle@parsecorners%
	\fi%
	\pgf@next%
}
\def\pgf@@@chamferedrectangle@parsecorners{%
	\pgfutil@ifnextchar x{\pgf@@chamferedrectangle@parsecorners}{\pgf@@chamferedrectangle@parsecorners}%
}%

\pgfkeys{/pgf/.cd,
	chamfered rectangle angle/.initial=45,%
	chamfered rectangle xsep/.initial=.666ex,%
	chamfered rectangle ysep/.initial=.666ex%
}
 \pgfkeys{/pgf/chamfered rectangle sep/.style={%
	/pgf/chamfered rectangle xsep=#1,/pgf/chamfered rectangle ysep=#1}%
}




% Shape chamfered rectangle.
%
%
\pgfdeclareshape{chamfered rectangle}{%
	\savedmacro\getchamferedrectanglepoints{%
		\pgf@chamferedrectangle@getcorners%
		%
		% Get the node dimensions.
		%
		\pgfmathsetlength\pgf@xa{\pgfkeysvalueof{/pgf/inner xsep}}%
		\advance\pgf@xa.5\wd\pgfnodeparttextbox%
		\pgfmathsetlength\pgf@ya{\pgfkeysvalueof{/pgf/inner ysep}}%
		\advance\pgf@ya.5\ht\pgfnodeparttextbox%
		\advance\pgf@ya.5\dp\pgfnodeparttextbox%
		%
		% Get chamfer stuff. 
		%
		\pgfmathsetlength\pgfutil@tempdima{\pgfkeysvalueof{/pgf/chamfered rectangle angle}}%
		\ifdim\pgfutil@tempdima<89pt\relax%
			\ifdim\pgfutil@tempdima<1pt\relax%
				\pgfutil@tempdima1pt\relax%
			\fi%
		\else%		
			\pgfutil@tempdima89pt\relax%
		\fi%
		\pgfutil@tempdima-\pgfutil@tempdima%
		\advance\pgfutil@tempdima90pt\relax%
		\pgfmathtan@{\pgfmath@tonumber{\pgfutil@tempdima}}%
		\let\tanangle\pgfmathresult%
		\pgfmathcot@{\pgfmath@tonumber{\pgfutil@tempdima}}%
		\let\cotangle\pgfmathresult%
		\pgfmathsetlength\pgf@xb{\pgfkeysvalueof{/pgf/chamfered rectangle xsep}}%
		\pgf@yc\tanangle\pgf@xb%
		\ifdim\pgf@yc>\pgf@ya%
			\pgf@yc\pgf@ya%
			\pgf@xb\cotangle\pgf@yc%
		\fi%
		\pgfmathcot@{\pgfmath@tonumber{\pgfutil@tempdima}}%
		\pgfmathsetlength\pgf@yb{\pgfkeysvalueof{/pgf/chamfered rectangle ysep}}%
		\pgf@xc\cotangle\pgf@yb%
			\ifdim\pgf@xc>\pgf@xa%
			\pgf@xc\pgf@xa%
			\pgf@yb\tanangle\pgf@xc%
		\fi%
		%
		% Check for minimum width and height%
		%
		\pgfutil@tempdima\pgf@xa%
		\advance\pgfutil@tempdima\pgf@xb%
		\pgfmathsetlength\pgfutil@tempdimb{\pgfkeysvalueof{/pgf/minimum width}}%
		\ifdim\pgfutil@tempdima<.5\pgfutil@tempdimb%
			\pgf@xa.5\pgfutil@tempdimb%
			\advance\pgf@xa-\pgf@xb%
		\fi%
		\pgfutil@tempdima\pgf@ya%
		\advance\pgfutil@tempdima\pgf@yb%
		\pgfmathsetlength\pgfutil@tempdimb{\pgfkeysvalueof{/pgf/minimum height}}%
		\ifdim\pgfutil@tempdima<.5\pgfutil@tempdimb%
			\pgf@ya.5\pgfutil@tempdimb%
			\advance\pgf@ya-\pgf@yb%
		\fi%		
		%
		% Define the background path points.
		%
		\pgfextract@process\centerpoint{%
			\pgfmathsetlength\pgf@x{+.5\wd\pgfnodeparttextbox}%
			\pgfmathsetlength\pgf@y{+.5\ht\pgfnodeparttextbox}%
			\pgfmathaddtolength\pgf@y{+-.5\dp\pgfnodeparttextbox}%
		}%
		\pgfextract@process\beforenortheast{%
			\centerpoint%
			\advance\pgf@x\pgf@xa%
			\advance\pgf@x\pgf@xb%
			\advance\pgf@y\pgf@ya%
			\advance\pgf@y-\pgf@yc%
		}%
		\pgfextract@process\northeast{%
			\centerpoint%
			\advance\pgf@x\pgf@xa%
			\advance\pgf@y\pgf@ya%
			\ifx\northeastcorner\pgfutil@empty%
				\advance\pgf@x\pgf@xb%
				\advance\pgf@y\pgf@yb%
			\fi%
		}%
		\pgfextract@process\afternortheast{%
			\centerpoint%
			\advance\pgf@x\pgf@xa%
			\advance\pgf@x-\pgf@xc%
			\advance\pgf@y\pgf@ya%
			\advance\pgf@y\pgf@yb%
		}%	
		\pgfextract@process\northwest{%
			\centerpoint%
			\advance\pgf@x-\pgf@xa%
			\advance\pgf@y\pgf@ya%
			\ifx\northwestcorner\pgfutil@empty%
				\advance\pgf@x-\pgf@xb%
				\advance\pgf@y\pgf@yb%
			\fi%
		}%
		\pgfextract@process\beforesouthwest{%
			\centerpoint%
			\advance\pgf@x-\pgf@xa%
			\advance\pgf@x-\pgf@xb%
			\advance\pgf@y-\pgf@ya%
			\advance\pgf@y\pgf@yc%
		}%
		\pgfextract@process\southwest{%
			\centerpoint%
			\advance\pgf@x-\pgf@xa%
			\advance\pgf@y-\pgf@ya%
			\ifx\southwestcorner\pgfutil@empty%
				\advance\pgf@x-\pgf@xb%
				\advance\pgf@y-\pgf@yb%
			\fi%
		}%
		\pgfextract@process\aftersouthwest{%
			\centerpoint%
			\advance\pgf@x-\pgf@xa%
			\advance\pgf@x\pgf@xc%
			\advance\pgf@y-\pgf@ya%
			\advance\pgf@y-\pgf@yb%
		}%
		\pgfextract@process\southeast{%
			\centerpoint%
			\advance\pgf@x\pgf@xa%
			\advance\pgf@y-\pgf@ya%
			\ifx\southeastcorner\pgfutil@empty%
				\advance\pgf@x\pgf@xb%
				\advance\pgf@y-\pgf@yb%
			\fi%
		}%
		%
		% Calculate the `miter' vectors.
		%
		\pgfmathanglebetweenlines{\beforenortheast}{\afternortheast}{\beforenortheast}%
			{\beforesouthwest\pgf@ya\pgf@y\beforenortheast\pgf@y\pgf@ya}%
		\pgfutil@tempdima\pgfmathresult pt\relax%
		\ifdim\pgfutil@tempdima>180pt\relax%
			\advance\pgfutil@tempdima-180pt\relax%
		\fi%
		\pgfmathsetlength\pgfutil@tempdimb{\pgfkeysvalueof{/pgf/outer xsep}}%
		\ifdim\pgfutil@tempdima<90pt\relax%
			\pgfmathcosec@{\pgfmath@tonumber{\pgfutil@tempdima}}%
			\pgfutil@tempdimb\pgfmathresult\pgfutil@tempdimb%
			\pgfutil@tempdima0pt\relax%
		\else%
			\pgfutil@tempdima.5\pgfutil@tempdima%
			\pgfmathcosec@{\pgfmath@tonumber{\pgfutil@tempdima}}%
			\pgfutil@tempdimb\pgfmathresult\pgfutil@tempdimb%
			\pgfutil@tempdima-\pgfutil@tempdima%
			\advance\pgfutil@tempdima90pt\relax%
		\fi%
		\pgfextract@process\before@ne@anchor{%
			\beforenortheast%
			\pgf@xa\pgf@x%
			\pgf@ya\pgf@y%
			\pgfqpointpolar{\pgfmath@tonumber{\pgfutil@tempdima}}{\the\pgfutil@tempdimb}%
			\advance\pgf@x\pgf@xa%
			\advance\pgf@y\pgf@ya%
		}%
		\pgfutil@tempdima-\pgfutil@tempdima%
		\advance\pgfutil@tempdima180pt\relax%
		\pgfextract@process\before@sw@anchor{%
			\beforesouthwest%
			\pgf@xa\pgf@x%
			\pgf@ya\pgf@y%
			\pgfqpointpolar{-\pgfmath@tonumber{\pgfutil@tempdima}}{\the\pgfutil@tempdimb}%
			\advance\pgf@x\pgf@xa%
			\advance\pgf@y\pgf@ya%
		}%
		%
		\pgfmathanglebetweenlines{\afternortheast}{\aftersouthwest\pgf@xa\pgf@x\afternortheast\pgf@x\pgf@xa}%
			{\afternortheast}{\beforenortheast}%
		\pgfutil@tempdima\pgfmathresult pt\relax%
		\ifdim\pgfutil@tempdima>270pt\relax%
			\advance\pgfutil@tempdima-270pt\relax%
		\fi%
		\pgfmathsetlength\pgfutil@tempdimb{\pgfkeysvalueof{/pgf/outer ysep}}%
		\ifdim\pgfutil@tempdima<90pt\relax%
			\pgfmathcosec@{\pgfmath@tonumber{\pgfutil@tempdima}}%
			\pgfutil@tempdimb\pgfmathresult\pgfutil@tempdimb%
			\pgfutil@tempdima90pt\relax%
		\else%
			\pgfutil@tempdima.5\pgfutil@tempdima%
			\pgfmathcosec@{\pgfmath@tonumber{\pgfutil@tempdima}}%
			\pgfutil@tempdimb\pgfmathresult\pgfutil@tempdimb%
		\fi%		
		%
		\pgfextract@process\after@ne@anchor{%
			\afternortheast%
			\pgf@xa\pgf@x%
			\pgf@ya\pgf@y%
			\pgfqpointpolar{\pgfmath@tonumber{\pgfutil@tempdima}}{\the\pgfutil@tempdimb}%
			\advance\pgf@x\pgf@xa%
			\advance\pgf@y\pgf@ya%
		}%
		\pgfutil@tempdima-\pgfutil@tempdima%
		\advance\pgfutil@tempdima180pt\relax%
		\pgfextract@process\after@sw@anchor{%
			\aftersouthwest
			\pgf@xa\pgf@x%
			\pgf@ya\pgf@y%
			\pgfqpointpolar{-\pgfmath@tonumber{\pgfutil@tempdima}}{\the\pgfutil@tempdimb}%
			\advance\pgf@x\pgf@xa%
			\advance\pgf@y\pgf@ya%
		}%
		\addtosavedmacro\before@ne@anchor%
		\addtosavedmacro\after@ne@anchor%
		\addtosavedmacro\before@sw@anchor%
		\addtosavedmacro\after@sw@anchor%
		\pgfextract@process\ne@anchor{%
			\ifx\northeastcorner\pgfutil@empty%
				\northeast%
				\pgfmathaddtolength\pgf@x{\pgfkeysvalueof{/pgf/outer xsep}}%
				\pgfmathaddtolength\pgf@y{\pgfkeysvalueof{/pgf/outer ysep}}%
			\else%
				\pgfpointlineattime{0.5}{\before@ne@anchor}{\after@ne@anchor}%
			\fi%
		}%
		\pgfextract@process\nw@anchor{%
			\ifx\northwestcorner\pgfutil@empty%
				\northwest%
				\pgfmathaddtolength\pgf@x{-\pgfkeysvalueof{/pgf/outer xsep}}%
				\pgfmathaddtolength\pgf@y{\pgfkeysvalueof{/pgf/outer ysep}}%
			\else%
				\pgfpointlineattime{0.5}{%
					\before@ne@anchor%
					\pgf@ya\pgf@y
					\before@sw@anchor%
					\pgf@y\pgf@ya%
				}{%
					\after@ne@anchor%
					\pgf@ya\pgf@y
					\after@sw@anchor%
					\pgf@y\pgf@ya%
				}%
			\fi%
		}%
		\pgfextract@process\sw@anchor{%
			\ifx\southwestcorner\pgfutil@empty%
				\southwest%
				\pgfmathaddtolength\pgf@x{-\pgfkeysvalueof{/pgf/outer xsep}}%
				\pgfmathaddtolength\pgf@y{-\pgfkeysvalueof{/pgf/outer ysep}}%
			\else%
				\pgfpointlineattime{0.5}{\before@sw@anchor}{\after@sw@anchor}%
			\fi%
		}%
		\pgfextract@process\se@anchor{%
			\ifx\southeastcorner\pgfutil@empty%
				\southeast%
				\pgfmathaddtolength\pgf@x{\pgfkeysvalueof{/pgf/outer xsep}}%
				\pgfmathaddtolength\pgf@y{-\pgfkeysvalueof{/pgf/outer ysep}}%
			\else%
				\pgfpointlineattime{0.5}{%
					\before@ne@anchor%
					\pgf@xa\pgf@x
					\before@sw@anchor%
					\pgf@x\pgf@xa%
				}{%
					\after@ne@anchor%
					\pgf@xa\pgf@x
					\after@sw@anchor%
					\pgf@x\pgf@xa%
				}%
			\fi%
		}%
		\addtosavedmacro\ne@anchor%
		\addtosavedmacro\nw@anchor%
		\addtosavedmacro\sw@anchor%
		\addtosavedmacro\se@anchor%
	}%
	\savedanchor\centerpoint{%
		\pgf@x.5\wd\pgfnodeparttextbox%
		\pgf@y.5\ht\pgfnodeparttextbox%
		\advance\pgf@y-.5\dp\pgfnodeparttextbox%
	}%
	\savedanchor\midpoint{%
		\pgf@x.5\wd\pgfnodeparttextbox%
		\pgfmathsetlength\pgf@y{+.5ex}%
	}%
	\savedanchor\basepoint{%
		\pgf@x.5\wd\pgfnodeparttextbox%
		\pgf@y0pt%
	}%
	\anchor{center}{\centerpoint}%
	\anchor{mid}{\midpoint}%
	\anchor{mid east}{%
		\getchamferedrectanglepoints%
		\midpoint%
		\pgf@ya\pgf@y%
		\pgf@process{%
			\before@sw@anchor%
			\pgf@ya\pgf@y%
			\before@ne@anchor%
			\pgf@y\pgf@ya		
		}%
		\ifdim\pgf@ya<\pgf@y%
			\pgfpointintersectionoflines{\midpoint}{\midpoint\pgf@ya\pgf@y\before@ne@anchor\pgf@y\pgf@ya}%
				{\before@sw@anchor\pgf@ya\pgf@y\before@ne@anchor\pgf@y\pgf@ya}%
				{\after@sw@anchor\pgf@ya\pgf@y\after@ne@anchor\pgf@y\pgf@ya}%
		\else%
			\pgf@process{\before@ne@anchor}%
			\ifdim\pgf@ya<\pgf@y%
				\pgfpointintersectionoflines{\midpoint}{\midpoint\pgf@ya\pgf@y\before@ne@anchor\pgf@y\pgf@ya}%
					{\before@sw@anchor\pgf@ya\pgf@y\before@ne@anchor\pgf@y\pgf@ya}%
					{\before@ne@anchor}%
			\else%
				\pgfpointintersectionoflines{\midpoint}{\midpoint\pgf@ya\pgf@y\before@ne@anchor\pgf@y\pgf@ya}%
					{\before@ne@anchor}%
					{\after@ne@anchor}%
			\fi%
		\fi%			
	}%
	\anchor{mid west}{%
		\getchamferedrectanglepoints%
		\midpoint%
		\pgf@ya\pgf@y%
		\pgf@process{\before@sw@anchor}%
		\ifdim\pgf@ya<\pgf@y%
			\pgfpointintersectionoflines{\midpoint}{\midpoint\pgf@ya\pgf@y\before@sw@anchor\pgf@y\pgf@ya}%
				{\before@sw@anchor}{\after@sw@anchor}%
		\else%
			\pgf@process{\before@ne@anchor\pgf@ya\pgf@y\before@sw@anchor\pgf@y\pgf@ya}%
			\ifdim\pgf@ya<\pgf@y%
				\pgfpointintersectionoflines{\midpoint}{\midpoint\pgf@ya\pgf@y\before@sw@anchor\pgf@y\pgf@ya}%
					{\before@ne@anchor\pgf@ya\pgf@y\before@sw@anchor\pgf@y\pgf@ya}%
					{\before@sw@anchor}%
			\else%
				\pgfpointintersectionoflines{\midpoint}{\midpoint\pgf@ya\pgf@y\before@sw@anchor\pgf@y\pgf@ya}%
					{\before@ne@anchor\pgf@ya\pgf@y\before@sw@anchor\pgf@y\pgf@ya}%
					{\after@ne@anchor\pgf@ya\pgf@y\after@sw@anchor\pgf@y\pgf@ya}%
			\fi%
		\fi%			
	}%
	\anchor{base}{\basepoint}%
	\anchor{base east}{%
		\getchamferedrectanglepoints%
		\basepoint%
		\pgf@ya\pgf@y%
		\pgf@process{%
			\before@sw@anchor%
			\pgf@ya\pgf@y%
			\before@ne@anchor%
			\pgf@y\pgf@ya		
		}%
		\ifdim\pgf@ya<\pgf@y%
			\pgfpointintersectionoflines{\basepoint}{\basepoint\pgf@ya\pgf@y\before@ne@anchor\pgf@y\pgf@ya}%
				{\before@sw@anchor\pgf@ya\pgf@y\before@ne@anchor\pgf@y\pgf@ya}%
				{\after@sw@anchor\pgf@ya\pgf@y\after@ne@anchor\pgf@y\pgf@ya}%
		\else%
			\pgf@process{\before@ne@anchor}%
			\ifdim\pgf@ya<\pgf@y%
				\pgfpointintersectionoflines{\basepoint}{\basepoint\pgf@ya\pgf@y\before@ne@anchor\pgf@y\pgf@ya}%
					{\before@sw@anchor\pgf@ya\pgf@y\before@ne@anchor\pgf@y\pgf@ya}%
					{\before@ne@anchor}%
			\else%
				\pgfpointintersectionoflines{\basepoint}{\basepoint\pgf@ya\pgf@y\before@ne@anchor\pgf@y\pgf@ya}%
					{\before@ne@anchor}%
					{\after@ne@anchor}%
			\fi%
		\fi%			
	}%
	\anchor{base west}{%
		\getchamferedrectanglepoints%
		\basepoint%
		\pgf@ya\pgf@y%
		\pgf@process{\before@sw@anchor}%
		\ifdim\pgf@ya<\pgf@y%
			\pgfpointintersectionoflines{\basepoint}{\basepoint\pgf@ya\pgf@y\before@sw@anchor\pgf@y\pgf@ya}%
				{\before@sw@anchor}{\after@sw@anchor}%
		\else%
			\pgf@process{\before@ne@anchor\pgf@ya\pgf@y\before@sw@anchor\pgf@y\pgf@ya}%
			\ifdim\pgf@ya<\pgf@y%
				\pgfpointintersectionoflines{\basepoint}{\basepoint\pgf@ya\pgf@y\before@sw@anchor\pgf@y\pgf@ya}%
					{\before@ne@anchor\pgf@ya\pgf@y\before@sw@anchor\pgf@y\pgf@ya}%
					{\before@sw@anchor}%
			\else%
				\pgfpointintersectionoflines{\basepoint}{\basepoint\pgf@ya\pgf@y\before@sw@anchor\pgf@y\pgf@ya}%
					{\before@ne@anchor\pgf@ya\pgf@y\before@sw@anchor\pgf@y\pgf@ya}%
					{\after@ne@anchor\pgf@ya\pgf@y\after@sw@anchor\pgf@y\pgf@ya}%
			\fi%
		\fi%			
	}%
	\anchor{before north east}{\getchamferedrectanglepoints\before@ne@anchor}%
	\anchor{north east}{\getchamferedrectanglepoints\ne@anchor}%
	\anchor{after north east}{\getchamferedrectanglepoints\after@ne@anchor}%
	\anchor{north}{%
		\getchamferedrectanglepoints%
		\centerpoint%
		\pgf@xa\pgf@x%
		\after@ne@anchor%
		\pgf@x\pgf@xa}%	
	\anchor{before north west}{%
		\getchamferedrectanglepoints%
		\after@sw@anchor%
		\pgf@xa\pgf@x%
		\after@ne@anchor%
		\pgf@x\pgf@xa}%
	\anchor{north west}{\getchamferedrectanglepoints\nw@anchor}%
	\anchor{after north west}{%
		\getchamferedrectanglepoints%
		\before@sw@anchor%
		\pgf@xa\pgf@x%
		\before@ne@anchor%
		\pgf@x\pgf@xa}%
	\anchor{west}{%
		\getchamferedrectanglepoints%
		\centerpoint%
		\pgf@ya\pgf@y%
		\before@sw@anchor%
		\pgf@y\pgf@ya}%	
	\anchor{before south west}{\getchamferedrectanglepoints\before@sw@anchor}%
	\anchor{south west}{\getchamferedrectanglepoints\sw@anchor}%
	\anchor{after south west}{\getchamferedrectanglepoints\after@sw@anchor}%
		\anchor{south}{%
		\getchamferedrectanglepoints%
		\centerpoint%
		\pgf@xa\pgf@x%
		\after@sw@anchor%
		\pgf@x\pgf@xa}%	
	\anchor{before south east}{%
		\getchamferedrectanglepoints%
		\after@sw@anchor%
		\pgf@ya\pgf@y%
		\after@ne@anchor%
		\pgf@y\pgf@ya}%
	\anchor{south east}{\getchamferedrectanglepoints\se@anchor}%
	\anchor{after south east}{%
		\getchamferedrectanglepoints%
		\before@sw@anchor%
		\pgf@ya\pgf@y%
		\before@ne@anchor%
		\pgf@y\pgf@ya}%
	\anchor{east}{%
		\getchamferedrectanglepoints%
		\centerpoint%
		\pgf@ya\pgf@y%
		\before@ne@anchor%
		\pgf@y\pgf@ya}%	
	\backgroundpath{%
		\pgfpathmoveto{\beforenortheast}%
		\pgfpathlineto{\northeast}%
		\pgfpathlineto{\afternortheast}%
		\pgfpathlineto{\aftersouthwest\pgf@xa\pgf@x\afternortheast\pgf@x\pgf@xa}%
		\pgfpathlineto{\northwest}%
		\pgfpathlineto{\beforesouthwest\pgf@xa\pgf@x\beforenortheast\pgf@x\pgf@xa}%
		\pgfpathlineto{\beforesouthwest}%
		\pgfpathlineto{\southwest}%
		\pgfpathlineto{\aftersouthwest}%
		\pgfpathlineto{\aftersouthwest\pgf@ya\pgf@y\afternortheast\pgf@y\pgf@ya}%
		\pgfpathlineto{\southeast}%
		\pgfpathlineto{\beforesouthwest\pgf@ya\pgf@y\beforenortheast\pgf@y\pgf@ya}%		
		\pgfpathclose%
	}
	\anchorborder{%
		\pgfextract@process\externalpoint{%
			\pgf@xa\pgf@x%
			\pgf@ya\pgf@y%
			\centerpoint%
			\advance\pgf@x\pgf@xa%
			\advance\pgf@y\pgf@ya%
		}%
		\pgfmathanglebetweenpoints{\centerpoint}{\externalpoint}%
		\let\externalangle\pgfmathresult%
		\getchamferedrectanglepoints%
		\pgfmathanglebetweenpoints{\centerpoint}{\centerpoint\pgf@ya\pgf@y\before@sw@anchor\pgf@y\pgf@ya}%
		\ifdim\externalangle pt<\pgfmathresult pt\relax% west.
			\pgfmathanglebetweenpoints{\centerpoint}{\centerpoint\pgf@xa\pgf@x\after@ne@anchor\pgf@x\pgf@xa}%
			\ifdim\externalangle pt<\pgfmathresult pt\relax% north.
				\pgfmathanglebetweenpoints{\centerpoint}{\ne@anchor}%
				\ifdim\externalangle pt<\pgfmathresult pt\relax% north east.
					\pgfmathanglebetweenpoints{\centerpoint}{\before@ne@anchor}%
					\ifdim\externalangle pt<\pgfmathresult pt\relax% before north east.
						\pgfpointintersectionoflines{\centerpoint}{\externalpoint}%
							{\centerpoint\pgf@ya\pgf@y\before@ne@anchor\pgf@y\pgf@ya}{\before@ne@anchor}%
					\else% 
						\pgfpointintersectionoflines{\centerpoint}{\externalpoint}%
							{\before@ne@anchor}{\ne@anchor}%
					\fi%
				\else%
					\pgfmathanglebetweenpoints{\centerpoint}{\after@ne@anchor}%
					\ifdim\externalangle pt<\pgfmathresult pt\relax% after north east.
							\pgfpointintersectionoflines{\centerpoint}{\externalpoint}%
							{\ne@anchor}{\after@ne@anchor}%
					\else% 
						\pgfpointintersectionoflines{\centerpoint}{\externalpoint}%
							{\after@ne@anchor}{\centerpoint\pgf@xa\pgf@x\after@ne@anchor\pgf@x\pgf@xa}%
					\fi%
				\fi%
			\else%
				\pgfmathanglebetweenpoints{\centerpoint}{\nw@anchor}%
				\ifdim\externalangle pt<\pgfmathresult pt\relax% north west.
					\pgfmathanglebetweenpoints{\centerpoint}{\after@sw@anchor\pgf@xa\pgf@x\after@ne@anchor\pgf@x\pgf@xa}%
					\ifdim\externalangle pt<\pgfmathresult pt\relax% before north west.
						\pgfpointintersectionoflines{\centerpoint}{\externalpoint}%
							{\centerpoint\pgf@xa\pgf@x\after@ne@anchor\pgf@x\pgf@xa}%
							{\after@sw@anchor\pgf@xa\pgf@x\after@ne@anchor\pgf@x\pgf@xa}%
					\else%
						\pgfpointintersectionoflines{\centerpoint}{\externalpoint}%
							{\after@sw@anchor\pgf@xa\pgf@x\after@ne@anchor\pgf@x\pgf@xa}%
							{\nw@anchor}%
					\fi%
				\else%
					\pgfmathanglebetweenpoints{\centerpoint}{\before@sw@anchor\pgf@xa\pgf@x\before@ne@anchor\pgf@x\pgf@xa}%
					\ifdim\externalangle pt<\pgfmathresult pt\relax% after north west.
						\pgfpointintersectionoflines{\centerpoint}{\externalpoint}%
							{\nw@anchor}{\before@sw@anchor\pgf@xa\pgf@x\before@ne@anchor\pgf@x\pgf@xa}%
					\else%
						\pgfpointintersectionoflines{\centerpoint}{\externalpoint}%
							{\before@sw@anchor\pgf@xa\pgf@x\before@ne@anchor\pgf@x\pgf@xa}%
							{\before@sw@anchor\pgf@xa\pgf@x\centerpoint\pgf@x\pgf@xa}%
					\fi%
				\fi%
			\fi%
		\else%
			\pgfmathanglebetweenpoints{\centerpoint}{\centerpoint\pgf@xa\pgf@x\after@sw@anchor\pgf@x\pgf@xa}%
			\ifdim\externalangle pt<\pgfmathresult pt\relax% south.
				\pgfmathanglebetweenpoints{\centerpoint}{\sw@anchor}%
				\ifdim\externalangle pt<\pgfmathresult pt\relax% south west.
					\pgfmathanglebetweenpoints{\centerpoint}{\before@sw@anchor}%
					\ifdim\externalangle pt<\pgfmathresult pt\relax% before south west.
						\pgfpointintersectionoflines{\centerpoint}{\externalpoint}%
							{\before@sw@anchor\pgf@xa\pgf@x\centerpoint\pgf@x\pgf@xa}%
							{\before@sw@anchor}%
					\else%
						\pgfpointintersectionoflines{\centerpoint}{\externalpoint}%
							{\before@sw@anchor}{\sw@anchor}%
					\fi%
				\else%
					\pgfmathanglebetweenpoints{\centerpoint}{\after@sw@anchor}%
					\ifdim\externalangle pt<\pgfmathresult pt\relax% after south west.
						\pgfpointintersectionoflines{\centerpoint}{\externalpoint}%
							{\before@sw@anchor}{\after@sw@anchor}%
					\else%
						\pgfpointintersectionoflines{\centerpoint}{\externalpoint}%
							{\after@sw@anchor}{\centerpoint\pgf@xa\pgf@x\after@sw@anchor\pgf@x\pgf@xa}%
					\fi%
				\fi%
			\else%
				\pgfmathanglebetweenpoints{\centerpoint}{\se@anchor}%
				\ifdim\externalangle pt<\pgfmathresult pt\relax% south east.
					\pgfmathanglebetweenpoints{\centerpoint}{\after@ne@anchor\pgf@xa\pgf@x\after@sw@anchor\pgf@x\pgf@xa}%
					\ifdim\externalangle pt<\pgfmathresult pt\relax% before south east.
						\pgfpointintersectionoflines{\centerpoint}{\externalpoint}%
							{\after@ne@anchor\pgf@xa\pgf@x\after@sw@anchor\pgf@x\pgf@xa}%
							{\centerpoint\pgf@xa\pgf@x\after@sw@anchor\pgf@x\pgf@xa}%
					\else%
						\pgfpointintersectionoflines{\centerpoint}{\externalpoint}%
							{\after@ne@anchor\pgf@xa\pgf@x\after@sw@anchor\pgf@x\pgf@xa}{\se@anchor}
					\fi%
				\else%
					\pgfmathanglebetweenpoints{\centerpoint}{\before@ne@anchor\pgf@xa\pgf@x\before@sw@anchor\pgf@x\pgf@xa}%
					\ifdim\externalangle pt<\pgfmathresult pt\relax% after south east.
						\pgfpointintersectionoflines{\centerpoint}{\externalpoint}%
							{\se@anchor}{\before@ne@anchor\pgf@xa\pgf@x\before@sw@anchor\pgf@x\pgf@xa}%					
					\else%
						\pgfpointintersectionoflines{\centerpoint}{\externalpoint}%
							{\before@ne@anchor\pgf@xa\pgf@x\before@sw@anchor\pgf@x\pgf@xa}%
							{\centerpoint\pgf@ya\pgf@y\before@ne@anchor\pgf@y\pgf@ya}%
					\fi%
				\fi%
			\fi%			
		\fi%
	}%			
}


\endinput
