TikZ dash pattern vs. closed paths

A solution which tries to duplicate the closed path to such that the end is just an ordinary point in the middle: (Inspired by Qrrbrbirlbel's use path TikZ key)

\documentclass[tikz,border=3.14mm]{standalone}
\makeatletter
% This assumes that every closed path starts and ends with these tokens.
% That would make sense, but I do not know if it is true
\def\helpdoublepath\pgfsyssoftpath@movetotoken#1#2#3\pgfsyssoftpath@closepathtoken#4#5{%
  \unexpanded{\pgfsyssoftpath@movetotoken{#1}{#2}#3\pgfsyssoftpath@linetotoken{#1}{#2}#3\pgfsyssoftpath@closepathtoken{#4}{#5}}%
}
\def\doublepath#1{%
  \edef#1{\expandafter\helpdoublepath#1}%
}
\tikzset{double path/.code=\tikz@addmode{\pgfsyssoftpath@getcurrentpath\temp\doublepath\temp\pgfsyssoftpath@setcurrentpath\temp}}
\makeatother
\begin{document}
 \begin{tikzpicture}
   \draw[double path,dash pattern=on 5cm off 100cm,blue,ultra thick]
   (0,0) -- (1,0) -- (1,1) -- (0,1) -- cycle;
  \begin{scope}[xshift=2cm]
  \draw[blue,ultra thick]
   (0,0) -- (1,0) -- (1,1) -- (0,1) -- cycle;
  \end{scope}
 \end{tikzpicture} 
\end{document}

enter image description here


It's been a while since I wrote a PDF interpreter, but I believe you need to specify the line cap:

  \draw[line cap = rect, dash pattern=on 5cm off 16cm,blue,ultra thick]

enter image description here

Tags:

Draw

Tikz Pgf