U
    \	axS                     @   sp  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
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 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.ed"gd#d$d% Z/d&d' Z0ed(gde$rPd)ndd*d+d, Z1d-d. Z2ed/gddd0d1d2 Z3ed3gd4d5 Z4ed6gd7dd8d9d: Z5ed"gd#d;d< Z6d=d> Z7d?d@ Z8dAdB Z9dCdD Z:ed"gd#dEdF Z;dGdH Z<edIgd7dJdKdL Z=edMgd7dJdNdO Z>dPdQ Z?ej+@dRdSdTdU ZAdVdW ZBdXdY ZCdZd[ ZDd\d] ZEd^d_ ZFdS )`z'
Tests specific to the patches module.
    N)assert_almost_equalassert_array_equal)PatchPolygon	RectangleFancyArrowPatch)image_comparisoncheck_figures_equal)Bbox)collectionscolorspatchespathstyle
transformsrcParams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   Zget_xyZset_xy)xyZxyclosedp r   A/tmp/pip-unpacked-wheel-wjyw_3jo/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   Zrect1Zrect2Z	angle_radZrotation_matrixZ	new_vertsr   r   r   test_rotate_rect7   s    r,   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   r-   r.   r   )r   r'   r   r    Zroll)Zpos_verticesZneg_verticesr   r   r   test_negative_rectO   s    r1   clip_to_bboxc            	      C   s   t  \} }|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 )Ni   ijd      
         i      ?Zcoralnone)alpha	facecolor	edgecolorig     `S2   iZgreen   black)r;   r<   lwr=   )pltsubplotsset_xlimset_ylimmpathPathunit_regular_stardeepcopyverticesunit_circleZmake_compound_pathmpatches	PathPatch	add_patchmtransformsr
   r2   )	figaxr   path2Zcombinedpatchbboxresult_pathZresult_patchr   r   r   test_clip_to_bboxW   s6       

    rV   Z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.
       Nr/   r   r7   dashdotr   r   r   r9   r   r   r   g      ?	linewidth	linestyler<   r=   r]   
linestylesr<   r=   r   rF   rG   rH   rK   r    concatenaterJ   codesrB   axesrL   rM   rN   mcollectionsZPathCollectionZadd_collectionrD   rE   	starcirclevertsrc   Z	cut_star1Z	cut_star2rQ   rS   colr   r   r   test_patch_alpha_colorings   s.    
 
 
rk   Z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 )NrX   r/   r   r7   rY         ?rZ   r[   )r]   r^   r;   r<   r=   )r]   r`   r;   r<   r=   r   ra   rf   r   r   r   test_patch_alpha_override   s2    
 
 
rm   defaultc                  C   s*   t jddddd} |  d dks&td S )Nr0   r   r:   )r<   r;   r   )rB   Circleget_facecolorAssertionError)cr   r   r   test_patch_color_none   s    rs   Z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 )NrX   r/   r   r7   )r   )r7      r6   rt   r   r   r   r   r   r   r\   r_   r   ra   rf   r   r   r   test_patch_custom_linestyle   s2    
  
  
rw   c            
      C   s   t jd} t j }t|j| jd d d g}t|j| jg}ddddddd	d
