
    ^j1                         d dl Zd dlmZmZ d dlmZmZ d Z	 G d d      Z
 G d de      Z G d	 d
      Z G d dej                        Z G d d      Z G d d      Z G d d      Zy)    N)ticker_api)Bbox	Transformc                 r   g }| dd | dd z
  }t        d      t        ddd      fD ]  }| j                  |   \  }}|j                  |   \  }}|j                  |   \  }	}
|j                  |   \  }}|	||	kD  f|||k  ffD ]  \  }}g }|dd |dd z  j	                         \  }||   |||   z
  ||   z  ||   z  z   }|j                  t        |||         D cg c]E  \  }}|
|cxk  r|k  r5n n2||f|   t        j                  t        j                  |ddd          fG c}}        
 |S c c}}w )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appendzipnpdegreesarctan2)xysbbox	crossingsdxysslusvsdusdvsuminvminumaxvmaxu0insidecrossidxsvvvdxys                       n/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/mpl_toolkits/axisartist/grid_finder.py_find_line_box_crossingsr)      sw   , Iqr7S"XDT{E$b12 IrB66":SXXb\
dXXb\
d "t),tR$Y.?@ 	IJBECR[6!":-668EDDR"T(]c$i7#d)CCB!"d4j1HAsTQ5F$5F abjjS2Y)?@AH I		II Hs   A
D3c                   "    e Zd ZdZd Zd Zd Zy)ExtremeFinderSimplezU
    A helper class to figure out the range of grid lines that need to be drawn.
    c                      || _         || _        y)zy
        Parameters
        ----------
        nx, ny : int
            The number of samples in each direction.
        N)nxny)selfr-   r.   s      r(   __init__zExtremeFinderSimple.__init__3   s         c           	          | j                  t        |d      t        j                  ||||            }|j                  |j
                  |j                  |j                  fS )am  
        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.
        N)_find_transformed_bbox_User2DTransformr   from_extentsx0x1y0y1)r/   transform_xyr7   r9   x2y2tbboxs          r(   __call__zExtremeFinderSimple.__call__=   sR    & ++\40$2C2CBBPR2SUxx588UXX55r1   c           
         t        j                  t        j                  t        j                  |j                  |j
                  | j                        t        j                  |j                  |j                  | j                              d      j                  }t        j                         }|j                  |j                  |             |j                  dd| j                  z  z   dd| j                  z  z         S )a  
        Compute an approximation of the bounding box obtained by applying
        *trans* to *bbox*.

        See ``__call__`` for details; this method performs similar
        calculations, but using a different representation of the arguments and
        return value.
        )   r	   r   r@   )r   reshapemeshgridlinspacer6   r7   r-   r8   r9   r.   r   r   nullupdate_from_data_xy	transformexpanded)r/   transr   gridr=   s        r(   r3   z*ExtremeFinderSimple._find_transformed_bboxT   s     zz"++bkk$''477DGG&L&(kk$''477DGG&LN!##$1 	 		!!%//$"78~~a!dgg+oq1tww;??r1   N)__name__
__module____qualname____doc__r0   r>   r3    r1   r(   r+   r+   .   s    6.@r1   r+   c                   6     e Zd ZdZdxZZ fdZd Zd Z xZ	S )r4   z.A transform defined by two user-set functions.r@   c                 >    t         |           || _        || _        y)z
        Parameters
        ----------
        forward, backward : callable
            The forward and backward transforms, taking ``x`` and ``y`` as
            separate arguments and returning ``(tr_x, tr_y)``.
        N)superr0   _forward	_backward)r/   forwardbackward	__class__s      r(   r0   z_User2DTransform.__init__j   s     	!r1   c                 l    t        j                   | j                  t        j                  |             S N)r   	transposerR   )r/   valuess     r(   transform_non_affinez%_User2DTransform.transform_non_affinex   s%    ||MDMM2<<+?@AAr1   c                 N     t        |       | j                  | j                        S rX   )typerS   rR   r/   s    r(   invertedz_User2DTransform.inverted|   s    tDz$..$--88r1   )
rJ   rK   rL   rM   
input_dimsoutput_dimsr0   r[   r_   __classcell__rV   s   @r(   r4   r4   e   s     8  J"B9r1   r4   c                       e Zd ZdZ	 	 	 	 	 ddZd Zd Zd Zd Zd Z	eZ
 ej                  d	d
      d        Z ej                  d	d      d        Zd Zy)
GridFinderz
    Internal helper for `~.grid_helper_curvelinear.GridHelperCurveLinear`, with
    the same constructor parameters; should not be directly instantiated.
    Nc                     |t        dd      }|
