I am trying to debug a problem with an issue on circuitikz
that I have been able to reduce to this MWE --- sorry if it's not so short...
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\makeatletter
\pgfdeclareshape{sline}{
\anchor{center}{
\pgfpointorigin
}
\anchor{left}{\pgf@x=-0.5cm\pgf@y=0pt}
\anchor{right}{\pgf@x=0.5cm\pgf@y=0pt}
\backgroundpath{
\pgfscope
\pgfsetcolor{red}
\pgfpathmoveto{\pgfpoint{-0.5cm}{0pt}}
\pgfpathlineto{\pgfpoint{0.5cm}{0pt}}
\pgfusepath{draw}
\endpgfscope
}
}
\def\goforpaths{
\pgfextra{
\pgfmathanglebetweenpoints{\tikztostart}{\tikztotarget}
\edef\mydirection{\pgfmathresult}%Calculate direction(angle) of path
}
($(\tikztostart)!0.5!(\tikztotarget)$) node[sline, rotate=\mydirection](N){}
(\tikztostart) -- (N.left) (N.right) -- (\tikztotarget)
\tikztonodes
}
\tikzset{slineto/.style={/tikz/to path=\goforpaths}}
\makeatother
\begin{document}
\begin{tikzpicture}[
scale=1.2,
% scale=2
]
\draw (24,-1) to[slineto] ++(0,2);
\end{tikzpicture}
\end{document}
The MWE mimics what circuitikz
is doing to place components along paths; in this case, the component is a simple red line.
Now, when the scale factor is not an integer I have this very strange behavior in the joins:
(Notice that I tested with different PDF viewers).
For integer scale factors or no scale, the result is perfect:
(this is the same snippet with scale=2
). Also, if you change the 24
in the coordinate to 0
, the problem almost disappears.
I suppose this is some kind of accumulated error on calculations of coordinates --- but it's quite strange, so the probability that I am doing something wrong is very high. Can anyone spot where my error is?
circuitikz
tag because this specific question does not involve it. Thanks anyway!24
, this leads to the problem.\pgfmathreciprocal@
....0
instead of24
, the result is perfect. I you use240
instead of24
, the result is perfectly bad! Don't usescale
!!! (Ok, it's not a solution...)