o
    Zqi&E                     @   sl  d dl Zd dlZd dlZd dlmZmZmZ d dlmZ d dl	m
Z
mZmZmZmZ ejdZee
ee
 ee
ejjk@  ZejejejejfZejejfejejfejejffZ ejejffZ!ej"dkrzeej#f7 Ze ej$ej#ff7 Z e%d d dde%ddd	d	e%d
d
dde%ddddgZ&ee
ee
 e'e
dk@  Z(ej)de
ej)dedd Z*ej)dedd Z+ej)deej)deej)dg ddd Z,ej)de-ddej)de dd Z.ej)de dd Z/ej)de dd Z0ej)de d d! Z1ej)d"e-d#ej)de d$d% Z2ej)d"e-d#ej)de d&d' Z3ej)de d(d) Z4ej)de-dd#ej)de d*d+ Z5ej)de-dd#ej)de d,d- Z6ej)de!d.d/ Z7ej)de!d0d1 Z8ej)de-ddej)de!ej)dd dgd2d3 Z9ej)de!d4d5 Z:ej)d"e-d#ej)de!d6d7 Z;ej)d"e-d#ej)de!d8d9 Z<ej)de-dd#ej)de!d:d; Z=ej)de-dd
d<d= Z>d>d? Z?d@dA Z@ej)dBdCdD e(D dEdD e(D  dFdG ZAej)dHe%dIdIdde%d dJdKdgd edLfe%dIdIdde%d dJdKdgdIedLfe%dIdIdde%d dJdKdgdeg dMfe%dIdIdde%d dJdKdgdeg dNfe%dIdIdde%d dJdKdgdOe fgdPdQ ZBdRdS ZCdTdU ZDdVdW ZEdXdY ZFdZd[ ZGd\d] ZHd^d_ ZId`da ZJdbdc ZKdS )d    N)GeometryGeometryCollectionPolygon)assert_geometries_equal)	all_typesemptyignore_invalidpointpolygonz?ignore:The symmetric_difference_all function:DeprecationWarning      r               	   
   afuncc                 C   s   |t ju r| jdkrt | dkrt jdkrtd || t}t|t	s'J || | gt}|j
dks5J t|d t	s>J d S )Nr   r   )r   r   r   z(GEOS 3.9.5 crashes with mixed collectionr   r   )shapely
difference	geom_typeZget_num_geometriesgeos_versionpytestZxfailr	   
isinstancer   shape)r   r   actual r   h/home/app/PaddleOCR-VL/.venv_paddleocr/lib/python3.10/site-packages/shapely/tests/test_set_operations.pytest_set_operation_array8   s   




r!   c                 C   sX   | t ju r
td tjtdd | ttdgd W d    d S 1 s%w   Y  d S )N0disjoint_subset_union does not support grid_size.grid_size parameter only accepts scalar valuesmatch   	grid_size)r   disjoint_subset_unionr   skipraises
ValueErrorr	   )r   r   r   r    +test_set_operation_prec_nonscalar_grid_sizeJ   s   

"r-   r(   )r   r&   r   c                 C   s   |t ju r
td || | gt|d}|jdksJ t|d ts#J t j| |d}t jt|d}|||g|}t 	t 
|t 
| sHJ d S )Nr"   r'   r   r   )r   r)   r   r*   r	   r   r   r   Zset_precisionequals	normalizeall)r   r   r(   r   bZpoint2expectedr   r   r    test_set_operation_prec_arrayT   s   

$r3   nr&   zfunc, related_funcc                 C   sJ   |t d |  }t d }td| D ]	}||t | }qt||s#J d S )Nr   r&   reduce_test_dataranger   r.   )r4   r   related_funcr   r2   ir   r   r    test_set_operation_reduce_1dimg   s
   r:   c                 C   s.   t dd}| |d d g}t ||sJ d S )Nr&   )r   ZPointr.   )r   r8   geomr   r   r   r    %test_set_operation_reduce_single_geomr   s   r<   c                 C   s|   t gd gd }| |d d}t|tsJ | |dd}|jdks"J | |dd}|jdks/J | |dd}|jdks<J d S )	Nr   r   axisr   r   r&   r   r	   r   r   r   r   r8   datar   r   r   r    test_set_operation_reduce_axisy   s   rD   c                 C   sr   | t jdtdtksJ t jdtd}| |tksJ | |dd tgd ks+J | |dd g ks7J d S )N)r   )Zdtype)r   r   r   r=   r   r&   )npr   objecttolist)r   r8   Zarr_empty_2Dr   r   r    test_set_operation_reduce_empty   s
   rH   none_positionr   c                 C   s@   t d d }||d  | |}|t d t d }t|| d S Nr   r   r&   r6   insertr   r   r8   rI   	test_datar   r2   r   r   r    "test_set_operation_reduce_one_none   s
   rO   c                 C   sL   t d d }||d  ||d  | |}|t d t d }t|| d S rJ   rK   rM   r   r   r    "test_set_operation_reduce_two_none   s   rP   c                 C   s   | t d gt ks
J d S N)r   r   r8   r   r   r    (test_set_operation_reduce_some_none_len2   s   rS   c                 C   s   t |d g|  tg  d S rQ   r   r   r4   r   r8   r   r   r    "test_set_operation_reduce_all_none   s   rV   c                 C   sT   |d g|  gd dd  ttgksJ |d gd g|  dd  ttgks(J d S )Nr   r&   r=   r   )rG   r   rU   r   r   r    &test_set_operation_reduce_all_none_arr   s   (,rW   c                 C   sF   t jtdd | ttgdgd W d    d S 1 sw   Y  d S )Nr#   r$   r&   r'   )r   r+   r,   r	   rR   r   r   r    2test_set_operation_prec_reduce_nonscalar_grid_size   s
   "rX   c                 C   s"   | t t gtjd}|d u sJ d S Nr'   )r	   rE   nan)r   r8   r   r   r   r    ,test_set_operation_prec_reduce_grid_size_nan   s   r[   c                 C   sR   |t d |  |d}t d }td| D ]}||t | |d}qt||s'J d S )Nr'   r   r&   r5   )r4   r   r8   r(   r   r2   r9   r   r   r    #test_set_operation_prec_reduce_1dim   s
   r\   c                 C   s   t gd gd }| |dd d}t|tsJ | |ddd}|jdks$J | |ddd}|jdks2J | |ddd}|jdks@J d S )	Nr   r   r&   )r(   r>   r   r   r?   r@   rA   rB   r   r   r    #test_set_operation_prec_reduce_axis   s   r]   c                 C   sH   t d d }||d  | |dd}|t d t d dd}t|| d S Nr   r&   r'   r   rK   rM   r   r   r    'test_set_operation_prec_reduce_one_none   s
   r_   c                 C   sT   t d d }||d  ||d  | |dd}|t d t d dd}t|| d S r^   rK   rM   r   r   r    'test_set_operation_prec_reduce_two_none   s   r`   c                 C   s    t |d g|  ddtg  d S )Nr&   r'   rT   rU   r   r   r    'test_set_operation_prec_reduce_all_none   s    ra   c                 C   sz   t ddddt ddddt ddddg}t |d|  }|d }td| D ]
}t ||| }q)t||dd dS )zm
    This is tested separately from other set operations as it expects only
    non-overlapping polygons
    r   r&   r   r   NTr/   )r   boxcoverage_union_allr7   coverage_unionr   )r4   rN   r   r2   r9   r   r   r    test_coverage_union_reduce_1dim   s   rf   c                  C   s   dd t dD } tj| d d}t|tsJ tj| dd}|jdks%J tj| dd}|jdks3J tj| d	d}|jdksAJ d S )
