昨天我在更新我的回答时十二月挑战(一棵装饰树),我遇到了一个问题:如果我选择的图片尺寸太小,那么它会失败
尺寸太大。
代码
\documentclass[tikz, border=2mm]{standalone}
\usetikzlibrary{decorations.markings}
\begin{document}
\newcommand{\XMasPic}[5]%
% x pos, ypos, width, height, draw commands
{ \begin{scope}[shift={(#1,#2)}, x={(#3,0)}, y={(0,#4)}]
\fill[gray!5] (0,0) rectangle (1,1);
\draw[clip] (0,0) rectangle (1,1);
#5
\draw (0,0) rectangle (1,1);
\end{scope}
}
\newcommand{\DecoratedTree}[4]%
{ \XMasPic{#1}{#2}{#3}{#4}%
{ \fill[inner color=blue!40!black, outer color=blue!10!black] (0.02,0.02) rectangle (0.98,0.98);
\xdef\CuCo{0}
\draw
[ yellow,
bend left=10,
decoration=
{ markings,
mark=between positions 0.01 and 1 step 0.02 with
{
\pgfmathtruncatemacro{\C}{mod(\CuCo,3)}
\fill[inner color=\ifcase\C red\or blue\or yellow\fi, outer color=transparent, opacity=0.2] (0,0) circle (0.015);
\fill[inner color=\ifcase\C red\or blue\or yellow\fi, outer color=\ifcase\C red!50\or blue!50\or yellow!50\fi] (0,0) circle (0.005);
\pgfmathparse{\CuCo+1}
\xdef\CuCo{\pgfmathresult}
}
},
postaction={decorate}] (0.61,0.21) to (0.40,0.265) (0.585,0.325) to (0.43,0.38) (0.56,0.44) to (0.45,0.50) (0.55,0.55) to (0.46,0.61) (0.53,0.665) to (0.475,0.72);
}
}
\begin{tikzpicture}
%\DecoratedTree{4}{0}{3.2}{3.2} % fails;
\DecoratedTree{0}{0}{3.3}{3.3}
\end{tikzpicture}
\end{document}
预期输出
是\XMasPic
一个包装器,它将图像缩放到所需的尺寸(宽度#3
和高度#4
),并在内部提供坐标缩放,以便所有坐标都可以表示为 0 到 1 之间的值(参见 Caramdir 对这个问题)
该错误似乎是由于装饰中的增量很小而发生的:
mark=between positions 0.01 and 1 step
0.02
with {...}
我怀疑这一步0.02
太小了数学将其四舍五入为零,因此永远不会完成。
有人能确认这是导致此错误的原因吗?并且最好推荐一种解决方法吗?