%% xytpic.tex from $Id: xytpic.doc,v 3.3 1996/12/18 09:50:38 ross Exp $
%%
%% Xy-pic ``tpic'' TPIC backend, for lines, curves and fills.
%% Copyright (c) 1995-1996 Ross Moore <ross@mpce.mq.edu.au>
%%
%% This file is part of the Xy-pic package for graphs and diagrams in TeX.
%% See the companion README and INSTALL files for further information.
%% Copyright (c) 1991-1996 Kristoffer H. Rose <krisrose@brics.dk>
%%
%% The Xy-pic package is free software; you can redistribute it and/or modify
%% it under the terms of the GNU General Public License as published by the
%% Free Software Foundation; either version 2 of the License, or (at your
%% option) any later version.
%%
%% The Xy-pic package is distributed in the hope that it will be useful, but
%% WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
%% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
%% for more details.
%%
%% You should have received a copy of the GNU General Public License along
%% with this package; if not, write to the Free Software Foundation, Inc.,
%% 675 Mass Ave, Cambridge, MA 02139, USA.
%%
\ifx\xyloaded\undefined \input xy \fi
\xyprovide{tpic}{TPIC backend}{\stripRCS$Revision: 3.3 $}%
 {Ross Moore}{ross@mpce.mq.edu.au}%
 {Mathematics Department, Macquarie University, NSW~2109, Australia}
\xynew@{if}\ifTPICspecials@
\xydef@\UseTPICspecials{\TPICspecials@true}
\xydef@\NoTPICspecials{\TPICspecials@false}
\xynew@{count}\xytpic@cnt
\xydef@\xytpic@max{300}
\xydef@\maxTPICpoints#1{\count@=#1 \relax
 \ifnum\count@>\tw@ \edef\xytpic@max{\the\count@}%
 \else\expandafter\xyTPICmaxwarning@\expandafter{\the\count@}\fi}
\xydef@\xyTPICmaxwarning@#1{max points must be at least 2, #1 invalid}
\xydef@\xytpic@style@@{\xytpic@fp}
\xydef@\xytpic@reset@{\gdef\xytpic@style@@{\xytpic@fp}%
 \global\xytpic@cnt=\z@ }
\xydef@\xytpic@set@#1{\xdef\xytpic@style@@{\noexpand#1}}
\xydef@\xytpic@pn#1{\xyTPIC@special{pn #1}}
\xydef@\xytpic@pa#1#2{\global\advance\xytpic@cnt\@ne\relax
 \ifnum\xytpic@cnt=\xytpic@max\relax \xyTPIC@special{pa #1 #2}%
 \kern-\X@c\raise-\Y@c\hbox{\xytpic@style@@}\kern\X@c
 \global\xytpic@cnt=\@ne \relax\fi \xyTPIC@special{pa #1 #2}}
\xydef@\xytpic@fp{\xyTPIC@special{fp}}
\xydef@\xytpic@ip{\xyTPIC@special{ip}}
\xydef@\xytpic@da#1{\xyTPIC@special{da #1}}
\xydef@\xytpic@dt#1{\xyTPIC@special{dt #1}}
\xydef@\xytpic@sp#1{\xyTPIC@special{sp #1}}
\xydef@\xytpic@ar#1#2#3#4#5#6{\xyTPIC@special{ar #1 #2 #3 #4 #5 #6}}
\xydef@\xytpic@ia#1#2#3#4#5#6{\xyTPIC@special{ia #1 #2 #3 #4 #5 #6}}
\xydef@\xytpic@sh#1{\xyTPIC@special{sh #1}}
\xydef@\xytpic@wh{\xyTPIC@special{sh 0}}
\xydef@\xytpic@bk{\xyTPIC@special{sh 1}}
\xydef@\xyTPIC@special#1{\special{#1}}
\xydef@\xyTPIC@noisy#1{\W@{TPIC: #1}\special{#1}}
\xydef@\NoisyTPIC{\let\xyTPIC@special=\xyTPIC@noisy}
\xydef@\xyTPICsplit@#1#2{\setboxz@h{#1\boxz@#2}}%
\xydef@\xytpic@pt#1{\dimen@=#1\divide\dimen@ by72
 \multiply\dimen@ by 1000 \advance\dimen@.5\p@
 \count@=\dimen@ \divide\count@\p@ }
\xydef@\xytpic@in#1{\dimen@=#1\divide\dimen@ by72
 \edef\next@{\expandafter\removePT@\the\dimen@}}%
