\input regression-test.tex \documentclass{article} \usepackage{tikzphysics} \newdimen\Actual \newdimen\Expected \newdimen\Difference \newcommand{\AssertAnchor}[5]{% \pgfextractx{\Actual}{\pgfpointanchor{#1}{#2}}\Expected=#3\relax \Difference=\dimexpr\Actual-\Expected\relax \ifdim\Difference<0pt\Difference=-\Difference\fi \ifdim\Difference<0.03pt\TYPE{PASS: #5 x}\else\TYPE{FAIL: #5 x got \the\Actual expected \the\Expected}\fi \pgfextracty{\Actual}{\pgfpointanchor{#1}{#2}}\Expected=#4\relax \Difference=\dimexpr\Actual-\Expected\relax \ifdim\Difference<0pt\Difference=-\Difference\fi \ifdim\Difference<0.03pt\TYPE{PASS: #5 y}\else\TYPE{FAIL: #5 y}\fi} \makeatletter \newcommand{\AssertShape}[3]{% \edef\ActualShape{\csname pgf@sh@ns@#1\endcsname}% \def\ExpectedShape{#2}% \ifx\ActualShape\ExpectedShape\TYPE{PASS: #3}\else\TYPE{FAIL: #3}\fi} \begin{document} \START \setbox0=\hbox{\begin{tikzpicture} \node[spring] (D) {}; \AssertShape{D}{physicsspring}{spring dispatches to node shape} \AssertAnchor{D}{start}{-1.5cm}{0pt}{default start} \AssertAnchor{D}{end}{1.5cm}{0pt}{default end} \AssertAnchor{D}{north}{0pt}{4.5pt}{amplitude bounds} \node[physicsspring,minimum width=4cm,pre length=3mm,post length=5mm, amplitude=2mm] (S) {}; \AssertAnchor{S}{coil-start}{-17mm}{0pt}{pre lead endpoint} \AssertAnchor{S}{coil-end}{15mm}{0pt}{post lead endpoint} \AssertAnchor{S}{axis-25}{-1cm}{0pt}{axis quarter} \AssertAnchor{S}{axis-50}{0pt}{0pt}{axis midpoint} \AssertAnchor{S}{axis-100}{2cm}{0pt}{axis end} \node[physics spring,spring length=2cm,pre length=0pt,post length=0pt, amplitude=1mm] (Short) {}; \AssertAnchor{Short}{start}{-1cm}{0pt}{spring length alias} \AssertAnchor{S}{coil-start}{-17mm}{0pt}{saved lead survives next node} \AssertAnchor{S}{north}{0pt}{2mm}{saved amplitude survives next node} \node[spring,minimum width=4cm,rotate=90] (Vertical) {}; \AssertAnchor{Vertical}{start}{0pt}{-2cm}{vertical start} \AssertAnchor{Vertical}{end}{0pt}{2cm}{vertical end} \node[spring,minimum width=4cm,rotate=30,anchor=start] (Tilt) at (0,0) {}; \AssertAnchor{Tilt}{start}{0pt}{0pt}{rotated anchored start} \AssertAnchor{Tilt}{end}{3.4641cm}{2cm}{rotated anchored end} \node[spring,minimum width=4cm,xscale=-1,yscale=2,transform shape] (Scaled) {}; \AssertAnchor{Scaled}{start}{2cm}{0pt}{mirrored start} \AssertAnchor{Scaled}{north}{0pt}{9pt}{scaled amplitude bound} \node (Contents) [node contents={},spring,spring length=2cm]; \AssertShape{Contents}{physicsspring}{node contents before spring dispatches} \draw[spring] (0,-1)--node[above] (Label) {$k$} (3,-1); \AssertShape{Label}{rectangle}{path label remains ordinary node} \path (0,0)--node[midway,spring,spring length=2cm] (Inline) {} (4,0); \AssertShape{Inline}{physicsspring}{inline spring node dispatches} \node (Outer) {\tikz{\draw[spring] (0,0)--node[above] (Nested) {$k$} (2,0);}}; \AssertShape{Nested}{rectangle}{nested spring path preserves label shape} \end{tikzpicture}} \setbox0=\hbox{\begin{tikzpicture} \tikzset{every spring/.style={spring length=5cm,amplitude=3mm}} \node[spring] (Hook) {}; \AssertAnchor{Hook}{end}{2.5cm}{0pt}{spring hook length} \node[spring,spring length=2cm,amplitude=1mm] (Override) {}; \AssertAnchor{Override}{end}{1cm}{0pt}{local length overrides hook} \AssertAnchor{Override}{north}{0pt}{1mm}{local amplitude overrides hook} \draw[physicsspring,pre length=0,post length=0] (0,0)--(3,0); \TYPE{PASS: path alias and zero leads compile after spring nodes} \draw[spring,pre length=3mm,post length=5mm,amplitude=2mm, segment length=4mm] (0,0)--(3,0) \pgfextra{ \pgfmathsetlength{\Actual}{\pgfkeysvalueof{/pgf/decoration/pre length}} \Difference=\dimexpr\Actual-3mm\relax \ifdim\Difference<0pt\Difference=-\Difference\fi \ifdim\Difference<0.03pt\TYPE{PASS: path pre lead stays independent}\else\TYPE{FAIL: path pre lead}\fi \pgfmathsetlength{\Actual}{\pgfkeysvalueof{/pgf/decoration/post length}} \Difference=\dimexpr\Actual-5mm\relax \ifdim\Difference<0pt\Difference=-\Difference\fi \ifdim\Difference<0.03pt\TYPE{PASS: path post lead stays independent}\else\TYPE{FAIL: path post lead}\fi }; \end{tikzpicture}} \setbox0=\hbox{\begin{tikzpicture} \node[spring] (Fresh) {}; \AssertAnchor{Fresh}{end}{1.5cm}{0pt}{spring hook remains scoped} \node[spring,minimum height=1cm,outer sep=2pt] (Box) {}; \AssertAnchor{Box}{north}{0pt}{\dimexpr5mm+2pt\relax}{reserved height and outer sep} \AssertAnchor{Box}{end}{1.5cm}{0pt}{attachment excludes outer sep} \end{tikzpicture}} \END \end{document}