Skip to content

Commit

Permalink
Merge pull request pgf-tikz#1163 from muzimuzhi/implicite-matrix
Browse files Browse the repository at this point in the history
fix: incorrectly placed matrix delimiters
  • Loading branch information
hmenke authored Jul 21, 2022
2 parents 5fac67f + e6f774d commit 28917fd
Show file tree
Hide file tree
Showing 5 changed files with 205 additions and 1 deletion.
1 change: 1 addition & 0 deletions doc/generic/pgf/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ lot of contributed changes. Thanks to everyone who volunteered their time!
- Make `graphdrawing` work with `name prefix` and `name suffix` options #1087
- pgfkeys was a bit too relaxed around `\relax` #1132
- Remove spurious spaces for `3d view` #1151
- Fix incorrectly placed matrix delimiters for implicitly positioned nodes #1102

### Changed

Expand Down
76 changes: 76 additions & 0 deletions testfiles/gh-issue-1102.lvt
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
\documentclass{minimal}
\input{pgf-regression-test}

\RequirePackage{tikz}
\usetikzlibrary{calc, matrix}

\begin{document}

\setbox0=\hbox{$()$} % avoid logging font info cmex10 at test for "matrix delimiters"

\START

\SEPARATOR
\TYPE{Testing that special nodes are placed at expected position^^J%
when main nodes are implicitly positioned.}
\SEPARATOR

