[latex3-commits] [git/LaTeX3-latex3-latex3] master: l3draw: Basic point arithmetic (535ccc1)
Joseph Wright
joseph.wright at morningstar2.co.uk
Wed Feb 7 13:27:09 CET 2018
Repository : https://github.com/latex3/latex3
On branch : master
Link : https://github.com/latex3/latex3/commit/535ccc13e674637a5fa0c2c3592e9eb2651b9da3
>---------------------------------------------------------------
commit 535ccc13e674637a5fa0c2c3592e9eb2651b9da3
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date: Wed Feb 7 12:27:09 2018 +0000
l3draw: Basic point arithmetic
Some renaming as a result: make the flow clearer.
>---------------------------------------------------------------
535ccc13e674637a5fa0c2c3592e9eb2651b9da3
l3trial/l3draw/l3draw-points.dtx | 94 ++++++++++++++++++++++++++++++++++----
l3trial/l3draw/l3draw.dtx | 4 +-
2 files changed, 87 insertions(+), 11 deletions(-)
diff --git a/l3trial/l3draw/l3draw-points.dtx b/l3trial/l3draw/l3draw-points.dtx
index c6a1822..a1b9c8d 100644
--- a/l3trial/l3draw/l3draw-points.dtx
+++ b/l3trial/l3draw/l3draw-points.dtx
@@ -60,25 +60,49 @@
%
% \subsection{Support functions}
%
-% \begin{macro}{\@@_process_point:nn}
+% \begin{macro}{\@@_point_process:nn}
% Execute whatever code is passed to extract the $x$ and $y$ co-ordinates.
% The second argument here should itself absorb two arguments.
% \begin{macrocode}
-\cs_new_protected:Npn \@@_process_point:nn #1#2
+\cs_new_protected:Npn \@@_point_process:nn #1#2
{
\use:x { \exp_not:n {#2} #1 }
}
% \end{macrocode}
% \end{macro}
%
+% \begin{macro}[EXP]{\@@_point_expand:nnN}
+% \begin{macro}[EXP]{\@@_point_expand_auxi:nnN, \@@_point_expand_auxi:ffN}
+% \begin{macro}[EXP]{\@@_point_expand_auxii:nnnnN}
+% \begin{macro}[EXP]
+% {\@@_point_expand_auxiii:nnnnN, \@@_point_expand_auxiii:ffnnN}
+% The aim here is to expand the point expressions fully. As each one will
+% contain two co-ordinates, we have to \texttt{f}-type expand twice: once
+% to get the first co-ordinate, and again to get the second one fully
+% expanded. Once that is all done, the result is passed to the resulting
+% processor.
+% \begin{macrocode}
+\cs_new:Npn \@@_point_expand:nnN #1#2#3
+ { \@@_point_expand_auxi:ffN {#1} {#2} #3 }
+\cs_new:Npn \@@_point_expand_auxi:nnN #1#2#3
+ { \@@_point_expand_auxii:nnnnN #1 #2 #3 }
+\cs_generate_variant:Nn \@@_point_expand_auxi:nnN { ff }
+\cs_new:Npn \@@_point_expand_auxii:nnnnN #1#2#3#4#5
+ { \@@_point_expand_auxiii:ffnnN {#2} {#4} {#1} {#3} #5 }
+\cs_new:Npn \@@_point_expand_auxiii:nnnnN #1#2#3#4#5
+ { #5 {#3} {#1} {#4} {#2} }
+\cs_generate_variant:Nn \@@_point_expand_auxiii:nnnnN { ff }
+% \end{macrocode}
+% \end{macro}
+%
% \subsection{Co-ordinates}
%
-% The most basic way of giving points is as simple $(x,y)$ points.
+% The most basic way of giving points is as simple $(x,y)$ co-ordinates.
%
-% \begin{macro}[EXP]{\draw_point:nn}
+% \begin{macro}[EXP]{\draw_point_coord:nn}
% Simply turn the given values into dimensions.
% \begin{macrocode}
-\cs_new:Npn \draw_point:nn #1#2
+\cs_new:Npn \draw_point_coord:nn #1#2
{
{ \fp_to_dim:n {#1} }
{ \fp_to_dim:n {#2} }
@@ -86,6 +110,58 @@
% \end{macrocode}
% \end{macro}
%
+% \subsection{Point expression arithmetic}
+%
+% These functions all take point expressions as arguments.
+%
+% \begin{macro}[EXP]{\draw_point_add:nn, \draw_point_diff:nn}
+% \begin{macro}[EXP]{\@@_point_add:nnnn, \@@_point_diff:nnnn}
+% Simple maths once the expansion is done.
+% \begin{macrocode}
+\cs_new:Npn \draw_point_add:nn #1#2
+ {
+ \@@_point_expand:nnN {#1} {#2}
+ \@@_point_diff:nnnn
+ }
+\cs_new:Npn \@@_point_add:nnnn #1#2#3#4
+ {
+ { \fp_to_dim:n { #1 + #3 } }
+ { \fp_to_dim:n { #2 + #4 } }
+ }
+\cs_new:Npn \draw_point_diff:nn #1#2
+ {
+ \@@_point_expand:nnN {#1} {#2}
+ \@@_point_diff:nnnn
+ }
+\cs_new:Npn \@@_point_diff:nnnn #1#2#3#4
+ {
+ { \fp_to_dim:n { #3 - #1 } }
+ { \fp_to_dim:n { #4 - #2 } }
+ }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}[EXP]{\draw_point_scale:nn}
+% \begin{macro}[EXP]{\@@_point_scale:nnnn}
+% Much the same idea, but as argument |#1| here is a simple floating point
+% expression there is a bit of \enquote{cheating} to reuse the expansion
+% mechanism.
+% \begin{macrocode}
+\cs_new:Npn \draw_point_scale:nn #1#2
+ {
+ \@@_point_expand:nnN { { \fp_eval:n {#1} } { } } {#2}
+ \@@_point_scale:nnnn
+ }
+\cs_new:Npn \@@_point_scale:nnnn #1#2#3#4
+ {
+ { \fp_to_dim:n { #1 * #3 } }
+ { \fp_to_dim:n { #1 * #4 } }
+ }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+%
% \subsection{Vector support}
%
% As well as co-ordinates relative to the drawing
@@ -123,7 +199,7 @@
{ \@@_set_vec:nn { y } {#1} }
\cs_new_protected:Npn \@@_set_vec:nn #1#2
{
- \@@_process_point:nn {#2} { \@@_set_vec:nnn {#1} }
+ \@@_point_process:nn {#2} { \@@_set_vec:nnn {#1} }
}
\cs_new_protected:Npn \@@_set_vec:nnn #1#2#3
{
@@ -137,9 +213,9 @@
%
% Initialise the vectors.
% \begin{macrocode}
-\draw_set_xvec:n { \draw_point:nn { 1cm } { 0cm } }
-\draw_set_yvec:n { \draw_point:nn { 0cm } { 1cm } }
-\draw_set_zvec:n { \draw_point:nn { -0.385cm } { -0.385cm } }
+\draw_set_xvec:n { \draw_point_coord:nn { 1cm } { 0cm } }
+\draw_set_yvec:n { \draw_point_coord:nn { 0cm } { 1cm } }
+\draw_set_zvec:n { \draw_point_coord:nn { -0.385cm } { -0.385cm } }
% \end{macrocode}
%
% \begin{macro}[EXP]{\draw_point_vec:nn}
diff --git a/l3trial/l3draw/l3draw.dtx b/l3trial/l3draw/l3draw.dtx
index 43546a3..b880c8c 100644
--- a/l3trial/l3draw/l3draw.dtx
+++ b/l3trial/l3draw/l3draw.dtx
@@ -61,9 +61,9 @@
%
% \subsection{Points}
%
-% \begin{function}[EXP]{\draw_point:nn}
+% \begin{function}[EXP]{\draw_point_coord:nn}
% \begin{syntax}
-% \cs{draw_point:nn} \marg{x} \marg{y}
+% \cs{draw_coord:nn} \marg{x} \marg{y}
% \end{syntax}
%
% \begin{function}[EXP]{\draw_set_xvec:n, \draw_set_yvec:n, \draw_set_zvec:n}
More information about the latex3-commits
mailing list