o
    i                     @   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mZ G dd dZdd Zd	d
 Zdd 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/d0 Z)d1d2 Z*d3d4 Z+d5d6 Z,d7d8 Z-d9d: Z.ed;gd<d=d>d?d@ Z/edAgd<dBd>dCdD Z0dEdF Z1dGdH Z2e
jj dIej3ej4gdJdKgdLdMdN Z5dOdP Z6dQdR Z7dSdT Z8dUdV Z9dWdX Z:dYdZ Z;d[d\ Z<d]d^ Z=d_d` Z>dadb Z?e dcdd Z@dedf ZAdgdh ZBdidj ZCdS )k    N)assert_array_equalassert_array_almost_equalassert_array_less)Path)image_comparisoncheck_figures_equalc                   @   s   e Zd Zg dZg dZg dg dgZddgZej	deegi eeddgfeeegi eeedgfeege
ed	eeedgfeege
ed
eedegfeeege
ed
eeeegfeege
eedeeeegfgdd ZdS )TestTriangulationParamsr      r   r   r
   r   r   r   r      r   r      FTzargs, kwargs, expectedN	trianglesmaskr   r   c                 C   s   ddg}ddd}t j|| i ||\}}}}	}
}|\}}}}||u s(J ||u s.J t|| |	|u s9J |
|ks?J ||ksEJ d S )Nr   r   r   4)ab)mtriTriangulation_extract_triangulation_paramsr   )selfargskwargsexpectedZ
other_argsZother_kwargsx_y_
triangles_mask_args_kwargs_xyr   r    r(   r/var/www/html/eduruby.in/lip-sync/lip-sync-env/lib/python3.10/site-packages/matplotlib/tests/test_triangulation.py!test_extract_triangulation_params   s   	

z9TestTriangulationParams.test_extract_triangulation_params)__name__
__module____qualname__r&   r'   r   r   pytestmarkparametrizedictr*   r(   r(   r(   r)   r      s    r   c                  C   sX   dg} g dg dg dg| g}t j|i \}}}}}}|d u s#J || gks*J d S )NTr   r   r   r   r   r   r   )r   r   r   )r   r   r    r!   r"   r#   r$   r%   r(   r(   r)   *test_extract_triangulation_positional_mask+   s   r4   c                  C   sT  g d} g d}t jtdd t| ddg W d    n1 s"w   Y  t jtdd t| |g d W d    n1 sBw   Y  t jtd	d t| |d
 W d    n1 s`w   Y  t jtdd t| |g dg W d    n1 sw   Y  t jtdd t| |g dg W d    d S 1 sw   Y  d S )Nr	   r   zx and y must be equal-lengthmatchr   r   z>triangles must be a \(N, 3\) int array, but found shape \(3,\)r   z3triangles must be a \(N, 3\) int array, not 'other'otherzfound value 99)r   r   c   zfound value -1)r   r   r
   r.   raises
ValueErrorr   r   r&   r'   r(   r(   r)   test_triangulation_init7   s.   "r=   c               	   C   s   g d} g d}g dg dg}t | ||}t|jg dg dg |ddg t|jddg |d  |jd u s>J d	}g d
dgdgddfD ]}tjt|d || W d    n1 sdw   Y  qKd S )Nr	   r   r   )r   r   r   )r
   r
   r   )r
   r
   r   FTz3mask array must have same length as triangles array)FTFr5   )	r   r   r   	neighborsset_maskr   r.   r:   r;   )r&   r'   r   triangmsgr   r(   r(   r)   test_triangulation_set_maskK   s    
rB   c            	      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   r   r   r   )npmeshgridlinspaceravelr   r   r   r&   r'   lenr   minmaxedgesr>   
_neighborsr   uniquearange)	nxnyr&   r'   npointsZ
ntrianglesZnedgesr@   r>   r(   r(   r)   test_delaunayb   s*   $ rU   c                  C   sx   d} d}d}t jd t j| }t j| }|| ||< || ||< t||}tt |jt t 	| | d S )N
      r      )
