a
    r=ic/                     @   s   d dl Zd dlmZ d dlmZmZ dd ZG dd dZ	G dd	 d	eZ
G d
d dZG dd dejZG dd dZG dd dZG dd dZdS )    N)ticker)Bbox	Transformc              
   C   s@  g }| dd | dd  }t dt dddfD ]}| j| \}}|j| \}}|j| \}	}
|j| \}}|	||	kf|||k ffD ]\}}|g  |dd |dd A  \}|D ]|}|| |||  ||  ||   }|
|  kr|ksq q||f| }ttj|| ddd  }|d ||f qqq0|S )a  
    Find the points where a polyline crosses a bbox, and the crossing angles.

    Parameters
    ----------
    xys : (N, 2) array
        The polyline coordinates.
    bbox : `.Bbox`
        The bounding box.

    Returns
    -------
    list of ((float, float), float)
        Four separate lists of crossings, for the left, right, bottom, and top
        sides of the bbox, respectively.  For each list, the entries are the
        ``((x, y), ccw_angle_in_degrees)`` of the crossing, where an angle of 0
        means that the polyline is moving to the right at the crossing point.

        The entries are computed by linearly interpolating at each crossing
        between the nearest points on either side of the bbox edges.
       N)	sliceTminmaxappendZnonzeronpdegreesZarctan2)ZxysZbboxZ	crossingsZdxysslusvsZdusZdvsZuminZvminZumaxZvmaxZu0ZinsideidxsidxvZcrossingtheta r   t/home/droni/.local/share/virtualenvs/DPS-5Je3_V2c/lib/python3.9/site-packages/mpl_toolkits/axisartist/grid_finder.py_find_line_box_crossings   s$     
$r   c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	ExtremeFinderSimplezU
    A helper class to figure out the range of grid lines that need to be drawn.
    c                 C   s   || _ || _dS )zy
        Parameters
        ----------
        nx, ny : int
            The number of samples in each direction.
        Nnxny)selfr   r   r   r   r   __init__6   s    zExtremeFinderSimple.__init__c           
      C   sb   t t ||| jt ||| j\}}|t |t |\}}	| | | |	 |	 S )ai  
        Compute an approximation of the bounding box obtained by applying
        *transform_xy* to the box delimited by ``(x1, y1, x2, y2)``.

        The intended use is to have ``(x1, y1, x2, y2)`` in axes coordinates,
        and have *transform_xy* be the transform from axes coordinates to data
        coordinates; this method then returns the range of data coordinates
        that span the actual axes.

        The computation is done by sampling ``nx * ny`` equispaced points in
        the ``(x1, y1, x2, y2)`` box and finding the resulting points with
        extremal coordinates; then adding some padding to take into account the
        finite sampling.

        As each sampling step covers a relative range of *1/nx* or *1/ny*,
        the padding is computed by expanding the span covered by the extremal
        coordinates by these fractions.
        )	r   Zmeshgridlinspacer   r   Zravel_add_padr	   r
   )
r   transform_xyx1y1x2y2xyZxtZytr   r   r   __call__@   s
    zExtremeFinderSimple.__call__c                 C   s8   || | j  }|| | j }|| || || || fS )z,Perform the padding mentioned in `__call__`.r   )r   Zx_minZx_maxZy_minZy_maxZdxZdyr   r   r   r   X   s    zExtremeFinderSimple._add_padN)__name__
__module____qualname____doc__r   r'   r   r   r   r   r   r   1   s   
r   c                       s8   e Zd ZdZd ZZ fddZdd Zdd Z  Z	S )	_User2DTransformz.A transform defined by two user-set functions.   c                    s   t    || _|| _dS )z
        Parameters
        ----------
        forward, backward : callable
            The forward and backward transforms, taking ``x`` and ``y`` as
            separate arguments and returning ``(tr_x, tr_y)``.
        N)superr   _forward	_backward)r   forwardZbackward	__class__r   r   r   d   s    

