o
    :aE                     @   s  d dl Z d dlZd dlmZ d dl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lmZ d	d
 Zdd Zdd Zdd Zdd Ze	d d gdd gddgd dgge	je	je	je	jge	d d gd dgdd gge	je	je	jge	d dgddgge	je	jge	ddgge	jggZg dZej de!eedd Z"ej de	j#e	j$gdd Z%dd Z&dd Z'ed gd!d"d#d$d% Z(ed&gd!d'd(d) Z)ed*gd"d+d,d- Z*d.d/ Z+d0d1 Z,ed2gd!d'd3d4 Z-ed5gd!d'd6d7 Z.ed8gd!d'd9d: Z/ed;gd<d!g d=d>d?d@ Z0dAdB Z1dCdD Z2dEdF Z3dGdH Z4ej dIe5dJdK dLD dMdN Z6ej dOe7dPdQdRdSdT Z8dUdV Z9dWdX Z:dYdZ Z;dS )[    N)assert_array_equal)patches)Path)Polygon)image_comparison)
transforms)
MouseEventc                  C   sL   t tddd} | jjdksJ | jd u sJ t|  jt	j
 j d S )Nr      Tclosed)r   npZzerosverticesshapecodesr   get_extentsextentsr   BboxZnullpath r   </usr/lib/python3/dist-packages/matplotlib/tests/test_path.pytest_empty_closed_path   s   

r   c                     sJ   t    fdd} tt |   W d    d S 1 sw   Y  d S )Nc                      s    j d  _ d S )N       @)r   r   r   r   r   modify_vertices   s   z+test_readonly_path.<locals>.modify_vertices)r   unit_circlepytestraisesAttributeError)r   r   r   r   test_readonly_path   s
   "r   c                  C   s"  t ddd} tjttd| j d t	|  W d    n1 s&w   Y  t dddd}tjttd|j d t	| W d    n1 sRw   Y  t ddd}t d}td|j d	|j }tjt|d t	|| W d    d S 1 sw   Y  d S )
N         z
has shape )matchr
      zYour vertices have shape z but your codes have shape )
r   arangeZreshaper   r   
ValueErrorreescaper   r   )Z
bad_verts1Z
bad_verts2Z
good_vertsZ	bad_codesmsgr   r   r   test_path_exceptions#   s(   


"r*   c                  C   sJ   g d} t | dd}ddg}||}|jdksJ tj|ddg d S )N)r   r   r      r-   r-   )r-   r   r+   Tr         ?r0   )      ?r0   boolF)r   contains_pointsdtyper   testingassert_equal)Zverts2r   pointsretr   r   r   test_point_in_path6   s   
r9   c                  C   s4   t  } g d}| j|dd}tj|g d d S )N))        r:   )      ?r:   )?r<   g      )Zradius)TFF)r   r   r3   r   r5   r6   )r   r7   resultr   r   r   $test_contains_points_negative_radiusA   s   r>   r-   r
   ))r:   r:         ?      ?)r:   r:   r@   r0   )r:   r@   r@   r@   )r@   r   r@   r   zpath, extentsc                 C   s   t |  j|ksJ d S )N)r   allr   r   )r   r   r   r   r   test_exact_extentsZ   s   rB   ignored_codec                 C   sB   t ddgddgddggt jt j| g}t| jdksJ d S )Nr   r-   r
   )r:   r:   r@   r@   )r   MOVETOr   rA   r   r   )rC   r   r   r   r   test_extents_with_ignored_codesh   s   rE   c                  C   sl   t ddgddgddgddgddgg} t| }t t jdgg}||}t|dks.J |d r4J d S Nr   r-   r0   )r   arrayr   nanr3   len)Zboxptestcontainsr   r   r   test_point_in_path_nanr   s   (
rM   c                  C   s   t  \} }|jddd |dd}| |jd|js"J | |jd|jr1J | |jd|jr@J d S )	Nlogr,   )Zxscaleylimr-   
   )   r0   r/   )2   r0   )pltsubplotssetZaxvspanZget_pathZcontains_point	transData	transform)figaxZpolygonr   r   r   test_nonlinear_containment{   s   rZ   zarrow_contains_point.pngTZmpl20)remove_textstylec                  C   s&  t  \} }|d |d tjddddd}|| tjddd	dd}|| tjd