rG   randomseedr   r   r   rP   r   deleterQ   )rT   Z	duplicateZduplicate_ofr&   r'   r@   r(   r(   r)   test_delaunay_duplicate_points   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 )NrE         $@          @g       @)rG   rI   r.   r:   RuntimeErrorr   r   appendr<   r(   r(   r)   test_delaunay_points_in_line   s   rb   zx, yr   rC   r      )r   r   r   )rC   rc   rC   r   r   r   )rC   rc   rc   )r   r   r   r   r   r   )rC   rC   rC   rc   rC   rc   c                 C   s<   t t t| | W d    d S 1 sw   Y  d S Nr9   r<   r(   r(   r)   !test_delaunay_insufficient_points   s   "rf   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 re   )rG   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 re   r<   ).0tri)rm   r@   rk   r(   r)   	<genexpr>   s     zCtest_delaunay_robust.<locals>.tris_contain_point.<locals>.<genexpr>)sumr   r@   rk   rm   rr   r)   tris_contain_point   s   z0test_delaunay_robust.<locals>.tris_contain_pointr   r   )rG   arrayasarrayr   r   )rl   Ztest_pointsrt   r@   Z
test_pointr(   rs   r)   test_delaunay_robust   s0   $(rw   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   rx   r   r   rx   r   rh   )
r   r   r   rx   rx   rx   r   r   r   rh   r   r   r   )r   rD   r   r   r   rD   )r   rC   rD   )r   rD   rc   )rD   rW   rc   )rD   rC   	   )rW   rD   r{   )   rW   r{   )rC   r|   r{   rx   r   Zaxisy   k)
edgecolorszpoint colorsz   )
facecolorsr   r   )
rG   rv   r   r   r   meanpltZsubplot	tripcolortitle)r&   r'   r   r@   ZCpointsZxmidZymidZCfacesr(   r(   r)   test_tripcolor   s&   


r   c                  C   s6  g d} g d}t  \}}tjtdd || | W d    n1 s&w   Y  tjtdd || |g d W d    n1 sFw   Y  tjtdd |j| |g dd	 W d    n1 sgw   Y  tjtd
d |j| |ddgdd W d    n1 sw   Y  tjtd
d |j| |ddgdd W d    n1 sw   Y  tjtdd |j| |g dd W d    n1 sw   Y  tjtdd || |ddgd W d    n1 sw   Y  || |g d |j| |g ddd || |ddg |j| |ddgd	 d S )Nr	   r   z!tripcolor\(\) missing 1 required r5   z!The length of c must match eitherr   r   r   z,length of facecolors must match .* triangles)r   r   r   rD   r   z-'gouraud' .* at the points.* not at the facesr   r   Zgouraud)r   shading)r   z+positional.*'c'.*keyword-only.*'facecolors')CzUnexpected positional parameterZunused_positional)r   subplotsr.   r:   	TypeErrorr   r;   )r&   r'   figaxr(   r(   r)   test_tripcolor_color  sH   r   c                  C   sp   t jd t jdt jdt jd} }}t  }d}|j| |||dj}|j	|j
f|ks6J d S )Ni!N,rV   )      ?rh   )clim)rG   rY   rZ   Zrandr   figureadd_subplotr   normZvminZvmax)r   r   cr   r   r   r(   r(   r)   test_tripcolor_clim%  s   (r   c                  C   s   g d} g d}ddg}t  \}}tjtdd |j| |||d W d    n1 s-w   Y  tjtdd |j| |d|d W d    d S 1 sNw   Y  d S )	Nr	   r   皙?rx   z"Positional parameter c .*no effectr5   r   zinterpreted as c)r   r   r.   ZwarnsUserWarningr   )r&   r'   r   r   r   r(   r(   r)   test_tripcolor_warnings/  s   "r   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   )rG   ru   int32copyr   r   rN   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 )BNrD   r   r   rD   r   rC   rD   r   r   rC   r   rc   rC   r   r   rc   r   rW   rc   rD   rC   r|   rC   r{   r|   rC   rc   r{   rc   rV   r{   rc   rW   rV   rW   r^   rV   r|   r{      r{      r   r{   rV   r   rV      r   rV   r^   r   r^      r   r   r|   rV   )r         ?      @      
@)r   r   rD   r
   rc   r
   rV   r
   r   r      r
   r
   r
   r
   r
   rx   )r
   r
   r
   r
   r
   r   r   rC   r
   rW   r
   r^   r
   r   r      )rx         ?      @rx   r   r   r   r   rE   rF   r_         @)rE   rE   rE   r   r   r   rF   r_   r   r   r   r   )r   r   rD   r   r   r   r   r   rc   rW   rV   r^   rE   r   r   r   r   r   r   r   r   r   r   r
   r2   r   r   r   r   rD   r   r   r   rC   r   rD   rC   r   rC   rc   rD   rc   rC   )皙r   ?gffffff?gffffff?g333333@g333333@r   皙?)r
   r   r   r   r   r   r
   )r
   rc   rc   rc   rW   rW   r
   )r   r   r   r   r   r   r   r   )r   r   rC   r   )r   r   rD   )r   rD   rC   )r   rc   r   )r   rc   rD   rC   rc   rW   r   r   r   r   r   r   r   r   r   r   r   )gɿ皙?ri   g333333?)rx   rx   rx   rx   )r
   r   r   r
   )r
   r
   r   r
   )rG   rH   rQ   rJ   zerosrK   r   r   get_trifinderr   r?   )
