ó
 ‰\c           @   s.   d  d g Z  d d l Z d „  Z d „  Z d S(   t   polygon_clipt   polygon_areaiÿÿÿÿNc         C   sË   d d l  m } m } | j t j |  | f ƒ j d t ƒ} | j | | g | | g g ƒ }	 | j	 |	 ƒ j
 ƒ  d }
 t j |
 d |
 d k ƒ r¡ |
 d  }
 n  |
 d d … d f |
 d d … d f f S(   sû  Clip a polygon to the given bounding box.

    Parameters
    ----------
    rp, cp : (N,) ndarray of double
        Row and column coordinates of the polygon.
    (r0, c0), (r1, c1) : double
        Top-left and bottom-right coordinates of the bounding box.

    Returns
    -------
    r_clipped, c_clipped : (M,) ndarray of double
        Coordinates of clipped polygon.

    Notes
    -----
    This makes use of Sutherland-Hodgman clipping as implemented in
    AGG 2.4 and exposed in Matplotlib.

    iÿÿÿÿ(   t   patht
   transformst   closedi    iþÿÿÿNi   (   t
   matplotlibR   R   t   Patht   npt   vstackt   Tt   Truet   Bboxt   clip_to_bboxt   to_polygonst   all(   t   rpt   cpt   r0t   c0t   r1t   c1R   R   t   polyt	   clip_rectt   poly_clipped(    (    s8   lib/python2.7/site-packages/skimage/_shared/_geometry.pyR       s    '!c         C   sT   t  j |  ƒ }  t  j | ƒ } d t  j t  j | d  |  d | d |  d  ƒ ƒ S(   sÓ   Compute the area of a polygon.

    Parameters
    ----------
    pr, pc : (N,) array of float
        Polygon row and column coordinates.

    Returns
    -------
    a : float
        Area of the polygon.
    g      à?iÿÿÿÿi   (   R   t   asarrayt   abst   sum(   t   prt   pc(    (    s8   lib/python2.7/site-packages/skimage/_shared/_geometry.pyR   (   s    (   t   __all__t   numpyR   R    R   (    (    (    s8   lib/python2.7/site-packages/skimage/_shared/_geometry.pyt   <module>   s   	"