o
    ýòTiã.  ã                   @   sB   d Z ddlZddlmZ ddlmZ ddlmZ G dd„ dƒZdS )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                   @   s€   e Zd ZdZedd„ ƒZedd„ ƒZedd„ ƒZedd	„ ƒZddd„Z	dd„ Z
dd„ Zdd„ Zddd„Zddd„Zddd„ZdS )ÚPolygonAreazArea of a geodesic polygonc                 C   sz   t  | |¡\}}t  | ¡} t  |¡}|dkr+| d  k r |ks)n | dkr+|dkr+dS |dk r;|d  k r:| kr;dS  dS )z/Count crossings of prime meridian for AddPoint.r   é   éÿÿÿÿ)r   ZAngDiffZAngNormalize)Úlon1Úlon2Zlon12Ú_© r   úY/var/www/html/evchargy.com/venv/lib/python3.10/site-packages/geographiclib/polygonarea.pyÚ_transit7   s   

ÿþþzPolygonArea._transitc                 C   sV   t  | d¡} t  |d¡}d|  krdk rn ndndd|   kr'dk r(d S  d S )z.Count crossings of prime meridian for AddEdge.g     €†@r   ih  r   ©r   Ú	remainder)r   r	   r   r   r   Ú_transitdirectD   s   ÿÿzPolygonArea._transitdirectc                 C   s¼   |   |¡ |d@ r|  |  ¡ dk rdnd| d ¡ |s |  ¡  |r@|  ¡ |d kr1|  | ¡ n'|  ¡ | d kr?|  |¡ n|  ¡ |krM|  | ¡ n|  ¡ dk rX|  |¡ d|  ¡  S )z)Reduce accumulator area to allowed range.r   r   r   é   ç        )Z	RemainderÚAddÚSumZNegate©ÚareaÚarea0Ú	crossingsÚreverseÚsignr   r   r   Ú_areareduceAM   s   
"
€
zPolygonArea._areareduceAc                 C   sª   t  | |¡} |d@ r| | dk rdnd| d 7 } |s| d9 } |r=| |d kr.| |8 } d|  S | | d kr9| |7 } d|  S | |krI| |8 } d|  S | dk rQ| |7 } d|  S )z$Reduce double area to allowed range.r   r   r   r   r   r   r   r   r   r   Ú_areareduceBd   s"   	øûýzPolygonArea._areareduceBFc                 C   sš   || _ 	 || _	 dtj |j | _	 tjtjB tj	B | jr tj
ntjtjB B | _| js/tƒ | _tƒ | _d| _	 tj| _	 tj| _	 d| _tj | _| _dS )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ÚpiZ_c2r   r   ZLATITUDEZ	LONGITUDEZDISTANCEZEMPTYZAREAZLONG_UNROLLÚ_maskr   Ú_areasumÚ_perimetersumÚnumÚnanÚlat1r   Ú
_crossingsÚ_lat0Ú_lon0)Úselfr   r   r   r   r   Ú__init__{   s,   	
ÿ
ýzPolygonArea.__init__c                 C   sH   d| _ d| _| js| j d¡ | j d¡ tj | _ | _	 | _
| _dS )zReset to empty polygon.r   N)r%   r(   r   r#   ÚSetr$   r    r&   r)   r*   r'   r   )r+   r   r   r   ÚClear™   s
   zPolygonArea.Clearc              
   C   s¦   | j dkr| | _| _| | _| _n8| j | j| j||| j¡\
}}}}}}}}}}| j 	|¡ | j
sD| j 	|¡ |  jt | j|¡7  _|| _|| _|  j d7  _ dS )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)r%   r)   r'   r*   r   r   Ú_GenInverser"   r$   r   r   r#   r(   r   r   )r+   ÚlatÚlonr
   Ús12ÚS12r   r   r   ÚAddPoint¡   s   
	ÿzPolygonArea.AddPointc              	   C   s   | j dkrF| j | j| j|d|| j¡\	}}}}}}}}}| j |¡ | js7| j	 |¡ |  j
t | j|¡7  _
|| _|| _|  j d7  _ dS dS )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)r%   r   Ú
_GenDirectr'   r   r"   r$   r   r   r#   r(   r   r   )r+   ÚaziÚsr
   r0   r1   r3   r   r   r   ÚAddEdge¸   s   
ÿ÷zPolygonArea.AddEdgeTc           
   
   C   sÔ   | j rtj}| jdk rd}| j sd}| j||fS | j r&| j ¡ }| j||fS | j | j| j	| j
| j| j¡\
}}}}}}}}}}| j |¡}t| jƒ}| |¡ | jt | j	| j¡ }	t || 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    r&   r%   r$   r   r   r/   r'   r   r)   r*   r"   r   r#   r   r(   r   r   r   r   )
r+   r   r   r   Ú	perimeterr
   r2   r3   Útempsumr   r   r   r   ÚComputeÏ   s&   


ÿ

ÿzPolygonArea.Computec                 C   sH  | j rtj}| jdkrd}| j sd}d||fS | j ¡ }| j r!dn| j ¡ }| j}| jd }	| j r4dgnddgD ]T}
| j 	|
dkrD| j
n||
dkrL| jn||
dkrT| jn||
dkr\| jn|| j¡\
}}}}}}}}}}||7 }| j sŒ||7 }|t |
dkr€| jn||
dkrˆ| jn|¡7 }q8| j r•|	||fS t || 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    r&   r%   r$   r   r#   r(   r   r/   r'   r   r)   r*   r"   r   r   r   r   )r+   r0   r1   r   r   r   r9   r:   r   r%   Úir
   r2   r3   r   r   r   Ú	TestPointú   s6   



  ýÿ€
ÿ
zPolygonArea.TestPointc              
   C   s  | j dkrdtjtjfS | j d }| j ¡ | }| jr!||tjfS | j ¡ }| j}| j 	| j
| j|d|| j¡\	}	}
}}	}	}	}	}	}||7 }|t | j|¡7 }| j |
|| j| j| j¡\
}	}}	}	}	}	}	}	}	}||7 }||7 }|t || j¡7 }t || 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)r%   r    r&   r$   r   r   r#   r(   r   r5   r'   r   r"   r   r   r/   r)   r*   r   r   r   )r+   r6   r7   r   r   r%   r9   r:   r   r
   r0   r1   r3   r2   r   r   r   r   ÚTestEdge#  s.   


ÿÿÿ
zPolygonArea.TestEdgeN)F)FT)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ústaticmethodr   r   r   r   r,   r.   r4   r8   r;   r=   r>   r   r   r   r   r   4   s"    






+)r   )	rB   r    Zgeographiclib.geomathr   Zgeographiclib.accumulatorr   Zgeographiclib.geodesicr   r   r   r   r   r   Ú<module>   s    .