def svg_rect_to_path(x, y, width, height, rx=None, ry=None):
    """Convert rect SVG element to path

    https://www.w3.org/TR/SVG/shapes.html#RectElement
    """
    if rx is None or ry is None:
        if rx is not None:
            rx, ry = rx, rx
        elif ry is not None:
            rx, ry = ry, ry
        else:
            rx, ry = 0, 0

    ops = []
    ops.append(f"M{x + rx:g},{y:g}")
    ops.append(f"H{x + width - rx:g}")
    if rx > 0 and ry > 0:
        ops.append(f"A{rx:g},{ry:g},0,0,1,{x + width:g},{y + ry:g}")
    ops.append(f"V{y + height - ry:g}")
    if rx > 0 and ry > 0:
        ops.append(f"A{rx:g},{ry:g},0,0,1,{x + width - rx:g},{y + height:g}")
    ops.append(f"H{x + rx:g}")
    if rx > 0 and ry > 0:
        ops.append(f"A{rx:g},{ry:g},0,0,1,{x:g},{y + height - ry:g}")
    ops.append(f"V{y + ry:g}")
    if rx > 0 and ry > 0:
        ops.append(f"A{rx:g},{ry:g},0,0,1,{x + rx:g},{y:g}")
    ops.append("z")
    return " ".join(ops)