Nc                    s"   g | ]  fd dt dD qS )c              	      s$   g | ]}t | |d   d  qS )r&   )r   rc   ).0r9   jr   r    
<listcomp>  s   $ z>test_coverage_union_reduce_axis.<locals>.<listcomp>.<listcomp>r   )r7   )rg   r   rh   r    rj     s   " z3test_coverage_union_reduce_axis.<locals>.<listcomp>r   r=   r   r   r&   r?   r@   )r7   r   rd   r   r   r   )rC   r   r   r   r    test_coverage_union_reduce_axis  s   rk   c                  C   s   t g d} t g d}tjdkr2tjtjdd t| | W d    d S 1 s+w   Y  d S tjdkrMt| |}t| |g}t||dd d S tjtjd	d t| | W d    d S 1 sgw   Y  d S )
N)r&   r&   r&   r   r   r   )r   r&   rl   )rm   )g?r&   )r   r&   )r   r   rm   )r      r   ZTopologyExceptionr$   r   Trb   z6CoverageUnion cannot process incorrectly noded inputs.)	r   r   r   r   r+   GEOSExceptionre   Zmultipolygonsr   )r
   otherresultr2   r   r   r    &test_coverage_union_overlapping_inputs  s    
"
"rs   zgeom_1, geom_2c                 C   s   g | ]}t |gqS r   )r
   )rg   Znon_polygonr   r   r    rj   7  s    rj   c                 C   s   g | ]}t D ]}||gqqS r   )non_polygon_types)rg   Znon_polygon_1Znon_polygon_2r   r   r    rj   9  s    c                    s  t jdkra fdd  | } |}t|dkr@||kr@t  t | |}W d    n1 s1w   Y  | |ks>J d S tjt jdd t | | W d    d S 1 sZw   Y  d S tjt jdd t | | W d    d S 1 s{w   Y  d S )Nr   c                    sH   t | dr| jst }| jD ]}| |O }q|S | jdddhS )NgeomsZMultiZ
