Monday, 19 August 2013

TikZ: compilation time performance of decorations

TikZ: compilation time performance of decorations

I want to produce a picture that contains lots of cylinder-kind shapes
(maybe about 200) along certain paths. Here is an example of such a shape:
\documentclass{standalone}
\usepackage[svgnames]{xcolor}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
%%%%% H-O bond between atom 1 and atom 3
%%% O half of the bond
% O half bond shading
\pgfdeclareverticalshading{1_3_O3_BondShading}{100bp}{
color(0.000bp)=(Black!75!Red);
color(22.773bp)=(Black!75!Red);
color(45.525bp)=(Black!3.893!Red);
color(53.986bp)=(White!26.261!Red);
color(59.561bp)=(White!26.261!Red);
color(68.022bp)=(Black!3.893!Red);
color(90.773bp)=(Black!75!Red);
color(100.000bp)=(Black!75!Red)}
% O half bond drawing
\begin{scope}
\pgfsetadditionalshadetransform{\pgftransformyscale{0.0856124622417}}
\pgfpathmoveto{\pgfpoint{3.107cm}{-5.942cm}}
\pgfpathlineto{\pgfpoint{2.998cm}{-5.816cm}}
\pgfpatharcaxes{0}{180}{\pgfpoint{0.085cm}{0.073cm}}{\pgfpoint{-0.034cm}{0.040cm}}
\pgfpathlineto{\pgfpoint{2.936cm}{-6.088cm}}
\pgfpatharcaxes{180}{0}{\pgfpoint{0.085cm}{0.073cm}}{\pgfpoint{-0.034cm}{0.040cm}}
\pgfusepath{clip}
\pgfpathcircle{\pgfpoint{2.968cm}{-5.952cm}}{1.168cm}
\pgfshadepath{1_3_O3_BondShading}{-49.384}
\pgfusepath{}
\end{scope}
%%% H half of the bond
% H half bond shading
\pgfdeclareverticalshading{1_3_H1_BondShading}{100bp}{
color(0.000bp)=(Black!75!White);
color(22.773bp)=(Black!75!White);
color(45.525bp)=(Black!20.000!White);
color(53.986bp)=(White!26.261!White);
color(59.561bp)=(White!26.261!White);
color(68.022bp)=(Black!20.000!White);
color(90.773bp)=(Black!75!White);
color(100.000bp)=(Black!75!White)}
% H half bond drawing
\begin{scope}
\pgfsetadditionalshadetransform{\pgftransformyscale{0.0856124622417}}
\pgfpathmoveto{\pgfpoint{2.936cm}{-6.088cm}}
\pgfpathlineto{\pgfpoint{3.026cm}{-6.193cm}}
\pgfpatharcaxes{180}{0}{\pgfpoint{0.086cm}{0.073cm}}{\pgfpoint{0.034cm}{-0.040cm}}
\pgfpathlineto{\pgfpoint{3.107cm}{-5.942cm}}
\pgfpatharcaxes{0}{180}{\pgfpoint{0.085cm}{0.073cm}}{\pgfpoint{-0.034cm}{0.040cm}}
\pgfusepath{clip}
\pgfpathcircle{\pgfpoint{3.066cm}{-6.067cm}}{1.168cm}
\pgfshadepath{1_3_H1_BondShading}{-49.384}
\pgfusepath{}
\end{scope}
\end{tikzpicture}
\end{document}
Since this makes the code unreadably long I thought of putting this into a
decoration. The decoration will have to take a lot of arguments: the
names, colors and positions of the shadings, as well as the coordinates
for the \pgfpatharcaxes commands. Unfortunately, I have very little
experience with TeX and pgf programming so that this will take up some
time. Since I want to be sure that this time investment is not wasted I'd
like to know whether it is to be expected that TikZ decorations come with
any penalty for the compilation time compared to the normal code shown
above (I would refrain from using a decoration if the compilation would
take more than twice as long)? Is it advisable to use a decoration in my
case or might there be reasons against it?

No comments:

Post a Comment