
    g{                    R   d Z ddlZddlZddlZddlZddlZddlZddlZddl	m
Z
 ddlmZ ddlmZmZmZ ddlmZ dZd	 Z G d
 d      Z G d de      Z ej.                  ej0                  ej0                  g      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z  G d de       Z! G d de       Z" G d  d!      Z# G d" d#e#e      Z$ G d$ d%e#e       Z%d& Z& G d' d(e      Z' G d) d*e       Z(d+ Z) G d, d-e       Z* G d. d/e       Z+ ejX                  d0       G d1 d2e+             Z- G d3 d4e       Z. G d5 d6e       Z/ G d7 d8e       Z0 G d9 d:e       Z1 G d; d<e      Z2 G d= d>e2      Z3dDd?Z4d@ Z5dEdAZ6dB Z7dFdCZ8y)GaT  
Matplotlib includes a framework for arbitrary geometric transformations that is used to
determine the final position of all elements drawn on the canvas.

Transforms are composed into trees of `TransformNode` objects
whose actual value depends on their children.  When the contents of
children change, their parents are automatically invalidated.  The
next time an invalidated transform is accessed, it is recomputed to
reflect those changes.  This invalidation/caching approach prevents
unnecessary recomputations of transforms, and contributes to better
interactive performance.

For example, here is a graph of the transform tree used to plot data to the figure:

.. graphviz:: /api/transforms.dot
    :alt: Diagram of transform tree from data to figure coordinates.

The framework can be used for both affine and non-affine
transformations.  However, for speed, we want to use the backend
renderers to perform affine transformations whenever possible.
Therefore, it is possible to perform just the affine or non-affine
part of a transformation on a set of data.  The affine is always
assumed to occur after the non-affine.  For any transform::

  full transform == non-affine part + affine part

The backends are not expected to handle non-affine transformations
themselves.

See the tutorial :ref:`transforms_tutorial` for examples
of how to use transforms.
    N)inv)_api)affine_transformcount_bboxes_overlapping_bboxupdate_path_extents   )PathFc                  j     t        j                  t        j                  d      d  fdS )a+  
    Generate a ``__str__`` method for a `.Transform` subclass.

    After ::

        class T:
            __str__ = _make_str_method("attr", key="other")

    ``str(T(...))`` will be

    .. code-block:: text

        {type(T).__name__}(
            {self.attr},
            key={self.other})
    z    )prefixc                 N    t        | t              rt        |       S t        |       S N)
isinstancestrrepr)xs    H/var/www/html/venv/lib/python3.12/site-packages/matplotlib/transforms.pystrreprz!_make_str_method.<locals>.strreprJ   s    jC&847Dc!fD    c                      t               j                  dz   dj                  g  fdD         fdj                         D              z   dz   S )N(,c           
   3   T   K   | ]  } d  t        |            z          ! yw)
Ngetattr).0argindentselfr   s     r   	<genexpr>z5_make_str_method.<locals>.<lambda>.<locals>.<genexpr>M   s/      ' TGGD#,>$??@ 's   %(c           
   3   f   K   | ](  \  }} d |z   dz    t        |            z          * yw)r   =Nr   )r   kr   r   r   r   s      r   r    z5_make_str_method.<locals>.<lambda>.<locals>.<genexpr>O   s;      4 !S TAX^ggdC6H.IIJ 4s   .1))type__name__joinitems)r   argsr   kwargsr   s   `r   <lambda>z"_make_str_method.<locals>.<lambda>K   sd    T
c!
(( 5 '!%' 54$*LLN45 6	6
 	 r   )	functoolspartialtextwrapr   )r)   r*   r   r   s   ``@@r   _make_str_methodr/   8   s(    " xw?FD r   c                        e Zd ZdZ ed      \  ZZZdZ  e	j                  d       e	j                  d             ZdZ	 ddZerd Zd Zd	 Z fd
Zd Zd Zd Zd Z xZS )TransformNodea'  
    The base class for anything that participates in the transform tree
    and needs to invalidate its parents or be invalidated.  This includes
    classes that are not really transforms, such as bounding boxes, since some
    transforms depend on bounding boxes to compute their values.
       F3.9c                      yNF clss    r   r+   zTransformNode.<lambda>f       r   c                 J    i | _         | j                  | _        |xs d| _        y)a  
        Parameters
        ----------
        shorthand_name : str
            A string representing the "name" of the transform. The name carries
            no significance other than to improve the readability of
            ``str(transform)`` when DEBUG=True.
         N)_parents_INVALID_FULL_invalid_shorthand_name)r   shorthand_names     r   __init__zTransformNode.__init__n   s%     **-3r   c                 4    | j                   xs t        |       S r   )r?   r   r   s    r   __str__zTransformNode.__str__}   s    ''54:5r   c           	          i | j                   d| j                  j                         D ci c]  \  }}| |        c}}iS c c}}w )Nr<   )__dict__r<   r(   )r   r#   vs      r   __getstate__zTransformNode.__getstate__   sJ    H$-- H0C0C0EF1QVFH 	HFs   A
c           
          || _         | j                  j                         D ci c]6  \  }}|/|t        j                  || j                  j
                  |fd      8 c}}| _        y c c}}w )Nc                      ||      S r   r6   _popr#   s      r   r+   z,TransformNode.__setstate__.<locals>.<lambda>   s
    CF r   )rF   r<   r(   weakrefrefrM   )r   	data_dictr#   rG   s       r   __setstate__zTransformNode.__setstate__   sa    ! ++-@1 w{{1DMM,=,=JKK@ @s   ;A*c                    t        j                   t                     }i |_        t        |       j	                         D ]?  \  }}t        |t              st        |       |j                  v s/|j                  |       A |S r   )	copysuperr<   varsr(   r   r1   idset_children)r   otherkeyval	__class__s       r   __copy__zTransformNode.__copy__   sl    		%'"  T
((* 	(HC#}-"T(cll2J""3'	( r   c                 x    | j                  | j                  r| j                  |       S | j                  |       S )z
        Invalidate this `TransformNode` and triggers an invalidation of its
        ancestors.  Should be called any time the transform changes.
        levelinvalidating_node)_invalidate_internal	is_affine_INVALID_AFFINE_ONLYr=   rC   s    r   
invalidatezTransformNode.invalidate   sI    
 ((/3~~$++" ) $ 	$CGCUCU" ) $ 	$r   c                     || j                   k  r| j                  sy|| _         t        | j                  j	                               D ]  } |       }||j                  ||        ! y)z
        Called by :meth:`invalidate` and subsequently ascends the transform
        stack calling each TransformNode's _invalidate_internal method.
        Nr^   )r>   pass_throughlistr<   valuesra   )r   r_   r`   parents       r   ra   z"TransformNode._invalidate_internal   se     DMM!$*;*;4==//12 	QFXF!++%4+P	Qr   c                     t        |       }|D ]?  }t        j                  | |j                  j                  |fd      }||j                  |<   A y)z
        Set the children of the transform, to let the invalidation
        system know which transforms can invalidate this transform.
        Should be called from the constructor of any transforms that
        depend on other transforms.
        c                      ||      S r   r6   rK   s      r   r+   z,TransformNode.set_children.<locals>.<lambda>   s
    3q6 r   N)rV   rN   rO   r<   rM   )r   childrenid_selfchildrO   s        r   rW   zTransformNode.set_children   sO     T( 	*E ++ENN$6$6'IKC&)ENN7#	*r   c                     | S )a  
        Return a frozen copy of this transform node.  The frozen copy will not
        be updated when its children change.  Useful for storing a previously
        known state of a transform where ``copy.deepcopy()`` might normally be
        used.
        r6   rC   s    r   frozenzTransformNode.frozen   s	     r   r   )r&   
