Skip to content

Beautify direction calculation

Created by: apriljunge

Most of the symbols of trackschematic have the possibility to specify a direction. For turnouts it's done (simplified) like this:

\pgfmathsetmacro{\branchfactor}{-1}
\pgfmathsetmacro{\facefactor}{-1}

\path[fill=black] (0,0) -- ++($\facefactor*(0.4,0)$) -- ++($\branchfactor*(0,0.4)$) -- cycle;% turnout marker
\fill[\foreground] ($\facefactor*(0.075,0) + \branchfactor*(0,-0.1 )$) circle (0.05);% points indicator left
\fill[\foreground] ($\facefactor*(0.225,0) + \branchfactor*(0,-0.1 )$) circle (0.05);% points indicator left
\fill[\foreground] ($\facefactor*(0.015,0) + \branchfactor*(0, 0.15)$) circle (0.05);% points indicator right
\fill[\foreground] ($\facefactor*(0.115,0) + \branchfactor*(0, 0.25)$) circle (0.05);% points indicator right

My suggestion is to use scaling to have cleaner code. The implementation of above would look like this and have the exactly same output:

\pgfmathsetmacro{\branchfactor}{-1}
\pgfmathsetmacro{\facefactor}{-1}

\begin{scope}[xscale=\facefactor, yscale=\branchfactor]
    \path[fill=black] (0,0) -- ++(0.4,0) -- ++(0,0.4) -- cycle;% turnout marker
    \fill[\foreground] (0.075,-0.1) circle (0.05);% points indicator left
    \fill[\foreground] (0.225,-0.1 ) circle (0.05);% points indicator left
    \fill[\foreground] (0.015, 0.15) circle (0.05);% points indicator right
    \fill[\foreground] (0.115, 0.25) circle (0.05);% points indicator right
\end{scope}

What do you think?