³ò
djOc           @   s:   d    Z  d   Z d   Z d   Z d   Z d   Z d S(   c         C   sÎ   d } x· t  d t |   d  D] } |  | d |  d d |  | d |  d d g } |  | d d |  d d |  | d d |  d d g } | | d | d | d | d 7} q  Wt | d  S(   s3   Finds the volume of a non self-intersecting polygoni    i   i   (   t   ranget   lent   abs(   t   polygont   crossSumt   it   at   b(    (    s7   /home/wjholcomb/.../projects/unsorted/us_map/polygon.pyt   area   s     4<*c      
   C   s  h  } xt  i   D]ô \ } } t i |  } g  } xa t  i   D]S \ } } | | j	 o t i | |  } n | d  j	 o | i |  n d }	 qA Wxl | D]d } |	 t i |  7}	 x> | D]6 }
 |
 | j	 o# |	 t i t i | |
   8}	 qż qż W|	 | } q Wq Wd  S(   Ni    (   t   hullst   itemsR   R   t   convexIntersectiont   Nonet   append(   t   polygonst   coveredPercentst   abbrt   hullt	   totalAreat   intersectionst   testAbbrt   testHullt   intersectiont   coveredAreat   testIntersectiont   coveredPercent(    (    s7   /home/wjholcomb/.../projects/unsorted/us_map/polygon.pyt   sortByPercentageIntersection   s*      
  c   	      C   sP  |  | g } d d g } xx t  d t |   D]a } xX t  d t | |   D]= } | | | d | | | | d j  o | t | <qN qN Wq. WxZ t  d t |   D]C } | | | | d } | i | | | | d   | | | <qİ W| d d d | d d d d g | d d d | d d d d g g } d d g } d S(   s-   Finds the intersection of two convex polygonsi    i   N(   R    R   t   leftmostVervexIndext   extendR   (	   R   R   R   t   leftmostVertexIndexR   t   jt
   newpolygont   previousPointt   activeIndex(    (    s7   /home/wjholcomb/.../projects/unsorted/us_map/polygon.pyR   "   s"      ) 	%+c         C   s   |  d } | i  d d g  xz |  D]r } t | d | d  | d <t | d | d  | d <t | d | d  | d <t | d | d  | d <q% W| S(   Ni    i   i   i   (   R   t   mint   max(   R   t   extentst   point(    (    s7   /home/wjholcomb/.../projects/unsorted/us_map/polygon.pyt   boundingRectangleN   s     c         C   s@   | d |  d | d |  d | d |  d | d |  d S(   sE   Return positive if p-q-r are clockwise, neg if ccw, zero if colinear.i   i    (    (   t   pt   qt   r(    (    s7   /home/wjholcomb/.../projects/unsorted/us_map/polygon.pyt   orientation\   s    c         C   s×   g  } g  } |  i    x´ |  D]Ĵ } xC t |  d j o/ t | d | d |  d j o | i   q& WxC t |  d j o/ t | d | d |  d j o | i   ql W| i |  | i |  q W| | f S(   sG   Graham scan to find upper and lower convex hulls of a set of 2d points.i   iŝ˙˙˙i˙˙˙˙i    (   t   sortR   R*   t   popR   (   t   pointst   uppert   lowerR%   (    (    s7   /home/wjholcomb/.../projects/unsorted/us_map/polygon.pyt   convexHulls`   s    
  4  4 N(   R   R   R   R&   R*   R0   (    (    (    s7   /home/wjholcomb/.../projects/unsorted/us_map/polygon.pys   <module>   s
   			,		