o
    iIK                     @   s  d Z ddlZddlmZmZ ddlZddlmZm	Z	m
Z
 ddlmZmZ ddlmZ ddlmZ ddlmZmZmZmZmZmZ ddl Z e j!dkZ"d	d
 Z#dd Z$dd Z%edgdd Z&edgdddd Z'edgdddd Z(ej)ddd Z*edgdddd Z+d d! Z,d"d# Z-ed$gde"rd%ndd&d'd( Z.d)d* Z/ed+gddd,d-d. Z0ed/gd0d1 Z1ed2gd3dd4d5d6 Z2ed7gd8d9d: Z3d;d< Z4d=d> Z5d?d@ Z6dAdB Z7ed7gd8dCdD Z8dEdF Z9edGgd3dHdIdJ Z:edKgd3dHdLdM Z;dNdO Z<dS )Pz'
Tests specific to the patches module.
    N)assert_almost_equalassert_array_equal)Polygon	RectangleFancyArrowPatch)image_comparisoncheck_figures_equal)Bbox)collectionscolorspatchespathstyle
transformswin32c                  C   s   ddgddgddgg} | ddgg }t | dd}t| | ||  t| | t |dd}t| |  || t| |  t | dd}t| |  ||  t| |  t |dd}t| | || t| | d S )Nr      TclosedF)r   r   get_xyset_xy)xyxyclosedp r   X/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/matplotlib/tests/test_patches.pytest_Polygon_close   s$   



r   c            	      C   s   t ddg} d}d}d}t| |||d}t| ||}t j| d }t t |t | gt |t |gg}t || |  j	|  }t
| | d S )N      ?g       @      g      >@)angle     f@)npasarrayr   piarraycossininner	get_vertsTr   )	locwidthheightr   rect1rect2	angle_radrotation_matrix	new_vertsr   r   r   test_rotate_rect7   s   r2   c                  C   sH   t ddd d d } t ddd d d }tt|dd|  d S )	N)r   r   r   r   r3   r4   r   )r   r(   r   r!   roll)pos_verticesneg_verticesr   r   r   test_negative_rectO   s   r:   clip_to_bboxc            	      C   s   t  } | d}|ddg |ddg tjd }| j	ddg9  _	| j	dd	g8  _	tj
  }| j	ddg9  _	| j	dd
