\ProvidesPackage{pgfheaps}[2004/01/26 ver 0.11]

% Copyright 2003 by Till Tantau <tantau@cs.tu-berlin.de>.
%
% This program can be redistributed and/or modified under the terms
% of the LaTeX Project Public License Distributed from CTAN
% archives in directory macros/latex/base/lppl.txt.

\RequirePackage{pgf}

\ProcessOptions

%
% Package for drawing heap diagrams.
%

\newdimen\pgf@heapx
\newdimen\pgf@heapy




% Construct the path of a heap.
% 
% #1 = Position of heap label.
% #2 = Position of left base
% #3 = Position of right base
% 
% Example:
%
% \pgfheappath{\pgfxy(1,0)}{\pgfxy(-1,0)}{\pgfxy(1,0)}
% \pgffill

\def\pgfheappath#1#2#3{%
  \pgfdiff{#2}{#3}%
  \pgf@heapx=-.25\pgf@x%
  \pgf@heapy=-.25\pgf@y%
  \pgfmoveto{#2}%
  \pgfbezier%
    {\pgfpartway{0.5}{#2}{\pgfrelative{#1}{\pgfpoint{\pgf@heapx}{\pgf@heapy}}}}%
    {\pgfrelative{#1}{\pgfpoint{\pgf@heapx}{\pgf@heapy}}}%
    {#1}%
  \pgf@heapx=-\pgf@heapx%
  \pgf@heapy=-\pgf@heapy%  
  \pgfbezier%
    {\pgfrelative{#1}{\pgfpoint{\pgf@heapx}{\pgf@heapy}}}%
    {\pgfpartway{0.5}{#3}{\pgfrelative{#1}{\pgfpoint{\pgf@heapx}{\pgf@heapy}}}}%
    {#3}%
  \ignorespaces}


% Draw a heap label. 
% 
% #1 = Position of heap label.
% #2 = Label text.
% 
% Example:
%
% \pgfheaplabel{\pgfxy(1,0)}{Class P}

\def\pgfheaplabel#1#2{%
  \setbox\pgf@hbox=\hbox{\selectfont#2}%
  \pgf@heapy=\ht\pgf@hbox%
  \pgfputat{\pgfrelative{#1}{\pgfpoint{0pt}{-2\pgf@heapy}}}{\pgfbox[center,base]{#2}}%
  \ignorespaces}


% Draw a labeled heap. 
% 
% #1 = Position of heap label.
% #2 = Position of left base
% #3 = Position of right base
% #4 = Label text.
% 
% Example:
%
% \pgfheaplabeled{\pgfxy(1,0)}{\pgfxy(-1,0)}{\pgfxy(1,0)}{Class P}

\def\pgfheaplabeled#1#2#3#4{%
  \pgfheaplabel{#1}{#4}%
  \pgfheappath{#1}{#2}{#3}%
  \pgfstroke%
  \ignorespaces}



% Draw a labeled heap. 
% 
% #1 = Height of the label
% #2 = Left and right extension of the base.
% #3 = Label text.
% 
% Example:
%
% \pgfheaplabeledcentered{1cm}{1cm}{Class P}

\def\pgfheaplabeledcentered#1#2#3{%
  \pgfheaplabeled{\pgfpoint{0pt}{#1}}{\pgfpoint{-#2}{0pt}}{\pgfpoint{#2}{0pt}}{#3}\ignorespaces}

\endinput
