# Ignoring rotation in pgf decorations

Edit: I am interested in how this problem could or could not be solved using pgf decorations, not in how to draw this specific shape.

I am trying to use pgf line decorations to draw dotted lines, where the dots are squares, as in:

However pgf automatically rotates the environment in which the squares are drawn as in the following code:

\documentclass{article}
\usepackage{tikz}

\usetikzlibrary{calc,decorations}

\pgfdeclaredecoration{Squares}{initial}{
\state{initial}[width=10pt]{
\fill (0cm,0cm) rectangle (5pt,5pt);
}
\state{final}{
\pgfpathlineto{\pgfpointdecoratedpathlast}
}
}

\begin{document}
\begin{center}
\begin{tikzpicture}
\draw[decorate,decoration=Squares] (0,0) -- (5,5);
\end{tikzpicture}
\end{center}
\end{document}


which outputs this:

Is there a way to either compensate for the automatic rotation, or alternately disable it?

Rotate your \fill decoration command by the opposite of the rotation upon entering the decoration code (given by \pgfdecoratedangle):

\documentclass[tikz]{standalone}

\usetikzlibrary{calc,decorations}

\pgfdeclaredecoration{Squares}{initial}{
\state{initial}[width=10pt]{
\fill[rotate=-\pgfdecoratedangle] (0cm,0cm) rectangle (5pt,5pt);
}
\state{final}{
\pgfpathlineto{\pgfpointdecoratedpathlast}
}
}

\begin{document}
\begin{tikzpicture}
\draw[decorate,decoration=Squares] (0,0) -- (1,5);
\draw[decorate,decoration=Squares] (0,0) -- (5,5);
\draw[decorate,decoration=Squares] (0,0) to[out=0,in=-90] (5,5);
\draw[decorate,decoration=Squares] (0,0) -- (5,1);
\end{tikzpicture}
\end{document}