U
    …7hã.  ã                   @   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   s~   t  | |¡\}}t  | ¡} t  |¡}|dkrV| d  k r@|ksRn | dkrV|dkrVdS |dk rz|d  k rr| krzn ndS dS )z/Count crossings of prime meridian for AddPoint.r   é   éÿÿÿÿ)r   ZAngDiffZAngNormalize)Úlon1Úlon2Zlon12Ú_© r   úS/var/www/formularioweb/env/lib/python3.8/site-packages/geographiclib/polygonarea.pyÚ_transit7   s    

ÿÿ&þzPolygonArea._transitc                 C   sX   t  | d¡} t  |d¡}d|  kr,dk r4n ndndd|   krJdk rRn ndn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@ r4|  |  ¡ dk r&dnd| d ¡ |s@|  ¡  |r€|  ¡ |d krb|  | ¡ q°|  ¡ | d kr°|  |¡ n0|  ¡ |krš|  | ¡ n|  ¡ dk r°|  |¡ 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@ r0| | dk r"dnd| d 7 } |s<| d9 } |rn| |d krV| |8 } q| | d kr| |7 } n"| |kr€| |8 } n| dk r| |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sXtƒ | _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$| | _| _| | _| _np| j | j| j||| j¡\
}}}}}}}}}}| j 	|¡ | j
sˆ| 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rˆ| j | j| j|d|| j¡\	}}}}}}}}}| j |¡ | jsn| j	 |¡ |  j
t | j|¡7  _
|| _|| _|  j d7  _ 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 r0d}| j s$d}| j||fS | j rL| 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Ï   s4     
 
    ÿ

 ÿzPolygonArea.Computec                 C   sN  | j rtj}| jdkr.d}| j s$d}d||fS | j ¡ }| j rBdn| j ¡ }| j}| jd }	| j rhdgnddgD ]¬}
| j 	|
dkrˆ| j
n||
dkr˜| jn||
dkr¨| jn||
dkr¸| jn|| j¡\
}}}}}}}}}}||7 }| j sp||7 }|t |
dkr| jn||
dkr| jn|¡7 }qp| j r0|	||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ú   s@     
 

 
  ýÿ
 ÿzPolygonArea.TestPointc              
   C   s  | j dkrdtjtjfS | j d }| j ¡ | }| jrB||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#  sB    


     ÿ    ÿ ÿzPolygonArea.TestEdgeN)F)FT)FT)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
   .