
    g.                     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       Y/var/www/api/v1/venv_getwork_v1/lib/python3.12/site-packages/geographiclib/polygonarea.py_transitzPolygonArea._transit7   s     ||D$'HE1T"DT"D!1T!1!%dai  @	dQ&6$&6"@&6A@    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    
 >>$&Dt~~dE/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     	NN51}
hhdhhj1n"5a79 DKKM	eAg	5&88:%!5	u	5&88:>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}
D1Hq"-a//d DBJD	a : E6!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)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*   r+   s      r   __init__zPolygonArea.__init__{   s     DJ(DM(TWWuyy(DJ?##h&8&88##$%)]]8>>==8#7#779DJ ==+-$-$DDH@DI4DI5DO"hh&DJ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\    DHDO==$--++A.16:hh>DJ>>di$)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)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)r8   r<   r:   r=   r   r*   _GenInverser5   r7   r   r+   r6   r;   r   r   )r>   latlonr   s12S12s         r   AddPointzPolygonArea.AddPoint   s     xx1}""dj49""dj49)-)?)?		499c3

*4&aaAq!Q3
S!]]#;//		3??didiHHMHr   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)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)r8   r*   
_GenDirectr:   r   r5   r7   r   r+   r6   r;   r   r   )r>   azisr   rE   rF   rH   s          r   AddEdgezPolygonArea.AddEdge   s     xx1}(,

(=(=		499c5!TZZ)9%ac1aAq#
Q]]#;55diiEEdidi
hh!mh 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   , }}TXXdxx!|i]]3DXXy$&&}}$$((*iXXy$&&'+zz'='=
iiDJJ

DJJ(@$AsAq!Q1a""&&s+I$--(GKK+"6"6tyy$**"MMI##GTZZ$+T3D88Y$$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    }}TXXdxx1}i]]3D	4""&&(I]]c(9(9(;GItxx!|]]qcA.)-)?)?!V		16diis1f

#Q!Vtzz

*&aaAq!Q3 3i]]3[))qAv$))378Av3H 	H	 / }})T!!##GTZZ$+T3D	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{    xx1}$((""
((Q,C""&&(1,I}})TXX%%}}  "GI&*jj&;&;
iiC4::'7#AsCAq!QsNG++DIIs;;I'+zz'='=	3

DJJ

(4$AsAq!Q1aIsNG%%c4::66I##GTZZ$+T3D	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   