Decomposition of discrete curves into piecewise straight segments in linear time