__module____qualname____doc__range_VALIDrc   r=   rb   r   
deprecatedclasspropertyis_bboxrf   rA   DEBUGrD   rH   rQ   r\   rd   ra   rW   rp   __classcell__r[   s   @r   r1   r1   T   s     38(/F - I$odooe$%7T%7%78I%JKGL
4 	6H
@
$Q*&r   r1   c            
          e Zd ZdZ  ej
                  d       ej                  d             ZdZe	re
d        Zd Zej                  e_        d Zed        Zed	        Zed
        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Z ed        Z!ed        Z"d Z#d Z$d Z%d Z&d Z'd  Z(d! Z)d" Z*d# Z+d$ Z,d%d&d'd(d)d*d+d,d-d.	Z-d/ Z.d0 Z/d>d2Z0d3 Z1d4 Z2d5 Z3d6 Z4d7 Z5d?d8Z6d9 Z7d: Z8d; Z9e
d<        Z:e
d=        Z;y1)@BboxBasea`  
    The base class of all bounding boxes.

    This class is immutable; `Bbox` is a mutable subclass.

    The canonical representation is as two points, with no
    restrictions on their ordering.  Convenience properties are
    provided to get the left, bottom, right and top edges and width
    and height, but these are not stored explicitly.
    r3   c                      y)NTr6   r7   s    r   r+   zBboxBase.<lambda>   r9   r   Tc                 
   t        | t        j                  j                        rt	        j
                  d       t        j                  |       } t        | dd d f   | dd d f   z
  dk(        rt	        j
                  d       y y )NzBbox bounds are a masked array.r   r   zSingular Bbox.)r   npmaMaskedArrayr   warn_externalasarrayany)pointss    r   _checkzBboxBase._check   si    &"%%"3"34""#DEZZ'FF1a4L6!Q$</A56""#34 7r   c                 P    t        | j                         j                               S r   )Bbox
get_pointsrS   rC   s    r   rp   zBboxBase.frozen   s    DOO%**,--r   c                 "    | j                         S r   r   r   r)   r*   s      r   	__array__zBboxBase.__array__   s      r   c                 (    | j                         d   S )z
        The first of the pair of *x* coordinates that define the bounding box.

        This is not guaranteed to be less than :attr:`x1` (for that, use
        :attr:`xmin`).
        r   r   r   rC   s    r   x0zBboxBase.x0         &&r   c                 (    | j                         d   S )z
        The first of the pair of *y* coordinates that define the bounding box.

        This is not guaranteed to be less than :attr:`y1` (for that, use
        :attr:`ymin`).
        r   r   r   rC   s    r   y0zBboxBase.y0   r   r   c                 (    | j                         d   S )z
        The second of the pair of *x* coordinates that define the bounding box.

        This is not guaranteed to be greater than :attr:`x0` (for that, use
        :attr:`xmax`).
        r   r   r   rC   s    r   x1zBboxBase.x1  r   r   c                 (    | j                         d   S )z
        The second of the pair of *y* coordinates that define the bounding box.

        This is not guaranteed to be greater than :attr:`y0` (for that, use
        :attr:`ymax`).
        r   r   r   rC   s    r   y1zBboxBase.y1  r   r   c                 (    | j                         d   S )z
        The first pair of (*x*, *y*) coordinates that define the bounding box.

        This is not guaranteed to be the bottom-left corner (for that, use
        :attr:`min`).
        r   r   rC   s    r   p0zBboxBase.p0        ##r   c                 (    | j                         d   S )z
        The second pair of (*x*, *y*) coordinates that define the bounding box.

        This is not guaranteed to be the top-right corner (for that, use
        :attr:`max`).
        r   r   rC   s    r   p1zBboxBase.p1!  r   r   c                 V    t        j                  | j                         dddf         S )z"The left edge of the bounding box.Nr   r   minr   rC   s    r   xminzBboxBase.xmin+  #     vvdoo'1-..r   c                 V    t        j                  | j                         dddf         S )z$The bottom edge of the bounding box.Nr   r   rC   s    r   yminzBboxBase.ymin0  r   r   c                 V    t        j                  | j                         dddf         S )z#The right edge of the bounding box.Nr   r   maxr   rC   s    r   xmaxzBboxBase.xmax5  r   r   c                 V    t        j                  | j                         dddf         S )z!The top edge of the bounding box.Nr   r   rC   s    r   ymaxzBboxBase.ymax:  r   r   c                 L    t        j                  | j                         d      S )z+The bottom-left corner of the bounding box.r   axisr   rC   s    r   r   zBboxBase.min?       vvdoo'a00r   c                 L    t        j                  | j                         d      S )z)The top-right corner of the bounding box.r   r   r   rC   s    r   r   zBboxBase.maxD  r   r   c                 0    | j                         dddf   S )z
        The pair of *x* coordinates that define the bounding box.

        This is not guaranteed to be sorted from left to right.
        Nr   r   rC   s    r   	intervalxzBboxBase.intervalxI        A&&r   c                 0    | j                         dddf   S )z
        The pair of *y* coordinates that define the bounding box.

        This is not guaranteed to be sorted from bottom to top.
        Nr   r   rC   s    r   	intervalyzBboxBase.intervalyR  r   r   c                 8    | j                         }|d   |d   z
  S )z'The (signed) width of the bounding box.r   r   r   r   r   s     r   widthzBboxBase.width[  #     "d|fTl**r   c                 8    | j                         }|d   |d   z
  S )z(The (signed) height of the bounding box.r   r   r   r   s     r   heightzBboxBase.heighta  r   r   c                 8    | j                         }|d   |d   z
  S )z2The (signed) width and height of the bounding box.r   r   r   r   s     r   sizezBboxBase.sizeg  s#     "ay6!9$$r   c                 L    | j                         \  \  }}\  }}||||z
  ||z
  fS )z?Return (:attr:`x0`, :attr:`y0`, :attr:`width`, :attr:`height`).r   r   r   r   r   r   s        r   boundszBboxBase.boundsm  s4     "__.R(2rBRb))r   c                 >    | j                         j                         S )z8Return (:attr:`x0`, :attr:`y0`, :attr:`x1`, :attr:`y1`).)r   flattenrC   s    r   extentszBboxBase.extentss  s      ((**r   c                     t         r   NotImplementedErrorrC   s    r   r   zBboxBase.get_pointsx  s    !!r   c                 d    | j                   \  }}||cxk  xr |k  nc xs ||cxk\  xr |k\  S c S )zX
        Return whether *x* is in the closed (:attr:`x0`, :attr:`x1`) interval.
        r   r   r   r   r   s       r   	containsxzBboxBase.containsx{  1     BQ}"}-a2--r   c                 d    | j                   \  }}||cxk  xr |k  nc xs ||cxk\  xr |k\  S c S )zX
        Return whether *y* is in the closed (:attr:`y0`, :attr:`y1`) interval.
        r   r   yr   r   s       r   	containsyzBboxBase.containsy  r   r   c                 J    | j                  |      xr | j                  |      S )zR
        Return whether ``(x, y)`` is in the bounding box or on its edge.
        )r   r   r   r   r   s      r   containszBboxBase.contains  s!     ~~a 6T^^A%66r   c                     | j                   \  }}}}|j                   \  }}}}	||k  r||}}||k  r||}}||k  r||}}|	|k  r||	}}	||k  xr ||k  xr ||	k  xr ||k  S )z
        Return whether this bounding box overlaps with the other bounding box.

        Parameters
        ----------
        other : `.BboxBase`
        r   
r   rX   ax1ay1ax2ay2bx1by1bx2by2s
             r   overlapszBboxBase.overlaps  s     "\\S#s"]]S#s9CC9CC9CC9CCczFcSjFSCZFC3JFr   c                 d    | j                   \  }}||cxk  xr |k  nc xs ||cxkD  xr |kD  S c S )zV
        Return whether *x* is in the open (:attr:`x0`, :attr:`x1`) interval.
        r   r   s       r   fully_containsxzBboxBase.fully_containsx  1     BA{{)b1krk)k)r   c                 d    | j                   \  }}||cxk  xr |k  nc xs ||cxkD  xr |kD  S c S )zV
        Return whether *y* is in the open (:attr:`y0`, :attr:`y1`) interval.
        r   r   s       r   fully_containsyzBboxBase.fully_containsy  r   r   c                 J    | j                  |      xr | j                  |      S )zV
        Return whether ``x, y`` is in the bounding box, but not on its edge.
        )r   r   r   s      r   fully_containszBboxBase.fully_contains  s%     ##A&B4+?+?+BBr   c                     | j                   \  }}}}|j                   \  }}}}	||k  r||}}||k  r||}}||k  r||}}|	|k  r||	}}	||k  xr ||k  xr ||	k  xr ||k  S )z
        Return whether this bounding box overlaps with the other bounding box,
        not including the edges.

        Parameters
        ----------
        other : `.BboxBase`
        r   r   s
             r   fully_overlapszBboxBase.fully_overlaps  s     "\\S#s"]]S#s9CC9CC9CC9CCSyBS3YB39BsBr   c           	          | j                         }|j                  t        j                  |d   |d   |d   g|d   |d   gg            \  }}}t	        ||d   |d   gg      S )zX
        Construct a `Bbox` by statically transforming this one by *transform*.
        r   r   r   r   r   r   )r   	transformr   arrayr   )r   r   ptsllullrs         r   transformedzBboxBase.transformed  sw     oo((Vc$iT+c$iT-CD*F G
BR"Q%A())r   )      ?r   r   )r   r   )      ?r   )r   r   )r   r   )r   r   )r   r   )r   r   )	CSWSSEENENNWWc                     |j                   \  }}}}| j                   \  }}}	}
t        |t              r| j                  |   n|\  }}t	        | j
                  ||||	z
  z  z   |z
  ||||
z
  z  z   |z
  gz         S )a  
        Return a copy of the `Bbox` anchored to *c* within *container*.

        Parameters
        ----------
        c : (float, float) or {'C', 'SW', 'S', 'SE', 'E', 'NE', ...}
            Either an (*x*, *y*) pair of relative coordinates (0 is left or
            bottom, 1 is right or top), 'C' (center), or a cardinal direction
            ('SW', southwest, is bottom left, etc.).
        container : `Bbox`
            The box within which the `Bbox` is positioned.

        See Also
        --------
        .Axes.set_anchor
        )r   r   r   coefsr   _points)r   c	containerlbwhLBr   Hcxcys                r   anchoredzBboxBase.anchored  s    " %%
1a[[
1a",Q"4A!BDLL"A,&!+"A,&!+-- . 	.r   c                     | j                   \  }}t        | j                  d   | j                  d   ||z  ||z  gz   g      S )a  
        Return a copy of the `Bbox`, shrunk by the factor *mx*
        in the *x* direction and the factor *my* in the *y* direction.
        The lower left corner of the box remains unchanged.  Normally
        *mx* and *my* will be less than 1, but this is not enforced.
        r   )r   r   r   )r   mxmyr  r  s        r   shrunkzBboxBase.shrunk  sJ     yy1T\\!_\\!_QQ'779 : 	:r   Nc                     |dk  s|dk  rt        d      || }|j                  \  }}||z  |z  }||k  r|}n
||z  |z  }|}t        | j                  d   | j                  d   ||fz   g      S )a  
        Return a copy of the `Bbox`, shrunk so that it is as
        large as it can be while having the desired aspect ratio,
        *box_aspect*.  If the box coordinates are relative (i.e.
        fractions of a larger box such as a figure) then the
        physical aspect ratio of that figure is specified with
        *fig_aspect*, so that *box_aspect* can also be given as a
        ratio of the absolute dimensions, not the relative dimensions.
        r   z.'box_aspect' and 'fig_aspect' must be positive)
ValueErrorr   r   r   )r   
box_aspectr  
fig_aspectr  r  r	  r   s           r   shrunk_to_aspectzBboxBase.shrunk_to_aspect  s     ?jAoMNNI~~1
NZ'6AJ+AAT\\!_\\!_1v-/ 0 	0r   c           
          dg|d}| j                   \  }}}}||z
  }t        j                  |      D 	cg c]"  \  }}	t        |||z  z   |g||	|z  z   |gg      $ c}	}S c c}	}w )z
        Return a list of new `Bbox` objects formed by splitting the original
        one with vertical lines at fractional positions given by *args*.
        r   r   r   	itertoolspairwiser   )
r   r)   xfr   r   r   r   r  xf0xf1s
             r   splitxzBboxBase.splitx  s    
 ]$]]BBG ) 2 22 68C rC!G|R(2a<*<=> 8 	8 8   'A!c                     dg|d}| j                   \  }}}}||z
  }t        j                  |      D 	cg c]"  \  }}	t        ||||z  z   g|||	|z  z   gg      $ c}	}S c c}	}w )z
        Return a list of new `Bbox` objects formed by splitting the original
        one with horizontal lines at fractional positions given by *args*.
        r   r   r  )
r   r)   yfr   r   r   r   r  yf0yf1s
             r   splityzBboxBase.splity%  s    
 ]$]]BBG ) 2 22 68C r2a<(2rC!G|*<=> 8 	8 8r  c                    t        |      dk(  ryt        j                  |      }t        j                  d      5  | j                  |k  || j
                  k  z  j                  d      j                         cddd       S # 1 sw Y   yxY w)z
        Count the number of vertices contained in the `Bbox`.
        Any vertices with a non-finite x or y value are ignored.

        Parameters
        ----------
        vertices : (N, 2) array
        r   ignore)invalidr   r   N)lenr   r   errstater   r   allsum)r   verticess     r   count_containszBboxBase.count_contains0  sp     x=A::h'[[* 	?hh))+,/CQCK	? 	? 	?s   =BBc                     t        | t        j                  |D cg c]  }t        j                  |       c}            S c c}w )z
        Count the number of bounding boxes that overlap this one.

        Parameters
        ----------
        bboxes : sequence of `.BboxBase`
        )r   r   
atleast_3dr   )r   bboxesr   s      r   count_overlapszBboxBase.count_overlaps@  s7     -"--f =! =>@ 	@ =s   Ac                     | j                   }| j                  }||z  |z
  dz  }||z  |z
  dz  }t        j                  | | g||gg      }t	        | j
                  |z         S )zr
        Construct a `Bbox` by expanding this one around its center by the
        factors *sw* and *sh*.
        g       @)r   r   r   r   r   r   )r   swshr   r   deltawdeltahas           r   expandedzBboxBase.expandedK  sq    
 

u*u$+v+&#-HHw(66*:;<DLL1$%%r   c                 V    | j                         }||}t        || | g||ggz         S )z
        Construct a `Bbox` by padding this one on all four sides.

        Parameters
        ----------
        w_pad : float
            Width pad
        h_pad : float, optional
            Height pad.  Defaults to *w_pad*.

        )r   r   )r   w_padh_padr   s       r   paddedzBboxBase.paddedW  s<     "=EFvv.??@@r   c                 6    t        | j                  ||fz         S )z<Construct a `Bbox` by translating this one by *tx* and *ty*.)r   r   r   txtys      r   
translatedzBboxBase.translatedh  s    DLLB8+,,r   c                 v    | j                         \  \  }}\  }}t        j                  ||g||g||g||gg      S )z
        Return the corners of this rectangle as an array of points.

        Specifically, this returns the array
        ``[[x0, y0], [x0, y1], [x1, y0], [x1, y1]]``.
        )r   r   r   r   s        r   cornerszBboxBase.cornersl  sE     "__.R(2rxx"bB8b"XBx@AAr   c                     | j                         }t               j                  |      j                  |      }t        j                         }|j                  |d       |S )z
        Return the axes-aligned bounding box that bounds the result of rotating
        this `Bbox` by an angle of *radians*.
        T)r%  )rB  Affine2Drotater   r   unitupdate_from_data_xy)r   radiansrB  corners_rotatedbboxs        r   rotatedzBboxBase.rotatedv  sO    
 ,,."*++G4>>wGyy{   >r   c                    t        |       st        d      t        j                  | D cg c]  }|j                   c}      }t        j
                  | D cg c]  }|j                   c}      }t        j                  | D cg c]  }|j                   c}      }t        j
                  | D cg c]  }|j                   c}      }t        ||g||gg      S c c}w c c}w c c}w c c}w )z8Return a `Bbox` that contains all of the given *bboxes*.z'bboxes' cannot be empty)
r'  r  r   r   r   r   r   r   r   r   )r/  rJ  r   r   r   r   s         r   unionzBboxBase.union  s     6{788VV624TYY23VV624TYY23VV624TYY23VV624TYY23b"XBx())	 3222s   CC!C&1C+c                    t        j                  | j                  |j                        }t        j                  | j                  |j                        }t        j                  | j
                  |j
                        }t        j                  | j                  |j                        }||k  r||k  rt        ||g||gg      S dS )zr
        Return the intersection of *bbox1* and *bbox2* if they intersect, or
        None if they don't.
        N)r   maximumr   minimumr   r   r   r   )bbox1bbox2r   r   r   r   s         r   intersectionzBboxBase.intersection  s     ZZ

EJJ/ZZ

EJJ/ZZ

EJJ/ZZ

EJJ/-/2X"(tb"XBx()LLr   )Nr   r   )<r&   rq   rr   rs   r   rv   rw   rx   rb   ry   staticmethodr   rp   r1   r   propertyr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r#  r,  r0  r7  r;  r@  rB  rK  rM  rS  r6   r   r   r}   r}      s   	 %odooe$%7T%7%78H%IJGI		5 
	5."**FN! ' ' ' ' ' ' ' ' $ $ $ $ / / / / / / / / 1 1 1 1 ' ' ' ' + +
 + +
 % %
 * *
 + +"..7G(**CC** E.0	:00	8	8? 	@
&A"-B	 * * 	M 	Mr   r}   c                   z    e Zd ZdZ fdZer
eZd Z fdZ fdZe	d        Z
e	d        Ze	d        Ze	d	d
d       Zd Zd Zd Zd Zd)dZd*dZd*dZd)dZej.                  j0                  d        Zej2                  j0                  d        Zej4                  j0                  d        Zej6                  j0                  d        Zej8                  j0                  d        Zej:                  j0                  d        Zej<                  j0                  d        Zej>                  j0                  d        Zej@                  j0                  d        Z e!d        Z"e"j0                  d        Z"e!d        Z#e#j0                  d         Z#e!d!        Z$e$j0                  d"        Z$d# Z%d$ Z&d% Z'd& Z(d' Z)d( Z* xZ+S )+r   a	  
    A mutable bounding box.

    Examples
    --------
    **Create from known bounds**

    The default constructor takes the boundary "points" ``[[xmin, ymin],
    [xmax, ymax]]``.

        >>> Bbox([[1, 1], [3, 7]])
        Bbox([[1.0, 1.0], [3.0, 7.0]])

    Alternatively, a Bbox can be created from the flattened points array, the
    so-called "extents" ``(xmin, ymin, xmax, ymax)``

        >>> Bbox.from_extents(1, 1, 3, 7)
        Bbox([[1.0, 1.0], [3.0, 7.0]])

    or from the "bounds" ``(xmin, ymin, width, height)``.

        >>> Bbox.from_bounds(1, 1, 2, 6)
        Bbox([[1.0, 1.0], [3.0, 7.0]])

    **Create from collections of points**

    The "empty" object for accumulating Bboxs is the null bbox, which is a
    stand-in for the empty set.

        >>> Bbox.null()
        Bbox([[inf, inf], [-inf, -inf]])

    Adding points to the null bbox will give you the bbox of those points.

        >>> box = Bbox.null()
        >>> box.update_from_data_xy([[1, 1]])
        >>> box
        Bbox([[1.0, 1.0], [1.0, 1.0]])
        >>> box.update_from_data_xy([[2, 3], [3, 2]], ignore=False)
        >>> box
        Bbox([[1.0, 1.0], [3.0, 3.0]])

    Setting ``ignore=True`` is equivalent to starting over from a null bbox.

        >>> box.update_from_data_xy([[1, 1]], ignore=True)
        >>> box
        Bbox([[1.0, 1.0], [1.0, 1.0]])

    .. warning::

        It is recommended to always specify ``ignore`` explicitly.  If not, the
        default value of ``ignore`` can be changed at any time by code with
        access to your Bbox, for example using the method `~.Bbox.ignore`.

    **Properties of the ``null`` bbox**

    .. note::

        The current behavior of `Bbox.null()` may be surprising as it does
        not have all of the properties of the "empty set", and as such does
        not behave like a "zero" object in the mathematical sense. We may
        change that in the future (with a deprecation period).

    The null bbox is the identity for intersections

        >>> Bbox.intersection(Bbox([[1, 1], [3, 7]]), Bbox.null())
        Bbox([[1.0, 1.0], [3.0, 7.0]])

    except with itself, where it returns the full space.

        >>> Bbox.intersection(Bbox.null(), Bbox.null())
        Bbox([[-inf, -inf], [inf, inf]])

    A union containing null will always return the full space (not the other
    set!)

        >>> Bbox.union([Bbox([[0, 0], [0, 0]]), Bbox.null()])
        Bbox([[-inf, -inf], [inf, inf]])
    c                    t        |   di | t        j                  |t              }|j
                  dk7  rt        d      || _        t        j                         | _
        d| _        | j                  j                         | _        y)z
        Parameters
        ----------
        points : `~numpy.ndarray`
            A (2, 2) array of the form ``[[x0, y0], [x1, y1]]``.
           rY  z7Bbox points must be of the form "[[x0, y0], [x1, y1]]".TNr6   )rT   rA   r   r   floatshaper  r   _default_minposrS   _minpos_ignore_points_orig)r   r   r*   r[   s      r   rA   zBbox.__init__  sx     	"6"FE*<<6! 7 8 8&++- !LL--/r   c                 L    | j                  |        | j                  |fi | y r   )r   	___init__)r   r   r*   s      r   rA   zBbox.__init__  s!    KKDNN6,V,r   c                 X    | j                  | j                         t        |           y r   )r   r   rT   rd   )r   r[   s    r   rd   zBbox.invalidate  s    KK%G r   c                 b    t         |          }| j                  j                         |_        |S r   )rT   rp   minposrS   r]  )r   frozen_bboxr[   s     r   rp   zBbox.frozen  s*    gn&"kk..0r   c                  $    t        ddgddgg      S )z/Create a new unit `Bbox` from (0, 0) to (1, 1).r   r   )r   r6   r   r   rF  z	Bbox.unit  s     aVaV$%%r   c                      t        t        j                  t        j                  gt        j                   t        j                   gg      S )z9Create a new null `Bbox` from (inf, inf) to (-inf, -inf).)r   r   infr6   r   r   nullz	Bbox.null  s2     bffbff%"&&'9:;;r   c                 >    t         j                  | || |z   ||z         S )z{
        Create a new `Bbox` from *x0*, *y0*, *width* and *height*.

        *width* and *height* may be negative.
        )r   from_extents)r   r   r   r   s       r   from_boundszBbox.from_bounds  s#       ReR&[AAr   N)rd  c                 f    t        t        j                  |d            }| | |j                  dd |S )a  
        Create a new Bbox from *left*, *bottom*, *right* and *top*.

        The *y*-axis increases upwards.

        Parameters
        ----------
        left, bottom, right, top : float
            The four extents of the bounding box.
        minpos : float or None
            If this is supplied, the Bbox will have a minimum positive value
            set. This is useful when dealing with logarithmic scales and other
            scales where negative bounds result in floating point errors.
        rX  N)r   r   reshaper]  )rd  r)   rJ  s      r   rk  zBbox.from_extents$  s1      BJJtV,-$DLLOr   c                 &    dj                  | |      S )Nz@Bbox(x0={0.x0:{1}}, y0={0.y0:{1}}, x1={0.x1:{1}}, y1={0.y1:{1}})format)r   fmts     r   
__format__zBbox.__format__9  s    NF4	r   c                     t        | d      S )Nr;   rp  rC   s    r   rD   zBbox.__str__>  s    dBr   c                 $    dj                  |       S )Nz*Bbox([[{0.x0}, {0.y0}], [{0.x1}, {0.y1}]])rp  rC   s    r   __repr__zBbox.__repr__A  s    ;BB4HHr   c                     || _         y)a  
        Set whether the existing bounds of the box should be ignored
        by subsequent calls to :meth:`update_from_data_xy`.

        value : bool
            - When ``True``, subsequent calls to `update_from_data_xy` will
              ignore the existing bounds of the `Bbox`.
            - When ``False``, subsequent calls to `update_from_data_xy` will
              include the existing bounds of the `Bbox`.
        N)r^  )r   values     r   r%  zBbox.ignoreD  s     r   c                    || j                   }|j                  j                  dk(  ryt        |d| j                  | j
                  |      \  }}}|rn| j                          |r,|dddf   | j                  dddf<   |d   | j
                  d<   |r-|dddf   | j                  dddf<   |d   | j
                  d<   yyy)a  
        Update the bounds of the `Bbox` to contain the vertices of the
        provided path. After updating, the bounds will have positive *width*
        and *height*; *x0* and *y0* will be the minimal values.

        Parameters
        ----------
        path : `~matplotlib.path.Path`
        ignore : bool, optional
           - When ``True``, ignore the existing bounds of the `Bbox`.
           - When ``False``, include the existing bounds of the `Bbox`.
           - When ``None``, use the last value passed to :meth:`ignore`.
        updatex, updatey : bool, default: True
            When ``True``, update the x/y values.
        Nr   r   )r^  r+  r   r   r   r]  rd   )r   pathr%  updatexupdateyr   rd  changeds           r   update_from_pathzBbox.update_from_pathQ  s      >\\F==""5$dllF#< OO%+AqD\QT""()Q%+AqD\QT""()Q  r   c                     t        j                  |      }| j                  t        j                  |t        j                  |j
                        g      |d       y)a  
        Update the x-bounds of the `Bbox` based on the passed in data. After
        updating, the bounds will have positive *width*, and *x0* will be the
        minimal value.

        Parameters
        ----------
        x : `~numpy.ndarray`
            Array of x-values.
        ignore : bool, optional
           - When ``True``, ignore the existing bounds of the `Bbox`.
           - When ``False``, include the existing bounds of the `Bbox`.
           - When ``None``, use the last value passed to :meth:`ignore`.
        F)r%  r|  Nr   ravelrG  column_stackonesr   )r   r   r%  s      r   update_from_data_xzBbox.update_from_data_xs  sE     HHQK  !RWWQVV_1E!F(. 	! 	?r   c                     t        j                  |      }| j                  t        j                  t        j                  |j
                        |g      |d       y)a  
        Update the y-bounds of the `Bbox` based on the passed in data. After
        updating, the bounds will have positive *height*, and *y0* will be the
        minimal value.

        Parameters
        ----------
        y : `~numpy.ndarray`
            Array of y-values.
        ignore : bool, optional
            - When ``True``, ignore the existing bounds of the `Bbox`.
            - When ``False``, include the existing bounds of the `Bbox`.
            - When ``None``, use the last value passed to :meth:`ignore`.
        F)r%  r{  Nr  )r   r   r%  s      r   update_from_data_yzBbox.update_from_data_y  sE     HHQK  "''!&&/11E!F(. 	! 	?r   c                 b    t        |      dk(  ryt        |      }| j                  ||||       y)a  
        Update the `Bbox` bounds based on the passed in *xy* coordinates.

        After updating, the bounds will have positive *width* and *height*;
        *x0* and *y0* will be the minimal values.

        Parameters
        ----------
        xy : (N, 2) array-like
            The (x, y) coordinates.
        ignore : bool, optional
            - When ``True``, ignore the existing bounds of the `Bbox`.
            - When ``False``, include the existing bounds of the `Bbox`.
            - When ``None``, use the last value passed to :meth:`ignore`.
        updatex, updatey : bool, default: True
             When ``True``, update the x/y values.
        r   N)r%  r{  r|  )r'  r	   r~  )r   xyr%  r{  r|  rz  s         r   rG  zBbox.update_from_data_xy  s8    $ r7a<Bxd6&-w 	 	@r   c                 B    || j                   d<   | j                          y Nr   r   rd   r   rZ   s     r   r   zBbox.x0       Tr   c                 B    || j                   d<   | j                          y Nr   r  r  s     r   r   zBbox.y0  r  r   c                 B    || j                   d<   | j                          y Nr   r  r  s     r   r   zBbox.x1  r  r   c                 B    || j                   d<   | j                          y Nr   r  r  s     r   r   zBbox.y1  r  r   c                 B    || j                   d<   | j                          y Nr   r  r  s     r   r   zBbox.p0      Qr   c                 B    || j                   d<   | j                          y Nr   r  r  s     r   r   zBbox.p1  r  r   c                 J    || j                   d d df<   | j                          y r  r  r   intervals     r   r   zBbox.intervalx      %QTr   c                 J    || j                   d d df<   | j                          y r  r  r  s     r   r   zBbox.intervaly  r  r   c                     |\  }}}}t        j                  ||g||z   ||z   ggt              }t        j                  | j                  |k7        r|| _        | j                          y y r   )r   r   rZ  r   r   rd   )r   r   r  r  r  r  r   s          r   r   zBbox.bounds  s_    
1aAq6AE1q5>2E:66$,,&()!DLOO *r   c                     | j                   S )a  
        The minimum positive value in both directions within the Bbox.

        This is useful when dealing with logarithmic scales and other scales
        where negative bounds result in floating point errors, and will be used
        as the minimum extent instead of *p0*.
        r]  rC   s    r   rd  zBbox.minpos  s     ||r   c                 "    || j                   d d  y r   r  r  s     r   rd  zBbox.minpos  s    Qr   c                      | j                   d   S )a#  
        The minimum positive value in the *x*-direction within the Bbox.

        This is useful when dealing with logarithmic scales and other scales
        where negative bounds result in floating point errors, and will be used
        as the minimum *x*-extent instead of *x0*.
        r   r  rC   s    r   minposxzBbox.minposx       ||Ar   c                 "    || j                   d<   y r  r  r  s     r   r  zBbox.minposx      Qr   c                      | j                   d   S )a#  
        The minimum positive value in the *y*-direction within the Bbox.

        This is useful when dealing with logarithmic scales and other scales
        where negative bounds result in floating point errors, and will be used
        as the minimum *y*-extent instead of *y0*.
        r   r  rC   s    r   minposyzBbox.minposy   r  r   c                 "    || j                   d<   y r  r  r  s     r   r  zBbox.minposy  r  r   c                 (    d| _         | j                  S )zn
        Get the points of the bounding box as an array of the form
        ``[[x0, y0], [x1, y1]]``.
        r   )r>   r   rC   s    r   r   zBbox.get_points  s    
 ||r   c                 x    t        j                  | j                  |k7        r|| _        | j                          yy)z
        Set the points of the bounding box directly from an array of the form
        ``[[x0, y0], [x1, y1]]``.  No error checking is performed, as this
        method is mainly for internal use.
        N)r   r   r   rd   r   s     r   
set_pointszBbox.set_points  s/     66$,,&()!DLOO *r   c                     t        j                  | j                  |j                         k7        r&|j                         | _        | j	                          yy)zS
        Set this bounding box from the "frozen" bounds of another `Bbox`.
        N)r   r   r   r   rd   r   rX   s     r   setzBbox.set!  sA     66$,,%"2"2"445 ++-DLOO 6r   c                 F    | j                         xs | j                         S )z/Return whether the bbox has changed since init.)mutatedxmutatedyrC   s    r   mutatedzBbox.mutated)  s    }}1$--/1r   c                     | j                   d   | j                  d   k7  xs | j                   d   | j                  d   k7  S )z4Return whether the x-limits have changed since init.r   r   r   r_  rC   s    r   r  zBbox.mutatedx-  D    T"d&7&7&== >T"d&7&7&==	?r   c                     | j                   d   | j                  d   k7  xs | j                   d   | j                  d   k7  S )z4Return whether the y-limits have changed since init.r   r   r  rC   s    r   r  zBbox.mutatedy2  r  r   )NTTr   ),r&   rq   rr   rs   rA   ry   ra  rd   rp   rT  rF  ri  rl  rk  rs  rD   rv  r%  r~  r  r  rG  r}   r   setterr   r   r   r   r   r   r   r   rU  rd  r  r  r   r  r  r  r  r  rz   r{   s   @r   r   r     s\   N`0& 		-	! & & < < B B #'  (
 I ,D?&?&@2 [[  [[  [[  [[  [[  [[      __    ]]    ^^    ^^ 2?
?r   r   c                   T     e Zd ZdZ fdZ edd      Zd ZereZ	d Zd Z
d Z xZS )	TransformedBboxz
    A `Bbox` that is automatically transformed by a given
    transform.  When either the child bounding box or transform
    changes, the bounds of this bbox will update accordingly.
    c                 0   t        j                  t        |       t        j                  t        |       |j                  dk7  s|j
                  dk7  rt        d      t        |    di | || _	        || _
        | j                  ||       d| _        y)ze
        Parameters
        ----------
        bbox : `Bbox`
        transform : `Transform`
        rJ  r   rY  z8The input and output dimensions of 'transform' must be 2Nr6   )r   check_isinstancer}   	Transform
input_dimsoutput_dimsr  rT   rA   _bbox
_transformrW   r   )r   rJ  r   r*   r[   s       r   rA   zTransformedBbox.__init__?  s     	hT2i9=1$	(=(=(BJL L 	"6"
#$	*r   r  r  c                 h   | j                   r| j                  j                         }| j                  j	                  |d   |d   g|d   |d   g|d   |d   g|d   |d   gg      }t
        j                  j                  |d      }t        |d d df         t        |d d df         f}|d   |d   kD  r|d d d   }t        |d d df         t        |d d df         f}|d   |d   kD  r|d d d   }t        j                  |d   |d   g|d   |d   gg      | _        d| _         | j                  S )	Nr   r   r   r           r   r   )r>   r  r   r  r   r   r   filledr   r   r   r   )r   pr   xsyss        r   r   zTransformedBbox.get_pointsT  sT   ==

%%'A __..D'1T7#D'1T7#D'1T7#D'1T7#%&F
 UU\\&#.FVAqD\"Cq!t$55Bw4 "XVAqD\"Cq!t$55Bw4 "X88A1A1% DL
 DM||r   c                 H    | j                         }| j                  |       |S r   _get_pointsr   r   s     r   r   zTransformedBbox.get_pointsu  !    %%'FKKMr   c                      | j                   j                  | j                  j                         j	                  ||f       S r   )r  r   r  invertedr   r   s      r   r   zTransformedBbox.containsz  s5    "tzz""DOO$<$<$>$H$H!Q$PQQr   c                      | j                   j                  | j                  j                         j	                  ||f       S r   )r  r   r  r  r   r   s      r   r   zTransformedBbox.fully_contains~  s7    (tzz(($//*B*B*D*N*NPQSTv*VWWr   )r&   rq   rr   rs   rA   r/   rD   r   ry   r  r   r   rz   r{   s   @r   r  r  8  s;    & w5G<  	
RXr   r  c                       e Zd ZdZd fd	Z edd      Zd ZereZ	d Ze
d        Zej                  d        Ze
d	        Zej                  d
        Ze
d        Zej                  d        Ze
d        Zej                  d        Z xZS )LockableBboxz
    A `Bbox` where some elements may be locked at certain values.

    When the child bounding box changes, the bounds of this bbox will update
    accordingly with the exception of the locked elements.
    c                 D   t        j                  t        |       t        