z_User2DTransform.__init__c                 C   s   t | jt | S N)r   Z	transposer/   )r   valuesr   r   r   transform_non_affiner   s    z%_User2DTransform.transform_non_affinec                 C   s   t | | j| jS r4   )typer0   r/   r   r   r   r   invertedv   s    z_User2DTransform.inverted)
r(   r)   r*   r+   Z
input_dimsZoutput_dimsr   r6   r9   __classcell__r   r   r2   r   r,   _   s
   r,   c                   @   sZ   e Zd ZdddZdd Zdd Zdd	 Zd
d Zdd ZeZ	dd Z
dd Zdd ZdS )
GridFinderNc                 C   sv   |du rt dd}|du r t }|du r.t }|du r<t }|du rJt }|| _|| _|| _|| _|| _| | dS )a  
        transform : transform from the image coordinate (which will be
        the transData of the axes to the world coordinate.

        or transform = (transform_xy, inv_transform_xy)

        locator1, locator2 : grid locator for 1st and 2nd axis.
        N   )	r   MaxNLocatorFormatterPrettyPrintextreme_findergrid_locator1grid_locator2tick_formatter1tick_formatter2set_transform)r   	transformr?   r@   rA   rB   rC   r   r   r   r   |   s     
zGridFinder.__init__c              
   C   sp  |  | j||||}|\}}}}	| ||\}
}}t|
}
| ||	\}}}t|}|
d| | }|d| | }| ||||||	\}}|| d }|| d }t|| || || || }|||| 	|||
|| 	||||d}i  }|d d< dD ](}|d d | }| 
|||||< qi  }|d d< dD ](}|d d | }| |||||< qB|S )	z
        lon_values, lat_values : list of grid values. if integer is given,
                           rough number of grids in each direction.
        Ng|=)extremes	lon_lines	lat_lineslonlatrI   Ztick_labelsleftbottomrighttoptick_levelsrJ   )r?   inv_transform_xyr@   r   ZasarrayrA   _get_raw_grid_linesr   Zfrom_extents_clip_grid_lines_and_find_ticksrB   rC   )r   r!   r"   r#   r$   rF   lon_minlon_maxlat_minlat_maxZlon_levsZlon_nZ
