o
    :a                     @   s  d dl Zd dlmZmZmZ d dlm  mZ	 d dl
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 Zdd Zd	d
 Ze
jdg g fdgdgfddgddgfg dg dfg dg dfg dg dfgdd Zdd Zedgdd Z dd Z!dd  Z"d!d" Z#d#d$ Z$d%d& Z%d'd( Z&d)d* Z'd+d, Z(ed-gd.d/d0d1d2 Z)ed3gd.d4d0d5d6 Z*d7d8 Z+d9d: Z,e
jjd;ej-ej.gd<d=gd>d?d@ Z/dAdB Z0dCdD Z1dEdF Z2dGdH Z3dIdJ Z4dKdL Z5dMdN Z6dOdP Z7dQdR Z8dSdT Z9dS )U    N)assert_array_equalassert_array_almost_equalassert_array_less)Path)image_comparisonc            	      C   sL  d} d}t t dd| t dd|\}}| }| }| | }d| d  |d  }d|  | d|   d|  d }t||}t|j| t|j| t	|j
|ksWJ t |j
dksaJ t |j
|d ksmJ t	|j|ksvJ t |jdksJ t |j|d ksJ |j}d |_t|j| tt |j
t | d S )	N                    ?         r   )npmeshgridlinspaceravelmtriTriangulationr   xylen	trianglesminmaxedges	neighbors
_neighborsr   uniquearange)	Znxnyr   r   npointsZ
ntrianglesZnedgestriangr    r"   E/usr/lib/python3/dist-packages/matplotlib/tests/test_triangulation.pytest_delaunay   s*   $ r$   c                  C   sx   d} d}d}t jd t j| }t j| }|| ||< || ||< t||}tt |jt t 	| | d S )N
      r      )
r   ZrandomZseedr   r   r   r   r   deleter   )r    Z	duplicateZduplicate_ofr   r   r!   r"   r"   r#   test_delaunay_duplicate_points9   s   r)   c                  C   sz   t ddd} t ddd}tt t| | W d    n1 s$w   Y  t | d} t |d}t| | d S )Nr	         $@          @g       @)r   r   pytestraisesRuntimeErrorr   r   appendr   r   r"   r"   r#   test_delaunay_points_in_lineM   s   r2   zx, yr   r   r      )r   r   r   )r   r3   r   )r   r   r   )r   r3   r3   )r   r   r   r   r   r   )r   r   r   r3   r   r3   c                 C   s<   t t t| | W d    d S 1 sw   Y  d S N)r-   r.   
ValueErrorr   r   r1   r"   r"   r#   !test_delaunay_insufficient_points[   s   "r6   c               
      s   t ddgddgddgddgddgd	d
gddgg} t ddgddgddgddgddgddgddgg}dd   fdd}t| d d df | d d df }|D ]}|||dks]J qRt| dd df | dd df }d S )NgLXz?g     gCM??g~9B.?g     g/7R?g9?g     ڿgHC?g     ڿgt?g     ڿg(\?gq=
ףpݿg?gzGڿffffff?gQ޿g)\(ܿ      ?皙?c                 S   s   t | |fj}t||S r4   )r   ZvstackTr   Zcontains_point)ZxtriZytrixy
tri_pointsr"   r"   r#   tri_contains_point   s   z0test_delaunay_robust.<locals>.tri_contains_pointc                    s   t  fdd jD S )Nc                 3   s(    | ]} j | j| V  qd S r4   r1   ).0tri)r=   r!   r;   r"   r#   	<genexpr>   s     zCtest_delaunay_robust.<locals>.tris_contain_point.<locals>.<genexpr>)sumr   r!   r;   r=   rB   r#   tris_contain_point   s   z0test_delaunay_robust.<locals>.tris_contain_pointr   r   )r   arrayasarrayr   r   )r<   Ztest_pointsrD   r!   Z
test_pointr"   rC   r#   test_delaunay_robustk   s0   $(rG   ztripcolor1.pngc                  C   s   t g d} t g d}t g dg dg dg dg dg dg d	g d
g dg dg
}t| ||}| d|  }| |j jdd}||j jdd}d| | }td tj||dd t	d td tj||dd t	d d S )N)
r         ?r   r   rH   r   r   rH   r   r8   )
r   r   r   rH   rH   rH   r   r   r   r8   r   r   r   )r   r   r   r   r   r   )r   r   r   )r   r   r3   )r   r&   r3   )r   r   	   )r&   r   rK   )   r&   rK   )r   rL   rK   rH   r   Zaxisy   k)
edgecolorszpoint colorsz   )
facecolorsrP   rR   )
r   rF   r   r   r   meanpltZsubplotZ	tripcolortitle)r   r   r   r!   ZCpointsZxmidZymidZCfacesr"   r"   r#   test_tripcolor   s&   


