Ë
    Ï.fã.  ã                   óH   — d Z ddlZddlmZ ddlmZ ddlmZ  G d„ d«      Zy)a‡  Define the :class:`~geographiclib.polygonarea.PolygonArea` class

The constructor initializes a empty polygon.  The available methods are

  * :meth:`~geographiclib.polygonarea.PolygonArea.Clear` reset the
    polygon
  * :meth:`~geographiclib.polygonarea.PolygonArea.AddPoint` add a vertex
    to the polygon
  * :meth:`~geographiclib.polygonarea.PolygonArea.AddEdge` add an edge
    to the polygon
  * :meth:`~geographiclib.polygonarea.PolygonArea.Compute` compute the
    properties of the polygon
  * :meth:`~geographiclib.polygonarea.PolygonArea.TestPoint` compute the
    properties of the polygon with a tentative additional vertex
  * :meth:`~geographiclib.polygonarea.PolygonArea.TestEdge` compute the
    properties of the polygon with a tentative additional edge

The public attributes for this class are

  * :attr:`~geographiclib.polygonarea.PolygonArea.earth`
    :attr:`~geographiclib.polygonarea.PolygonArea.polyline`
    :attr:`~geographiclib.polygonarea.PolygonArea.area0`
    :attr:`~geographiclib.polygonarea.PolygonArea.num`
    :attr:`~geographiclib.polygonarea.PolygonArea.lat1`
    :attr:`~geographiclib.polygonarea.PolygonArea.lon1`

é    N)ÚMath)ÚAccumulator)ÚGeodesicc                   ó‚   — e Zd ZdZed„ «       Zed„ «       Zed„ «       Zed„ «       Zdd„Z	d„ Z
d„ Zd	„ Zdd
„Zdd„Zdd„Zy)ÚPolygonAreazArea of a geodesic polygonc                 óî   — t        j                  | |«      \  }}t        j                  | «      } t        j                  |«      }|dkD  r| dcxk  r|k  sn | dkD  r|dk(  rdS |dk  r|dcxk  r| k  rdS  dS )z/Count crossings of prime meridian for AddPoint.r   é   éÿÿÿÿ)r   ÚAngDiffÚAngNormalize)Úlon1Úlon2Úlon12Ú_s       úXC:\Users\user\Documents\project_loop\venv\Lib\site-packages\geographiclib/polygonarea.pyÚ_transitzPolygonArea._transit7   s‰   € ô �|‰|˜D $Ó'�H€Eˆ1Ü×Ñ˜TÓ"€DÜ×Ñ˜TÓ"€DØ˜’ ¨Ô!1¨TÔ!1Ø!%¨¢¨d°aªið ð @à š	 d¨QÔ&6°$Ò&6�"ð@à&6¸Að@ó    c                 ó¤   — t        j                  | d«      } t        j                  |d«      }d|cxk  rdk  rn ndndd| cxk  rdk  rdz
  S  dz
  S )z.Count crossings of prime meridian for AddEdge.g     €†@r   ih  r	   ©r   Ú	remainder)r   r   s     r   Ú_transitdirectzPolygonArea._transitdirectD   sX   € ô
 �>‰>˜$ Ó&€D¬t¯~©~¸dÀEÓ/J¨Ø˜”?˜s•?‰a¨Ø˜”?˜s’?ˆañ+ð -Ø"¨ñ+ð -r   c                 ó  — | j                  |«       |dz  r,| j                  | j                  «       dk  rdnd|z  dz  «       |s| j                  «        |rR| j                  «       |dz  kD  r| j                  | «       ns| j                  «       | dz  k  r\| j                  |«       nJ| j                  «       |k\  r| j                  | «       n$| j                  «       dk  r| j                  |«       d| j                  «       z   S )z)Reduce accumulator area to allowed range.r	   r   r
   é   ç        )Ú	RemainderÚAddÚSumÚNegate©ÚareaÚarea0Ú	crossingsÚreverseÚsigns        r   Ú_areareduceAzPolygonArea._areareduceAM   sÑ   € ð 	‡N�N�5ÔØ�1‚}Ø
‡h�h�d—h‘h“j 1’n‘¨"°Ñ5°aÑ7Ô9ñ �D—K‘K”MáØ	�‰‹�e˜A‘gÒ	Ø�‰�5�&ÕØ�8‰8‹:˜%˜ ™Ò!Ø�‰�5Õà	�‰‹�uÒ	Ø�‰�5�&ÕØ�8‰8‹:˜Š>Ø�‰�5Ôà�—‘“ÑÐr   c                 óô   — t        j                  | |«      } |dz  r| | dk  rdnd|z  dz  z  } |s| dz  } |r%| |dz  kD  r
| |z  } d| z   S | | dz  k  r| |z  } d| z   S | |k\  r
| |z  } d| z   S | dk  r| |z  } d| z   S )z$Reduce double area to allowed range.r	   r   r
   r   r   r   r   s        r   Ú_areareduceBzPolygonArea._areareduceBd   sÆ   € ô �>‰>˜$ Ó&€DØ�1‚}Ø
