a
    ¡˜ëja  ã                   @  s¤   U d dl mZ d dlmZ d dlmZmZmZmZm	Z	 G dd„ deƒZ
dd„ ZG dd	„ d	ƒZG d
d„ deƒZG dd„ deƒZG dd„ deƒZeeedœZded< dS )é    )Úannotations)ÚEnum)ÚAnyÚDictÚSequenceÚTupleÚUnionc                   @  s   e Zd ZdZdZdS )ÚOrientation)é   éÿÿÿÿ)r
   r
   N)Ú__name__Ú
__module__Ú__qualname__ÚSCREENÚ	CARTESIAN© r   r   úa/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/unstructured/documents/coordinates.pyr	      s   r	   c                 C  s0   d| |  d|  d | | d|  d  | S )zTConvert a coordinate into another system along an axis using a linear transformationr
   é   r   )Zold_tZ	old_t_maxZ	new_t_maxZt_orientationr   r   r   Úconvert_coordinate   s
    ÿýr   c                   @  s‚   e Zd ZU dZded< dddœdd„Zdd	œd
d„Zddddœdd„Zddddœdd„Zd ddddœdd„Z	d dddœdd„Z
dS )ÚCoordinateSystemz6A finite coordinate plane with given width and height.r	   ÚorientationzUnion[int, float]©ÚwidthÚheightc                 C  s   || _ || _d S )Nr   )Úselfr   r   r   r   r   Ú__init__   s    zCoordinateSystem.__init__Úobject)Úotherc                 C  sJ   t |tƒsdS t| jjƒt|jjƒkoH| j|jkoH| j|jkoH| j|jkS )NF)Ú
isinstancer   ÚstrÚ	__class__r   r   r   r   )r   r   r   r   r   Ú__eq__   s    

ÿ
þ
üzCoordinateSystem.__eq__zUnion[float, int]z+Tuple[Union[float, int], Union[float, int]])ÚxÚyÚreturnc                 C  s4   | j j\}}t|d| j|ƒ}t|d| j|ƒ}||fS )zDConvert to this coordinate system from a relative coordinate system.r
   ©r   Úvaluer   r   r   ©r   r"   r#   Zx_orientationZy_orientationZnew_xZnew_yr   r   r   Úconvert_from_relative'   s    z&CoordinateSystem.convert_from_relativec                 C  s4   | j j\}}t|| jd|ƒ}t|| jd|ƒ}||fS )zDConvert from this coordinate system to a relative coordinate system.r
   r%   r'   r   r   r   Úconvert_to_relative2   s    z$CoordinateSystem.convert_to_relative)Ú
new_systemr"   r#   r$   c                 C  s   |   ||¡\}}| ||¡S )zGConvert from this coordinate system to another given coordinate system.)r)   r(   )r   r*   r"   r#   Zrel_xZrel_yr   r   r   Ú!convert_coordinates_to_new_system=   s    z2CoordinateSystem.convert_coordinates_to_new_systemz5Sequence[Tuple[Union[float, int], Union[float, int]]]z7Tuple[Tuple[Union[float, int], Union[float, int]], ...])r*   Úcoordinatesr$   c                 C  s0   g }|D ]\}}|  | j|||d�¡ qt|ƒS )zLConvert (x, y) coordinates from current system to another coordinate system.)r*   r"   r#   )Úappendr+   Útuple)r   r*   r,   Znew_system_coordinatesr"   r#   r   r   r   Ú*convert_multiple_coordinates_to_new_systemG   s    ÿz;CoordinateSystem.convert_multiple_coordinates_to_new_systemN)r   r   r   Ú__doc__Ú__annotations__r   r!   r(   r)   r+   r/   r   r   r   r   r      s   


r   c                   @  s   e Zd ZdZejZdd„ ZdS )ÚRelativeCoordinateSystemzDRelative coordinate system where x and y are on a scale from 0 to 1.c                 C  s   d| _ d| _d S )Nr
   r   )r   r   r   r   r   Z   s    z!RelativeCoordinateSystem.__init__N)r   r   r   r0   r	   r   r   r   r   r   r   r   r2   U   s   r2   c                   @  s   e Zd ZdZejZdS )Ú
PixelSpacezbCoordinate system representing a pixel space, such as an image. The origin is at the top
    left.N)r   r   r   r0   r	   r   r   r   r   r   r   r3   _   s   r3   c                   @  s   e Zd ZdZejZdS )Ú
PointSpacezbCoordinate system representing a point space, such as a pdf. The origin is at the bottom
    left.N)r   r   r   r0   r	   r   r   r   r   r   r   r4   f   s   r4   )r3   r4   r   zDict[str, Any]ÚTYPE_TO_COORDINATE_SYSTEM_MAPN)Ú
__future__r   Úenumr   Útypingr   r   r   r   r   r	   r   r   r2   r3   r4   r5   r1   r   r   r   r   Ú<module>   s   A
ý