
    h                     0    d dl ZddZd Zd ZdZd Zd Zy)	    N   c                     | j                   j                         | j                         j                         z  rt        d      | j                  }t        |||      \  }}t        |||      }|S )a'  
    Calculate the distance along a Hilbert curve.

    The distances are calculated for the midpoints of the geometries in the
    GeoDataFrame.

    Parameters
    ----------
    geoms : GeometryArray
    total_bounds : 4-element array
        Total bounds of geometries - array
    level : int (1 - 16), default 16
        Determines the precision of the curve (points on the curve will
        have coordinates in the range [0, 2^level - 1]).

    Returns
    -------
    np.ndarray
        Array containing distances along the Hilbert curve

    zTHilbert distance cannot be computed on a GeoSeries with empty or missing geometries.)is_emptyanyisna
ValueErrorbounds_continuous_to_discrete_coords_encode)geomstotal_boundslevelr	   xy	distancess          P/var/www/html/immo/lib/python3.12/site-packages/geopandas/tools/hilbert_curve.py_hilbert_distancer      sm    , ~~ejjl..00"
 	

 \\F *&%FDAqq!$I    c                 d   d|z  dz
  }| dddf   | dddf   z   dz  }| dddf   | dddf   z   dz  }|Rt        j                  |      t        j                  |      t        j                  |      t        j                  |      f}|\  }}}}	t        |||f|      }
t        |||	f|      }|
|fS )a  Calculate mid points & ranges of geoms and returns as discrete coords.

    Parameters
    ----------
    bounds : Bounds of each geometry - array

    p : The number of iterations used in constructing the Hilbert curve

    total_bounds : Total bounds of geometries - array

    Returns
    -------
    Discrete two-dimensional numpy array
    Two-dimensional array Array of hilbert distances for each geom

          Nr   g       @   )npnanminnanmax_continuous_to_discrete)r	   r   r   side_lengthx_midsy_midsxminyminxmaxymaxx_inty_ints               r   r
   r
   *   s    $ e8q.K QTlVAqD\)S0FQTlVAqD\)S0F IIfIIfIIfIIf	
 *D$d $FT4L+FE#FT4L+FE%<r   c                     |d   |d   z
  }|dk(  r%t        j                  | t         j                        S | |d   z
  ||z  z  }t        j                  |d||       |j	                  t         j                        S )aL  Convert a continuous one-dimensional array to discrete integer values
    based their ranges.

    Parameters
    ----------
    vals : Array of continuous values

    val_range : Tuple containing range of continuous values

    n : Number of discrete values

    Returns
    -------
    One-dimensional array of discrete ints

    r   r   dtype)out)r   
zeros_likeuint32clipastype)vals	val_rangenwidthress        r   r   r   T   sn    " aL9Q<'Ez}}T33)A,1u9
-CGGCA3::bii  r   c                 ^    | | dz  z  dz  } | | dz  z  dz  } | | dz  z  dz  } | | dz  z  dz  } | S )	N   i     ir   i3333r   iUUUU )r   s    r   _interleaver7   v   sO    	
a1f#A	
a1f#A	
a1f#A	
a1f#AHr   c                    t        j                  |d      }t        j                  |d      }| t        kD  rt        d      |d| z
  z  }|d| z
  z  }||z  }d|z  }d||z  z  }||dz  z  }||dz	  z  }|dz	  |z  }|dz	  ||dz	  z  z  |z  }	||dz	  z  |dz	  z  |z  }
|j	                         }|j	                         }|	j	                         }|
j	                         }||dz	  z  ||dz	  z  z  }||dz	  z  |||z  dz	  z  z  }|	||dz	  z  ||dz	  z  z  z  }	|
||dz	  z  ||z  |dz	  z  z  z  }
|j	                         }|j	                         }|	j	                         }|
j	                         }||dz	  z  ||dz	  z  z  }||dz	  z  |||z  dz	  z  z  }|	||dz	  z  ||dz	  z  z  z  }	|
||dz	  z  ||z  |dz	  z  z  z  }
|j	                         }|j	                         }|	j	                         }|
j	                         }|	||d	z	  z  ||d	z	  z  z  z  }	|
||d	z	  z  ||z  |d	z	  z  z  z  }
|	|	dz	  z  }|
|
dz	  z  }||z  }|d||z  z  z  }t        |      dz  t        |      z  d
d| z  z
  z	  S )Nr+   r'   zLevel out of ranger   i  r   r   r5   r4       )r   asarray	MAX_LEVELr   copyr7   )r   r   r   abcdABCDi0i1s                r   r   r   ~   s   


1H%A


1H%Ay-..	b5jA	b5jA 	
AA
A!a%A	QZA	Q!VA	
a1A
q&Q!q&\	"a'A
qAv,16	"a'A	A	A	A	A	
a1f!qAv,'A	
a1f!A!|,-A!qAv,1Q<	((A!qAv,AEa1f-	..A	A	A	A	A	
a1f!qAv,'A	
a1f!A!|,-A!qAv,1Q<	((A!qAv,AEa1f-	..A 	
A	A	A	A!qAv,1Q<	((A!qAv,AEa1f-	..A 	
Q!VA	Q!VA 
QB	
fQ	 B_![_4"q5y.IIr   )Nr   )numpyr   r   r
   r   r;   r7   r   r6   r   r   <module>rH      s+    #L'T!> 	:Jr   