[latex3-commits] [git/LaTeX3-latex3-latex3] master: l3draw support for vetor-based points (45c1050)
Joseph Wright
joseph.wright at morningstar2.co.uk
Wed Feb 7 10:45:12 CET 2018
Repository : https://github.com/latex3/latex3
On branch : master
Link : https://github.com/latex3/latex3/commit/45c10502257adaca47fb6a7598cb2136c6901fe1
>---------------------------------------------------------------
commit 45c10502257adaca47fb6a7598cb2136c6901fe1
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date: Wed Feb 7 09:45:12 2018 +0000
l3draw support for vetor-based points
Here an expandable FPU makes things a lot clearer!
>---------------------------------------------------------------
45c10502257adaca47fb6a7598cb2136c6901fe1
l3trial/l3draw/l3draw-points.dtx | 121 +++++++++++++++++++++++++++++++-
l3trial/l3draw/l3draw.dtx | 11 +++
l3trial/l3draw/testfiles/m3draw000.tlg | 6 ++
3 files changed, 135 insertions(+), 3 deletions(-)
diff --git a/l3trial/l3draw/l3draw-points.dtx b/l3trial/l3draw/l3draw-points.dtx
index e061b10..e86a53c 100644
--- a/l3trial/l3draw/l3draw-points.dtx
+++ b/l3trial/l3draw/l3draw-points.dtx
@@ -60,16 +60,23 @@
%<@@=draw>
% \end{macrocode}
%
-% \begin{macro}{\@@_pass_point:nN}
+% \subsection{Support functions}
+%
+% \begin{macro}{\@@_process_point: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 \@@_pass_point:nN #1#2
+\cs_new_protected:Npn \@@_process_point:nn #1#2
{
- \use:x { \exp_not:N #2 #1 }
+ \use:x { \exp_not:n {#2} #1 }
}
% \end{macrocode}
% \end{macro}
%
+% \subsection{Co-ordinates}
+%
+% The most basic way of giving points is as simple $(x,y)$ points.
+%
% \begin{macro}[EXP]{\draw_point:nn}
% Simply turn the given values into dimensions.
% \begin{macrocode}
@@ -81,6 +88,114 @@
% \end{macrocode}
% \end{macro}
%
+% \subsection{Vector support}
+%
+% As well as co-ordinates relative to the drawing
+%
+% \begin{variable}
+% {
+% \l_@@_xvec_x_dim,
+% \l_@@_xvec_y_dim,
+% \l_@@_yvec_x_dim,
+% \l_@@_yvec_y_dim,
+% \l_@@_zvec_x_dim,
+% \l_@@_zvec_y_dim
+% }
+% Base vectors to map to the underlying two-dimensional drawing space.
+% \begin{macrocode}
+\dim_new:N \l_@@_xvec_x_dim
+\dim_new:N \l_@@_xvec_y_dim
+\dim_new:N \l_@@_yvec_x_dim
+\dim_new:N \l_@@_yvec_y_dim
+\dim_new:N \l_@@_zvec_x_dim
+\dim_new:N \l_@@_zvec_y_dim
+% \end{macrocode}
+% \end{variable}
+%
+% \begin{macro}{\draw_set_xvec:n, \draw_set_yvec:n, \draw_set_zvec:n}
+% \begin{macro}{\@@_set_vec:nn}
+% \begin{macro}{\@@_set_vec:nnn}
+% Calculate the underlying position and store it.
+% \begin{macrocode}
+\cs_new_protected:Npn \draw_set_xvec:n #1
+ { \@@_set_vec:nn { x } {#1} }
+\cs_new_protected:Npn \draw_set_yvec:n #1
+ { \@@_set_vec:nn { y } {#1} }
+\cs_new_protected:Npn \draw_set_zvec:n #1
+ { \@@_set_vec:nn { y } {#1} }
+\cs_new_protected:Npn \@@_set_vec:nn #1#2
+ {
+ \@@_process_point:nn {#2} { \@@_set_vec:nnn {#1} }
+ }
+\cs_new_protected:Npn \@@_set_vec:nnn #1#2#3
+ {
+ \dim_set:cn { l_@@_ #1 vec_x_dim } {#2}
+ \dim_set:cn { l_@@_ #1 vec_y_dim } {#3}
+ }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+%
+% 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 } }
+% \end{macrocode}
+%
+% \begin{macro}[EXP]{\draw_point_vec:nn}
+% \begin{macro}[EXP]{\@@_point_vec:nn, \@@_point_vec:ff}
+% \begin{macro}[EXP]{\draw_point_vec:nnn}
+% \begin{macro}[EXP]{\@@_point_vec:nnn, \@@_point_vec:fff}
+% Force a single evaluation of each factor, then use these to work out the
+% underlying point.
+% \begin{macrocode}
+\cs_new:Npn \draw_point_vec:nn #1#2
+ { \@@_point_vec:ff { \fp_eval:n {#1} } { \fp_eval:n {#2} } }
+\cs_new:Npn \@@_point_vec:nn #1#2
+ {
+ {
+ \fp_to_dim:n
+ { #1 * \l_@@_xvec_x_dim + #2 * \l_@@_yvec_x_dim }
+ }
+ {
+ \fp_to_dim:n
+ { #1 * \l_@@_xvec_y_dim + #2 * \l_@@_yvec_y_dim }
+ }
+ }
+\cs_generate_variant:Nn \@@_point_vec:nn { ff }
+\cs_new:Npn \draw_point_vec:nnn #1#2#3
+ {
+ \@@_point_vec:fff
+ { \fp_eval:n {#1} } { \fp_eval:n {#2} } { \fp_eval:n {#3} }
+ }
+\cs_new:Npn \@@_point_vec:nnn #1#2#3
+ {
+ {
+ \fp_to_dim:n
+ {
+ #1 * \l_@@_xvec_x_dim
+ + #2 * \l_@@_yvec_x_dim
+ + #3 * \l_@@_zvec_x_dim
+ }
+ }
+ {
+ \fp_to_dim:n
+ {
+ #1 * \l_@@_xvec_y_dim
+ + #2 * \l_@@_yvec_y_dim
+ + #3 * \l_@@_zvec_y_dim
+ }
+ }
+ }
+\cs_generate_variant:Nn \@@_point_vec:nnn { fff }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+%
% \begin{macrocode}
%</initex|package>
% \end{macrocode}
diff --git a/l3trial/l3draw/l3draw.dtx b/l3trial/l3draw/l3draw.dtx
index 1e2fd64..43546a3 100644
--- a/l3trial/l3draw/l3draw.dtx
+++ b/l3trial/l3draw/l3draw.dtx
@@ -66,6 +66,17 @@
% \cs{draw_point:nn} \marg{x} \marg{y}
% \end{syntax}
%
+% \begin{function}[EXP]{\draw_set_xvec:n, \draw_set_yvec:n, \draw_set_zvec:n}
+% \begin{syntax}
+% \cs{draw_set_xvec:n} \marg{point expr}
+% \end{syntax}
+%
+% \begin{function}[EXP]{\draw_point_vec:nn, \draw_point_vec:nnn}
+% \begin{syntax}
+% \cs{draw_point_vec:nn} \marg{xscale} \marg{yscale}
+% \cs{draw_point_vec:nnn} \marg{xscale} \marg{yscale} \mag{zscale}
+% \end{syntax}
+%
% \end{documentation}
%
% \begin{implementation}
diff --git a/l3trial/l3draw/testfiles/m3draw000.tlg b/l3trial/l3draw/testfiles/m3draw000.tlg
index a17ff47..967e789 100644
--- a/l3trial/l3draw/testfiles/m3draw000.tlg
+++ b/l3trial/l3draw/testfiles/m3draw000.tlg
@@ -8,6 +8,12 @@ Author: Joseph Wright
\g__draw_path_xmin_dim=\dimen...
\g__draw_path_ymax_dim=\dimen...
\g__draw_path_ymin_dim=\dimen...
+\l__draw_xvec_x_dim=\dimen...
+\l__draw_xvec_y_dim=\dimen...
+\l__draw_yvec_x_dim=\dimen...
+\l__draw_yvec_y_dim=\dimen...
+\l__draw_zvec_x_dim=\dimen...
+\l__draw_zvec_y_dim=\dimen...
\g__draw_xmax_dim=\dimen...
\g__draw_xmin_dim=\dimen...
\g__draw_ymax_dim=\dimen...
More information about the latex3-commits
mailing list