a
    
d                     @   sP  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 ZAdS )g    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 sPJ ||u s\J t|| |	|u srJ |
|ks~J ||ksJ 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(   l/var/www/html/stable-diffusion-webui/venv/lib/python3.9/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 sFJ || gksTJ 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   sV  g d} g d}t jtdd  t| ddg W d    n1 sD0    Y  t jtdd" t| |g d W d    n1 s0    Y  t jtd	d t| |d
 W d    n1 s0    Y  t jtdd$ t| |g dg W d    n1 s0    Y  t jtdd$ t| |g dg W d    n1 sH0    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$    .0,4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    q1 s0    Y  qd 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   sP  d} d}t t dd| t dd|\}}| }| }| | }d| d  |d  }d|  | d|   d|  d }t||}t|j| t|j| t	|j
|ksJ t |j
dksJ t |j
|d ksJ t	|j|ksJ t |jdksJ t |j|d ksJ |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)	Znxnyr&   r'   npointsZ
ntrianglesZnedgesr@   r>   r(   r(   r)   test_delaunayb   s*    $ rT   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   )rS   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 sH0    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    *ra   zx, yr   rC   r      )r   r   r   )rC   rb   rC   )r   r   r   )rC   rb   rb   )r   r   r   r   r   r   )rC   rC   rC   rb   rC   rb   c                 C   s:   t t t| | W d    n1 s,0    Y  d S Nr9   r<   r(   r(   r)   !test_delaunay_insufficient_points   s    rd   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sJ qt| 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 rc   )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 rc   r<   ).0tri)rk   r@   ri   r(   r)   	<genexpr>   s   zCtest_delaunay_robust.<locals>.tris_contain_point.<locals>.<genexpr>)sumr   r@   ri   rk   rp   r)   tris_contain_point   s    z0test_delaunay_robust.<locals>.tris_contain_pointr   r   )rG   arrayasarrayr   r   )rj   Ztest_pointsrr   r@   Z
test_pointr(   rq   r)   test_delaunay_robust   s0    $ru   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   rv   r   r   rv   r   rf   )
r   r   r   rv   rv   rv   r   r   r   rf   r   r   r   )r   rD   r   r   r   rD   )r   rC   rD   )r   rD   rb   )rD   rV   rb   )rD   rC   	   )rV   rD   ry   )   rV   ry   )rC   rz   ry   rv   r   Zaxisy   k)
edgecolorszpoint colorsz   )
facecolorsr~   r   )
rG   rt   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   s  g d} g d}t  \}}tjtdd || | W d    n1 sL0    Y  tjtdd" || |g d W d    n1 s0    Y  tjtdd$ |j| |g dd	 W d    n1 s0    Y  tjtd
d& |j| |ddgdd W d    n1 s0    Y  tjtd
d& |j| |ddgdd W d    n1 sZ0    Y  tjtdd$ |j| |g dd W d    n1 s0    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')C)r   subplotsr.   r:   	TypeErrorr   r;   )r&   r'   figaxr(   r(   r)   test_tripcolor_color  s6    *02664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slJ d S )Ni!N,rU   )      ?rf   )clim)rG   rX   rY   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  || ||d W d    n1 sX0    Y  tjtdd" |j| |||d	 W d    n1 s0    Y  tjtdd" |j| |d
|d	 W d    n1 s0    Y  d S )Nr	   r   皙?rv   zAdditional positional paramr5   Zunused_positionalz"Positional parameter c .*no effectr   zinterpreted as c)r   r   r.   ZwarnsDeprecationWarningr   UserWarning)r&   r'   r   r   r   r(   r(   r)   test_tripcolor_warnings-  s    .0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   rs   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stJ |||}t	|g dA d S )BNrD   r   r   rD   r   rC   rD   r   r   rC   r   rb   rC   r   r   rb   r   rV   rb   rD   rC   rz   rC   ry   rz   rC   rb   ry   rb   rU   ry   rb   rV   rU   rV   r]   rU   rz   ry      ry      r   ry   rU   r   rU      r   rU   r]   r   r]      r   r   rz   rU   )r         ?      @      
@)r   r   rD   r
   rb   r
   rU   r
   r   r      r
   r
   r
   r
   r
   rv   )r
   r
   r
   r
   r
   r   r   rC   r
   rV   r
   r]   r
   r   r      )rv         ?      @rv   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   rb   rV   rU   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   rb   rD   rb   rC   )皙r   ?gffffff?gffffff?g333333@g333333@r   皙?)r
   r   r   r   r   r   r
   )r
   rb   rb   rb   rV   rV   r
   )r   r   r   r   r   r   r   r   )r   r   rC   r   )r   r   rD   )r   rD   rC   )r   rb   r   )r   rb   rD   rC   rb   rV   r   r   r   r   r   r   r   r   r   r   r   )gɿ皙?rg   g333333?)rv   rv   rv   rv   )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_trifinderF  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|
   q.g d}	|	}