\BEGINTEST{labels}
% adapted from https://github.com/pgf-tikz/pgf/issues/126
\begin{tikzpicture}[L/.style={label={[name=#1]above:{.}}}]
\draw (0,4) -- (3,4) node[midway, L=a] (A) {A};
\draw (0,3) -- node[L=b] (B) {B} (3,3);

\draw (0,2) -- (3,2) node[near end, L=c] (C) {C};
\draw (0,1) -- node[near end, L=d] (D) {D} (3,1);

% `label distance` is initially 0pt
\AssertTikzPointEquals{(a.south)}{(A.north)}
\AssertTikzPointEquals{(b.south)}{(B.north)}
\AssertTikzPointEquals{(c.south)}{(C.north)}
\AssertTikzPointEquals{(d.south)}{(D.north)}
\end{tikzpicture}
\ENDTEST

\BEGINTEST{pins}
\catcode`\@=11\relax
\def\distance{\tikz@pin@distance}
\catcode`\@=12\relax

\begin{tikzpicture}[P/.style={pin={[name=#1]above:{.}}}]
\draw (0,4) -- (3,4) node[midway, P=a] (A) {A};
\draw (0,3) -- node[P=b] (B) {B} (3,3);

\draw (0,2) -- (3,2) node[near end, P=c] (C) {C};
\draw (0,1) -- node[near end, P=d] (D) {D} (3,1);

\AssertTikzPointEquals{(a.south)}{($ (A.north) + (0pt,\distance) $)}
\AssertTikzPointEquals{(b.south)}{($ (B.north) + (0pt,\distance) $)}
\AssertTikzPointEquals{(c.south)}{($ (C.north) + (0pt,\distance) $)}
\AssertTikzPointEquals{(d.south)}{($ (D.north) + (0pt,\distance) $)}
\end{tikzpicture}
\ENDTEST

\BEGINTEST{matrix delimiters}
% adapted from https://github.com/pgf-tikz/pgf/issues/1102
\begin{tikzpicture}[ampersand replacement=\&,
every left delimiter/.style={name=left},
every right delimiter/.style={name=right},
every above delimiter/.style={name=above},
every below delimiter/.style={name=below}]

\draw[->] (0, 0) --
node[matrix of math nodes, anchor=north,
left delimiter=(, right delimiter=),
above delimiter=\{, below delimiter=\}] (M)
{0 \& -1 \\ 1 \& 0 \\}
(1, 0);

\AssertTikzPointEquals{(M.south west)}{(left.south east)}
\AssertTikzPointEquals{(M.south east)}{(right.south west)}
\AssertTikzPointEquals{(M.north west)}{(above.south east)}
\AssertTikzPointEquals{(M.south west)}{(below.south west)}
\end{tikzpicture}
\ENDTEST

\END
30 changes: 30 additions & 0 deletions testfiles/gh-issue-1102.tlg
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
This is a generated file for the l3build validation system.
Don't change this file in any respect.
============================================================
Testing that special nodes are placed at expected position
when main nodes are implicitly positioned.
============================================================
============================================================
TEST 1: labels
============================================================
PASSED
PASSED
PASSED
PASSED
============================================================
============================================================
TEST 2: pins
============================================================
PASSED
PASSED
PASSED
PASSED
============================================================
============================================================
TEST 3: matrix delimiters
============================================================
PASSED
PASSED
PASSED
PASSED
============================================================
97 changes: 97 additions & 0 deletions testfiles/support/pgf-regression-test.tex
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
\input regression-test.tex

\OMIT
\catcode`\@=11\relax

\newbox\PGFTESTBOX

Expand Down Expand Up @@ -38,4 +39,100 @@
\ENDTEST
}

% more typeout commands
\def\PASSED {\TYPE{PASSED}}
\def\FAILED {\TYPE{FAILED}}
\long\def\FAILEDAT#1{\TYPE{FAILED at #1}}

% more assert commands, which if fails will typeout more diagnostic info
\newif\ifassert@return
\newdimen\assert@equals@tolerance

% \AssertPointEquals[<tolerance>]{<point>}{<point>}
% [<tolerance>] omitted -> assert equiality within 0.001pt
% <point> ::= <tikz point> | <pgfqpoint>
\protected\long\def\AssertTikzPointEquals{%
\begingroup
\pgfutil@ifnextchar[%]
{\AssertTikzPointEquals@opt}
{\AssertTikzPointEquals@}%
}

\protected\long\def\AssertTikzPointEquals@opt[#1]#2#3{%
\edef\assert@input{%
\string\AssertTikzPointEquals\unexpanded{[#1]{#2}{#3}}}%
\AssertTikzPointEquals@@[{#1}]{#2}{#3}%
}

\protected\long\def\AssertTikzPointEquals@#1#2{%
\edef\assert@input{%
\string\AssertTikzPointEquals\unexpanded{{#1}{#2}}}%
\AssertTikzPointEquals@@[.001pt]{#1}{#2}%
}

\protected\long\def\AssertTikzPointEquals@@[#1]#2#3{%
\assert@equals@tolerance=\dimexpr#1\relax
\ifdim\assert@equals@tolerance<0pt
\TYPE{\string\AssertTikzPointEquals: negative tolerance \the\assert@equals@tolerance}%
\fi
\expandafter\TikzGetOnePoint\expandafter{#2}\assert@tempa
\expandafter\TikzGetOnePoint\expandafter{#3}\assert@tempb
\assert@returntrue
\ifx\assert@tempa\assert@tempb
\else
\assert@tempa\pgf@xa=\pgf@x\pgf@ya=\pgf@y
\assert@tempb%\pgf@xb=\pgf@x\pgf@yb=\pgf@y
%
\ifdim\pgf@x>\dimexpr\pgf@xa+\assert@equals@tolerance\relax
\else
\ifdim\pgf@x<\dimexpr\pgf@xa-\assert@equals@tolerance\relax
\assert@returnfalse
\else
\ifdim\pgf@y>\dimexpr\pgf@ya+\assert@equals@tolerance\relax
\assert@returnfalse
\else
\ifdim\pgf@y<\dimexpr\pgf@ya-\assert@equals@tolerance\relax
\assert@returnfalse
\fi
\fi
\fi
\fi
\fi
\ifassert@return
\PASSED
\else
\FAILEDAT{\assert@input}%
\TYPE{%
- Expected: \detokenize\expandafter{#2} => (\the\pgf@xa, \the\pgf@ya)^^J%
- Actual: \space\space\detokenize\expandafter{#3} => (\the\pgf@x, \the\pgf@y)^^J%
- Tolerance: \the\assert@equals@tolerance
}%
\fi
\endgroup
}

% pgf or tikz specific testing commands

% \TikzGetOnePoint{<point>}{<macro>}
% <point> ::= <tikz point> | <pgfqpoint>
\protected\long\def\TikzGetOnePoint#1#2{%
\pgfutil@ifnextchar\pgfqpoint
{\TikzGetOnePoint@{#2}}
{\def\assert@tempc{\TikzGetOnePoint@@{#2}}%
\tikz@scan@one@point\assert@tempc}%
#1%
}

% \TikzGetOnePoint@{<macro>}\pgfqpoint{<x>}{<y>}
\protected\long\def\TikzGetOnePoint@#1#2#3#4{%
\TikzGetOnePoint@@{#1}{\pgfqpoint{#3}{#4}}%
}

% \TikzGetOnePoint@@{<macro>}{<general pgfpoint>}
\protected\long\def\TikzGetOnePoint@@#1#2{%
\pgf@process{#2}%
\edef#1{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}%
}

\catcode`\@=12\relax
\TIMO
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@

\def\tikz@delimiter#1#2#3#4#5#6#7#8{%
\bgroup
\pgfextra{\let\tikz@save@last@fig@name=\tikz@last@fig@name}%
\pgfextra{\let\tikz@save@last@fig@name=\tikz@last@fig@name\tikz@node@is@a@labelfalse}%
node[outer sep=0pt,inner sep=0pt,draw=none,fill=none,anchor=#1,at=(\tikz@last@fig@name.#2),#3]
{%
{\nullfont\pgf@process{\pgfpointdiff{\pgfpointanchor{\tikz@last@fig@name}{#4}}{\pgfpointanchor{\tikz@last@fig@name}{#5}}}}%
Expand Down

0 comments on commit 28917fd

Please sign in to comment.