
    Nga                        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e          Z
d Z G d d          Z G d	 d
e          Z G d de          Z G d de          ZeeedZded<   dS )    )annotations)Enum)AnyDictSequenceTupleUnionc                      e Zd ZdZdZdS )Orientation)   )r   r   N)__name__
__module____qualname__SCREEN	CARTESIAN     ^/var/www/html/ai-engine/env/lib/python3.11/site-packages/unstructured/documents/coordinates.pyr   r      s        FIIIr   r   c                H    d| |z  z
  d|z
  z  dz  | |z  d|z   z  dz  z   |z  S )zTConvert a coordinate into another system along an axis using a linear transformationr      r   )old_t	old_t_max	new_t_maxt_orientations       r   convert_coordinater      sI     
UY	1}#459
)
q=0
1A
5	6 r   c                  N    e Zd ZU dZded<   ddZdd
ZddZddZddZ	ddZ
dS )CoordinateSystemz6A finite coordinate plane with given width and height.r   orientationwidthUnion[int, float]heightc                "    || _         || _        d S )Nr    r"   )selfr    r"   s      r   __init__zCoordinateSystem.__init__   s    
r   otherobjectc                    t          |t                    sdS t          | j        j                  t          |j        j                  k    o/| j        |j        k    o| j        |j        k    o| j        |j        k    S )NF)
isinstancer   str	__class__r   r    r"   r   )r%   r'   s     r   __eq__zCoordinateSystem.__eq__   sx    %!122 	5'((C0H,I,II 6
ek)6u|+6  E$55		
r   xUnion[float, int]yreturn+Tuple[Union[float, int], Union[float, int]]c                    | 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.   r0   x_orientationy_orientationnew_xnew_ys          r   convert_from_relativez&CoordinateSystem.convert_from_relative'   sH     (,'7'=$}"1a]CC"1amDDe|r   c                    | j         j        \  }}t          || j        d|          }t          || j        d|          }||fS )zDConvert from this coordinate system to a relative coordinate system.r   r4   r6   s          r   convert_to_relativez$CoordinateSystem.convert_to_relative2   sH     (,'7'=$}"1dj!]CC"1dk1mDDe|r   
new_systemc                `    |                      ||          \  }}|                    ||          S )zGConvert from this coordinate system to another given coordinate system.)r=   r;   )r%   r>   r.   r0   rel_xrel_ys         r   !convert_coordinates_to_new_systemz2CoordinateSystem.convert_coordinates_to_new_system=   s3     //155u//u===r   coordinates5Sequence[Tuple[Union[float, int], Union[float, int]]]7Tuple[Tuple[Union[float, int], Union[float, int]], ...]c                    g }|D ]0\  }}|                     |                     |||                     1t          |          S )zLConvert (x, y) coordinates from current system to another coordinate system.)r>   r.   r0   )appendrB   tuple)r%   r>   rC   new_system_coordinatesr.   r0   s         r   *convert_multiple_coordinates_to_new_systemz;CoordinateSystem.convert_multiple_coordinates_to_new_systemG   se     "$ 	 	DAq"))66*PQUV6WW    +,,,r   N)r    r!   r"   r!   )r'   r(   )r.   r/   r0   r/   r1   r2   )r>   r   r.   r/   r0   r/   r1   r2   )r>   r   rC   rD   r1   rE   )r   r   r   __doc____annotations__r&   r-   r;   r=   rB   rJ   r   r   r   r   r      s         @@   
 
 
 
	 	 	 		 	 	 	> > > >- - - - - -r   r   c                  &    e Zd ZdZej        Zd ZdS )RelativeCoordinateSystemzDRelative coordinate system where x and y are on a scale from 0 to 1.c                "    d| _         d| _        d S )Nr   r$   )r%   s    r   r&   z!RelativeCoordinateSystem.__init__Z   s    
r   N)r   r   r   rK   r   r   r   r&   r   r   r   rN   rN   U   s1        NN'K    r   rN   c                       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   rK   r   r   r   r   r   r   rQ   rQ   _   s"          $KKKr   rQ   c                       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   rK   r   r   r   r   r   r   rS   rS   f   s"          'KKKr   rS   )rQ   rS   r   zDict[str, Any]TYPE_TO_COORDINATE_SYSTEM_MAPN)
__future__r   enumr   typingr   r   r   r   r	   r   r   r   rN   rQ   rS   rT   rL   r   r   r   <module>rX      so   " " " " " " "       4 4 4 4 4 4 4 4 4 4 4 4 4 4    $   
  >- >- >- >- >- >- >- >-B    /   % % % % %! % % %( ( ( ( (! ( ( ( (1 1       r   