def width_and_height_to_path(width, height, radii=None):

    width = float(width)
    height = float(height)

    # The calculation to obtain the 'k' coefficient can be found here:
    # http://itc.ktu.lt/itc354/Riskus354.pdf
    # "APPROXIMATION OF A CUBIC BEZIER CURVE BY CIRCULAR ARCS AND VICE VERSA"
    # by Aleksas Riskus
    k = 0.5522847498

    all_zeros = True

    if radii is not None:
        # check if all values are equal to '0'
        for value in radii.values():
            if value != 0:
                all_zeros = False

        if all_zeros is True:
            path = "m %f,%f h %f v %f h %f v %f z" % (-width/2, -height/2, 
                                                      width, height, 
                                                      -width, -height)
        else:

            top_left = float(radii.get('tl') or radii.get('top_left') or 0)
            top_right = float(radii.get('tr') or radii.get('top_right') or 0)
            bot_right = float(radii.get('br') or radii.get('bot_right') or radii.get('bottom_right') or 0)
            bot_left = float(radii.get('bl') or radii.get('bot_left') or radii.get('bottom_left') or 0)

            path = "m %f,%f " % (-width/2, 0)
            if top_left == 0:
                path += "v %f h %f " % (-height/2, width/2)
            else:
                r = top_left
                path += "v %f c %f,%f %f,%f %f,%f h %f " % (-(height/2-r), 0,-k*r, -r*(k-1),-r, r,-r, width/2-r) 

            if top_right == 0:
                path += "h %f v %f " % (width/2, height/2)
            else:
                r = top_right
                path += "h %f c %f,%f %f,%f %f,%f v %f " % (width/2-r, k*r,0, r,-r*(k-1), r,r, height/2-r) 

            if bot_right == 0:
                path += "v %f h %f " % (height/2, -width/2)
            else:
                r = bot_right
                path += "v %f c %f,%f %f,%f %f,%f h %f " % (height/2-r, 0,k*r, r*(k-1),r, -r,r, -(width/2-r)) 

            if bot_left == 0:
                path += "h %f v %f " % (-width/2, -height/2)
            else:
                r = bot_left
                path += "h %f c %f,%f %f,%f %f,%f v %f " % (-(width/2-r), -k*r,0, -r,r*(k-1), -r,-r, -(height/2-r)) 
            
            path += "z"

    else:
        path = "m %f,%f h %f v %f h %f v %f z" % (-width/2, -height/2, 
                                                   width, height, 
                                                   -width, -height)        

    return path
Returns a centered path based on width and height; smooth corners
dataset/ETHPy150Open boldport/pcbmode/pcbmode/utils/svg.py/width_and_height_to_path