ddddd}|| |||g}tt	dddt	ddd\}}t
t| | D ]3\}\}	}
|j|	|
g\}}td| j||}t
|D ]\}}||\}}|r|j|	|
ddd qyq]d S )Nr	   )r0   g      ?)r1   r?   z->(   )
arrowstylemutation_scale)r0   r-   )r1   r;   z]-[)r0   r1   )r1   g      ?ZfancyF)r^   fillr_   r   r
   g?Zbutton_press_eventrQ   r)sc)rS   rT   set_xlimset_ylimr   ZFancyArrowPatch	add_patchr   Zmeshgridr%   	enumeratezipZravelrV   rW   r   ZcanvasrL   Zscatter)rX   rY   ZarrowZarrow1Zarrow2Zpatches_listXYkxyZxdispZydispZeventmZpatchZinsideresr   r   r   test_arrow_contains_point   sB   





"rp   zpath_clipping.svg)r[   c               	   C   s   t jdd} tg dg dg dg dg dg dg d	gD ]8\}}| d
d|d }g d}||d |d |d   ||d |d |d   |t|dddd qd S )N)g      @g@)Zfigsize)   rr   rr   ^    rt   )rv   rr   )rq   rs   ru   rv   d   )rr   rx   rs   ru   rw   )ry   rr     ru   rw   )ry   rz   rv   r{   rw   )rz   r|   rw   ry   )r|   rw   ry   rz   r!   r
   r-   )r      i  i  r   r"   ZnoneZredT)Z	facecolorZ	edgecolorr   )rS   Zfigurerg   Zadd_subplotrd   re   rf   r   )rX   iZxyrY   Zbboxr   r   r   test_path_clipping   s$   
r   zsemi_log_with_zero.png)r\   c                  C   s^   t dd} dd| d d   d }t \}}|j| |ddd	d
 |dd |d d S )NirP   r@   r
   r-      -o   rk   )ZlwZmarkeredgecolorgHz>T)r   r%   rS   rT   Zsemilogyre   Zgridrl   rm   rX   rY   r   r   r   test_log_transform_with_zero   s   r   c                  C   s   t  } | jjdksJ d S )Nr	   )r   make_compound_pathr   r   )ra   r   r   r   test_make_compound_path_empty   s   r   c                  C   sL   ddg} dt | | gt jt jgg }t j| }t|jt jkdks$J d S )Nr   r"   )r   rD   STOPr   r   sumr   )ZzeropathsZcompound_pathr   r   r   test_make_compound_path_stops   s   
r   zxkcd.pngc                  C   sp   t jd t ddt j d} t | }t  t \}}|	| | W d    d S 1 s1w   Y  d S )Nr   r
   rx   )
r   randomseedlinspaceZpiZsinrS   xkcdrT   plotr   r   r   r   	test_xkcd   s   

"r   zxkcd_marker.pngc                  C   s   t jd t ddd} | }d|  }dt d }t * t \}}|j| |ddd |j| |ddd |j| |d	dd W d    d S 1 sKw   Y  d S )
Nr   rQ            @+rP   )mso^)	r   r   r   r   onesrS   r   rT   r   )rl   y1Zy2Zy3rX   rY   r   r   r   test_xkcd_marker   s   
"r   zmarker_paths.pdfc                  C   sD   d} t t| t| d t|  t d|  t dd d S )N   r!   )rS   Zerrorbarr   r%   r   ZxlimrO   )Nr   r   r   test_marker_paths_pdf   s   r   Znan_pathdefault)ZpdfZsvgepsZpng)r\   r[   
extensionsc                  C   sV   dt jdt jdddg} t jdt jddt jd	g}t \}}|| d
 ||d
 d S )Nr   r
   r!   rQ   r$   r   	   rP   r    r   )r   rH   rS   rT   r   )Zy0r   rX   rY   r   r   r   test_nan_isolated_points  s
   r   c                  C   s*  t ddgddgddgddgdd	gd
