a
    s=ic.                     @   sH  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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/d0 Z)d1d2 Z*d3d4 Z+d5d6 Z,d7d8 Z-ed9gd:d;d<d=d> Z.ed?gd:d@d<dAdB Z/dCdD Z0dEdF Z1e
jjdGej2ej3gdHdIgdJdKdL Z4dMdN Z5dOdP Z6dQdR Z7dSdT Z8dUdV Z9dWdX Z:dYdZ Z;d[d\ Z<d]d^ Z=d_d` Z>e dadb Z?dcdd Z@dS )e    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_argsother_kwargsx_y_
triangles_mask_args_kwargs_xyr   r    r)   t/home/droni/.local/share/virtualenvs/DPS-5Je3_V2c/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    r5   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   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edges	neighbors
_neighborsr   uniquearange)	nxnyr'   r(   npointsZ
ntrianglesZnedgestriangrK   r)   r)   r*   test_delaunayK   s*    $ rS   c                  C   sx   d} d}d}t jd t j| }t j| }|| ||< || ||< t||}tt |jt t 	| | d S )N
      r      )
rC   randomseedr   r   r   rM   r   deleterN   )rQ   Z	duplicateZduplicate_ofr'   r(   rR   r)   r)   r*   test_delaunay_duplicate_pointsu   s    rZ   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 )NrA         $@          @g       @)rC   rE   r/   r;   RuntimeErrorr   r   appendr=   r)   r)   r*   test_delaunay_points_in_line   s    *r`   zx, yr   r?   r      )r   r   r   )r?   ra   r?   )r   r   r   )r?   ra   ra   )r   r   r   r   r   r   )r?   r?   r?   ra   r?   ra   c                 C   s:   t t t| | W d    n1 s,0    Y  d S Nr:   r=   r)   r)   r*   !test_delaunay_insufficient_points   s    rc   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 rb   )rC   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 rb   r=   ).0tri)rj   rR   rh   r)   r*   	<genexpr>   s   zCtest_delaunay_robust.<locals>.tris_contain_point.<locals>.<genexpr>)sumr   rR   rh   rj   ro   r*   tris_contain_point   s    z0test_delaunay_robust.<locals>.tris_contain_pointr   r   )rC   arrayasarrayr   r   )ri   Ztest_pointsrq   rR   Z
test_pointr)   rp   r*   test_delaunay_robust   s0    $rt   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   ru   r   r   ru   r   re   )
r   r   r   ru   ru   ru   r   r   r   re   r   r   r   )r   r@   r   r   r   r@   )r   r?   r@   )r   r@   ra   )r@   rU   ra   )r@   r?   	   )rU   r@   rx   )   rU   rx   )r?   ry   rx   ru   r   Zaxisy   k)
edgecolorszpoint colorsz   )
facecolorsr}   r   )
rC   rs   r   r   r   meanpltZsubplot	tripcolortitle)r'   r(   r   rR   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 r6   z!The length of C must match eitherr   r   r   z,length of facecolors must match .* triangles)r   r   r   r@   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,rT   )      ?re   )clim)rC   rW   rX   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   皙?ru   zAdditional positional paramr6   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   )rC   rr   int32copyr   r   rJ   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 )BNr@   r   r   r@   r   r?   r@   r   r   r?   r   ra   r?   r   r   ra   r   rU   ra   r@   r?   ry   r?   rx   ry   r?   ra   rx   ra   rT   rx   ra   rU   rT   rU   r\   rT   ry   rx      rx      r   rx   rT   r   rT      r   rT   r\   r   r\      r   r   ry   rT   )r         ?      @      
@)r   r   r@   r
   ra   r
   rT   r
   r   r      r
   r
   r
   r
   r
   ru   )r
   r
   r
   r
   r
   r   r   r?   r
   rU   r
   r\   r
   r   r      )ru         ?      @ru   r   r   r   r   rA   rB   r]         @)rA   rA   rA   r   r   r   rB   r]   r   r   r   r   )r   r   r@   r   r   r   r   r   ra   rU   rT   r\   rA   r   r   r   r   r   r   r   r   r   r   r
   r3   r   r   r   r   r@   r   r   r   r?   r   r@   r?   r   r?   ra   r@   ra   r?   )皙r   ?gffffff?gffffff?g333333@g333333@r   皙?)r
   r   r   r   r   r   r
   )r
   ra   ra   ra   rU   rU   r
   )r   r   r   r   r   r   r   r   )r   r   r?   r   )r   r   r@   )r   r@   r?   )r   ra   r   )r   ra   r@   r?   ra   rU   r   r   r   r   r   r   r   r   r   r   r   )gɿ皙?rf   g333333?)ru   ru   ru   ru   )r
   r   r   r
   )r
   r
   r   r
   )rC   rD   rN   rF   zerosrG   r   r   get_trifinderr   set_mask)
