diff options
Diffstat (limited to 'Master/texmf-dist/source/latex/l3experimental/l3draw/l3draw-transforms.dtx')
-rw-r--r-- | Master/texmf-dist/source/latex/l3experimental/l3draw/l3draw-transforms.dtx | 286 |
1 files changed, 286 insertions, 0 deletions
diff --git a/Master/texmf-dist/source/latex/l3experimental/l3draw/l3draw-transforms.dtx b/Master/texmf-dist/source/latex/l3experimental/l3draw/l3draw-transforms.dtx new file mode 100644 index 00000000000..4f325f01092 --- /dev/null +++ b/Master/texmf-dist/source/latex/l3experimental/l3draw/l3draw-transforms.dtx @@ -0,0 +1,286 @@ +% \iffalse meta-comment +% +%% File: l3draw-transforms.dtx Copyright(C) 2018 The LaTeX3 Project +% +% It may be distributed and/or modified under the conditions of the +% LaTeX Project Public License (LPPL), either version 1.3c of this +% license or (at your option) any later version. The latest version +% of this license is in the file +% +% http://www.latex-project.org/lppl.txt +% +% This file is part of the "l3experimental bundle" (The Work in LPPL) +% and all files in that bundle must be distributed together. +% +% ----------------------------------------------------------------------- +% +% The development version of the bundle can be found at +% +% https://github.com/latex3/latex3 +% +% for those people who are interested. +% +%<*driver> +\RequirePackage{expl3} +\documentclass[full]{l3doc} +\begin{document} + \DocInput{\jobname.dtx} +\end{document} +%</driver> +% \fi +% +% \title{^^A +% The \pkg{l3draw-transforms} package\\ Transformations^^A +% } +% +% \author{^^A +% The \LaTeX3 Project\thanks +% {^^A +% E-mail: +% \href{mailto:latex-team@latex-project.org} +% {latex-team@latex-project.org}^^A +% }^^A +% } +% +% \date{Released 2018/02/21} +% +% \maketitle +% +% \begin{implementation} +% +% \section{\pkg{l3draw-transforms} implementation} +% +% \begin{macrocode} +%<*initex|package> +% \end{macrocode} +% +% \begin{macrocode} +%<@@=draw> +% \end{macrocode} +% +% \begin{variable}{\l_@@_transformcm_active_bool} +% An internal flag to avoid redundant calculations. +% \begin{macrocode} +\bool_new:N \l_@@_transformcm_active_bool +% \end{macrocode} +% \end{variable} +% +% \begin{variable} +% { +% \l_@@_transformcm_aa_fp, \l_@@_transformcm_ab_fp, +% \l_@@_transformcm_ba_fp, \l_@@_transformcm_aa_fp, +% \l_@@_transformcm_xshift_dim, +% \l_@@_transformcm_yshift_dim +% } +% The active matrix itself. +% \begin{macrocode} +\fp_new:N \l_@@_transformcm_aa_fp +\fp_new:N \l_@@_transformcm_ab_fp +\fp_new:N \l_@@_transformcm_ba_fp +\fp_new:N \l_@@_transformcm_bb_fp +\dim_new:N \l_@@_transformcm_xshift_dim +\dim_new:N \l_@@_transformcm_yshift_dim +% \end{macrocode} +% \end{variable} +% +% \begin{macro}{\draw_transform_reset:} +% Fast resetting. +% \begin{macrocode} +\cs_new_protected:Npn \draw_transform_reset: + { + \fp_set:Nn \l_@@_transformcm_aa_fp { 1} + \fp_zero:N \l_@@_transformcm_ab_fp + \fp_zero:N \l_@@_transformcm_ba_fp + \fp_set:Nn \l_@@_transformcm_bb_fp { 1 } + \dim_zero:N \l_@@_transformcm_xshift_dim + \dim_zero:N \l_@@_transformcm_yshift_dim + } +\draw_transform_reset: +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\draw_transform:nnnnn} +% \begin{macro}{\@@_transform:nnnnnnn} +% Setting the transform matrix is straight-forward, with just a bit +% of expansion to sort out. With the mechanism active, the identity +% matrix is set. +% \begin{macrocode} +\cs_new_protected:Npn \draw_transform:nnnnn #1#2#3#4#5 + { + \@@_point_process:nn + { \@@_transform:nnnnnnn {#1} {#2} {#3} {#4} } + {#5} + } +\cs_new_protected:Npn \@@_transform:nnnnnnn #1#2#3#4#5#6 + { + \fp_set:Nn \l_@@_transformcm_aa_fp {#1} + \fp_set:Nn \l_@@_transformcm_ab_fp {#2} + \fp_set:Nn \l_@@_transformcm_ba_fp {#3} + \fp_set:Nn \l_@@_transformcm_bb_fp {#4} + \dim_set:Nn \l_@@_transformcm_xshift_dim {#5} + \dim_set:Nn \l_@@_transformcm_yshift_dim {#6} + \bool_lazy_all:nTF + { + { \fp_compare_p:nNn \l_@@_transformcm_aa_fp = \c_one_fp } + { \fp_compare_p:nNn \l_@@_transformcm_ab_fp = \c_zero_fp } + { \fp_compare_p:nNn \l_@@_transformcm_ba_fp = \c_zero_fp } + { \fp_compare_p:nNn \l_@@_transformcm_bb_fp = \c_one_fp } + } + { \bool_set_false:N \l_@@_transformcm_active_bool } + { \bool_set_true:N \l_@@_transformcm_active_bool } + } +% \end{macrocode} +% \end{macro} +% \end{macro} +% +% \begin{macro}{\draw_transform_concat:nnnnn} +% \begin{macro}{\@@_transform_concat:nnnnnn} +% \begin{macro}{\@@_transform_concat_aux:nnnnnn} +% Much the same story for adding to an existing matrix. The part that is more +% complex is the calculations required: everything gets passed back to +% \cs{@@_transform_set:nnnnnn}, with pre-expansion just in case there are +% \emph{e.g}~random values. The final step is \texttt{x}-type expanded as +% otherwise later values affect earlier ones. +% \begin{macrocode} +\cs_new_protected:Npn \draw_transform_concat:nnnnn #1#2#3#4#5 + { + \@@_point_process:nn + { \@@_transform_concat:nnnnnn {#1} {#2} {#3} {#4} } + {#5} + } +\cs_new_protected:Npn \@@_transform_concat:nnnnnn #1#2#3#4#5#6 + { + \use:x + { + \@@_transform_concat_aux:nnnnnn + { \fp_eval:n {#1} } + { \fp_eval:n {#2} } + { \fp_eval:n {#3} } + { \fp_eval:n {#4} } + {#5} + {#6} + } + } +\cs_new_protected:Npn \@@_transform_concat_aux:nnnnnn #1#2#3#4#5#6 + { + \use:x + { + \@@_transform:nnnnnnn + { #1 * \l_@@_transformcm_aa_fp + #2 * \l_@@_transformcm_ba_fp } + { #1 * \l_@@_transformcm_ab_fp + #2 * \l_@@_transformcm_bb_fp } + { #3 * \l_@@_transformcm_aa_fp + #4 * \l_@@_transformcm_ba_fp } + { #3 * \l_@@_transformcm_ab_fp + #4 * \l_@@_transformcm_bb_fp } + { + \fp_to_dim:n + { + \l_@@_transformcm_xshift_dim + + \l_@@_transformcm_aa_fp * #5 + + \l_@@_transformcm_ba_fp * #6 + } + } + { + \fp_to_dim:n + { + \l_@@_transformcm_yshift_dim + + \l_@@_transformcm_ab_fp * #5 + + \l_@@_transformcm_bb_fp * #6 + } + } + } + } +% \end{macrocode} +% \end{macro} +% \end{macro} +% \end{macro} +% +% \begin{macro}{\draw_transform_invert:} +% \begin{macro}{\@@_transform_invert:n, \@@_transform_invert:f} +% Standard mathematics: calculate the inverse matrix and use that, then +% undo the shifts. +% \begin{macrocode} +\cs_new_protected:Npn \draw_transform_invert: + { + \bool_if:NT \l_@@_transformcm_active_bool + { + \@@_transform_invert:f + { + \fp_eval:n + { + 1 / + ( + \l_@@_transformcm_aa_fp * \l_@@_transformcm_bb_fp + - \l_@@_transformcm_ab_fp * \l_@@_transformcm_ba_fp + ) + } + } + } + \dim_set:Nn \l_@@_transformcm_xshift_dim + { + \fp_to_dim:n + { + -\l_@@_transformcm_xshift_dim * \l_@@_transformcm_aa_fp + -\l_@@_transformcm_yshift_dim * \l_@@_transformcm_ba_fp + } + } + \dim_set:Nn \l_@@_transformcm_yshift_dim + { + \fp_to_dim:n + { + -\l_@@_transformcm_xshift_dim * \l_@@_transformcm_ab_fp + -\l_@@_transformcm_yshift_dim * \l_@@_transformcm_bb_fp + } + } + } +\cs_new_protected:Npn \@@_transform_invert:n #1 + { + \fp_set:Nn \l_@@_transformcm_aa_fp + { \l_@@_transformcm_bb_fp * #1 } + \fp_set:Nn \l_@@_transformcm_ab_fp + { -\l_@@_transformcm_ab_fp * #1 } + \fp_set:Nn \l_@@_transformcm_ba_fp + { -\l_@@_transformcm_ba_fp * #1 } + \fp_set:Nn \l_@@_transformcm_bb_fp + { \l_@@_transformcm_aa_fp * #1 } + } +\cs_generate_variant:Nn \@@_transform_invert:n { f } +% \end{macrocode} +% \end{macro} +% \end{macro} +% +% \begin{macro}{\draw_transform_triangle:nnn} +% Simple maths to move the canvas origin to |#1| and the two axes to +% |#2| and |#3|. +% \begin{macrocode} +\cs_new_protected:Npn \draw_transform_triangle:nnn #1#2#3 + { + \@@_point_process:nnn + { + \@@_point_process:nn + { \@@_tranform_triangle:nnnnnn } + {#1} + } + {#2} {#3} + } +\cs_new_protected:Npn \@@_tranform_triangle:nnnnnn #1#2#3#4#5#6 + { + \use:x + { + \@@_transform:nnnnnnn + { #3 - #1 } + { #4 - #2 } + { #5 - #1 } + { #6 - #2 } + {#1} + {#2} + } + } +% \end{macrocode} +% \end{macro} +% +% \begin{macrocode} +%</initex|package> +% \end{macrocode} +% +% \end{implementation} +% +% \PrintIndex |