def trunc(x, y, w, h):
    """Truncates x and y coordinates to live in the (0, 0) to (w, h)
    
    Args: 
        x: the x-coordinate of a point
        y: the y-coordinate of a point
        w: the width of the truncation box
        h: the height of the truncation box. 
    """
    return min(max(x, 0), w - 1), min(max(y, 0), h - 1)