\typeout{%
GasTeX v1.0b2 Sept. 28, 1998}
%%----------------------------------------------------------------------
%%
%% Graphs and Automata Simplified in TeX
%%
%% Macros for drawing easily graphs and automata under the picture 
%% environment of LaTeX 2.09 or LaTeX2e.
%% Documentation and examples in doc_gastex.tex
%%
%% Paul Gastin
%% LIAFA
%% Universite Paris 7
%% 2, place Jussieu
%% F-75251 Paris Cedex 05
%% email : Paul.Gastin@liafa.jussieu.fr
%% www : http://www.liafa.jussieu.fr/~gastin
%%
%%----------------------------------------------------------------------
%% The only change wrt v1.0b1 is that I added some macros from epic.sty
%% so that it is no more needed to read this file. One should use simply
%% \usepackage{pspictpg,gastex}
%%----------------------------------------------------------------------
%%
%% Definitions:

\newif\if@arrow\@arrowtrue

\unitlength=4pt
% \d@my@unit est l'unit� utilis�e par tous les dessins de gastex.sty.
% Les valeurs donn�es en \unitlength sont transform�es en \d@my@unit.
% Ceci a pour effet d'augmenter la pr�cision des dessins.
\newdimen\d@my@unit
% \d@my@unit= 2048sp % environ 0.011 mm
% \d@my@unit= 4096sp % environ 0.022 mm
  \d@my@unit= 8192sp % environ 0.044 mm
% \d@my@unit=16384sp % environ 0.088 mm

\newcount\c@aux \newdimen\d@aux
\newcount\c@auxa \newcount\c@auxb \newcount\c@auxc \newcount\c@auxd
\newcount\c@xa \newcount\c@xb \newcount\c@xc \newcount\c@xd
\newcount\c@ya \newcount\c@yb \newcount\c@yc \newcount\c@yd
\newcount\c@deltax \newcount\c@deltay
\newbox\temp@box

\def\setstatediam#1{%
  \d@aux=#1\unitlength \c@aux=\d@aux \divide\c@aux\d@my@unit
  \edef\state@diam{\the\c@aux}%
  }
\setstatediam{6}

\def\setrepeatedstatediam#1{%
  \d@aux=#1\unitlength \c@aux=\d@aux \divide\c@aux\d@my@unit
  \edef\repeted@diam{\the\c@aux}%
  }
\setrepeatedstatediam{5}

\def\setloopdiam#1{%
  \d@aux=#1\unitlength \c@aux=\d@aux \divide\c@aux\d@my@unit
  \edef\loop@diam{\the\c@aux}%
  }
\setloopdiam{6}

\def\settranslabelskip#1{%
  \d@aux=#1\unitlength \c@aux=\d@aux \divide\c@aux\d@my@unit
  \edef\trans@label@skip{\the\c@aux}%
  }
\settranslabelskip{1}

\def\settransdecal#1{%
  \d@aux=#1\unitlength \c@aux=\d@aux \divide\c@aux\d@my@unit
  \edef\trans@decal{\the\c@aux}%
  }
\settransdecal{0}

\def\setprofcurve#1{%
  \d@aux=#1\unitlength \c@aux=\d@aux \divide\c@aux\d@my@unit
  \edef\prof@curve{\the\c@aux}%
  }
\setprofcurve{3}

\def\setmaxbezier#1{\def\max@bezier{#1}}
\def\setnbptbezier#1{\def\max@bezier{#1}} % compatibilit� version 0.3
\setmaxbezier{500}

\def\setprecision#1{} % compatibilit� version 0.3

%%----------------------------------------------------------------------
%%
%% States.