t               }|
t               }|
t               }|
t               }|| _        || _        || _        || _        || _        | j                  |       y )N   )	r+   MaxNLocatorFormatterPrettyPrintextreme_findergrid_locator1grid_locator2tick_formatter1tick_formatter2set_transform)r/   rF   rj   rk   rl   rm   rn   s          r(   r0   zGridFinder.__init__   s     !0R8N 'MM 'MM"24O"24O,**..9%r1   c                     t        j                  | j                  | j                  d|      }t	        |t
        j                        r|j                  |      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   r@   )idx)r   getitem_checkedrm   rn   
isinstancemticker	Formatterformat_ticks)r/   rq   	directionfactorlevelsfmts         r(   _format_tickszGridFinder._format_ticks   s^     ""$$)=)=>CI,6sG<M<M,N  ( 	5FF3	5r1   c           	      .   t        j                  d d gg|i |}d|v r<t        j                  dd       t        j                  |d   |d   |d   |d	         }n|d
   }| j
                  j                  | j                         j                         |      } | j                  |j                   \  }}} | j                  |j                   \  }	}
}t        j                  |d|       |z  }t        j                  |	d|
       |z  }| j                  |||      \  }}|j!                  dd      }d|i}dd||||fdd|	|||ffD ]  \  }}}}}}|g g g g ddx||<   }t#        |||      D ]I  \  }}}t%        ||      }t#        g d|      D ]&  \  }}|D ]  }|d   |   j'                  ||d        ( K |d   D ]M  }|d   |   D  cg c]  } | d   	 }} | j)                  ||||      }!t#        |d   |   |!      D ]
  \  } }"|"| d<    O  |S c c} w )zp
        Compute positioning information for grid lines and ticks, given the
        axes' data *bbox*.
        c                     t               S rX   locals)r7   r9   r;   r<   s       r(   <lambda>z*GridFinder.get_grid_info.<locals>.<lambda>   s    FH r1   c                     t               S rX   r~   )r   s    r(   r   z*GridFinder.get_grid_info.<locals>.<lambda>   s    68 r1   r7   3.11zPassing extents as separate arguments to get_grid_info is deprecated since %(since)s and support will be removed %(removal)s; pass a single bbox instead.)messager9   r;   r<   r   Ngp   ?extremesr   lonr@   lat)leftrightbottomtop)linesticksr   )levellocr   label)r   select_matching_signaturewarn_deprecatedr   r5   rj   r3   get_transformr_   rk   	intervalxrl   	intervalyr   asarray_get_raw_grid_linesrG   r   r)   r   r{   )#r/   argskwargsparamsr   r=   lon_levslon_n
lon_factorlat_levslat_n
lat_factor
lon_values
lat_values	lon_lines	lat_linesbbox_expanded	grid_inforq   
lon_or_latlevsrx   rZ   r   gir   r&   r   all_crossingssider   crossingticklabelsr   s#                                      r(   get_grid_infozGridFinder.get_grid_info   s   
 //,.CDWGKWOUW6>  ') $$tfTlF4L&,HD &>D##:: ))+T3 '9d&8&8%//&J#%&8d&8&8%//&J#%ZZ% 01J>
