ó
±éRc           @  s5  d  Z  d d l m 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(   sO   
A module providing some utility functions regarding bezier path manipulation.
iÿÿÿÿ(   t   print_functionN(   t   Path(   t   xort   NonIntersectingPathExceptionc           B  s   e  Z RS(    (   t   __name__t
   __module__(    (    (    sK   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/bezier.pyR      s   c         C  sì   | |  | | } | | | | }	 | | }
 } | | } } |
 | | | } | d k rm 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   kt   xt   y(    (    sK   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/bezier.pyt   get_intersection   s    	5c         C  s‚   | d k r |  | |  | 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(    (    sK   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/bezier.pyt   get_normal_points2   s    c         C  s"   |  d  d | |  d | } | S(   Niÿÿÿÿi   (    (   t   betat   tt	   next_beta(    (    sK   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/bezier.pyt   _de_casteljau1K   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(   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_listt	   left_betat
   right_beta(    (    sK   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/bezier.pyt   split_de_casteljauP   s    		#g        g      ð?g{®Gáz„?c         C  sò   |  | ƒ } |  | ƒ } | | ƒ } | | ƒ } t  | | ƒ sN t d ƒ ‚ n  x� | d | d d | d | d d | d k  r� | | f Sd | | }	 |  |	 ƒ }
 | |
 ƒ } t  | | ƒ rÙ |	 } |
 } | } qQ |	 } |
 } | } qQ 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

    s4   the segment does not seem 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(    (    sK   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/bezier.pyt*   find_bezier_t_intersecting_with_closedpathc   s*    !
	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(	   s:   
    A simple class of a 2-dimensional bezier segment
    g      ð?i   g       @i   g      @i   c         C  sˆ   t  | ƒ } t j | ƒ |  _ t j | d } t j | ƒ } | 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    (	   R0   R,   t   aranget   _ordersRC   t   _binom_coeffR-   t   _pxt   _py(   t   selft   control_pointst   _ot   _coefft   _control_pointst   xxt   yy(    (    sK   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/bezier.pyt   __init__    s    c         C  su   t  j d | |  j ƒ d d d … } t  j | |  j ƒ } | | } t | |  j ƒ } t | |  j ƒ } | | f S(   s   evaluate a point at tg      ð?Niÿÿÿÿ(   R,   t   powerRE   t   sumRG   RH   (   RI   R)   t   one_minus_t_powerst   t_powerst   ttt   _xt   _y(    (    sK   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/bezier.pyt
   point_at_t±   s    &
(   R   R   t   __doc__R,   t   arrayRF   RP   RX   (    (    (    sK   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/bezier.pyRC   •   s   	c   	      C  sW   t  |  ƒ } | j } 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
    R:   g       @(   RC   RX   RB   R5   (	   t   bezierR7   R:   t   bzR6   R8   R9   t   _leftt   _right(    (    sK   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/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!   (    sK   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/bezier.pyt   _fá   s    R8   R9   R:   N(   RB   (   R7   t   xyR    R!   t   rmint   rmaxR:   Ra   (    (   R    R   R   R!   sK   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/bezier.pyt    find_r_to_boundary_of_closedpathÒ   s
    c         C  sÏ  |  j  ƒ  } t | ƒ \ } } | | d ƒ } d } | }	 t j }
 d } d } xd | D]\ \ } } | } | t | ƒ d 7} | | d ƒ | k r¬ |
 |	 d | g ƒ } Pn  | }	 qV W| d k rÑ t d ƒ ‚ n  t | d d d … | d d d … ƒ } t | | | ƒ \ } } t | ƒ d k rEt	 j
 g } t	 j t	 j
 g } n“ t | ƒ d k r„t	 j t	 j g } t	 j t	 j t	 j g } nT t | ƒ d k rÏt	 j t	 j t	 j g } t	 j t	 j t	 j t	 j g } n	 t ƒ  ‚ | d } | } |  j d k r9t	 |
 |  j |  | g ƒ ƒ } t	 |
 | |  j | g ƒ ƒ } nj t	 |
 |  j |  | g ƒ |
 |  j |  | g ƒ ƒ } t	 |
 | |  j | g ƒ |
 | |  j | g ƒ ƒ } | rÅ| t k rÅ| | } } n  | | f S(	   sW    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   concatenateR0   R   t   zipR_   R   t   LINETOt   MOVETOt   CURVE3t   CURVE4t   codest   verticest   False(   t   patht   insideR:   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(    (    sK   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/bezier.pyt   split_path_inoutë   sV    	
)!	
"c           s#   | d ‰ ‡  ‡ ‡ f d †  } | S(   Ni   c           s*   |  \ } } | ˆ  d | ˆ d ˆ k  S(   Ni   (    (   Rb   R   R   (   R   R   t   r2(    sK   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/bezier.pyRa   2  s    (    (   R   R   R`   Ra   (    (   R   R   Rˆ   sK   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/bezier.pyt   inside_circle/  s    
c         C  s=   | |  | | } } | | | | d } | | | | f S(   Ng      à?(    (   t   x0t   y0R#   R$   t   dxt   dyR   (    (    sK   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/bezier.pyt   get_cos_sin:  s    gñhãˆµøä>c         C  so   t  j |  | ƒ } t  j | | ƒ } t  j | | ƒ } | | k  rG d St  j | t  j ƒ | k  rg d St Sd S(   s•    returns
       * 1 if two lines are parralel in same direction
       * -1 if two lines are parralel in opposite direction
       * 0 otherwise
    i   iÿÿÿÿN(   R,   t   arctan2t   abst   piRq   (   t   dx1t   dy1t   dx2t   dy2R:   t   theta1t   theta2t   dtheta(    (    sK   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/bezier.pyt   check_if_parallel@  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(   s«   
    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   iÿÿÿÿs8   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(    (    sK   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/bezier.pyt   get_parallelsQ  s8    $$ 				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 parametric value 0, 0.5, and 1.
    g      à?i   (    (   Rž   RŸ   t   mmxt   mmyR¢   R£   R    R¡   (    (    sK   /opt/xtal/ccp4-6.5-linux32/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(   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²   (    (    sK   /opt/xtal/ccp4-6.5-linux32/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(   s$   
    fill in the codes if None.
    i   R}   i    N(
   Ro   Rh   R,   t   emptyRp   t   shapet   fillR   Rk   Rl   (   t   pR   (    (    sK   /opt/xtal/ccp4-6.5-linux32/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(   s7   
    concatenate list of paths into a single path.
    (   RÑ   R/   Rp   Ro   R   R,   Ri   (   t   pathsRp   Ro   RÐ   t   _path(    (    sK   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/bezier.pyt   concatenate_pathsâ  s    (   RY   t
   __future__R    t   numpyR,   t   matplotlib.pathR   t   operatorR   Rš   R   R   R   R'   R+   R5   RB   t   objectRC   R_   Re   Rq   R‡   R‰   RŽ   R™   R³   R¶   RÌ   RÑ   RÔ   (    (    (    sK   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/bezier.pyt   <module>   s.   				0*D			G	0	