|   di | || _        | j                  |       d| _        ||||g}|D cg c]  }|du  }	}t        j                  j                  |t        |	      j                  d      | _        yc c}w )a  
        Parameters
        ----------
        bbox : `Bbox`
            The child bounding box to wrap.

        x0 : float or None
            The locked value for x0, or None to leave unlocked.

        y0 : float or None
            The locked value for y0, or None to leave unlocked.

        x1 : float or None
            The locked value for x1, or None to leave unlocked.

        y1 : float or None
            The locked value for y1, or None to leave unlocked.

        r  NmaskrX  r6   )r   r  r}   rT   rA   r  rW   r   r   r   r   rZ  rn  _locked_points)r   rJ  r   r   r   r   r*   fprZ   r  r[   s             r   rA   zLockableBbox.__init__  s    ( 	hT2"6"
$"b"')*t** eekk"e$k?GGO +s   Br  r  c                     | j                   r[| j                  j                         }t        j                  | j
                  j                  || j
                        | _        d| _         | j                  S r  )r>   r  r   r   wherer  r  r   r   s     r   r   zLockableBbox.get_points  sX    ==ZZ**,F88D$7$7$<$<$*$($7$79DL DM||r   c                 H    | j                         }| j                  |       |S r   r  r   s     r   r   zLockableBbox.get_points  r  r   c                 T    | j                   j                  d   ry| j                   d   S )zB
        float or None: The value used for the locked x0.
        r   Nr  r  rC   s    r   	locked_x0zLockableBbox.locked_x0  ,    
 ##D)&&t,,r   c                     |d u | j                   j                  d<   || j                   j                  d<   | j                          y r  r  r  datard   )r   r   s     r   r  zLockableBbox.locked_x0  <    )+t  &)+  &r   c                 T    | j                   j                  d   ry| j                   d   S )zB
        float or None: The value used for the locked y0.
        r   Nr  rC   s    r   	locked_y0zLockableBbox.locked_y0  r  r   c                     |d u | j                   j                  d<   || j                   j                  d<   | j                          y r  r  )r   r   s     r   r  zLockableBbox.locked_y0  r  r   c                 T    | j                   j                  d   ry| j                   d   S )zB
        float or None: The value used for the locked x1.
        r   Nr  rC   s    r   	locked_x1zLockableBbox.locked_x1  r  r   c                     |d u | j                   j                  d<   || j                   j                  d<   | j                          y r  r  )r   r   s     r   r  zLockableBbox.locked_x1  r  r   c                 T    | j                   j                  d   ry| j                   d   S )zB
        float or None: The value used for the locked y1.
        r   Nr  rC   s    r   	locked_y1zLockableBbox.locked_y1  r  r   c                     |d u | j                   j                  d<   || j                   j                  d<   | j                          y r  r  )r   r   s     r   r  zLockableBbox.locked_y1  r  r   )NNNN)r&   rq   rr   rs   rA   r/   rD   r   ry   r  rU  r  r  r  r  r  rz   r{   s   @r   r  r    s    P: w(89G  	
 - -  
 - -  
 - -  
 - -  r   r  c                       e Zd ZdZdZ	 dZ	 dZ	 dZ	 d Zd Z	d Z
ed        Zd Zd	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd ZddZd Zy)r  a  
    The base class of all `TransformNode` instances that
    actually perform a transformation.

    All non-affine transformations should be subclasses of this class.
    New affine transformations should be subclasses of `Affine2D`.

    Subclasses of this class should override the following members (at
    minimum):

    - :attr:`input_dims`
    - :attr:`output_dims`
    - :meth:`transform`
    - :meth:`inverted` (if an inverse exists)

    The following attributes may be overridden if the default is unsuitable:

    - :attr:`is_separable` (defaults to True for 1D -> 1D transforms, False
      otherwise)
    - :attr:`has_inverse` (defaults to True if :meth:`inverted` is overridden,
      False otherwise)

    If the transform needs to do something non-standard with
    `matplotlib.path.Path` objects, such as adding curves
    where there were once line segments, it should override:

    - :meth:`transform_path`
    NFc                 6   t        d | j                  D              dk(  r)| j                  | j                  cxk(  rdk(  r
n nd| _        t        d | j                  D              dk(  r2t        | d      r%| j                  t        j                  urd| _        y y y y )Nc              3   6   K   | ]  }d t        |      v   yw)is_separableNrU   r   ri   s     r   r    z.Transform.__init_subclass__.<locals>.<genexpr>1  s     I6$v,.I   r   Tc              3   6   K   | ]  }d t        |      v   yw)has_inverseNr  r  s     r   r    z.Transform.__init_subclass__.<locals>.<genexpr>7  s     H&f-Hr  r  )	r*  __mro__r  r  r  hasattrr  r  r  r7   s    r   __init_subclass__zTransform.__init_subclass__,  s    
 IS[[IIQNNNcoo::#C HCKKHHAMC,LL	(:(::"CO ; - Nr   c                 F    t        |t              rt        | |      S t        S )z
        Compose two transforms together so that *self* is followed by *other*.

        ``A + B`` returns a transform ``C`` so that
        ``C.transform(x) == B.transform(A.transform(x))``.
        )r   r  composite_transform_factoryNotImplementedr  s     r   __add__zTransform.__add__<  s'     eY/ ,D%8 	 	 r   c              #   (   K   t               | f yw)a  
        Return an iterator breaking down this transform stack from left to
        right recursively. If self == ((A, N), A) then the result will be an
        iterator which yields I : ((A, N), A), followed by A : (N, A),
        followed by (A, N) : (A), but not ((A, N), A) : I.

        This is equivalent to flattening the stack then yielding
        ``flat_stack[:i], flat_stack[i:]`` where i=0..(n-1).
        NIdentityTransformrC   s    r   _iter_break_from_left_to_rightz(Transform._iter_break_from_left_to_rightK  s       !4''s   c                      y)a  
        Return the number of transforms which have been chained
        together to form this Transform instance.

        .. note::

            For the special case of a Composite transform, the maximum depth
            of the two is returned.

        r   r6   rC   s    r   depthzTransform.depthW  s     r   c                 v    | j                   |j                   k  ry| j                         D ]  \  }}||k(  s y y)aQ  
        Return whether the given transform is a sub-tree of this transform.

        This routine uses transform equality to identify sub-trees, therefore
        in many situations it is object id which will be used.

        For the case where the given transform represents the whole
        of this transform, returns True.
        FT)r  r   )r   rX   rL   sub_trees       r   contains_branchzTransform.contains_branche  sE     ::#  >>@ 	KAx5 	 r   c                 `    | j                   dk7  rt        d      | j                  |      fdz  S )aU  
        Return whether the given branch is a sub-tree of this transform on
        each separate dimension.

        A common use for this method is to identify if a transform is a blended
        transform containing an Axes' data transform. e.g.::

            x_isdata, y_isdata = trans.contains_branch_seperately(ax.transData)

        rY  Lcontains_branch_seperately only supports transforms with 2 output dimensions)r  r  r  r   other_transforms     r   contains_branch_seperatelyz$Transform.contains_branch_seperatelyx  sB     q  C D D $$_581<<r   c                 P   t        |t              st        S | j                         D ]  \  }}||k(  s|c S  |j                         D ]3  \  }}|| k(  s|j                  st        d      |j                         c S  |j                  r| |j                         z   S t        d      )a  
        Compose *self* with the inverse of *other*, cancelling identical terms
        if any::

            # In general:
            A - B == A + B.inverted()
            # (but see note regarding frozen transforms below).

            # If A "ends with" B (i.e. A == A' + B for some A') we can cancel
            # out B:
            (A' + B) - B == A'

            # Likewise, if B "starts with" A (B = A + B'), we can cancel out A:
            A - (A + B') == B'.inverted() == B'^-1

        Cancellation (rather than naively returning ``A + B.inverted()``) is
        important for multiple reasons:

        - It avoids floating-point inaccuracies when computing the inverse of
          B: ``B - B`` is guaranteed to cancel out exactly (resulting in the
          identity transform), whereas ``B + B.inverted()`` may differ by a
          small epsilon.
        - ``B.inverted()`` always returns a frozen transform: if one computes
          ``A + B + B.inverted()`` and later mutates ``B``, then
          ``B.inverted()`` won't be updated and the last two terms won't cancel
          out anymore; on the other hand, ``A + B - B`` will always be equal to
          ``A`` even if ``B`` is mutated.
        zQThe shortcut cannot be computed since 'other' includes a non-invertible componentzpIt is not possible to compute transA - transB since transB cannot be inverted and there is no shortcut possible.)r   r  r  r   r  r  r  )r   rX   	remainderr  s       r   __sub__zTransform.__sub__  s    < %+!!#'#F#F#H 	!Ix5   	! $)#G#G#I 	,Ix4 ,,$>? ? !))++	, %..*** 2 3 3r   c                 >    | j                         j                         S )z9Array interface to get at this Transform's affine matrix.
