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/tex/latex/hobby | |
parent | fc11ec42903196eb886eff26e3c251aa47fdd8fb (diff) |
hobby
git-svn-id: svn://tug.org/texlive/trunk@32795 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/hobby')
3 files changed, 151 insertions, 27 deletions
diff --git a/Master/texmf-dist/tex/latex/hobby/hobby.code.tex b/Master/texmf-dist/tex/latex/hobby/hobby.code.tex index 18c3409d5a3..0e567fcc528 100644 --- a/Master/texmf-dist/tex/latex/hobby/hobby.code.tex +++ b/Master/texmf-dist/tex/latex/hobby/hobby.code.tex @@ -20,17 +20,43 @@ \cs_generate_variant:Nn \fp_set:Nn {Nx} \cs_generate_variant:Nn \tl_if_eq:nnTF {VnTF} \cs_generate_variant:Nn \tl_if_eq:nnTF {xnTF} +\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 +} \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} \bool_new:N \l_hobby_closed_bool \bool_new:N \l_hobby_disjoint_bool +\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 +} \array_new:N \l_hobby_points_array \array_new:N \l_hobby_points_x_array \array_new:N \l_hobby_points_y_array @@ -150,16 +176,12 @@ (\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} \array_push:Nx \l_hobby_distances_array {\fp_to_tl:N \l_hobby_tempd_fp} } -\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} -} \cs_new:Nn \fp_veclen:Nnn { \fp_set:Nn #1 {((#2)^2 + (#3)^2)^.5} } @@ -214,7 +236,7 @@ \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}} \fp_compare:nT {\l_hobby_tempa_fp > \c_pi_fp } { \fp_sub:Nn \l_hobby_tempa_fp {2 * \c_pi_fp} @@ -276,7 +298,7 @@ \fp_sub:Nn \l_hobby_tempa_fp {2 * \c_pi_fp} } {} - \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} } @@ -403,7 +425,7 @@ \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}} \fp_compare:nT {\l_hobby_tempa_fp > \c_pi_fp } { \fp_sub:Nn \l_hobby_tempa_fp {2 * \c_pi_fp} @@ -681,8 +703,14 @@ sin ( (\array_get:Nn \l_hobby_angles_array {##1}) #1 } } +\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 } @@ -744,7 +772,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 @@ -752,20 +780,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 + } } \cs_new:Nn \hobby_save_path:n { \tl_clear:N \l_tmpa_tl @@ -817,6 +845,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 diff --git a/Master/texmf-dist/tex/latex/hobby/pgflibraryhobby.code.tex b/Master/texmf-dist/tex/latex/hobby/pgflibraryhobby.code.tex index 5d0f4a91996..37d6a70a6ed 100644 --- a/Master/texmf-dist/tex/latex/hobby/pgflibraryhobby.code.tex +++ b/Master/texmf-dist/tex/latex/hobby/pgflibraryhobby.code.tex @@ -20,11 +20,22 @@ x/.code={\pgf@x=#1cm}, y/.code={\pgf@y=#1cm} } +\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 \def\hobby@curveto#1#2#3{% \pgfpathcurveto{\hobby@topgf{#1}}{\hobby@topgf{#2}}{\hobby@topgf{#3}}% } -\def\hobby@moveto#1{% - \pgfpathmoveto{\hobby@topgf{#1}}% +\def\hobby@moveto#1#2#3{% + \pgfpathmoveto{\hobby@topgf{#3}}% } \def\hobby@topgf#1{% \pgfqkeys{/pgf/hobby}{#1}% @@ -137,12 +148,12 @@ \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))}% \hobby@qpoints \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))}% \pgfmathsetmacro\hobby@psi{\hobby@omegaone - \hobby@omegazero}% \pgfmathsetmacro\hobby@psi{\hobby@psi > pi ? \hobby@psi - 2*pi : \hobby@psi}% \pgfmathsetmacro\hobby@psi{\hobby@psi < -pi ? \hobby@psi + 2*pi : \hobby@psi}% diff --git a/Master/texmf-dist/tex/latex/hobby/tikzlibraryhobby.code.tex b/Master/texmf-dist/tex/latex/hobby/tikzlibraryhobby.code.tex index a3fa361d216..ced64271e8b 100644 --- a/Master/texmf-dist/tex/latex/hobby/tikzlibraryhobby.code.tex +++ b/Master/texmf-dist/tex/latex/hobby/tikzlibraryhobby.code.tex @@ -116,12 +116,14 @@ }, 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}% } @@ -138,8 +140,79 @@ Hobby externalise/.is if=hobby@externalise, Hobby externalize/.is if=hobby@externalise } +\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}}% +} +\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}}% +} +\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 +} +\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 +} \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 @@ -152,6 +225,9 @@ #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{}% @@ -183,9 +259,12 @@ \def\hobby@curveto@override{% \hobby@curveto@delegate} \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}% @@ -196,7 +275,8 @@ \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% +} \def\hobby@addfromtikz#1{% #1% \tikz@make@last@position{#1}% @@ -255,6 +335,8 @@ \expandafter\global\expandafter\let\expandafter#1\csname hobby@orig@\string#1\endcsname% } \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 @@ -467,6 +549,7 @@ \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 } \def\hobby@qrestore@tikz@commands{% |