3

When working on yesterday's update on my answer to the december challenge (a dcorated tree), I encountered a problem: if I choose the picture's dimensions to small, then it fails with

Dimension too large.

Code

\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}

Expected Output

enter image description here

The \XMasPic is a wrapper that scales the image to the desired dimensions (width #3 and height #4) and internally provides a coordinate scaling so that all coordinates can be expressed as values bewtween 0 and 1 (see Caramdir's answer to this question)

This error appears to occur due to the small increment in the decoration:

mark=between positions 0.01 and 1 step0.02with {...}

I suspect that the step 0.02 is so small that pgfmath rounds it to zero and therefore never finishes.

Can anyone confirm this is the reason for this error, and ideally recommend a way to get around it?

closed as off-topic by Symbol 1, Mico, Stefan Pinnow, CarLaTeX, gernot Mar 28 '17 at 22:21

  • This question does not fall within the scope of TeX, LaTeX or related typesetting systems as defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

  • I asked a general question about this here. – cfr Dec 20 '15 at 22:05
  • Not sure but can you say \begin{scope}[shift={(#1,#2)}, xscale=#3, yscale=#4] rather than setting x and y? That is, I'm not sure if this is equivalent or not. – cfr Dec 20 '15 at 22:12
  • [I guess it is not equivalent: the y seems too squished.] – cfr Dec 20 '15 at 22:17
  • 3
    I'm voting to close this question as off-topic because the error cannot be reproduced anymore. – Symbol 1 Mar 28 '17 at 20:07