
    kh%                     d    d dl mZmZmZmZ d dlmZmZ d dlmZ  G d d      Z G d dee      Z	y)	    )ListDictr   Any)ABCabstractmethod)copyc                        e Zd ZddZd Zd Zy)BaseLayoutElementc                     |r| n
t        |       }t        |      }|j                         D ],  \  }}||v r|||<   d| |v r	||d| <    t        d|        |S )N_zUnknown attribute name: )r   varsitems
ValueError)selfinplacekwargsobjvar_dictkeyvals          V/var/www/teggl/fontify/venv/lib/python3.12/site-packages/layoutparser/elements/base.pysetzBaseLayoutElement.set   s{    d4:9 	CHCh #SEh&&)1SE# #;C5!ABB	C 
    c           	          dj                  t        |       j                         D cg c]  \  }}| d|  c}}      }| j                  j                   d| dS c c}}w )Nz, =())joinr   r   	__class____name__)r   r   r   info_strs       r   __repr__zBaseLayoutElement.__repr__"   sZ    99T$Z=M=M=OPcQsenPQ..))*!H:Q77 Qs   A
c                 b    |j                   | j                   uryt        |       t        |      k(  S )NF)r   r   r   others     r   __eq__zBaseLayoutElement.__eq__'   s(    ??$..0DzT%[((r   N)F)r    
__module____qualname__r   r"   r&    r   r   r
   r
      s    8
)r   r
   c                      e Zd Zeedefd              Zeedee   fd              Zeed               Z	eed               Z
eed               Zeed               Zeed               Zed	        Zed
        Zei dfd       Zeddd defd       Zeddd defd       Zedd       Zedd       Zedd       Zed        Zdeeef   fdZedeeef   dd fd       Zy)BaseCoordElementreturnc                      y)zThe name of the classNr)   r   s    r   _namezBaseCoordElement._name0        	r   c                      y)z?A list of features names used for initializing the class objectNr)   r.   s    r   	_featureszBaseCoordElement._features6   r0   r   c                      y Nr)   r.   s    r   widthzBaseCoordElement.width@        	r   c                      y r4   r)   r.   s    r   heightzBaseCoordElement.heightE   r6   r   c                      y r4   r)   r.   s    r   coordinateszBaseCoordElement.coordinatesJ   r6   r   c                      y r4   r)   r.   s    r   pointszBaseCoordElement.pointsO   r6   r   c                      y r4   r)   r.   s    r   areazBaseCoordElement.areaT   r6   r   c                      y)aY  
        Given the current element in relative coordinates to another element which is in absolute coordinates,
        generate a new element of the current element in absolute coordinates.

        Args:
            other (:obj:`BaseCoordElement`):
                The other layout element involved in the geometric operations.

        Raises:
            Exception: Raise error when the input type of the other element is invalid.

        Returns:
            :obj:`BaseCoordElement`:
                The BaseCoordElement object of the original element in the absolute coordinate system.
        Nr)   r$   s     r   condition_onzBaseCoordElement.condition_on]       $ 	r   c                      y)aC  
        Given the current element and another element both in absolute coordinates,
        generate a new element of the current element in relative coordinates to the other element.

        Args:
            other (:obj:`BaseCoordElement`): The other layout element involved in the geometric operations.

        Raises:
            Exception: Raise error when the input type of the other element is invalid.

        Returns:
            :obj:`BaseCoordElement`:
                The BaseCoordElement object of the original element in the relative coordinate system.
        Nr)   r$   s     r   relative_tozBaseCoordElement.relative_toq       " 	r   Fc                      y)a  
        Identify whether the current element is within another element.

        Args:
            other (:obj:`BaseCoordElement`):
                The other layout element involved in the geometric operations.
            soft_margin (:obj:`dict`, `optional`, defaults to `{}`):
                Enlarge the other element with wider margins to relax the restrictions.
            center (:obj:`bool`, `optional`, defaults to `False`):
                The toggle to determine whether the center (instead of the four corners)
                of the current element is in the other element.

        Returns:
            :obj:`bool`: Returns `True` if the current element is in the other element and `False` if not.
        Nr)   )r   r%   soft_margincenters       r   is_inzBaseCoordElement.is_in   rA   r   r%   strictc                      y)zIntersect the current shape with the other object, with operations defined in
        :doc:`../notes/shape_operations`.
        Nr)   r   r%   rI   s      r   	intersectzBaseCoordElement.intersect       r   c                      y)z|Union the current shape with the other object, with operations defined in
        :doc:`../notes/shape_operations`.
        Nr)   rK   s      r   unionzBaseCoordElement.union   rM   r   c                      y)a  Pad the layout element on the four sides of the polygon with the user-defined pixels. If
        safe_mode is set to True, the function will cut off the excess padding that falls on the negative
        side of the coordinates.

        Args:
            left (:obj:`int`, `optional`, defaults to 0): The number of pixels to pad on the upper side of the polygon.
            right (:obj:`int`, `optional`, defaults to 0): The number of pixels to pad on the lower side of the polygon.
            top (:obj:`int`, `optional`, defaults to 0): The number of pixels to pad on the left side of the polygon.
            bottom (:obj:`int`, `optional`, defaults to 0): The number of pixels to pad on the right side of the polygon.
            safe_mode (:obj:`bool`, `optional`, defaults to True): A bool value to toggle the safe_mode.

        Returns:
            :obj:`BaseCoordElement`: The padded BaseCoordElement object.
        Nr)   )r   leftrighttopbottom	safe_modes         r   padzBaseCoordElement.pad   rD   r   c                      y)a  
        Shift the layout element by user specified amounts on x and y axis respectively. If shift_distance is one
        numeric value, the element will by shifted by the same specified amount on both x and y axis.

        Args:
            shift_distance (:obj:`numeric` or :obj:`Tuple(numeric)` or :obj:`List[numeric]`):
                The number of pixels used to shift the element.

        Returns:
            :obj:`BaseCoordElement`: The shifted BaseCoordElement of the same shape-specific class.
        Nr)   )r   shift_distances     r   shiftzBaseCoordElement.shift   s     	r   c                      y)a  
        Scale the layout element by a user specified amount on x and y axis respectively. If scale_factor is one
        numeric value, the element will by scaled by the same specified amount on both x and y axis.

        Args:
            scale_factor (:obj:`numeric` or :obj:`Tuple(numeric)` or :obj:`List[numeric]`): The amount for downscaling or upscaling the element.

        Returns:
            :obj:`BaseCoordElement`: The scaled BaseCoordElement of the same shape-specific class.
        Nr)   )r   scale_factors     r   scalezBaseCoordElement.scale   s     	r   c                      y)z
        Crop the input image according to the coordinates of the element.

        Args:
            image (:obj:`Numpy array`): The array of the input image.

        Returns:
            :obj:`Numpy array`: The array of the cropped image.
        Nr)   )r   images     r   