rV   c                  C   sh   t jg dg dgt jd} t g d}|  }t|d d df |d d df | j t||  d S )Nr   r   r   )r   r   r   Zdtype))r   r   )r   g?)r   r   )r   r   r   r   )r   rE   int32copyr   r   r   r   )r   ZpointsZold_trianglesr"   r"   r#   test_no_modify   s
   (r[   c            
      C   s  t t dt d\} }|  } | }g dg dg dg dg dg dg dg d	g d
g dg dg dg dg dg dg dg dg dg}t t|}d|dd< t| |||}| }g d}g d}t ||\}}| }| }|||}t	|g d ||d |d }t	|g d g d}g d}|||}t	|g d ddg}ddg}|||}t	|d d!g d}	g d"} d#d d d d |	dg}g d$g d%g d&g dg d'g d(g d)g d*g}t| ||}| }g d+}d,d-g}t ||\}}|||}t	|g d.g d/g d}	d#|	 d d d d dg} g d0}g d1g d2g d3g d4g d5g d6g d7g d*g}t| ||}| }d,d-g}g d+}t ||\}}|||}t	|d#d#gd d8gd d8gd d9gdd9gdd:gd#d#gg g d;} g d<}g d1g d=g}t| ||}| }g d>}g d?}|||}t	|g d@ |
dd g || ksJ |||}t	|g dA d S )BNr   r   r   r   r   r   r   r   r   r   r   r3   r   r   r   r3   r   r&   r3   r   r   rL   r   rK   rL   r   r3   rK   r3   r%   rK   r3   r&   r%   r&   r+   r%   rL   rK      rK      ri   rK   r%   rk   r%      rk   r%   r+   rn   r+      rn   r   rL   r%   )      ?      ?      @      
@)r   r   r   r3   rv   r%   rv   ri   rn      rv   rv   rv   rv   rv   rH   )rv   rv   rv   rv   rv   r   r   r   rv   r&   rv   r+   rv   rk   rq      )rH         ?      @rH   ry   rz   ry   ry   r	   r
   r,         @)r	   r	   r	   r{   r{   r{   r
   r,   ry   ry   ry   ry   )r   r   r   rk   rq   rx   r   rn   r3   r&   r%   r+   r	   r{   r   rx   ry   r   r   r   r   ry   ry   rv   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r3   r   r3   r   )皙皙??gffffff?gffffff?g333333@g333333@r   皙?)rv   r   r   r   r   r   rv   )rv   r3   r3   r3   r&   r&   rv   )ry   ry   r   r   r   r   ry   r   r   r   )r   r   r   )r   r   r   )r   r   r   )r   r   r   )r   r3   r   )r   r3   r   r   r3   r&   r   r   r   r   r   r   r   r   r   r   r   )gɿ皙?r9   g333333?)rH   rH   rH   rH   )rv   r   r   rv   )rv   rv   r   rv   )r   r   r   r   zerosr   r   r   get_trifinderr   set_mask)