g}t	 \}}t
|D ]6\}}t || |} tj| d|ddd}	||	 ql|d|d g |d|d g |j  d S )NrX   r/   ---z-.:solidZdashedrY   Zdottedr   ru   rv   r\   r   )rF   rG   rH   rK   r    rb   rJ   rc   rB   rC   	enumeraterL   rM   rN   rD   rE   ZcanvasZdraw)
rg   rh   ri   rc   r`   rP   rQ   ilsrS   r   r   r   test_patch_linestyle_accents   s.    
    r   Zpng)
extensionsc           	      C   s   t j }|  }| }tddddgD ]X\}}t |j| |j}tj|d|ddd}|	| tj|dd	ddd}|	| q*|
d
|d g |d
|d g |
d
|d g |d
|d g d S )Nr:   None  r   ru   rv   r\   rx   r/   r   )rF   rG   rK   Zadd_subplotr|   rJ   rc   rL   rM   rN   rD   rE   )	fig_testfig_refrh   Zax_testZax_refr}   r~   r   rS   r   r   r   test_patch_linestyle_none   s.    
 
 r   c                  C   s|   dddddd} dd |   D }tjf |}|   D ]@\}\}}}t|||ksVtt||| t|||ks6tq6d S )	N)r0   r   r   Z
set_center)r7   r5   Z
set_radius)r   r   Z	set_width)r      Z
set_theta1)-   r>   Z
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>)itemsrL   Wedgegetattrrq   )Z
param_dictZ	init_argswattrZold_vZnew_vfuncr   r   r   test_wedge_movement  s    r   Zwedge_rangegffffff?)rW   Z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 ]J\}\}}|d }|d }tj|d |d fd||dddd}| | qR| 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   r:   r   )r<   r=   rA   r.   r5   	   )rB   rd   r|   rL   r   
add_artistrD   rE   )	rQ   t1argsr}   r   r   xyZwedger   r   r   test_wedge_range  s.    

  r   c                  C   s  t jddd} t| dkstt jddddd} t| dks@tt jddddd} t| d	ksbtt jddddd
d} t| dkstt jddddd
dd} d}t| |kstt jdddd} t| dkstt j	dddd} t| dkstt j
dddd} t| dksttjdddgdd}t |} t| dksBtt td} t| dksdtddgddgddgg}t |} t| dkstt j|d } t| d!d" d#kstt dd$} t| d%kstt dd$d&} t| d'kstt | dd}t|d(kst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)r?   r7   )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)rX   )r   r   r   r   r*   z6Wedge(center=(1, 2), r=3, theta1=4, theta2=5, width=6)rt   )r   r*   r+   r   r   r   z>Arc(xy=(1, 2), width=3, height=4, angle=5, theta1=6, theta2=7)r3   )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   Tr   zPathPatch3((1, 2) ...)r   r   z
Polygon0()r   r   zPolygon3((1, 2) ...))r   N   zFancyArrowPatch(Path(array()r   r?   zFancyArrowPatch((1, 2)->(3, 4))datazConnectionPatch((1, 2), (3, 4))z'Shadow(ConnectionPatch((1, 2), (3, 4))))rL   ro   strrq   Ellipser   r   ArcZRegularPolygonZCirclePolygonZFancyBboxPatchrF   rG   rM   r   r    emptyr   ConnectionPatchShadow)r   expectedr   r   sr   r   r   test_patch_str9  sB    

r   Zmulti_color_hatch)rW   r   c               
   C   s   t  \} }|tdtdd}t|D ],\}}|d |d| |d q*|	  |
d tdD ]H}tdd|i  t|d	 dfd
dddd}W 5 Q R X || qrd S )Nr7   r   rX   r:   zC{}/Fzhatch.colorg?g?z//)Zhatchfc)rB   rC   barranger|   Zset_facecolorZset_edgecolorformatZ	set_hatchZautoscale_viewZ	autoscalemstylecontextr   rN   )rP   rQ   Zrectsr}   rectr   r   r   r   test_multi_color_hatchu  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   r7   rX   r   r   r?   rt   r   )Zmatplotlib.testing.jpl_unitsZtestingZ	jpl_unitsregisterrL   r   kmrB   rC   rN   rD   rE   )Ur   rP   rQ   r   r   r   test_units_rectangle  s    *
r   zconnection_patch.pngZmpl20)r   rW   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axesAZaxesB
arrowstyle)g333333?r   )        皙?zaxes fractionrx   )r   r   r   r   r   )rB   rC   rL   r   r   Zget_yaxis_transform)rP   ax1ax2conr   r   r   r   r   r   r   test_connection_patch  s$      

 r   c              	   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   r7   )r   r   r   r   r   r   ZshrinkBz
figure.dpisavefig.dpir   r3   )	rC   rL   r   r   rT   rB   r   r*   r+   )r   r   r   r   r   Zbbr   r   r   test_connection_patch_fig  s0        
    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   rL   r   rB   rC   rN   )r   r   startdeltarS   rP   rQ   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 5 Q R X tt td|fd| W 5 Q R X d S )Nr   r   r   r   i  r7   )r   pytestZraises	TypeErrorrL   r   )r   r   Zdt_deltar   r   r   test_datetime_datetime_fails  s    r   c                     s   t dddd ddddg}      d tfdd	| D }t fd
d	| D }t||ks|td S )Nr9   r9   r9   r   r   r   r9   r   r9   rl   r9   c                    s   g | ]}  |qS r   Z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     )	rL   r   get_pathget_transform_process_radiusr    r#   allrq   )pointsr   resultr   )r   r   r   r   r   test_contains_point  s    
r   c                  C   sd   t dddd} ddddg}|  }|  }| d }||||}| |}t||ks`td S )Nr   r9   r   r   r   r   r   )	rL   r   r   r   r   Zcontains_pointsr    r   rq   )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   figurer   r9   )r   r*   r+   r   r   )ZoxZoyH   )r   r*   r+   r   Zecr;   )r    r#   rB   r   rC   rL   r   r   rN   Zdpir!   mcolorsZto_rgbrp   )r   r   r   ZdxyZa1r   ZshadowZa2r   r   r   test_shadow  s(    


  
r   c                  C   sD   ddl m }  | ddd}t \}}td|fd|f}|| d S )Nr   r   i  r   {Gz?)r   rB   rC   r   rN   )r   ZdtimerP   rQ   Zarrowr   r   r   test_fancyarrow_units
  s
    r   zlarge_arc.svg)r   c                  C   s   t dd\} \}}d}d}d}||fD ]8}tj||f||ddd}|| |  |d q(|d	d
 |dd |dd |dd d S )Nr   r      ii  r   )rA   colorequalrt   r5   r7   rX   iXiPF  ii  )	rB   rC   rL   r   rN   set_axis_off
