o
    h*                     @   sf  d dl Z d dlZd dlmZ d dlmZmZmZ d dl	Z	d dl
mZmZmZmZmZmZ d dlmZ d dlmZ d dlmZ d dlmZ d d	lmZ d d
lmZ dd Zdd Z dd Z!dd Z"edgdddd Z#dd Z$dd Z%e	j&'ddd Z(dd  Z)d!d" Z*e	j&j+e,d# d$d%d&d' Z-e	j&j+e,d# d$d%d(d) Z.d*d+ Z/d,d- Z0d.d/ Z1dS )0    N)assert_array_almost_equal)featuresImageTiffTags)collectionspatheffectspyplot
transformsrcParams
rc_context)RendererAgg)Figure)imread)Path)image_comparison)IdentityTransformc                  C   s   t ddg} | d | jd t }| j||  dd |d | j||  dd |d t	t
t|d d	d
d d S )N   皙?)r   r   r         ?none)	facecolor	edgecolorr   r   r   )              ?r   r      )decimal)r   set_facecolorpatch	set_alphaioBytesIOsavefigget_facecolorseekr   tupler   )figbuf r(   m/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/matplotlib/tests/test_agg.pytest_repeated_save_with_alpha   s$   



r*   c               	   C   sf   t  } t \}}ttddgddgddgddgddggg}|| |dd t	|  d S )Ni   
   gMbP?r   )
r    r!   pltsubplotsr   PathCollectionr   
add_artistset_xlimr"   )bufffax
collectionr(   r(   r)   !test_large_single_path_collection3   s   &
r7   c                  C   sV   t d\} }d}t|}|| |||d |d  t }| j|dd d S )Nr   i  g?g333333?pngformat)	r.   r/   nparangesemilogxfill_betweenr    r!   r"   )r&   r5   stepsdatar'   r(   r(   r)   test_marker_with_nanA   s   

rA   c                  C   sR   t  } t }| }td}|d d d  d9  < || |j| dd d S )N順    r8   r9   )r    r!   r   r/   r;   onesplotr"   )r3   r&   r5   pointsr(   r(   r)   test_long_pathM   s   

rH   zagg_filter.pngT)remove_textc                     sp  dd d$fdd	G dd d} G dd	 d	| G fd
dd|  G  fddd| }t  \}}|jg dg ddddddddd	\}|jg dg ddddddddd	\}|d}||fD ]:}| }| }	|||	\}
|
| tj| |dddd}|
	| |

