def sort(polylines):
for n, c in enumerate(polylines):<EOL><INDENT>l = len(c)<EOL>if l > <NUM_LIT:2>:<EOL><INDENT>mid = c.mean(axis=<NUM_LIT:0>)<EOL>distV = (c - mid)<EOL>dists = norm(distV, axis=-<NUM_LIT:1>)<EOL>firstI = np.argmax(dists)<EOL>sign = np.sign(distV[firstI])<EOL>dd = np.logical_or(np.sign(distV[:, <NUM_LIT:0>]) != sign[<NUM_LIT:0>],<EOL>np.sign(distV[:, <NUM_LIT:1>]) != sign[<NUM_LIT:1>])<EOL>dists[~dd] = <NUM_LIT:0><EOL>lastI = np.argmax(dists)<EOL>ind = _sort(c, firstI, lastI)<EOL>c = c[ind]<EOL>polylines[n] = c<EOL><DEDENT><DEDENT>
sort points within polyline
p0-p1-p2...