t |	|
\}	}
|||fD ](}||	|
}t|jd gd gd  q|t 
dd!d}	g d"}
t |	|
\}	}
|||fD ]T}||	|
}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 ]Z}t ||	|
| }t |dt | ksrJ t ||d<t || ks<J q<d S )=NrD   Gz?)\(@r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rz   rU   geomkindr         @rb   )r   rf   r   r   )g      пr         ?r   Tr   )r   rf   r   r   r   )r   g)\(333333?c                    s,    | d d  |d d   |  |  S )Nrv   r   r(   r<   r   r   r   r(   r)   quad  s    ztest_triinterp.<locals>.quadc                    s0   d  | d  |  d |d  |   fS )Nr   rv   r(   r<   r   r(   r)   gradient_quad  s    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   rb   rC   r   rb   r   r   rb   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   matestrs   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rd||< n.|dkr0d||d < n|dkrFd||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 qd 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rt|
|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   ry   rV   r   r   r   r   r   r   r   rv   r         @g      @)N)rG   rs   r   r   ranger   float64r   )r  r   aybxZbyZcxcyr&   r'   r   r@   Zidofr   r  r  r  Zcaser   r(   r(   r)   !test_triinterpcubic_C1_continuity  sH    





&..r  c                  C   sd  dd } d\}}t jj| || }|  | }t|| D ]T}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||| qzt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_matrixf  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  rs   r   )r  r   r  matZ	mat_denseZitestr   r&   _Zi_zeroZj_zeror  r  r  Zdimr(   r(   r)   test_triinterpcubic_cg_solverb  s^    



r   c                  C   sp  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 ]}t || t ||  }t | | t ||  }	t	||	|}
tj
|
|dd}tj|}| }t |dd |dd d f< tdD ]6}t |dd	|d d |f   ||d d d f< qtt jt |ddt jddgt jd qtd S )N)rE   gˡE?rv   rE   rF   rD   r   r   r   r   r   r   r   r   r   r   r{   )rG   rs   r   r  rI   r   r   r  r   r   r   r  Z_DOF_estimator_geomZcompute_geom_weightsro   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&    4r&  c               
   C   sj  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 ]2}|j|||t jdt jd d\}t|| q0qVd S )NrE   r   r
   r   r   r   r   r   r2   r   r   r   r   r   r   r      r   r   r   rD   rU   r   )Z	tri_index)rG   rs   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  sJ    (


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 ]B}|| }|dkr||
|||< n|||}t|||  q֐qd}dD ]}|dkrN|| }|}||
 }|}n|}|| }|
}|| }t	|||j}t||	}t||	}tj||	dd}|||d}dD ]$}|| ||}t|||  qq&d S )Nr(  rU   333333?c                 S   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 
Nrv   r   r   rU   r   g      >@      @g      &@re   rG   hypotarctan2expr   rM   rL   r&   r'   Zr1Ztheta1Zr2Ztheta2r   r(   r(   r)   r     s    *&z)test_triinterp_transformations.<locals>.zffffff?r   r   FZendpoint.r   r{         rF   rW   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    
$



rA  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(  rU   r,  c                 S   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 r-  r/  r3  r(   r(   r)   r   l  s    *&z%test_tri_smooth_contouring.<locals>.zr4  r   r   Fr5  .r   r{   rD   subdivrE   rF   g?rv   z0.5)ZlwcolorZblack)levelscolors)rG   rI   r   r7  r8  r   r9  r  r   r   r?   r0  r   r   UniformTriRefinerrefine_fieldrQ   r   triplot
tricontour)r:  r;  r<  r   r=  r>  r  r*  r?  r@  refinertri_refiz_test_refirE  r(   r(   r)   test_tri_smooth_contouringe  s0    $

rN  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   r1  r   rM   rL   )r&   r'   Zr_sqr!  r   r(   r(   r)   dipole_potential  s    z2test_tri_smooth_gradient.<locals>.dipole_potential   rU   r   r4  r   r   Fr5  .r   r{   r   rB  equalz0.8)rD  rE   rF   g{Gz?Zhot)r^   rF   rF   rF   )rE  cmapZ
linewidthsri   r\   Zbluegy&1|?r   r	  )ZunitsZscaleZzorderrD  widthZ	headwidthZ
headlength)rG   rI   r   r7  r8  r   r9  r  r   r   r?   r0  r   r   rG  rH  r   r   r&   r'   r   r   ZgcaZ
set_aspectrI  rQ   mplZ	colormapsrJ  Zquiver)rO  r:  r;  r<  r=  r>  r&   r'   Vr@   rK  rL  rM  ZtciZExZEyZE_normrE  rR  r(   r(   r)   test_tri_smooth_gradient  sD    $


