Look at next code, when I want to draw a grid from right to left or top to bottom, vertical or horizontal lines are not drawn, even with xstep=-1
or ystep=-1
(as it's suggested in Jake's answer in Grid missing horizontal lines).
What am I missing? I'm using TikZ's CVS version.
\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\newcommand{\arrow}[2]{\draw[->,blue,thick,shorten <=5mm, shorten >=5mm] #1 -- #2 ;}
\begin{document}
\begin{tikzpicture}
\draw[help lines] (-2,-2) grid (2,2);
\draw[red,fill] (0,0) circle (1mm) node[below right] {(0,0)};
\node[anchor=south,align=center] at (0,2){(-2,-2) to (2,2)};
\arrow{(-2,-2)}{(2,2)}
\end{tikzpicture}
\begin{tikzpicture}
\draw[help lines] (-2,2) grid[ystep=-1] (2,-2);
\arrow{(-2,2)}{(2,-2)}
\draw[red,fill] (0,0) circle (1mm) node[above right] {(0,0)};
\node[anchor=south,align=center] at (0,2){(-2,2) to (2,-2)};
\end{tikzpicture}
\begin{tikzpicture}
\draw[help lines] (2,-2) grid[xstep=-1] (-2,2);
\arrow{(2,-2)}{(-2,2)}
\draw[red,fill] (0,0) circle (1mm) node[above right] {(0,0)};
\node[anchor=south,align=center] at (0,2){(2,-2) to (-2,2)};
\end{tikzpicture}
\begin{tikzpicture}
\draw[help lines] (2,2) grid[xstep=-1,ystep=-1] (-2,-2);
\arrow{(2,2)}{(-2,-2)}
\draw[red,fill] (0,0) circle (1mm) node[below right] {(0,0)};
\node[anchor=south,align=center] at (0,2){(2,2) to (-2,-2)};
\end{tikzpicture}
\end{document}
Best Answer
If I'm not mistaken somewhere, I've patched the
\pgfpathgrid
command found inpgfcorepathconstruct.code.tex
file. But please let me know if it fails in any other cases that I might have skipped.With this you don't need to use negative step sizes since it will increment accordingly.
In a nutshell, I've checked if the start point is larger than the finish point and then multiply a few inequalities with
-1
with\c@pgf@counta
being the conditional variable.