Ñò
t,2Jc           @   sþ   d  Z  d d k Z d d k l Z d d k l Z d d k l Z d „  Z	 d „  Z
 d „  Z d	 „  Z d
 d d d „ Z d d d „  ƒ  YZ d d „ Z d
 d d d „ Z d e d „ Z d „  Z d „  Z d „  Z d d „ Z d „  Z d d d
 d „ Z d S(   sO   
A module providing some utility functions regarding bezier path manipulation.
iÿÿÿÿN(   t   sqrt(   t   Path(   t   xorc         C   sö   | |  | | } | | | | }	 | | }
 } | | } } |
 | | | } | d j o t  d ƒ ‚ n | | } } | |
 } } g  } | | | | g D] } | | | q¢ ~ \ } } } } | | | |	 } | | | |	 } | | f S(   s‡    return a intersecting point between a line through (cx1, cy1)
    and having angle t1 and a line through (cx2, cy2) and angle t2.
    g        s   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   _[1]t   kt   xt   y(    (    sA   P:\graphics\Tools\Python26\lib\site-packages\matplotlib\bezier.pyt   get_intersection   s    	=c         C   s„   | d j o |  | |  | f S| | } } | | } } | | |  | | | }	 }
 | | |  | | | } } |	 |
 | | f S(   s²   
    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(    (    sA   P:\graphics\Tools\Python26\lib\site-packages\matplotlib\bezier.pyt   get_normal_points0   s    c         C   s"   |  d  d | |  d | } | S(   Niÿÿÿÿi   (    (   t   betat   tt	   next_beta(    (    sA   P:\graphics\Tools\Python26\lib\site-packages\matplotlib\bezier.pyt   _de_casteljau1M   s    c         C   sµ   t  i |  ƒ }  |  g } x@ t o8 t |  | ƒ }  | i |  ƒ t |  ƒ d j o Pq q Wg  } | D] }  | |  d qf ~ } g  } t | ƒ D] }  | |  d q‘ ~ } | | f S(   s’   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_listR   t	   left_betat   _[2]t
   right_beta(    (    sA   P:\graphics\Tools\Python26\lib\site-packages\matplotlib\bezier.pyt   split_de_casteljauQ   s    	 
%+g        g      ð?g{®Gáz„?c         C   sø   |  | ƒ } |  | ƒ } | | ƒ } | | ƒ } t  | | ƒ p t d ƒ ‚ n x¡ | d | d d | d | d d | d j  o | | f Sd | | }	 |  |	 ƒ }
 | |
 ƒ } t  | | ƒ o |	 } |
 } | } qS |	 } |
 } | } qS d S(   s)   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 insed the path
    
    s6   the segment does not seemed to intersect with the pathi    i   i   g      à?N(   R   R   (   t   bezier_point_at_tt   inside_closedpatht   t0t   t1t	   tolerencet   startt   endt   start_insidet
   end_insidet   middle_tt   middlet   middle_inside(    (    sA   P:\graphics\Tools\Python26\lib\site-packages\matplotlib\bezier.pyt*   find_bezier_t_intersecting_with_closedpathh   s&    5
t   BezierSegmentc           B   sq   e  Z d  Z h e i d d g ƒ d 6e i d d d g ƒ d 6e i d d d d g ƒ d 6Z d „  Z d „  Z RS(	   s:   
    A simple class of a 2-dimensional bezier segment
    g      ð?i   g       @i   g      @i   c         C   sˆ   t  | ƒ } t i | ƒ |  _ t i | d } t i | ƒ } | d d … d f } | d d … d f } | | |  _ | | |  _ d S(   s³   
        *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   Ni    (	   R.   R*   t   aranget   _ordersRB   t   _binom_coeffR+   t   _pxt   _py(   t   selft   control_pointst   _ot   _coefft   _control_pointst   xxt   yy(    (    sA   P:\graphics\Tools\Python26\lib\site-packages\matplotlib\bezier.pyt   __init__¥   s    c         C   su   t  i d | |  i ƒ d d d … } t  i | |  i ƒ } | | } t | |  i ƒ } t | |  i ƒ } | | f S(   s   evaluate a point at tg      ð?Niÿÿÿÿ(   R*   t   powerRD   t   sumRF   RG   (   RH   R'   t   one_minus_t_powerst   t_powerst   ttt   _xt   _y(    (    sA   P:\graphics\Tools\Python26\lib\site-packages\matplotlib\bezier.pyt
   point_at_t¶   s    &
(   t   __name__t
   __module__t   __doc__R*   t   arrayRE   RO   RW   (    (    (    sA   P:\graphics\Tools\Python26\lib\site-packages\matplotlib\bezier.pyRB   š   s   	c   	      C   sW   t  |  ƒ } | i } t | | d | ƒ\ } } t |  | | d ƒ \ } } | | f S(   s   
    bezier : control points of the bezier segment
    inside_closedpath : a function which returns true if the point is inside the path
    R9   g       @(   RB   RW   RA   R4   (	   t   bezierR6   R9   t   bzR5   R7   R8   t   _leftt   _right(    (    sA   P:\graphics\Tools\Python26\lib\site-packages\matplotlib\bezier.pyt)   split_bezier_intersecting_with_closedpathÂ   s    		c      
      sG   | \ ‰ ‰ ‡ ‡ ‡  ‡ f d †  } t  | |  d | d | d | ƒd S(   sì   
    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   (    sA   P:\graphics\Tools\Python26\lib\site-packages\matplotlib\bezier.pyt   _få   s    R7   R8   R9   N(   RA   (   R6   t   xyR   R   t   rmint   rmaxR9   Rb   (    (   R   R   R   R   sA   P:\graphics\Tools\Python26\lib\site-packages\matplotlib\bezier.pyt    find_r_to_boundary_of_closedpath×   s    c         C   sÞ  |  i  ƒ  } | i ƒ  \ } } | | d ƒ } d } | }	 t i }
 d } d } xf | D]^ \ } } | } | t | ƒ d 7} | | d ƒ | j o |
 |	 d | g ƒ } Pn | }	 qV W| d j o t d ƒ ‚ n t | d d d … | d d d … ƒ } t | | | ƒ \ } } t | ƒ d j o" t	 i
 g } t	 i t	 i
 g } n˜ t | ƒ d j o. t	 i t	 i g } t	 i t	 i t	 i g } nW t | ƒ d j o: t	 i t	 i t	 i g } t	 i t	 i t	 i t	 i g } n
 t ƒ  ‚ | d } | } |  i d j oB t	 |
 |  i |  | g ƒ ƒ } t	 |
 | |  i | g ƒ ƒ } nk t	 |
 |  i |  | g ƒ |
 |  i |  | g ƒ ƒ } t	 |
 | |  i | g ƒ |
 | |  i | g ƒ ƒ } | o | t j o | | } } n | | f S(	   sX    divide a path into two segment at the point where inside(x, y)
    becomes False. 
    iþÿÿÿi    i   i   s2   The path does not seem to intersect with the patchNi   i   (   t   iter_segmentst   nextt   NoneR*   t   concatenateR.   R   t   zipR`   R   t   LINETOt   MOVETOt   CURVE3t   CURVE4t   codest   verticest   False(   t   patht   insideR9   t   reorder_inoutt	   path_itert
   ctl_pointst   commandt   begin_insidet   bezier_patht   ctl_points_oldt   concatt   ioldt   it   bpt   leftt   rightt
   codes_leftt   codes_rightt
   verts_leftt   verts_rightt   path_int   path_out(    (    sA   P:\graphics\Tools\Python26\lib\site-packages\matplotlib\bezier.pyt   split_path_inoutï   sX    	 
)"	
#c            s#   | d ‰ ‡ ‡  ‡ f d †  } | S(   Ni   c            s*   |  \ } } | ˆ d | ˆ d ˆ  j  S(   Ni   (    (   Rc   R   R   (   t   r2R   R   (    sA   P:\graphics\Tools\Python26\lib\site-packages\matplotlib\bezier.pyRb   8  s    (    (   R   R   Ra   Rb   (    (   R   R   R‰   sA   P:\graphics\Tools\Python26\lib\site-packages\matplotlib\bezier.pyt   inside_circle6  s    
c         C   s=   | |  | | } } | | | | d } | | | | f S(   Ng      à?(    (   t   x0t   y0R!   R"   t   dxt   dyR   (    (    sA   P:\graphics\Tools\Python26\lib\site-packages\matplotlib\bezier.pyt   get_cos_sinA  s    c      	   C   sH  |  d \ } } |  d \ } } |  d \ } } t  | | | | ƒ \ } }	 t  | | | | ƒ \ }
 } t | | | |	 | ƒ \ } } } } t | | |
 | | ƒ \ } } } } t | | | |	 | | |
 | ƒ \ } } t | | | |	 | | |
 | ƒ \ } } | | f | | f | | f g } | | f | | f | | f g } | | f S(   s¬   
    Given the quadraitc bezier control points *bezier2*, returns
    control points of quadrativ bezier lines roughly parralel to given
    one separated by *width*. 
    i    i   i   (   R   R%   R   (   t   bezier2t   widtht   c1xt   c1yt   cmxt   cmyt   c2xt   c2yR   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(    (    sA   P:\graphics\Tools\Python26\lib\site-packages\matplotlib\bezier.pyt   get_parallelsG  s    
$$!!g      à?c         C   s–  |  d \ } } |  d \ } } |  d \ } } | | }	 }
 | | } } t  | |	 d | |
 d ƒ } | |	 | | |
 | } } t |	 |
 | | | ƒ \ } } } } | | d | | d } } | | d | | d } } t  | | d | | d ƒ } | | | | | | } } t | | | | | | ƒ \ } } } } | | f | | f | | f g } | | f | | f | | f g } | | f S(   sª   
    Being similar to get_parallels, returns
    control points of two quadrativ bezier lines having a width roughly parralel to given
    one separated by *width*. 
    i   i   i    g       @(   R    R%   (   R   R    t   shrink_factort   xx1t   yy1t   xx2t   yy2t   xx3t   yy3R   R   R‹   RŒ   t   distR   R   R!   R"   R#   R$   t   xx12t   yy12t   xx23t   yy23t   xm1t   ym1t   xm2t   ym2t   l_plust   l_minus(    (    sA   P:\graphics\Tools\Python26\lib\site-packages\matplotlib\bezier.pyt   make_wedged_bezier2u  s      $ (!!c         C   sK   d d | |  | } d d | | | } |  | f | | f | | f g S(   s’    Find control points of the bezier line throught c1, mm, c2. We
    simply assume that c1, mm, c2 which have parameteric value 0, 0.5, and 1.
    g      à?i   (    (   R’   R“   t   mmxt   mmyR–   R—   R”   R•   (    (    sA   P:\graphics\Tools\Python26\lib\site-packages\matplotlib\bezier.pyt   find_control_points–  s    c   %      C   s  |  d \ } } |  d \ } } |  d \ }	 }
 t  | | | | ƒ \ } } t  | | |	 |
 ƒ \ } } t | | | | | | ƒ \ } } } } t |	 |
 | | | | ƒ \ } } } } | | d | | d } } | |	 d | |
 d } } | | d | | d } } t  | | | | ƒ \ } } t | | | | | | ƒ \ } }  }! }" t | | | |  | | ƒ }# t | | |! |" | | ƒ }$ |# |$ f S(   sª   
    Being similar to get_parallels, returns
    control points of two quadrativ bezier lines having a width roughly parralel 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¥   (    (    sA   P:\graphics\Tools\Python26\lib\site-packages\matplotlib\bezier.pyR¹   ¡  s&    (((		(    (   RZ   t   numpyR*   t   mathR    t   matplotlib.pathR   t   operatorR   R   R%   R)   R4   RA   RB   R`   Rf   Rr   Rˆ   RŠ   R   R¦   R¹   R¼   (    (    (    sA   P:\graphics\Tools\Python26\lib\site-packages\matplotlib\bezier.pyt   <module>   s(   	 			1*G			.!	6