o
    h/                     @   s   d dl Zd dlmZ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_api)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 ]Y\}}g }|dd |dd A  \}|D ]<}|| |||  ||  ||   }|
|  krw|ksyn qY||f| }ttj|| ddd  }|||f qY|| qBq|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nonzeronpdegreesarctan2append)xysbbox	crossingsdxysslusvsdusdvsuminvminumaxvmaxu0insidecrossidxsidxvcrossingtheta r&   w/var/www/html/construction_image-detection-poc/venv/lib/python3.10/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__7   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   meshgridlinspacer+   r,   ravel_add_padr
   r   )
r-   transform_xyx1y1x2y2xyxtytr&   r&   r'   __call__A   s
    zExtremeFinderSimple.__call__c                 C   s8   || | j  }|| | j }|| || || || fS )z,Perform the padding mentioned in `__call__`.r*   )r-   x_minx_maxy_miny_maxdxdyr&   r&   r'   r2   Y   s   zExtremeFinderSimple._add_padN)__name__
__module____qualname____doc__r.   r<   r2   r&   r&   r&   r'   r)   2   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                       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-   forwardbackward	__class__r&   r'   r.   e   s   


z_User2DTransform.__init__c                 C   s   t | jt | S N)r   	transposerK   )r-   valuesr&   r&   r'   transform_non_affines   s   z%_User2DTransform.transform_non_affinec                 C   s   t | | j| jS rQ   )typerL   rK   r-   r&   r&   r'   invertedw   s   z_User2DTransform.inverted)
rC   rD   rE   rF   
input_dimsoutput_dimsr.   rT   rW   __classcell__r&   r&   rO   r'   rG   `   s    rG   c                   @   sh   e Zd 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 )
GridFinderz
    Internal helper for `~.grid_helper_curvelinear.GridHelperCurveLinear`, with
    the same constructor parameters; should not be directly instantiated.
    Nc                 C   sv   |d u r	t dd}|d u rt }|d u rt }|d u rt }|d u r%t }|| _|| _|| _|| _|| _| | d S )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   s:   t j| j| jd|d}t|tjr||S ||||S )a  
        Helper to support both standard formatters (inheriting from
        `.mticker.Formatter`) and axisartist-specific ones; should be called instead of
        directly calling ``self.tick_formatter1`` and ``self.tick_formatter2``.  This
        method should be considered as a temporary workaround which will be removed in
        the future at the same time as axisartist-specific formatters.
        )r   rH   )r"   )r   check_getitemrb   rc   
isinstancemticker	Formatterformat_ticks)r-   r"   	directionfactorlevelsfmtr&   r&   r'   _format_ticks   s   
zGridFinder._format_ticksc           (   	   C   s  |  | j||||}|\}}}}	| ||\}
}}t|
}
| ||	\}}}t|}|
d| | }|d| | }| ||||||	\}}t||||	dd}d|i}dd|
|||fdd||||ffD ]|\}}}}}}dd	 |D g g g g d
d ||< }t
|||D ].\\}}}} tt||g|}!t
g d
|!D ]\}"}#|#D ]}$|d |" | |$d qqq|d D ]'}"dd	 |d |" D }| ||"||}%t
|d |" |%D ]\}&}'|'|&d< qqqh|S )z
        lon_values, lat_values : list of grid values. if integer is given,
                           rough number of grids in each direction.
        Ngp   ?extremesr   lonrH   latc                 S   s   g | ]}|gqS r&   r&   .0lr&   r&   r'   
