This is a follow up question of two other questions. The first is Node at every vertex and the second one is this. My goal is to combine the two. In particular, I want to write something like
\draw[polyline] (0,0) -- (1,1) -- (2,0) -- (3,1);
And the result would be a polyline (polygon) such that each vertex will be marked with a circle and there will be an arrow at the middle of each segment. This is what I have so far:
\begin{tikzpicture}[
mnode/.style={circle,draw=black,fill=black,inner sep=0pt,minimum size=2pt},
node at every point/.style={%
decoration={%
show path construction,
lineto code={%
\coordinate (pos) at ($0.5*(\tikzinputsegmentlast)+0.5*(\tikzinputsegmentfirst)$);
\coordinate (direction) at ($(\tikzinputsegmentlast)-(\tikzinputsegmentfirst)$);
\gettikzxy{(direction)}{\dirx}{\diry}
\pgfmathsetmacro\rotationdir{atan(\diry/\dirx)}
\node at (pos) [rotate=\rotationdir] {>};
\node at (\tikzinputsegmentlast) [#1] {};
},
moveto code={\node at (\tikzinputsegmentfirst) [#1] {};},
curveto code={\node at (\tikzinputsegmentlast) [#1] {};}
},
postaction=decorate
}
]
\draw[node at every point=mnode] (0,0) -- (1,2) -- (2.3,0) -- (2.5,1);
\end{tikzpicture}
And this is the result:

This code exhibits two problems. First, the arrow looks bad, and secondly it cannot handle vertical segments. In the latter case, \dirx is zero and the code fails. I tried to hack it using \pgfmathifthenelse{x}{y}{z} of \ifthenelse but nothing worked for me...
How can I address the two problems?