�D˜1’H‰q "¨Ñ-¨aÑ/Ñ/€dñ �D˜B‘J�DáØ	��a‘ŠØ�‰ˆð �‰:Ðð �E�6˜!‘8ÒØ�‰ˆð �‰:Ðð 
�ŠØ�‰ˆð �‰:Ðð �!Š8Ø�‰ˆà�‰:Ðr   c                 ó\  — || _         	 || _        	 dt        j                  z  |j                  z  | _        	 t        j                  t        j                  z  t        j                  z  | j                  rt        j                  n t        j                  t        j                  z  z  | _        | j                  st        «       | _        t        «       | _        d| _        	 t        j$                  | _        	 t        j$                  | _        	 d| _        t        j$                  x| _        | _        y)zãConstruct a PolygonArea object

    :param earth: a :class:`~geographiclib.geodesic.Geodesic` object
    :param polyline: if true, treat object as a polyline instead of a polygon

    Initially the polygon has no vertices.
    é   r   N)ÚearthÚpolylineÚmathÚpiÚ_c2r!   r   ÚLATITUDEÚ	LONGITUDEÚDISTANCEÚEMPTYÚAREAÚLONG_UNROLLÚ_maskr   Ú_areasumÚ_perimetersumÚnumÚnanÚlat1r   Ú
_crossingsÚ_lat0Ú_lon0)Úselfr*   r+   s      r   Ú__init__zPolygonArea.__init__{   s×   € ð €D„JØ(Ø€D„MØ(Ø”T—W‘W‘˜uŸy™yÑ(€D„JØ?Ü×#Ñ#¤h×&8Ñ&8Ñ8Ü×#Ñ#ñ$à%)§]¢]”8—>’>Ü—=‘=¤8×#7Ñ#7Ñ7ñ9€D„Jð �=Š=¬+«-˜$œ-Ü$›€DÔØ€D„HØ@Ü—‘€D„IØ4Ü—‘€D„IØ5Ø€D„OÜ"Ÿh™hÐ&€D„J�•r   c                 óø   — d| _         d| _        | j                  s| j                  j	                  d«       | j
                  j	                  d«       t        j                  x| _        x| _	        x| _
        | _        y)zReset to empty polygon.r   N)r8   r;   r+   r6   ÚSetr7   r,   r9   r<   r=   r:   r   )r>   s    r   ÚClearzPolygonArea.Clear™   s\   € à€D„HØ€D„OØ�=Š=˜$Ÿ-™-×+Ñ+¨AÔ.Ø×Ñ×Ñ˜1ÔÜ6:·h±hÐ>€D„JÐ>�”Ð>˜dœi¨$­)r   c           
      ó  — | j                   dk(  r|x| _        | _        |x| _        | _        nË| j
                  j                  | j                  | j                  ||| j                  «      \
  }}}}}}}}}}| j                  j                  |«       | j                  sN| j                  j                  |«       | xj                  t        j                  | j                  |«      z  c_        || _        || _        | xj                   dz  c_         y)zÕAdd the next vertex to the polygon

    :param lat: the latitude of the point in degrees
    :param lon: the longitude of the point in degrees

    This adds an edge from the current vertex to the new vertex.
    r   r	   N)r8   r<   r:   r=   r   r*   Ú_GenInverser5   r7   r   r+   r6   r;   r   r   )r>   ÚlatÚlonr   Ús12ÚS12s         r   ÚAddPointzPolygonArea.AddPoint¡   sÒ   € ð ‡x�x�1‚}Ø"Ð"€d„j�4”9Ø"Ð"€d„j�4•9à)-¯©×)?Ñ)?Ø�	‰	�4—9‘9˜c 3¨¯
