o
    Tit                     @   sp   d Z ddlmZmZmZmZ ddlmZ ddl	m
Z
 ddlmZ ddlmZmZ ddlmZ G dd	 d	e
Zd
S )z
 This module houses the GEOSCoordSeq object, which is used internally
 by GEOSGeometry to house the actual coordinates of the Point,
 LineString, and LinearRing geometries.
    )byrefc_bytec_doublec_uint)
prototypes)GEOSBaseGEOSException)CS_PTRgeos_version_tuple)numpyc                   @   sB  e Zd ZdZeZdHddZdd Zdd Zd	d
 Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zedd  Zd!d" Zd#d$ Zd%d& Zd'd( Zd)d* Zd+d, Zd-d. Zd/d0 Zd1d2 Zd3d4 Zd5d6 Z d7d8 Z!ed9d: Z"ed;d< Z#ed=d> Z$d?d@ Z%edAdB Z&edCdD Z'edEdF Z(dGS )IGEOSCoordSeqzGThe internal representation of a list of coordinates inside a Geometry.Fc                 C   s"   t |ts	td|| _|| _dS )zInitialize from a GEOS pointer.z4Coordinate sequence should initialize with a CS_PTR.N)
isinstancer
   	TypeErrorZ_ptr_z)selfptrz r   `/var/www/html/evchargy.com/venv/lib/python3.10/site-packages/django/contrib/gis/geos/coordseq.py__init__   s   

zGEOSCoordSeq.__init__c                 c   s     t | jD ]}| | V  qdS )z3Iterate over each point in the coordinate sequence.N)rangesize)r   ir   r   r   __iter__   s   zGEOSCoordSeq.__iter__c                 C      | j S )z7Return the number of points in the coordinate sequence.)r   r   r   r   r   __len__    s   zGEOSCoordSeq.__len__c                 C   s
   t | jS )z<Return the string representation of the coordinate sequence.)strtupler   r   r   r   __str__$   s   
zGEOSCoordSeq.__str__c                 C   s   |  | | |S )z8Return the coordinate sequence value at the given index.)_checkindex_point_getterr   indexr   r   r   __getitem__(   s   

zGEOSCoordSeq.__getitem__c                 C   s|   t |ttfrntrt |tjrntd| jdkr#| jr#d}| j}nd}| j	}t
||kr2td| | ||| dS )z5Set the coordinate sequence value at the given index.zBMust set coordinate with a sequence (list, tuple, or numpy array).      z"Dimension of value does not match.N)r   listr   r   Zndarrayr   dimsr   _set_point_3d_set_point_2dlenr!   )r   r$   valueZn_argsZpoint_setterr   r   r   __setitem__-   s    
zGEOSCoordSeq.__setitem__c                 C   s(   d|  kr| j k sn td| dS )zCheck the given index.r   zinvalid GEOS Geometry index: %sN)r   
IndexErrorr#   r   r   r   r!   E   s   zGEOSCoordSeq._checkindexc                 C   s    |dk s|dkrt d| dS )zCheck the given dimension.r   r'   zinvalid ordinate dimension "%d"Nr   )r   dimr   r   r   	_checkdimJ   s   zGEOSCoordSeq._checkdimc                 C      t | j|tt S N)capiZcs_getxr   r   r   r#   r   r   r   _get_xO      zGEOSCoordSeq._get_xc                 C   r2   r3   )r4   Zcs_getyr   r   r   r#   r   r   r   _get_yR   r6   zGEOSCoordSeq._get_yc                 C   r2   r3   )r4   Zcs_getzr   r   r   r#   r   r   r   _get_zU   r6   zGEOSCoordSeq._get_zc                 C      t | j|| d S r3   )r4   Zcs_setxr   r   r$   r-   r   r   r   _set_xX      zGEOSCoordSeq._set_xc                 C   r9   r3   )r4   Zcs_setyr   r:   r   r   r   _set_y[   r<   zGEOSCoordSeq._set_yc                 C   r9   r3   )r4   Zcs_setzr   r:   r   r   r   _set_z^   r<   zGEOSCoordSeq._set_zc                 C   s   | j dkr| jr| jS | jS )Nr&   )r)   r   _get_point_3d_get_point_2dr   r   r   r   r"   a   s   zGEOSCoordSeq._point_getterc                 C   s   |  || |fS r3   )r5   r7   r#   r   r   r   r@   e   r<   zGEOSCoordSeq._get_point_2dc                 C   s   |  || || |fS r3   )r5   r7   r8   r#   r   r   r   r?   h   s   zGEOSCoordSeq._get_point_3dc                 C   s$   |\}}|  || | || d S r3   )r;   r=   )r   r$   r-   xyr   r   r   r+   k   s   zGEOSCoordSeq._set_point_2dc                 C   s2   |\}}}|  || | || | || d S r3   )r;   r=   r>   )r   r$   r-   rA   rB   r   r   r   r   r*   p   s   
zGEOSCoordSeq._set_point_3dc                 C   s,   |  | | | t| j||tt S )z3Return the value for the given dimension and index.)r!   r1   r4   Zcs_getordinater   r   r   )r   	dimensionr$   r   r   r   getOrdinatew   s   

zGEOSCoordSeq.getOrdinatec                 C   s*   |  | | | t| j||| dS )z0Set the value for the given dimension and index.N)r!   r1   r4   Zcs_setordinater   )r   rC   r$   r-   r   r   r   setOrdinate}   s   

zGEOSCoordSeq.setOrdinatec                 C      |  d|S )zGet the X value at the index.r   rD   r#   r   r   r   getX      zGEOSCoordSeq.getXc                 C      |  d|| dS )z(Set X with the value at the given index.r   NrE   r:   r   r   r   setX      zGEOSCoordSeq.setXc                 C   rF   )z#Get the Y value at the given index.   rG   r#   r   r   r   getY   rI   zGEOSCoordSeq.getYc                 C   rJ   )z(Set Y with the value at the given index.rN   NrK   r:   r   r   r   setY   rM   zGEOSCoordSeq.setYc                 C   rF   )z(Get Z with the value at the given index.r'   rG   r#   r   r   r   getZ   rI   zGEOSCoordSeq.getZc                 C   rJ   )z(Set Z with the value at the given index.r'   NrK   r:   r   r   r   setZ   rM   zGEOSCoordSeq.setZc                 C      t | jtt S )z,Return the size of this coordinate sequence.)r4   Z
cs_getsizer   r   r   r   r   r   r   r         zGEOSCoordSeq.sizec                 C   rS   )z2Return the dimensions of this coordinate sequence.)r4   Z
cs_getdimsr   r   r   r   r   r   r   r)      rT   zGEOSCoordSeq.dimsc                 C   r   )z
        Return whether this coordinate sequence is 3D. This property value is
        inherited from the parent Geometry.
        )r   r   r   r   r   hasz   s   zGEOSCoordSeq.haszc                 C   s   t t| j| jS )zClone this coordinate sequence.)r   r4   Zcs_cloner   rU   r   r   r   r   clone   s   zGEOSCoordSeq.clonec                    s:    j rdnddd fddtt D   S )z2Return the KML representation for the coordinates.z	%s,%s,%s z%s,%s,0 z<coordinates>%s</coordinates> c                 3   s    | ]	} |  V  qd S r3   r   .0r   r   substrr   r   	<genexpr>   s    z#GEOSCoordSeq.kml.<locals>.<genexpr>)rU   joinr   r,   stripr   r   rZ   r   kml   s   $zGEOSCoordSeq.kmlc                    s6   | j }| j |dkr dS t fddt|D S )z3Return a tuple version of this coordinate sequence.rN   r   c                 3   s    | ]} |V  qd S r3   r   rX   Z	get_pointr   r   r\      s    z%GEOSCoordSeq.tuple.<locals>.<genexpr>)r   r"   r   r   )r   nr   r`   r   r      s
   zGEOSCoordSeq.tuplec                 C   s   t  dk r8d}t| }t|D ]$}|d | }|| | d | | d  7 }|| | d | | d  8 }q|dkS t }t| jt|sLtdtjj	 |j
dkS )z<Return whether this coordinate sequence is counterclockwise.)r&      g        rN   r   z*Error encountered in GEOS C function "%s".)r   r,   r   r   r4   Z	cs_is_ccwr   r   r	   	func_namer-   )r   Zareara   r   jretr   r   r   is_counterclockwise   s   


z GEOSCoordSeq.is_counterclockwiseN)F))__name__
__module____qualname____doc__r
   Zptr_typer   r   r   r    r%   r.   r!   r1   r5   r7   r8   r;   r=   r>   propertyr"   r@   r?   r+   r*   rD   rE   rH   rL   rO   rP   rQ   rR   r   r)   rU   rV   r_   r   rf   r   r   r   r   r      sX    






r   N)rj   ctypesr   r   r   r   Zdjango.contrib.gis.geosr   r4   Zdjango.contrib.gis.geos.baser   Zdjango.contrib.gis.geos.errorr	   Zdjango.contrib.gis.geos.libgeosr
   r   Zdjango.contrib.gis.shortcutsr   r   r   r   r   r   <module>   s    