summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/generic/pgf/math/pgfmathutil.code.tex
blob: 07a573c54baacfc24fbfd73b603816c457cbe753 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
% This file defines utilities common to the \pgfmath files.
%
% (c) 2007 Mark Wibrow
%
% but subject to the LaTeX Project Public License 
% (http://www.latex-project.org/lppl.txt)
%
% and the GNU Public License 
% (http://www.gnu.org/licenses/gpl.txt)
%
% Version 0.0 08/03/2007

% Alias some pgf stuff, just in case it needs replacing later.
%
\let\pgfmath@x\pgf@x
\let\pgfmath@xa\pgf@xa
\let\pgfmath@xb\pgf@xb
\let\pgfmath@xc\pgf@xc

\let\pgfmath@y\pgf@y
\let\pgfmath@ya\pgf@ya
\let\pgfmath@yb\pgf@yb
\let\pgfmath@yc\pgf@yc

\let\c@pgfmath@counta\c@pgf@counta
\let\c@pgfmath@countb\c@pgf@countb
\let\c@pgfmath@countc\c@pgf@countc

\let\pgfmath@ifnextchar\pgfutil@ifnextchar

\let\pgfmath@tonumber\pgf@sys@tonumber

\let\pgfmath@ifundefined\pgfutil@ifundefined

\newif\ifpgfmath@in@
\def\pgfmath@in@#1#2{%
 \def\pgfmath@in@@##1#1##2##3\pgfmath@in@@{%
  \ifx\pgfmath@in@##2\pgfmath@in@false\else\pgfmath@in@true\fi}%
 \pgfmath@in@@#2#1\pgfmath@in@\pgfmath@in@@}
 
% Need to redefine to something more appropriate...?
%
\def\pgfmath@error#1#2{\PackageError{PGF Math}{#1}{#2}}
\def\pgfmath@warning#1#2{\PackageWarning{PGF Math}{#1}{#2}}

% \pgfmath@pt
%
% Needed to test for 'pt' resulting from 
% expansion using \the.
%
{\catcode`\p=12\catcode`\t=12\gdef\PgfmaTh@PT{pt}}		
\edef\pgfmath@pt{\PgfmaTh@PT}%

% \pgfmath@ifin@
%
% Interface for \pgfutil@in@
%
\def\pgfmath@ifin@#1#2{%
	\pgfutil@in@{#1}{#2}%
	\ifpgfutil@in@%
		\expandafter\pgfmath@firstoftwo%
	\else%
		\expandafter\pgfmath@secondoftwo%
	\fi%
}

% \pgfmath@empty
%
% A handy macro.
%
\def\pgfmath@empty{}


% \ifpgfmath@empty
%
% Has #1 been let to \pgf@empty?
%
\def\ifpgfmath@empty#1{%
	\ifx#1\pgfmath@empty\relax
		\expandafter\pgfmath@firstoftwo%
	\else%
		\expandafter\pgfmath@secondoftwo%
	\fi%
}
\def\pgfmath@firstoftwo#1#2{#1}
\def\pgfmath@secondoftwo#1#2{#2}

% \ifpgfmath@ifletto
%
% Has #1 been let to #2?
%
\def\pgfmath@ifletto#1#2{%
	\ifx#1#2\relax%
		\expandafter\pgfmath@firstoftwo%
	\else%
		\expandafter\pgfmath@secondoftwo%
	\fi%
}

% \ifpgfmath@iflettoeither
%
% Has #1 been let to #2 or #3?
%
\def\pgfmath@iflettoeither#1#2#3{%
	\ifx#1#2\relax%
		\let\pgfmath@equaltoeithernext\pgfmath@firstoftwo%
	\else%
		\ifx#1#3\relax%
			\let\pgfmath@equaltoeithernext\pgfmath@firstoftwo%
		\else%
			\let\pgfmath@equaltoeithernext\pgfmath@secondoftwo%
		\fi%
	\fi%
	\pgfmath@equaltoeithernext%
}

% \pgfmath@gobbletilpgfmath@
%
% Gobble stream until \pgfmath@ {which is undefined}.
% 
\def\pgfmath@gobbletilpgfmath@#1\pgfmath@{}
\def\pgfmath@gobbleone#1{}%


% \pgfmathloop
%
% A version of the standard TeX and LaTeX
% \loop, with an additional macro \pgfmathcounter
% (which is *not* a TeX counter) which keeps
% track of the iterations.
%
\newif\ifpgfmathcontinueloop
\def\pgfmathloop#1\repeatpgfmathloop{%
	\def\pgfmathcounter{1}%
	\def\pgfmath@iterate{%
		#1\relax%
		{% Do this inside a group, just in case...
			\c@pgfmath@counta=\pgfmathcounter%
			\advance\c@pgfmath@counta by1\relax%
			\xdef\pgfmathloop@temp{\the\c@pgfmath@counta}%
		}%	
		\edef\pgfmathcounter{\pgfmathloop@temp}%
		\expandafter\pgfmath@iterate\fi}%
	\pgfmath@iterate\let\pgfmath@iterate=\relax}
\let\repeatpgfmathloop=\fi


% \pgfmath@returnone
%
% \edef \pfgmathresult to the value of #1 after the end
% of a group.
%
% #1 - a dimension/count/skip register or a macro
%      representing a number or dimension.
%
\def\pgfmath@returnone#1{%
	\afterassignment\pgfmath@gobbletilpgfmath@%
	\pgfmath@x#1pt\relax\pgfmath@%
	\xdef\pgfmath@resulttemp{\pgf@sys@tonumber{\pgfmath@x}}%
	\gdef\pgfmath@returnone@{%
		\edef\pgfmathresult{\pgfmath@resulttemp}%
	}%
	\aftergroup\pgfmath@returnone@}


% \pgfmath@returntwo
%
% \edef \pfgmathresultx to the value of #1, and
% \pgfmathresulty to the value of #2, after the end
% of a group.
%
% #1 - a dimension/count/skip register or a macro
%      representing a number or dimension.
%
% #2 - a dimension/count/skip register or a macro
%      representing a number or dimension.
%	
\def\pgfmath@returntwo#1#2{%
	\afterassignment\pgfmath@gobbletilpgfmath@%
	\pgfmath@x#1pt\relax\pgfmath@%
	\xdef\pgfmath@resulttempx{\pgf@sys@tonumber{\pgfmath@x}}%
	\afterassignment\pgfmath@gobbletilpgfmath@%
	\pgfmath@x#2pt\relax\pgfmath@%
	\xdef\pgfmath@resulttempx{\pgf@sys@tonumber{\pgfmath@x}}%
	\gdef\pgfmath@returntwo@{%
		\edef\pgfmathresultx{\pgfmath@resulttempx}%
		\edef\pgfmathresulty{\pgfmath@resulttempy}%
	}%
	\aftergroup\pgfmath@returntwo@}

% \pgfmath@smuggleone
%
% Summgle a macro outside a group.
%
\def\pgfmath@smuggleone#1{%
	\xdef\pgfmath@smuggleditem{#1}%
	\gdef\pgfmath@@smuggleone{\edef#1{\pgfmath@smuggleditem}}%
	\aftergroup\pgfmath@@smuggleone}