r'   r(   r   r   rR   	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|
   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 )=Nr@   Gz?)\(@r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   ry   rT   geomkindr         @ra   )r   re   r   r   )g      пr         ?r   Tr   )r   re   r   r   r   )r   g)\(333333?c                    s,    | d d  |d d   |  |  S )Nru   r   r)   r=   r   r   r   r)   r*   quad  s    ztest_triinterp.<locals>.quadc                    s0   d  | d  |  d |d  |   fS )Nr   ru   r)   r=   r   r)   r*   gradient_quad  s    z%test_triinterp.<locals>.gradient_quad)r   &jjZ? rh?rA   rB   rB   rA   )333333?HPs?X9v?rA   rA   rB   rB   r   r   r   r@   r@   r   r   r@   r   r?   r   r?   r   ra   r?   r   ra   r   r   ra   r   r   rA   rB   r?   userr   dzr\   r   r   r   d   )rC   rD   rN   rF   r   rG   r   r   LinearTriInterpolatorCubicTriInterpolatorrE   r   r   r   matestrr   gradientmeshgrid_trianglesabsrI   dot)r'   r(   zr   r   rR   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@rA   r   r   Nr   )rC   cosrE   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   rA   rB   r   r   r   r   r   r   r   r   rx   rU   r   r   r   r   r   r   r   ru   r         @g      @)N)rC   rr   r   r   ranger   float64r   )r  r   aybxZbyZcxcyr'   r(   r   rR   Zidofr   r  r  r  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   r@   rA   r   Nr   )rC   concatenaterN   r   onesr  )r   mlrowscolsvalsr)   r)   r*   poisson_sparse_matrixO  s&    """"(("*z<test_triinterpcubic_cg_solver.<locals>.poisson_sparse_matrix)r   r@   r   rB   r   )Ar   x0tol)r   1   r   )rB   rB   rB   rB   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   )rB   r]   rA   )r]   rB         @)rA   r  rB   )r   triinterpolateZ_Sparse_Matrix_cooZcompress_cscZto_denser
  rC   r   r  Z_cgr   r   r  r  rr   r   )r  r   r  matZ	mat_denseZitestr   r'   _Zi_zeroZj_zeror  r  r  dimr)   r)   r*   test_triinterpcubic_cg_solverK  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)rA   gˡE?ru   rA   rB   r@   r   r   r   r   r   r   r   r   r   r   rz   )rC   rr   r   r  rE   r   r   r  r   r   r   r  Z_DOF_estimator_geomZcompute_geom_weightsrn   r
  r   rH   r   )r   r  r'   r(   r   r   Zsum_wthetax_roty_rotrR   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 )NrA   r   r
   r   r   r   r   r   r3   r   r   r   r   r   r   r      r   r   r   r@   rT   r   )Z	tri_index)rC   rr   r   r   rE   rH   r'   rI   r(   rD   rF   r   mar   r   r   r   Z_interpolate_multikeysr  r   )r   r  y0ZtransformationsZtransformationr$  r%  r'   r(   r   r   rR   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*  rT   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 
Nru   r   r   rT   r   g      >@      @g      &@rd   rC   hypotarctan2expr   rI   rH   r'   r(   r1Ztheta1r2Ztheta2r   r)   r)   r*   r     s    *&z)test_triinterp_transformations.<locals>.zffffff?r   r   FZendpoint.r   rz         rB   rV   r   r   )ZlinZmin_Er   gZ$.Ar=   r'   )rC   rE   r   repeatnewaxisr   flattenr  r   r   rD   rF   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   rR   r   r   r   Z
dic_interpZ
interp_keyr   ZinterpzZscale_factorZscaled_axisr)   r)   r*   test_triinterp_transformations  s    
$



rE  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*  rT   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/  r1  r5  r)   r)   r*   r   U  s    *&z%test_tri_smooth_contouring.<locals>.zr8  r   r   Fr9  .r   rz   r@   subdivrA   rB   g?ru   z0.5)Zlwcolorblack)levelscolors)rC   rE   r   r;  r<  r   r=  r  r   r   r   r2  r   r   UniformTriRefinerrefine_fieldrN   r   triplot
tricontour)r>  r?  r@  r   rA  rB  r  r,  rC  rD  refinertri_refiz_test_refirJ  r)   r)   r*   test_tri_smooth_contouringN  s0    $

rS  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   )rC   r3  r   rI   rH   )r'   r(   Zr_sqr#  r   r)   r)   r*   dipole_potentialy  s    z2test_tri_smooth_gradient.<locals>.dipole_potential   rT   r   r8  r   r   Fr9  .r   rz   r   rF  equalz0.8)rH  rA   rB   g{Gz?Zhot)r]   rB   rB   rB   )rJ  cmapZ
linewidthsrh   r[   bluegy&1|?r   r	  )ZunitsscaleZzorderrH  widthZ	headwidthZ
headlength)rC   rE   r   r;  r<  r   r=  r  r   r   r   r2  r   r   rL  rM  r   r   r'   r(   r   r   ZgcaZ
set_aspectrN  rN   mplZ	colormapsrO  Zquiver)rT  r>  r?  r@  rA  rB  r'   r(   VrR   rP  rQ  rR  ZtciZExZEyZE_normrJ  rW  r)   r)   r*   test_tri_smooth_gradientu  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rA   rB   ru   rA   r]   rA   ru   r   r:  rB   r   rv   rw   r   FFTr   F)Zrescaler]   )rA   rB   r]   )rB   r	  r0  rx   c                 S   s   t | | t |  S rb   )rC   r   sign)r'   r   r)   r)   r*   power  s    ztest_tritools.<locals>.powerr   r   r   r      )r   r   r   r   r   r   r   r         "   #   ~                                    TP   ),   -   >   ?   N   O   rs  Q   R   S   b   r9   t   u   )rC   rr   sqrtr   boolr   r   TriAnalyzerr   Zscale_factorsZcircle_ratiosr+  Zmasked_arraynanrE   rD   rF   r   Zget_flat_tri_maskr   r   r   )r'   r(   r   r   rR   analyserr   ra  Z	mask_flatZ
verif_maskZcorners_indexZcenter_indexr)   r)   r*   test_tritools  sN    "

"





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   r:  rB   r   r   Tr   rF  r   ry   rz   r   rA   rB   rA   rB   rA   rA   rB   rB   rv   r   r   r   r   r   r   r   )rC   rE   rD   rF   r   r  r   r   r   rL  refine_triangulationr'   r(   Zin1dZaroundr   r   rn   r   r   rs   r2  r
  rM  ZdstackZlexsortr   )r   rG  r'   r(   r   rR   rP  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triinterpolatorrG  )	rC   Zmgridr;  r=  Z
zeros_liker   r   rL  rM  )r  r'   r(   r   rl   rP  r   r)   r)   r*   test_trirefine_masked  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
  rC   rr   r   )r   rl   r  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sHJ dd S )Nr  r  rv   r   r   zb-z(triplot should return the artist it adds)r   r   r   r   r   rN  )r   rR   r)   r)   r*   test_triplot_return<  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   rF  )	rC   rr   Z	isfortranr   r   rL  r  r   r   )
Z
triangles1Z
triangles2r'   r(   Ztriang1Ztriang2Zrefiner1Zrefiner2Zfine_triang1Zfine_triang2r)   r)   r*   ,test_trirefiner_fortran_contiguous_trianglesF  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   )rC   rE   maprF   rD   radiansr   r  r   r   rK   rL   r   )
xir'   r(   wr#  x1y1rR   Zqhull_neighborsZown_neighborsr)   r)   r*   test_qhull_triangle_orientation]  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 )Nr^  rA   ru   r   r:  rB   r   rv   rw   r   r_  r   )	rC   rr   r  r   r  r   r   r  Z_get_compressed_triangulation)r'   r(   r   r   rR   r  r)   r)   r*   #test_trianalyzer_mismatched_indicest  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)rA   rB   rB   )rA   rA   rB   )r   r   r   rB   rA   )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  tjtdd |	ddg W d    n1 s^0    Y  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 s0    Y  g d}tj
||}tjtdd |dd W d    n1 s*0    Y  tjtdd tj  W d    n1 sd0    Y  tj|}tjtdd" |dgddg W d    n1 s0    Y  d S )Nr   )_triz.function takes exactly 7 arguments \(0 given\)r6   z,x and y must be 1D arrays of the same lengthr   F)r   r   r   r4   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
   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;   r   r[  r   r<   Zcalculate_plane_coefficientsr   ZTriContourGeneratorZcreate_filled_contourZTrapezoidMapTriFinderZ	find_many)r  r'   r(   r   rR   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   ru   )r   r   r   r   ru   g    _B)rC   rs   r   r   rG   r   )r'   r(   offsetrR   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 triangulationr6   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  rC   infr  r+  rr   )r'   r(   rR   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)rA   ru   rB   )rA   rB   rA   )rB   r]   r   )r   r   r  rO  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 )Nr3   r4   r   z--)Zls)Z	linestyle)r   rN  )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 )Nr3   r4   r   label)r  r   r   )r   r   rN  Zget_legend_handles_labelsrG   )	r'   r(   r  r   r   linesmarkersZhandleslabelsr)   r)   r*   test_triplot_label  s    
r  )AnumpyrC   Znumpy.testingr   r   r   Znumpy.ma.testutilsr+  Z	testutilsr   r/   r  r[  Zmatplotlib.pyplotZpyplotr   Zmatplotlib.trirl   r   Zmatplotlib.pathr   Zmatplotlib.testing.decoratorsr   r   r   r5   r>   rS   rZ   r`   r0   r1   rc   rt   r   r   r   r   r   r   r   r  r"  r(  r-  rE  rS  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98


S
