o
    i#                     @  s@  d dl mZ d dlmZmZ d dlmZ d dlZd dl	m
Z
mZmZ d dlmZmZmZmZmZmZ er:d dlmZ dFddZdGddZdHddZdIddZdJddZdKddZdLd#d$ZdMd'd(ZdNd,d-ZdNd.d/Z dMd0d1Z!dOd2d3Z"dPd5d6Z#dQd7d8Z$dRd9d:Z%dKd;d<Z&dSd>d?Z'dTd@dAZ(dUdBdCZ)dVdDdEZ*dS )W    )annotations)chainpairwise)TYPE_CHECKINGN)check_code_arraycheck_offset_arraycheck_point_array)	CLOSEPOLYLINETOMOVETO
code_dtypeoffset_dtypepoint_dtypeoffsetscpy.OffsetArrayreturncpy.CodeArrayc                 C  sH   t |  | d }tj|ttd}t|| dd < t|| dd d < |S )zSDetermine codes from offsets, assuming they all correspond to closed polygons.
    ZdtypeN   )r   npfullr
   r   r   r	   )r   ncodes r   ^/var/www/html/eduruby.in/lip-sync/lip-sync-env/lib/python3.10/site-packages/contourpy/array.pycodes_from_offsets   s   r   pointscpy.PointArrayc                 C  sv   t |  t| tjt|ttd}t|| dd < | dd d }tj|| dd  || kdd}t	||| < |S )zDetermine codes from offsets and points, using the equality of the start and end points of
    each line to determine if lines are closed or not.
    r   Nr   r   Zaxis)
r   r   r   r   lenr
   r   r   allr	   )r   r   r   Zend_offsetsclosedr   r   r   codes_from_offsets_and_points   s   "r#   c                 C  sJ   t |  t| }tj|ttd}t|d< t| d | d kr#t|d< |S )zDetermine codes for a single line, using the equality of the start and end points to
    determine if the line is closed or not.
    r   r   r   )	r   r    r   r   r
   r   r   r!   r	   )r   r   r   r   r   r   codes_from_points/   s   r$   list_of_codeslist[cpy.CodeArray]c                 C     | st dtj| tdS )zAConcatenate a list of codes arrays into a single code array.
    z!Empty list passed to concat_codesr   )
ValueErrorr   concatenater   r%   r   r   r   concat_codes=      r+   list_of_codes_or_nonelist[cpy.CodeArray | None]cpy.CodeArray | Nonec                 C     dd | D }|rt |S dS )zQConcatenate a list of codes arrays or None into a single code array or None.
    c                 S     g | ]}|d ur|qS Nr   .0r   r   r   r   
<listcomp>I       z(concat_codes_or_none.<locals>.<listcomp>N)r+   )r-   r%   r   r   r   concat_codes_or_noneF   s   r7   list_of_offsetslist[cpy.OffsetArray]c                   sb   st dt}tjdd D td tjd g fddt|d D R td}|S )	zEConcatenate a list of offsets arrays into a single offset array.
    z#Empty list passed to concat_offsetsc                 S  s   g | ]}|d  qS )r   r   r4   r   r   r   r   r5   W       z"concat_offsets.<locals>.<listcomp>r   r   c                 3  s,    | ]}|d   d d  |  V  qdS )r   Nr   )r4   iZ
cumulativer8   r   r   	<genexpr>Y   s   * z!concat_offsets.<locals>.<genexpr>r   )r(   r    r   cumsumr   r)   range)r8   r   retr   r=   r   concat_offsetsP   s   &rB   list_of_offsets_or_nonelist[cpy.OffsetArray | None]cpy.OffsetArray | Nonec                 C  r0   )zUConcatenate a list of offsets arrays or None into a single offset array or None.
    c                 S  r1   r2   r   r:   r   r   r   r5   d   r6   z*concat_offsets_or_none.<locals>.<listcomp>N)rB   )rC   r8   r   r   r   concat_offsets_or_none_      rF   list_of_pointslist[cpy.PointArray]c                 C  r'   )zBConcatenate a list of point arrays into a single point array.
    z"Empty list passed to concat_pointsr   )r(   r   r)   r   rH   r   r   r   concat_pointsk   r,   rK   list_of_points_or_nonelist[cpy.PointArray | None]cpy.PointArray | Nonec                 C  r0   )zRConcatenate a list of point arrays or None into a single point array or None.
    c                 S  r1   r2   r   r4   r   r   r   r   r5   y   r6   z)concat_points_or_none.<locals>.<listcomp>N)rK   rL   rH   r   r   r   concat_points_or_nonet   rG   rQ   c                 C  r0   )zvConcatenate a list of points or None into a single point array or None, with NaNs used to
    separate each line.
    c                 S  r1   r2   r   rO   r   r   r   r5      r6   z2concat_points_or_none_with_nan.<locals>.<listcomp>N)concat_points_with_nanrP   r   r   r   concat_points_or_none_with_nan   s   rS   c                   sf   | st dt| dkr| d S tjdtjtd | d gtt fdd| dd D  } t| S )	zaConcatenate a list of points into a single point array with NaNs used to separate each line.
    z+Empty list passed to concat_points_with_nanr   r   )r      r   c                 3  s    | ]} |fV  qd S r2   r   )r4   x
