-
Notifications
You must be signed in to change notification settings - Fork 110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sloped
should consider the current transformation
#1058
Comments
The current PGF code ensures that the "external" transformation is only applied when A little improvement to your answer on TeX-SX (the added transformation calculations are now surrounded by \documentclass{article}
\usepackage{tikz}
\makeatletter
\def\pgftransformlineattime#1#2#3{%
\pgfgettransformentries\pgf@tempaa\pgf@tempab\pgf@tempba\pgf@tempbb\pgf@notimportantx\pgf@notimportanty%%% ⬅️⬅️⬅️ new
\pgf@process{#2}%
\pgf@xb=\pgf@x% xb/yb = start point
\pgf@yb=\pgf@y%
\pgf@process{#3}%
\pgf@xc=\pgf@x% xc/yc = end point
\pgf@yc=\pgf@y%
\pgftransformshift{\pgfpointlineattime{#1}{\pgfqpoint{\pgf@xb}{\pgf@yb}}{\pgfqpoint{\pgf@xc}{\pgf@yc}}}%
\ifpgfresetnontranslationattime%
\pgftransformresetnontranslations%
\fi%
\ifpgfslopedattime%
\advance\pgf@xc by-\pgf@xb%
\advance\pgf@yc by-\pgf@yb%
% Now that we get the tangent vector without transformation
% It suffices to apply the non-shift part of the transformation
{%%% ⬇️⬇️⬇️ new
\ifpgfresetnontranslationattime
\pgfsettransformentries\pgf@tempaa\pgf@tempab\pgf@tempba\pgf@tempbb{0pt}{0pt}%
\pgf@pos@transform{\pgf@xc}{\pgf@yc}%
\global\pgf@xc\pgf@xc
\global\pgf@yc\pgf@yc
\fi
}%%% ⬆️⬆️⬆️ new
% OK, now xc and yc are correctly tangent to the line
% Continue the usual routine
\ifpgfallowupsidedownattime%
\else%
\ifdim\pgf@xc<0pt%
\pgf@xc=-\pgf@xc%
\pgf@yc=-\pgf@yc%
\fi%
\fi%
\pgf@x=\pgf@xc%
\pgf@y=\pgf@yc%
\pgfpointnormalised{}% x/y = normalised vector
\pgf@ya=-\pgf@y%
\pgftransformcm%
{\pgf@sys@tonumber{\pgf@x}}{\pgf@sys@tonumber{\pgf@y}}%
{\pgf@sys@tonumber{\pgf@ya}}{\pgf@sys@tonumber{\pgf@x}}{\pgfpointorigin}%
\fi%
}
\makeatother
\begin{document}
\begin{tikzpicture}[xscale=2, yscale=3, xshift=40, yshift=50, nodes={above}]
\draw (0, 0) -- node[sloped]
{\texttt{sloped} only} +(2, 2);
\draw (2, 0) -- node[transform shape]
{\texttt{transform shape} only} +(2, 2);
\draw (4, 0) -- node[sloped, transform shape]
{\texttt{sloped} and \texttt{transform shape}} +(2, 2);
\end{tikzpicture}%
\end{document} |
I agree that (E.g., your code above seems to assume that the node is attached, tangentially, |
@muzimuzhi PR please. |
Brief outline of the proposed feature
Inspired by this SX question and this older one,
I would like to suggest that we should consider the current transformation
when computing the slope of the
sloped
nodes.Usage example
The following code
produces a line and a node that do not align.
This is because in the definition of
\pgftransformlineattime
,the slope is calculated using the start and end coordinates
without applying the current transformation.
(For instance, in the above example, the diff vector will be (1cm, 1cm), not (2cm, 3cm).)
If we take that into account, a proper slope can be computed.
See my answer for one possible fix.
The text was updated successfully, but these errors were encountered: