
    ue                     b    d Z ddlZddlmZ ddlmZ d Zd Zd	 Zd
 Z	d Z
ddZd ZdefdZdS )zO
Functions that make it easier to provide a default centering
for a view state
    N   )	ViewState   )is_pandas_dfc                     || z
  || z
  z  S )N )xx0s     Blib/python3.11/site-packages/pydeck/data_utils/viewport_helpers.py_squared_diffr   
   s    FrAv    c           	          t          |           t          |          k    st          d          t          j        t	          d t          | |          D                                 S )a-  Euclidean distance in n-dimensions

    Parameters
    ----------
    y : tuple of float
        A point in n-dimensions
    y1 : tuple of float
        A point in n-dimensions

    Examples
    --------
    >>> EPSILON = 0.001
    >>> euclidean((3, 6, 5), (7, -5, 1)) - 12.369 < EPSILON
    True
    z,Input coordinates must be of the same lengthc                 4    g | ]\  }}t          ||          S r   )r   ).0r	   r
   s      r   
<listcomp>zeuclidean.<locals>.<listcomp>    s&    GGG51b-2..GGGr   )len	Exceptionmathsqrtsumzip)yy1s     r   	euclideanr      sY      q66SWWFGGG9SGGC2JJGGGHHIIIr   c                     t          d | D                       t          |           z  }t          d | D                       t          |           z  }||fS )zGets centroid in a series of points

    Parameters
    ----------
    points : list of list of float
        List of (x, y) coordinates

    Returns
    -------
    tuple
        The centroid of a list of points
    c                 8    g | ]}t          |d                    S r   floatr   ps     r   r   z"geometric_mean.<locals>.<listcomp>0   "    ---qt---r   c                 8    g | ]}t          |d                    S r   r   r    s     r   r   z"geometric_mean.<locals>.<listcomp>1   r"   r   )r   r   )pointsavg_xavg_ys      r   geometric_meanr(   #   s\     --f---..V<E--f---..V<E5>r   c                     d | D             }d | D             }t          |          }t          |          }t          |          }t          |          }||f||ffS )a  Get the bounding box around the data,

    Parameters
    ----------
    points : list of list of float
        List of (x, y) coordinates

    Returns
    -------
    dict
        Dictionary containing the top left and bottom right points of a bounding box
    c                     g | ]
}|d          S r   r   r    s     r   r   zget_bbox.<locals>.<listcomp>B       			1!A$			r   c                     g | ]
}|d          S r$   r   r    s     r   r   zget_bbox.<locals>.<listcomp>C   r+   r   )maxmin)r%   xsysmax_xmax_ymin_xmin_ys          r   get_bboxr5   5   si     
 				B					BGGEGGEGGEGGEENUEN++r   c                     fd| D             }t          |d           }d |D             dt          |                   S )a  Gets the k furthest points from the center

    Parameters
    ----------
    points : list of list of float
        List of (x, y) coordinates
    center : list of list of float
        Center point
    k : int
        Number of points

    Returns
    -------
    list
        Index of the k furthest points

    Todo
    ---
    Currently implemently naively, needs to be more efficient
    c                 4    g | ]}|t          |          fS r   )r   )r   ptcenters     r   r   z'k_nearest_neighbors.<locals>.<listcomp>`   s(    FFF"iF334FFFr   c                     | d         S )Nr   r   )r	   s    r   <lambda>z%k_nearest_neighbors.<locals>.<lambda>a   s
    1 r   )keyc                     g | ]
}|d          S r   r   )r   r	   s     r   r   z'k_nearest_neighbors.<locals>.<listcomp>b   s    %%%QAaD%%%r   N)sortedint)r%   r9   kpts_with_distance
sorted_ptss    `   r   k_nearest_neighborsrC   K   sX    * GFFFvFFF)~~>>>J%%*%%%hAh//r   c                     |dk    r| S t          |           }t          j        |t          |           z            }t	          | ||          S )as  Computes the bounding box of the maximum zoom for the specified list of points

    Parameters
    ----------
    points : list of list of float
        List of (x, y) coordinates
    proportion : float, default 1
        Value between 0 and 1 representing the minimum proportion of data to be captured

    Returns
    -------
    list
        k nearest data points
    r   )r(   r   floorr   rC   )r%   
proportioncentroid	n_to_keeps       r   	get_n_pctrI   e   sK     Qf%%H
:F344Ivx;;;r   c                    t          | d         d         | d         d                   t          | d         d         | d         d                   z
  }t          | d         d         | d         d                   t          | d         d         | d         d                   z
  }t          ||          }d}|dt          j        dd          z  k     rd}nkt	          dt          j        |          t          j        d	          z  t          j        d          t          j        d          z  z
  z            }|dk     rd}|S )
aJ  Computes the zoom level of a lat/lng bounding box

    Parameters
    ----------
    bbox : list of list of float
        Northwest and southeast corners of a bounding box, given as two points in a list

    Returns
    -------
    int
        Zoom level of map in a WGS84 Mercator projection (e.g., like that of Google Maps)
    r   r   Ng     v@r         g       @)r-   r.   r   powr?   log)bboxlat_difflng_diffmax_diff
zoom_levels        r   bbox_to_zoom_levelrU   }   s    471:tAwqz**SaT!WQZ-H-HHH471:tAwqz**SaT!WQZ-H-HHH8X&&HJ548Ar??*++

 2 2TXc]] BtxPUY]YabcYdYdGdefgg
>>Jr   c                     t          |           r|                     d          } t          t          | |                    }t	          |          }t          |           } ||d         |d         |          }|S )a\  Automatically computes a zoom level for the points passed in.

    Parameters
    ----------
    points : list of list of float or pandas.DataFrame
        A list of points
    view_propotion : float, default 1
        Proportion of the data that is meaningful to plot
    view_type : class constructor for pydeck.ViewState, default :class:`pydeck.bindings.view_state.ViewState`
        Class constructor for a viewport. In the current version of pydeck,
        users most likely do not have to modify this attribute.

    Returns
    -------
    pydeck.Viewport
        Viewport fitted to the data
    F)indexr   r   )latitude	longitudezoom)r   
to_recordsr5   rI   rU   r(   )r%   view_proportion	view_typerP   rZ   r9   instances          r   compute_viewr_      s~    $ F 0"""//Ifo6677Dd##DF##Fy&)vaytLLLHOr   r$   )__doc__r   bindings.view_stater   type_checkingr   r   r   r(   r5   rC   rI   rU   r_   r   r   r   <module>rc      s      + + + + + + ' ' ' ' ' '  J J J*  $, , ,,0 0 04< < < <0  6 *+i      r   