def normalize_stop_positions(positions):
    """Normalize stop positions between 0 and 1.

    Return ``(first, last, positions)``.

    first: original position of the first position.
    last: original position of the last position.
    positions: list of positions between 0 and 1.

    """
    first, last = positions[0], positions[-1]
    total_length = last - first
    if total_length == 0:
        positions = [0] * len(positions)
    else:
        positions = [(pos - first) / total_length for pos in positions]
    return first, last, positions
Normalize stop positions between 0 and 1.

Return ``(first, last, positions)``.

first: original position of the first position.
last: original position of the last position.
positions: list of positions between 0 and 1.
weasyprint/images.py