g7  _	tj||}tj|dddd}|| tddgddgg}||}tj|ddddd}|| d S )No   i   ijd      
         i      ?coralnone)alpha	facecolor	edgecolorig     `S2   igreen   black)rF   rG   lwrH   )pltfigureadd_subplotset_xlimset_ylimmpathPathunit_regular_stardeepcopyverticesunit_circlemake_compound_pathmpatches	PathPatch	add_patchmtransformsr	   r;   )	figaxr   path2combinedpatchbboxresult_pathresult_patchr   r   r   test_clip_to_bboxW   s*   



rf   patch_alpha_coloringT)remove_textc            	      C   s   t jd} t j }t|j| jddd g}t|j| jg}t ||}t |d |}t	 }t
j|ddddd	}|| tj|gddddd
}|| |ddg |ddg dS )z
    Test checks that the patch and collection are rendered with the specified
    alpha values in their facecolor and edgecolor.
       Nr5   r   rA   dashdotr   r   r   rC   r   r   r   g      ?	linewidth	linestylerG   rH   rn   
linestylesrG   rH   r   rS   rT   rU   rX   r!   concatenaterW   codesrN   axesrZ   r[   r\   mcollectionsPathCollectionadd_collectionrQ   rR   	starcirclevertsrt   	cut_star1	cut_star2r_   rb   colr   r   r   test_patch_alpha_coloringu   s*   


r   patch_alpha_overridec            	      C   s   t jd} t j }t|j| jd d d g}t|j| jg}t ||}t |d |}t	 }t
j|dddddd	}|| tj|gdddddd
}|| |ddg |ddg d S )Nri   r5   r   rA   rj         ?rk   rl   )rn   ro   rF   rG   rH   )rn   rq   rF   rG   rH   r   rr   ry   r   r   r   test_patch_alpha_override   s.   


r   defaultc                  C   s*   t jddddd} |  d dksJ d S )Nr6   r   rE   )rG   rF   r   )rN   Circleget_facecolor)cr   r   r   test_patch_color_none   s   r   patch_custom_linestylec            	      C   s   t jd} t j }t|j| jd d d g}t|j| jg}t ||}t |d |}t	 }t
j|ddddd}|| tj|gddgddd	}|| |dd
g |dd
g d S )Nri   r5   r   rA   )r   )rA      r@   r   r   r   r   r   r   r   rm   rp   r   rr   ry   r   r   r   test_patch_custom_linestyle   s*   


r   c            
      C   s   t jd} t j }t|j| jd d d g}t|j| jg}g d}t	 }|
ddd}t|D ]\}}t || |} tj| d|ddd}	||	 q5|d|d g |d|d g |j  d S )	Nri   r5   )-z--z-.:soliddashedrj   dottedr   r   r   r   rm   )rS   rT   rU   rX   r!   rs   rW   rt   rN   rO   rP   	enumeraterZ   r[   r\   rQ   rR   canvasdraw)
rz   r{   r|   rt   rq   r^   r_   ilsrb   r   r   r   test_patch_linestyle_accents   s$   
r   c                  C   s   dddddd} dd |   D }tjd	i |}|   D ] \}\}}}t|||ks-J t||| t|||ks=J qd S )
N)r6   r   r   
set_center)rA   r?   
set_radius)r   r   	set_width)r      
set_theta1)-   rI   
set_theta2)centerrr+   theta1theta2c                 S   s   i | ]	\}}||d  qS )r   r   ).0kvr   r   r   
<dictcomp>   s    z'test_wedge_movement.<locals>.<dictcomp>r   )itemsrZ   Wedgegetattr)
param_dict	init_argswattrold_vnew_vfuncr   r   r   test_wedge_movement   s   r   wedge_rangegffffff?)rh   tolc            	   
   C   s   t  } d}ddgddg||d gddgd	d
gddgddgddgddgg	}t|D ]%\}\}}|d }|d }tj|d |d fd||dddd}| | q)| ddg | ddg d S )Ngo͂@g,(J@g 7
m@g,(J@gm7
m@r    r   h  Z   i  iL   i|  r   .   r   r   rE   r   )rG   rH   rM   r4   r?   	   )rN   ru   r   rZ   r   
add_artistrQ   rR   )	r_   t1argsr   r   r   xywedger   r   r   test_wedge_range  s*   

r   c                  C   s  t jddd} t| dksJ t jddddd} t| dks J t jddddd} t| d	ks1J t jddddd
d} t| dksCJ t jddddd
dd} d}t| |ksXJ t jdddd} t| dkshJ t jdddd} t| dksxJ t j	dddd} t| dksJ t
jg ddd}t |} t| dksJ ddgddgddgg}t |} t| dksJ t j|d} t| dd  d!ksJ t dd"} t| d#ksJ t dd"d$} t| d%ksJ t | dd}t|d&ksJ dS )'z
    Check that patches have nice and working `str` representation.

    Note that the logic is that `__str__` is defined such that:
    str(eval(str(p))) == str(p)
    r   r   r   )r   radiuszCircle(xy=(1, 2), radius=3)rK   rA   )r   r+   r,   r   z.Ellipse(xy=(1, 2), width=3, height=4, angle=5)z0Rectangle(xy=(1, 2), width=3, height=4, angle=5)ri   )r   r   r   r   r+   z6Wedge(center=(1, 2), r=3, theta1=4, theta2=5, width=6)r   )r   r+   r,   r   r   r   z>Arc(xy=(1, 2), width=3, height=4, angle=5, theta1=6, theta2=7)r=   )r   z3RegularPolygon((1, 2), 20, radius=5, orientation=0))r   r   
resolutionz.CirclePolygon((1, 2), radius=5, resolution=20))r+   r,   z)FancyBboxPatch((1, 2), width=3, height=4))r   r   r   r   Tr   zPathPatch3((1, 2) ...)r   r   zPolygon3((1, 2) ...))r   N   zFancyArrowPatch(Path(array()r   rK   zFancyArrowPatch((1, 2)->(3, 4))datazConnectionPatch((1, 2), (3, 4))z'Shadow(ConnectionPatch((1, 2), (3, 4))))rZ   r   strEllipser   r   ArcRegularPolygonCirclePolygonFancyBboxPatchrS   rT   r[   r   r   ConnectionPatchShadow)r   expectedr   r   sr   r   r   test_patch_str"  s>   

r   multi_color_hatch)rh   r   c               	   C   s   t  \} }|tdtdd}t|D ]\}}|d |d| |d q|	  |
d tdD ].}tdd|i t|d	 dfd
dddd}W d    n1 s]w   Y  || q9d S )NrA   r   ri   rE   zC{}/Fzhatch.colorg?g?z//)hatchfc)rN   subplotsbarranger   set_facecolorset_edgecolorformat	set_hatchautoscale_view	autoscalemstylecontextr   r\   )r^   r_   rectsr   rectr   r   r   r   test_multi_color_hatch[  s   

r   zunits_rectangle.pngc                  C   s   dd l m  m}  |   td| j d| j fd| j d| j }t \}}|	| |
d| j d| j g |d| j d| j g d S )	Nr   rA   ri   r   r   rK   r   r   )matplotlib.testing.jpl_unitstesting	jpl_unitsregisterrZ   r   kmrN   r   r\   rQ   rR   )Ur   r^   r_   r   r   r   test_units_rectanglen  s   *
r   zconnection_patch.pngmpl20)r   rh   c               	   C   sl   t dd\} \}}tjdddd||dd}|| d}d	}d
}| }tj||||dd}|| d S )Nr   r   )皙?r   )?r   r   ->)xyAxyBcoordsAcoordsBaxesAaxesB
arrowstyle)g333333?r   )        皙?zaxes fractionr   )r   r   r   r   r   )rN   r   rZ   r   r   get_yaxis_transform)r^   ax1ax2conr   r   r   r   r   r   r   test_connection_patch{  s   

r   png)
extensionsc              	   C   s   |  dd\}}tjdd|ddddd	}| | | dd\}}|j}tjd
 tjd< tjdd||jd |jd fdddd	}|| d S )Nr   r   )333333?r   r   )iizfigure pixelsr   rA   )r   r   r   r   r   r   shrinkBz
figure.dpisavefig.dpir   r=   )	r   rZ   r   r   rc   rN   rcParamsr+   r,   )fig_testfig_refr   r   r   bbr   r   r   test_connection_patch_fig  s    
r  c                  C   sX   ddl m } m} | dddddd}|dd}t|df|d}t \}}|| d S )Nr   )datetime	timedelta  r      )seconds)r  r	  rZ   r   rN   r   r\   )r  r	  startdeltarb   r^   r_   r   r   r   test_datetime_rectangle  s   
r  c                  C   s   ddl m }  | dddddd}| ddd}tt t|df|d W d    n1 s.w   Y  tt td|fd| W d    d S 1 sMw   Y  d S )Nr   r  r
  r   i  rA   )r  pytestraises	TypeErrorrZ   r   )r  r  dt_deltar   r   r   test_datetime_datetime_fails  s   "r  c                     s|   t dddd g d}      d tfdd| D }t fdd| D }t||ks<J d S )	NrC   rC   rC   r   r   )r   rC   )r   rC   )r   rC   r  c                    s   g | ]	}  |qS r   contains_pointr   point)r   r   	transformr   r   
<listcomp>  s    z'test_contains_point.<locals>.<listcomp>c                    s   g | ]}  |qS r   r  r  )ellr   r   r    s    )rZ   r   get_pathget_transform_process_radiusr!   r$   all)pointsr   resultr   )r  r   r   r  r   test_contains_point  s   
r%  c                  C   s`   t dddd} g d}|  }|  }| d }||||}| |}t||ks.J d S )Nr  rC   r   r   r  )rZ   r   r  r   r!  contains_pointsr!   r"  )r  r#  r   r  r   r   r$  r   r   r   test_contains_points  s   