crop_imagezBaseCoordElement.crop_image   s     	r   c                     | j                   D ci c]  }t        | |      |t        | |       }}| j                  |d<   |S c c}w )z
        Generate a dictionary representation of the current object:
            {
                "block_type": <"interval", "rectangle", "quadrilateral"> ,
                "non_empty_block_attr1": value1,
                ...
            }
        
block_type)r2   getattrr/   )r   r   datas      r   to_dictzBaseCoordElement.to_dict   sX     ~~
tS!- s##
 

 "ZZ\
s    Arc   c           
          | j                   |d   k(  sJ d|d            | di | j                  D ci c]  }|||   
 c}S c c}w )zInitialize an instance based on the dictionary representation

        Args:
            data (:obj:`dict`): The dictionary representation of the object
        ra   zIncompatible block types r)   )r/   r2   )clsrc   fs      r   	from_dictzBaseCoordElement.from_dict  s\     IIl++	<&tL'9&:;	<+ 9#--8Qaaj8998s   AN)T)r   r   r   r   T)r   )   )r    r'   r(   propertyr   strr/   r   r2   r5   r8   r:   r<   r>   r@   rC   rH   boolrL   rO   rV   rY   r\   r_   r   r   rd   classmethodrh   r)   r   r   r+   r+   /   s   s    49                    &  $ ')%  . 1 4  
 - t    $    $  "c3h $ :T#s(^ :0B : :r   r+   N)
typingr   r   r   abcr   r   r   r
   r+   r)   r   r   <module>rp      s.    ) ( # ) )8c:s- c:r   