get_affine
get_matrixr   s      r   r   zTransform.__array__       ++--r   c                    t        j                  |      }|j                  }|j                  d| j                  f      }| j                  | j                  |            }|dk(  r&t         j                  j                  |      rJ |d   S |dk(  r|j                  d      S |dk(  r|S t        dj                  | j                              )a  
        Apply this transformation on the given array of *values*.

        Parameters
        ----------
        values : array-like
            The input values as an array of length :attr:`input_dims` or
            shape (N, :attr:`input_dims`).

        Returns
        -------
        array
            The output values as an array of length :attr:`output_dims` or
            shape (N, :attr:`output_dims`), depending on the input.
        r  r   r   r   rY  z5Input values must have shape (N, {dims}) or ({dims},))dims)r   
asanyarrayndimrn  r  transform_affinetransform_non_affiner   	is_maskedr  rq  )r   rh   r  ress       r   r   zTransform.transform  s    $ v&{{T__ 56 ##D$=$=f$EF 19uus+++t919;;r?"QYJCVV)+ 	+r   c                 @    | j                         j                  |      S )a  
        Apply only the affine part of this transformation on the
        given array of values.

        ``transform(values)`` is always equivalent to
        ``transform_affine(transform_non_affine(values))``.

        In non-affine transformations, this is generally a no-op.  In
        affine transformations, this is equivalent to
        ``transform(values)``.

        Parameters
        ----------
        values : array
            The input values as an array of length :attr:`input_dims` or
            shape (N, :attr:`input_dims`).

        Returns
        -------
        array
            The output values as an array of length :attr:`output_dims` or
            shape (N, :attr:`output_dims`), depending on the input.
        r  r   r   rh   s     r   r  zTransform.transform_affine  s    0  **622r   c                     |S )a  
        Apply only the non-affine part of this transformation.

        ``transform(values)`` is always equivalent to
        ``transform_affine(transform_non_affine(values))``.

        In non-affine transformations, this is generally equivalent to
        ``transform(values)``.  In affine transformations, this is
        always a no-op.

        Parameters
        ----------
        values : array
            The input values as an array of length :attr:`input_dims` or
            shape (N, :attr:`input_dims`).

        Returns
        -------
        array
            The output values as an array of length :attr:`output_dims` or
            shape (N, :attr:`output_dims`), depending on the input.
        r6   r  s     r   r  zTransform.transform_non_affine  s	    . r   c                 R    t        | j                  |j                                     S )z
        Transform the given bounding box.

        For smarter transforms including caching (a common requirement in
        Matplotlib), see `TransformedBbox`.
        )r   r   r   )r   rJ  s     r   transform_bboxzTransform.transform_bbox  s     DNN4??#4566r   c                     t               S )z&Get the affine part of this transform.r  rC   s    r   r  zTransform.get_affine!  s     ""r   c                 >    | j                         j                         S )z5Get the matrix for the affine part of this transform.r  rC   s    r   r  zTransform.get_matrix%  r  r   c                 j    t        |      | j                  k7  rt        d      | j                  |      S )a  
        Return a transformed point.

        This function is only kept for backcompatibility; the more general
        `.transform` method is capable of transforming both a list of points
        and a single point.

        The point is given as a sequence of length :attr:`input_dims`.
        The transformed point is returned as a sequence of length
        :attr:`output_dims`.
        z/The length of 'point' must be 'self.input_dims')r'  r  r  r   )r   points     r   transform_pointzTransform.transform_point)  s/     u:(NOO~~e$$r   c                 B    | j                  | j                  |            S )z
        Apply the transform to `.Path` *path*, returning a new `.Path`.

        In some cases, this transform may insert curves into the path
        that began as line segments.
        )transform_path_affinetransform_path_non_affiner   rz  s     r   transform_pathzTransform.transform_path9  s      ))$*H*H*NOOr   c                 @    | j                         j                  |      S )z
        Apply the affine part of this transform to `.Path` *path*, returning a
        new `.Path`.

        ``transform_path(path)`` is equivalent to
        ``transform_path_affine(transform_path_non_affine(values))``.
        )r  r'  r)  s     r   r'  zTransform.transform_path_affineB  s      66t<<r   c                 z    | j                  |j                        }t        j                  ||j                  |      S )z
        Apply the non-affine part of this transform to `.Path` *path*,
        returning a new `.Path`.

        ``transform_path(path)`` is equivalent to
        ``transform_path_affine(transform_path_non_affine(values))``.
        )r  r+  r	   _fast_from_codes_and_vertscodes)r   rz  r   s      r   r(  z#Transform.transform_path_non_affineL  s1     %%dmm4..q$**dCCr   c                    | j                   dk7  s| j                  dk7  rt        d      t        j                  |      }t        j                  |      }t        j                  d|       t        j                  d|       t        |      t        |      k7  rt        d      |st        j                  |      }||t        j                  t        j                  |      t        j                  |      g      z  z   }| j                  |      }| j                  |      }||z
  }t        j                  |ddd	f   |ddd