\def\letstate{%
  \@ifnextchar[{\letstate@un}{\letstate@deux}}
\def\letstate@un[#1,#2] #3=(#4,#5){%
  \d@aux=#4\unitlength \c@aux=\d@aux \divide\c@aux\d@my@unit
  \expandafter\edef\csname state@#3@x\endcsname{\the\c@aux}%
  \d@aux=#5\unitlength \c@aux=\d@aux \divide\c@aux\d@my@unit
  \expandafter\edef\csname state@#3@y\endcsname{\the\c@aux}%
  \d@aux=#1\unitlength \c@aux=\d@aux \divide\c@aux\d@my@unit
  \expandafter\edef\csname state@#3@diam\endcsname{\the\c@aux}%
  \d@aux=#2\unitlength \c@aux=\d@aux \divide\c@aux\d@my@unit
  \expandafter\edef\csname state@#3@repdiam\endcsname{\the\c@aux}%
  }
\def\letstate@deux #1=(#2,#3){%
  \d@aux=#2\unitlength \c@aux=\d@aux \divide\c@aux\d@my@unit
  \expandafter\edef\csname state@#1@x\endcsname{\the\c@aux}%
  \d@aux=#3\unitlength \c@aux=\d@aux \divide\c@aux\d@my@unit
  \expandafter\edef\csname state@#1@y\endcsname{\the\c@aux}%
  \expandafter\edef\csname state@#1@diam\endcsname{\state@diam}%
  \expandafter\edef\csname state@#1@repdiam\endcsname{\repeted@diam}%
  }