r   r   r   maskr!   	trifinderxsystrisdeltar"   r"   r#   test_trifinder   s   


	



(

r   c                     s  t t dt d\} }|  } | }d|  d|  }g dg dg dg dg dg d	g d
g dg dg dg dg dg dg dg dg dg dg dg}t t|}d|dd< t| |||}t||}t	||}tj	||dd}t 
ddd}	g d}
t |	|
\}	}
|||fD ]}||	|
}t|d|	 d|
   qg d}	|	}
t |	|
\}	}
|||fD ]}||	|
}t|jd gd gd  qt 
dd!d}	g d"}
t |	|
\}	}
|||fD ])}||	|
}t|d|	 d|
   |	dk|	d#k |
dk |
d#k }t|j| qd$\  fd%d&} fd'd(}t g d)} t g d*}t g d+g d,g d-g d.g d/g d0g d1g d2g}t| ||}|| |}|| |}t 
d3d4d5}	t 
d3d4d5}
t |	|
\}	}
tj	||d6|d7}||	|
}t|||	|
 || |\}}|| |\}}t|| t|| d8}t t 
d3d4|d t 
d3d4|d \} }|  } | }|| |}tj| |t|d d9}t t 
d:d;d5t 
d:d;d5\}	}
|	 }	|
 }
