def path_prune(path, collinear_fn):
    """
    prune the path, i.e. remove unnecessary waypoints that are collinear to each other
    """
    if len(path) <= 1:
        return path[:]
    new_path = [path[0]]
    line_start = path[0]
    line_end = path[1]
    for i in range(2, len(path)):
        next_end = path[i]
        if collinear_fn(line_start, line_end, next_end):
            line_end = next_end
        else:
            new_path.append(line_end)
            line_start = line_end
            line_end = next_end
    new_path.append(line_end)
    return new_path