ó
 m[c           @` sr   d  d l  m Z m Z m Z m Z d  d l Z d  d l j Z d  d l j	 Z	 d  d l
 Z d e f d „  ƒ  YZ d S(   i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsNt   Triangulationc           B` sw   e  Z d  Z d
 d
 d „ Z d „  Z e d „  ƒ Z d „  Z d „  Z	 e
 d „  ƒ Z d „  Z e d „  ƒ Z d	 „  Z RS(   u  
    An unstructured triangular grid consisting of npoints points and
    ntri triangles.  The triangles can either be specified by the user
    or automatically generated using a Delaunay triangulation.

    Parameters
    ----------
    x, y : array_like of shape (npoints)
        Coordinates of grid points.
    triangles : integer array_like of shape (ntri, 3), optional
        For each triangle, the indices of the three points that make
        up the triangle, ordered in an anticlockwise manner.  If not
        specified, the Delaunay triangulation is calculated.
    mask : boolean array_like of shape (ntri), optional
        Which triangles are masked out.

    Attributes
    ----------
    `edges`
    `neighbors`
    is_delaunay : bool
        Whether the Triangulation is a calculated Delaunay
        triangulation (where `triangles` was not specified) or not.

    Notes
    -----
    For a Triangulation to be valid it must not have duplicate points,
    triangles formed from colinear points, or overlapping triangles.
    c         C` sÝ  t  j | d t  j ƒ|  _ t  j | d t  j ƒ|  _ |  j j |  j j k s` |  j j d k ro t d ƒ ‚ n  d  |  _	 d  |  _
 d  |  _ t |  _ | d  k rÉ t j | | ƒ \ |  _ |  _ t |  _ n© t  j | d t  j d d ƒ|  _ |  j j d k s|  j j d d k r!t d ƒ ‚ n  |  j j ƒ  t |  j ƒ k rNt d	 ƒ ‚ n  |  j j ƒ  d
 k  rrt d ƒ ‚ n  | d  k	 rÇt  j | d t ƒ|  _	 |  j	 j |  j j d
 f k rÇt d ƒ ‚ qÇn  d  |  _ d  |  _ d  S(   Nt   dtypei   u'   x and y must be equal-length 1-D arrayst   orderu   Ci   i   u   triangles must be a (?,3) arrayu&   triangles max element is out of boundsi    u&   triangles min element is out of boundsu3   mask array must have same length as triangles array(   t   npt   asarrayt   float64t   xt   yt   shapet   ndimt
   ValueErrort   Nonet   maskt   _edgest
   _neighborst   Falset   is_delaunayt   _qhullt   delaunayt	   trianglest   Truet   arrayt   int32t   maxt   lent   mint   boolt   _cpp_triangulationt
   _trifinder(   t   selfR
   R   R   R   (    (    s;   lib/python2.7/site-packages/matplotlib/tri/triangulation.pyt   __init__)   s0    *				!(	c         C` s   |  j  ƒ  j | ƒ S(   ub  
        Calculate plane equation coefficients for all unmasked triangles from
        the point (x,y) coordinates and specified z-array of shape (npoints).
        Returned array has shape (npoints,3) and allows z-value at (x,y)
        position in triangle tri to be calculated using
        z = array[tri,0]*x + array[tri,1]*y + array[tri,2].
        (   t   get_cpp_triangulationt   calculate_plane_coefficients(   R!   t   z(    (    s;   lib/python2.7/site-packages/matplotlib/tri/triangulation.pyR$   P   s    c         C` s.   |  j  d k r' |  j ƒ  j ƒ  |  _  n  |  j  S(   uñ   
        Return integer array of shape (nedges,2) containing all edges of
        non-masked triangles.

        Each edge is the start point index and end point index.  Each
        edge (start,end and end,start) appears only once.
        N(   R   R   R#   t	   get_edges(   R!   (    (    s;   lib/python2.7/site-packages/matplotlib/tri/triangulation.pyt   edgesZ   s    	c         C` sS   |  j  d  k rL t j |  j |  j |  j |  j |  j |  j	 |  j
 ƒ |  _  n  |  j  S(   N(   R   R   t   _triR   R
   R   R   R   R   R   R   (   R!   (    (    s;   lib/python2.7/site-packages/matplotlib/tri/triangulation.pyR#   g   s
    c         C` s7   |  j  d k	 r, |  j j d |  j  d d ƒS|  j Sd S(   uC   
        Return an array of triangles that are not masked.
        i   t   axisi    N(   R   R   R   t   compress(   R!   (    (    s;   lib/python2.7/site-packages/matplotlib/tri/triangulation.pyt   get_masked_trianglesp   s    c          O` s`  t  |  d t ƒ r* |  d } |  d }  n)|  d } |  d } |  d }  | j d d ƒ } t } | d k r‘ t |  ƒ d k r‘ |  d } t } n  | d k	 rÖ y t j | d t j	 ƒ} WqÖ t
 k
 rÒ d } qÖ Xn  | d k	 r| j d k s| j d d k rd } n  | d k	 r,| r,|  d }  n  | j d d ƒ } t | | | | ƒ } | |  | f S(	   uÎ  
        Return a Triangulation object from the args and kwargs, and
        the remaining args and kwargs with the consumed values removed.

        There are two alternatives: either the first argument is a
        Triangulation object, in which case it is returned, or the args
        and kwargs are sufficient to create a new Triangulation to
        return.  In the latter case, see Triangulation.__init__ for
        the possible args and kwargs.
        i    i   i   u	   trianglesR   i   u   maskN(   t
   isinstanceR   t   popR   R   R   R   R   R   R   R   R   R   (   t   argst   kwargst   triangulationR
   R   R   t	   from_argsR   (    (    s;   lib/python2.7/site-packages/matplotlib/tri/triangulation.pyt   get_from_args_and_kwargsy   s0    




		c         C` s8   |  j  d k r1 d d l m } | |  ƒ |  _  n  |  j  S(   uÃ   
        Return the default :class:`matplotlib.tri.TriFinder` of this
        triangulation, creating it if necessary.  This allows the same
        TriFinder object to be easily shared.
        i    (   t   TrapezoidMapTriFinderN(   R    R   t   matplotlib.tri.trifinderR3   (   R!   R3   (    (    s;   lib/python2.7/site-packages/matplotlib/tri/triangulation.pyt   get_trifinder§   s    c         C` s.   |  j  d k r' |  j ƒ  j ƒ  |  _  n  |  j  S(   u  
        Return integer array of shape (ntri,3) containing neighbor
        triangles.

        For each triangle, the indices of the three triangles that
        share the same edges, or -1 if there is no such neighboring
        triangle.  neighbors[i,j] is the triangle that is the neighbor
        to the edge from point index triangles[i,j] to point index
        triangles[i,(j+1)%3].
        N(   R   R   R#   t   get_neighbors(   R!   (    (    s;   lib/python2.7/site-packages/matplotlib/tri/triangulation.pyt	   neighbors³   s    c         C` s¸   | d k r d |  _ nF t j | d t ƒ|  _ |  j j |  j j d f k r^ t d ƒ ‚ n  |  j d k	 rƒ |  j j	 |  j ƒ n  d |  _
 d |  _ |  j d k	 r´ |  j j ƒ  n  d S(   up   
        Set or clear the mask array.  This is either None, or a boolean
        array of shape (ntri).
        R   i    u3   mask array must have same length as triangles arrayN(   R   R   R   R   R   R   R   R   R   t   set_maskR   R   R    t   _initialize(   R!   R   (    (    s;   lib/python2.7/site-packages/matplotlib/tri/triangulation.pyR8   Ã   s    		N(   t   __name__t
   __module__t   __doc__R   R"   R$   t   propertyR'   R#   R+   t   staticmethodR2   R5   R7   R8   (    (    (    s;   lib/python2.7/site-packages/matplotlib/tri/triangulation.pyR      s   '	
				.	(   t
   __future__R    R   R   R   t   sixt   matplotlib._triR(   t   matplotlib._qhullR   t   numpyR   t   objectR   (    (    (    s;   lib/python2.7/site-packages/matplotlib/tri/triangulation.pyt   <module>   s
   "