def corners_to_box(x0, y0, x1, y1):
    """convert two corners (x0, y0, x1, y1) to (x, y, width, height)"""
    x0, x1 = min(x0, x1), max(x0, x1)
    y0, y1 = min(y0, y1), max(y0, y1)
    return x0, y0, x1 - x0 + 1, y1 - y0 + 1