ZZ% 01J>
#77
JPUV	9i;'	 E8ZYGE8ZYG=
 	*8CT665
 "$rRK* Ij!B "%UFD!9 TQ 8m L'*:M(K TOD)$- T7D)0051RSTTT 7 *24W+d2CD$WDD++CvtD#&r'{4'8&#A *KD%$)DM**	*(  Es   Hc                    | j                         }t        j                  |j                  |j                  d      }t        j                  |j
                  |j                  d      }|D cg c]<  }|j                  t        j                  t        j                  ||      |g            > }}|D 	cg c]<  }	|j                  t        j                  |t        j                  ||	      g            > }
}	||
fS c c}w c c}	w )Nd   )
r   r   rC   r6   r7   r8   r9   rF   column_stack	full_like)r/   r   r   r   rH   lonslatsr   r   r   r   s              r(   r   zGridFinder._get_raw_grid_lines   s    ""${{477DGGS1{{477DGGS1 *, __R__bll46Mt5T%UV ,	 , !+, __R__dBLLs<S5T%UV ,	 ,)##	,,s   +AC92AC>c                     t        |t              r|| _        y t        |      dk(  r't	        t        t        |            rt        | | _        y t        d      )Nr@   zF'aux_trans' must be either a Transform instance or a pair of callables)	rs   r   _aux_transformlenallmapcallabler4   	TypeError)r/   	aux_transs     r(   ro   zGridFinder.set_transform   sM    i+"+D^q SXy)A%B"2I">D > ? ?r1   c                     | j                   S rX   )r   r^   s    r(   r   zGridFinder.get_transform   s    """r1   r   zgrid_finder.get_transform())alternativec                 v    | j                   j                  t        j                  ||g            j                  S rX   )r   rF   r   r   r   r/   xys      r(   r:   zGridFinder.transform_xy   s,    "",,R__aV-DEGGGr1   z&grid_finder.get_transform().inverted()c                     | j                   j                         j                  t        j                  ||g            j
                  S rX   )r   r_   rF   r   r   r   r   s      r(   inv_transform_xyzGridFinder.inv_transform_xy   s9    ""++-77OOQF#%%&Q	'r1   c                 r    |j                         D ]$  \  }}|dv rt        | ||       t        d|       y )N)rj   rk   rl   rm   rn   zUnknown update property )itemssetattr
ValueError)r/   r   kr&   s       r(   updatezGridFinder.update  sK    LLN 	CDAq ( (
 a# #;A5!ABB	Cr1   )NNNNN)rJ   rK   rL   rM   r0   r{   r   r   ro   r   update_transformr   
deprecatedr:   r   r   rN   r1   r(   re   re      s     !%##!%!%&053j$?# %T__V)FGH HH T__V)QR' S'	Cr1   re   c                   4     e Zd Z	 	 	 	 	 d fd	Z fdZ xZS )rh   c                 N    t         |   |||||       | j                          y )N)stepsinteger	symmetricprune)rQ   r0   create_dummy_axis)r/   nbinsr   trimr   r   r   rV   s          r(   r0   zMaxNLocator.__init__  s.     	eW#,E 	 	; r1   c                 f    t         |   ||      }t        j                  |      t	        |      dfS Nr   )rQ   tick_valuesr   arrayr   )r/   v1v2locsrV   s       r(   r>   zMaxNLocator.__call__  s-    w"2r*xx~s4y!++r1   )
   NTFFNrJ   rK   rL   r0   r>   rb   rc   s   @r(   rh   rh     s!    '+ 	!, ,r1   rh   c                       e Zd Zd Zd Zy)FixedLocatorc                     || _         y rX   )_locs)r/   r   s     r(   r0   zFixedLocator.__init__  s	    
r1   c                     t        ||g      \  }}t        j                  | j                  D cg c]  }||cxk  r|k  sn n| c}      }|t	        |      dfS c c}w r   )sortedr   r   r   r   )r/   r   r   lr   s        r(   r>   zFixedLocator.__call__"  sR    R!BxxDJJ@q"-R-@ASY!! As
   AANrJ   rK   rL   r0   r>   rN   r1   r(   r   r     s    "r1   r   c                       e Zd ZddZd Zy)ri   c                 p    t        j                  |d      | _        | j                  j                          y )NF)useMathText	useOffset)rt   ScalarFormatter_fmtr   )r/   r   s     r(   r0   zFormatterPrettyPrint.__init__+  s)    ++#u6			##%r1   c                 8    | j                   j                  |      S rX   )r   rv   )r/   rw   rx   rZ   s       r(   r>   zFormatterPrettyPrint.__call__0  s    yy%%f--r1   N)Tr   rN   r1   r(   ri   ri   *  s    &
.r1   ri   c                   &     e Zd Zd fd	Zd Z xZS )DictFormatterc                 >    t         |           || _        || _        y)zq
        format_dict : dictionary for format strings to be used.
        formatter : fall-back formatter
        N)rQ   r0   _format_dict_fallback_formatter)r/   format_dict	formatterrV   s      r(   r0   zDictFormatter.__init__5  s     
 	'#, r1   c                     | j                   r| j                  |||      }ndgt        |      z  }t        ||      D cg c]!  \  }}| j                  j	                  ||      # c}}S c c}}w )zG
        factor is ignored if value is found in the dictionary
         )r   r   r   r   get)r/   rw   rx   rZ   fallback_stringsr   r&   s          r(   r>   zDictFormatter.__call__>  sw     ###7766 + !#tc&k1(89;Aq !!%%a+ ; 	; ;s   &A)rX   r   rc   s   @r(   r   r   4  s    -
;r1   r   )numpyr   
matplotlibr   rt   r   matplotlib.transformsr   r   r)   r+   r4   re   rh   r   ri   r   rN   r1   r(   <module>r      sl     . 1$N4@ 4@n9y 98JC JCZ,'%% , " ". .; ;r1   