summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2012-07-24 16:55:31 +0000
committerKarl Berry <karl@freefriends.org>2012-07-24 16:55:31 +0000
commit3772071fea36876c9bd7ed1fd05f7352f1d362d5 (patch)
tree0d3a5b83892d21e6cba11f5df4650ff34fd53870
parent3accf11dd41cac5f2c81b83a2a712c77ffab2b6a (diff)
randomwalk (18jul12)
git-svn-id: svn://tug.org/texlive/trunk@27139 c570f23f-e606-0410-a88d-b1316a301751
-rw-r--r--Master/texmf-dist/doc/latex/randomwalk/README24
-rw-r--r--Master/texmf-dist/doc/latex/randomwalk/randomwalk.pdfbin457902 -> 519255 bytes
-rw-r--r--Master/texmf-dist/source/latex/randomwalk/randomwalk.dtx531
-rw-r--r--Master/texmf-dist/source/latex/randomwalk/randomwalk.ins6
-rw-r--r--Master/texmf-dist/tex/latex/randomwalk/randomwalk.sty274
5 files changed, 373 insertions, 462 deletions
diff --git a/Master/texmf-dist/doc/latex/randomwalk/README b/Master/texmf-dist/doc/latex/randomwalk/README
index a2d9741aeaa..4d128bebdc3 100644
--- a/Master/texmf-dist/doc/latex/randomwalk/README
+++ b/Master/texmf-dist/doc/latex/randomwalk/README
@@ -5,25 +5,27 @@ Released under the LaTeX Project Public License v1.3c or later
See http://www.latex-project.org/lppl.txt
----------------------------------------------------------------
-The randomwalk package provides a user command, \RandomWalk,
-to draw random walks with a given number of steps. Lengths and angles
-of the steps can be customized in various ways.
+The randomwalk package provides a user command, "\RandomWalk", to draw
+random walks with a given number of steps. Lengths and angles of the
+steps can be customized in various ways.
-This package uses TikZ. It also uses the expl3 and xpackages bundles.
+This package uses TikZ. It also uses the l3kernel and l3packages bundles.
This is work in progress, all suggestions/comments/bug reports are welcome!
-The package is extracted by running
- pdflatex randomwalk.ins
+The package is extracted by running
+
+ pdflatex randomwalk.ins
The documentation is produced by running
- pdflatex randomwalk.dtx
- makeindex -s gglo.ist -o randomwalk.gls randomwalk.glo
- makeindex -s gind.ist -o randomwalk.ind randomwalk.idx
- pdflatex randomwalk.dtx
- pdflatex randomwalk.dtx
+
+ pdflatex randomwalk.dtx
+ makeindex -s gglo.ist -o randomwalk.gls randomwalk.glo
+ makeindex -s gind.ist -o randomwalk.ind randomwalk.idx
+ pdflatex randomwalk.dtx
+ pdflatex randomwalk.dtx
diff --git a/Master/texmf-dist/doc/latex/randomwalk/randomwalk.pdf b/Master/texmf-dist/doc/latex/randomwalk/randomwalk.pdf
index 8ad6e1ed658..3463b0c2aee 100644
--- a/Master/texmf-dist/doc/latex/randomwalk/randomwalk.pdf
+++ b/Master/texmf-dist/doc/latex/randomwalk/randomwalk.pdf
Binary files differ
diff --git a/Master/texmf-dist/source/latex/randomwalk/randomwalk.dtx b/Master/texmf-dist/source/latex/randomwalk/randomwalk.dtx
index 1e38dd7d3bf..13512f7b461 100644
--- a/Master/texmf-dist/source/latex/randomwalk/randomwalk.dtx
+++ b/Master/texmf-dist/source/latex/randomwalk/randomwalk.dtx
@@ -1,5 +1,5 @@
% \iffalse
-%% File: randomwalk.dtx Copyright (C) 2011 Bruno Le Floch
+%% File: randomwalk.dtx Copyright (C) 2011-2012 Bruno Le Floch
%%
%% It may be distributed and/or modified under the conditions of the
%% LaTeX Project Public License (LPPL), either version 1.3c of this
@@ -13,15 +13,12 @@
%<*driver|package>
\RequirePackage{l3names}
%</driver|package>
-%\fi
-\GetIdInfo$Id: randomwalk.dtx 0.2 2011-09-09 10:15:31Z blefloch $
- {Customizable Random Walks using TikZ}%
-%\iffalse
%<*driver>
%\fi
-\ProvidesFile{\ExplFileName.dtx}
- [\ExplFileDate\space v\ExplFileVersion\space\ExplFileDescription]
+\ProvidesFile{randomwalk.dtx}
+ [2012-07-10 v0.2 Customizable random walks using TikZ]
%\iffalse
+\RequirePackage[check-declarations]{expl3}
\documentclass[full]{l3doc}
\usepackage{randomwalk}
\usepackage{amsmath}
@@ -34,9 +31,9 @@
%
% \title{The \textsf{randomwalk} package: \\
% customizable random walks using TikZ\thanks{This file has version
-% number \ExplFileVersion, last revised \ExplFileDate.}}
+% number 0.2, last revised 2012-07-10.}}
% \author{Bruno Le Floch}
-% \date{\ExplFileDate}
+% \date{July 10, 2012}
%
% \maketitle
% \tableofcontents
@@ -45,14 +42,14 @@
%
% \begin{abstract}
%
-% The |randomwalk| package draws random walks using TikZ. The following
-% parameters can be customized:
+% The \pkg{randomwalk} package draws random walks using TikZ. The
+% following parameters can be customized:
% \begin{itemize}
-% \item The number of steps, of course.
-% \item The length of the steps, either a fixed length, or a length taken
-% at random from a given set.
-% \item The angle of each step, either taken at random from a given set, or
-% uniformly distributed.
+% \item The number of steps, of course.
+% \item The length of the steps, either a fixed length, or a length
+% taken at random from a given set.
+% \item The angle of each step, either taken at random from a given
+% set, or uniformly distributed.
% \end{itemize}
%
% \end{abstract}
@@ -60,8 +57,9 @@
%
% \section{How to use it}
%
-% The |randomwalk| package has exactly one user command: |\RandomWalk|,
-% which takes a list of key-value pairs as its argument. A few examples:
+% The \pkg{randomwalk} package has exactly one user command:
+% \cs{RandomWalk}, which takes a list of key-value pairs as its
+% argument. A few examples:
% \begin{verbatim}
% \RandomWalk {number = 100, length = {4pt, 10pt}}
% \RandomWalk {number = 100, angles = {0,60,120,180,240,300}, degree}
@@ -70,37 +68,34 @@
% \end{verbatim}
% The simplest is to give a list of all the keys, and their meaning:
% \begin{itemize}
-%
-% \item |number|: the number of steps (default \(10\))
-%
-% \item |length|: the length of each step: either one dimension (e.g., |1em|),
-% or a comma-separated list of dimensions (e.g. |{2pt, 5pt}|), by
-% default |10pt|. The length of each step is a random element in this set
-% of possible dimensions.
-%
-% \item |angles|: the polar angle for each step: a comma-separated list of
-% angles, and each step takes a random angle among the list. If this is not specified, then the angle is uniformly distributed along the circle.
-%
-% \item |degree|(|s|): specifies that the angles are given in degrees.
-%
-% \item |angles-relative|: instead of being absolute, the angles are relative
-% to the direction of the previous step.
-%
+% \item \texttt{number}: the number of steps (default \(10\))
+% \item \texttt{length}: the length of each step: either one dimension
+% (\emph{e.g.}, |1em|), or a comma-separated list of dimensions
+% (\emph{e.g.}, |{2pt, 5pt}|), by default |10pt|. The length of each
+% step is a random element in this set of possible dimensions.
+% \item \texttt{angles}: the polar angle for each step: a
+% comma-separated list of angles, and each step takes a random angle
+% among the list. If this is not specified, then the angle is
+% uniformly distributed along the circle.
+% \item \texttt{degree} or \texttt{degrees}: specify that the angles
+% are given in degrees.
+% \item \texttt{angles-relative}: instead of being absolute, the
+% angles are relative to the direction of the previous step.
% \end{itemize}
%
% \begin{figure}
% \begin{center}
% \framebox{\RandomWalk {number = 400, length = {4pt, 10pt}}}
-% \caption{The result of \texttt{RandomWalk\{number\ =\
-% 400,\ length\ =\ \{4pt,\ 10pt\}\}}: a \(400\) steps long walk,
-% where each step has one of two lengths.}
+% \caption{The result of \texttt{RandomWalk\{number\ =\ 400,\
+% length\ =\ \{4pt,\ 10pt\}\}}: a \(400\) steps long walk, where
+% each step has one of two lengths.}
% \end{center}
% \end{figure}
%
% \begin{figure}
% \begin{center}
-% \framebox{\RandomWalk{number = 100,
-% angles = {0,60,120,180,240,300}, degrees}}
+% \framebox{\RandomWalk{number = 100, angles =
+% {0,60,120,180,240,300}, degrees}}
% \caption{The result of \texttt{\string\RandomWalk\{number\ =\
% 100,\ angles\ =\ \{0,60,120,180,240,300\}, degrees\}}: angles
% are constrained.}
@@ -109,10 +104,10 @@
%
% \begin{figure}
% \begin{center}
-% \framebox{\RandomWalk {number = 40, length = 1em,
-% angles = {0,15,30,-15,-30}, degree, angles-relative}}
-% \caption{A last example: \texttt{\string\RandomWalk\ \{number\ =\ 100,\
-% length\ =\ 2em,\ angles\ =\ \{0,10,20,-10,-20\},\
+% \framebox{\RandomWalk {number = 40, length = 1em, angles =
+% {0,15,30,-15,-30}, degree, angles-relative}}
+% \caption{A last example: \texttt{\string\RandomWalk\ \{number\ =\
+% 100,\ length\ =\ 2em,\ angles\ =\ \{0,10,20,-10,-20\},\
% degree,\ angles-relative\}}}
% \end{center}
% \end{figure}
@@ -125,147 +120,225 @@
%
% \subsection{Packages}
%
-% The whole |expl3| bundle is loaded first, including Joseph Wright's
-% very useful package |l3fp.sty| for floating point calculations.
+% The whole \pkg{expl3} bundle is loaded first.
%
%<*package>
% \begin{macrocode}
+%<@@=randomwalk>
+% \end{macrocode}
+%
+% \begin{macrocode}
\ProvidesExplPackage
- {\ExplFileName}{\ExplFileDate}{\ExplFileVersion}{\ExplFileDescription}
+ {randomwalk.sty}{2012/07/10}{0.2}{Customizable random walks using TikZ}
\RequirePackage{expl3}
\RequirePackage{xparse}
% \end{macrocode}
%
-% I use some LaTeX2e packages: TikZ, for figures, and lcg for
-% random numbers.
+% I use some \LaTeXe{} packages: \pkg{TikZ}, for figures, and \pkg{lcg}
+% for random numbers.
% \begin{macrocode}
\RequirePackage{tikz}
% \end{macrocode}
%
-% |lcg| needs to know the smallest and biggest random numbers that it
-% should produce, |\c_rw_lcg_first| and |_last|. It will then store them in
-% |\c@lcg@rand|: the |\c@| is there because of how \LaTeXe\ defines
-% counters. To make it clear that |\c| has a very special meaning here,
-% I do not follow \LaTeX3 naming conventions.
+% \pkg{lcg} needs to know the smallest and biggest random numbers that
+% it should produce, which we take to be $0$ and $\cs{c_@@_lcg_last_int}
+% = 2^{31}-2$. It will then store them in \cs{c@lcg@rand}: the |\c@| is
+% there because of how \LaTeXe{} defines counters. To make it clear that
+% |\c| has a very special meaning here, I do not follow \LaTeX3 naming
+% conventions.
%
-% The |lcg| package would support a range of \( 2^{31} - 1 \), but
-% |l3fp| constrains us to \(9\) digit numbers, so we take the closest
-% available power of \(2\), namely \( 536870911 = 2^{29} - 1 \).
+% It seems that the \pkg{lcg} package has to be loaded after the
+% document class, hence we do it \cs{AtBeginDocument}.
+% \begin{macrocode}
+\int_const:Nn \c_@@_lcg_last_int { \c_max_int - \c_one }
+\AtBeginDocument
+ {
+ \RequirePackage
+ [
+ first= \c_zero ,
+ last = \c_@@_lcg_last_int ,
+ counter = lcg@rand
+ ]
+ { lcg }
+ \rand % This \rand avoids some very odd bug.
+ }
+% \end{macrocode}
+%
+% \subsection{Variables}
%
+% \begin{variable}{\l_@@_step_number_int}
+% The number of steps requested by the caller.
% \begin{macrocode}
-\int_const:Nn \c_rw_lcg_first_int {0}
-\int_const:Nn \c_rw_lcg_last_int {536870911}
-\int_const:Nn \c_rw_lcg_range_int
- { \c_rw_lcg_last_int - \c_rw_lcg_first_int }
-\RequirePackage
- [
- first= \c_rw_lcg_first_int,
- last = \c_rw_lcg_last_int,
- counter = lcg@rand
- ]
- { lcg }
-\rand % This \rand avoids some very odd bug.
+\int_new:N \l_@@_step_number_int
% \end{macrocode}
+% \end{variable}
%
-% We need this constant for fast conversion from degrees to radians later.
+% \begin{variable}{\l_@@_relative_angles_bool}
+% Booleans for whether angles are relative (keyval option).
% \begin{macrocode}
-\fp_const:Nn \c_rw_one_degree_fp {+1.74532925e-2}
+\bool_new:N \l_@@_relative_angles_bool
% \end{macrocode}
+% \end{variable}
%
+% \begin{variable}{\l_@@_revert_random_bool}
+% Booleans for whether to revert the random seed to its original value
+% or keep the last value reached at the end of a random path.
+% \begin{macrocode}
+\bool_new:N \l_@@_revert_random_bool
+% \end{macrocode}
+% \end{variable}
+%
+% \begin{macro}{\@@_rand_angle:, \@@_rand_length:}
+% Set the \cs{l_@@_angle_fp} and \cs{l_@@_length_fp} of the next step,
+% most often randomly.
+% \begin{macrocode}
+\cs_new_protected_nopar:Npn \@@_rand_angle: { }
+\cs_new_protected_nopar:Npn \@@_rand_length: { }
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{variable}{\l_@@_angle_fp, \l_@@_length_fp}
+% Angle and length of the next step.
+% \begin{macrocode}
+\fp_new:N \l_@@_angle_fp
+\fp_new:N \l_@@_length_fp
+% \end{macrocode}
+% \end{variable}
+%
+% \begin{variable}{\l_@@_old_x_fp, \l_@@_old_y_fp}
+% \begin{variable}{\l_@@_new_x_fp, \l_@@_new_y_fp}
+% Coordinates of the two ends of each step: each \cs{draw} statement
+% goes from the |_old| point to the |_new| point. See
+% \cs{@@_step_draw:}.
+% \begin{macrocode}
+\fp_new:N \l_@@_old_x_fp
+\fp_new:N \l_@@_old_y_fp
+\fp_new:N \l_@@_new_x_fp
+\fp_new:N \l_@@_new_y_fp
+% \end{macrocode}
+% \end{variable}
+% \end{variable}
+%
+% \begin{variable}{\l_@@_angles_seq, \l_@@_lengths_seq}
+% Sequences containing all allowed angles and lengths.
+% \begin{macrocode}
+\seq_new:N \l_@@_angles_seq
+\seq_new:N \l_@@_lengths_seq
+% \end{macrocode}
+% \end{variable}
%
% \subsection{How the key-value list is treated}
%
% \begin{macro}{\RandomWalk}
-% The only user command is |\RandomWalk|: it simply does the setup, and
-% calls the internal macro |\rw_walk:|.
+% The only user command is \cs{RandomWalk}: it simply does the setup,
+% and calls the internal macro \cs{@@_walk:}.
% \begin{macrocode}
\DeclareDocumentCommand \RandomWalk { m }
{
- \rw_set_defaults:
+ \@@_set_defaults:
\keys_set:nn { randomwalk } { #1 }
- \rw_walk:
+ \@@_walk:
}
% \end{macrocode}
% \end{macro}
%
-%
-% \begin{macro}{\g_rw_Ado_tl}
-% \begin{macro}{\g_rw_Ldo_tl}
-% \begin{macro}{\rw_set_defaults:}
+% \begin{macro}{\@@_set_defaults:}
% Currently, the package treats the length of steps, and the angle,
-% completely independently. The token list \cs{g_rw_Ldo_tl} contains
-% the action that should be done to decide the length of the next step,
-% while the token list \cs{g_rw_Ado_tl} pertains to the angle.
+% completely independently. The function \cs{@@_rand_length:}
+% contains the action that decides the length of the next step, while
+% the function \cs{@@_rand_angle:} pertains to the angle.
%
-% \cs{rw_set_defaults:} sets the default values before processing the user's
-% key-value input.
+% \cs{@@_set_defaults:} sets the default values before processing the
+% user's key-value input.
% \begin{macrocode}
-\tl_new:N \g_rw_Ado_tl
-\tl_new:N \g_rw_Ldo_tl
-\bool_new:N \l_rw_A_relative_bool
-\bool_new:N \l_rw_revert_random_bool
-\cs_new:Npn \rw_set_defaults:
+\cs_new:Npn \@@_set_defaults:
{
- \fp_set:Nn \l_rw_step_length_fp {10}
- \int_set:Nn \l_rw_step_number_int {10}
- \tl_gset:Nn \g_rw_Ado_tl { \rw_Ainterval:nn {-\c_pi_fp} {\c_pi_fp} }
- \tl_gset:Nn \g_rw_Ldo_tl { \rw_Lfixed:n \l_rw_step_length_fp } %^^A bug?
- \bool_set_false:N \l_rw_revert_random_bool
- \bool_set_false:N \l_rw_A_relative_bool
+ \int_set:Nn \l_@@_step_number_int {10}
+ \cs_gset_protected_nopar:Npn \@@_rand_angle:
+ { \@@_fp_set_rand:Nnn \l_@@_angle_fp { - pi } { pi } }
+ \cs_gset_protected_nopar:Npn \@@_rand_length:
+ { \fp_set:Nn \l_@@_length_fp {10} }
+ \bool_set_false:N \l_@@_revert_random_bool
+ \bool_set_false:N \l_@@_relative_angles_bool
}
% \end{macrocode}
% \end{macro}
-% \end{macro}
-% \end{macro}
%
% \begin{macro}{\keys_define:nn}
% We introduce the keys for the package.
% \begin{macrocode}
\keys_define:nn { randomwalk }
{
- number .value_required:,
- length .value_required:,
- angles .value_required:,
- number .code:n = {\int_set:Nn \l_rw_step_number_int {#1}},
+ number .value_required: ,
+ length .value_required: ,
+ angles .value_required: ,
+ number .int_set:N = \l_@@_step_number_int ,
length .code:n =
{
- \clist_set:Nn \l_rw_lengths_clist {#1}
- \rw_clist_fp_from_dim:N \l_rw_lengths_clist
- \int_compare:nNnTF { \clist_length:N \l_rw_lengths_clist } = {1}
- { \tl_gset:Nn \g_rw_Ldo_tl { \rw_Lfixed:n \l_rw_lengths_clist } }
- { \tl_gset:Nn \g_rw_Ldo_tl { \rw_Llist:N \l_rw_lengths_clist } }
- },
+ \seq_set_split:Nnn \l_@@_lengths_seq { , } {#1}
+ \seq_set_map:NNn \l_@@_lengths_seq
+ \l_@@_lengths_seq { \dim_to_fp:n {##1} }
+ \int_compare:nNnTF { \seq_length:N \l_@@_lengths_seq } = {1}
+ {
+ \cs_gset_protected_nopar:Npn \@@_rand_length:
+ { \fp_set:Nn \l_@@_length_fp {#1} }
+ }
+ {
+ \cs_gset_protected_nopar:Npn \@@_rand_length:
+ {
+ \@@_fp_set_rand_seq_item:NN
+ \l_@@_length_fp \l_@@_lengths_seq
+ }
+ }
+ } ,
angles .code:n =
{
- \clist_set:Nn \l_rw_angles_clist {#1}
- \tl_gset:Nn \g_rw_Ado_tl { \rw_Alist:N \l_rw_angles_clist }
- },
- degree .code:n = { \rw_radians_from_degrees:N \l_rw_angles_clist },
- degrees .code:n = { \rw_radians_from_degrees:N \l_rw_angles_clist },
- angles-relative .code:n = { \bool_set_true:N \l_rw_A_relative_bool },
- revert-random .bool_set:N = \l_rw_revert_random_bool,
+ \seq_set_split:Nnn \l_@@_angles_seq { , } {#1}
+ \cs_gset_protected_nopar:Npn \@@_rand_angle:
+ {
+ \bool_if:NTF \l_@@_relative_angles_bool
+ { \@@_fp_add_rand_seq_item:NN }
+ { \@@_fp_set_rand_seq_item:NN }
+ \l_@@_angle_fp \l_@@_angles_seq
+ }
+ } ,
+ degree .code:n =
+ { \@@_radians_from_degrees:N \l_@@_angles_seq } ,
+ degrees .code:n =
+ { \@@_radians_from_degrees:N \l_@@_angles_seq } ,
+ angles-relative .code:n =
+ { \bool_set_true:N \l_@@_relative_angles_bool } ,
+ revert-random .bool_set:N = \l_@@_revert_random_bool ,
}
% \end{macrocode}
% \end{macro}
%
+% \begin{macro}{\@@_radians_from_degrees:N}
+% Helper macro to convert all items in |#1| to degrees.
+% \begin{macrocode}
+\cs_new:Npn \@@_radians_from_degrees:N #1
+ { \seq_set_map:NNn #1 #1 { \fp_eval:n { ##1 deg } } }
+% \end{macrocode}
+% \end{macro}
%
% \subsection{Drawing}
%
-% \begin{macro}{\rw_walk:}
-% We are ready to define |\rw_walk:|, which draws a TikZ picture of
-% a random walk with the parameters set up by the |keys|.
-% We reset all the coordinates to zero originally. Then we draw the relevant
-% TikZ picture by repeatedly calling |\rw_step_draw:|.
+% \begin{macro}{\@@_walk:}
+% We are ready to define \cs{@@_walk:}, which draws a \pkg{TikZ}
+% picture of a random walk with the parameters set up by the
+% \texttt{keys}. We reset all the coordinates to zero originally.
+% Then we draw the relevant \pkg{TikZ} picture by repeatedly calling
+% \cs{@@_step_draw:}.
% \begin{macrocode}
-\cs_new:Npn \rw_walk:
+\cs_new:Npn \@@_walk:
{
- \fp_zero:N \l_rw_old_x_fp
- \fp_zero:N \l_rw_old_y_fp
- \fp_zero:N \l_rw_new_x_fp
- \fp_zero:N \l_rw_new_y_fp
\begin{tikzpicture}
- \prg_replicate:nn { \l_rw_step_number_int } { \rw_step_draw: }
- \bool_if:NF \l_rw_revert_random_bool
+ \fp_zero:N \l_@@_old_x_fp
+ \fp_zero:N \l_@@_old_y_fp
+ \fp_zero:N \l_@@_new_x_fp
+ \fp_zero:N \l_@@_new_y_fp
+ \prg_replicate:nn { \l_@@_step_number_int } { \@@_step_draw: }
+ \bool_if:NF \l_@@_revert_random_bool
{ \int_gset_eq:NN \cr@nd \cr@nd }
\end{tikzpicture}
}
@@ -273,191 +346,85 @@
% \cs{cr@nd} is internal to the lcg package.
% \end{macro}
%
-% \begin{macro}{\rw_step_draw:}
-% |\rw_step_draw:| passes its second argument \emph{with one level of
-% braces removed} to its first argument, responsible for making a random
-% step. Then, |\rw_step_draw:| draws the random step.
+% \begin{macro}{\@@_step_draw:}
+% \cs{@@_step_draw:} calls \cs{@@_rand_length:} and
+% \cs{@@_rand_angle:} to determine the length and angle of the new
+% step. This is then converted to cartesian coordinates and added to
+% the previous end-point. Finally, we call \pkg{TikZ}'s \cs{draw} to
+% produce a line from the |_old| to the |_new| point.
% \begin{macrocode}
-\cs_new:Npn \rw_step_draw:
+\cs_new:Npn \@@_step_draw:
{
- \g_rw_Ldo_tl
- \g_rw_Ado_tl
- \rw_cartesian_from_polar:NNNN
- \l_rw_step_x_fp \l_rw_step_y_fp
- \l_rw_radius_fp \l_rw_angle_fp
- \fp_add:Nn \l_rw_new_x_fp { \l_rw_step_x_fp }
- \fp_add:Nn \l_rw_new_y_fp { \l_rw_step_y_fp }
- \draw ( \fp_to_dim:N \l_rw_old_x_fp, \fp_to_dim:N \l_rw_old_y_fp )
- -- ( \fp_to_dim:N \l_rw_new_x_fp, \fp_to_dim:N \l_rw_new_y_fp );
- \fp_set_eq:NN \l_rw_old_x_fp \l_rw_new_x_fp
- \fp_set_eq:NN \l_rw_old_y_fp \l_rw_new_y_fp
+ \@@_rand_length:
+ \@@_rand_angle:
+ \fp_set_eq:NN \l_@@_old_x_fp \l_@@_new_x_fp
+ \fp_set_eq:NN \l_@@_old_y_fp \l_@@_new_y_fp
+ \fp_add:Nn \l_@@_new_x_fp { \l_@@_length_fp * cos \l_@@_angle_fp }
+ \fp_add:Nn \l_@@_new_y_fp { \l_@@_length_fp * sin \l_@@_angle_fp }
+ \draw ( \fp_to_dim:N \l_@@_old_x_fp, \fp_to_dim:N \l_@@_old_y_fp )
+ -- ( \fp_to_dim:N \l_@@_new_x_fp, \fp_to_dim:N \l_@@_new_y_fp );
}
% \end{macrocode}
% \end{macro}
%
-% The next couple of macros store a random floating point in
-% |\l_rw_length_fp| or |\l_rw_angle_fp|.
+% \subsection{On random numbers and items}
%
-% \begin{macro}{\rw_L..:.}
-% First for the length of steps.
-% \begin{macrocode}
-\cs_new:Npn \rw_Lfixed:n #1
- { \fp_set:Nn \l_rw_radius_fp {#1} }
-\cs_new:Npn \rw_Llist:N #1
- { \rw_set_to_random_clist_element:NN \l_rw_radius_fp #1 }
-\cs_new:Npn \rw_Linterval:nn #1#2
- { \rw_set_to_random_fp:Nnn \l_rw_radius_fp {#1} {#2} }
-% \end{macrocode}
-% \end{macro}
+% For random numbers, the interface of \pkg{lcg} is not quite enough, so
+% we provide our own \LaTeX3-y functions. Also, this will allow us to
+% change quite easily our source of random numbers.
%
-% \begin{macro}{\rw_A..:.}
-% Then for angles.
+% \begin{macro}[aux]{\@@_int_set_rand:Nnn}
+% Sets the integer register |#1| equal to a random integer between
+% |#2| and |#3| inclusive.
% \begin{macrocode}
-\cs_new:Npn \rw_Ainterval:nn #1#2
+\cs_new:Npn \@@_int_set_rand:Nnn #1#2#3
{
- \bool_if:NTF \l_rw_A_relative_bool
- { \rw_add_to_random_fp:Nnn }
- { \rw_set_to_random_fp:Nnn }
- \l_rw_angle_fp {#1} {#2}
- }
-\cs_new:Npn \rw_Alist:N #1
- {
- \bool_if:NTF \l_rw_A_relative_bool
- { \rw_add_to_random_clist_element:NN }
- { \rw_set_to_random_clist_element:NN }
- \l_rw_angle_fp #1
+ \rand
+ \int_set:Nn #1 { #2 + \int_mod:nn {\c@lcg@rand} { #3 + 1 - (#2) } }
}
% \end{macrocode}
% \end{macro}
%
-% \begin{macro}{\rw_cartesian_from_polar:NNNN}
-% The four arguments of |\rw_cartesian_from_polar:NNNN| are
-% \( (x, y, r, \theta) \): it sets \( (x, y) \) equal to the cartesian
-% coordinates corresponding to a radius \(r\) and an angle \( \theta \).
-% We also give a version with global assignments.
+% \begin{macro}[aux]{\@@_fp_set_rand:Nnn, \@@_fp_add_rand:Nnn}
+% \begin{macro}[aux]{\@@_fp_set_rand_aux:NNnn}
+% We also need floating point random numbers, both assigned and added
+% to the variable |#1| (well, |#2| of the auxiliary).
% \begin{macrocode}
-\cs_new_protected:Npn \rw_cartesian_from_polar:NNNN #1#2#3#4
- {
- \fp_cos:Nn #1 {\fp_use:N #4}
- \fp_sin:Nn #2 {\fp_use:N #4}
- \fp_mul:Nn #1 {\fp_use:N #3}
- \fp_mul:Nn #2 {\fp_use:N #3}
- }
-\cs_new_protected:Npn \rw_gcartesian_from_polar:NNNN #1#2#3#4
+\cs_new_nopar:Npn \@@_fp_set_rand:Nnn
+ { \@@_fp_set_rand_aux:NNnn \fp_set:Nn }
+\cs_new_nopar:Npn \@@_fp_add_rand:Nnn
+ { \@@_fp_set_rand_aux:NNnn \fp_add:Nn }
+\cs_new:Npn \@@_fp_set_rand_aux:NNnn #1#2#3#4
{
- \fp_gcos:Nn #1 {\fp_use:N #4}
- \fp_gsin:Nn #2 {\fp_use:N #4}
- \fp_gmul:Nn #1 {\fp_use:N #3}
- \fp_gmul:Nn #2 {\fp_use:N #3}
+ \rand
+ #1 #2 { #3 + (#4 - (#3)) * \c@lcg@rand / \c_@@_lcg_last_int }
}
% \end{macrocode}
% \end{macro}
+% \end{macro}
%
-% We cannot yet do the conversion in the other direction: |l3fp.dtx| does
-% not yet provide inverse trigonometric functions. But in fact, we do not
-% need this conversion, so let's stop worrying.
-%
-% \subsection{On random numbers etc.}
-%
-% For random numbers, the interface of |lcg| is not quite enough, so we
-% provide our own \LaTeX3y functions. Also, this will allow us to change
-% quite easily our source of random numbers.
-%
+% \begin{macro}[aux]{\@@_fp_set_rand_seq_item:NN, \@@_fp_add_rand_seq_item:NN}
+% \begin{macro}[aux]{\@@_fp_set_rand_item_aux:NNNNN}
+% We can now pick an element at random from a sequence, and either
+% assign it or add it to the fp variable |#4|. The same auxiliary
+% could be used for picking random items from other types of lists.
% \begin{macrocode}
-\cs_new:Npn \rw_set_to_random_int:Nnn #1#2#3
+\cs_new_protected_nopar:Npn \@@_fp_set_rand_seq_item:NN
+ { \@@_fp_set_rand_item_aux:NNNNN \fp_set:Nn \seq_item:Nn \seq_length:N }
+\cs_new_protected_nopar:Npn \@@_fp_add_rand_seq_item:NN
+ { \@@_fp_set_rand_item_aux:NNNNN \fp_add:Nn \seq_item:Nn \seq_length:N }
+\cs_new_protected:Npn \@@_fp_set_rand_item_aux:NNNNN #1#2#3#4#5
{
\rand
- \int_set:Nn #1 { \int_mod:nn {\c@lcg@rand} { #3 - (#2) } }
- }
-% \end{macrocode}
-% We also need floating point random numbers.
-% \begin{macrocode}
-\cs_new:Npn \rw_set_to_random_fp:Nnn #1#2#3
- {
- \fp_set:Nn \l_rw_tmpa_fp {#3}
- \fp_sub:Nn \l_rw_tmpa_fp {#2}
- \rand
- \fp_set:Nn \l_rw_tmpb_fp { \int_use:N \c@lcg@rand }
- \fp_div:Nn \l_rw_tmpb_fp { \int_use:N \c_rw_lcg_range_int }
- \fp_mul:Nn \l_rw_tmpa_fp { \l_rw_tmpb_fp }
- \fp_add:Nn \l_rw_tmpa_fp {#2}
- \fp_set:Nn #1 { \l_rw_tmpa_fp }
- }
-\cs_new:Npn \rw_add_to_random_fp:Nnn #1#2#3
- {
- \fp_set:Nn \l_rw_tmpa_fp {#3}
- \fp_sub:Nn \l_rw_tmpa_fp {#2}
- \rand
- \fp_set:Nn \l_rw_tmpb_fp { \int_use:N \c@lcg@rand }
- \fp_div:Nn \l_rw_tmpb_fp { \int_use:N \c_rw_lcg_range_int }
- \fp_mul:Nn \l_rw_tmpa_fp { \l_rw_tmpb_fp }
- \fp_add:Nn \l_rw_tmpa_fp {#2}
- \fp_add:Nn #1 { \l_rw_tmpa_fp } %here: mod?
- }
-% \end{macrocode}
-%
-% We can now pick an element at random from a comma-separated list
-% \begin{macrocode}
-\cs_new:Npn \rw_set_to_random_clist_element:NN #1#2
- {
- \rw_set_to_random_int:Nnn \l_rw_tmpb_int {0} { \clist_length:N #2 }
- \fp_set:Nn #1 { \clist_item:Nn #2 { \l_rw_tmpb_int } }
- }
-\cs_new:Npn \rw_add_to_random_clist_element:NN #1#2
- {
- \rw_set_to_random_int:Nnn \l_rw_tmpb_int {0} { \clist_length:N #2 }
- \fp_add:Nn #1 { \clist_item:Nn #2 { \l_rw_tmpb_int } }
- }
-% \end{macrocode}
-%
-% \subsection{Other comma list operations}
-% More stuff on |clist|s.
-% \begin{macrocode}
-\cs_new:Npn \rw_radians_from_degrees:N #1
- {
- \clist_clear:N \l_rw_tmpa_clist
- \clist_map_inline:Nn #1
- {
- \fp_set:Nn \l_rw_tmpa_fp {##1}
- \fp_mul:Nn \l_rw_tmpa_fp { \c_rw_one_degree_fp }
- \clist_push:NV \l_rw_tmpa_clist \l_rw_tmpa_fp
- }
- \clist_set_eq:NN #1 \l_rw_tmpa_clist
- }
-\cs_new:Npn \rw_clist_fp_from_dim:N #1
- {
- \clist_clear:N \l_rw_tmpa_clist
- \clist_map_inline:Nn #1
- {
- \fp_set_from_dim:Nn \l_rw_tmpa_fp {##1}
- \clist_push:NV \l_rw_tmpa_clist \l_rw_tmpa_fp
- }
- \clist_set_eq:NN #1 \l_rw_tmpa_clist
+ #1 #4 { #2 #5 { 1 + \int_mod:nn { \c@lcg@rand } { #3 #5 } } }
}
% \end{macrocode}
+% \end{macro}
+% \end{macro}
%
-% \subsection{Variables}
-%
-% We need a bunch of floating point numbers: each step line goes from the
-% |_old| point to the |_new| point. The coordinates |_add| are those of the
-% vector from one to the next, so that |_new = _old + _add|.
% \begin{macrocode}
-\fp_new:N \l_rw_old_x_fp
-\fp_new:N \l_rw_old_y_fp
-\fp_new:N \l_rw_step_x_fp
-\fp_new:N \l_rw_step_y_fp
-\fp_new:N \l_rw_new_x_fp
-\fp_new:N \l_rw_new_y_fp
-\fp_new:N \l_rw_angle_fp
-\int_new:N \l_rw_step_number_int
-\clist_new:N \l_rw_angles_clist
-\clist_new:N \l_rw_lengths_clist
-\fp_new:N \l_rw_tmpa_fp
-\fp_new:N \l_rw_tmpb_fp
-\clist_new:N \l_rw_tmpa_clist
-\int_new:N \l_rw_tmpb_int
-% \end{macrocode}
%</package>
+% \end{macrocode}
%
% \end{implementation}
%
diff --git a/Master/texmf-dist/source/latex/randomwalk/randomwalk.ins b/Master/texmf-dist/source/latex/randomwalk/randomwalk.ins
index 151851b0974..4e21b32a93c 100644
--- a/Master/texmf-dist/source/latex/randomwalk/randomwalk.ins
+++ b/Master/texmf-dist/source/latex/randomwalk/randomwalk.ins
@@ -1,4 +1,4 @@
-\input docstrip.tex
+\input l3docstrip.tex
\askforoverwritefalse
\preamble
@@ -6,8 +6,8 @@
Do not distribute a modified version of this file.
Communicate any suggestions for changing this package
-to Bruno Le Floch (first@su.rname.fr, replaced by the
-relevant parts of my name).
+to Bruno Le Floch (see the latex-randomwalk repository
+on GitHub).
\endpreamble
% stop docstrip adding \endinput
diff --git a/Master/texmf-dist/tex/latex/randomwalk/randomwalk.sty b/Master/texmf-dist/tex/latex/randomwalk/randomwalk.sty
index be8fe93766d..9ea8446040a 100644
--- a/Master/texmf-dist/tex/latex/randomwalk/randomwalk.sty
+++ b/Master/texmf-dist/tex/latex/randomwalk/randomwalk.sty
@@ -9,10 +9,10 @@
%% Do not distribute a modified version of this file.
%%
%% Communicate any suggestions for changing this package
-%% to Bruno Le Floch (first@su.rname.fr, replaced by the
-%% relevant parts of my name).
+%% to Bruno Le Floch (see the latex-randomwalk repository
+%% on GitHub).
%%
-%% File: randomwalk.dtx Copyright (C) 2011 Bruno Le Floch
+%% File: randomwalk.dtx Copyright (C) 2011-2012 Bruno Le Floch
%%
%% It may be distributed and/or modified under the conditions of the
%% LaTeX Project Public License (LPPL), either version 1.3c of this
@@ -23,201 +23,143 @@
%%
%% -----------------------------------------------------------------------
\RequirePackage{l3names}
-\GetIdInfo$Id: randomwalk.dtx 0.2 2011-09-09 10:15:31Z blefloch $
- {Customizable Random Walks using TikZ}%
\ProvidesExplPackage
- {\ExplFileName}{\ExplFileDate}{\ExplFileVersion}{\ExplFileDescription}
+ {randomwalk.sty}{2012/07/10}{0.2}{Customizable random walks using TikZ}
\RequirePackage{expl3}
\RequirePackage{xparse}
\RequirePackage{tikz}
-\int_const:Nn \c_rw_lcg_first_int {0}
-\int_const:Nn \c_rw_lcg_last_int {536870911}
-\int_const:Nn \c_rw_lcg_range_int
- { \c_rw_lcg_last_int - \c_rw_lcg_first_int }
-\RequirePackage
- [
- first= \c_rw_lcg_first_int,
- last = \c_rw_lcg_last_int,
- counter = lcg@rand
- ]
- { lcg }
-\rand % This \rand avoids some very odd bug.
-\fp_const:Nn \c_rw_one_degree_fp {+1.74532925e-2}
+\int_const:Nn \c__randomwalk_lcg_last_int { \c_max_int - \c_one }
+\AtBeginDocument
+ {
+ \RequirePackage
+ [
+ first= \c_zero ,
+ last = \c__randomwalk_lcg_last_int ,
+ counter = lcg@rand
+ ]
+ { lcg }
+ \rand % This \rand avoids some very odd bug.
+ }
+\int_new:N \l__randomwalk_step_number_int
+\bool_new:N \l__randomwalk_relative_angles_bool
+\bool_new:N \l__randomwalk_revert_random_bool
+\cs_new_protected_nopar:Npn \__randomwalk_rand_angle: { }
+\cs_new_protected_nopar:Npn \__randomwalk_rand_length: { }
+\fp_new:N \l__randomwalk_angle_fp
+\fp_new:N \l__randomwalk_length_fp
+\fp_new:N \l__randomwalk_old_x_fp
+\fp_new:N \l__randomwalk_old_y_fp
+\fp_new:N \l__randomwalk_new_x_fp
+\fp_new:N \l__randomwalk_new_y_fp
+\seq_new:N \l__randomwalk_angles_seq
+\seq_new:N \l__randomwalk_lengths_seq
\DeclareDocumentCommand \RandomWalk { m }
{
- \rw_set_defaults:
+ \__randomwalk_set_defaults:
\keys_set:nn { randomwalk } { #1 }
- \rw_walk:
+ \__randomwalk_walk:
}
-\tl_new:N \g_rw_Ado_tl
-\tl_new:N \g_rw_Ldo_tl
-\bool_new:N \l_rw_A_relative_bool
-\bool_new:N \l_rw_revert_random_bool
-\cs_new:Npn \rw_set_defaults:
+\cs_new:Npn \__randomwalk_set_defaults:
{
- \fp_set:Nn \l_rw_step_length_fp {10}
- \int_set:Nn \l_rw_step_number_int {10}
- \tl_gset:Nn \g_rw_Ado_tl { \rw_Ainterval:nn {-\c_pi_fp} {\c_pi_fp} }
- \tl_gset:Nn \g_rw_Ldo_tl { \rw_Lfixed:n \l_rw_step_length_fp } %^^A bug?
- \bool_set_false:N \l_rw_revert_random_bool
- \bool_set_false:N \l_rw_A_relative_bool
+ \int_set:Nn \l__randomwalk_step_number_int {10}
+ \cs_gset_protected_nopar:Npn \__randomwalk_rand_angle:
+ { \__randomwalk_fp_set_rand:Nnn \l__randomwalk_angle_fp { - pi } { pi } }
+ \cs_gset_protected_nopar:Npn \__randomwalk_rand_length:
+ { \fp_set:Nn \l__randomwalk_length_fp {10} }
+ \bool_set_false:N \l__randomwalk_revert_random_bool
+ \bool_set_false:N \l__randomwalk_relative_angles_bool
}
\keys_define:nn { randomwalk }
{
- number .value_required:,
- length .value_required:,
- angles .value_required:,
- number .code:n = {\int_set:Nn \l_rw_step_number_int {#1}},
+ number .value_required: ,
+ length .value_required: ,
+ angles .value_required: ,
+ number .int_set:N = \l__randomwalk_step_number_int ,
length .code:n =
{
- \clist_set:Nn \l_rw_lengths_clist {#1}
- \rw_clist_fp_from_dim:N \l_rw_lengths_clist
- \int_compare:nNnTF { \clist_length:N \l_rw_lengths_clist } = {1}
- { \tl_gset:Nn \g_rw_Ldo_tl { \rw_Lfixed:n \l_rw_lengths_clist } }
- { \tl_gset:Nn \g_rw_Ldo_tl { \rw_Llist:N \l_rw_lengths_clist } }
- },
+ \seq_set_split:Nnn \l__randomwalk_lengths_seq { , } {#1}
+ \seq_set_map:NNn \l__randomwalk_lengths_seq
+ \l__randomwalk_lengths_seq { \dim_to_fp:n {##1} }
+ \int_compare:nNnTF { \seq_length:N \l__randomwalk_lengths_seq } = {1}
+ {
+ \cs_gset_protected_nopar:Npn \__randomwalk_rand_length:
+ { \fp_set:Nn \l__randomwalk_length_fp {#1} }
+ }
+ {
+ \cs_gset_protected_nopar:Npn \__randomwalk_rand_length:
+ {
+ \__randomwalk_fp_set_rand_seq_item:NN
+ \l__randomwalk_length_fp \l__randomwalk_lengths_seq
+ }
+ }
+ } ,
angles .code:n =
{
- \clist_set:Nn \l_rw_angles_clist {#1}
- \tl_gset:Nn \g_rw_Ado_tl { \rw_Alist:N \l_rw_angles_clist }
- },
- degree .code:n = { \rw_radians_from_degrees:N \l_rw_angles_clist },
- degrees .code:n = { \rw_radians_from_degrees:N \l_rw_angles_clist },
- angles-relative .code:n = { \bool_set_true:N \l_rw_A_relative_bool },
- revert-random .bool_set:N = \l_rw_revert_random_bool,
- }
-\cs_new:Npn \rw_walk:
+ \seq_set_split:Nnn \l__randomwalk_angles_seq { , } {#1}
+ \cs_gset_protected_nopar:Npn \__randomwalk_rand_angle:
+ {
+ \bool_if:NTF \l__randomwalk_relative_angles_bool
+ { \__randomwalk_fp_add_rand_seq_item:NN }
+ { \__randomwalk_fp_set_rand_seq_item:NN }
+ \l__randomwalk_angle_fp \l__randomwalk_angles_seq
+ }
+ } ,
+ degree .code:n =
+ { \__randomwalk_radians_from_degrees:N \l__randomwalk_angles_seq } ,
+ degrees .code:n =
+ { \__randomwalk_radians_from_degrees:N \l__randomwalk_angles_seq } ,
+ angles-relative .code:n =
+ { \bool_set_true:N \l__randomwalk_relative_angles_bool } ,
+ revert-random .bool_set:N = \l__randomwalk_revert_random_bool ,
+ }
+\cs_new:Npn \__randomwalk_radians_from_degrees:N #1
+ { \seq_set_map:NNn #1 #1 { \fp_eval:n { ##1 deg } } }
+\cs_new:Npn \__randomwalk_walk:
{
- \fp_zero:N \l_rw_old_x_fp
- \fp_zero:N \l_rw_old_y_fp
- \fp_zero:N \l_rw_new_x_fp
- \fp_zero:N \l_rw_new_y_fp
\begin{tikzpicture}
- \prg_replicate:nn { \l_rw_step_number_int } { \rw_step_draw: }
- \bool_if:NF \l_rw_revert_random_bool
+ \fp_zero:N \l__randomwalk_old_x_fp
+ \fp_zero:N \l__randomwalk_old_y_fp
+ \fp_zero:N \l__randomwalk_new_x_fp
+ \fp_zero:N \l__randomwalk_new_y_fp
+ \prg_replicate:nn { \l__randomwalk_step_number_int } { \__randomwalk_step_draw: }
+ \bool_if:NF \l__randomwalk_revert_random_bool
{ \int_gset_eq:NN \cr@nd \cr@nd }
\end{tikzpicture}
}
-\cs_new:Npn \rw_step_draw:
- {
- \g_rw_Ldo_tl
- \g_rw_Ado_tl
- \rw_cartesian_from_polar:NNNN
- \l_rw_step_x_fp \l_rw_step_y_fp
- \l_rw_radius_fp \l_rw_angle_fp
- \fp_add:Nn \l_rw_new_x_fp { \l_rw_step_x_fp }
- \fp_add:Nn \l_rw_new_y_fp { \l_rw_step_y_fp }
- \draw ( \fp_to_dim:N \l_rw_old_x_fp, \fp_to_dim:N \l_rw_old_y_fp )
- -- ( \fp_to_dim:N \l_rw_new_x_fp, \fp_to_dim:N \l_rw_new_y_fp );
- \fp_set_eq:NN \l_rw_old_x_fp \l_rw_new_x_fp
- \fp_set_eq:NN \l_rw_old_y_fp \l_rw_new_y_fp
- }
-\cs_new:Npn \rw_Lfixed:n #1
- { \fp_set:Nn \l_rw_radius_fp {#1} }
-\cs_new:Npn \rw_Llist:N #1
- { \rw_set_to_random_clist_element:NN \l_rw_radius_fp #1 }
-\cs_new:Npn \rw_Linterval:nn #1#2
- { \rw_set_to_random_fp:Nnn \l_rw_radius_fp {#1} {#2} }
-\cs_new:Npn \rw_Ainterval:nn #1#2
- {
- \bool_if:NTF \l_rw_A_relative_bool
- { \rw_add_to_random_fp:Nnn }
- { \rw_set_to_random_fp:Nnn }
- \l_rw_angle_fp {#1} {#2}
- }
-\cs_new:Npn \rw_Alist:N #1
+\cs_new:Npn \__randomwalk_step_draw:
{
- \bool_if:NTF \l_rw_A_relative_bool
- { \rw_add_to_random_clist_element:NN }
- { \rw_set_to_random_clist_element:NN }
- \l_rw_angle_fp #1
+ \__randomwalk_rand_length:
+ \__randomwalk_rand_angle:
+ \fp_set_eq:NN \l__randomwalk_old_x_fp \l__randomwalk_new_x_fp
+ \fp_set_eq:NN \l__randomwalk_old_y_fp \l__randomwalk_new_y_fp
+ \fp_add:Nn \l__randomwalk_new_x_fp { \l__randomwalk_length_fp * cos \l__randomwalk_angle_fp }
+ \fp_add:Nn \l__randomwalk_new_y_fp { \l__randomwalk_length_fp * sin \l__randomwalk_angle_fp }
+ \draw ( \fp_to_dim:N \l__randomwalk_old_x_fp, \fp_to_dim:N \l__randomwalk_old_y_fp )
+ -- ( \fp_to_dim:N \l__randomwalk_new_x_fp, \fp_to_dim:N \l__randomwalk_new_y_fp );
}
-\cs_new_protected:Npn \rw_cartesian_from_polar:NNNN #1#2#3#4
- {
- \fp_cos:Nn #1 {\fp_use:N #4}
- \fp_sin:Nn #2 {\fp_use:N #4}
- \fp_mul:Nn #1 {\fp_use:N #3}
- \fp_mul:Nn #2 {\fp_use:N #3}
- }
-\cs_new_protected:Npn \rw_gcartesian_from_polar:NNNN #1#2#3#4
- {
- \fp_gcos:Nn #1 {\fp_use:N #4}
- \fp_gsin:Nn #2 {\fp_use:N #4}
- \fp_gmul:Nn #1 {\fp_use:N #3}
- \fp_gmul:Nn #2 {\fp_use:N #3}
- }
-\cs_new:Npn \rw_set_to_random_int:Nnn #1#2#3
+\cs_new:Npn \__randomwalk_int_set_rand:Nnn #1#2#3
{
\rand
- \int_set:Nn #1 { \int_mod:nn {\c@lcg@rand} { #3 - (#2) } }
+ \int_set:Nn #1 { #2 + \int_mod:nn {\c@lcg@rand} { #3 + 1 - (#2) } }
}
-\cs_new:Npn \rw_set_to_random_fp:Nnn #1#2#3
+\cs_new_nopar:Npn \__randomwalk_fp_set_rand:Nnn
+ { \__randomwalk_fp_set_rand_aux:NNnn \fp_set:Nn }
+\cs_new_nopar:Npn \__randomwalk_fp_add_rand:Nnn
+ { \__randomwalk_fp_set_rand_aux:NNnn \fp_add:Nn }
+\cs_new:Npn \__randomwalk_fp_set_rand_aux:NNnn #1#2#3#4
{
- \fp_set:Nn \l_rw_tmpa_fp {#3}
- \fp_sub:Nn \l_rw_tmpa_fp {#2}
\rand
- \fp_set:Nn \l_rw_tmpb_fp { \int_use:N \c@lcg@rand }
- \fp_div:Nn \l_rw_tmpb_fp { \int_use:N \c_rw_lcg_range_int }
- \fp_mul:Nn \l_rw_tmpa_fp { \l_rw_tmpb_fp }
- \fp_add:Nn \l_rw_tmpa_fp {#2}
- \fp_set:Nn #1 { \l_rw_tmpa_fp }
+ #1 #2 { #3 + (#4 - (#3)) * \c@lcg@rand / \c__randomwalk_lcg_last_int }
}
-\cs_new:Npn \rw_add_to_random_fp:Nnn #1#2#3
+\cs_new_protected_nopar:Npn \__randomwalk_fp_set_rand_seq_item:NN
+ { \__randomwalk_fp_set_rand_item_aux:NNNNN \fp_set:Nn \seq_item:Nn \seq_length:N }
+\cs_new_protected_nopar:Npn \__randomwalk_fp_add_rand_seq_item:NN
+ { \__randomwalk_fp_set_rand_item_aux:NNNNN \fp_add:Nn \seq_item:Nn \seq_length:N }
+\cs_new_protected:Npn \__randomwalk_fp_set_rand_item_aux:NNNNN #1#2#3#4#5
{
- \fp_set:Nn \l_rw_tmpa_fp {#3}
- \fp_sub:Nn \l_rw_tmpa_fp {#2}
\rand
- \fp_set:Nn \l_rw_tmpb_fp { \int_use:N \c@lcg@rand }
- \fp_div:Nn \l_rw_tmpb_fp { \int_use:N \c_rw_lcg_range_int }
- \fp_mul:Nn \l_rw_tmpa_fp { \l_rw_tmpb_fp }
- \fp_add:Nn \l_rw_tmpa_fp {#2}
- \fp_add:Nn #1 { \l_rw_tmpa_fp } %here: mod?
- }
-\cs_new:Npn \rw_set_to_random_clist_element:NN #1#2
- {
- \rw_set_to_random_int:Nnn \l_rw_tmpb_int {0} { \clist_length:N #2 }
- \fp_set:Nn #1 { \clist_item:Nn #2 { \l_rw_tmpb_int } }
- }
-\cs_new:Npn \rw_add_to_random_clist_element:NN #1#2
- {
- \rw_set_to_random_int:Nnn \l_rw_tmpb_int {0} { \clist_length:N #2 }
- \fp_add:Nn #1 { \clist_item:Nn #2 { \l_rw_tmpb_int } }
- }
-\cs_new:Npn \rw_radians_from_degrees:N #1
- {
- \clist_clear:N \l_rw_tmpa_clist
- \clist_map_inline:Nn #1
- {
- \fp_set:Nn \l_rw_tmpa_fp {##1}
- \fp_mul:Nn \l_rw_tmpa_fp { \c_rw_one_degree_fp }
- \clist_push:NV \l_rw_tmpa_clist \l_rw_tmpa_fp
- }
- \clist_set_eq:NN #1 \l_rw_tmpa_clist
- }
-\cs_new:Npn \rw_clist_fp_from_dim:N #1
- {
- \clist_clear:N \l_rw_tmpa_clist
- \clist_map_inline:Nn #1
- {
- \fp_set_from_dim:Nn \l_rw_tmpa_fp {##1}
- \clist_push:NV \l_rw_tmpa_clist \l_rw_tmpa_fp
- }
- \clist_set_eq:NN #1 \l_rw_tmpa_clist
+ #1 #4 { #2 #5 { 1 + \int_mod:nn { \c@lcg@rand } { #3 #5 } } }
}
-\fp_new:N \l_rw_old_x_fp
-\fp_new:N \l_rw_old_y_fp
-\fp_new:N \l_rw_step_x_fp
-\fp_new:N \l_rw_step_y_fp
-\fp_new:N \l_rw_new_x_fp
-\fp_new:N \l_rw_new_y_fp
-\fp_new:N \l_rw_angle_fp
-\int_new:N \l_rw_step_number_int
-\clist_new:N \l_rw_angles_clist
-\clist_new:N \l_rw_lengths_clist
-\fp_new:N \l_rw_tmpa_fp
-\fp_new:N \l_rw_tmpb_fp
-\clist_new:N \l_rw_tmpa_clist
-\int_new:N \l_rw_tmpb_int
%%
%%
%% End of file `randomwalk.sty'.