def end_direction(w, side, n=16):
    a = 0
    b = min(n, len(w))
    if (side != 0):
        a = (- b)
        b = (- 1)
    dx = diff(w.x[a:b]).mean()
    dy = diff(w.y[a:b]).mean()
    return (dx, dy)
def end_direction(w, side, n=16):
    a = 0
    b = min(n, len(w))
    if (side != 0):
        a = (- b)
        b = (- 1)
    dx = diff(w.x[a:b]).mean()
    dy = diff(w.y[a:b]).mean()
    return (dx, dy)