
    kh
              	       p   d dl mZmZmZmZmZmZmZ d dlZd dl	m
Z
 deeeeef   dej                  fdZdej                  deeeeef   fdZ	 dd	ej                  dej                  d
edej                  fdZdej                  dej                  defdZdej                  dej                  defdZy)    )ListUnionDictr   AnyOptionalTupleN)Imagecoordsreturnc                 R    | \  }}}}t        j                  ||g||g||g||gg      S )N)nparray)r
   x_1y_1x_2y_2s        W/var/www/teggl/fontify/venv/lib/python3.12/site-packages/layoutparser/elements/utils.pycvt_coordinates_to_pointsr      sB    Cc388#J#J#J#J		
     pointsc                     | d d df   j                         }| d d df   j                         }| d d df   j                         }| d d df   j                         }||||fS )Nr      )minmax)r   r   r   r   r   s        r   cvt_points_to_coordinatesr   "   si    
A,


C
A,


C
A,


C
A,


Cc3r   Mis_invc                 0   |rt         j                  j                  |       } t        j                  |t        j                  |j
                  d   df      g      j                  }t        j                  | |      }||d   z  j                  d d d df   }|S )Nr   r      )r   linalginvhstackonesshapeTmatmul)r   r   r   src_middst_middsts         r   perspective_transformationr+   *   s~     IIMM!ii&,,q/1)=!>?@BBGii7#GWR[ 
#
#ArrE
*CJr   verticepolygon_pointsc           
          || z
  }t        j                  ||ddd d f   d      }t        t        ||dd        D cg c])  \  }}t         j                  j                  ||g      dk\  + c}}      S c c}}w )Nr   r   )axis)r   appendallzipr!   det)r,   r-   r   edgese1e2s         r   vertice_in_polygonr7   9   sl     g%FIIffQqS!Vn15E3ueABi;PQR		r2h'1,QRRQs   .A4
xsysc                     dt        j                  t        j                  | t        j                  |d            t        j                  |t        j                  | d            z
        z  S )zCalculate the area of polygons using
    `Shoelace Formula <https://en.wikipedia.org/wiki/Shoelace_formula>`_.

    Args:
        xs (`np.ndarray`): The x coordinates of the points
        ys (`np.ndarray`): The y coordinates of the points
    g      ?r   )r   absdotroll)r8   r9   s     r   polygon_arear>   E   sG     r2772q>2RVVBA5OOPPPr   )F)typingr   r   r   r   r   r   numpyr   PILr	   floatndarrayr   r   boolr+   r7   r>    r   r   <module>rF      s    A @ @  
eE5%,F&G 
BJJ 
 bjj  U5%PU;U5V   7<	zz::/3ZZS

 SBJJ S4 SQRZZ QRZZ QE Qr   