©
ó*4Ñ&€aˆˆa��A�q˜!˜Q  3à
×Ñ×Ñ˜SÔ!Ø�]Š]Ø�‰×Ñ˜#ÔØ�Šœ;×/Ñ/°·	±	¸3Ó?Ñ?�Ø€d„iØ€d„iØ‡H‚H��M†Hr   c           	      óä  — | j                   dk7  rá| j                  j                  | j                  | j                  |d|| j
                  «      \	  }}}}}}}}}| j                  j                  |«       | j                  sN| j                  j                  |«       | xj                  t        j                  | j                  |«      z  c_
        || _        || _        | xj                   dz  c_         yy)zëAdd the next edge to the polygon

    :param azi: the azimuth at the current the point in degrees
    :param s: the length of the edge in meters

    This specifies the new vertex in terms of the edge from the current
    vertex.

    r   Fr	   N)r8   r*   Ú
_GenDirectr:   r   r5   r7   r   r+   r6   r;   r   r   )r>   ÚaziÚsr   rE   rF   rH   s          r   ÚAddEdgezPolygonArea.AddEdge¸   s»   € ð ‡x�x�1‚}Ø(,¯
©
×(=Ñ(=Ø�	‰	�4—9‘9˜c 5¨!¨T¯Z©Zó)9Ñ%€aˆˆc�1�a˜˜A˜q #à
×Ñ×Ñ˜QÔØ�]Š]Ø�‰×Ñ˜#ÔØ�Šœ;×5Ñ5°d·i±iÀÓEÑE�Ø€d„iØ€d„iØ
‡h‚h�!�m†hð r   c           
      ó  — | j                   rt        j                  }| j                  dk  rd}| j                   sd}| j                  |fS | j                   r)| j                  j                  «       }| j                  |fS | j                  j                  | j                  | j                  | j                  | j                  | j                  «      \
  }}}}}}}}}}| j                  j                  |«      }t        | j                  «      }|j                  |«       | j                   t"        j%                  | j                  | j                  «      z   }	t"        j'                  || j(                  |	||«      }| j                  ||fS )a‹  Compute the properties of the polygon

    :param reverse: if true then clockwise (instead of
      counter-clockwise) traversal counts as a positive area
    :param sign: if true then return a signed result for the area if the
      polygon is traversed in the "wrong" direction instead of returning
      the area for the rest of the earth
    :return: a tuple of number, perimeter (meters), area (meters^2)

    Arbitrarily complex polygons are allowed.  In the case of
    self-intersecting polygons the area is accumulated "algebraically",
    e.g., the areas of the 2 loops in a figure-8 polygon will partially
    cancel.

    If the object is a polygon (and not a polyline), the perimeter
    includes the length of a final edge connecting the current point to
    the initial point.  If the object is a polyline, then area is nan.

    More points can be added to the polygon after this call.

    r   r   )r+   r,   r9   r8   r7   r   r*   rD   r:   r   r<   r=   r5   r   r6   r   r;   r   r   r%   r!   )
r>   r#   r$   r    Ú	perimeterr   rG   rH   Útempsumr"   s
             r   ÚComputezPolygonArea.ComputeÏ   s7  € ð, ‡}‚}œTŸX™X�dØ‡x�x�!‚|Ø€iØ�]Š] 3˜DØ�X‰X�y $Ð&Ð&à‡}‚}Ø×$Ñ$×(Ñ(Ó*€iØ�X‰X�y $Ð&Ð&à'+§z¡z×'=Ñ'=Ø
‡i�i�—‘˜DŸJ™J¨¯
©
°D·J±Jó(@Ñ$€A€sˆAˆq�!�Q˜˜1˜a à×"Ñ"×&Ñ& sÓ+€IÜ˜$Ÿ-™-Ó(€GØ‡K�K�ÔØ—‘¤+×"6Ñ"6°t·y±yÀ$Ç*Á*Ó"MÑM€IÜ×#Ñ# G¨T¯Z©Z¸Ø$+¨Tó3€Dà�8‰8�Y Ð$Ð$r   c                 ór  — | j                   rt        j                  }| j                  dk(  rd}| j                   sd}d|fS | j                  j                  «       }| j                   rdn| j                  j                  «       }| j                  }| j                  dz   }	| j                   rdgnddgD ]Ì  }
| j                  j                  |
dk(  r| j                  n||
dk(  r| j                  n||
dk7  r| j                  n||
dk7  r| j                  n|| j                  «      \
  }}}}}}}}}}||z  }| j                   rŒ�||z  }|t        j!                  |