t||}t	||}tj	||dd}||	|
}t ||	|
| }||fD ]-}t ||	|
| }t |dt | ks6J t ||d<t || ksGJ qd S )=Nr   Gz?)\(@r\   r]   r^   r_   r`   ra   rb   rc   rd   re   rf   rg   rh   rj   rl   rm   ro   rp   r   rL   r%   geomkindrr         @r3   )rr   r8   rt   r   )g      пrs         ?ru   Tr   )rr   r8   rs   r   r   )r   g)\(333333?c                    s,    | d d  |d d   |  |  S )NrH   r   r"   r1   abcr"   r#   quadT  s   ,ztest_triinterp.<locals>.quadc                    s0   d  | d  |  d |d  |   fS )Nr   rH   r"   r1   r   r"   r#   gradient_quadW  s   0z%test_triinterp.<locals>.gradient_quad)r   &jjZ? rh?r	   r
   r
   r	   )333333?HPs?X9v?r	   r	   r
   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r3   r   r   r3   r   r   r3   r   r   r	   r
   r   userr   dzr+   r   r   r   d   )r   r   r   r   r   r   r   r   LinearTriInterpolatorCubicTriInterpolatorr   r   r   r   matestrE   gradientmeshgrid_trianglesabsr   dot)r   r   zr   r   r!   linear_interpcubic_min_E
cubic_geomr   r   interpzsr   r   r   Z
cubic_userZ	interp_zsZinterp_dzsdxZinterp_dzsdyZdzsdxZdzsdynZdiff_linZ
diff_cubicr"   r   r#   test_triinterp%  s   


 





,
$

r   c                  C   s  ddd} d\}}d\}}d\}}t |||ddddg}t |||ddddg}t g dg d	g d
g dg dg dg dg dg}	t|||	}
tdD ]}t jdt jd}t jdt jd}t jdt jd}t jddgt jd}|d }d|||d f< |dkrd||< n|dkrd||d < n
|dkrd||d < tj|
|d||fd}| |||f|d d df  | |||f|d d df  | |||f|d d df  | ||| d || d f | ||| d || d f | ||| d || d f | ||| | d || | d f | |d| | | d d| | | d f | ||d|  | d |d|  | d f | ||| d|  d || d|  d f qQd S )Nc              	   S   s  d}d}d}|\}}||t t ddt j |  }||t t ddt j |  }	| |g|gd }
| |g|g\}}|dur\t|
|d  t|d |d  t|d |d  | ||	|
 }| ||	\}}|| }|| }t|||  t|||  t|||  dS )	aJ  
        Checks the continuity of interpolator (and its derivatives) near
        location loc. Can check the value at loc itself if *values* is
        provided.

        *interpolator* TriInterpolator
        *loc* location to test (x0, y0)
        *values* (optional) array [z0, dzx0, dzy0] to check the value at *loc*
           绽|=g      Y@r	   r   r   Nr   )r   cosr   pisinr   r   r   )interpolatorlocvaluesZn_starepsilonrO   Zloc_xZloc_yZstar_xZstar_yr   dzxdzyZdiff_zZtab_dzxZtab_dzyZdiff_dzxZdiff_dzyr"   r"   r#   check_continuity  s&   
""z;test_triinterpcubic_C1_continuity.<locals>.check_continuity)r   r   )r   r   )r   r   r	   r
   r   r   r   r   r   r   r   r   rK   r&   rX   r   r   r   r   r   r   rH   r{         @g      @r4   )r   rE   r   r   ranger   float64r   )r   axayZbxZbyZcxcyr   r   r   r!   Zidofr   r   r   r   caser   r"   r"   r#   !test_triinterpcubic_C1_continuity  sJ   


&..0r   c                  C   sb  dd } d\}}t jj| || }|  | }t|| D ]*}tj|| tjd}d||< t jj	||t|| dd\}}t
t||| qd\}	}
| ||\}}}}|d	||	k  d	||
k  }|d	||	k  d	||
k  }t||	|	d	 |
|
d	 gg}t||	d	 |	|
d	 |
gg}t|g d
g}t j||||| d || d f}|  | }t|| d D ].}tj|| d tjd}d||< t jj	||t|| d dd\}}t
t||| qtjdtjd}tjg dtjd}tjg dtjd}d}t j||||}|  | }t
|tjg dg dg dgtjd d S )Nc                 S   s  ||  }t t j|t jdt j|d t jdt jd|t jdt j||  t jdt j| |t jdg}t t j|t jdt jd|t jdt j|d t jdt j| |t jdt j||  t jdg}t dt j|t jd t j|d t jd t j|d t jd t j||  t jd t j||  t jd g}d||d| d  |d d|< d|d| d d| d  |d d|< |||| | | | ffS )z
        Return the sparse, (n*m, n*m) matrix in coo format resulting from the
        discretisation of the 2-dimensional Poisson equation according to a
        finite difference numerical scheme on a uniform (n, m) grid.
        rX   r   r   r	   r   Nr   )r   concatenater   rY   onesr   )r   mlrowscolsvalsr"   r"   r#   poisson_sparse_matrix  s&   """"(("*z<test_triinterpcubic_cg_solver.<locals>.poisson_sparse_matrix)ri   r   rX   r
   r   )Ar   x0tol)ri   1   r   )r
   r
   r
   r
   r   rx   )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   r   r   r   r   r   r   r   r   )r   r   )r
   r,   r	   )r,   r
         @)r	   r   r
   )r   triinterpolateZ_Sparse_Matrix_cooZcompress_cscZto_denser   r   r   r   Z_cgr   r   r   r   rE   rY   )r   r   r   ZmatZ	mat_denseZitestr   r   _Zi_zeroZj_zeror   r   r   Zdimr"   r"   r#   test_triinterpcubic_cg_solver  s^   



r   c                  C   sn  d\} }t | d|  ddg}t || ddg}t jdt jd}g dg dg}t dd	g}t dd	t j d
D ]z}t || t ||  }t | | t ||  }	t	||	|}
tj
|
|dd}tj|}| }t |dd |dd d f< tdD ]}t |dd	|d d |f   ||d d d f< qtt jt |ddt jddgt jd q:d S )N)r	   gˡE?rH   r	   r
   r   rX   )r   r   r   r   r   rn   r   r   r   r   r   rM   )r   rE   r   r   r   r   r   r   r   r   r   r   Z_DOF_estimator_geomZcompute_geom_weightsrA   r   r   r   r   )r   r   r   r   r   r   Zsum_wthetax_roty_rotr!   r   Zdof_estimatorZweightsitrir"   r"   r#    test_triinterpcubic_geom_weights(  s(   2r   c               
   C   sh  d} t g d}t ddddd| dg}ddgddgddgddgddgddgg}|D ]}|d | |d |  }|d  | |d |  }||}}d| d	|  }	g d
g dg dg dg dg dg dg dg}
t|||
}t t |jt |jd}t t |jt |jd}t 	||\}}|
 }|
 }| ||dk}t jjd| d	|  |d}t||	}t||	}tj||	dd}|||fD ]}|||}t|| qd}|j|df }|j|df }t |j| |j| d}t |j| |j| d}d| d	|  }|||fD ]}|j|||t jdt jd d\}t|| qq+d S )Nr	   r|   rv   r   r   r   r   r   r}   r~   r   r^   r   r   r   r      r   r   r   r   r%   rX   )Z	tri_index)r   rE   r   r   r   r   r   r   r   r   r   r   mar   r   r   r   Z_interpolate_multikeysr   rY   )r   r   y0ZtransformationsZtransformationr   r   r   r   r   r   r!   r   r   Zmask_outZ	zs_targetr   r   r   r   r   r   Zpt1Zpt2r"   r"   r#   test_triinterp_colinearB  sN   (


r   c                  C   s  d} d}d}dd }t |d|}t jd|  dt j |  | d	d
}t j|dt jf |dd}|d d dd df  t j|  7  < |t |  }|t |  }t	||}|||}	t ddd}
t ddd}t 
|
|\}
}|
 }
| }i }tdD ]}dt j |  | }t || t ||  }t | | t ||  }t ||
 t ||  }t | |
 t ||  }t	|||j}t||	}t||	}tj||	dd}|||d}dD ]}|| }|dkr||
|||< q|||}t|||  qqd}dD ]X}|dkr#|| }|}||
 }|}n|}|| }|
}|| }t	|||j}t||	}t||	}tj||	dd}|||d}dD ]}|| ||}t|||  qSqd S )Nr   r%   333333?c                 S      t d|  d| }t d|  d| }t |  d | d }t |  d | d }dt |d d d  d t d|  t |d d d d t d|   d	| d |d     }t || t |t |  S 
NrH   r   r   r%   r   g      >@      @g      &@r7   r   hypotarctan2Zexpr   r   r   r   r   Zr1Ztheta1Zr2Ztheta2r   r"   r"   r#   r        *&"z)test_triinterp_transformations.<locals>.zffffff?r   r   FZendpoint.r   rM         r
   r'   r   r   )ZlinZmin_Er   gZ$.Ar1   r   )r   r   r   repeatnewaxisr   flattenr   r   r   r   r   r   r   r   r   r   r   )n_anglesn_radii
min_radiusr   radiianglesr   r   triang0z0Zxs0Zys0Z	interp_z0Zi_angler   r   r   r   r   r!   r   r   r   Z
dic_interpZ
interp_keyr   ZinterpzZscale_factorZscaled_axisr"   r"   r#   test_triinterp_transformations  s   
$

	
r
  ztri_smooth_contouring.pngTg;On?)Zremove_textr   c                  C   s<  d} d}d}dd }t |d|}t jd|  dt j |  | d	d
}t j|dt jf |dd}|d d dd df  t j|  7  < |t |  }|t |  }t	||}|||}	|
t ||j jdd||j jdd|k  t|}
|
j|	dd\}}t ddd}tj|ddd tj|||dd d S )Nr   r%   r   c                 S   r   r   r   r   r"   r"   r#   r     r   z%test_tri_smooth_contouring.<locals>.zr   r   r   Fr   .r   rM   r   subdivr	   r
   g?rH   z0.5)ZlwcolorZblack)levelsZcolors)r   r   r   r   r  r   r  r   r   r   r   r   r   rS   UniformTriRefinerrefine_fieldr   rT   triplot
tricontour)r  r  r  r   r  r  r   r   r  r	  refinertri_refiz_test_refir  r"   r"   r#   test_tri_smooth_contouring  s0   $

r  ztri_smooth_gradient.pnggZd;O?c                  C   s  dd } d}d}d}t |d|}t jddt j |d	d
}t j|dt jf |dd}|d d dd df  t j| 7  < |t |  }|t |  }| ||}t	||}	|	
t ||	j jdd||	j jdd|k  t|	}
|
j|dd\}}t|	| }||	j|	j\}}t ||}t  t d tj|	dd t ddd}tjdd d}tj||||g dd tj|	j|	j|| || dddddddd  d S )!Nc                 S   sL   | d |d  }t || }t || }t || t |t |  S )zAn electric dipole potential V.r   )r   r   r   r   r   )r   r   Zr_sqr   r   r"   r"   r#   dipole_potential  s   "z2test_tri_smooth_gradient.<locals>.dipole_potential   r%   r   r   r   r   Fr   .r   rM   r   r  Zequalz0.8)r  r	   r
   g{Gz?Zhot)nameZlut)r,   r
   r
   r
   )r  cmapZ
linewidthsr;   r*   Zbluegy&1|?r{   r   )ZunitsZscaleZzorderr  widthZ	headwidthZ
headlength)r   r   r   r   r  r   r  r   r   r   r   r   r   rS   r  r  r   r   r   r   rT   figureZgcaZ
set_aspectr  r   cmZget_cmapr  Zquiver)r  r  r  r  r  r  r   r   Vr!   r  r  r  ZtciZExZEyZE_normr  r  r"   r"   r#   test_tri_smooth_gradient  sD   $


r  c                  C   s  t g d} t dddt d ddg}t jg dg dg d	gt jd
}t jg dtd
}tj| |||d}t|}t|j	t ddddt d   g t|j
ddt jdddt d  t jg| t g d} t g d}t jg dgt jd
}t| ||}t|}t|
 t dg d}dd }t dd|d } t || d|| d\} }|  } | }tj| |t|d d}t|}|d}t jdtd
}	g d}
d|	|
< t||	 t jdtd
}d|d< || |d}g d}d|	|< t||	 d S )Nr	   r
   rH   r	   r,   r	   rH   r{   r   r
   r   rI   rJ   rX   FFTr   F)Zrescaler,   )r	   r
   r,   )r
   r   r   rK   c                 S   s   t | | t |  S r4   )r   r   sign)r   r   r"   r"   r#   powerV  s   ztest_tritools.<locals>.powerr   rr   r   r      )r   r   r   r   rn   rq   rw   rx         "   #   ~                                    TP   ),   -   >   ?   N   O   r5  Q   R   S   b   c   t   u   )r   rE   sqrtrY   boolr   r   TriAnalyzerr   Zscale_factorsZcircle_ratiosr   Zmasked_arraynanr   r   r   r   Zget_flat_tri_maskr   r   r   )r   r   r   r   r!   analyserr   r#  Z	mask_flatZ
verif_maskZcorners_indexZcenter_indexr"   r"   r#   test_tritools9  sN   "

"





rH  c                  C   sh  d} d}t dd| d }t ||\}}| }| }t jd| d  td}d|| d d < tj||t| d |d}t	|}|j
|d	}|j}|j}	| |d  }
t dd|
d }t ||\}}| }| }t t |d
|  dt |d
|	  d}t|d |j}t j|j|j ddd }t j|j|j ddd }| }|||}|j| }t|| t g d}t g d}t||g dg dgt||g dg dgg}t |d |d }g }tdD ]8}t	|| }|j|dd	\}}t |j|j|fd }|t |d d df |d d df f }||g7 }qt|d |d  d S )Nr   r   r   r
   r   rX   T)r   r   r  rz   rL   rM   r{   r	   r
   r	   r
   r	   r	   r
   r
   rI   rW   r   r   r   r   r   r   )r   r   r   r   r   rD  r   r   r   r  refine_triangulationr   r   Zin1dZaroundr   r   rA   r   r   rF   r   r   r  ZdstackZlexsortr   )r   r  r   r   r   r!   r  Zrefi_triangZx_refiZy_refiZn_refiZx_verifZy_verifZind1dZ	refi_maskZrefi_tri_barycenter_xZrefi_tri_barycenter_yZ
tri_finderZrefi_tri_indicesZrefi_tri_maskr   Zxyz_dataiZrefined_triangZ	refined_zZxyzr"   r"   r#   test_trirefiner  sn   



*rN  r   ZlinearZcubic)Zidsc                 C   sx   t jd dd df \}}t | d}t | d}t |}t||}t|}| ||}|j||dd d S )Nr   )Ztriinterpolatorr  )	r   Zmgridr   r  Z
zeros_liker   r   r  r  )r   r   r   r   r?   r  r   r"   r"   r#   test_trirefine_masked  s   


rO  c                 C   s   g }t | d D ]7}t | d D ].}|||   }|d ||   }||d |   }|d |d |   }||||g|||gg7 }qqtj|tjdS )zU
    Return (2*(N-1)**2, 3) array of triangles to mesh (N, N)-point np.meshgrid.
    r   rX   )r   r   rE   rY   )r   r?   rM  jr   r   r   dr"   r"   r#   r     s   r   c                  C   sL   t   } tjg dg dg dg dgd}| |dd us$J dd S )NrI  rJ  rI   rW   r   zb-z(triplot should return the artist it adds)rT   r  Zadd_subplotr   r   r  )r   r!   r"   r"   r#   test_triplot_return  s   rR  c            
      C   s   t g dg dg} t | rJ t j| ddd}t |s!J t g d}t g d}t||| }t|||}t|}t|}|jdd	}|jdd	}	t|j|	j d S )
NrK  )r   r   r   TF)rZ   Zorder)g(\?gzG?gQ?g{Gz?)gQ@@gzGA@gQA@gףp=
A@r   r  )	r   rE   Z	isfortranr   r   r  rL  r   r   )
Z
triangles1Z
triangles2r   r   Ztriang1Ztriang2Zrefiner1Zrefiner2Zfine_triang1Zfine_triang2r"   r"   r#   ,test_trirefiner_fortran_contiguous_triangles  s   

rT  c            
      C   s   t ddd} tt jt | | \}}||d k|dk @ |dk@ }|| || }}t d}|t | |t |  }|t | |t |  }t	||}|j
}d |_|j
}	t||	 d S )Nr   r   r   r   g333333g333333   )r   r   mapr   r   Zradiansr   r   r   r   r   r   r   )
Zxir   r   wr   Zx1Zy1r!   Zqhull_neighborsZown_neighborsr"   r"   r#   test_qhull_triangle_orientation  s   
rX  c                  C   s   t g d} t dddt d ddg}t jg dg dg d	gt jd
}t jg dtd
}tj| |||d}t|}|  d S )Nr   r	   rH   r{   r   r
   r   rI   rJ   rX   r!  r   )	r   rE   rC  rY   rD  r   r   rE  Z_get_compressed_triangulation)r   r   r   r   r!   rG  r"   r"   r#   #test_trianalyzer_mismatched_indices  s   "
rY  c                  C   sd   g d} g d}g d}t   tt t | ||ddg W d    d S 1 s+w   Y  d S )N)r	   r
   r
   )r	   r	   r
   )r   r   r   r
   r	   )rT   r  r-   r.   r5   tricontourf)r   r   r   r"   r"   r#   "test_tricontourf_decreasing_levels  s   "r[  c               
   C   s  ddl m}  tjtdd tj  W d    n1 sw   Y  tjtdd tjg dgg gd d d d W d    n1 sBw   Y  g d}g d	}tjtd
d tj||ddggd d d d W d    n1 spw   Y  g dg}tjtdd tj|||ddgd d d W d    n1 sw   Y  tjtdd tj|||d dggd d W d    n1 sw   Y  tjtdd tj|||d d dggd W d    n1 sw   Y  tj|||d d d d}tjtdd |g  W d    n	1 sw   Y  tjtdd |	ddg W d    n	1 s,w   Y  tjtdd tj
  W d    n	1 sIw   Y  tjtdd tj
|dg W d    n	1 siw   Y  g d}tj
||}tjtdd |dd W d    n	1 sw   Y  tjtdd tj  W d    n	1 sw   Y  tj|}tjtdd |dgddg W d    d S 1 sw   Y  d S )Nr   )_triz.function takes exactly 7 arguments \(0 given\)matchz,x and y must be 1D arrays of the same lengthr   F)r   r   r   )r   r   r   z.triangles must be a 2D array of shape \(\?,3\)r   zCmask must be a 1D array with the same length as the triangles arrayz,edges must be a 2D array with shape \(\?,2\)zGneighbors must be a 2D array with the same shape as the triangles arrayrv   z<z array must have same length as triangulation x and y arrayz.function takes exactly 2 arguments \(0 given\)z?z must be a 1D array with the same length as the x and y arraysz(filled contour levels must be increasingz-function takes exactly 1 argument \(0 given\)z*x and y must be array-like with same shape)
matplotlibr\  r-   r.   	TypeErrormplr   r5   Zcalculate_plane_coefficientsr   ZTriContourGeneratorZcreate_filled_contourZTrapezoidMapTriFinderZ	find_many)r\  r   r   r   r!   r   Ztcgr   r"   r"   r#   test_internal_cpp_api  s    
$rb  c                  C   s\   t g d} t g d}d}t| |}t| | || }t|jt|jks,J d S )N)r   r   r   r   rH   )r   r   r   r   rH   g    _B)r   rF   r   r   r   r   )r   r   offsetr!   Ztriang_offsetr"   r"   r#   test_qhull_large_offsetm  s   rd  c                  C   sF  g d} g d}t | |}t  tjtdd t|dddtj	g W d    n1 s/w   Y  tjtdd t|dddtj	 g W d    n1 sRw   Y  tjtdd t|dddtj
g W d    n1 stw   Y  tjtdd t|tjjg d	g d
d W d    d S 1 sw   Y  d S )Nr   r   zCz array must not contain non-finite values within the triangulationr]  r   r   r   z9z must not contain masked points within the triangulation)r   r   r   r   )r   r   r   r   r   )r   r   rT   r  r-   r.   r5   rZ  r   infrF  r   rE   )r   r   r!   r"   r"   r#   test_tricontour_non_finite_zx  s    ""rf  c                  C   sp   g d} g d}g d}t  \}}|| ||}|| ||}|j|jks(J |||}|j|jks6J d S )N)r	   rH   r
   )r	   r
   r	   )r
   r,   r{   )rT   ZsubplotsrZ  r  Z_contour_generator)r   r   r   Zfigr   Ztcs1Ztcs2Ztcs3r"   r"   r#   test_tricontourset_reuse  s   rg  ):Znumpyr   Znumpy.testingr   r   r   Znumpy.ma.testutilsr   Z	testutilsr   r-   r_  ra  Zmatplotlib.cmr  Zmatplotlib.pyplotZpyplotrT   Zmatplotlib.trir?   r   Zmatplotlib.pathr   Zmatplotlib.testing.decoratorsr   r$   r)   r2   ZmarkZparametrizer6   rG   rV   r[   r   r   r   r   r   r   r
  r  r  rH  rN  r   r   rO  r   rR  rT  rX  rY  r[  rb  rd  rf  rg  r"   r"   r"   r#   <module>   sp    *

-

g_VN>]
&
498


S