
    :Qga                        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<   y)    )annotations)Enum)AnyDictSequenceTupleUnionc                      e Zd ZdZdZy)Orientation)   )r   r   N)__name__
__module____qualname__SCREEN	CARTESIAN     _/var/www/html/answerous/venv/lib/python3.12/site-packages/unstructured/documents/coordinates.pyr   r      s    FIr   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                      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
y
)CoordinateSystemz6A finite coordinate plane with given width and height.r   orientationc                     || _         || _        y )Nwidthheight)selfr"   r#   s      r   __init__zCoordinateSystem.__init__   s    
r   c                D   t        |t              syt        | j                  j                        t        |j                  j                        k(  xrO | j
                  |j
                  k(  xr4 | j                  |j                  k(  xr | j                  |j                  k(  S )NF)
isinstancer   str	__class__r   r"   r#   r   )r$   others     r   __eq__zCoordinateSystem.__eq__   s    %!12''(C0H0H,II 6

ekk)6u||+6   E$5$55		
r   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$   xyx_orientationy_orientationnew_xnew_ys          r   convert_from_relativez&CoordinateSystem.convert_from_relative'   sL     (,'7'7'='=$}"1a]C"1am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   r-   r/   s          r   convert_to_relativez$CoordinateSystem.convert_to_relative2   sL     (,'7'7'='=$}"1djj!]C"1dkk1mDe|r   c                P    | j                  ||      \  }}|j                  ||      S )zGConvert from this coordinate system to another given coordinate system.)r8   r6   )r$   
new_systemr0   r1   rel_xrel_ys         r   !convert_coordinates_to_new_systemz2CoordinateSystem.convert_coordinates_to_new_system=   s-     //15u//u==r   c                v    g }|D ](  \  }}|j                  | j                  |||             * t        |      S )zLConvert (x, y) coordinates from current system to another coordinate system.)r:   r0   r1   )appendr=   tuple)r$   r:   coordinatesnew_system_coordinatesr0   r1   s         r   *convert_multiple_coordinates_to_new_systemz;CoordinateSystem.convert_multiple_coordinates_to_new_systemG   sP     "$ 	DAq"))66*PQUV6W	 +,,r   N)r"   Union[int, float]r#   rD   )r*   object)r0   Union[float, int]r1   rF   return+Tuple[Union[float, int], Union[float, int]])r:   r   r0   rF   r1   rF   rG   rH   )r:   r   rA   z5Sequence[Tuple[Union[float, int], Union[float, int]]]rG   z7Tuple[Tuple[Union[float, int], Union[float, int]], ...])r   r   r   __doc____annotations__r%   r+   r6   r8   r=   rC   r   r   r   r   r      s    @
		 	 
5				 	 
5		>$> > 	>
 
5>-$- K- 
A	-r   r   c                  .    e Zd ZdZej
                  Zd Zy)RelativeCoordinateSystemzDRelative coordinate system where x and y are on a scale from 0 to 1.c                     d| _         d| _        y )Nr   r!   )r$   s    r   r%   z!RelativeCoordinateSystem.__init__Z   s    
r   N)r   r   r   rI   r   r   r   r%   r   r   r   rL   rL   U   s    N''Kr   rL   c                  (    e Zd ZdZej
                  Zy)
PixelSpacezbCoordinate system representing a pixel space, such as an image. The origin is at the top
    left.N)r   r   r   rI   r   r   r   r   r   r   rO   rO   _   s     $$Kr   rO   c                  (    e Zd ZdZej
                  Zy)
PointSpacezbCoordinate system representing a point space, such as a pdf. The origin is at the bottom
    left.N)r   r   r   rI   r   r   r   r   r   r   rQ   rQ   f   s     ''Kr   rQ   )rO   rQ   r   zDict[str, Any]TYPE_TO_COORDINATE_SYSTEM_MAPN)
__future__r   enumr   typingr   r   r   r   r	   r   r   r   rL   rO   rQ   rR   rJ   r   r   r   <module>rV      sn    "  4 4$ 
>- >-B/ %! %(! ( (1 ~ r   