r'  c                 C   s   t ddg}t ddg}dtjd< |  }tj|ddd}tj||d |d	 d
}|| || | }tj|ddd}tj||j	d |  ddt 
t| d t 
t| d dd}|| || d S )Nr   r   r   rO   r  rC   )r   r+   r,   r   r   )oxoyH   )r   r+   r,   r   ecrF   )r!   r$   rN   r  r   rZ   r   r   r\   dpir"   mcolorsto_rgbr   )r  r  r   dxya1r   shadowa2r   r   r   test_shadow  s$   



r3  c                  C   sD   ddl m }  | ddd}t \}}td|fd|f}|| d S )Nr   r  i  r   {Gz?)r  rN   r   r   r\   )r  dtimer^   r_   arrowr   r   r   test_fancyarrow_units  s
   r7  zlarge_arc.svg)r   c                  C   s   t dd\} \}}d}d}d}||fD ]}tj||f||ddd}|| |  |d q|d	d
 |dd |dd |dd d S )Nr   r      ii  r   )rM   colorequalr   r?   rA   ri   iXiPF  ii  )	rN   r   rZ   r   r\   set_axis_off
set_aspectrQ   rR   )r^   r   r   r   r   diameterr_   ar   r   r   test_large_arc  s   
r?  zall_quadrants_arcs.svgc                  C   sV  t jddddd\} }d}d}d}d}t| |D ]\}\}}d	}	td
d
td f||fD ]J\}
}t||	dD ];\}\}}tj|| |
 || |
 f|| || dd| d| t	t
||d d| d| d	}|| q:|d }	q0|| d |d  || d |d  |jd	dd |jd	dd |  |d qd S )Nr   F)r@   r@   )squeezefigsizei ))r5   r5   )r5   r   r   )r   r5   ))r   r   )r   r   )r   r5   )r5   r   )r   )r   r   )r   r4  )r   gMbP?r   gH.?)r  rK   Cr   r   zbig )rM   r9  zorderr   labelgidi  r   )r9  r:  )rN   r   zipravelr!   sqrtr   rZ   r   rad2degarctan2r\   rQ   rR   axhlineaxvliner;  r<  )r^   ax_arrscalediag_centerson_axis_centersskewsr_   sxsyr   prescalecentersjx_signy_signr>  r   r   r   test_rotated_arcs  sB   


rY  c                  C   s8   ddg} t | | gj}tt| g j|ksJ d S )Nr   )r	   extentsr!   r"  r   get_extents)r  correct_extentsr   r   r   test_degenerate_polygon2  s   "r]  )=__doc__numpyr!   numpy.testingr   r   r  matplotlib.patchesr   r   r   matplotlib.testing.decoratorsr   r   matplotlib.transformsr	   matplotlib.pyplotpyplotrN   
matplotlibr
   rv   r   r-  r   rZ   r   rS   r   r   r   r]   sysplatformon_winr   r2   r:   rf   r   r   markr   r   r   r   r   r   r   r   r   r  r  r  r%  r'  r3  r7  r?  rY  r]  r   r   r   r   <module>   sb     
#






9






	

$