diff options
author | Karl Berry <karl@freefriends.org> | 2014-01-26 22:14:21 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2014-01-26 22:14:21 +0000 |
commit | f743052d85acf7d676d00e1903db1806032ac9f6 (patch) | |
tree | 09ad4bdf5a9a5607a4727be3a8e7adcd23fe2662 /Master/texmf-dist/source/latex/hobby/hobby.dtx | |
parent | fc11ec42903196eb886eff26e3c251aa47fdd8fb (diff) |
hobby
git-svn-id: svn://tug.org/texlive/trunk@32795 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/source/latex/hobby/hobby.dtx')
-rw-r--r-- | Master/texmf-dist/source/latex/hobby/hobby.dtx | 242 |
1 files changed, 195 insertions, 47 deletions
diff --git a/Master/texmf-dist/source/latex/hobby/hobby.dtx b/Master/texmf-dist/source/latex/hobby/hobby.dtx index c41e8f8d9fc..74ad06c13dd 100644 --- a/Master/texmf-dist/source/latex/hobby/hobby.dtx +++ b/Master/texmf-dist/source/latex/hobby/hobby.dtx @@ -110,7 +110,7 @@ and the derived files hobby.code.tex %</driver> % \fi % -% \CheckSum{3002} +% \CheckSum{3304} % % \CharacterTable % {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z @@ -135,6 +135,7 @@ and the derived files hobby.code.tex % \providecommand*{\url}{\texttt} % \title{The \textsf{Hobby} package: code} % \author{Andrew Stacey \\ \url{stacey@math.ntnu.no}} +% \date{\hobbyVersion\ from\ \hobbyDate} % \maketitle % % @@ -165,17 +166,42 @@ and the derived files hobby.code.tex % % We declare all our variables. % +% Start with version and date, together with a check to see if we've been loaded twice (fail gracefully if so). +% +% \begin{macrocode} +\tl_clear:N \l_tmpa_tl +\tl_if_exist:NT \g__hobby_version +{ + \tl_set:Nn \l_tmpa_tl { + \ExplSyntaxOff + \tl_clear:N \l_tmpa_tl + \endinput + } +} +\tl_use:N \l_tmpa_tl + +\tl_new:N \g__hobby_version +\tl_new:N \g__hobby_date +\tl_set:Nn \g__hobby_version {1.4} +\tl_set:Nn \g__hobby_date {2014-01-21} +\DeclareDocumentCommand \hobbyVersion {} +{ + \tl_use:N \g__hobby_version +} +\DeclareDocumentCommand \hobbyDate {} +{ + \tl_use:N \g__hobby_date +} +% \end{macrocode} +% % The function for computing the lengths of the control points depends on three parameters. % These are set to \(a = \sqrt{2}\), \(b = 1/16\), and \(c = \frac{3 - \sqrt{5}}{2}\). % \begin{macrocode} \fp_new:N \g_hobby_parama_fp \fp_new:N \g_hobby_paramb_fp \fp_new:N \g_hobby_paramc_fp - \fp_gset:Nn \g_hobby_parama_fp {2^.5} - \fp_gset:Nn \g_hobby_paramb_fp {1/16} - \fp_gset:Nn \g_hobby_paramc_fp {(3-5^.5)/2} % \end{macrocode} % @@ -195,6 +221,18 @@ and the derived files hobby.code.tex % \end{macrocode} % \end{macro} % +% \begin{macro}{\l_hobby_save_aux_bool} +% \Verb+\l_hobby_save_aux_bool+ is \Verb+true+ if when saving paths then they should be saved to the \Verb+aux+ file. +% \begin{macrocode} +\bool_new:N \l_hobby_save_aux_bool +\bool_set_true:N \l_hobby_save_aux_bool +\DeclareDocumentCommand \HobbyDisableAux {} +{ + \bool_set_false:N \l_hobby_save_aux_bool +} +% \end{macrocode} +% \end{macro} +% % \begin{macro}{\l_hobby_points_array} % \Verb+\l_hobby_points_array+ is an array holding the specified points on the path. % In the \LaTeX3 code, a ``point'' is a token list of the form \Verb+x = <number>, y = <number>+. @@ -568,7 +606,7 @@ and the derived files hobby.code.tex (\array_get:Nn \l_hobby_points_y_array {#1 + 1}) - (\array_get:Nn \l_hobby_points_y_array {#1})} - \fp_atantwo:NNN \l_hobby_tempc_fp \l_hobby_tempb_fp \l_hobby_tempa_fp + \fp_set:Nn \l_hobby_tempc_fp { atan ( \l_hobby_tempb_fp, \l_hobby_tempa_fp ) } \fp_veclen:NVV \l_hobby_tempd_fp \l_hobby_tempa_fp \l_hobby_tempb_fp \array_push:Nx \l_hobby_angles_array {\fp_to_tl:N \l_hobby_tempc_fp} @@ -577,19 +615,6 @@ and the derived files hobby.code.tex % \end{macrocode} % \end{macro} % -% -% \begin{macro}{\fp_atantwo:NNN} -% Computes the angle of the point specified by the latter two arguments, storing the answer in the first. -% The inverse tangent function is not yet implemented in \LaTeX3 so for now we use the \Verb+pgfmath+ function. -% When this is implemented in \LaTeX3 this should be replaced. -% \begin{macrocode} -\cs_new:Nn \fp_atantwo:NNN { - \pgfmathparse{rad(atan2(\fp_use:N #3,\fp_use:N #2))} - \exp_args:NNo \fp_set:Nn #1 {\pgfmathresult} -} -% \end{macrocode} -% \end{macro} -% % \begin{macro}{\fp_veclen:NVV} % Computes the length of the vector specified by the latter two arguments, storing the answer in the first. % \begin{macrocode} @@ -720,7 +745,7 @@ and the derived files hobby.code.tex \fp_if_undefined:NF \l_hobby_out_angle_fp { \fp_set:Nn \l_hobby_tempa_fp { \l_hobby_out_angle_fp - - \array_get:Nn \l_hobby_angles_array {0} } + - \array_get:Nn \l_hobby_angles_array {0}} % \end{macrocode} % We want to ensure that these angles lie in the range \((-\pi,\pi]\). % So if the angle is bigger than \(\pi\), we subtract \(2 \pi\). @@ -819,21 +844,12 @@ and the derived files hobby.code.tex % \end{macrocode} % Similarly, we check to see if the angle is less than \(-\pi\). % \begin{macrocode} - \fp_compare:nTF {\l_hobby_tempa_fp < -\c_pi_fp } + \fp_compare:nTF {\l_hobby_tempa_fp <= -\c_pi_fp } { \fp_add:Nn \l_hobby_tempa_fp {2 * \c_pi_fp} } {} % \end{macrocode} -% At the moment, the mixing of \Verb+pgfmath+ and \LaTeX3 that goes into computing the differences means that we can never get \Verb+\c_pi_fp+ so testing for equality is meaningless. -% However, when \Verb+atan2+ is implemented in \LaTeX3 then this might make sense again. -% -%^^A \fp_compare:nTF {\l_hobby_tempa_fp = -\c_pi_fp } -%^^A { -%^^A \fp_add:Nn \l_hobby_tempa_fp {2 * \c_pi_fp} -%^^A } -%^^A {} -% % The wrapping routine might not get it right at the edges so we add in the override. % \begin{macrocode} \array_get:NnNTF \l_hobby_excess_angle_array {##1} \l_tmpa_tl { @@ -997,7 +1013,7 @@ and the derived files hobby.code.tex \array_put:Nnn \l_hobby_matrix_b_array {0} {1} \array_put:Nnn \l_hobby_matrix_c_array {0} {0} \fp_set:Nn \l_hobby_tempa_fp { \l_hobby_out_angle_fp - - \array_get:Nn \l_hobby_angles_array {0} } + - \array_get:Nn \l_hobby_angles_array {0}} % \end{macrocode} % We want to ensure that these angles lie in the range \((-\pi,\pi]\). % So if the angle is bigger than \(\pi\), we subtract \(2 \pi\). @@ -1370,8 +1386,14 @@ sin ( (\array_get:Nn \l_hobby_angles_array {##1}) % The path-generation code doesn't know what to actually do with the path so the initialisation code will set some macros to do that. % This is an auxiliary command that sets these macros. % \begin{macrocode} +\cs_new:Npn \hobby_moveto:nnn #1#2#3 {} +\cs_new:Npn \hobby_curveto:nnn #1#2#3 {} +\cs_new:Npn \hobby_close:n #1 {} +\cs_generate_variant:Nn \hobby_moveto:nnn {VVV,nnV} +\cs_generate_variant:Nn \hobby_curveto:nnn {VVV} +\cs_generate_variant:Nn \hobby_close:n {V} \cs_new:Nn \hobby_set_cmds:nnn { - \cs_gset_eq:NN \hobby_moveto:n #1 + \cs_gset_eq:NN \hobby_moveto:nnn #1 \cs_gset_eq:NN \hobby_curveto:nnn #2 \cs_gset_eq:NN \hobby_close:n #3 } @@ -1498,7 +1520,7 @@ sin ( (\array_get:Nn \l_hobby_angles_array {##1}) \cs_new:Nn \hobby_use_path: { \bool_if:NT \l_hobby_disjoint_bool { \array_get:NnN \l_hobby_points_array {0} \l_tmpa_tl - \exp_args:No \hobby_moveto:n {\l_tmpa_tl} + \hobby_moveto:nnV {} {} \l_tmpa_tl } \int_step_inline:nnnn {1} {1} {\l_hobby_npoints_int} { \array_get:NnN \l_hobby_controla_array {##1} \l_tmpa_tl @@ -1506,20 +1528,20 @@ sin ( (\array_get:Nn \l_hobby_angles_array {##1}) \array_get:NnN \l_hobby_points_array {##1} \l_tmpc_tl \array_get:NnN \l_hobby_actions_array {##1} \l_tmpd_tl \int_compare:nNnTF {\tl_item:Nn \l_tmpd_tl {1}} = {\l_hobby_draw_int} { - \exp_args:Nooo \hobby_curveto:nnn {\l_tmpa_tl} {\l_tmpb_tl} {\l_tmpc_tl} + \hobby_curveto:VVV \l_tmpa_tl \l_tmpb_tl \l_tmpc_tl }{ \bool_gset_false:N \l_hobby_closed_bool - \exp_args:No \hobby_moveto:n {\l_tmpc_tl} + \hobby_moveto:VVV \l_tmpa_tl \l_tmpb_tl \l_tmpc_tl } \tl_if_eq:xnTF {\tl_item:Nn \l_tmpd_tl {2}} {1} { \bool_gset_false:N \l_hobby_closed_bool - \exp_args:No \hobby_moveto:n {\l_tmpc_tl} + \hobby_moveto:VVV \l_tmpa_tl \l_tmpb_tl \l_tmpc_tl }{} } \bool_if:NT \l_hobby_closed_bool { \array_get:NnN \l_hobby_points_array {0} \l_tmpa_tl - \exp_args:No \hobby_close:n {\l_tmpa_tl} - } + \hobby_close:V \l_tmpa_tl + } } % \end{macrocode} % \end{macro} @@ -1582,6 +1604,8 @@ sin ( (\array_get:Nn \l_hobby_angles_array {##1}) \tl_if_exist_p:c {g_hobby_#1_path} && ! \tl_if_exist_p:c {g_hobby_#1_path_saved} + && + \l_hobby_save_aux_bool } { \tl_clear:N \l_tmpa_tl @@ -1673,6 +1697,24 @@ sin ( (\array_get:Nn \l_hobby_angles_array {##1}) } % \end{macrocode} % +% \begin{macro}{hobbyatan2} +% The original PGF version of \Verb+atan2+ had the arguments the wrong way around. +% This was fixed in the CVS version in July 2013, but as old versions are likely to be in use for some time, we define a wrapper function that ensures that the arguments are correct. +% \begin{macrocode} +\pgfmathparse{atan2(0,1)} +\def\hobby@temp{0.0} +\ifx\pgfmathresult\hobby@temp + \pgfmathdeclarefunction{hobbyatan2}{2}{% + \pgfmathatantwo@{#1}{#2}% + } +\else + \pgfmathdeclarefunction{hobbyatan2}{2}{% + \pgfmathatantwo@{#2}{#1}% + } +\fi +% \end{macrocode} +% \end{macro} +% % \begin{macro}{\hobby@curveto} % This is passed to the path-generation code to translate the path into a PGF path. % \begin{macrocode} @@ -1685,8 +1727,8 @@ sin ( (\array_get:Nn \l_hobby_angles_array {##1}) % \begin{macro}{\hobby@moveto} % This is passed to the path-generation code to translate the path into a PGF path. % \begin{macrocode} -\def\hobby@moveto#1{% - \pgfpathmoveto{\hobby@topgf{#1}}% +\def\hobby@moveto#1#2#3{% + \pgfpathmoveto{\hobby@topgf{#3}}% } % \end{macrocode} % \end{macro} @@ -1896,7 +1938,7 @@ sin ( (\array_get:Nn \l_hobby_angles_array {##1}) \advance\pgf@xb by -\pgf@xa \advance\pgf@yb by -\pgf@ya \pgfmathsetmacro\hobby@done{sqrt((\pgf@xb/\hobby@sf)^2 + (\pgf@yb/\hobby@sf)^2)}% - \pgfmathsetmacro\hobby@omegaone{rad(atan2(\pgf@xb,\pgf@yb))}% + \pgfmathsetmacro\hobby@omegaone{rad(hobbyatan2(\pgf@yb,\pgf@xb))}% % \end{macrocode} % Now we do the same with the vector from the zeroth to the first point. % \begin{macrocode} @@ -1904,7 +1946,7 @@ sin ( (\array_get:Nn \l_hobby_angles_array {##1}) \advance\pgf@xa by -\pgf@x \advance\pgf@ya by -\pgf@y \pgfmathsetmacro\hobby@dzero{sqrt((\pgf@xa/\hobby@sf)^2 + (\pgf@ya/\hobby@sf)^2)}% - \pgfmathsetmacro\hobby@omegazero{rad(atan2(\pgf@xa,\pgf@ya))}% + \pgfmathsetmacro\hobby@omegazero{rad(hobbyatan2(\pgf@ya,\pgf@xa))}% % \end{macrocode} % \Verb+\hobby@psi+ is the angle subtended at the midpoint. % We adjust to ensure that it is in the right range. @@ -2021,7 +2063,6 @@ sin ( (\array_get:Nn \l_hobby_angles_array {##1}) % \end{macrocode} % \end{macro} % -% % \iffalse %</pgflibrary> % \fi @@ -2141,12 +2182,14 @@ sin ( (\array_get:Nn \l_hobby_angles_array {##1}) }, restore Hobby path/.code={% \pgfextra{% - \hobbyinit\hobby@moveto\hobby@curveto\hobby@close + \hobbyinit\hobby@tikz@moveto\hobby@tikz@curveto\hobby@tikz@close + \global\let\hobby@collected@onpath\pgfutil@empty \hobbyrestorepath{#1}} }, restore and use Hobby path/.code 2 args={% \pgfextra{% - \hobbyinit\hobby@moveto\hobby@curveto\hobby@close + \hobbyinit\hobby@tikz@moveto\hobby@tikz@curveto\hobby@tikz@close + \global\let\hobby@collected@onpath\pgfutil@empty \hobbyrestorepath{#1}% \hobbyusepath{#2}% } @@ -2164,12 +2207,107 @@ sin ( (\array_get:Nn \l_hobby_angles_array {##1}) Hobby externalize/.is if=hobby@externalise } % \end{macrocode} +% +% \begin{macro}{\hobby@tikz@curveto} +% This is passed to the path-generation code to translate the path into a PGF path. +% \begin{macrocode} +\def\hobby@tikz@curveto#1#2#3{% + \pgfutil@ifundefined{tikz@timer@start}{% + \expandafter\hobby@topgf\expandafter{\hobby@initial@pt}% + \edef\tikz@timer@start{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}% + }{}% + \hobby@topgf{#1}% + \edef\tikz@timer@cont@one{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}% + \hobby@topgf{#2}% + \edef\tikz@timer@cont@two{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}% + \hobby@topgf{#3}% + \let\tikz@timer=\tikz@timer@curve + \edef\tikz@timer@end{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}% + \ifx\hobby@collected@onpath\pgfutil@empty + \else + \expandafter\hobby@nodes@onpath\hobby@collected@onpath\relax\relax + \fi + \pgfpathcurveto{\hobby@topgf{#1}}{\hobby@topgf{#2}}{\hobby@topgf{#3}}% + \hobby@topgf{#3}% + \edef\tikz@timer@start{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}% +} +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\hobby@tikz@moveto} +% This is passed to the path-generation code to translate the path into a PGF path. +% \begin{macrocode} +\def\hobby@tikz@moveto#1#2#3{% + \pgfutil@ifundefined{tikz@timer@start}{% + \expandafter\hobby@topgf\expandafter{\hobby@initial@pt}% + \edef\tikz@timer@start{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}% + }{}% + \hobby@topgf{#3}% + \edef\tikz@timer@end{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}% + \def\pgf@temp{#1}% + \ifx\pgf@temp\pgfutil@empty + \let\tikz@timer=\tikz@timer@line + \else + \hobby@topgf{#1}% + \edef\tikz@timer@cont@one{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}% + \hobby@topgf{#2}% + \edef\tikz@timer@cont@two{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}% + \let\tikz@timer=\tikz@timer@curve + \fi + \ifx\hobby@collected@onpath\pgfutil@empty + \else + \expandafter\hobby@nodes@onpath\hobby@collected@onpath\relax\relax + \fi + \pgfpathmoveto{\hobby@topgf{#3}}% + \hobby@topgf{#3}% + \edef\tikz@timer@start{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}% +} +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\hobby@tikz@close} +% Closes a path. +% \begin{macrocode} +\def\hobby@tikz@close#1{% + \hobby@topgf{#1}% + \edef\tikz@timer@end{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}% + \let\tikz@timer=\tikz@timer@line + \ifx\hobby@collected@onpath\pgfutil@empty + \else + \expandafter\hobby@nodes@onpath\hobby@collected@onpath\relax\relax + \fi + \pgfpathclose +} +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\hobby@nodes@onpath} +% \begin{macrocode} +\def\hobby@nodes@onpath#1#2\relax{% + \gdef\hobby@collected@onpath{#2}% + \def\pgf@temp{#1}% + \ifx\pgf@temp\pgfutil@empty + \else + \def\@gtempa{\relax} + \ifx\pgf@temp\@gtempa + \else + \tikz@node@is@a@labeltrue + \tikz@scan@next@command#1\pgf@stop + \tikz@node@is@a@labelfalse + \fi + \fi +} +% \end{macrocode} +% \end{macro} +% % \begin{macro}{\curvethrough} % This is the parent command. % We initialise the path-generation code, set any parameters, and then hand over control to the point processing macro. % \begin{macrocode} \newcommand\curvethrough[2][]{% - \hobbyinit\hobby@moveto\hobby@curveto\hobby@close + \hobbyinit\hobby@tikz@moveto\hobby@tikz@curveto\hobby@tikz@close + \global\let\hobby@collected@onpath\pgfutil@empty + \let\hobby@initial@pt\pgfutil@empty \hobbysetparams{#1}% \tikzset{designated Hobby path=this}% \global\let\hobby@this@opts=\pgfutil@empty @@ -2191,6 +2329,9 @@ sin ( (\array_get:Nn \l_hobby_angles_array {##1}) #1% \pgfmathsetmacro\hobby@x{\the\pgf@x/1cm}% \pgfmathsetmacro\hobby@y{\the\pgf@y/1cm}% + \ifx\hobby@initial@pt\pgfutil@empty + \xdef\hobby@initial@pt{x = \hobby@x, y = \hobby@y}% + \fi \expandafter\hobbyaddpoint\expandafter{\hobby@point@options,% x = \hobby@x, y = \hobby@y}% \def\hobby@point@options{}% @@ -2246,9 +2387,12 @@ sin ( (\array_get:Nn \l_hobby_angles_array {##1}) % To ensure that the generation code is called, we add a lot of hooks to lots of TikZ commands. % \begin{macrocode} \def\hobby@curveto@auto{% - \hobbyinit\hobby@moveto\hobby@curveto\hobby@close + \hobbyinit\hobby@tikz@moveto\hobby@tikz@curveto\hobby@tikz@close + \expandafter\gdef\expandafter\hobby@collected@onpath\expandafter{\expandafter{\tikz@collected@onpath} }% + \let\tikz@collected@onpath=\pgfutil@empty \pgfmathsetmacro\hobby@x{\the\tikz@lastx/1cm}% \pgfmathsetmacro\hobby@y{\the\tikz@lasty/1cm}% + \xdef\hobby@initial@pt{x = \hobby@x, y = \hobby@y}% \expandafter\hobbysetparams\expandafter{\hobby@next@opts}% \expandafter\hobbyaddpoint\expandafter{\hobby@point@options,% x = \hobby@x, y = \hobby@y}% @@ -2259,7 +2403,8 @@ sin ( (\array_get:Nn \l_hobby_angles_array {##1}) \global\let\hobby@this@opts=\pgfutil@empty \global\let\hobby@next@opts=\pgfutil@empty \global\let\hobby@point@options=\pgfutil@empty - \tikz@scan@one@point\hobby@addfromtikz} + \tikz@scan@one@point\hobby@addfromtikz% +} % \end{macrocode} % \end{macro} % @@ -2349,6 +2494,8 @@ sin ( (\array_get:Nn \l_hobby_angles_array {##1}) % \begin{macro}{\hobby@midcurveto@auto} % \begin{macrocode} \def\hobby@midcurveto@auto{% + \expandafter\expandafter\expandafter\gdef\expandafter\expandafter\expandafter\hobby@collected@onpath\expandafter\expandafter\expandafter{\expandafter\hobby@collected@onpath\expandafter{\tikz@collected@onpath} }% + \let\tikz@collected@onpath=\pgfutil@empty \let\tikz@scan@point@options=\pgfutil@empty \global\let\hobby@action=\pgfutil@empty \global\let\hobby@this@opts=\pgfutil@empty @@ -2671,6 +2818,7 @@ sin ( (\array_get:Nn \l_hobby_angles_array {##1}) \hobby@qinit@tikz@modcmd\tikz@to \hobby@qinit@tikz@modcmd\pgf@stop \hobby@qinit@tikz@modcmd\tikz@decoration + \hobby@qinit@tikz@modcmd\tikz@@close \global\let\hobby@curveto@delegate=\hobby@qmidcurveto@auto } % \end{macrocode} |