set_aspectrD   rE   )rP   r   r   r   r   ZdiameterrQ   ar   r   r   test_large_arc  s    
r   zall_quadrants_arcs.svgc                  C   sX  t jddddd\} }d}d}d}d}t| |D ]\}\}}d	}	td
d
td f||fD ]\}
}t||	dD ]v\}\}}tj|| |
 || |
 f|| || dd| d| t	t
||d d| d| d	}|| qv|d }	qb|| d |d  || d |d  |jd	dd |jd	dd |  |d q4d S )Nr   F)r6   r6   )ZsqueezeZfigsizei ))r/   r/   )r/   r   r   )r   r/   ))r   r   )r   r   )r   r/   )r/   r   )r   )r   r   )r   r   )r   gMbP?r   gH.?)r   r?   Cr   r   zbig )rA   r   Zzorderr   labelgidi  r   )r   r   )rB   rC   zipZravelr    sqrtr|   rL   r   Zrad2degZarctan2rN   rD   rE   ZaxhlineZaxvliner   r   )rP   Zax_arrZscaleZdiag_centersZon_axis_centersZskewsrQ   ZsxZsyr   ZprescaleZcentersjZx_signZy_signr   r   r   r   test_rotated_arcs'  s@    


r  c                  C   s8   ddg} t | | gj}tt| g j|ks4td S )Nr   )r
   Zextentsr    r   r   Zget_extentsrq   )r   Zcorrect_extentsr   r   r   test_degenerate_polygonL  s    r  kwarg)r=   r<   c              	   C   s4   t jtdd tf ddi| di W 5 Q R X d S )NzQSetting the 'color' property will override the edgecolor or facecolor properties.)matchr   r@   )r   ZwarnsUserWarningr   )r  r   r   r   test_color_override_warningR  s    r  c                  C   s"   t td} |  g kstd S )Nr   )r   r    zerosr'   rq   )Zpolyr   r   r   test_empty_vertsZ  s    r
  c                  C   sN   t  } | td   |  td  ks,t| d  |  td ksJtd S )Nzpatch.antialiased)r   Zset_antialiasedr   Zget_antialiasedrq   rS   r   r   r   test_default_antialiased_  s
    
r  c                  C   s.   t  } | d | d  |  dks*td S )Nry   r{   )r   Zset_linestyleZget_linestylerq   r  r   r   r   test_default_linestylei  s    

r  c                  C   s   t  } |  dkstd S )NZbutt)r   Zget_capstylerq   r  r   r   r   test_default_capstylep  s    r  c                  C   s   t  } |  dkstd S )NZmiter)r   Zget_joinstylerq   r  r   r   r   test_default_joinstyleu  s    r  )G__doc__Znumpyr    Znumpy.testingr   r   r   Zmatplotlib.patchesr   r   r   r   Zmatplotlib.testing.decoratorsr   r	   Zmatplotlib.transformsr
   Zmatplotlib.pyplotZpyplotrB   Z
matplotlibr   re   r   r   r   rL   r   rF   r   r   r   rO   r   sysplatformZon_winr   r,   r1   rV   rk   rm   markrs   rw   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  Zparametrizer  r
  r  r  r  r  r   r   r   r   <module>   sr   $
#








<






	

$

