def __init__(self, rel_x, rel_y, w=1, h=1, main_point_offset=None,
                 parent=None, image=None):
        """rel_x, rel_y, w, h are all cast to integers as its assumed we are
        dealing with whole pixels.
        """
        rel_x, rel_y, w, h = int(rel_x), int(rel_y), int(w), int(h)

        if rel_x < 0:
            raise ValueError('rel_x must be >= 0')
        if rel_y < 0:
            raise ValueError('rel_y must be >= 0')
        if w < 1:
            raise ValueError('w must be >= 1')
        if h < 1:
            raise ValueError('h must be >= 1')
        if parent is not None and rel_x + w > parent.w:
            raise ValueError('rel_x + w must be <= parent.w or parent must be None')
        if parent is not None and rel_y + h > parent.h:
            raise ValueError('rel_y + h must be <= parent.h or parent must be None')

        self._rel_x, self._rel_y, self._w, self._h = (
            int(rel_x),
            int(rel_y),
            int(w),
            int(h)
        )

        if main_point_offset is None:
            self._main_point_offset = (w // 2, h // 2)
        else:
            self._main_point_offset = tuple(int(i) for i in main_point_offset)
        self._parent = parent
        if image is not None:
            ih, iw = image.shape[:2]
            if ih != h or iw != w:
                raise AssertionError('image width and height should be the '
                                     'same as the locations')
        self._image = image
def __init__ ( self , rel_x , rel_y , w = 1 , h = 1 , main_point_offset = None , parent = None , image = None ) : rel_x , rel_y , w , h = int ( rel_x ) , int ( rel_y ) , int ( w ) , int ( h ) if rel_x < 0 : raise ValueError ( 'rel_x must be >= 0' ) if rel_y < 0 : raise ValueError ( 'rel_y must be >= 0' ) if w < 1 : raise ValueError ( 'w must be >= 1' ) if h < 1 : raise ValueError ( 'h must be >= 1' ) if parent is not None and rel_x + w > parent . w : raise ValueError ( 'rel_x + w must be <= parent.w or parent must be None' ) if parent is not None and rel_y + h > parent . h : raise ValueError ( 'rel_y + h must be <= parent.h or parent must be None' ) self . _rel_x , self . _rel_y , self . _w , self . _h = ( int ( rel_x ) , int ( rel_y ) , int ( w ) , int ( h ) ) if main_point_offset is None : self . _main_point_offset = ( w // 2 , h // 2 ) else : self . _main_point_offset = tuple ( int ( i ) for i in main_point_offset ) self . _parent = parent if image is not None : ih , iw = image . shape [ : 2 ] if ih != h or iw != w : raise AssertionError ( 'image width and height should be the ' 'same as the locations' ) self . _image = image
rel_x, rel_y, w, h are all cast to integers as its assumed we are
        dealing with whole pixels.