\xydef@\xytpic@dot@@{\xytpic@pa00}
\xydef@\xytpic@width@{\xytpic@pt{\xylinethick@}%
 \expandafter\xytpic@pn\expandafter{\the\count@}}
\xydef@\xytpic@line{%
 \xytpic@dot@@ \xytpic@pt{-\d@X}\count@@=\count@
 \xytpic@pt\d@Y \edef\next@{{\the\count@@}{\the\count@}}%
 \expandafter\xytpic@pa\next@ \xytpic@style@@ \xytpic@reset@ }
\xydef@\xytpic@solid@@{\xytpic@set@\xytpic@fp}
\xydef@\xytpic@dashed@@{\xytpic@in\xydashl@ \xytpic@dad}
\xydef@\xytpic@dotted@@{\dimen@=.5\xydashl@ \xytpic@in\dimen@ \xytpic@dtd}
\xydef@\xytpic@dad{\expandafter\xytpic@set@\expandafter{%
 \expandafter\xytpic@da\expandafter{\next@}}}
\xydef@\xytpic@dtd{\expandafter\xytpic@set@\expandafter{%
 \expandafter\xytpic@dt\expandafter{\next@}}}
\xydef@\xytpic@polysolid@{\xytpic@set@\xytpic@fp}
\xydef@\xytpic@polydashed@#1{\count@=#1 \xytpic@dad}
\xydef@\xytpic@polydotted@#1{\count@=#1 \xytpic@dtd}
\xydef@\xytpic@postpoly@{\xytpic@style@@ \xytpic@reset@}
\xydef@\TPICalternative@#1#2{%
\expandafter\global\expandafter\let\csname origxy#2@\endcsname=#1%
 \xdef#1{\noexpand\ifTPICspecials@
 \noexpand\expandafter\expandafter\noexpand\csname xytpic@#2@\endcsname
 \noexpand\else
 \noexpand\expandafter\expandafter\noexpand\csname origxy#2@\endcsname
 \noexpand\fi}}%
\xydef@\setupxyTPIC@{\xywarning@{using TPIC specials}%
 \TPICalternative@{\solid@}{solid}%
 \TPICalternative@{\dash@}{dashed}%
 \TPICalternative@{\point@}{point}%
 \TPICalternative@{\circhar@@}{circhar}%
 \TPICalternative@{\splinesolid@}{splinesolid}%
 \xywithoption{frame}{\xyinputorelse@{xytp-f}{}\xyuncatcodes}%
 \let\setupxyTPIC@=\reloadxyTPIC@ 
 \activateTPIC@ }
\xydef@\xyunloadTPIC@{\xywarning@{TPIC specials turned off}%
 \xywithoption{curve}{\xysetup@@\uninstallTPICcurves@ }%
 \xywithoption{line}{\xysetup@@\uninstallTPICline@ }%
 \xywithoption{frame}{\xysetup@@\uninstallTPICframes@ }%
 \TPICspecials@false
 \let\setupxyTPIC@=\reloadxyTPIC@ }
\xydef@\activateTPIC@{%
 \xywithoption{line}{\xysetup@@\installTPICline@}%
 \xywithoption{curve}{\xysetup@@\installTPICcurves@}%
 \xywithoption{frame}{\xysetup@@\installTPICframes@}%
 \TPICspecials@true }
\xydef@\reloadxyTPIC@{\xywarning@{TPIC specials back on}\activateTPIC@ }
\xydef@\xytpic@solid@{%
 \ifInvisible@ \let\next@=\no@@
 \else \DN@{\xyTPICstraight@{\xytpic@solid@@ \xytpic@line}}\fi
 \next@ }
\xydef@\xytpic@dashed@{\line@
 \def\Connect@@{\xyTPICstraight@{\xytpic@dashed@@ \xytpic@line}}}
\xydef@\xytpic@point@{\xytpic@dot@@\xytpic@fp\egroup
 \Invisible@false \Hidden@false \def\Leftness@{.5}\def\Upness@{.5}\ctipEdge@
 \def\Drop@@{\styledboxz@}%
 \def\Connect@@{\xyTPICstraight@{\xytpic@dotted@@ \xytpic@line}}}