LinearRingZ
LineString)hasattris_emptysetru   r   lstripreplace)r;   Zgtsparteffective_geom_typesr   r    r}   B  s   
zDtest_coverage_union_non_polygon_inputs.<locals>.effective_geom_typesr&   z Overlay input is mixed-dimensionr$   z)Unhandled geometry type in CoverageUnion.)r   r   lenr   re   r   r+   rp   )Zgeom_1Zgeom_2Zgeom_types_1Zgeom_types_2rr   r   r|   r    &test_coverage_union_non_polygon_inputs4  s&   
""r   zgeom,grid_size,expected皙?皙?ffffff@)	r   r   r   r   )r   r   )r   r   )r   r   )r   r   )r   r   )r   r   r   )r   r   r   )r   r   )r   r   )r   r   rn   r   )r   )r   r   )r   r   rn   r   d   c                 C   s"   t j| |d}t ||sJ d S rY   )r   	union_allr.   )r;   r(   r2   r   r   r   r    test_union_all_prec^  s   =r   c                  C   sP   t ddddt ddddg} t j| dd}t j| dd}t ||s&J d S )	Nr   r   r   r   r   r   r&   r'   )r   rc   Zunary_unionr   r.   )ru   r   r2   r   r   r    test_uary_union_alias  s    r   c                   C   @   t jdd tttd  W d    d S 1 sw   Y  d S )Nz>positional argument `grid_size` for `difference` is deprecatedr$   )r   deprecated_callr   r   r	   r   r   r   r    $test_difference_deprecate_positional  
   "r   c                   C   r   )Nz@positional argument `grid_size` for `intersection` is deprecatedr$   )r   r   r   intersectionr	   r   r   r   r    &test_intersection_deprecate_positional  r   r   c                   C   B   t jdd tttgd  W d    d S 1 sw   Y  d S )Nz?positional argument `axis` for `intersection_all` is deprecatedr$   )r   r   r   intersection_allr	   r   r   r   r    *test_intersection_all_deprecate_positional  
   "r   c                   C   r   )NzHpositional argument `grid_size` for `symmetric_difference` is deprecatedr$   )r   r   r   symmetric_differencer	   r   r   r   r    .test_symmetric_difference_deprecate_positional  r   r   c                   C   r   )NzGpositional argument `axis` for `symmetric_difference_all` is deprecatedr$   )r   r   r   symmetric_difference_allr	   r   r   r   r    2test_symmetric_difference_all_deprecate_positional  r   r   c                   C   r   )Nz9positional argument `grid_size` for `union` is deprecatedr$   )r   r   r   unionr	   r   r   r   r    test_union_deprecate_positional  r   r   c                   C   s   t jdd tttgd  W d    n1 sw   Y  t jdd tttgd d  W d    d S 1 s9w   Y  d S )Nz=positional argument `grid_size` for `union_all` is deprecatedr$   zJpositional arguments `grid_size` and `axis` for `union_all` are deprecated)r   r   r   r   r	   r   r   r   r    #test_union_all_deprecate_positional  s   "r   c                  C   s^   t ddddt ddddg} tjdd t | d  W d    d S 1 s(w   Y  d S )Nr   r&   r   zApositional argument `axis` for `coverage_union_all` is deprecatedr$   )r   rc   r   r   rd   )rC   r   r   r    ,test_coverage_union_all_deprecate_positional  s    "r   )LnumpyrE   r   r   r   r   r   Zshapely.testingr   Zshapely.tests.commonr   r   r   r	   r
   markfilterwarningsZ
pytestmarkarrayrw   Zget_type_idZGeometryTypeZGEOMETRYCOLLECTIONZall_single_typesr   r   r   r   ZSET_OPERATIONSr   r   r   ZREDUCE_SET_OPERATIONSZREDUCE_SET_OPERATIONS_PRECr   r)   Zdisjoint_subset_union_allrc   r6   Zget_dimensionsrt   Zparametrizer!   r-   r3   r7   r:   r<   rD   rH   rO   rP   rS   rV   rW   rX   r[   r\   r]   r_   r`   ra   rf   rk   rs   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    <module>   s   

	




		


	




	




<