dk(  r| j                  n||
dk7  r| j                  n|«      z  }ŒÎ | j                   r|	|fS t        j#                  || j$                  |||«      }|	||fS )a  Compute the properties for a tentative additional vertex

    :param lat: the latitude of the point in degrees
    :param lon: the longitude of the point in degrees
    :param reverse: if true then clockwise (instead of
      counter-clockwise) traversal counts as a positive area
    :param sign: if true then return a signed result for the area if the
      polygon is traversed in the "wrong" direction instead of returning
      the area for the rest of the earth
    :return: a tuple of number, perimeter (meters), area (meters^2)

    r   r   r	   )r+   r,   r9   r8   r7   r   r6   r;   r*   rD   r:   r   r<   r=   r5   r   r   r'   r!   )r>   rE   rF   r#   r$   r    rP   rQ   r"   r8   Úir   rG   rH   s                 r   Ú	TestPointzPolygonArea.TestPointú   s›  € ð ‡}‚}œTŸX™X�dØ‡x�x�1‚}Ø€iØ�]Š] 3˜DØ�	˜4ÐÐà×"Ñ"×&Ñ&Ó(€IØ—]’]‰c¨¯©×(9Ñ(9Ó(;€GØ—‘€I t§x¡x°!¡| Ø—]’]ˆq‰c¨¨A¨ò 	HˆØ)-¯©×)?Ñ)?Ø˜!’Vˆ�	Š	 °1¸²6 d§i¢i¸sØ˜1’fˆ�
Š
 #°Q¸!²V t§z¢zÀØ�
‰
ó*Ñ&€aˆˆa��A�q˜!˜Q  3ð �3Ñ€iØ�]‹]Ø�3‰ˆØ”[×)Ñ)°q¸A²v¨$¯)ª)À3Ø78¸A²v¨¯ªÀ3óHñ 	H‰	ð	Hð ‡}‚}Ø�)˜TÐ!Ð!ä×#Ñ# G¨T¯Z©Z¸Ø$+¨Tó3€Dà�	˜4ÐÐr   c           
      ó^  — | j                   dk(  r!dt        j                  t        j                  fS | j                   dz   }| j                  j	                  «       |z   }| j
                  r||t        j                  fS | j                  j	                  «       }| j                  }| j                  j                  | j                  | j                  |d|| j                  «      \	  }	}
}}	}	}	}	}	}||z  }|t        j                  | j                  |«      z  }| j                  j                  |
|| j                   | j"                  | j                  «      \
  }	}}	}	}	}	}	}	}	}||z  }||z  }|t        j%                  || j"                  «      z  }t        j'                  || j(                  |||«      }|||fS )a  Compute the properties for a tentative additional edge

    :param azi: the azimuth at the current the point in degrees
    :param s: the length of the edge in meters
    :param reverse: if true then clockwise (instead of
      counter-clockwise) traversal counts as a positive area
    :param sign: if true then return a signed result for the area if the
      polygon is traversed in the "wrong" direction instead of returning
      the area for the rest of the earth
    :return: a tuple of number, perimeter (meters), area (meters^2)

    r   r	   F)r8   r,   r9   r7   r   r+   r6   r;   r*   rK   r:   r   r5   r   r   rD   r<   r=   r   r'   r!   )r>   rL   rM   r#   r$   r8   rP   rQ   r"   r   rE   rF   rH   rG   r    s                  r   ÚTestEdgezPolygonArea.TestEdge#  s{  € ð ‡x�x�1‚}Ø”—‘œ$Ÿ(™(Ð"Ð"Ø
�(‰(�Q‰,€CØ×"Ñ"×&Ñ&Ó(¨1Ñ,€IØ‡}‚}Ø�)œTŸX™XÐ%Ð%à�}‰}× Ñ Ó"€GØ—‘€IØ&*§j¡j×&;Ñ&;Ø
‡i�i�—‘˜C ¨¨4¯:©:ó'7Ñ#€A€sˆC��A�q˜!˜Q àˆs�N€GØ”×+Ñ+¨D¯I©I°sÓ;Ñ;€IØ'+§z¡z×'=Ñ'=Ø	ˆ3�—
‘
˜DŸJ™J¨¯
©
ó(4Ñ$€A€sˆAˆq�!�Q˜˜1˜a à�Ñ€IØˆs�N€GØ”×%Ñ% c¨4¯:©:Ó6Ñ6€Iä×#Ñ# G¨T¯Z©Z¸Ø$+¨Tó3€Dà�	˜4ÐÐr   N)F)FT)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ústaticmethodr   r   r%   r'   r?   rB   rI   rN   rR   rU   rW   © r   r   r   r   4   sz   „ Ù"àñ
@ó ð
@ð ñ-ó ð-ð ñó ðð, ñó ðó,'ò<?òò.ó.(%óV& ôR# r   r   )	r[   r,   Úgeographiclib.geomathr   Úgeographiclib.accumulatorr   Úgeographiclib.geodesicr   r   r]   r   r   ú<module>ra      s%   ðñó\ Ý &Ý 1Ý +÷R ò R r   