
    h.                     H    S r SSKrSSKJr  SSKJr  SSKJr   " S S5      rg)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                       \ rS rSrSr\S 5       r\S 5       r\S 5       r\S 5       r	SS jr
S rS	 rS
 rSS jrSS jrSS jrSrg)PolygonArea4   zArea of a geodesic polygonc                     [         R                  " X5      u  p#[         R                  " U 5      n [         R                  " U5      nUS:  a  U Ss=:  a  U::  d  O  U S:  a  US:X  a  S$ US:  a  USs=:  a  U ::  a  S$   S$ )z/Count crossings of prime meridian for AddPoint.r      )r   AngDiffAngNormalize)lon1lon2lon12_s       lC:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\geographiclib/polygonarea.py_transitPolygonArea._transit7   s     ||D'HET"DT"D!1T!1!%dai  @	dQ&6$&6"@&6A@    c                     [         R                  " U S5      n [         R                  " US5      nSUs=::  a  S:  a  O  OSOSSU s=::  a	  S:  a  S-
  $   S-
  $ )z.Count crossings of prime meridian for AddEdge.g     @r   ih  r
   r   	remainder)r   r   s     r   _transitdirectPolygonArea._transitdirectD   sX    
 >>$&Dt~~dE/J?s?a?s?a+ -"+ -r   c                 4   U R                  U5        US-  (       a-  U R                  U R                  5       S:  a  SOSU-  S-  5        U(       d  U R                  5         U(       aT  U R                  5       US-  :  a  U R                  U* 5        OvU R                  5       U* S-  ::  a  U R                  U5        OLU R                  5       U:  a  U R                  U* 5        O%U R                  5       S:  a  U R                  U5        SU R                  5       -   $ )z)Reduce accumulator area to allowed range.r
   r   r              )	RemainderAddSumNegateareaarea0	crossingsreversesigns        r   _areareduceAPolygonArea._areareduceAM   s     	NN51}