dgddgddgddgddgddgddgddgddgddgddgdd gd!d"gd#d"gd$d%gd&d'gd(d)gg} d*\}}}}tt | d d d+f | d d d,f fjd-d.}t||g||gg}|| d, }t 	|d/ |d0 ksJ t 	|d0 |d, ksJ d S )1NgmR?gDpTU?g     ?g_9?g     ?g      ?gUUu@gF^9?g      ?g$z|?g["8j@gUU@ga1?g["8@g}LRJ?gDpTU?gmR?g      @g=:r9?g["8@gAL0 @gUU@gy?gI?g9 @g["8
@g_9@g     @gB@gUU@gq1Pc1@g     @?ghs@gUU@gA!@gmR@g     @gbc@g     @?g9qa @gI?)r@   r1   g @r   r-   r   Tr   r   )
r   rG   r   ZvstackTr   r   Zclip_to_bboxto_polygonsrA   )ZhandZr0Zc0Zr1Zc1ZpolyZ	clip_rectZpoly_clippedr   r   r   (test_path_no_doubled_point_in_to_polygon  s>   0r   c                  C   s   ddgddgg} t | }t|jdddg  t|jdddd| g t| g  t|jdd| g ddgddgddgg} ddgddgddgddgg}t | }t|jddd|g t|jdddd| g t| |g t|jdd| g d S )	NrP   r   r]   )widthheightF)r   r   closed_only)r      )r   r   r   )datarJ   Zclosed_datar   r   r   test_path_to_polygons4  s"   r   c                  C   s   ddgddgg} t jt jg}t | }t | |}| }| }||us%J |j|jus-J ||us3J |j|jus;J |j|jusCJ d S Nr   r-   )r   rD   LINETOZdeepcopyr   r   Zvertsr   Zpath1Zpath2Z
path1_copyZ
path2_copyr   r   r   test_path_deepcopyI     
r   c                  C   s   ddgddgg} t jt jg}t | }t | |}| }| }||us%J |j|ju s-J ||us3J |j|ju s;J |j|ju sCJ d S r   )r   rD   r   copyr   r   r   r   r   r   test_path_shallowcopyX  r   r   phic                 C   s   g | ]}t g d | qS ))
r   r   r   -   <   K   Z   i   x      )r   rG   ).0Zdeltar   r   r   
<listcomp>g  s    r   )r   r   r-   c                 C   sx  g d}t  t| }tddg}||}||r#||s%J tddg}||}||r:||s<J |tddg}|tddg}||rX||sZJ |tddg}|tddg}||rv||sxJ ||sJ |tdd	g}|td
dg}||r||sJ |tddg}|tddg}||s||rJ |tddg}|tddg}||s||rJ |D ]*}|tddg}|td| dfd| dfg}||s||rJ q|D ]'}|tddg}|tdd| fdg}||s,||r.J q|D ]'}|tddg}|tdd| fdg}||rV||sXJ q2|tddg}|tg d}||rx||szJ |tddg}|tddg}||s||rJ |tddg}|tddg}||s||rJ d S )N)gh㈵>g:0yE>g|=g-q=)r   r   )r
   r   r+   r,   )r   r"   )r-   r"   r   rQ   )rQ   rQ   r.   )r"   r"   )r"   r   )r   r$   )r   r   r   r-   rQ   )r,   r	   r   )r-   r   )r   r   )r<   r-   )r:         )r@   r   )r@         @)r:   r   )r   ZAffine2Drotater   Zdeg2radr   Ztransform_pathintersects_path)r   Z	eps_arrayrW   abr   r   r   r   test_path_intersect_pathg  sZ   

"   r   offseti0ii  r   c                 C   sX   | }d|  }t ||}tj|jdd}tj|jdd}tj|d tj|d d S )Nih  r   )Zaxisr   r-   )r   Zarcr   minr   maxr5   Zassert_allclose)r   ZlowZhighr   ZminsZmaxsr   r   r   test_full_arc  s   r   c               	   C   s   t tddgddgddgddgddggtjg d	t jd
} t tddgddgddgddgddggtjg dt jd
}|| rEJ | |rLJ d S )NgƉ@g퟇@gЅ@g@g`m$@g;E@g6[@gч61@)r-   r
   r
   r
   O   )r4   g-Hߊ@gGN@g`؊@g{Kʠ@g
@)r-   r
   r
   r
   r
   )r   r   rG   Z	code_typer   Z	this_pathZoutline_pathr   r   r   !test_disjoint_zero_length_segment  s0   	

r   c                  C   s`   t tddgddgg} t tddgddgddgddgg}|| s'J | |s.J d S rF   )r   r   rG   r   r   r   r   r   "test_intersect_zero_length_segment  s    r   c                  C   s   t tjtjgtjtjggt jt jgt tjtjgtjtjggt tjtjgtjtjgtjtjgtjtjggt jt jt jt jgg} | D ]}|jdd}t|dksSJ |jd t j	ks]J qCd S )NT)Zremove_nansr-   r   )
r   r   rH   rD   	CLOSEPOLYCURVE3cleanedrI   r   r   )r   rJ   r   r   r   r   test_cleanup_closepoly  s   
 
r   )<r'   Znumpyr   Znumpy.testingr   r   Z
matplotlibr   Zmatplotlib.pathr   Zmatplotlib.patchesr   Zmatplotlib.testing.decoratorsr   Zmatplotlib.pyplotZpyplotrS   r   Zmatplotlib.backend_basesr   r   r   r*   r9   r>   rD   ZCURVE4r   r   Z_test_pathsZ_test_path_extentsZmarkZparametrizerh   rB   r   r   rE   rM   rZ   rp   r   r   r   r   r   r   r   r   r   r   r   r   Zconcatenater   ranger   r   r   r   r   r   r   r   <module>   s~    

&

		
%


	





#
Q