\def\drawstate(#1)#2{{%
  \unitlength=\d@my@unit
  \edef\cs@x{\csname state@#1@x\endcsname}%
  \edef\cs@y{\csname state@#1@y\endcsname}%
  \put(\cs@x,\cs@y){\makebox(0,0){#2}}
  \put(\cs@x,\cs@y){\circle{\csname state@#1@diam\endcsname}}
  }}

\def\drawinitialstate{%
  \@ifnextchar[{\@idrawinitialstate}{\@idrawinitialstate[l]}}
\def\@idrawinitialstate[#1](#2)#3{{%
  \unitlength=\d@my@unit
  \c@xa=\csname state@#2@x\endcsname
  \c@ya=\csname state@#2@y\endcsname
  \edef\cs@diam{\csname state@#2@diam\endcsname}%
  \c@auxa=\cs@diam \divide\c@auxa by 2
  \put(\c@xa,\c@ya){\makebox(0,0){#3}}
  \put(\c@xa,\c@ya){\circle{\cs@diam}}
  \if#1l \advance\c@xa by -\cs@diam \put(\c@xa,\c@ya){\vector( 1,0){\c@auxa}} \fi
  \if#1r \advance\c@xa by  \cs@diam \put(\c@xa,\c@ya){\vector(-1,0){\c@auxa}} \fi
  \if#1t \advance\c@ya by  \cs@diam \put(\c@xa,\c@ya){\vector(0,-1){\c@auxa}} \fi
  \if#1b \advance\c@ya by -\cs@diam \put(\c@xa,\c@ya){\vector(0, 1){\c@auxa}} \fi
  }}

\def\drawfinalstate{%
  \@ifnextchar[{\@idrawfinalstate}{\@idrawfinalstate[r]}}
\def\@idrawfinalstate[#1](#2)#3{{%
  \unitlength=\d@my@unit
  \c@xa=\csname state@#2@x\endcsname
  \c@ya=\csname state@#2@y\endcsname
  \c@auxa=\csname state@#2@diam\endcsname
  \put(\c@xa,\c@ya){\makebox(0,0){#3}}
  \put(\c@xa,\c@ya){\circle{\c@auxa}}
  \divide\c@auxa by 2
  \if#1l \advance\c@xa by -\c@auxa \put(\c@xa,\c@ya){\vector(-1,0){\c@auxa}} \fi
  \if#1r \advance\c@xa by  \c@auxa \put(\c@xa,\c@ya){\vector( 1,0){\c@auxa}} \fi
  \if#1t \advance\c@ya by  \c@auxa \put(\c@xa,\c@ya){\vector( 0,1){\c@auxa}} \fi
  \if#1b \advance\c@ya by -\c@auxa \put(\c@xa,\c@ya){\vector(0,-1){\c@auxa}} \fi
  }}

\def\drawrepeatedstate(#1)#2{{%
  \unitlength=\d@my@unit
  \edef\cs@x{\csname state@#1@x\endcsname}%
  \edef\cs@y{\csname state@#1@y\endcsname}%
  \put(\cs@x,\cs@y){\makebox(0,0){#2}}
  \put(\cs@x,\cs@y){\circle{\csname state@#1@diam\endcsname}}
  \put(\cs@x,\cs@y){\circle{\csname state@#1@repdiam\endcsname}}
  }}

%%----------------------------------------------------------------------
%%
%% Transitions.

\def\gastex@warning#1{%
  \typeout{gastex warning on input line \the\inputlineno : 
           #1 is an old option.}
  \typeout{Still accepted for compatibility reasons. Use l or r instead.}
  \typeout{}
  }

\def\drawtrans{\@arrowtrue\@ifnextchar[{\@idrawtrans}{\@idrawtrans[l]}}
\def\@idrawtrans[#1](#2,#3)#4{{%
  \if#1t \gastex@warning{t} \fi
  \if#1b \gastex@warning{b} \fi
  \unitlength=\d@my@unit
  \c@xa=\csname state@#2@x\endcsname
  \c@ya=\csname state@#2@y\endcsname
  \edef\cs@diama{\csname state@#2@diam\endcsname}%
  \c@xb=\csname state@#3@x\endcsname
  \c@yb=\csname state@#3@y\endcsname
  \edef\cs@diamb{\csname state@#3@diam\endcsname}%
  \c@deltax=\c@xb \advance\c@deltax -\c@xa
  \c@deltay=\c@yb \advance\c@deltay -\c@ya
  \distance(\c@xa,\c@ya)(\c@xb,\c@yb)
% Ending points of the transition.
  \c@auxc=-\trans@decal
  \multiply\c@auxc\c@deltay \divide\c@auxc\@distance
  \c@auxd= \trans@decal
  \multiply\c@auxd\c@deltax \divide\c@auxd\@distance
  \if#1b \c@auxc=-\c@auxc \c@auxd=-\c@auxd \fi
% 
  \c@auxa=\cs@diama \divide\c@auxa by 2
  \multiply\c@auxa\c@deltax \divide\c@auxa\@distance
  \c@auxb=\cs@diama \divide\c@auxb by 2
  \multiply\c@auxb\c@deltay \divide\c@auxb\@distance
  \advance\c@xa\c@auxa \advance\c@xa\c@auxc
  \advance\c@ya\c@auxb \advance\c@ya\c@auxd
% 
  \c@auxa=\cs@diamb \divide\c@auxa by 2
  \multiply\c@auxa\c@deltax \divide\c@auxa\@distance
  \c@auxb=\cs@diamb \divide\c@auxb by 2
  \multiply\c@auxb\c@deltay \divide\c@auxb\@distance
  \advance\c@xb -\c@auxa \advance\c@xb\c@auxc
  \advance\c@yb -\c@auxb \advance\c@yb\c@auxd
  \if@arrow
    \drawvector(\c@xa,\c@ya)(\c@xb,\c@yb)
  \else
    \@killglue\drawline(\c@xa,\c@ya)(\c@xb,\c@yb)
  \fi
% Coordinates (\c@xc,\c@yc) of the middle point of the curve.
  \c@xc=\c@xa \advance\c@xc\c@xb \divide\c@xc by 2
  \c@yc=\c@ya \advance\c@yc\c@yb \divide\c@yc by 2
% Label of the transition.
  \@drawlabel[#1]{#4}
  }}

\def\drawcurvedtrans{\@arrowtrue
  \@ifnextchar[{\@idrawcurvedtrans}{\@idrawcurvedtrans[l]}}
\def\@idrawcurvedtrans[#1](#2,#3)#4{{%
  \if#1t \gastex@warning{t} \fi
  \if#1b \gastex@warning{b} \fi
  \unitlength=\d@my@unit
  \edef\cs@xa{\csname state@#2@x\endcsname}%
  \edef\cs@ya{\csname state@#2@y\endcsname}%
  \edef\cs@diama{\csname state@#2@diam\endcsname}%
  \edef\cs@xb{\csname state@#3@x\endcsname}%
  \edef\cs@yb{\csname state@#3@y\endcsname}%
  \edef\cs@diamb{\csname state@#3@diam\endcsname}%
  \c@deltax=\cs@xb \advance\c@deltax by -\cs@xa
  \c@deltay=\cs@yb \advance\c@deltay by -\cs@ya
  \distance(\cs@xa,\cs@ya)(\cs@xb,\cs@yb)
% Computation of the point D defining the quadratic B�zier curve.
  \c@aux=\prof@curve \multiply\c@aux by 2 \if#1b \c@aux=-\c@aux \fi
  \multiply\c@aux\c@deltay \divide\c@aux\@distance
  \c@xd=\cs@xa \advance\c@xd\cs@xb \divide\c@xd by 2 \advance\c@xd by -\c@aux
  \c@aux=\prof@curve \multiply\c@aux by 2 \if#1b \c@aux=-\c@aux \fi
  \multiply\c@aux\c@deltax \divide\c@aux\@distance
  \c@yd=\cs@ya \advance\c@yd\cs@yb \divide\c@yd by 2 \advance\c@yd by  \c@aux
% Coordinates (\c@xc,\c@yc) of the middle point of the curve.
  \c@xc=\c@xd \multiply\c@xc by 2 \advance\c@xc by \cs@xa
  \advance\c@xc by \cs@xb \divide\c@xc by 4
  \c@yc=\c@yd \multiply\c@yc by 2 \advance\c@yc by \cs@ya
  \advance\c@yc by \cs@yb \divide\c@yc by 4
% Label of the transition.
  \@drawlabel[#1]{#4}
% Drawing of the B�zier curve.
  \r@qbezier(\cs@xa,\cs@ya,\cs@diama)(\c@xd,\c@yd)(\cs@xb,\cs@yb,\cs@diamb)
  }}

\def\drawqbeziertrans{\@arrowtrue
  \@ifnextchar[{\@idrawqbeziertrans}{\@idrawqbeziertrans[l]}}
\def\@idrawqbeziertrans[#1](#2)(#3,#4)(#5)#6{{%
  \if#1t \gastex@warning{t} \fi
  \if#1b \gastex@warning{b} \fi
  \d@aux=#3\unitlength \c@xd=\d@aux \divide\c@xd\d@my@unit
  \d@aux=#4\unitlength \c@yd=\d@aux \divide\c@yd\d@my@unit
  \unitlength=\d@my@unit
  \edef\cs@xa{\csname state@#2@x\endcsname}%
  \edef\cs@ya{\csname state@#2@y\endcsname}%
  \edef\cs@diama{\csname state@#2@diam\endcsname}%
  \edef\cs@xb{\csname state@#5@x\endcsname}%
  \edef\cs@yb{\csname state@#5@y\endcsname}%
  \edef\cs@diamb{\csname state@#5@diam\endcsname}%
  \c@deltax=\cs@xb \advance\c@deltax -\cs@xa
  \c@deltay=\cs@yb \advance\c@deltay -\cs@ya
  \distance(\cs@xa,\cs@ya)(\cs@xb,\cs@yb)
% Coordinates (\c@xc,\c@yc) of the middle point of the curve.
  \c@xc=\c@xd \multiply\c@xc by 2 \advance\c@xc by \cs@xa
  \advance\c@xc by \cs@xb \divide\c@xc by 4
  \c@yc=\c@yd \multiply\c@yc by 2 \advance\c@yc by \cs@ya
  \advance\c@yc by \cs@yb \divide\c@yc by 4
% Label of the transition.
  \@drawlabel[#1]{#6}
% Drawing of the B�zier curve.
  \r@qbezier(\cs@xa,\cs@ya,\cs@diama)(\c@xd,\c@yd)(\cs@xb,\cs@yb,\cs@diamb)
  }}

\def\drawcbeziertrans{\@arrowtrue
  \@ifnextchar[{\@idrawcbeziertrans}{\@idrawcbeziertrans[l]}}
\def\@idrawcbeziertrans[#1](#2)(#3,#4)(#5,#6)(#7)#8{{%
  \if#1t \gastex@warning{t} \fi
  \if#1b \gastex@warning{b} \fi
% Parameters in \d@my@unit.
  \edef\cs@xa{\csname state@#2@x\endcsname}%
  \edef\cs@ya{\csname state@#2@y\endcsname}%
  \edef\cs@diama{\csname state@#2@diam\endcsname}%
  \edef\cs@xd{\csname state@#7@x\endcsname}%
  \edef\cs@yd{\csname state@#7@y\endcsname}%
  \edef\cs@diamd{\csname state@#7@diam\endcsname}%
  \d@aux=#3\unitlength
  \c@aux=\d@aux \divide\c@aux\d@my@unit \edef\cs@xb{\the\c@aux}%
  \d@aux=#4\unitlength
  \c@aux=\d@aux \divide\c@aux\d@my@unit \edef\cs@yb{\the\c@aux}%
  \d@aux=#5\unitlength
  \c@aux=\d@aux \divide\c@aux\d@my@unit \edef\cs@xc{\the\c@aux}%
  \d@aux=#6\unitlength
  \c@aux=\d@aux \divide\c@aux\d@my@unit \edef\cs@yc{\the\c@aux}%
  \unitlength=\d@my@unit
% Drawing of the B�zier curve.
  \r@cbezier(\cs@xa,\cs@ya,\cs@diama)(\cs@xb,\cs@yb)%
            (\cs@xc,\cs@yc)(\cs@xd,\cs@yd,\cs@diamd)
% Coordinates (\c@xc,\c@yc) of the middle point of the curve.
  \c@xc=\cs@xb \advance\c@xc\cs@xc \multiply\c@xc by 3
  \advance\c@xc\cs@xa \advance\c@xc\cs@xd \divide\c@xc by 8
  \c@yc=\cs@yb \advance\c@yc\cs@yc \multiply\c@yc by 3
  \advance\c@yc\cs@ya \advance\c@yc\cs@yd \divide\c@yc by 8
% Slope (\c@deltax,\c@deltay) at the middle point of the curve.
  \c@deltax=\cs@xd \advance\c@deltax by \cs@xc 
  \advance\c@deltax by -\cs@xb \advance\c@deltax by -\cs@xa 
  \multiply\c@deltax by 3 \divide\c@deltax by 4
  \c@deltay=\cs@yd \advance\c@deltay by\cs@yc 
  \advance\c@deltay by -\cs@yb \advance\c@deltay by -\cs@ya 
  \multiply\c@deltay by 3 \divide\c@deltay by 4
% Computation of \@distance for \@drawlabel.
  \x@diff=\c@deltax\unitlength\relax
  \y@diff=\c@deltay\unitlength\relax
  \sqrtandstuff{\x@diff}{\y@diff}{1\unitlength}
  \@distance=\num@segments
% Label of the transition.
  \@drawlabel[#1]{#8}
  }}

%%----------------------------------------------------------------------
%%
%% Loops

\def\drawloop{\@arrowtrue\@ifnextchar[{\@idrawloop}{\@idrawloop[t]}}
\def\@idrawloop[#1](#2)#3{{%
  \unitlength=\d@my@unit
  \edef\cs@xa{\csname state@#2@x\endcsname}%
  \edef\cs@ya{\csname state@#2@y\endcsname}%
  \edef\cs@diama{\csname state@#2@diam\endcsname}%
% Label of the transition.
  \c@aux=\cs@diama \divide\c@aux by 2 \advance\c@aux\loop@diam
  \advance\c@aux\trans@label@skip
  \if#1l
    \c@xc=\cs@xa \advance\c@xc -\c@aux
    \c@yc=\cs@ya
    \put(\c@xc,\c@yc){\makebox(0,0)[r]{#3}}
    \r@loop(180,\loop@diam)(\cs@xa,\cs@ya,\cs@diama)
  \fi
  \if#1r
    \c@xc=\cs@xa \advance\c@xc\c@aux
    \c@yc=\cs@ya
    \put(\c@xc,\c@yc){\makebox(0,0)[l]{#3}}
    \r@loop(0,\loop@diam)(\cs@xa,\cs@ya,\cs@diama)
  \fi
  \if#1t
    \c@xc=\cs@xa
    \c@yc=\cs@ya \advance\c@yc\c@aux
    \put(\c@xc,\c@yc){\makebox(0,0)[b]{#3}}
    \r@loop(90,\loop@diam)(\cs@xa,\cs@ya,\cs@diama)
  \fi
  \if#1b
    \c@xc=\cs@xa
    \c@yc=\cs@ya \advance\c@yc -\c@aux
    \put(\c@xc,\c@yc){\makebox(0,0)[t]{#3}}
    \r@loop(270,\loop@diam)(\cs@xa,\cs@ya,\cs@diama)
  \fi
}}

%%----------------------------------------------------------------------
%%
%% Graphs

\def\letvertex{%
  \@ifnextchar[{\letvertex@un}{\letvertex@deux}}
\def\letvertex@un[#1] #2=(#3,#4){%
  \d@aux=#3\unitlength \c@aux=\d@aux \divide\c@aux\d@my@unit
  \expandafter\edef\csname state@#2@x\endcsname{\the\c@aux}%
  \d@aux=#4\unitlength \c@aux=\d@aux \divide\c@aux\d@my@unit
  \expandafter\edef\csname state@#2@y\endcsname{\the\c@aux}%
  \d@aux=#1\unitlength \c@aux=\d@aux \divide\c@aux\d@my@unit
  \expandafter\edef\csname state@#2@diam\endcsname{\the\c@aux}%
  }
\def\letvertex@deux #1=(#2,#3){%
  \d@aux=#2\unitlength \c@aux=\d@aux \divide\c@aux\d@my@unit
  \expandafter\edef\csname state@#1@x\endcsname{\the\c@aux}%
  \d@aux=#3\unitlength \c@aux=\d@aux \divide\c@aux\d@my@unit
  \expandafter\edef\csname state@#1@y\endcsname{\the\c@aux}%
  \expandafter\edef\csname state@#1@diam\endcsname{\state@diam}%
  }

\def\setvertexdiam{\setstatediam}
\def\setedgelabelskip{\settranslabelskip}
\def\setedgedecal{\settransdecal}
\def\drawcircledvertex{\drawstate}

\def\drawvertex(#1)#2{{%
  \unitlength=\d@my@unit
  \edef\cs@x{\csname state@#1@x\endcsname}%
  \edef\cs@y{\csname state@#1@y\endcsname}%
  \put(\cs@x,\cs@y){\makebox(0,0){#2}}
  }}

\def\drawedge{\@arrowtrue
  \@ifnextchar[{\@idrawtrans}{\@idrawtrans[l]}}

\def\drawundirectededge{\@arrowfalse
  \@ifnextchar[{\@idrawtrans}{\@idrawtrans[l]}}

\def\drawcurvededge{\@arrowtrue
  \@ifnextchar[{\@idrawcurvedtrans}{\@idrawcurvedtrans[l]}}

\def\drawundirectedcurvededge{\@arrowfalse
  \@ifnextchar[{\@idrawcurvedtrans}{\@idrawcurvedtrans[l]}}

\def\drawqbezieredge{\@arrowtrue
  \@ifnextchar[{\@idrawqbeziertrans}{\@idrawqbeziertrans[l]}}

\def\drawundirectedqbezieredge{\@arrowfalse
  \@ifnextchar[{\@idrawqbeziertrans}{\@idrawqbeziertrans[l]}}

\def\drawcbezieredge{\@arrowtrue
  \@ifnextchar[{\@idrawcbeziertrans}{\@idrawcbeziertrans[l]}}

\def\drawundirectedcbezieredge{\@arrowfalse
  \@ifnextchar[{\@idrawcbeziertrans}{\@idrawcbeziertrans[l]}}

\def\drawundirectedloop{\@arrowfalse
  \@ifnextchar[{\@idrawloop}{\@idrawloop[t]}}

%%----------------------------------------------------------------------
%%
%% Miscellanees
%----------------------------------------------------------------------
%% The following is just taken from epic.sty
\newdimen\@dotgap
\newcount\@x@diff
\newcount\@y@diff
\newdimen\x@diff
\newdimen\y@diff
\newcount\num@segments
\newif\ifsqrt@done
%% from sqrtandstuff func basically need \num@segments.
%% given a deltax, deltay and dotgap, it calculates \num@segments = number of
%% segments along the hypotenuse. used by \dottedline & \dashline.
%% It finishes quickly if any of deltax or deltay are zero or close to zero.
\def\sqrtandstuff#1#2#3{
\ifdim #1 <0pt \@x@diff= -#1 \else\@x@diff=#1\fi
\ifdim #2 <0pt \@y@diff= -#2 \else\@y@diff=#2\fi
%% @diff's will be positive and diff's will retain their sign.
\@dotgap=#3 \divide\@dotgap \tw@
\advance\@x@diff \@dotgap \advance\@y@diff \@dotgap% for round-off errors
\@dotgap=#3
\divide\@x@diff \@dotgap \divide\@y@diff \@dotgap
\sqrt@donefalse
\ifnum\@x@diff < 2
   \ifnum\@y@diff < 2 \num@segments=\@x@diff \advance\num@segments \@y@diff
		      \sqrt@donetrue
        \else\num@segments=\@y@diff \sqrt@donetrue\fi
   \else\ifnum\@y@diff < 2 \num@segments=\@x@diff \sqrt@donetrue\fi
\fi
\ifsqrt@done \ifnum\num@segments=\z@ \num@segments=\@ne\fi\relax
 \else \ifnum\@y@diff >\@x@diff
		 \@tempcnta=\@x@diff \@x@diff=\@y@diff \@y@diff=\@tempcnta
       \fi    		%exchange @x@diff & @y@diff, so now @x@diff > @y@diff
  \num@segments=\@y@diff
  \multiply\num@segments \num@segments
  \multiply\num@segments by 457
  \divide\num@segments \@x@diff
  \advance\num@segments by 750 % for round-off, going to divide by 1000.
  \divide\num@segments \@m
  \advance\num@segments \@x@diff
		%num@segments = @x@diff + (0.457*sqr(@y@diff)/@x@diff)
\fi}
%----------------------------------------------------------------------
%% \distance: Compute the distance in \unitlength between two points. 
%% result in \@distance.
%% Note: use \x@diff, \y@diff, \num@segments and \sqrtandstuff defined in epic.
%%
\newcount\@distance
\def\distance(#1,#2)(#3,#4){%
  \x@diff=#3\unitlength\relax\advance\x@diff by -#1\unitlength\relax
  \y@diff=#4\unitlength\relax\advance\y@diff by -#2\unitlength\relax
  \sqrtandstuff{\x@diff}{\y@diff}{1\unitlength}
  \@distance=\num@segments
% \typeout{distance = \the\@distance}
}

% Label of a transition.
% #1 is a letter among l(eft), r(ight) specifying the label position with
% respect to the transition when looking in the direction of the  transition.
% #2 is the label of the transition.
% We need,
% - (\c@xc,\c@yc) coordinates of the middle point C of the transition,
% - (\c@deltax,\c@deltay) giving the slope at point C
% - \@distance = sqrt(\c@deltax^2 +\c@deltay^2).
\def\@drawlabel[#1]#2{{%
% Computation of the shift from C to the label.
  \setbox\temp@box\hbox{#2}
  \c@auxa=\wd\temp@box
  \divide\c@auxa\d@my@unit \multiply\c@auxa\c@deltay
  \ifnum\c@auxa<0 \c@auxa=-\c@auxa \fi
  \c@auxc=\ht\temp@box \advance\c@auxc by \dp\temp@box
  \divide\c@auxc\d@my@unit \multiply\c@auxc\c@deltax
  \ifnum\c@auxc<0 \c@auxc=-\c@auxc \fi
  \advance\c@auxc\c@auxa \divide\c@auxc\@distance \divide\c@auxc by 2
  \advance\c@auxc\trans@label@skip
  \c@auxa=-\c@deltay \multiply\c@auxa\c@auxc \divide\c@auxa\@distance
  \c@auxb=\c@deltax \multiply\c@auxb\c@auxc \divide\c@auxb\@distance
  \if#1r \c@auxa=-\c@auxa \c@auxb=-\c@auxb \fi
  \if#1b \c@auxa=-\c@auxa \c@auxb=-\c@auxb \fi
% Shifting of point C and drawing of the label.
  \advance\c@xc\c@auxa \advance\c@yc\c@auxb
  \put(\c@xc,\c@yc){\makebox(0,0){#2}}
  }}

\endinput