r&   r'   r   r   r@   	trifinderxsystrisdeltar(   r(   r)   test_trifinderE  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 )=NrD   Gz?)\(@r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r|   rV   geomkindr         @rc   )r   rh   r   r   )g      пr         ?r   Tr   )r   rh   r   r   r   )r   g)\(333333?c                    s,    | d d  |d d   |  |  S )Nrx   r   r(   r<   r   r   r   r(   r)   quad  s   ,ztest_triinterp.<locals>.quadc                    s0   d  | d  |  d |d  |   fS )Nr   rx   r(   r<   r   r(   r)   gradient_quad  s   0z%test_triinterp.<locals>.gradient_quad)r   &jjZ? rh?rE   rF   rF   rE   )333333?HPs?X9v?rE   rE   rF   rF   r   r   r   rD   rD   r   r   rD   r   rC   r   rC   r   rc   rC   r   rc   r   r   rc   r   r   rE   rF   rC   userr   dzr^   r   r   r   d   )rG   rH   rQ   rJ   r   rK   r   r   LinearTriInterpolatorCubicTriInterpolatorrI   r   r   r   matestru   gradientmeshgrid_trianglesabsrM   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@rE   r   r   Nr   )rG   cosrI   pisinr   r   r   )interpolatorlocvaluesZn_starepsilonr   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   rE   rF   r   r   r   r   r   r   r   r   r{   rW   r   r   r   r   r   r   r   rx   r         @g      @re   )rG   ru   r   r   ranger   float64r   )r	  r   ay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.
        r   r   rD   rE   r   Nr   )rG   concatenaterQ   r   onesr  )r   mlrowscolsvalsr(   r(   r)   poisson_sparse_matrixe  s&   """"(("*z<test_triinterpcubic_cg_solver.<locals>.poisson_sparse_matrix)r   rD   r   rF   r   )Ar   x0tol)r   1   r   )rF   rF   rF   rF   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   )rF   r_   rE   )r_   rF         @)rE   r  rF   )r   _triinterpolateZ_Sparse_Matrix_cooZcompress_cscZto_denser  rG   r   r  Z_cgr   r   r  r  ru   r   )r  r   r  matZ	mat_denseZitestr   r&   _Zi_zeroZj_zeror  r  r  dimr(   r(   r)   test_triinterpcubic_cg_solvera  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)rE   gˡE?rx   rE   rF   rD   r   r   r   r   r   r   r   r   r   r   r}   )rG   ru   r   r  rI   r  r   r  r   r   r   r  Z_DOF_estimator_geomZcompute_geom_weightsrq   r  r   rL   r   )r   r  r&   r'   r   r   Zsum_wthetax_roty_rotr@   r   Zdof_estimator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 )NrE   r   r
   r   r   r   r   r   r2   r   r   r   r   r   r   r      r   r   r   rD   rV   r   )Z	tri_index)rG   ru   r   r   rI   rL   r&   rM   r'   rH   rJ   r   mar   r   r   r   Z_interpolate_multikeysr  r   )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_colinear  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+  rV   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 
Nrx   r   r   rV   r   g      >@      @g      &@rg   rG   hypotarctan2expr   rM   rL   r&   r'   r1Ztheta1r2Ztheta2r   r(   r(   r)   r        *&"z)test_triinterp_transformations.<locals>.zffffff?r   r   FZendpoint.r   r}         rF   rX   r   r   )ZlinZmin_Er   gZ$.Ar<   r&   )rG   rI   r  repeatnewaxisr   flattenr  r   r   rH   rJ   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   
$

	
rH  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+  rV   r/  c                 S   r0  r1  r3  r7  r(   r(   r)   r   k  r:  z%test_tri_smooth_contouring.<locals>.zr;  r   r   Fr<  .r   r}   rD   subdivrE   rF   g?rx   z0.5)Zlwcolorblack)levelscolors)rG   rI   r  r>  r?  r   r@  r  r   r   r?   r4  r   r   UniformTriRefinerrefine_fieldrQ   r   triplot
tricontour)rA  rB  rC  r   rD  rE  r  r-  rF  rG  refinertri_refiz_test_refirM  r(   r(   r)   test_tri_smooth_contouringd  s0   $

rV  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 }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   )rG   r5  r   rM   rL   )r&   r'   Zr_sqr$  r   r(   r(   r)   dipole_potential  s   "z2test_tri_smooth_gradient.<locals>.dipole_potential   rV   r   r;  r   r   Fr<  .r   r}   r   rI  equalz0.8)rK  rE   rF   g{Gz?Zhot)r_   rF   rF   rF   )rM  cmapZ
linewidthsrk   r]   bluegy&1|?r   r
  )ZunitsscaleZzorderrK  widthZ	headwidthZ
headlength)rG   rI   r  r>  r?  r   r@  r  r   r   r?   r4  r   r   rO  rP  r   r   r&   r'   r   r   ZgcaZ
set_aspectrQ  rQ   mplZ	colormapsrR  Zquiver)rW  rA  rB  rC  rD  rE  r&   r'   Vr@   rS  rT  rU  ZtciZExZEyZE_normrM  rZ  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	d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rE   rF   rx   rE   r_   rE   rx   r   r=  rF   r   ry   rz   r   FFTr   r   gV͞^&?F)Zrescaler_   )rE   rF   r_   )rF   r
  r2  r{   c                 S   s   t | | t |  S re   )rG   r   sign)r&   r   r(   r(   r)   power  s   ztest_tritools.<locals>.powerr   r   r      )r   r   r   r   r   r   r   r         "   #   ~                                    TP   ),   -   >   ?   N   O   rv  Q   R   S   b   r8   t   u   )rG   ru   sqrtr   boolr   r   TriAnalyzerr   Zscale_factorsZcircle_ratiosr,  Zmasked_arraynanrI   rH   rJ   r   Zget_flat_tri_maskr   r   r?   )r&   r'   r   r   r@   analyserr   rd  Z	mask_flatZ
verif_maskZcorners_indexZcenter_indexr(   r(   r)   test_tritools  sJ   "

"





r  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=  rF   r   r   Tr   rI  r   r|   r}   r   rE   rF   rE   rF   rE   rE   rF   rF   ry   r   r   r   r   r   r   r   )rG   rI   rH   rJ   r   r  r   r   r   rO  refine_triangulationr&   r'   isinZaroundr   r   rq   r   r   rv   r4  r  rP  ZdstackZlexsortr   )r   rJ  r&   r'   r   r@   rS  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_trirefine  sn   



*r  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triinterpolatorrJ  )	rG   Zmgridr>  r@  Z
zeros_liker   r   rO  rP  )r  r&   r'   r   ro   rS  r   r(   r(   r)   test_trirefine_masked0  s   


r  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   r   )r  rG   ru   r   )r   ro   r  jr   r   r   dr(   r(   r)   r   B  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 )Nr  r  ry   r   r   zb-z(triplot should return the artist it adds)r   r   r   r   r   rQ  )r   r@   r(   r(   r)   test_triplot_returnQ  s   r  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 )
Nr  )r   r   r   TF)r   order)g(\?gzG?gQ?g{Gz?)gQ@@gzGA@gQA@gףp=
A@r   rI  )	rG   ru   Z	isfortranr   r   rO  r  r   r   )
Z
triangles1Z
triangles2r&   r'   Ztriang1Ztriang2Zrefiner1Zrefiner2Zfine_triang1Zfine_triang2r(   r(   r)   ,test_trirefiner_fortran_contiguous_triangles[  s   

r  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   )rG   rI   maprJ   rH   radiansr   r  r   r   r>   rO   r   )
xir&   r'   wr$  x1y1r@   Zqhull_neighborsZown_neighborsr(   r(   r)   test_qhull_triangle_orientationr  s   
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|}|  d S )Nra  rE   rx   r   r=  rF   r   ry   rz   r   rb  r   )	rG   ru   r  r   r  r   r   r  Z_get_compressed_triangulation)r&   r'   r   r   r@   r  r(   r(   r)   #test_trianalyzer_mismatched_indices  s   "
r  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)rE   rF   rF   )rE   rE   rF   )r   r   r   rF   rE   )r   r   r.   r:   r;   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  ddgd fD ] }tjtdd |	| W d    n	1 s2w   Y  q|	dg t
| td |	d t
| ddgddgddgg tjtdd tj  W d    n	1 svw   Y  tjtdd tj|dg W d    n	1 sw   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 sw   Y  d S )Nr   )_triz1__init__\(\): incompatible constructor arguments.r5   z,x and y must be 1D arrays of the same lengthr   r(   F)r   r   r   r3   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 arrayr
   zMz must be a 1D array with the same length as the triangulation x and y arraysT)r   r   r   z?z must be a 1D array with the same length as the x and y arraysz(filled contour levels must be increasingz*x and y must be array-like with same shape)
matplotlibr  r.   r:   r   r^  r   r;   Zcalculate_plane_coefficientsr?   r   Z	get_edgesrG   emptyZTriContourGeneratorZcreate_filled_contourZTrapezoidMapTriFinderZ	find_many)	r  r&   r'   r   r@   r   r   Ztcgr   r(   r(   r)   test_internal_cpp_api  s    

 $r  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   rx   )r   r   r   r   rx   g    _B)rG   rv   r   r   rK   r   )r&   r'   offsetr@   Ztriang_offsetr(   r(   r)   test_qhull_large_offset  s   r  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 triangulationr5   r   r   r   z9z must not contain masked points within the triangulation)r   r   r   r   )r   r   r   r   r   )r   r   r   r   r.   r:   r;   r  rG   infr  r,  ru   )r&   r'   r@   r(   r(   r)   test_tricontour_non_finite_z  s    ""r  c                  C   sp   g d} g d}g d}t  \}}|| ||}|| ||}|j|jks(J |||}|j|jks6J d S )N)rE   rx   rF   )rE   rF   rE   )rF   r_   r   )r   r   r  rR  Z_contour_generator)r&   r'   r   r   r   Ztcs1Ztcs2Ztcs3r(   r(   r)   test_tricontourset_reuse  s   r  c                 C   sJ   g d}g d}g dg}|   j|||dd |  j|||dd d S )Nr2   r3   r   z--)Zls)Z	linestyle)r   rQ  )Zfig_testZfig_refr&   r'   datar(   r(   r)   test_triplot_with_ls,  s
   
r  c            	      C   sz   g d} g d}g dg}t  \}}|j| ||dd\}}| \}}|dgks+J t|dks3J |d |u s;J d S )Nr2   r3   r   label)r  r   r   )r   r   rQ  Zget_legend_handles_labelsrK   )	r&   r'   r  r   r   linesmarkersZhandleslabelsr(   r(   r)   test_triplot_label5  s   
r  c                  C   s4  g d} g d}t | |}t \}}|j|g ddgd}| }t|dks+J ddgddgddgg}t|d j| t	|d j
g d	 t|d jd
d|g |j|g ddgd}| }t|dkskJ ddgddgddgddgddgg}t|d j| t	|d j
g d t|d  |g d S )Nr   rD   rD   r   r   r   r   rD   rD   r   r   r   r   r   r   rx   rM  r   r   r   rd   F)Zclosed_onlyr   r   r   r   r   r   r   r   r   r   r|  )r   r   r   r   rR  	get_pathsrK   r   verticesr   codesto_polygonsr&   r'   r@   r!  r   cspathsZexpected_verticesr(   r(   r)   test_tricontour_pathA  s(   "r  c                  C   s  g d} g d}t | |}t \}}|j|g dddgd}| }t|dks,J ddgddgddgddgddgg}t|d	 j| t	|d	 j
g d
 t|d	  |g |j|g dddgd}| }t|dksqJ dd	gddgd	dgd	d	gdd	gg}t|d	 j| t	|d	 j
g d
 t|d	  |g |j|g dddgd}| }t|dksJ 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
}t|d	 j| t	|d	 j
g d t|d	  t|dg d S )Nr  r  r  rx   r   r  r   r   r   r  r  r   g      rD   )
r   r   r   r   r|  r   r   r   r   r|  rC   )r   r   r   r   r  r  rK   r   r  r   r  r  rG   splitr  r(   r(   r)   test_tricontourf_path[  s6   "" r  )DnumpyrG   Znumpy.testingr   r   r   Znumpy.ma.testutilsr,  Z	testutilsr   r.   r  r^  Zmatplotlib.pyplotZpyplotr   Zmatplotlib.triro   r   Zmatplotlib.pathr   Zmatplotlib.testing.decoratorsr   r   r   r4   r=   rB   rU   r\   rb   r/   r0   rf   rw   r   r   r   r   r   r   r   r  r#  r)  r.  rH  rV  r`  r  r  r   r   r  r   r  r  r  r  r  r  r  r  r  r  r  r  r  r(   r(   r(   r)   <module>   s    *

-


g_VN>]
&
488


[
