Ńň
n,2Jc        
   @   s¨   d  d k  Z  y e Wn# e j
 o d  d k l Z n Xd  d k Z d  d k l Z d  d k	 l
 Z
 l Z d d g Z d e f d     YZ d e f d     YZ d S(	   i˙˙˙˙N(   t   Set(   t   delaunay(   t   LinearInterpolatort   NNInterpolatort   Triangulationt   DuplicatePointWarningc           B   s   e  Z d  Z RS(   sB   Duplicate points were passed in to the triangulation routine.
    (   t   __name__t
   __module__t   __doc__(    (    (    sO   C:\graphics\Tools\Python26\Lib\site-packages\matplotlib\delaunay\triangulate.pyR      s   c           B   s   e  Z d  Z d   Z d   Z d   Z e i d  Z e i d  Z	 d
 d  Z d
 e i d  Z d
 e i d  Z d	   Z RS(   sw  A Delaunay triangulation of points in a plane.

    Triangulation(x, y)
    x, y -- the coordinates of the points as 1-D arrays of floats

    Let us make the following definitions:
        npoints = number of points input
        nedges = number of edges in the triangulation
        ntriangles = number of triangles in the triangulation

        point_id = an integer identifying a particular point (specifically, an
            index into x and y), range(0, npoints)
        edge_id = an integer identifying a particular edge, range(0, nedges)
        triangle_id = an integer identifying a particular triangle
            range(0, ntriangles)

    Attributes: (all should be treated as read-only to maintain consistency)
      x, y -- the coordinates of the points as 1-D arrays of floats.

      circumcenters -- (ntriangles, 2) array of floats giving the (x,y)
        coordinates of the circumcenters of each triangle (indexed by a
        triangle_id).

      edge_db -- (nedges, 2) array of point_id's giving the points forming
        each edge in no particular order; indexed by an edge_id.

      triangle_nodes -- (ntriangles, 3) array of point_id's giving the points
        forming each triangle in counter-clockwise order; indexed by a
        triangle_id.

      triangle_neighbors -- (ntriangles, 3) array of triangle_id's giving the
        neighboring triangle; indexed by a triangle_id.

        The value can also be -1 meaning that that edge is on the convex hull of
        the points and there is no neighbor on that edge. The values are ordered
        such that triangle_neighbors[tri, i] corresponds with the edge
        *opposite* triangle_nodes[tri, i]. As such, these neighbors are also in
        counter-clockwise order.

      hull -- list of point_id's giving the nodes which form the convex hull
        of the point set. This list is sorted in counter-clockwise order.
    c         C   s5  t  i | d t  i |  _ t  i | d t  i |  _ |  i i |  i i j p t |  i i  d j o t d   n |  i i |  _ |  i	   } | i |  i i j oC t
 i d t  | |  _ |  i |  i |  _ |  i |  i |  _ n
 d  |  _ t |  i |  i  \ |  _ |  _ |  _ |  _ |  i   |  _ d  S(   Nt   dtypei   s#   x,y must be equal-length 1-D arrayssB   Input data contains duplicate x,y points; some values are ignored.(   t   npt   asarrayt   float64t   xt   yt   shapet   lent
   ValueErrort	   old_shapet   _collapse_duplicate_pointst   warningst   warnR   t   j_uniquet   NoneR   t   circumcenterst   edge_dbt   triangle_nodest   triangle_neighborst   _compute_convex_hullt   hull(   t   selfR   R   R   (    (    sO   C:\graphics\Tools\Python26\Lib\site-packages\matplotlib\delaunay\triangulate.pyt   __init__?   s     2		-c         C   sk   t  i d |  i |  i f  } t  i t t  i |  i |  d j t  i |  i |  d j Bg  } | | S(   s   Generate index array that picks out unique x,y points.

        This appears to be required by the underlying delaunay triangulation
        code.
        t   keysi    (   R
   t   lexsortR   R   t   hstackt   Truet   diff(   R   t   j_sortedt   mask_unique(    (    sO   C:\graphics\Tools\Python26\Lib\site-packages\matplotlib\delaunay\triangulate.pyR   Z   s
    <c         C   s  |  i  d j } h  } | i t t |  i | d d  d f d d  d f |  i | d d  d f d d  d f    | i t t |  i | d d  d f d d  d f |  i | d d  d f d d  d f    | i t t |  i | d d  d f d d  d f |  i | d d  d f d d  d f    t | i    } x& | o | i | i | d   qhW| i   | S(   sÁ   Extract the convex hull from the triangulation information.

        The output will be a list of point_id's in counter-clockwise order
        forming the convex hull of the data set.
        i˙˙˙˙Ni    i   i   (	   R   t   updatet   dictt   zipR   t   listt   popitemt   appendt   pop(   R   t   bordert   edgesR   (    (    sO   C:\graphics\Tools\Python26\Lib\site-packages\matplotlib\delaunay\triangulate.pyR   h   s    646464 
c         C   sl   t  i | d t  i } | i |  i j o t d   n |  i d j	 o | |  i } n t |  | |  S(   sâ   Get an object which can interpolate within the convex hull by
        assigning a plane to each triangle.

        z -- an array of floats giving the known function values at each point
          in the triangulation.
        R	   s#   z must be the same shape as x and yN(	   R
   R   R   R   R   R   R   R   R   (   R   t   zt   default_value(    (    sO   C:\graphics\Tools\Python26\Lib\site-packages\matplotlib\delaunay\triangulate.pyt   linear_interpolator   s    c         C   sl   t  i | d t  i } | i |  i j o t d   n |  i d j	 o | |  i } n t |  | |  S(   sÜ   Get an object which can interpolate within the convex hull by
        the natural neighbors method.

        z -- an array of floats giving the known function values at each point
          in the triangulation.
        R	   s#   z must be the same shape as x and yN(	   R
   R   R   R   R   R   R   R   R   (   R   R0   R1   (    (    sO   C:\graphics\Tools\Python26\Lib\site-packages\matplotlib\delaunay\triangulate.pyt   nn_interpolator   s    c         C   s^  | d  j o2 |  i d |  i d |  i d |  i d f } n t i | t i  \ } } } } t | t i i |  i   } t | t i i |  i   } t	 | t i
 i |  i   } t	 | t i
 i |  i   } t	 | | d | | d  } | | d } | | d }	 t i | d | | | d | g |	 |	 d | |	 d | g g  \ }
 } t i |  i |
 f  } t i |  i | f  } |  i | |  } t i t |  i  d f t i  } |  i | d  d   d f <|  i | d  d   d f <d d k l } | | |  \ } } } } t i | |
 | d | | d | d f  } | | f S(   Ni    i   g       @i   i   i˙˙˙˙(   t   lstsq(   R   R   R   R
   R   R   t   mint   minimumt   reducet   maxt   maximumt   arrayR"   t	   __class__t   onesR   t
   numpy.dualR4   (   R   R0   t   bboxt   minxt   maxxt   minyt   maxyt   Mt   midxt   midyt   xpt   ypt   x1t   y1t   newtrit   xy1R4   t   ct   rest   rankt   st   zp(    (    sO   C:\graphics\Tools\Python26\Lib\site-packages\matplotlib\delaunay\triangulate.pyt   prep_extrapolator    s,    2!"+$1c         C   s(   |  i  | |  \ } } | i | |  S(   N(   RQ   R3   (   R   R0   R>   R1   RJ   RP   (    (    sO   C:\graphics\Tools\Python26\Lib\site-packages\matplotlib\delaunay\triangulate.pyt   nn_extrapolatorź   s    c         C   s(   |  i  | |  \ } } | i | |  S(   N(   RQ   R2   (   R   R0   R>   R1   RJ   RP   (    (    sO   C:\graphics\Tools\Python26\Lib\site-packages\matplotlib\delaunay\triangulate.pyt   linear_extrapolatorŔ   s    c         C   sh   h  } x[ |  i  D]P \ } } | i | t    } | i |  | i | t    } | i |  q W| S(   sľ   Return a graph of node_id's pointing to node_id's.

        The arcs of the graph correspond to the edges in the triangulation.

        {node_id: set([node_id, ...]), ...}
        (   R   t
   setdefaultt   sett   add(   R   t   gt   it   jRO   (    (    sO   C:\graphics\Tools\Python26\Lib\site-packages\matplotlib\delaunay\triangulate.pyt
   node_graphÄ   s    
 N(   R   R   R   R   R   R   R
   t   nanR2   R3   R   RQ   RR   RS   RZ   (    (    (    sO   C:\graphics\Tools\Python26\Lib\site-packages\matplotlib\delaunay\triangulate.pyR      s   *			(   R   RU   t	   NameErrort   setsR    t   numpyR
   t   matplotlib._delaunayR   t   interpolateR   R   t   __all__t   RuntimeWarningR   t   objectR   (    (    (    sO   C:\graphics\Tools\Python26\Lib\site-packages\matplotlib\delaunay\triangulate.pyt   <module>   s   