lon_factorZlat_levsZlat_nZ
lat_factor
lon_values
lat_valuesrG   rH   ZddxZddybbZ	grid_infoZ
tck_labels	directionlevsr   r   r   get_grid_info   sN    

 
zGridFinder.get_grid_infoc           	         sL   t ||dt ||d  fdd|D }fdd|D }||fS )Nd   c                    s    g | ]} t | qS r   r    r   Z	full_like).0rI   )lats_ir   r   r   
<listcomp>   s   z2GridFinder._get_raw_grid_lines.<locals>.<listcomp>c              	      s    g | ]}  t |qS r   r_   )r`   rJ   )lons_ir   r   r   rb      s   )r   r   )	r   rX   rY   rT   rU   rV   rW   rG   rH   r   )ra   rc   r   r   rR      s    zGridFinder._get_raw_grid_linesc              	   C   s   g g t g g g g dt g g g g dg d}|d }|d }t|||D ]\\}}	}
}tt||	g|}|d |
 |d ||	fg t|g dD ].\}}|D ] }|| | || | qqqD|S )NrK   )r5   levelsrP   	tick_locslinesrP   re   rd   rf   )rL   rN   rM   rO   )dictzipr   r   column_stackr   )r   rf   r5   r\   rZ   giZ
tck_levelsZtck_locslxZlyr   ZlevZtcksZtckr[   tr   r   r   rS      s&    z*GridFinder._clip_grid_lines_and_find_ticksc                 C   sD   t |tr|| _n.t|dkr8ttt|r8t| | _ntdd S )Nr-   zF'aux_trans' must be either a Transform instance or a pair of callables)	
isinstancer   _aux_transformlenallmapcallabler,   	TypeError)r   Z	aux_transr   r   r   rD      s
    
zGridFinder.set_transformc                 C   s   | j S r4   )rn   r8   r   r   r   get_transform   s    zGridFinder.get_transformc                 C   s   | j t||gjS r4   )rn   rE   r   ri   r   r   r%   r&   r   r   r   r      s    zGridFinder.transform_xyc                 C   s   | j  t||gjS r4   )rn   r9   rE   r   ri   r   ru   r   r   r   rQ     s    
zGridFinder.inv_transform_xyc                 K   s:   |  D ],\}}|dv r&t| || qtd|qd S )N)r?   r@   rA   rB   rC   zUnknown update property )itemssetattr
ValueError)r   kwargskr   r   r   r   update  s    zGridFinder.update)NNNNN)r(   r)   r*   r   r]   rR   rS   rD   rt   Zupdate_transformr    rQ   r{   r   r   r   r   r;   {   s        
 5	r;   c                       s*   e Zd Zd	 fdd	Z fddZ  ZS )
r=   
   NTFc                    s"   t  j|||||d |   d S )N)stepsinteger	symmetricprune)r.   r   create_dummy_axis)r   Znbinsr}   Ztrimr~   r   r   r2   r   r   r     s    zMaxNLocator.__init__c                    s"   t  ||}t|t|dfS )Nr   )r.   Ztick_valuesr   arrayro   r   v1v2locsr2   r   r   r'   #  s    zMaxNLocator.__call__)r|   NTFFNr(   r)   r*   r   r'   r:   r   r   r2   r   r=     s        
r=   c                   @   s   e Zd Zdd Zdd ZdS )FixedLocatorc                 C   s
   || _ d S r4   )_locs)r   r   r   r   r   r   )  s    zFixedLocator.__init__c                    s:   t  g\ t fdd| jD }|t|dfS )Nc                    s(   g | ] } |  krkrn q|qS r   r   )r`   lr   r   r   r   rb   .      z)FixedLocator.__call__.<locals>.<listcomp>r   )sortedr   r   r   ro   r   r   r   r   r'   ,  s    zFixedLocator.__call__Nr(   r)   r*   r   r'   r   r   r   r   r   (  s   r   c                   @   s   e Zd ZdddZdd ZdS )r>   Tc                 C   s   t j|dd| _| j  d S )NF)useMathTextZ	useOffset)mtickerZScalarFormatter_fmtr   )r   r   r   r   r   r   5  s    zFormatterPrettyPrint.__init__c                 C   s   | j |S r4   )r   Zformat_ticks)r   r[   factorr5   r   r   r   r'   :  s    zFormatterPrettyPrint.__call__N)Tr   r   r   r   r   r>   4  s   
r>   c                       s&   e Zd Zd fdd	Zdd Z  ZS )DictFormatterNc                    s   t    || _|| _dS )zq
        format_dict : dictionary for format strings to be used.
        formatter : fall-back formatter
        N)r.   r   _format_dict_fallback_formatter)r   Zformat_dict	formatterr2   r   r   r   ?  s    
zDictFormatter.__init__c                    s<    j r  |||}ndgt| } fddt||D S )zG
        factor is ignored if value is found in the dictionary
         c                    s   g | ]\}} j ||qS r   )r   get)r`   rz   r   r8   r   r   rb   Q  s   z*DictFormatter.__call__.<locals>.<listcomp>)r   ro   rh   )r   r[   r   r5   Zfallback_stringsr   r8   r   r'   H  s    
zDictFormatter.__call__)Nr   r   r   r2   r   r   >  s   	r   )numpyr   Z
matplotlibr   r   Zmatplotlib.transformsr   r   r   r   r,   r;   r=   r   r>   r   r   r   r   r   <module>   s   *. 