| d  |
| |
d  qc|d!d" |d!d" |jd# |jd# d S )%Nc                 S   sv   t jd| d  | |dd  | d| d  | d| d  f }t |}t j||  |dd}||d | d  S )NrC   r   r   rD   same)mode)r;   r_hanningconvolvesum)x
window_lenswyr(   r(   r)   smooth1dY   s   6
z!test_agg_filter.<locals>.smooth1dr   c                    s:   t t|dd d }t d| |} t d| |} | S )Nr   rC   r   r   )maxintr;   apply_along_axis)AsigmarQ   )rU   r(   r)   smooth2da   s   z!test_agg_filter.<locals>.smooth2dc                   @   s$   e Zd Zdd Zdd Zdd ZdS )z#test_agg_filter.<locals>.BaseFilterc                 S   s   dS )Nr   r(   selfdpir(   r(   r)   get_padi   s   z+test_agg_filter.<locals>.BaseFilter.get_padc                 S   s   t d)Nz"Should be overridden by subclasses)NotImplementedError)r]   
padded_srcr^   r(   r(   r)   process_imagel   s   z1test_agg_filter.<locals>.BaseFilter.process_imagec                 S   s@   |  |}t|||f||fdgd}| ||}|| | fS )Nr   constant)r_   r;   padrb   )r]   imr^   rd   ra   	tgt_imager(   r(   r)   __call__o   s   
z,test_agg_filter.<locals>.BaseFilter.__call__N)__name__
__module____qualname__r_   rb   rg   r(   r(   r(   r)   
BaseFilterg   s    rk   c                   @   s&   e Zd Zd	ddZdd Zdd ZdS )
z%test_agg_filter.<locals>.OffsetFilterr   c                 S   s
   || _ d S N)offsets)r]   rm   r(   r(   r)   __init__x   s   
z.test_agg_filter.<locals>.OffsetFilter.__init__c                 S   s   t t| jd | S )NH   )rW   rV   rm   r\   r(   r(   r)   r_   {      z-test_agg_filter.<locals>.OffsetFilter.get_padc                 S   sH   | j \}}tj|t|d | dd}tj|t|d |  dd}|S )Nro   r   )axisr   )rm   r;   rollrW   )r]   ra   r^   oxoya1a2r(   r(   r)   rb   ~   s   
z3test_agg_filter.<locals>.OffsetFilter.process_imageN)r   rh   ri   rj   rn   r_   rb   r(   r(   r(   r)   OffsetFilterv   s    
rx   c                       s.   e Zd ZdZdddZdd Z fdd	Zd
S )z'test_agg_filter.<locals>.GaussianFilterzSimple Gaussian filter.      ?r   r   r   c                 S   s   || _ || _|| _d S rl   )rZ   alphacolor)r]   rZ   r{   r|   r(   r(   r)   rn      s   
z0test_agg_filter.<locals>.GaussianFilter.__init__c                 S   s   t | jd d | S Nr   ro   )rW   rZ   r\   r(   r(   r)   r_      rp   z/test_agg_filter.<locals>.GaussianFilter.get_padc                    sh   t |}| j|d d d d d df<  |d d d d df | j | jd | |d d d d df< |S r}   )r;   
empty_liker|   r{   rZ   )r]   ra   r^   rf   r[   r(   r)   rb      s   
z5test_agg_filter.<locals>.GaussianFilter.process_imageN)ry   rz   )rh   ri   rj   __doc__rn   r_   rb   r(   r   r(   r)   GaussianFilter   s
    
r   c                       s,   e Zd Zd fdd	Zdd Zdd	 Zd
S )z)test_agg_filter.<locals>.DropShadowFilter333333?rz   r   c                    s    |||| _ || _d S rl   )gauss_filteroffset_filter)r]   rZ   r{   r|   rm   r   rx   r(   r)   rn      s   z2test_agg_filter.<locals>.DropShadowFilter.__init__c                 S   s   t | j|| j|S rl   )rV   r   r_   r   r\   r(   r(   r)   r_      s   
z1test_agg_filter.<locals>.DropShadowFilter.get_padc                 S   s    | j ||}| j||}|S rl   )r   rb   r   )r]   ra   r^   t1t2r(   r(   r)   rb      s   z7test_agg_filter.<locals>.DropShadowFilter.process_imageN)r   rz   r   rw   r(   r   r(   r)   DropShadowFilter   s    r   )皙?ry   ?)r   r   ry   zbo-brS   r+   r,   zLine 1)mecmfclwmewmslabel)ry   g?gffffff?zro-r   g      @g      rG   )rP   rT   unitsry   Tr   r   F)r   )r.   r/   rF   	get_xdata	get_ydataupdate_frommtransformsoffset_copyget_transformset_transform
set_zorder
get_zorderset_agg_filterset_rasterizedr2   set_ylimxaxisset_visibleyaxis)rk   r   r&   r5   line1line2gausslinexxyyshadow	transformr(   )r   rx   rU   r[   r)   test_agg_filterW   s<   


r   c                  C   sN   t jdd} t }tt | | W d    d S 1 s w   Y  d S )N)i,  i   )figsize)r.   figurer    r!   pytestraises
ValueErrorr"   )r&   r3   r(   r(   r)   test_too_large_image   s
   "r   c                  C   sd   t d} t \}}|| t|  |j  t \}}dtd< || t|  |j  d S )N   i   agg.path.chunksize)	ranger.   r/   rF   r;   sincanvasdrawr
   )rP   r&   r5   r(   r(   r)   test_chunksize   s   
r   Aggc                  C   sL   t g dg d t } t j| ddd t| }|jd dks$J d S )Nr   r   rC   r   r   r   jpgr   )r:   r^   r^   )r   r   )r.   rF   r    r!   r"   r   openinfor'   re   r(   r(   r)   test_jpeg_dpi   s
   
