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 | 283 |
1 files changed, 167 insertions, 116 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 index 4f325f01092..9b1478b48b7 100644 --- a/Master/texmf-dist/source/latex/l3experimental/l3draw/l3draw-transforms.dtx +++ b/Master/texmf-dist/source/latex/l3experimental/l3draw/l3draw-transforms.dtx @@ -42,7 +42,7 @@ % }^^A % } % -% \date{Released 2018/02/21} +% \date{Released 2018/03/05} % % \maketitle % @@ -58,149 +58,159 @@ %<@@=draw> % \end{macrocode} % -% \begin{variable}{\l_@@_transformcm_active_bool} +% This sub-module covers more-or-less the same ideas as +% \texttt{pgfcoretransformations.code.tex}. At present, equivalents of the +% following are currently absent: +% \begin{itemize} +% \item \cs{pgfgettransform}, \cs{pgfgettransformentries}: Awaiting use cases. +% \item \cs{pgftransformlineattime}, \cs{pgftransformarcaxesattime}, +% \cs{pgftransformcurveattime}: Need to look at the use cases for +% these to fully understand them. +% \item \cs{pgftransformarrow}: Likely to be done when other arrow functions +% are added. +% \item \cs{pgflowlevelsynccm}, \cs{pgflowlevel}: Likely to be added when +% use cases are encountered in other parts of the code. +% \end{itemize} +% +% \begin{variable}{\l_@@_matrix_active_bool} % An internal flag to avoid redundant calculations. % \begin{macrocode} -\bool_new:N \l_@@_transformcm_active_bool +\bool_new:N \l_@@_matrix_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 +% \l_@@_matrix_a_fp, +% \l_@@_matrix_b_fp, +% \l_@@_matrix_c_fp, +% \l_@@_matrix_a_fp, +% \l_@@_xshift_dim, +% \l_@@_yshift_dim % } -% The active matrix itself. +% The active matrix and shifts. % \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 +\fp_new:N \l_@@_matrix_a_fp +\fp_new:N \l_@@_matrix_b_fp +\fp_new:N \l_@@_matrix_c_fp +\fp_new:N \l_@@_matrix_d_fp +\dim_new:N \l_@@_xshift_dim +\dim_new:N \l_@@_yshift_dim % \end{macrocode} % \end{variable} % -% \begin{macro}{\draw_transform_reset:} +% \begin{macro}{\draw_transform_matrix_reset:, \draw_transform_shift_reset:} % Fast resetting. % \begin{macrocode} -\cs_new_protected:Npn \draw_transform_reset: +\cs_new_protected:Npn \draw_transform_matrix_reset: + { + \fp_set:Nn \l_@@_matrix_a_fp { 1 } + \fp_zero:N \l_@@_matrix_b_fp + \fp_zero:N \l_@@_matrix_c_fp + \fp_set:Nn \l_@@_matrix_d_fp { 1 } + } +\cs_new_protected:Npn \draw_transform_shift_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 + \dim_zero:N \l_@@_xshift_dim + \dim_zero:N \l_@@_yshift_dim } -\draw_transform_reset: +\draw_transform_matrix_reset: +\draw_transform_shift_reset: % \end{macrocode} % \end{macro} % -% \begin{macro}{\draw_transform:nnnnn} -% \begin{macro}{\@@_transform:nnnnnnn} +% \begin{macro}{\draw_transform_matrix:nnnn} +% \begin{macro}{\draw_transform_shift:n} +% \begin{macro}{\@@_transform_shift:nn} % 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 +\cs_new_protected:Npn \draw_transform_matrix:nnnn #1#2#3#4 { - \@@_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} + \fp_set:Nn \l_@@_matrix_a_fp {#1} + \fp_set:Nn \l_@@_matrix_b_fp {#2} + \fp_set:Nn \l_@@_matrix_c_fp {#3} + \fp_set:Nn \l_@@_matrix_d_fp {#4} \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 } + { \fp_compare_p:nNn \l_@@_matrix_a_fp = \c_one_fp } + { \fp_compare_p:nNn \l_@@_matrix_b_fp = \c_zero_fp } + { \fp_compare_p:nNn \l_@@_matrix_c_fp = \c_zero_fp } + { \fp_compare_p:nNn \l_@@_matrix_d_fp = \c_one_fp } } - { \bool_set_false:N \l_@@_transformcm_active_bool } - { \bool_set_true:N \l_@@_transformcm_active_bool } + { \bool_set_false:N \l_@@_matrix_active_bool } + { \bool_set_true:N \l_@@_matrix_active_bool } + } +\cs_new_protected:Npn \draw_transform_shift:n #1 + { + \@@_point_process:nn + { \@@_transform_shift:nn } {#1} + } +\cs_new_protected:Npn \@@_transform_shift:nn #1#2 + { + \dim_set:Nn \l_@@_xshift_dim {#1} + \dim_set:Nn \l_@@_yshift_dim {#2} } % \end{macrocode} % \end{macro} % \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{macro}{\draw_transform_matrix_concat:nnnn} +% \begin{macro}{\@@_transform_concat:nnnn} +% \begin{macro}{\draw_transform_shift_concat:n} +% \begin{macro}{\@@_transform_shift_concat:nn} +% Much the same story for adding to an existing matrix, with a bit of +% pre-expansion so that the calculation uses \enquote{frozen} values. % \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 +\cs_new_protected:Npn \draw_transform_matrix_concat:nnnn #1#2#3#4 { \use:x { - \@@_transform_concat_aux:nnnnnn + \@@_transform_concat:nnnn { \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 +\cs_new_protected:Npn \@@_transform_concat:nnnn #1#2#3#4 { \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 - } - } + \draw_transform_matrix:nnnn + { #1 * \l_@@_matrix_a_fp + #2 * \l_@@_matrix_c_fp } + { #1 * \l_@@_matrix_b_fp + #2 * \l_@@_matrix_d_fp } + { #3 * \l_@@_matrix_a_fp + #4 * \l_@@_matrix_c_fp } + { #3 * \l_@@_matrix_b_fp + #4 * \l_@@_matrix_d_fp } } } +\cs_new_protected:Npn \draw_transform_shift_concat:n #1 + { + \@@_point_process:nn + { \@@_transform_shift_concat:nn } {#1} + } +\cs_new_protected:Npn \@@_transform_shift_concat:nn #1#2 + { + \dim_set:Nn \l_@@_xshift_dim { \l_@@_xshift_dim + #1 } + \dim_set:Nn \l_@@_yshift_dim { \l_@@_yshift_dim + #2 } + } % \end{macrocode} % \end{macro} % \end{macro} % \end{macro} +% \end{macro} % -% \begin{macro}{\draw_transform_invert:} +% \begin{macro}{\draw_transform_matrix_invert:} % \begin{macro}{\@@_transform_invert:n, \@@_transform_invert:f} +% \begin{macro}{\draw_transform_shift_invert:} % Standard mathematics: calculate the inverse matrix and use that, then % undo the shifts. % \begin{macrocode} -\cs_new_protected:Npn \draw_transform_invert: +\cs_new_protected:Npn \draw_transform_matrix_invert: { - \bool_if:NT \l_@@_transformcm_active_bool + \bool_if:NT \l_@@_matrix_active_bool { \@@_transform_invert:f { @@ -208,44 +218,34 @@ { 1 / ( - \l_@@_transformcm_aa_fp * \l_@@_transformcm_bb_fp - - \l_@@_transformcm_ab_fp * \l_@@_transformcm_ba_fp + \l_@@_matrix_a_fp * \l_@@_matrix_d_fp + - \l_@@_matrix_b_fp * \l_@@_matrix_c_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 } + \fp_set:Nn \l_@@_matrix_a_fp + { \l_@@_matrix_d_fp * #1 } + \fp_set:Nn \l_@@_matrix_b_fp + { -\l_@@_matrix_b_fp * #1 } + \fp_set:Nn \l_@@_matrix_c_fp + { -\l_@@_matrix_c_fp * #1 } + \fp_set:Nn \l_@@_matrix_d_fp + { \l_@@_matrix_a_fp * #1 } } \cs_generate_variant:Nn \@@_transform_invert:n { f } +\cs_new_protected:Npn \draw_transform_shift_invert: + { + \dim_set:Nn \l_@@_xshift_dim { -\l_@@_xshift_dim } + \dim_set:Nn \l_@@_yshift_dim { -\l_@@_yshift_dim } + } % \end{macrocode} % \end{macro} % \end{macro} +% \end{macro} % % \begin{macro}{\draw_transform_triangle:nnn} % Simple maths to move the canvas origin to |#1| and the two axes to @@ -265,18 +265,69 @@ { \use:x { - \@@_transform:nnnnnnn + \draw_transform_matrix:nnnn { #3 - #1 } { #4 - #2 } { #5 - #1 } { #6 - #2 } - {#1} - {#2} + \draw_transform_shift:n { #1 , #2 } } } % \end{macrocode} % \end{macro} % +% \begin{macro} +% {\draw_transform_scale:n, \draw_transform_xscale:n, \draw_transform_yscale:n} +% \begin{macro} +% {\draw_transform_xshift:n, \draw_transform_yshift:n} +% \begin{macro} +% {\draw_transform_xslant:n, \draw_transform_yslant:n} +% Lots of shortcuts. +% \begin{macrocode} +\cs_new_protected:Npn \draw_transform_scale:n #1 + { \draw_transform_matrix_concat:nnnn { #1 } { 0 } { 0 } { #1 } } +\cs_new_protected:Npn \draw_transform_xscale:n #1 + { \draw_transform_matrix_concat:nnnn { #1 } { 0 } { 0 } { 1 } } +\cs_new_protected:Npn \draw_transform_yscale:n #1 + { \draw_transform_matrix_concat:nnnn { 1 } { 0 } { 0 } { #1 } } +\cs_new_protected:Npn \draw_transform_xshift:n #1 + { \draw_transform_shift_concat:n { #1 , 0 } } +\cs_new_protected:Npn \draw_transform_yshift:n #1 + { \draw_transform_shift_concat:n { 0 , #1 } } +\cs_new_protected:Npn \draw_transform_xslant:n #1 + { \draw_transform_matrix_concat:nnnn { 1 } { 0 } { #1 } { 1 } } +\cs_new_protected:Npn \draw_transform_yslant:n #1 + { \draw_transform_matrix_concat:nnnn { 1 } { #1 } { 0 } { 1 } } +% \end{macrocode} +% \end{macro} +% \end{macro} +% \end{macro} +% +% \begin{macro}{\draw_transform_rotate:n} +% \begin{macro} +% { +% \@@_transform_rotate:n, \@@_transform_rotate:f, +% \@@_transform_rotate:nn, \@@_transform_rotate:ff +% } +% Slightly more involved: evaluate the angle only once, and the sine and +% cosine only once. +% \begin{macrocode} +\cs_new_protected:Npn \draw_transform_rotate:n #1 + { \@@_transform_rotate:f { \fp_eval:n {#1} } } +\cs_new_protected:Npn \@@_transform_rotate:n #1 + { + \@@_transform_rotate:ff + { \fp_eval:n { cosd(#1) } } + { \fp_eval:n { sind(#1) } } + } +\cs_generate_variant:Nn \@@_transform_rotate:n { f } +\cs_new_protected:Npn \@@_transform_rotate:nn #1#2 + { \draw_transform_matrix_concat:nnnn {#1} {#2} { -#2 } { #1 } } +\cs_generate_variant:Nn \@@_transform_rotate:nn { ff } +% \end{macrocode} +% \end{macro} +% \end{macro} +% % \begin{macrocode} %</initex|package> % \end{macrocode} |