\xydef@\xyTPICstraight@#1{\setupDirection@
 \edef\Creset@@{\cfromthec@ \pfromthep@ \DirectionfromtheDirection@}%
 \DN@##1##2{\def\checkoverlap@@{%
 \ifdim##1\X@p>##1\X@c \let\next@=\relax \fi
 \ifdim##2\Y@p>##2\Y@c \let\next@=\relax \fi}}%
 \edef\nextii@{{\sd@X}{\sd@Y}}\expandafter\next@\nextii@
 \noCshavep@@ \edef\Cshavep@@{\pfromthep@ \noexpand\resetDirection@}%
 \noCshavec@@ \edef\Cshavec@@{\cfromthec@ \noexpand\resetDirection@}%
 \ifHidden@\else
 \ifdim\Y@c>\Y@max \Y@max=\Y@c \fi \ifdim\Y@p>\Y@max \Y@max=\Y@p \fi
 \ifdim\Y@c<\Y@min \Y@min=\Y@c \fi \ifdim\Y@p<\Y@min \Y@min=\Y@p \fi
 \ifdim\X@c>\X@max \X@max=\X@c \fi \ifdim\X@p>\X@max \X@max=\X@p \fi
 \ifdim\X@c<\X@min \X@min=\X@c \fi \ifdim\X@p<\X@min \X@min=\X@p \fi \fi
 \ifInvisible@\let\next@=\relax \else
 \DN@{\setboxz@h{\kern\X@c \raise\Y@c\hbox{#1}}%
 \ht\z@=\z@ \wd\z@=\z@ \dp\z@=\z@ {\Drop@@}}%
 \fi 
 \checkoverlap@@
 \ifdim\d@X=\z@ \ifdim\d@Y=\z@ \DN@{\relax}\fi\fi \next@
 \def\Cslidep@@{\noCslidep@@}\def\Cslidec@@{\noCslidec@@}%
 \def\Calong@@{\noCalong@@}\Creset@@ }
\xydef@\xytpic@splinesolid@{\xyTPICspline@\xytpic@fp }
\xydef@\xytpic@splinedashed@{\xytpic@in\xydashl@\expandafter\xyTPICspline@
 \expandafter{\expandafter\xytpic@da\expandafter{\next@}}}
\xydef@\xytpic@splinedotted@{\xytpic@in{.5\xydashl@}\expandafter\xyTPICspline@
 \expandafter{\expandafter\xytpic@dt\expandafter{\next@}}}
\xydef@\xyTPICspline@#1{\setbox\splinebox@=\copy\voidb@x
 \SloppyCurves
 \global\xytpic@cnt=\@ne \xytpic@set@{#1}%
 \def\splineextra@@{\xyTPICspline@dot}%
 \def\xycrvdrop@{ }\def\xycrvconn@{}\splineset@@ \xytpic@style@@}
\xydef@\xyTPICspline@dot{\xytpic@pt{\X@c}\count@@=\count@
 \xytpic@pt{-\Y@c}\edef\next@{{\the\count@@}{\the\count@}}%
 \expandafter\xytpic@pa\next@ }
\xydef@\xyTPIClinewidth@#1{\xytpic@pt{#1}\edef\next@{\the\count@}}
\xydef@\installTPICline@{%
 \let\xylinewidth@@=\xylinewidth@
 \let\xylineSpecial@@=\xytpic@pn
 \let\transxyline@@=\xyTPIClinewidth@ }
\xydef@\uninstallTPICline@{\UnloadLine@}%
\xydef@\xydoTPICcircle@#1{\DN@{#1}%
 \ifx\next@\empty\DN@{\xyTPICfullcircle@}%
 \else\expandafter\DNii@\expandafter{\addDASH@{}}%
 \ifx\next@\nextii@\DN@{\L@=\R@ \xyTPICfullcircle@}%
 \else\DN@{\dosolidcircle@{#1}}\fi\fi \next@ }
\xydef@\xyTPICfullcircle@{\xyTPICpartcircle@{00}0\twoPi@}%
\xydef@\xyTPICpartcircle@#1#2#3{%
 \xytpic@pt{\R@}\expandafter\DNii@\expandafter{\the\count@}%
 \xytpic@pt{\L@}\edef\next@{#1{\nextii@}{\the\count@}{#2}{#3}}%
 \expandafter\xytpic@ar\next@ }
\xydef@\qartPi@{0.7853981}
\xydef@\tartPi@{2.3561944}
\xydef@\xytpic@circhar@#1{\xytpic@width@\ifcase#1%
 \xytpic@pt{\R@}\edef\next@{{{\the\count@}0}}%
 \expandafter\xyTPICcirchar@i\next@{\tartPi@}{\fullPi@}\kern\partroottwo\R@
 \or
 \xytpic@pt{\halfroottwo\R@}\edef\next@{{{\the\count@}0}}%
 \expandafter\xyTPICcirchar@i\next@{\halfPi@}{\tartPi@}\kern\halfroottwo\R@
 \or
 \xytpic@pt{\z@}\edef\next@{{{\the\count@}0}}%
 \expandafter\xyTPICcirchar@i\next@{\qartPi@}{\halfPi@}\kern\halfroottwo\R@
 \or
 \xytpic@pt{-\halfroottwo\R@}\edef\next@{{{\the\count@}0}}%
 \expandafter\xyTPICcirchar@i\next@0{\qartPi@}\kern\partroottwo\R@
 \or
 \xytpic@pt{-\halfroottwo\R@}\edef\next@{{{\the\count@}0}}%
 \expandafter\xyTPICcirchar@i\next@{-\qartPi@}0\kern\partroottwo\R@
 \or
 \xytpic@pt{\z@}\edef\next@{{{\the\count@}0}}%
 \expandafter\xyTPICcirchar@i\next@{-\halfPi@}{-\qartPi@}\kern\halfroottwo\R@
 \or
 \xytpic@pt{\halfroottwo\R@}\edef\next@{{{\the\count@}0}}%
 \expandafter\xyTPICcirchar@i\next@{-\tartPi@}{-\halfPi@}\kern\halfroottwo\R@
 \or
 \xytpic@pt{\R@}\edef\next@{{{\the\count@}0}}%
 \expandafter\xyTPICcirchar@i\next@{-\fullPi@}{-\tartPi@}\kern\partroottwo\R@
 \fi}
\xydef@\xyTPICcirchar@i#1#2#3{\L@=\R@ \xyTPICpartcircle@{#1}{#2}{#3}}
\xydef@\xyTPIC@spline@ii@{\DN@{\xy@spline@ii}%
 \ifx\splineSTYLE@\empty\DN@{\xyTPICqspline@{0}}%
 \else\expandafter\DNii@\expandafter{\addDASH@{}}%
 \ifx\splineSTYLE@\nextii@\DN@{\xyTPICqspline@{0}}%
 \else\expandafter\DNii@\expandafter{\addDOT@{}}%
 \ifx\splineSTYLE@\nextii@\DN@{\xyTPICqspline@{-.5}}%
 \else\expandafter\expandafter\expandafter\DNii@\expandafter\expandafter
 \expandafter{\expandafter\addDASH@\addDASH@{}}%
 \ifx\splineSTYLE@\nextii@\DN@{\xyTPICqspline@{}}%
 \fi\fi\fi\fi
 \next@ }%
\xydef@\xyTPIC@accumulate{\xytpic@pt\X@c \count@@=\count@ 
 \xytpic@pt{-\Y@c}\edef\next@{{\the\count@@}{\the\count@}}%
 \expandafter\xytpic@pa\next@ }
\xydef@\xyTPICqspline@#1{\xytpic@width@
 \xytpic@in{#1\xydashl@}\expandafter\gdef\expandafter\xytpic@style@@
 \expandafter{\expandafter\xytpic@sp\expandafter{\next@}}%
 \save@ \cfromp@ \xyTPIC@accumulate
 \edef\smapp@@{\s@bot}\smapxy@i{\xyTPIC@accumulate}%
 \leave@ \xyTPIC@accumulate \xytpic@style@@ \xytpic@reset@
 \enter@{}\xy@spline@x }
\xydef@\installTPICcurves@{%
 \let\dosolidcircle@@=\xydoTPICcircle@
 \let\xy@spline@ii@@=\xyTPIC@spline@ii@
 }
\xydef@\uninstallTPICcurves@{%
 \let\dosolidcircle@@=\dosolidcircle@
 \let\xy@spline@ii@@=\xy@spline@ii }
 \xywithoption{frame}{\xyinputorelse@{xytp-f}{}}
\xydef@\uninstallTPICframes@{\UnloadFrames@}
\xyendinput