<listcomp>   s    z,GridFinder.get_grid_info.<locals>.<listcomp>)leftrightbottomtop)linesticksr|   )levellocc                 S   s   g | ]}|d  qS )r}   r&   )rt   tickr&   r&   r'   rv      s    label)r_   inv_transform_xyr`   r   asarrayra   _get_raw_grid_linesr   from_extentsexpandedzipr(   column_stackr   ro   )(r-   r4   r5   r6   r7   rp   lon_minlon_maxlat_minlat_maxlon_levslon_n
lon_factorlat_levslat_n
lat_factor
lon_values
lat_values	lon_lines	lat_linesbb	grid_infor"   
lon_or_latlevsrl   rS   r{   gilxlyr#   r}   all_crossingssider   r$   labelsr   r   r&   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&   r3   r   	full_like)rt   rq   )lats_ir-   r&   r'   rv          z2GridFinder._get_raw_grid_lines.<locals>.<listcomp>c              	      s    g | ]}  t |qS r&   r   )rt   rr   )lons_ir-   r&   r'   rv      r   )r   r0   )	r-   r   r   r   r   r   r   r   r   r&   )r   r   r-   r'   r      s   zGridFinder._get_raw_grid_linesc                 C   sD   t |tr
|| _d S t|dkrttt|rt| | _d S td)NrH   zF'aux_trans' must be either a Transform instance or a pair of callables)	rg   r   _aux_transformlenallmapcallablerG   	TypeError)r-   	aux_transr&   r&   r'   rd      s
   

zGridFinder.set_transformc                 C   s   | j S rQ   )r   rV   r&   r&   r'   get_transform   s   zGridFinder.get_transformc                 C   s   | j t||gjS rQ   )r   re   r   r   r	   r-   r8   r9   r&   r&   r'   r3      s   zGridFinder.transform_xyc                 C   s   | j  t||gjS rQ   )r   rW   re   r   r   r	   r   r&   r&   r'   r      s
   
zGridFinder.inv_transform_xyc                 K   s8   |  D ]\}}|dv rt| || qtd|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)rC   rD   rE   rF   r.   ro   r   r   rd   r   update_transformr3   r   r   r&   r&   r&   r'   r[   |   s"    
6	r[   c                       s4   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)rJ   r.   create_dummy_axis)r-   nbinsr   trimr   r   r   rO   r&   r'   r.     s   zMaxNLocator.__init__c                    s"   t  ||}t|t|dfS )Nr   )rJ   tick_valuesr   arrayr   r-   v1v2locsrO   r&   r'   r<     s   zMaxNLocator.__call__)r   NTFFNrC   rD   rE   r.   r<   rZ   r&   r&   rO   r'   r]     s    
r]   c                   @   s   e Zd Zdd Zdd ZdS )FixedLocatorc                 C   s
   || _ d S rQ   )_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 n|qS r&   r&   rs   r   r   r&   r'   rv   "  s   ( z)FixedLocator.__call__.<locals>.<listcomp>r   )sortedr   r   r   r   r   r&   r   r'   r<      s   zFixedLocator.__call__NrC   rD   rE   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)useMathText	useOffset)rh   ScalarFormatter_fmtr   )r-   r   r&   r&   r'   r.   )  s   zFormatterPrettyPrint.__init__c                 C   s   | j |S rQ   )r   rj   )r-   rk   rl   rS   r&   r&   r'   r<   .  s   zFormatterPrettyPrint.__call__N)Tr   r&   r&   r&   r'   r^   (  s    
r^   c                       s&   e Zd Zd fdd	Zdd Z  ZS )DictFormatterNc                    rI   )zq
        format_dict : dictionary for format strings to be used.
        formatter : fall-back formatter
        N)rJ   r.   _format_dict_fallback_formatter)r-   format_dict	formatterrO   r&   r'   r.   3  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)rt   r   r#   rV   r&   r'   rv   E  s    z*DictFormatter.__call__.<locals>.<listcomp>)r   r   r   )r-   rk   rl   rS   fallback_stringsr&   rV   r'   r<   <  s   
zDictFormatter.__call__rQ   r   r&   r&   rO   r'   r   2  s    	r   )numpyr   
matplotlibr   rh   r   matplotlib.transformsr   r   r(   r)   rG   r[   r]   r   r^   r   r&   r&   r&   r'   <module>   s    +. 