nan_spacerr   r   r>      s    z)concat_points_with_nan.<locals>.<genexpr>N)	r(   r    r   r   nanr   listr   rK   rJ   r   rV   r   rR      s    rR   c                 C  sX   t |  t| t|dkr| S tjtjtjgtd}tj| |dd tj	|ddS )zNInsert NaNs into a point array at locations specified by an offset array.
    rT   r   r   r   r   r   )
r   r   r    r   arrayrX   r   insertastypeZint64)r   r   rW   r   r   r   insert_nan_at_offsets   s   "r]   r   c                 C  s,   t |  tt| tkd t| tS )zBDetermine offsets from codes using locations of MOVETO codes.
    r   )r   r   appendnonzeror   r    r\   r   )r   r   r   r   offsets_from_codes   s   $r`   c                 C  *   | st dtjdgdd | D  tdS )z4Determine offsets from lengths of point arrays.
    z)Empty list passed to offsets_from_lengthsr   c                 S  s   g | ]}t |qS r   r    )r4   liner   r   r   r5      r;   z(offsets_from_lengths.<locals>.<listcomp>r   r(   r   r?   r   rJ   r   r   r   offsets_from_lengths      re   c                 C  ra   )zHDetermine outer offsets from codes using locations of MOVETO codes.
    z5Empty list passed to outer_offsets_from_list_of_codesr   c                 S  s   g | ]	}t |tkqS r   )r   Zcount_nonzeror   r3   r   r   r   r5      s    z4outer_offsets_from_list_of_codes.<locals>.<listcomp>r   rd   r*   r   r   r    outer_offsets_from_list_of_codes   s
   rg   c                 C  ra   )z4Determine outer offsets from a list of offsets.
    z7Empty list passed to outer_offsets_from_list_of_offsetsr   c                 S  s   g | ]}t |d  qS r   rb   r:   r   r   r   r5      r6   z6outer_offsets_from_list_of_offsets.<locals>.<listcomp>r   rd   )r8   r   r   r   "outer_offsets_from_list_of_offsets   rf   ri   &tuple[cpy.PointArray, cpy.OffsetArray]c                 C  s   t |  tt| dddf d }t|dkr'| tjdt| gtdfS tj| |dd} |tt|8 }tj	t|d td}d|d< ||dd< t| |d< | |fS )z^Remove NaN from a points array, also return the offsets corresponding to the NaN removed.
    Nr   r   r   rT   r   r   )
r   r   r_   isnanr    rZ   r   deleteZarangeempty)r   nan_offsetsr   r   r   r   
remove_nan   s    ro   c                 C  6   t |  t| t|dkrt| |dd S | gS )z]Split a code array at locations specified by an offset array into a list of code arrays.
    rT   r   r   )r   r   r    r   split)r   r   r   r   r   split_codes_by_offsets   s
   rr   c                 C  rp   )z_Split a point array at locations specified by an offset array into a list of point arrays.
    rT   r   r   )r   r   r    r   rq   )r   r   r   r   r   split_points_by_offsets   s
   rs   c                   sh   t   tt dddf d }t|dkr gS tdg|t gf} fddt|D S )z>Split a points array at NaNs into a list of point arrays.
    Nr   r   c                   s    g | ]\}} |d  | qS rh   r   )r4   ser   r   r   r5     s     z'split_points_at_nan.<locals>.<listcomp>)r   r   r_   rk   r    r)   r   )r   rn   r   rv   r   split_points_at_nan   s    rw   )r   r   r   r   )r   r   r   r   r   r   )r   r   r   r   )r%   r&   r   r   )r-   r.   r   r/   )r8   r9   r   r   )rC   rD   r   rE   )rH   rI   r   r   )rL   rM   r   rN   )r   r   r   r   r   r   )r   r   r   r   )rH   rI   r   r   )r%   r&   r   r   )r   r   r   rj   )r   r   r   r   r   r&   )r   r   r   r   r   rI   )r   r   r   rI   )+
__future__r   	itertoolsr   r   typingr   numpyr   Zcontourpy.typecheckr   r   r   Zcontourpy.typesr	   r
   r   r   r   r   Zcontourpy._contourpyZ
_contourpycpyr   r#   r$   r+   r7   rB   rF   rK   rQ   rS   rR   r]   r`   re   rg   ri   ro   rr   rs   rw   r   r   r   r   <module>   s8     




	




	





	


	

