B
    ¥0H[P  ã               @   s<   d dl mZ d dlmZ d dlmZmZ G dd„ deƒZdS )é    )ÚCLOB)Ú
WKTAdapter)ÚGeometryCollectionÚPolygonc               @   s0   e Zd ZeZdd„ Zdd„ Zdd„ Zdd„ Zd	S )
ÚOracleSpatialAdapterc             C   s>   t |tƒr|  |¡ nt |tƒr*|  |¡ |j| _|j| _dS )a  
        Oracle requires that polygon rings are in proper orientation. This
        affects spatial operations and an invalid orientation may cause
        failures. Correct orientations are:
         * Outer ring - counter clockwise
         * Inner ring(s) - clockwise
        N)Ú
isinstancer   Ú_fix_polygonr   Ú_fix_geometry_collectionZwktZsrid)ÚselfÚgeom© r   úqC:\Users\HIRONO~1\AppData\Local\Temp\pip-install-6bm3nxem\django\django\contrib\gis\db\backends\oracle\adapter.pyÚ__init__
   s    


zOracleSpatialAdapter.__init__c             C   sZ   |   |j¡rtt|jƒƒ|_x8tdt|ƒƒD ]&}|   || ¡s,tt|| ƒƒ||< q,W |S )z:Fix single polygon orientation as described in __init__().é   )Ú_isClockwiseZexterior_ringÚlistÚreversedÚrangeÚlen)r
   ZpolyÚir   r   r   r      s    z!OracleSpatialAdapter._fix_polygonc             C   s2   x,t |ƒD ] \}}t|tƒr
|  |¡||< q
W dS )zf
        Fix polygon orientations in geometry collections as described in
        __init__().
        N)Ú	enumerater   r   r   )r
   Zcollr   r   r   r   r   r	   %   s    
z-OracleSpatialAdapter._fix_geometry_collectionc             C   sj   t |ƒ}d}xTt|ƒD ]H}|d | }||| d || d  7 }||| d || d  8 }qW |dk S )z�
        A modified shoelace algorithm to determine polygon orientation.
        See https://en.wikipedia.org/wiki/Shoelace_formula.
        g        r   r   )r   r   )r
   ZcoordsÚnÚarear   Újr   r   r   r   .   s     z!OracleSpatialAdapter._isClockwiseN)	Ú__name__Ú
__module__Ú__qualname__r   Z
input_sizer   r   r	   r   r   r   r   r   r      s
   	r   N)Z	cx_Oracler   Z+django.contrib.gis.db.backends.base.adapterr   Zdjango.contrib.gis.geosr   r   r   r   r   r   r   Ú<module>   s   