f         }	|st        j                  |	      }	|	S )a  
        Transform a set of angles anchored at specific locations.

        Parameters
        ----------
        angles : (N,) array-like
            The angles to transform.
        pts : (N, 2) array-like
            The points where the angles are anchored.
        radians : bool, default: False
            Whether *angles* are radians or degrees.
        pushoff : float
            For each point in *pts* and angle in *angles*, the transformed
            angle is computed by transforming a segment of length *pushoff*
            starting at that point and making that angle relative to the
            horizontal axis, and measuring the angle between the horizontal
            axis and the transformed segment.

        Returns
        -------
        (N,) array
        rY  zOnly defined in 2D)NrY  )r   r   )anglesz'There must be as many 'angles' as 'pts'Nr   r   )r  r  r   r   r   r   check_shaper'  r  deg2radr  cossinr   arctan2rad2deg)
r   r0  r   rH  pushoffpts2tptstpts2dr6  s
             r   transform_angleszTransform.transform_anglesW  s'   0 ??a4#3#3q#8%&:;;F#jjo,0v;#c("FGGZZ'FWrv02v0@  A A A ~~c"t$DLJJqAw!Q$(

1Ar   c                     t               )a5  
        Return the corresponding inverse transformation.

        It holds ``x == self.inverted().transform(self.transform(x))``.

        The return value of this method should be treated as
        temporary.  An update to *self* does not cause a corresponding
        update to its inverted copy.
        r   rC   s    r   r  zTransform.inverted  s     "##r   )Fgh㈵>)r&   rq   rr   rs   r  r  r  r  r  r  r   rU  r  r  r
  r  r   r   r  r  r   r  r  r%  r*  r'  r(  r<  r  r6   r   r   r  r    s    : J
 K
 LJKG# 	 
(  &=$03d.#+J3427#.% P=	D/b
$r   r  c                        e Zd ZdZdZ fdZd Z ed      Zd Z	d Z
 ed       Z ed	       Z ed
       Z ed       Z ed       Z xZS )TransformWrappera  
    A helper class that holds a single child transform and acts
    equivalently to it.

    This is useful if a node of the transform tree must be replaced at
    run time with a transform of a different type.  This class allows
    that replacement to correctly trigger invalidation.

    `TransformWrapper` instances must have the same input and output dimensions
    during their entire lifetime, so the child transform may only be replaced
    with another child transform of the same dimensions.
    Tc                 z    t        j                  t        |       t        |           | j                  |       y)zn
        *child*: A `Transform` instance.  This child may later
        be replaced with :meth:`set`.
        )rn   N)r   r  r  rT   rA   r  )r   rn   r[   s     r   rA   zTransformWrapper.__init__  s+    
 	iu5r   c                 8    | j                   j                  |      S r   )_child__eq__r  s     r   rC  zTransformWrapper.__eq__  s    {{!!%((r   rB  c                 6    | j                   j                         S r   )rB  rp   rC   s    r   rp   zTransformWrapper.frozen  s    {{!!##r   c                    t        | d      r| j                          |j                  |j                  f}| j                  j                  | j                  j                  f}||k7  rt        d| d|       | j                  j                  j                  t        |       d       || _        | j                  |       |j                  | _
        |j                  | _        |j                  | _        |j                  | _        |j                  | _        |j                  | _        |j                   | _        |j"                  | _        |j$                  | _        d| _        | j                          d| _        y)z
        Replace the current child of this transform with another one.

        The new child must have the same number of input and output
        dimensions as the current child.
        rB  z+The input and output dims of the new child z% do not match those of current child Nr   )r  rd   r  r  rB  r  r<   rM   rV   rW   r   r  r  r*  r'  r(  r  r  r  r>   )r   rn   new_dimsold_dimss       r   r  zTransformWrapper.set  s@    4"OO((%*;*;<H..0G0GHH8# A( L;;C*FG G KK  $$RXt4%  % 6 6$)$>$>!#22%*%@%@").)H)H&****
 r   c                 .    | j                   j                  S r   )rB  r  rC   s    r   r+   zTransformWrapper.<lambda>  s    t{{'='= r   c                 .    | j                   j                  S r   )rB  r  rC   s    r   r+   zTransformWrapper.<lambda>      (?(? r   c                 .    | j                   j                  S r   )rB  rb   rC   s    r   r+   zTransformWrapper.<lambda>  s    dkk&;&; r   c                 .    | j                   j                  S r   )rB  r  rC   s    r   r+   zTransformWrapper.<lambda>  s    )A)A r   c                 .    | j                   j                  S r   )rB  r  rC   s    r   r+   zTransformWrapper.<lambda>  rJ  r   )r&   rq   rr   rs   rf   rA   rC  r/   rD   rp   r  rU  r  r  rb   r  r  rz   r{   s   @r   r?  r?    si     L) x(G$#J =>J?@K;<IABL?@Kr   r?  c                   \     e Zd ZdZdZ fdZd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Z xZS )
AffineBasezS
    The base class of all affine transformations of any number of dimensions.
    Tc                 2    t        |   |i | d | _        y r   )rT   rA   	_inverted)r   r)   r*   r[   s      r   rA   zAffineBase.__init__  s    $)&)r   c                 "    | j                         S r   r  r   s      r   r   zAffineBase.__array__  s      r   c                     t        |dd      r;t        |d      r/| j                         |j                         k(  j                         S t        S )Nrb   Fr  )r   r  r  r)  r  r  s     r   rC  zAffineBase.__eq__  sA    5+u-'%2NOO%)9)9);;@@BBr   c                 $    | j                  |      S r   )r  r  s     r   r   zAffineBase.transform  s    $$V,,r   c                     t        d      )Nz.Affine subclasses should override this method.r   r  s     r   r  zAffineBase.transform_affine  s    ! #, - 	-r   c                     |S r   r6   r  s     r   r  zAffineBase.transform_non_affine  s    r   c                 $    | j                  |      S r   )r'  r)  s     r   r*  zAffineBase.transform_path  s    ))$//r   c                 v    t        | j                  |j                        |j                  |j                        S r   )r	   r  r+  r.  _interpolation_stepsr)  s     r   r'  z AffineBase.transform_path_affine  s/    D))$--8JJ 9 9; 	;r   c                     |S r   r6   r)  s     r   r(  z$AffineBase.transform_path_non_affine      r   c                     | S r   r6   rC   s    r   r  zAffineBase.get_affine  r\  r   )r&   rq   rr   rs   rb   rA   r   rC  r   r  r  r*  r'  r(  r  rz   r{   s   @r   rO  rO    sA     I!
--
0;
r   rO  c                   N    e Zd ZdZdZdZd Zed        Zd Z	d Z
ere
Zd Z
d Zy	)
Affine2DBasea  
    The base class of all 2D affine transformations.

    2D affine transformations are performed using a 3x3 numpy array::

        a c e
        b d f
        0 0 1

    This class provides the read-only interface.  For a mutable 2D
    affine transformation, use `Affine2D`.

    Subclasses of this class will generally only need to override a
    constructor and `~.Transform.get_matrix` that generates a custom 3x3 matrix.
    rY  c                 P    t        | j                         j                               S r   )rD  r  rS   rC   s    r   rp   zAffine2DBase.frozen(  s    )..011r   c                 N    | j                         }|d   |d   cxk(  xr dk(  S c S )Nr   r   r  rS  r   mtxs     r   r  zAffine2DBase.is_separable,  s,    oo4yCI,,,,,r   c                 r    | j                         }t        |dd j                  dd      j                        S )zU
        Return the values of the matrix as an ``(a, b, c, d, e, f)`` tuple.
        NrY  r   r   )r  tupleswapaxesflatrb  s     r   	to_valueszAffine2DBase.to_values1  s4     ooS!W%%a+0011r   c                 *   | j                         }t        |t        j                  j                        rTt        |j                  |      }t        j                  j	                  |t        j                  j                  |            S t        ||      S )Nr  )r  r   r   r   r   r   r  getmask)r   rh   rc  tpointss       r   r  zAffine2DBase.transform_affine8  sf    oofbee//0&v{{C8G55$$W255==3H$II,,r   c                     t        |t        j                        s"t        j                  dt        |       d       | j                  |      S )NzA non-numpy array of type zE was passed in for transformation, which results in poor performance.)r   r   ndarrayr   r   r%   _transform_affiner  s     r   r  zAffine2DBase.transform_affineB  sK    
 fbjj1""0f ?M NO ))&11r   c                     | j                   | j                  rO| j                         }d }| j                  rd| j                  z  }t	        t        |      |      | _         d| _        | j                   S )Nz(%s)-1)r@   r   )rQ  r>   r  r?   rD  r   )r   rc  r@   s      r   r  zAffine2DBase.invertedM  s_    >>!T]]//#C!N##!)D,@,@!@%c#h~NDNDM~~r   N)r&   rq   rr   rs   r  r  rp   rU  r  rh  r  ry   rn  r  r6   r   r   r_  r_    sK     JK2 - -2- ,		2	r   r_  c                        e Zd ZdZd fd	Z ed      Zd Zed        Z	d Z
