| 1 |
% Copyright 2019 by Till Tantau |
| 2 |
% |
| 3 |
% This file may be distributed and/or modified |
| 4 |
% |
| 5 |
% 1. under the LaTeX Project Public License and/or |
| 6 |
% 2. under the GNU Public License. |
| 7 |
% |
| 8 |
% See the file doc/generic/pgf/licenses/LICENSE for more details. |
| 9 |
|
| 10 |
\ProvidesFileRCS{pgfmodulesorting.code.tex} |
| 11 |
|
| 12 |
% |
| 13 |
% This file defines commands for sorting data. This is useful for 3d plots, |
| 14 |
% but also for drawing things in the correct order. |
| 15 |
% |
| 16 |
|
| 17 |
|
| 18 |
\newcount\pgfsortingbuckets |
| 19 |
|
| 20 |
|
| 21 |
% Init the sorting |
| 22 |
% |
| 23 |
% #1 = number of buckets |
| 24 |
% |
| 25 |
% Description: |
| 26 |
% |
| 27 |
% This macro inits a sorting. At any time there can be only one active |
| 28 |
% sorting. When you init the sorting, #1 should be a number of |
| 29 |
% buckets. You can then call \pgfsortinginsert to insert code into the |
| 30 |
% buckets. Once you are done, calling \pgfsortingexecute will execute |
| 31 |
% first the code in buckets 0, then the code in bucket 1, and so on to |
| 32 |
% bucket number #1-1. |
| 33 |
% |
| 34 |
\def\pgfsortinginit#1{ |
| 35 |
\pgfsortingbuckets#1\relax% |
| 36 |
\c@pgf@counta=0\relax |
| 37 |
\pgfutil@loop |
| 38 |
\ifnum\c@pgf@counta<\c@pgf@countb\relax% |
| 39 |
\expandafter\global\expandafter\let\csname pgf@sort@\the\c@pgf@counta\endcsname\pgfutil@empty% |
| 40 |
\advance\c@pgf@counta by1\relax% |
| 41 |
\pgfutil@repeat |
| 42 |
}% |
| 43 |
|
| 44 |
% Insert code into some bucket |
| 45 |
% |
| 46 |
% #1 = the bucket |
| 47 |
% #2 = the code |
| 48 |
% |
| 49 |
\def\pgfsortinginsert#1#2{ |
| 50 |
\expandafter\let\expandafter\pgf@temp\csname pgf@lib@sort@#1\endcsname% |
| 51 |
\expandafter\def\expandafter\pgf@temp\expandafter{\pgf@temp#2}% |
| 52 |
\expandafter\global\expandafter\let\csname pgf@lib@sort@\the\c@pgf@counta\endcsname\pgf@temp% |
| 53 |
}% |
| 54 |
|
| 55 |
|
| 56 |
% After all code has been inserted into the buckets, you can call |
| 57 |
% this method to execute the code in the order of the buckets. |
| 58 |
\def\pgfsortingexecute{ |
| 59 |
\c@pgf@countb=\pgfoovalueof{buckets}\relax |
| 60 |
\c@pgf@counta=0\relax |
| 61 |
\pgfutil@loop |
| 62 |
\ifnum\c@pgf@counta<\c@pgf@countb\relax% |
| 63 |
\csname pgf@lib@sort@\the\c@pgf@counta\endcsname% |
| 64 |
\advance\c@pgf@counta by1\relax% |
| 65 |
\pgfutil@repeat |
| 66 |
}% |
| 67 |
|
| 68 |
|
| 69 |
\endinput |