hhdhhj1n"5a79 DKKM	eAg	5&88:%!5	u	5&88:>5r   c                    [         R                  " X5      n US-  (       a  X S:  a  SOSU-  S-  -  n U(       d  U S-  n U(       a#  XS-  :  a	  X-  n SU -   $ X* S-  ::  a  X-  n SU -   $ X:  a	  X-  n SU -   $ U S:  a  X-  n SU -   $ )z$Reduce double area to allowed range.r
   r   r   r   r   r   r"   s        r   _areareduceBPolygonArea._areareduceBd   s     >>$&D1}
1Hq"-a//d DBJD	a : 6!8 : 
 : !8:r   c                 l   Xl          X l         S[        R                  -  UR                  -  U l         [        R                  [        R                  -  [        R                  -  U R                  (       a  [        R                  O [        R                  [        R                  -  -  U l        U R                  (       d  [        5       U l        [        5       U l        SU l         [        R$                  U l         [        R$                  U l         SU l        [        R$                  =U l        U l        g)zConstruct 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/   r0   s      r   __init__PolygonArea.__init__{   s     J(M(TWWuyy(DJ?##h&8&88##$%)]]8>>==8#7#779DJ ==+-$-$DDH@DI4DI5DO"hh&DJr   c                    SU l         SU l        U R                  (       d  U R                  R	                  S5        U R
                  R	                  S5        [        R                  =U l        =U l	        =U l
        U l        g)zReset to empty polygon.r   N)r=   r@   r0   r;   Setr<   r1   r>   rA   rB   r?   r   )rC   s    r   ClearPolygonArea.Clear   s\    DHDO==$--++A.16:hh>DJ>>di$)r   c           
         U R                   S:X  a  U=U l        U l        U=U l        U l        OU R
                  R                  U R                  U R                  XU R                  5      u
  p4            p5U R                  R                  U5        U R                  (       dN  U R                  R                  U5        U =R                  [        R                  U R                  U5      -  sl        Xl        X l        U =R                   S-  sl         g)zAdd 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)r=   rA   r?   rB   r   r/   _GenInverser:   r<   r   r0   r;   r@   r   r   )rC   latlonr   s12S12s         r   AddPointPolygonArea.AddPoint   s     xx1}""dj49""dj49)-)?)?		499c

*4&aaAq!Q
S!]]#;//		3??iiHHMHr   c           	         U R                   S:w  a  U R                  R                  U R                  U R                  USX R
                  5      u	  p4n        p6U R                  R                  U5        U R                  (       dN  U R                  R                  U5        U =R                  [        R                  U R                  U5      -  sl
        X@l        XPl        U =R                   S-  sl         gg)zAdd 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)r=   r/   
_GenDirectr?   r   r:   r<   r   r0   r;   r@   r   r   )rC   azisr   rL   rM   rO   s          r   AddEdgePolygonArea.AddEdge   s     xx1}(,

(=(=		499c5!ZZ)9%ac1aAq
Q]]#;55diiEEii
hh!mh r   c           
      "   U R                   (       a  [        R                  nU R                  S:  a$  SnU R                   (       d  SnU R                  UW4$ U R                   (       a)  U R                  R                  5       nU R                  UW4$ U R                  R                  U R                  U R                  U R                  U R                  U R                  5      u
  pV            pWU R                  R                  U5      n[        U R                  5      nUR                  U5        U R                   ["        R%                  U R                  U R                  5      -   n	["        R'                  XR(                  U	X5      nU R                  XC4$ )aO  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   )r0   r1   r>   r=   r<   r    r/   rK   r?   r   rA   rB   r:   r   r;   r   r@   r   r   r(   r$   )
rC   r&   r'   r#   	perimeterr   rN   rO   tempsumr%   s
             r   ComputePolygonArea.Compute   s-   , }}TXXdxx!|i]]3DXXy$&&}}$$((*iXXy$&&'+zz'='=
iiDJJ

DJJ(@$AAq!Q1a""&&s+I$--(GKK+"6"6tyy$**"MMI##GZZ$+3D88Y$$r   c                    U R                   (       a  [        R                  nU R                  S:X  a  SnU R                   (       d  SnSUW4$ U R                  R                  5       nU R                   (       a  SOU R                  R                  5       nU R                  oR                  S-   n	U R                   (       a  S/OSS/ H  n
U R                  R                  U
S:X  a  U R                  OUU
S:X  a  U R                  OUU
S:w  a  U R                  OUU
S:w  a  U R                  OUU R                  5      u
  p            pXl-  nU R                   (       a  M  X}-  nU[        R!                  U
S:X  a  U R                  OUU
S:w  a  U R                  OU5      -  nM     U R                   (       a  XW4$ [        R#                  XpR$                  UX45      nXU4$ )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
   )r0   r1   r>   r=   r<   r    r;   r@   r/   rK   r?   r   rA   rB   r:   r   r   r+   r$   )rC   rL   rM   r&   r'   r#   rY   rZ   r%   r=   ir   rN   rO   s                 r   	TestPointPolygonArea.TestPoint   s    }}TXXdxx1}i]]3D	4""&&(I]]c(9(9(;GIxx!|]]qcA.)-)?)?!V		16diis1f

#Q!Vtzz

*&aaAq!Q i]]][))qAv$))378Av3H 	H	 / }}T!!##GZZ$+3D4r   c           
      N   U R                   S:X  a!  S[        R                  [        R                  4$ U R                   S-   nU R                  R	                  5       U-   nU R
                  (       a  XV[        R                  4$ U R                  R	                  5       nU R                  nU R                  R                  U R                  U R                  USX R                  5      u	  pn        pX|-  nU[        R                  U R                  U5      -  nU R                  R                  XU R                   U R"                  U R                  5      u
  p            pXm-  nX|-  nU[        R%                  XR"                  5      -  n[        R'                  XpR(                  UX45      nXVU4$ )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)r=   r1   r>   r<   r    r0   r;   r@   r/   rS   r?   r   r:   r   r   rK   rA   rB   r   r+   r$   )rC   rT   rU   r&   r'   r=   rY   rZ   r%   r   rL   rM   rO   rN   r#   s                  r   TestEdgePolygonArea.TestEdge#  s_    xx1}$((""
((Q,C""&&(1,I}}TXX%%}}  "GI&*jj&;&;
iiC::'7#ACAq!QNG++DIIs;;I'+zz'='=	

DJJ

(4$AAq!Q1aING%%c::66I##GZZ$+3D4r   )r;   r@   rA   rB   r:   r<   r$   r/   r?   r   r=   r0   N)F)FT)__name__
__module____qualname____firstlineno____doc__staticmethodr   r   r(   r+   rD   rH   rP   rV   r[   r_   rb   __static_attributes__ r   r   r   r   4   sz    "
@ 
@ - -  ,  ,'<?..(%V& R# r   r   )	rh   r1   geographiclib.geomathr   geographiclib.accumulatorr   geographiclib.geodesicr   r   rk   r   r   <module>ro      s%   \  & 1 +R  R r   