d Zd Zd	 Zd
 Zd Zd Zd Zd ZddZd Zd Z xZS )rD  z-
    A mutable 2D affine transformation.
    c                     t        |   di | |t        j                  }|j	                         | _        d| _        y)z
        Initialize an Affine transform from a 3x3 numpy float array::

          a c e
          b d f
          0 0 1

        If *matrix* is None, initialize with the identity transform.
        Nr   r6   )rT   rA   r  _mtxrS   r>   )r   matrixr*   r[   s      r   rA   zAffine2D.__init__^  s9     	"6">&++FKKM	r   rr  c                 f   | j                   t        j                  t        j                  | j                               k7  j                         r| j	                         S | j                   d   | j                   d   k7  r#d| j                   d    d| j                   d    dS d| j                   d    dS )Nr   r   zAffine2D().scale(z, r$   )rr  r   diagr   	_base_strrC   s    r   rD   zAffine2D.__str__q  s    II);!<<AAC   	= 99T?diio5 )4(9DIIdO;LAN	= )4(9;		=r   c                 x    t        t        j                  | |||||dddg	t              j	                  d            S )z
        Create a new Affine2D instance from the given values::

          a c e
          b d f
          0 0 1

        .
        r  r   )r2   r2   )rD  r   r   rZ  rn  )r6  r  r  r;  efs         r   from_valueszAffine2D.from_valuesx  s?     HHaAq!QS#6>FFvNP 	Pr   c                 N    | j                   rd| _        d| _         | j                  S )z
        Get the underlying transformation matrix as a 3x3 array::

          a c e
          b d f
          0 0 1

        .
        Nr   )r>   rQ  rr  rC   s    r   r  zAffine2D.get_matrix  s#     ==!DNDMyyr   c                 2    || _         | j                          y)z
        Set the underlying transformation matrix from a 3x3 array::

          a c e
          b d f
          0 0 1

        .
        Nrr  rd   rb  s     r   
set_matrixzAffine2D.set_matrix  s     	r   c                     t        j                  t        |       |j                         | _        | j                          y)zh
        Set this transformation from the frozen copy of another
        `Affine2DBase` object.
        )rX   N)r   r  r_  r  rr  rd   r  s     r   r  zAffine2D.set  s.    
 	l%8$$&	r   c                 l    t         j                  j                         | _        | j                          | S )zH
        Reset the underlying matrix to the identity transform.
        )r  rr  rS   rd   rC   s    r   clearzAffine2D.clear  s)    
 &**//1	r   c                 r   t        j                  |      }t        j                  |      }| j                  }|j	                         \  \  }}}\  }}	}
}||z  ||z  z
  |d<   ||z  ||	z  z
  |d<   ||z  ||
z  z
  |d<   ||z  ||z  z   |d<   ||z  ||	z  z   |d<   ||z  ||
z  z   |d<   | j                          | S )z
        Add a rotation (in radians) to this transform in place.

        Returns *self*, so this method can easily be chained with more
        calls to :meth:`rotate`, :meth:`rotate_deg`, :meth:`translate`
        and :meth:`scale`.
        r   r   r   rY  r   r   r   rY  )mathr3  r4  rr  tolistrd   )r   thetar6  r  rc  xxr  r   yxyyr   rL   s               r   rE  zAffine2D.rotate  s     HHUOHHUOii(+

%Rlr2rAFQVOD	FQVOD	FQVOD	FQVOD	FQVOD	FQVOD	r   c                 J    | j                  t        j                  |            S )z
        Add a rotation (in degrees) to this transform in place.

        Returns *self*, so this method can easily be chained with more
        calls to :meth:`rotate`, :meth:`rotate_deg`, :meth:`translate`
        and :meth:`scale`.
        )rE  r  rH  )r   degreess     r   
rotate_degzAffine2D.rotate_deg  s     {{4<<011r   c                 h    | j                  | |       j                  |      j                  ||      S )z
        Add a rotation (in radians) around the point (x, y) in place.

        Returns *self*, so this method can easily be chained with more
        calls to :meth:`rotate`, :meth:`rotate_deg`, :meth:`translate`
        and :meth:`scale`.
        )	translaterE  )r   r   r   r  s       r   rotate_aroundzAffine2D.rotate_around  s1     ~~qb1"%,,U3==aCCr   c                     t        |      t        |      }}| j                  | |       j                  |      j                  ||      S )z
        Add a rotation (in degrees) around the point (x, y) in place.

        Returns *self*, so this method can easily be chained with more
        calls to :meth:`rotate`, :meth:`rotate_deg`, :meth:`translate`
        and :meth:`scale`.
        )rZ  r  r  )r   r   r   r  s       r   rotate_deg_aroundzAffine2D.rotate_deg_around  sB     Qxq1~~qb1"%009CCAqIIr   c                     | j                   dxx   |z  cc<   | j                   dxx   |z  cc<   | j                          | S )z
        Add a translation in place.

        Returns *self*, so this method can easily be chained with more
        calls to :meth:`rotate`, :meth:`rotate_deg`, :meth:`translate`
        and :meth:`scale`.
        r  r  r}  r=  s      r   r  zAffine2D.translate  s7     			$2		$2r   c                 B   ||}| j                   dxx   |z  cc<   | j                   dxx   |z  cc<   | j                   dxx   |z  cc<   | j                   dxx   |z  cc<   | j                   dxx   |z  cc<   | j                   dxx   |z  cc<   | j                          | S )a2  
        Add a scale in place.

        If *sy* is None, the same scale is applied in both the *x*- and
        *y*-directions.

        Returns *self*, so this method can easily be chained with more
        calls to :meth:`rotate`, :meth:`rotate_deg`, :meth:`translate`
        and :meth:`scale`.
        r   r   r  r   r   r  r}  )r   sxsys      r   scalezAffine2D.scale  s     :B		$2		$2		$2		$2		$2		$2r   c                    t        j                  |      }t        j                  |      }| j                  }|j                         \  \  }}}\  }	}
}}|dxx   ||	z  z  cc<   |dxx   ||
z  z  cc<   |dxx   ||z  z  cc<   |dxx   ||z  z  cc<   |dxx   ||z  z  cc<   |dxx   ||z  z  cc<   | j	                          | S )aC  
        Add a skew in place.

        *xShear* and *yShear* are the shear angles along the *x*- and
        *y*-axes, respectively, in radians.

        Returns *self*, so this method can easily be chained with more
        calls to :meth:`rotate`, :meth:`rotate_deg`, :meth:`translate`
        and :meth:`scale`.
        r   r   r  r   r   r  )r  tanrr  r  rd   )r   xShearyShearrxryrc  r  r  r   r  r  r   rL   s                r   skewzAffine2D.skew  s     XXfXXfii(+

%Rlr2rAD	R"W	D	R"W	D	R"W	D	R"W	D	R"W	D	R"W	r   c                 r    | j                  t        j                  |      t        j                  |            S )aC  
        Add a skew in place.

        *xShear* and *yShear* are the shear angles along the *x*- and
        *y*-axes, respectively, in degrees.

        Returns *self*, so this method can easily be chained with more
        calls to :meth:`rotate`, :meth:`rotate_deg`, :meth:`translate`
        and :meth:`scale`.
        )r  r  rH  )r   r  r  s      r   skew_degzAffine2D.skew_deg)  s'     yyf-t||F/CDDr   r   )r&   rq   rr   rs   rA   r/   rv  rD   rT  rz  r  r~  r  r  rE  r  r  r  r  r  r  r  rz   r{   s   @r   rD  rD  Y  ss    " !(I= P P.2D
J.4Er   rD  c                   ~    e Zd ZdZ ej
                  d      Zd Z e       Z	d Z
d Zd Zd Zd Zd	 Zd
 Zd Zd Zy)r  zY
    A special class that does one thing, the identity transform, in a
    fast way.
    r2   c                     | S r   r6   rC   s    r   rp   zIdentityTransform.frozen>  r\  r   c                     | j                   S r   )rr  rC   s    r   r  zIdentityTransform.get_matrixD  s    yyr   c                 ,    t        j                  |      S r   r   r  r  s     r   r   zIdentityTransform.transformH      }}V$$r   c                 ,    t        j                  |      S r   r  r  s     r   r  z"IdentityTransform.transform_affineL  r  r   c                 ,    t        j                  |      S r   r  r  s     r   r  z&IdentityTransform.transform_non_affineP  r  r   c                     |S r   r6   r)  s     r   r*  z IdentityTransform.transform_pathT  r\  r   c                     |S r   r6   r)  s     r   r'  z'IdentityTransform.transform_path_affineX  r\  r   c                     |S r   r6   r)  s     r   r(  z+IdentityTransform.transform_path_non_affine\  r\  r   c                     | S r   r6   rC   s    r   r  zIdentityTransform.get_affine`  r\  r   c                     | S r   r6   rC   s    r   r  zIdentityTransform.invertedd  r\  r   N)r&   rq   rr   rs   r   identityrr  rp   r/   rD   r  r   r  r  r*  r'  r(  r  r  r6   r   r   r  r  7  sT     2;;q>D  G%%%r   r  c                   .    e Zd ZdZd Zd Z edd      Zy)_BlendedMixinzCCommon methods for `BlendedGenericTransform` and `BlendedAffine2D`.c                     t        |t        t        f      r4| j                  |j                  k(  xr | j                  |j                  k(  S | j                  | j                  k(  r| j                  |k(  S t
        S r   )r   BlendedAffine2DBlendedGenericTransform_x_yr  r  s     r   rC  z_BlendedMixin.__eq__l  s\    eo/FGHGGuxx'Bdgg.ABWW77e##!!r   c                 n    | j                   j                  |      | j                  j                  |      fS r   )r  r  r  )r   r   s     r   r
  z(_BlendedMixin.contains_branch_seperatelyt  s0    ''	2''	24 	4r   r  r  N)r&   rq   rr   rs   rC  r
  r/   rD   r6   r   r   r  r  i  s    M"4 tT*Gr   r  c                   x    e Zd ZdZdZdZdZdZd Ze	d        Z
d Z e	d       Z e	d       Zd	 Zd
 Zd Zd Zy)r  z
    A "blended" transform uses one transform for the *x*-direction, and
    another transform for the *y*-direction.

    This "generic" version can handle any given child transform in the
    *x*- and *y*-directions.
    rY  Tc                 ~    t        j                  | fi | || _        || _        | j	                  ||       d| _        y)ak  
        Create a new "blended" transform using *x_transform* to transform the
        *x*-axis and *y_transform* to transform the *y*-axis.

        You will generally not call this constructor directly but use the
        `blended_transform_factory` function instead, which can determine
        automatically which kind of blended transform to create.
        N)r  rA   r  r  rW   _affine)r   x_transformy_transformr*   s       r   rA   z BlendedGenericTransform.__init__  s<     	4*6*+{3r   c                 j    t        | j                  j                  | j                  j                        S r   )r   r  r  r  rC   s    r   r  zBlendedGenericTransform.depth  s    477==$''--00r   c                      yr5   r6   r  s     r   r  z'BlendedGenericTransform.contains_branch  s     r   c                 ^    | j                   j                  xr | j                  j                  S r   )r  rb   r  rC   s    r   r+   z BlendedGenericTransform.<lambda>      dgg&7&7&MDGG<M<M r   c                 ^    | j                   j                  xr | j                  j                  S r   )r  r  r  rC   s    r   r+   z BlendedGenericTransform.<lambda>      TWW((@TWW-@-@ r   c                 z    t        | j                  j                         | j                  j                               S r   )blended_transform_factoryr  rp   r  rC   s    r   rp   zBlendedGenericTransform.frozen  s%    ()9477>>;KLLr   c                 T   | j                   j                  r| j                  j                  r|S | j                   }| j                  }||k(  r |j                  dk(  r|j	                  |      S |j                  dk(  r|j	                  |      d d ddf   }n4|j	                  |d d df         }|j                  t        |      df      }|j                  dk(  r|j	                  |      d d dd f   }n4|j	                  |d d df         }|j                  t        |      df      }t        |t        j                  j                        s$t        |t        j                  j                        r"t        j                  j                  ||fd      S t        j                  ||fd      S )NrY  r   r   )r  rb   r  r  r  rn  r'  r   r   r   r   concatenate)r   rh   r   r   x_pointsy_pointss         r   r  z,BlendedGenericTransform.transform_non_affine  sa   77!2!2MGGGG6alla'))&11<<1--f5a1f=H--fQTl;H''X(:;H<<1--f5ae<H--fQTl;H''X(:;Hx!2!238RUU%6%6755$$h%91==>>8X"6::r   c                 z    t        | j                  j                         | j                  j                               S r   )r  r  r  r  rC   s    r   r  z BlendedGenericTransform.inverted  s)    &tww'7'7'9477;K;K;MNNr   c                    | j                   s| j                  | j                  | j                  k(  r | j                  j	                         | _        n| j                  j	                         j                         }| j                  j	                         j                         }t        j                  |d   |d   g dg      }t        |      | _        d| _         | j                  S Nr   r   r  r  r   )	r>   r  r  r  r  r  r   r   rD  )r   x_mtxy_mtxrc  s       r   r  z"BlendedGenericTransform.get_affine  s    ==DLL0ww$''!#ww113**,779**,779 hha%(ODE'}DM||r   N)r&   rq   rr   rs   r  r  r  rf   rA   rU  r  r  rb   r  rp   r  r  r  r6   r   r   r  r  {  sl     JKLL 1 1
 MNI@BKM;8Or   r  c                        e Zd ZdZdZd Zd Zy)r  z
    A "blended" transform uses one transform for the *x*-direction, and
    another transform for the *y*-direction.

    This version is an optimization for the case where both child
    transforms are of type `Affine2DBase`.
    Tc                 6   |j                   xr |j                   }|j                  xr |j                  }|xr |}|st        d      t        j                  | fi | || _        || _        | j                  ||       t        j	                  |        d| _	        y)a  
        Create a new "blended" transform using *x_transform* to transform the
        *x*-axis and *y_transform* to transform the *y*-axis.

        Both *x_transform* and *y_transform* must be 2D affine transforms.

        You will generally not call this constructor directly but use the
        `blended_transform_factory` function instead, which can determine
        automatically which kind of blended transform to create.
        zABoth *x_transform* and *y_transform* must be 2D affine transformsN)
