def _scale(x, length):
    """Scale points in 'x', such that distance between max(x) and min(x) equals
    to 'length'.

    min(x) will be moved to 0.
    """
    max_x, min_x = max(x), min(x)
    s = (float(length - 1) /
         (max_x - min_x) if x and max_x - min_x != 0 else length)
    return [int((i - min_x) * s) for i in x]