
 m[c           @` sS  d  Z  d d l m Z m Z m Z m Z d d l Z d d l Z d d l	 m
 Z
 d d l m Z d d l Z d e f d     YZ d   Z d	   Z d
   Z d   Z d d d d  Z d e f d     YZ d d  Z d d d d  Z d e d  Z d   Z d   Z d d  Z d   Z d   Z d d d d  Z  d   Z! d   Z" d S(   uO   
A module providing some utility functions regarding bezier path manipulation.
i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsN(   t   Path(   t   xort   NonIntersectingPathExceptionc           B` s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s0   lib/python2.7/site-packages/matplotlib/bezier.pyR      s   c         C` s   | |  | | } | | | | }	 | | }
 } | | } } |
 | | | } | d k rm t  d   n  | | } } | |
 } } g  | | | | g D] } | | ^ q \ } } } } | | | |	 } | | | |	 } | | f S(   u    return a intersecting point between a line through (cx1, cy1)
    and having angle t1 and a line through (cx2, cy2) and angle t2.
    g        u   Given lines do not intersect(   t
   ValueError(   t   cx1t   cy1t   cos_t1t   sin_t1t   cx2t   cy2t   cos_t2t   sin_t2t	   line1_rhst	   line2_rhst   at   bt   ct   dt   ad_bct   a_t   b_t   c_t   d_t   kt   xt   y(    (    s0   lib/python2.7/site-packages/matplotlib/bezier.pyt   get_intersection   s    	5c         C` s   | d k r |  | |  | f S| | } } | | } } | | |  | | | }	 }
 | | |  | | | } } |	 |
 | | f S(   u   
    For a line passing through (*cx*, *cy*) and having a angle *t*, return
    locations of the two points located along its perpendicular line at the
    distance of *length*.
    g        (    (   t   cxt   cyt   cos_tt   sin_tt   lengthR   R   R   R   t   x1t   y1t   x2t   y2(    (    s0   lib/python2.7/site-packages/matplotlib/bezier.pyt   get_normal_points6   s    c         C` s"   |  d  d | |  d | } | S(   Nii   (    (   t   betat   tt	   next_beta(    (    s0   lib/python2.7/site-packages/matplotlib/bezier.pyt   _de_casteljau1O   s    c         C` s   t  j |   }  |  g } x< t rV t |  |  }  | j |   t |   d k r Pq q Wg  | D] }  |  d ^ q^ } g  t |  D] }  |  d ^ q } | | f S(   u   split a bezier segment defined by its controlpoints *beta*
    into two separate segment divided at *t* and return their control points.

    i   i    i(   t   npt   asarrayt   TrueR.   t   appendt   lent   reversed(   R+   R,   t	   beta_listt	   left_betat
   right_beta(    (    s0   lib/python2.7/site-packages/matplotlib/bezier.pyt   split_de_casteljauT   s    		#g        g      ?g{Gz?c         C` s   |  |  } |  |  } | |  } | |  } | | k rW | | k rW t  d   n  x t r t j | d | d | d | d  | k  r | | f Sd | | }	 |  |	  }
 | |
  } t | |  r |	 } |
 } | } qZ |	 } |
 } | } qZ Wd S(   u%   Find a parameter t0 and t1 of the given bezier path which
    bounds the intersecting points with a provided closed
    path(*inside_closedpath*). Search starts from *t0* and *t1* and it
    uses a simple bisecting algorithm therefore one of the end point
    must be inside the path while the orther doesn't. The search stop
    when |t0-t1| gets smaller than the given tolerence.
    value for

    - bezier_point_at_t : a function which returns x, y coordinates at *t*

    - inside_closedpath : return True if the point is inside the path

    u3   Both points are on the same side of the closed pathi    i   g      ?N(   R   R1   R/   t   hypotR   (   t   bezier_point_at_tt   inside_closedpatht   t0t   t1t	   tolerencet   startt   endt   start_insidet
   end_insidet   middle_tt   middlet   middle_inside(    (    s0   lib/python2.7/site-packages/matplotlib/bezier.pyt*   find_bezier_t_intersecting_with_closedpathg   s(    	0
	t   BezierSegmentc           B` sq   e  Z d  Z i e j d d g  d 6e j d d d g  d 6e j d d d d g  d 6Z d   Z d   Z RS(	   u:   
    A simple class of a 2-dimensional bezier segment
    g      ?i   g       @i   g      @i   c         C` se   t  |  } t j |  |  _ t j | d } t j |  j \ } } | | |  _ | | |  _	 d S(   u   
        *control_points* : location of contol points. It needs have a
         shpae of n * 2, where n is the order of the bezier line. 1<=
         n <= 3 is supported.
        i   N(
   R3   R/   t   aranget   _ordersRG   t   _binom_coeffR0   t   Tt   _pxt   _py(   t   selft   control_pointst   _ot   _coefft   xxt   yy(    (    s0   lib/python2.7/site-packages/matplotlib/bezier.pyt   __init__   s    c         C` s]   d | |  j  d d d  | |  j  } t j | |  j  } t j | |  j  } | | f S(   u   evaluate a point at ti   Ni(   RI   R/   t   dotRL   RM   (   RN   R,   t   ttt   _xt   _y(    (    s0   lib/python2.7/site-packages/matplotlib/bezier.pyt
   point_at_t   s    )(   R   R   t   __doc__R/   t   arrayRJ   RT   RY   (    (    (    s0   lib/python2.7/site-packages/matplotlib/bezier.pyRG      s   	c   	      C` sW   t  |   } | j } t | | d | \ } } t |  | | d  \ } } | | f S(   u   
    bezier : control points of the bezier segment
    inside_closedpath : a function which returns true if the point is inside
                        the path
    R>   g       @(   RG   RY   RF   R8   (	   t   bezierR;   R>   t   bzR:   R<   R=   t   _leftt   _right(    (    s0   lib/python2.7/site-packages/matplotlib/bezier.pyt)   split_bezier_intersecting_with_closedpath   s    
	c      	   ` sG   | \        f d   } t  | |  d | d | d | d S(   u   
    Find a radius r (centered at *xy*) between *rmin* and *rmax* at
    which it intersect with the path.

    inside_closedpath : function
    cx, cy : center
    cos_t, sin_t : cosine and sine for the angle
    rmin, rmax :
    c         ` s     |    |   f S(   N(    (   t   r(   R#   R!   R"   R$   (    s0   lib/python2.7/site-packages/matplotlib/bezier.pyt   _f   s    R<   R=   R>   N(   RF   (   R;   t   xyR#   R$   t   rmint   rmaxR>   Rb   (    (   R#   R!   R"   R$   s0   lib/python2.7/site-packages/matplotlib/bezier.pyt    find_r_to_boundary_of_closedpath   s
    c         C` s  |  j    } t |  \ } } | | d  } | } t j }	 d }
 d } xp | D]\ \ } } | }
 | t |  d 7} | | d  | k r |	 | d | g  } Pn  | } qP Wt d   | j d
  } t | | |  \ } } t |  d k rt j	 g } t j
 t j	 g } n t |  d k rUt j t j g } t j
 t j t j g } nW t |  d k rt j t j t j g } t j
 t j t j t j g } n t d	   | d } | } |  j d k rt |	 |  j |  | g   } t |	 | |  j | g   } nj t |	 |  j |
  | g  |	 |  j |
  | g   } t |	 | |  j | g  |	 | |  j | g   } | r| t k r| | } } n  | | f S(   uW    divide a path into two segment at the point where inside(x, y)
    becomes False.
    ii    i   i   u*   The path does not intersect with the patchii   i   u   This should never be reached(   ii   N(   t   iter_segmentst   nextR/   t   concatenateR3   R	   t   reshapeR`   R   t   LINETOt   MOVETOt   CURVE3t   CURVE4t   AssertionErrort   codest   Nonet   verticest   False(   t   patht   insideR>   t   reorder_inoutt	   path_itert
   ctl_pointst   commandt   begin_insidet   ctl_points_oldt   concatt   ioldt   it   bezier_patht   bpt   leftt   rightt
   codes_leftt   codes_rightt
   verts_leftt   verts_rightt   path_int   path_out(    (    s0   lib/python2.7/site-packages/matplotlib/bezier.pyt   split_path_inout   sP    	
!
"c         ` s#   | d      f d   } | S(   Ni   c         ` s*   |  \ } } |   d |  d  k  S(   Ni   (    (   Rc   R   R   (   R!   R"   t   r2(    s0   lib/python2.7/site-packages/matplotlib/bezier.pyRb   (  s    (    (   R!   R"   Ra   Rb   (    (   R!   R"   R   s0   lib/python2.7/site-packages/matplotlib/bezier.pyt   inside_circle%  s    
c         C` sM   | |  | | } } | | | | d } | d k r; d S| | | | f S(   Ng      ?i    g        (   g        g        (    (   t   x0t   y0R&   R'   t   dxt   dyR   (    (    s0   lib/python2.7/site-packages/matplotlib/bezier.pyt   get_cos_sin0  s
    gh㈵>c         C` so   t  j |  |  } t  j | |  } t  j | |  } | | k  rG d St  j | t  j  | k  rg d St Sd S(   u    returns
       * 1 if two lines are parralel in same direction
       * -1 if two lines are parralel in opposite direction
       * 0 otherwise
    i   iN(   R/   t   arctan2t   abst   piRs   (   t   dx1t   dy1t   dx2t   dy2R>   t   theta1t   theta2t   dtheta(    (    s0   lib/python2.7/site-packages/matplotlib/bezier.pyt   check_if_parallel9  s    c      	   C` s  |  d \ } } |  d \ } } |  d \ } } t  | | | | | | | |  } | d k r t j d  t | | | |  \ }	 }
 |	 |
 } } n6 t | | | |  \ }	 }
 t | | | |  \ } } t | | |	 |
 |  \ } } } } t | | | | |  \ } } } } | d k r`d | | d | | } } d | | d | | } } nN t | | |	 |
 | | | |  \ } } t | | |	 |
 | | | |  \ } } | | f | | f | | f g } | | f | | f | | f g } | | f S(   u   
    Given the quadratic bezier control points *bezier2*, returns
    control points of quadratic bezier lines roughly parallel to given
    one separated by *width*.
    i    i   i   iu8   Lines do not intersect. A straight line is used instead.g      ?(   R   t   warningst   warnR   R*   R    (   t   bezier2t   widtht   c1xt   c1yt   cmxt   cmyt   c2xt   c2yt   parallel_testR   R   R   R   t   c1x_leftt   c1y_leftt	   c1x_rightt	   c1y_rightt   c2x_leftt   c2y_leftt	   c2x_rightt	   c2y_rightt   cmx_leftt   cmy_leftt	   cmx_rightt	   cmy_rightt	   path_leftt
   path_right(    (    s0   lib/python2.7/site-packages/matplotlib/bezier.pyt   get_parallelsJ  s<    $$ 						c         C` sK   d d | |  | } d d | | | } |  | f | | f | | f g S(   u    Find control points of the bezier line through c1, mm, c2. We
    simply assume that c1, mm, c2 which have parametric value 0, 0.5, and 1.
    g      ?i   (    (   R   R   t   mmxt   mmyR   R   R   R   (    (    s0   lib/python2.7/site-packages/matplotlib/bezier.pyt   find_control_points  s    g      ?c   %      C` s  |  d \ } } |  d \ } } |  d \ }	 }
 t  | | | |  \ } } t  | | |	 |
  \ } } t | | | | | |  \ } } } } t |	 |
 | | | |  \ } } } } | | d | | d } } | |	 d | |
 d } } | | d | | d } } t  | | | |  \ } } t | | | | | |  \ } }  }! }" t | | | |  | |  }# t | | |! |" | |  }$ |# |$ f S(   u   
    Being similar to get_parallels, returns control points of two quadrativ
    bezier lines having a width roughly parallel to given one separated by
    *width*.
    i    i   i   g      ?(   R   R*   R   (%   R   R   t   w1t   wmt   w2R   R   R   R   t   c3xt   c3yR   R   R   R   R   R   R   R   t   c3x_leftt   c3y_leftt	   c3x_rightt	   c3y_rightt   c12xt   c12yt   c23xt   c23yt   c123xt   c123yt   cos_t123t   sin_t123t
   c123x_leftt
   c123y_leftt   c123x_rightt   c123y_rightR   R   (    (    s0   lib/python2.7/site-packages/matplotlib/bezier.pyt   make_wedged_bezier2  s&    (((		c         C` sf   |  j  } | d k r^ t j |  j j d  d  } | j t j  t j	 | d <t |  j |  S|  Sd S(   u$   
    fill in the codes if None.
    i   u   ii    N(
   Rp   Rq   R/   t   emptyRr   t   shapet   fillR   Rk   Rl   (   t   pR   (    (    s0   lib/python2.7/site-packages/matplotlib/bezier.pyt   make_path_regular  s    	c         C` sn   g  } g  } x: |  D]2 } t  |  } | j | j  | j | j  q Wt t j |  t j |   } | S(   u7   
    concatenate list of paths into a single path.
    (   R   R2   Rr   Rp   R   R/   Ri   (   t   pathsRr   Rp   R   t   _path(    (    s0   lib/python2.7/site-packages/matplotlib/bezier.pyt   concatenate_paths  s    (#   RZ   t
   __future__R    R   R   R   t   sixt   numpyR/   t   matplotlib.pathR   t   operatorR   R   R	   R   R    R*   R.   R8   RF   t   objectRG   R`   Rf   Rs   R   R   R   R   R   R   R   R   R   (    (    (    s0   lib/python2.7/site-packages/matplotlib/bezier.pyt   <module>   s0   "				/#>				J	3	