def length_along_path(pp, index):
    """ Get the lenth measured along the path up to the given index.
    """
    index = min(index, len(pp) - 1)  # beware of the end
    diff_squared = (pp[:index] - pp[1:index+1]) ** 2
    distances = diff_squared.sum(1)
    return (distances ** 0.5).sum()
    # == sum(pp[j].distance(pp[j+1]) for j in range(index))