
    g                     `    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y)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     W/var/www/openai/venv/lib/python3.12/site-packages/pydeck/data_utils/viewport_helpers.py_squared_diffr   
   s    FrAv    c                     t        |       t        |      k(  st        d      t        j                  t	        t        | |      D cg c]  \  }}t        ||       c}}            S c c}}w )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 length)len	Exceptionmathsqrtsumzipr   )yy1r	   r
   s       r   	euclideanr      sW      q6SWFGG99SC2JGJ51b-2.JGHIIGs   A(c           	          t        | D cg c]  }t        |d          c}      t        |       z  }t        | D cg c]  }t        |d          c}      t        |       z  }||fS c c}w c c}w )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
    r   r   )r   floatr   )pointspavg_xavg_ys       r   geometric_meanr   #   sj     f-fqtf-.V<Ef-fqtf-.V<E5> .-s
   A'A,c                     | D cg c]  }|d   	 }}| D cg c]  }|d   	 }}t        |      }t        |      }t        |      }t        |      }||f||ffS c c}w c c}w )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
    r   r   )maxmin)r   r   xsysmax_xmax_ymin_xmin_ys           r   get_bboxr(   5   ss     	1!A$B		1!A$B	GEGEGEGEENUEN++ 
 	s
   AAc                     | D cg c]  }|t        ||      f }}t        |d       }|D cg c]  }|d   	 c}dt        |       S c c}w c c}w )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                     | d   S )Nr   r   )r	   s    r   <lambda>z%k_nearest_neighbors.<locals>.<lambda>a   s    1r   )keyr   N)r   sortedint)r   centerkptpts_with_distance
sorted_ptsr	   s          r   k_nearest_neighborsr4   K   sa    * @FFv"iF34vF)~>J$%*QAaD*%hA// G%s
   A	A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   r4   )r   
proportioncentroid	n_to_keeps       r   	get_n_pctr:   e   s@     Qf%H

:F3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}|S t	        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_levelrF   }   s    471:tAwqz*SaT!WQZ-HHH471:tAwqz*SaT!WQZ-HHH8X&HJ5488Ar?*+

   2TXXc] BtxxPUY]YaYabcYdGdefg
>Jr   c                     t        |       r| j                  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_recordsr(   r:   rF   r   )r   view_proportion	view_typerA   rK   r/   instances          r   compute_viewrP      s_    $ F"""/Ifo67Dd#DF#F&)vaytLHOr   )r   )__doc__r   bindings.view_stater   type_checkingr   r   r   r   r(   r4   r:   rF   rP   r   r   r   <module>rT      sE     + 'J*$,,04<06 *+i r   