rV  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   rv   rE   r^   rE   rv   r   r6  rF   r   rw   rx   r   FFTr   r   gV͞^&?F)Zrescaler^   )rE   rF   r^   )rF   r	  r.  ry   c                 S   s   t | | t |  S rc   )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   rl  Q   R   S   b   r8   t   u   )rG   rs   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   rZ  Z	mask_flatZ
verif_maskZcorners_indexZcenter_indexr(   r(   r)   test_tritools  sJ    "

"





r~  c                  C   sj  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 ]r}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   r6  rF   r   r   Tr   rB  r   rz   r{   r   rE   rF   rE   rF   rE   rE   rF   rF   rw   r   r   r   r   r   r   r   )rG   rI   rH   rJ   r   rz  r   r   r   rG  refine_triangulationr&   r'   Zin1dZaroundr   r   ro   r   r   rt   r0  r
  rH  ZdstackZlexsortr   )r   rC  r&   r'   r   r@   rK  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)idsc                 C   sx   t jd dd df \}}t | d}t | d}t |}t||}t|}| ||}|j||dd d S )Nr   )ZtriinterpolatorrC  )	rG   Zmgridr7  r9  Z
zeros_liker   r   rG  rH  )r  r&   r'   r   rm   rK  r   r(   r(   r)   test_trirefine_masked1  s    


r  c                 C   s   g }t | d D ]n}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   rs   r   )r   rm   r  jr   r   r   dr(   r(   r)   r   C  s    r   c                  C   sL   t   } tjg dg dg dg dgd}| |dd usHJ dd S )Nr  r  rw   r   r   zb-z(triplot should return the artist it adds)r   r   r   r   r   rI  )r   r@   r(   r(   r)   test_triplot_returnR  s    r  c            
      C   s   t g dg dg} t | r$J t j| ddd}t |sBJ 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   rB  )	rG   rs   Z	isfortranr   r   rG  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_orientations  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 )NrW  rE   rv   r   r6  rF   r   rw   rx   r   rX  r   )	rG   rs   ry  r   rz  r   r   r{  Z_get_compressed_triangulation)r&   r'   r   r   r@   r}  r(   r(   r)   #test_trianalyzer_mismatched_indices  s    "
r  c                  C   sb   g d} g d}g d}t   tt$ t | ||ddg W d    n1 sT0    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:0    Y  tjtdd, tjg dgg gdddd W d    n1 s0    Y  g d	}g d
}tjtdd. tj||ddggdddd W d    n1 s0    Y  g dg}tjtdd, tj|||ddgddd W d    n1 s60    Y  tjtdd, tj|||ddggdd W d    n1 s0    Y  tjtdd, tj|||dddggd W d    n1 s0    Y  tj|||dddd}tjtdd |g  W d    n1 s 0    Y  ddgd fD ]@}tjtdd |	| W d    n1 sj0    Y  q6|	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 s0    Y  tjtdd  tj|dg W d    n1 s20    Y  g d}tj||}tjtdd |dd W d    n1 s0    Y  tjtdd tj  W d    n1 s0    Y  tj|}tjtdd" |dgddg W d    n1 s0    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   rT  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    (:<
<<<*.
 *0,*r  c                  C   s\   t g d} t g d}d}t| |}t| | || }t|jt|jksXJ d S )N)r   r   r   r   rv   )r   r   r   r   rv   g    _B)rG   rt   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^0    Y  tjtdd( t|dddtj	 g W d    n1 s0    Y  tjtdd& t|dddtj
g W d    n1 s0    Y  tjtdd0 t|tjjg d	g d
d W d    n1 s80    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)  rs   )r&   r'   r@   r(   r(   r)   test_tricontour_non_finite_z  s    464r  c                  C   sp   g d} g d}g d}t  \}}|| ||}|| ||}|j|jksPJ |||}|j|jkslJ d S )N)rE   rv   rF   )rE   rF   rE   )rF   r^   r   )r   r   r  rJ  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   rI  )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sVJ t|dksfJ |d |u svJ d S )Nr2   r3   r   label)r  r   r   )r   r   rI  Zget_legend_handles_labelsrK   )	r&   r'   r  r   r   linesmarkersZhandleslabelsr(   r(   r)   test_triplot_label6  s    
r  )BnumpyrG   Znumpy.testingr   r   r   Znumpy.ma.testutilsr)  Z	testutilsr   r.   r  rT  Zmatplotlib.pyplotZpyplotr   Zmatplotlib.trirm   r   Zmatplotlib.pathr   Zmatplotlib.testing.decoratorsr   r   r   r4   r=   rB   rT   r[   ra   r/   r0   rd   ru   r   r   r   r   r   r   r   r  r   r&  r+  rA  rN  rV  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


[
