pgf-tikz / pgf

A Portable Graphic Format for TeX
https://pgf-tikz.github.io/
1.14k stars 108 forks source link

Nodes and magnified paths created with spy library not adhering to scoped transformations such as shift #1250

Open jasperhabicht opened 1 year ago

jasperhabicht commented 1 year ago

Brief outline of the bug

I noticed that nodes and/or magnifications created with the \spy macro provided by the spy library do not adhere to scoped transformations. If the transformations are defined explicitly the coordinates in the \spy macro, the transformation is applied correctly.

(PGF Version: 2021/05/15 v3.1.9a)

Minimal working example (MWE)

First MWE (shifted scope within spy scope):

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{spy}

\begin{document}
\begin{tikzpicture}[spy using outlines={magnification=4, size=1cm, connect spies}]

\draw[green] (0:0) circle[radius=1];

\spy[black!25] on (30:1)
    in node at (0,0);

\begin{scope}[shift={(2.5cm,0)}]

\draw[green] (0:0) circle[radius=1];

\spy[red, circle] on (30:1)
    in node at (0,0);

\end{scope}

\end{tikzpicture}
\end{document}

image

Obviously, spy nodes and magnified paths are not affected by scoped transformation.


Second MWE (spy scope only applied to scopes):

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{spy}

\begin{document}
\begin{tikzpicture}

\begin{scope}[spy using outlines={magnification=4, size=1cm, connect spies}]

\draw[green] (0:0) circle[radius=1];

\spy[black!25] on (30:1)
    in node at (0,0);

\end{scope}

\begin{scope}[spy using outlines={magnification=4, size=1cm, connect spies}, shift={(2.5cm,0)}]

\draw[green] (0:0) circle[radius=1];

\spy[red, circle] on (30:1)
    in node at (0,0);

\end{scope}

\end{tikzpicture}
\end{document}

image


Third, working MWE (explicit transformation to coordinates) and expected result of the two MWEs above:

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{spy}

\begin{document}
\begin{tikzpicture}[spy using outlines={magnification=4, size=1cm, connect spies}]

\draw[green] (0:0) circle[radius=1];

\spy[black!25] on (30:1)
    in node at (0,0);

\draw[green] ([shift={(2.5cm,0)}]0:0) circle[radius=1];

\spy[red, circle] on ([shift={(2.5cm,0)}]30:1)
    in node at ([shift={(2.5cm,0)}]0,0);

\end{tikzpicture}
\end{document}

image

hmenke commented 1 year ago

This is probably a variation of https://github.com/pgf-tikz/pgf/issues/334