rb   r  r  r  rA   r  r  rW   r_  rr  )r   r  r  r*   rb   r  
is_corrects          r   rA   zBlendedAffine2D.__init__  s      ))Ck.C.C	"//LK4L4L/<
 1 2 2 	4*6*+{3d#	r   c                 r   | j                   r| j                  | j                  k(  r | j                  j                         | _        nY| j                  j                         }| j                  j                         }t        j                  |d   |d   g dg      | _        d | _        d| _         | j                  S r  )r>   r  r  r  rr  r   r   rQ  )r   r  r  s      r   r  zBlendedAffine2D.get_matrix  s    ==ww$''! GG..0	**,**, HHeAha/%JK	!DNDMyyr   N)r&   rq   rr   rs   r  rA   r  r6   r   r   r  r    s     L4r   r  c                 r    t        | t              rt        |t              rt        | |      S t        | |      S )z
    Create a new "blended" transform using *x_transform* to transform
    the *x*-axis and *y_transform* to transform the *y*-axis.

    A faster version of the blended transform is returned for the case
    where both child transforms are affine.
    )r   r_  r  r  )r  r  s     r   r  r  	  s2     	;-{L1{K88";<<r   c                        e Zd ZdZdZ fdZd Z fdZd Zd Z	d Z
 ed	       Z ed
       Z ed       Z ed       Z edd      Zd Zd Zd Zd Zd Z xZS )CompositeGenericTransformz
    A composite transform formed by applying transform *a* then
    transform *b*.

    This "generic" version can handle any two arbitrary
    transformations.
    Tc                     |j                   |j                  k7  rt        d      |j                  | _        |j                   | _         t        |   di | || _        || _        | j                  ||       y)a@  
        Create a new composite transform that is the result of
        applying transform *a* then transform *b*.

        You will generally not call this constructor directly but write ``a +
        b`` instead, which will automatically choose the best kind of composite
        transform instance to create.
        HThe output dimension of 'a' must be equal to the input dimensions of 'b'Nr6   )r  r  r  rT   rA   _a_brW   r   r6  r  r*   r[   s       r   rA   z"CompositeGenericTransform.__init__%	  sl     ==ALL( ; < <,,=="6"!Qr   c                     d| _         t        | j                  j                         | j                  j                               }t        |t              s|j                         S |S r  )r>   r  r  rp   r  r   r  )r   rp   s     r   rp   z CompositeGenericTransform.frozen9	  sJ    ,GGNNdggnn.0&";<==?"r   c                     || j                   u r&| j                  j                  st        j                  }t
        |   ||       y r   )r  r  rb   r  r=   rT   ra   )r   r_   r`   r[   s      r   ra   z.CompositeGenericTransform._invalidate_internalB	  s8     '0A0A++E$U,=>r   c                     t        |t        t        f      r:| |u xs4 | j                  |j                  k(  xr | j                  |j                  k(  S yr5   )r   r  CompositeAffine2Dr  r  r  s     r   rC  z CompositeGenericTransform.__eq__I	  sM    e79JKL5= >TWW%8 &=)-EHH)<> r   c              #      K   | j                   j                         D ]  \  }}||| j                  z   f  | j                  j                         D ]  \  }}| j                   |z   |f  y wr   r  r   r  r   leftrights      r   r   z8CompositeGenericTransform._iter_break_from_left_to_rightP	  l     77AAC 	(KD%''	(77AAC 	(KD%''D.%''	(   A,A.c                 x    | j                   dk7  rt        d      | |k(  ry| j                  j                  |      S )NrY  r  )TT)r  r  r  r
  r  s     r   r
  z4CompositeGenericTransform.contains_branch_seperatelyV	  sE    q  C D D?"ww11/BBr   c                 \    | j                   j                  | j                  j                  z   S r   r  r  r  rC   s    r   r+   z"CompositeGenericTransform.<lambda>_	  s    $''--$''--"? r   c                 ^    | j                   j                  xr | j                  j                  S r   )r  rb   r  rC   s    r   r+   z"CompositeGenericTransform.<lambda>`	  r  r   c                 ^    | j                   j                  xr | j                  j                  S r   )r  r  r  rC   s    r   r+   z"CompositeGenericTransform.<lambda>b	  s    TWW))Bdgg.B.B r   c                 ^    | j                   j                  xr | j                  j                  S r   )r  r  r  rC   s    r   r+   z"CompositeGenericTransform.<lambda>d	  r  r   r  r  c                 @    | j                         j                  |      S r   r  r  s     r   r  z*CompositeGenericTransform.transform_affineh	  s     **622r   c                 T   | j                   j                  r| j                  j                  r|S | j                   j                  s1| j                  j                  r| j                   j                  |      S | j                  j                  | j                   j	                  |            S r   )r  rb   r  r  r   r  s     r   r  z.CompositeGenericTransform.transform_non_affinel	  sr    77!2!2M""tww'8'877//7777//0A0A&0IJJr   c                 T   | j                   j                  r| j                  j                  r|S | j                   j                  s1| j                  j                  r| j                   j                  |      S | j                  j                  | j                   j	                  |            S r   )r  rb   r  r(  r*  r)  s     r   r(  z3CompositeGenericTransform.transform_path_non_affineu	  sy    77!2!2K""tww'8'87744T::7744$(GG$:$:4$@B Br   c                 8   | j                   j                  s| j                   j                         S t        t	        j
                  | j                   j                         j                         | j                  j                         j                                     S r   )r  rb   r  rD  r   dotr  r  rC   s    r   r  z$CompositeGenericTransform.get_affine	  sn    ww  77%%''BFF477#5#5#7#B#B#D#'77#5#5#7#B#B#DF G Gr   c                 z    t        | j                  j                         | j                  j                               S r   )r  r  r  r  rC   s    r   r  z"CompositeGenericTransform.inverted	  s.    (GG 0 0 24 	4r   )r&   rq   rr   rs   rf   rA   rp   ra   rC  r   r
  rU  r  rb   r  r  r/   rD   r  r  r(  r  r  rz   r{   s   @r   r  r  	  s     L (?(C ?@EMNIBDL@BK tT*G3KBG4r   r  c                   P     e Zd ZdZ fdZed        Zd Z edd      Z	d Z
 xZS )r  z
    A composite transform formed by applying transform *a* then transform *b*.

    This version is an optimization that handles the case where both *a*
    and *b* are 2D affines.
    c                 D   |j                   r|j                   st        d      |j                  |j                  k7  rt        d      |j                  | _        |j                  | _        t	        |   di | || _        || _        | j                  ||       d| _	        y)aJ  
        Create a new composite transform that is the result of
        applying `Affine2DBase` *a* then `Affine2DBase` *b*.

        You will generally not call this constructor directly but write ``a +
        b`` instead, which will automatically choose the best kind of composite
        transform instance to create.
        z%'a' and 'b' must be affine transformsr  Nr6   )
rb   r  r  r  rT   rA   r  r  rW   rr  r  s       r   rA   zCompositeAffine2D.__init__	  s     {{!++DEE==ALL( ; < <,,=="6"!Q	r   c                 \    | j                   j                  | j                  j                  z   S r   r  rC   s    r   r  zCompositeAffine2D.depth	  s    ww}}tww}},,r   c              #      K   | j                   j                         D ]  \  }}||| j                  z   f  | j                  j                         D ]  \  }}| j                   |z   |f  y wr   r  r  s      r   r   z0CompositeAffine2D._iter_break_from_left_to_right	  r  r  r  r  c                     | j                   rYt        j                  | j                  j	                         | j
                  j	                               | _        d | _        d| _         | j                  S r  )r>   r   r  r  r  r  rr  rQ  rC   s    r   r  zCompositeAffine2D.get_matrix	  sS    ==""$""$&DI "DNDMyyr   )r&   rq   rr   rs   rA   rU  r  r   r/   rD   r  rz   r{   s   @r   r  r  	  s9    . - -( tT*Gr   r  c                     t        | t              r|S t        |t              r| S t        | t              rt        |t              rt        | |      S t	        | |      S )av  
    Create a new composite transform that is the result of applying
    transform a then transform b.

    Shortcut versions of the blended transform are provided for the
    case where both child transforms are affine, or one or the other
    is the identity transform.

    Composite transforms may also be created using the '+' operator,
    e.g.::

      c = a + b
    )r   r  rD  r  r  )r6  r  s     r   r  r  	  sQ    $ !&'	A(	)	Ax	 Z8%< A&&$Q**r   c                   >     e Zd ZdZdZ fdZ edd      Zd Z xZ	S )BboxTransformzP
    `BboxTransform` linearly transforms points from one `Bbox` to another.
    Tc                     t        j                  t        ||       t        |   di | || _        || _        | j                  ||       d| _        d| _	        y)zp
        Create a new `BboxTransform` that linearly transforms
        points from *boxin* to *boxout*.
        )boxinboxoutNr6   )
r   r  r}   rT   rA   _boxin_boxoutrW   rr  rQ  )r   r  r  r*   r[   s       r   rA   zBboxTransform.__init__	  sS    
 	heFC"6"%(	r   r  r  c                 t   | j                   r| j                  j                  \  }}}}| j                  j                  \  }}}}||z  }	||z  }
t        r|	dk(  s|
dk(  rt        d      t        j                  |	d| |	z  |z   gd|
| |
z  |z   gg dgt              | _	        d | _
        d| _         | j                  S )Nr   z/Transforming from or to a singular bounding boxr  r  )r>   r  r   r  ry   r  r   r   rZ  rr  rQ  )r   inlinbinwinhoutloutboutwouthx_scaley_scales              r   r  zBboxTransform.get_matrix	  s    ==!%!3!3Cc3%)\\%8%8"D$dSjGSjG'Q,'Q, EG G7cT'\$5F"G'*GcT'\$5F"G"G"I "'(DI "DNDMyyr   
r&   rq   rr   rs   r  rA   r/   rD   r  rz   r{   s   @r   r  r  	  s'     L x3Gr   r  c                   <     e Zd ZdZdZ fdZ ed      Zd Z xZ	S )BboxTransformToz
    `BboxTransformTo` is a transformation that linearly transforms points from
    the unit bounding box to a given `Bbox`.
    Tc                     t        j                  t        |       t        |   di | || _        | j                  |       d| _        d| _        y)z
        Create a new `BboxTransformTo` that linearly transforms
        points from the unit bounding box to *boxout*.
        )r  Nr6   )	r   r  r}   rT   rA   r  rW   rr  rQ  )r   r  r*   r[   s      r   rA   zBboxTransformTo.__init__
  sH    
 	hv6"6"&!	r   r  c                    | j                   rn| j                  j                  \  }}}}t        r|dk(  s|dk(  rt	        d      t        j                  |d|gd||gg dgt              | _        d | _	        d| _         | j                  S Nr   z(Transforming to a singular bounding box.r  r  )
r>   r  r   ry   r  r   r   rZ  rr  rQ  )r   r  r  r  r  s        r   r  zBboxTransformTo.get_matrix
  s    ==%)\\%8%8"D$d$!)tqy !KLL4#t"4$'t"4"4"6 "'(DI "DNDMyyr   r	  r{   s   @r   r  r  
  s%    
 L y)Gr   r  r3   c                       e Zd ZdZd Zy)BboxTransformToMaxOnlyz
    `BboxTransformToMaxOnly` is a transformation that linearly transforms points from
    the unit bounding box to a given `Bbox` with a fixed upper left of (0, 0).
    c                 
   | j                   rl| j                  j                  \  }}t        r|dk(  s|dk(  rt	        d      t        j                  |ddgd|dgg dgt              | _        d | _	        d| _         | j                  S r  )
r>   r  r   ry   r  r   r   rZ  rr  rQ  )r   r   r   s      r   r  z!BboxTransformToMaxOnly.get_matrix3
  s    ==))JD$$!)tqy !KLL4#s"3$'s"3"3"5 "'(DI "DNDMyyr   N)r&   rq   rr   rs   r  r6   r   r   r  r  -
  s    r   r  c                   <     e Zd ZdZdZ fdZ ed      Zd Z xZ	S )BboxTransformFromzj
    `BboxTransformFrom` linearly transforms points from a given `Bbox` to the
    unit bounding box.
    Tc                     t        j                  t        |       t        |   di | || _        | j                  |       d | _        d | _        y )N)r  r6   )	r   r  r}   rT   rA   r  rW   rr  rQ  )r   r  r*   r[   s      r   rA   zBboxTransformFrom.__init__I
  sF    he4"6"% 	r   r  c                 2   | j                   r| j                  j                  \  }}}}t        r|dk(  s|dk(  rt	        d      d|z  }d|z  }t        j                  |d| |z  gd|| |z  gg dgt              | _        d | _	        d| _         | j                  S )Nr   z*Transforming from a singular bounding box.r   r  r  )