r   c                  C   s^   ddl m}  t }|  }|dd t j|dd|id t	|}|j
d dks-J d S )Nr   )PngInfoSoftwaretestr8   pnginfor:   
pil_kwargs)PIL.PngImagePluginr   r    r!   add_textr.   r   r"   r   r   r   )r   r'   r   re   r(   r(   r)   test_pil_kwargs_png   s   
r   c                  C   sV   t  } ddi}t j| d|d t| }dd |j D }|d dks)J d S )Ndescriptionz
test imagetiffr   c                 S   s   i | ]\}}t j| j|qS r(   )r   TAGS_V2name).0kvr(   r(   r)   
<dictcomp>   s    z(test_pil_kwargs_tiff.<locals>.<dictcomp>ImageDescription)	r    r!   r.   r   r"   r   r   tag_v2items)r'   r   re   tagsr(   r(   r)   test_pil_kwargs_tiff   s   
r   webpzWebP support not available)reasonc                  C   s   t g dg d t } ddi}t j| d|d t|dks"J t }ddi}t j|d|d t|dks:J | j|  jksFJ d S )Nr   r   qualityr   r   r   d   )r.   rF   r    r!   r"   len	getbuffernbytes)	buf_smallpil_kwargs_low	buf_largepil_kwargs_highr(   r(   r)   test_pil_kwargs_webp   s   r   c                  C   sH   t g dg d t } t j| ddd t| }|jdks"J d S )Nr   r   r   T)r:   transparentRGBA)r.   rF   r    r!   r"   r   r   rK   r   r(   r(   r)   test_webp_alpha
  s
   
r   c                  C   sd   t  \} }|dgdgtddg tt | j	  W d    d S 1 s+w   Y  d S )Nr   )r   r   )rC   r   )
r.   r/   scatter	set_pathsr   r   r   	TypeErrorr   r   )r&   r5   r(   r(   r)   (test_draw_path_collection_error_handling  s
   "r   c            	   	   C   s  d} d}d| }d| }t d|| }t | | }d|d d d< tt ||fj}d|_t|||}| }|	d |
d |d	 tjtd
d |||t  W d    n1 saw   Y  |d  tjtdd |||t d W d    n1 sw   Y  tddi' tjtdd |||t  W d    n1 sw   Y  W d    n1 sw   Y  tddi' tjtdd |||t  W d    n1 sw   Y  W d    n1 sw   Y  tddi( tjtdd |||t  W d    n	1 sw   Y  W d    n	1 s'w   Y  d|_tjtdd |||t  W d    d S 1 sKw   Y  d S )NrB   i  r+      r   rC   r   r   /zcannot split hatched path)matchzcannot split filled path)r   r   r   r   z
Please seti@B zPlease reducei_ Fzshould_simplify is False)r;   linspacerE   r   vstackTsimplify_thresholdr   new_gcset_linewidthset_foreground	set_hatchr   r   OverflowError	draw_pathr   r   should_simplify)	Nr^   rS   hrP   rT   pathragcr(   r(   r)   test_chunksize_fails  sV   



$r   c                  C   s@   t  } | jddjg dg dtjddgd | j  d S )N3d)
projectionr   r   )	linewidth)path_effects)r.   r   add_subplotr   r   Stroker   r   )r&   r(   r(   r)   test_non_tuple_rgbafaceO  s
   r  )2r    numpyr;   numpy.testingr   PILr   r   r   r   
matplotlibr   r   r   r.   r	   r   r
   r   matplotlib.backends.backend_aggr   matplotlib.figurer   matplotlib.imager   matplotlib.pathr   matplotlib.testing.decoratorsr   matplotlib.transformsr   r*   r7   rA   rH   r   r   r   markbackendr   r   r   skipifcheckr   r   r   r   r  r(   r(   r(   r)   <module>   s>     

q

	
	

5