def getRangeFromCenter(center, size, minLimit, maxLimit):
    """Get linear range from center given constraints

    Return (min,max) pair with given range within (minLimit, maxLimit)
    ideally centered at given center

    Args:
        cneter (int): desired center
        size (int): size of the output range
        minLimit (int): absolute minimum value of the output range
        maxLimit (int): absolute maximum value of the output range

    Returns:
        (int, int): start, end of the range
    """
    if (center - int(size/2)) <= minLimit:   # left edge limited
        val0 = minLimit
        val1 = min(val0 + size, maxLimit)
        # print('left', val0, val1, center, size)
    elif (center + int(size/2)) >= maxLimit: # right edge limited
        val1 = maxLimit
        val0 = max(val1 - size, minLimit)
        # print('right', val0, val1, center, size)
    else:                                   # unlimited
        val0 = center - int(size/2)
        val1 = min(val0 + size, maxLimit)
        # print('center', val0, val1, center, size)
    return (val0, val1)