r>   r  r   ry   r  r   r   rZ  rr  rQ  )r   r  r   r  r  r  r  s          r   r  zBboxTransformFrom.get_matrixT
  s    ==!%!3!3Cc3#(cQh !MNNCiGCiG7cT'\"B'*GcT'\"B"B"D "'(DI "DNDMyyr   r	  r{   s   @r   r  r  B
  s%     L x(Gr   r  c                   8     e Zd ZdZ fdZ ed      Zd Z xZS )ScaledTranslationz|
    A transformation that translates by *xt* and *yt*, after *xt* and *yt*
    have been transformed by *scale_trans*.
    c                     t        |   di | ||f| _        || _        | j	                  |       d | _        d | _        y Nr6   )rT   rA   _t_scale_transrW   rr  rQ  )r   xtytscale_transr*   r[   s        r   rA   zScaledTranslation.__init__j
  sB    "6"r('+&	r   r  c                     | j                   rgt        j                  j                         | _        | j                  j                  | j                        | j                  d ddf<   d| _         d | _        | j                  S )NrY  r   )r>   r  rr  rS   r  r   r  rQ  rC   s    r   r  zScaledTranslation.get_matrixt
  sb    ==)..335DI#00::477CDIIbqb!eDM!DNyyr   )	r&   rq   rr   rs   rA   r/   rD   r  rz   r{   s   @r   r  r  e
  s     t$Gr   r  c                   (     e Zd ZdZ fdZd Z xZS )_ScaledRotationz^
    A transformation that applies rotation by *theta*, after transform by *trans_shift*.
    c                 L    t         |           || _        || _        d | _        y r   )rT   rA   _theta_trans_shiftrr  )r   r  trans_shiftr[   s      r   rA   z_ScaledRotation.__init__
  s$    '	r   c                     | j                   r^| j                  j                  | j                  dgg      d   }|d   }t	               j                  |      }|j                         | _        | j                  S r  )r>   r$  r   r#  rD  rE  r  rr  )r   transformed_coordsadjusted_thetarotations       r   r  z_ScaledRotation.get_matrix
  sh    ==!%!2!2!<!<t{{A>N=O!PQR!S/2Nz((8H ++-DIyyr   )r&   rq   rr   rs   rA   r  rz   r{   s   @r   r!  r!  
  s    r   r!  c                   <     e Zd ZdZdZ fdZ ed      Zd Z xZ	S )AffineDeltaTransformav  
    A transform wrapper for transforming displacements between pairs of points.

    This class is intended to be used to transform displacements ("position
    deltas") between pairs of points (e.g., as the ``offset_transform``
    of `.Collection`\s): given a transform ``t`` such that ``t =
    AffineDeltaTransform(t) + offset``, ``AffineDeltaTransform``
    satisfies ``AffineDeltaTransform(a - b) == AffineDeltaTransform(a) -
    AffineDeltaTransform(b)``.

    This is implemented by forcing the offset components of the transform
    matrix to zero.

    This class is experimental as of 3.3, and the API may change.
    Tc                 T    t        |   di | || _        | j                  |       y r  )rT   rA   _base_transformrW   )r   r   r*   r[   s      r   rA   zAffineDeltaTransform.__init__
  s)    "6"()$r   r-  c                     | j                   r@| j                  j                         j                         | _        d| j                  d ddf<   | j                  S )Nr   rY  r  )r>   r-  r  rS   rr  rC   s    r   r  zAffineDeltaTransform.get_matrix
  sH    ==,,779>>@DI !DIIbqb"fyyr   )
r&   rq   rr   rs   rf   rA   r/   rD   r  rz   r{   s   @r   r+  r+  
  s&      L%
 01Gr   r+  c                   @     e Zd ZdZ fdZd Zd Zd Zd Zd Z	 xZ
S )TransformedPathaa  
    A `TransformedPath` caches a non-affine transformed copy of the
    `~.path.Path`.  This cached copy is automatically updated when the
    non-affine part of the transform changes.

    .. note::

        Paths are considered immutable by this class. Any update to the
        path's vertices/codes will not trigger a transform recomputation.

    c                     t        j                  t        |       t        |           || _        || _        | j                  |       d| _        d| _	        y)zl
        Parameters
        ----------
        path : `~.path.Path`
        transform : `Transform`
        r  N)
r   r  r  rT   rA   _pathr  rW   _transformed_path_transformed_points)r   rz  r   r[   s      r   rA   zTransformedPath.__init__
  sL     	i9=
#)$!%#' r   c                 V   | j                   | j                  k(  s| j                  }| j                  j	                  | j
                        | _        t        j                  | j                  j                  | j
                  j                        d | j
                        | _
        d| _         y r  )r>   r=   r3  r  r(  r2  r	   r-  r  r+  r4  rC   s    r   _revalidatezTransformedPath._revalidate
  s     MMT///))199$**E " //OO889L9LM$**& $ r   c                 Z    | j                          | j                  | j                         fS )a3  
        Return a copy of the child path, with the non-affine part of
        the transform already applied, along with the affine part of
        the path necessary to complete the transformation.  Unlike
        :meth:`get_transformed_path_and_affine`, no interpolation will
        be performed.
        )r6  r4  r  rC   s    r   !get_transformed_points_and_affinez1TransformedPath.get_transformed_points_and_affine
  s(     	''):::r   c                 Z    | j                          | j                  | j                         fS )z
        Return a copy of the child path, with the non-affine part of
        the transform already applied, along with the affine part of
        the path necessary to complete the transformation.
        )r6  r3  r  rC   s    r   get_transformed_path_and_affinez/TransformedPath.get_transformed_path_and_affine
  s(     	%%t'888r   c                 l    | j                          | j                  j                  | j                        S )zD
        Return a fully-transformed copy of the child path.
        )r6  r  r'  r3  rC   s    r   get_fully_transformed_pathz*TransformedPath.get_fully_transformed_path
  s+     	44T5K5KLLr   c                 6    | j                   j                         S r   )r  r  rC   s    r   r  zTransformedPath.get_affine
  s    ))++r   )r&   rq   rr   rs   rA   r6  r8  r:  r<  r  rz   r{   s   @r   r0  r0  
  s'    
(	;9M,r   r0  c                   ,     e Zd ZdZ fdZ fdZ xZS )TransformedPatchPathz
    A `TransformedPatchPath` caches a non-affine transformed copy of the
    `~.patches.Patch`. This cached copy is automatically updated when the
    non-affine part of the transform or the patch changes.
    c                 l    t         |   |j                         |j                                || _        y)zQ
        Parameters
        ----------
        patch : `~.patches.Patch`
        N)rT   rA   get_pathget_transform_patch)r   patchr[   s     r   rA   zTransformedPatchPath.__init__  s+     	)5+>+>+@Ar   c                     | j                   j                         }|| j                  k7  r|| _        d | _        t        |           y r   )rC  rA  r2  r3  rT   r6  )r   
patch_pathr[   s     r   r6  z TransformedPatchPath._revalidate  s=    [[))+
 ##DJ%)D"r   )r&   rq   rr   rs   rA   r6  rz   r{   s   @r   r?  r?  
  s     r   r?  c                    t        j                  |       rt        j                  |      s| |fS d}|| k  r|| }} d}t        t        | |g      \  } }t	        t        |       t        |            }|d|z  t        j                  t              j                  z  k  r| } |}n=|| z
  ||z  k  r2|dk(  r| dk(  r| } |}n"| |t        |       z  z  } ||t        |      z  z  }|r|s|| }} | |fS )a  
    Modify the endpoints of a range as needed to avoid singularities.

    Parameters
    ----------
    vmin, vmax : float
        The initial endpoints.
    expander : float, default: 0.001
        Fractional amount by which *vmin* and *vmax* are expanded if
        the original interval is too small, based on *tiny*.
    tiny : float, default: 1e-15
        Threshold for the ratio of the interval to the maximum absolute
        value of its endpoints.  If the interval is smaller than
        this, it will be expanded.  This value should be around
        1e-15 or larger; otherwise the interval will be approaching
        the double precision resolution limit.
    increasing : bool, default: True
        If True, swap *vmin*, *vmax* if *vmin* > *vmax*.

    Returns
    -------
    vmin, vmax : float
        Endpoints, expanded and/or swapped if necessary.
        If either input is inf or NaN, or if both inputs are 0 or very
        close to zero, it returns -*expander*, *expander*.
    FTg    .Ar   )r   isfinitemaprZ  r   absfinfotiny)vminvmaxexpanderrL  
increasingswappedmaxabsvalues          r   nonsingularrS    s    8 KKr{{4'8y(""Gd{4d UT4L)JD$c$iT+KcDjBHHUO$8$888y	d*	*199DDHSY&&DHSY&&Dz4d:r   c                 >    | \  }}||kD  r||}}||cxk  xr |k  S c S )a:  
    Check, inclusively, whether an interval includes a given value.

    Parameters
    ----------
    interval : (float, float)
        The endpoints of the interval.
    val : float
        Value to check is within interval.

    Returns
    -------
    bool
        Whether *val* is within the *interval*.
    r6   r  rZ   r6  r  s       r   interval_containsrV  O  s0      DAq1u!1=q==r   c                 Z    | \  }}||kD  r||}}||z
  |z  }||z
  |cxk  xr ||z   k  S c S )a  
    Check, inclusively, whether an interval includes a given value, with the
    interval expanded by a small tolerance to admit floating point errors.

    Parameters
    ----------
    interval : (float, float)
        The endpoints of the interval.
    val : float
        Value to check is within interval.
    rtol : float, default: 1e-10
        Relative tolerance slippage allowed outside of the interval.
        For an interval ``[a, b]``, values
        ``a - rtol * (b - a) <= val <= b + rtol * (b - a)`` are considered
        inside the interval.

    Returns
    -------
    bool
        Whether *val* is within the *interval* (with tolerance).
    r6   )r  rZ   rtolr6  r  s        r   _interval_contains_closerY  e  sH    , DAq1u!1ET>Dt8s&a$h&&&&r   c                 P    | \  }}||cxk  xr |k  nc xs ||cxkD  xr |kD  S c S )aB  
    Check, excluding endpoints, whether an interval includes a given value.

    Parameters
    ----------
    interval : (float, float)
        The endpoints of the interval.
    val : float
        Value to check is within interval.

    Returns
    -------
    bool
        Whether *val* is within the *interval*.
    r6   rU  s       r   interval_contains_openr[    s-      DAqs;Q;%!c+A+%+%r   c                     t        j                  g d|       |dk(  r| t               j                  ||      z   S |t	        d      |dk(  r
|dz  }|dz  }| t        |||j                        z   S )a  
    Return a new transform with an added offset.

    Parameters
    ----------
    trans : `Transform` subclass
        Any transform, to which offset will be applied.
    fig : `~matplotlib.figure.Figure`, default: None
        Current figure. It can be None if *units* are 'dots'.
    x, y : float, default: 0.0
        The offset to apply.
    units : {'inches', 'points', 'dots'}, default: 'inches'
        Units of the offset.

    Returns
    -------
    `Transform` subclass
        Transform with applied offset.
    )dotsr   inches)unitsr]  z3For units of inches or points a fig kwarg is neededr   g      R@)r   check_in_listrD  r  r  r  dpi_scale_trans)transfigr   r   r_  s        r   offset_copyrd    s|    ( 	35Axz++Aq111
{NOO	T		T	$Q3+>+>???r   )gMbP?gV瞯<T)g|=)Nr  r  r^  )9rs   rS   r,   r  r.   rN   r  numpyr   numpy.linalgr   
matplotlibr   matplotlib._pathr   r   r   rz  r	   ry   r/   r1   r}   r   rh  r\  r   r  r  r  r?  rO  r_  rD  r  r  r  r  r  r  r  r  r  r  rv   r  r  r  r!  r+  r0  r?  rS  rV  rY  r[  rd  r6   r   r   <module>ri     s  J         J J 8y yxFM} FMR "((BFFBFF+,Y?8 Y?xHXh HXVv8 vrV$ V$rKAy KA\/ /dA: AH[E| [E|/ /d+ +$ZmY Zz2m\ 2j=o4	 o4d2 2j+6'L 'T#l #L _  (   F 4l &< BD,m D,N? 67t,':&(@r   