B
    ]”t\úM ã               @   sâ  d dl Z d dlZd dlmZ d dlZd dlZd dlZd dlZ	ddl
mZmZmZmZmZmZ ddlmZmZmZmZmZmZmZmZmZmZ ddlmZ e dgdgd	gd
gdgdœ¡G dd„ dej ƒƒZ!e "e!¡Z#xdD ]Z$ej% &e$e#i¡ qÚW e 'e!j(¡ G dd„ de!ƒZ)G dd„ de!ƒZ*G dd„ de!ƒZ+G dd„ de!ƒZ,G dd„ de!ƒZ-G dd„ de!ƒZ.G dd„ de!ƒZ/G dd„ de-ƒZ0ej% &de0j(j1i¡ ej2d d!d"G d#d$„ d$e!ƒƒZ3G d%d&„ d&e+ƒZ4G d'd(„ d(e!ƒZ5G d)d*„ d*e5ƒZ6G d+d,„ d,e5ƒZ7dNd.d/„Z8dOd1d2„Z9dPd4d5„Z:d6d7„ Z;d8d9„ Z<G d:d;„ d;e=ƒZ>dQdd<œd=d>„Z?G d?d@„ d@e>ƒZ@ej%j&e;e@jAƒe<e@jAƒdA G dBdC„ dCe!ƒZBG dDdE„ dEe>ƒZCdFdG„ ZDG dHdI„ dIe>ƒZEej%j&e;eEjAƒe;eCjAƒdJ G dKd!„ d!e!ƒZFG dLdM„ dMeFƒZGdS )Ré    N)ÚNumberé   )ÚartistÚcbookÚcolorsÚ	docstringÚlinesÚ
transforms)
ÚNonIntersectingPathExceptionÚconcatenate_pathsÚget_cos_sinÚget_intersectionÚget_parallelsÚinside_circleÚmake_path_regularÚmake_wedged_bezier2Ú)split_bezier_intersecting_with_closedpathÚsplit_path_inout)ÚPathÚaaZecZfcÚlwÚls)ÚantialiasedÚ	edgecolorÚ	facecolorÚ	linewidthÚ	linestylec            
   @   sZ  e Zd ZdZdZdZdZdZdPdd	„Zd
d„ Z	dd„ Z
dQdd„ZdRdd„ZdSdd„Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd d!„ Zd"d#„ Zd$d%„ Zd&d'„ Zd(d)„ Zd*d+„ Zd,d-„ Zd.d/„ Zd0d1„ Zd2d3„ Zd4d5„ Zd6d7„ Zd8d9„ Z d:d;„ Z!d<d=„ Z"e#e"e!ƒZ$d>d?„ Z%d@dA„ Z&dBdC„ Z'dDdE„ Z(dFdG„ Z)dHdI„ Z*e+j,dJdK„ ƒZ-dLdM„ Z.dTdNdO„Z/dS )UÚPatchzÅ
    A patch is a 2D artist with a face color and an edge color.

    If any of *edgecolor*, *facecolor*, *linewidth*, or *antialiased*
    are *None*, they default to their rc params setting.
    r   )ÚbuttÚroundZ
projecting)Úmiterr   ZbevelFNTc             K   s"  t j | ¡ |dkrtjd }|dkr*d}|	dkr6d}	|
dkrBd}
|dkrTtjd }t tjd ¡| _d| _|dk	rš|dk	s„|dk	rŽt	 
d	¡ |  |¡ n|  |¡ |  |¡ d| _d
| _|  |¡ |  |¡ |  |¡ |  |¡ |  |¡ |  |	¡ |  |
¡ t ¡ | _t|ƒr|  |¡ dS )zQ
        The following kwarg properties are supported

        %(Patch)s
        Nzpatch.linewidthÚsolidr   r    zpatch.antialiasedzhatch.colorTzPSetting the 'color' property will overridethe edgecolor or facecolor properties.r   )r   ÚArtistÚ__init__ÚmplÚrcParamsr   Úto_rgbaÚ_hatch_colorÚ_fillÚwarningsÚwarnÚ	set_colorÚset_edgecolorÚset_facecolorÚ
_us_dashesÚ
_linewidthÚset_fillÚset_linestyleÚset_linewidthÚset_antialiasedÚ	set_hatchÚset_capstyleÚset_joinstyler	   ÚIdentityTransformZ_combined_transformÚlenÚupdate)Úselfr   r   Úcolorr   r   r   ÚhatchÚfillZcapstyleZ	joinstyleÚkwargs© r?   ú1lib/python3.7/site-packages/matplotlib/patches.pyr#   )   s>    













zPatch.__init__c             C   s.   |   ¡ }|  ¡ }| |¡}t|ƒr*|d S g S )zé
        Return a copy of the vertices used in this patch

        If the patch contains Bezier curves, the curves will be
        interpolated by line segments.  To access the curves as
        curves, use :meth:`get_path`.
        r   )Úget_transformÚget_pathZto_polygonsr8   )r:   ÚtransÚpathZpolygonsr?   r?   r@   Ú	get_vertsa   s    
zPatch.get_vertsc             C   sB   |d k	r|S t | jtƒr | j}n|  ¡ d dkr6d}n|  ¡ }|S )Né   r   )Ú
isinstanceZ_pickerr   Úget_edgecolorÚget_linewidth)r:   ÚradiusÚ_radiusr?   r?   r@   Ú_process_radiusp   s    zPatch._process_radiusc             C   sF   t | jƒr|  | |¡S |  |¡}|  ¡  |j|jf|  ¡ |¡}|i fS )zUTest whether the mouse event occurred in the patch.

        Returns T/F, {}
        )ÚcallableZ	_containsrL   rB   Úcontains_pointÚxÚyrA   )r:   Z
mouseeventrJ   Úinsider?   r?   r@   Úcontains|   s    

zPatch.containsc             C   s    |   |¡}|  ¡  ||  ¡ |¡S )zÇ
        Returns ``True`` if the given *point* is inside the path
        (transformed with its transform attribute).

        *radius* allows the path to be made slightly larger or smaller.
        )rL   rB   rN   rA   )r:   ZpointrJ   r?   r?   r@   rN   ˆ   s    

zPatch.contains_pointc             C   s    |   |¡}|  ¡  ||  ¡ |¡S )a  
        Returns a bool array which is ``True`` if the (closed) path
        contains the corresponding point.
        (transformed with its transform attribute).

        *points* must be Nx2 array.
        *radius* allows the path to be made slightly larger or smaller.
        )rL   rB   Úcontains_pointsrA   )r:   ZpointsrJ   r?   r?   r@   rS   ”   s    	

zPatch.contains_pointsc             C   sv   t j | |¡ |j| _|j| _|j| _|j| _|j| _|j| _|j	| _	|j
| _
|  |j¡ |  | ¡ ¡ | ¡ | _dS )zM
        Updates this :class:`Patch` from the properties of *other*.
        N)r   r"   Úupdate_fromÚ
_edgecolorÚ
_facecolorÚ_original_edgecolorÚ_original_facecolorr(   Ú_hatchr'   r.   r2   r/   Úset_transformÚget_data_transformZis_transform_setZ_transformSet)r:   Úotherr?   r?   r@   rT   ¢   s    zPatch.update_fromc             C   s   |   ¡  |  ¡ ¡S )z‡
        Return a :class:`~matplotlib.transforms.Bbox` object defining
        the axis-aligned extents of the :class:`Patch`.
        )rB   Úget_extentsrA   )r:   r?   r?   r@   r]   ¸   s    zPatch.get_extentsc             C   s   |   ¡ tj | ¡ S )zm
        Return the :class:`~matplotlib.transforms.Transform` applied
        to the :class:`Patch`.
        )Úget_patch_transformr   r"   rA   )r:   r?   r?   r@   rA   ¿   s    zPatch.get_transformc             C   s   t j | ¡S )zŒ
        Return the :class:`~matplotlib.transforms.Transform` instance which
        maps data coordinates to physical coordinates.
        )r   r"   rA   )r:   r?   r?   r@   r[   Æ   s    zPatch.get_data_transformc             C   s   t  ¡ S )ah  
        Return the :class:`~matplotlib.transforms.Transform` instance which
        takes patch coordinates to data coordinates.

        For example, one may define a patch of a circle which represents a
        radius of 5 by providing coordinates for a unit circle, and a
        transform which scales the coordinates (the patch coordinate) by 5.
        )r	   r7   )r:   r?   r?   r@   r^   Í   s    	zPatch.get_patch_transformc             C   s   | j S )zV
        Returns True if the :class:`Patch` is to be drawn with antialiasing.
        )Ú_antialiased)r:   r?   r?   r@   Úget_antialiasedØ   s    zPatch.get_antialiasedc             C   s   | j S )z>
        Return the edge color of the :class:`Patch`.
        )rU   )r:   r?   r?   r@   rH   Þ   s    zPatch.get_edgecolorc             C   s   | j S )z>
        Return the face color of the :class:`Patch`.
        )rV   )r:   r?   r?   r@   Úget_facecolorä   s    zPatch.get_facecolorc             C   s   | j S )z2
        Return the line width in points.
        )r/   )r:   r?   r?   r@   rI   ê   s    zPatch.get_linewidthc             C   s   | j S )z'
        Return the linestyle.
        )Ú
_linestyle)r:   r?   r?   r@   Úget_linestyleð   s    zPatch.get_linestylec             C   s"   |dkrt jd }|| _d| _dS )z{
        Set whether to use antialiased rendering.

        Parameters
        ----------
        b : bool or None
        Nzpatch.antialiasedT)r$   r%   r_   Ústale)r:   r   r?   r?   r@   r3   ö   s    
zPatch.set_antialiasedc             C   s\   d}|d kr6t jd s"| jr"| jr.t jd }nd}d}t || j¡| _|rR| j| _d| _	d S )NTzpatch.force_edgecolorzpatch.edgecolorZnoneF)
r$   r%   r(   Ú_edge_defaultr   r&   Ú_alpharU   r'   rd   )r:   r;   Úset_hatch_colorr?   r?   r@   Ú_set_edgecolor  s    
zPatch._set_edgecolorc             C   s   || _ |  |¡ dS )zz
        Set the patch edge color.

        Parameters
        ----------
        color : color or None or 'auto'
        N)rW   rh   )r:   r;   r?   r?   r@   r,     s    zPatch.set_edgecolorc             C   s:   |d krt jd }| jr| jnd}t ||¡| _d| _d S )Nzpatch.facecolorr   T)r$   r%   r(   rf   r   r&   rV   rd   )r:   r;   Úalphar?   r?   r@   Ú_set_facecolor  s
    
zPatch._set_facecolorc             C   s   || _ |  |¡ dS )zp
        Set the patch face color.

        Parameters
        ----------
        color : color or None
        N)rX   rj   )r:   r;   r?   r?   r@   r-   $  s    zPatch.set_facecolorc             C   s   |   |¡ |  |¡ dS )a  
        Set both the edgecolor and the facecolor.

        .. seealso::

            :meth:`set_facecolor`, :meth:`set_edgecolor`
               For setting the edge or face color individually.

        Parameters
        ----------
        c : color
        N)r-   r,   )r:   Úcr?   r?   r@   r+   /  s    
zPatch.set_colorc             C   s\   |dk	r2yt |ƒ W n tk
r0   tdƒ‚Y nX tj | |¡ |  | j¡ |  | j¡ dS )z
        Set the alpha transparency of the patch.

        Parameters
        ----------
        alpha : float or None
        Nzalpha must be a float or None)	ÚfloatÚ	TypeErrorr   r"   Ú	set_alpharj   rX   rh   rW   )r:   ri   r?   r?   r@   rn   ?  s    zPatch.set_alphac             C   sZ   |dkr$t jd }|dkr$t jd }t|ƒ| _| j\}}t ||| j¡\| _| _d| _	dS )z_
        Set the patch linewidth in points

        ACCEPTS: float or None for default
        Nzpatch.linewidthzaxes.linewidthT)
r$   r%   rl   r/   r.   ÚmlinesÚ_scale_dashesÚ_dashoffsetÚ_dashesrd   )r:   ÚwÚoffsetr   r?   r?   r@   r2   Q  s    



zPatch.set_linewidthc             C   sH   |dkrd}|| _ t |¡ \}}| _t ||| j¡\| _| _d| _dS )a  
        Set the patch linestyle.

        ===========================   =================
        linestyle                     description
        ===========================   =================
        ``'-'`` or ``'solid'``        solid line
        ``'--'`` or  ``'dashed'``     dashed line
        ``'-.'`` or  ``'dashdot'``    dash-dotted line
        ``':'`` or ``'dotted'``       dotted line
        ===========================   =================

        Alternatively a dash tuple of the following form can be provided::

            (offset, onoffseq),

        where ``onoffseq`` is an even length tuple of on and off ink in points.

        Parameters
        ----------
        ls : {'-', '--', '-.', ':', '', (offset, on-off-seq), ...}
            The line style.
        Nr!   T)	rb   ro   Z_get_dash_patternr.   rp   r/   rq   rr   rd   )r:   r   rt   r?   r?   r@   r1   c  s    zPatch.set_linestylec             C   s,   t |ƒ| _|  | j¡ |  | j¡ d| _dS )zh
        Set whether to fill the patch.

        Parameters
        ----------
        b : bool
        TN)Úboolr(   rj   rX   rh   rW   rd   )r:   Úbr?   r?   r@   r0   …  s    
zPatch.set_fillc             C   s   | j S )zreturn whether fill is set)r(   )r:   r?   r?   r@   Úget_fill’  s    zPatch.get_fillc             C   s<   |  ¡ }|| jkr,td|f d| jf  ƒ‚|| _d| _dS )z{
        Set the patch capstyle

        Parameters
        ----------
        s : {'butt', 'round', 'projecting'}
        zset_capstyle passed "%s";
zvalid capstyles are %sTN)ÚlowerÚvalidCapÚ
ValueErrorÚ	_capstylerd   )r:   Úsr?   r?   r@   r5   ›  s    

zPatch.set_capstylec             C   s   | j S )zReturn the current capstyle)r{   )r:   r?   r?   r@   Úget_capstyleª  s    zPatch.get_capstylec             C   s<   |  ¡ }|| jkr,td|f d| jf  ƒ‚|| _d| _dS )zx
        Set the patch joinstyle

        Parameters
        ----------
        s : {'miter', 'round', 'bevel'}
        zset_joinstyle passed "%s";
zvalid joinstyles are %sTN)rx   Ú	validJoinrz   Ú
_joinstylerd   )r:   r|   r?   r?   r@   r6   ®  s    

zPatch.set_joinstylec             C   s   | j S )zReturn the current joinstyle)r   )r:   r?   r?   r@   Úget_joinstyle½  s    zPatch.get_joinstylec             C   s   || _ d| _dS )aØ  
        Set the hatching pattern

        *hatch* can be one of::

          /   - diagonal hatching
          \   - back diagonal
          |   - vertical
          -   - horizontal
          +   - crossed
          x   - crossed diagonal
          o   - small circle
          O   - large circle
          .   - dots
          *   - stars

        Letters can be combined, in which case all the specified
        hatchings are done.  If same letter repeats, it increases the
        density of hatching of that pattern.

        Hatching is supported in the PostScript, PDF, SVG and Agg
        backends only.

        Parameters
        ----------
        hatch : {'/', '\\', '|', '-', '+', 'x', 'o', 'O', '.', '*'}
        TN)rY   rd   )r:   r<   r?   r?   r@   r4   Á  s    zPatch.set_hatchc             C   s   | j S )z#Return the current hatching pattern)rY   )r:   r?   r?   r@   Ú	get_hatchà  s    zPatch.get_hatchc       
      C   s¢  |   ¡ sdS | d|  ¡ ¡ | ¡ }|j| jdd | j}| jd dkrLd}| |¡ | d| j	¡ | 
| j¡ | | j¡ | | j¡ |  |¡ | | j¡ | |  ¡ ¡ | j}|d dkrÂd}| | j¡ | jr| | j¡ y| | j¡ W n  tk
r   t d¡ Y nX |  ¡ dk	r0|j |  ¡ Ž  |  !¡ }|  "¡ }| #|¡}| $¡ }|  %¡ rvddl&m'}	 |	|  %¡ |ƒ}| (||||¡ | )¡  | *d¡ d	| _+dS )
z0Draw the :class:`Patch` to the given *renderer*.NÚpatchT)ÚisRGBArF   r   z6Your backend does not support setting the hatch color.)ÚPathEffectRendererF),Úget_visibleÚ
open_groupÚget_gidÚnew_gcÚset_foregroundrU   r/   r2   Ú
set_dashesrr   r5   r{   r6   r   r3   r_   Ú_set_gc_clipZset_urlZ_urlÚset_snapÚget_snaprV   rn   rf   rY   r4   rg   r'   ÚAttributeErrorr)   r*   Úget_sketch_paramsÚset_sketch_paramsrB   rA   Ztransform_path_non_affineZ
get_affineÚget_path_effectsÚmatplotlib.patheffectsr„   Ú	draw_pathÚrestoreÚclose_grouprd   )
r:   ÚrendererÚgcr   ÚrgbFacerD   Z	transformZtpathÚaffiner„   r?   r?   r@   Údrawä  sP    




z
Patch.drawc             C   s   t dƒ‚dS )z/
        Return the path of this patch
        zDerived must overrideN)ÚNotImplementedError)r:   r?   r?   r@   rB     s    zPatch.get_pathc             C   s   |   ¡  |  ¡ ¡S )N)rB   r]   rA   )r:   r–   r?   r?   r@   Úget_window_extent#  s    zPatch.get_window_extent)
NNNNNNNTNN)N)N)N)N)0Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úzorderry   r~   re   r#   rE   rL   rR   rN   rS   rT   r]   rA   r[   r^   r`   rH   ra   rI   rc   r3   rh   r,   rj   r-   r+   rn   r2   r1   r0   rw   Úpropertyr=   r5   r}   r6   r€   r4   r   r   Úallow_rasterizationrš   rB   rœ   r?   r?   r?   r@   r      sf            
.


"
9r   )Ú	RectangleÚCircleÚRegularPolygonÚPolygonÚWedgeÚArrowÚ
FancyArrowÚYAArrowÚCirclePolygonÚEllipseÚArcÚFancyBboxPatchr   c               @   sl   e Zd Zdd„ Zejddd„ƒZdd„ Zdd	„ Zd
d„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )ÚShadowc             C   s   dt | jƒ S )Nz
Shadow(%s))Ústrr‚   )r:   r?   r?   r@   Ú__str__2  s    zShadow.__str__Nc             K   s:   t  | ¡ || _|| _|| | _| _t ¡ | _|  	¡  dS )a  
        Create a shadow of the given *patch* offset by *ox*, *oy*.
        *props*, if not *None*, is a patch property update dictionary.
        If *None*, the shadow will have have the same color as the face,
        but darkened.

        kwargs are
        %(Patch)s
        N)
r   r#   r‚   ÚpropsÚ_oxÚ_oyr	   ÚAffine2DÚ_shadow_transformÚ_update)r:   r‚   ÚoxÚoyr³   r>   r?   r?   r@   r#   5  s    

zShadow.__init__c             C   sz   |   | j¡ |  t | jjtj ¡¡ | jd k	r>|  | j¡ n8dt 	t
 | j ¡ ¡¡ }|  |¡ |  |¡ |  d¡ d S )Ng333333Ó?g      à?)rT   r‚   Z
set_zorderÚnpZ	nextafterr¡   Úinfr³   r9   Úasarrayr   Zto_rgbra   r-   r,   rn   )r:   r;   r?   r?   r@   r¸   G  s    


zShadow._updatec             C   s.   |  | j¡}|  | j¡}| j ¡  ||¡ d S )N)Úpoints_to_pixelsr´   rµ   r·   ÚclearÚ	translate)r:   r–   r¹   rº   r?   r?   r@   Ú_update_transformU  s    zShadow._update_transformc             C   s   | j S )N)r´   )r:   r?   r?   r@   Ú_get_oxZ  s    zShadow._get_oxc             C   s
   || _ d S )N)r´   )r:   r¹   r?   r?   r@   Ú_set_ox]  s    zShadow._set_oxc             C   s   | j S )N)rµ   )r:   r?   r?   r@   Ú_get_oy`  s    zShadow._get_oyc             C   s
   || _ d S )N)rµ   )r:   rº   r?   r?   r@   Ú_set_oyc  s    zShadow._set_oyc             C   s
   | j  ¡ S )N)r‚   rB   )r:   r?   r?   r@   rB   f  s    zShadow.get_pathc             C   s   | j  ¡ | j S )N)r‚   r^   r·   )r:   r?   r?   r@   r^   i  s    zShadow.get_patch_transformc             C   s   |   |¡ t | |¡ d S )N)rÁ   r   rš   )r:   r–   r?   r?   r@   rš   l  s    
zShadow.draw)N)r   rž   rŸ   r²   r   Údedent_interpdr#   r¸   rÁ   rÂ   rÃ   rÄ   rÅ   rB   r^   rš   r?   r?   r?   r@   r°   1  s   r°   c               @   sÂ   e Zd ZdZdd„ Zejd,dd„ƒZdd„ Zd	d
„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ Zd#d$„ Zd%d&„ Zd'd(„ Zd)d*„ ZeeeƒZd+S )-r¤   zz
    Draw a rectangle with lower left at *xy* = (*x*, *y*) with
    specified *width*, *height* and rotation *angle*.
    c             C   s$   | j | j| j| j| jf}d}|| S )Nz5Rectangle(xy=(%g, %g), width=%g, height=%g, angle=%g))Ú_x0Ú_y0Ú_widthÚ_heightÚangle)r:   ÚparsÚfmtr?   r?   r@   r²   w  s    zRectangle.__str__ç        c             K   sb   t j| f|Ž |d | _|d | _|| _|| _| j| j | _| j| j | _t|ƒ| _	t
 ¡ | _dS )a÷  
        Parameters
        ----------
        xy : (float, float)
            The bottom and left rectangle coordinates
        width : float
            Rectangle width
        height : float
            Rectangle height
        angle : float, optional
          rotation in degrees anti-clockwise about *xy* (default is 0.0)
        fill : bool, optional
            Whether to fill the rectangle (default is ``True``)

        Notes
        -----
        Valid kwargs are:
        %(Patch)s
        r   r   N)r   r#   rÇ   rÈ   rÉ   rÊ   Ú_x1Ú_y1rl   rË   r	   r7   Ú_rect_transform)r:   ÚxyÚwidthÚheightrË   r>   r?   r?   r@   r#   |  s    


zRectangle.__init__c             C   s   t  ¡ S )z7
        Return the vertices of the rectangle.
        )r   Úunit_rectangle)r:   r?   r?   r@   rB   ¡  s    zRectangle.get_pathc             C   sX   |   ¡ \}}}}tj ||||¡}t ¡ }| ||| j¡ t |¡| _|  j|7  _dS )a  NOTE: This cannot be called until after this has been added
                 to an Axes, otherwise unit conversion will fail. This
                 makes it very important to call the accessor method and
                 not directly access the transformation member variable.
        N)	Ú_convert_unitsr	   ÚBboxÚfrom_extentsr¶   Zrotate_deg_aroundrË   ÚBboxTransformTorÑ   )r:   Úx0Úy0Úx1Úy1ÚbboxZ	rot_transr?   r?   r@   Ú_update_patch_transform§  s    z!Rectangle._update_patch_transformc             C   s   | j | j | _d S )N)rÇ   rÉ   rÏ   )r:   r?   r?   r@   Ú
_update_x1´  s    zRectangle._update_x1c             C   s   | j | j | _d S )N)rÈ   rÊ   rÐ   )r:   r?   r?   r@   Ú
_update_y1·  s    zRectangle._update_y1c             C   s<   |   | j¡}|  | j¡}|   | j¡}|  | j¡}||||fS )z2
        Convert bounds of the rectangle.
        )Úconvert_xunitsrÇ   Úconvert_yunitsrÈ   rÏ   rÐ   )r:   rÚ   rÛ   rÜ   rÝ   r?   r?   r@   rÖ   º  s
    zRectangle._convert_unitsc             C   s   |   ¡  | jS )N)rß   rÑ   )r:   r?   r?   r@   r^   Ä  s    zRectangle.get_patch_transformc             C   s   | j S )z'Return the left coord of the rectangle.)rÇ   )r:   r?   r?   r@   Úget_xÈ  s    zRectangle.get_xc             C   s   | j S )z)Return the bottom coord of the rectangle.)rÈ   )r:   r?   r?   r@   Úget_yÌ  s    zRectangle.get_yc             C   s   | j | jfS )z3Return the left and bottom coords of the rectangle.)rÇ   rÈ   )r:   r?   r?   r@   Úget_xyÐ  s    zRectangle.get_xyc             C   s   | j S )z"Return the width of the rectangle.)rÉ   )r:   r?   r?   r@   Ú	get_widthÔ  s    zRectangle.get_widthc             C   s   | j S )z#Return the height of the rectangle.)rÊ   )r:   r?   r?   r@   Ú
get_heightØ  s    zRectangle.get_heightc             C   s   || _ |  ¡  d| _dS )z$Set the left coord of the rectangle.TN)rÇ   rà   rd   )r:   rO   r?   r?   r@   Úset_xÜ  s    zRectangle.set_xc             C   s   || _ |  ¡  d| _dS )z&Set the bottom coord of the rectangle.TN)rÈ   rá   rd   )r:   rP   r?   r?   r@   Úset_yâ  s    zRectangle.set_yc             C   s&   |\| _ | _|  ¡  |  ¡  d| _dS )z…
        Set the left and bottom coords of the rectangle.

        Parameters
        ----------
        xy : (float, float)
        TN)rÇ   rÈ   rà   rá   rd   )r:   rÒ   r?   r?   r@   Úset_xyè  s    zRectangle.set_xyc             C   s   || _ |  ¡  d| _dS )zSet the width of the rectangle.TN)rÉ   rà   rd   )r:   rs   r?   r?   r@   Ú	set_widthõ  s    zRectangle.set_widthc             C   s   || _ |  ¡  d| _dS )z Set the height of the rectangle.TN)rÊ   rá   rd   )r:   Úhr?   r?   r@   Ú
set_heightû  s    zRectangle.set_heightc             G   s\   t |ƒdkr|d \}}}}n|\}}}}|| _|| _|| _|| _|  ¡  |  ¡  d| _dS )zj
        Set the bounds of the rectangle: l,b,w,h

        ACCEPTS: (left, bottom, width, height)
        r   r   TN)r8   rÇ   rÈ   rÉ   rÊ   rà   rá   rd   )r:   ÚargsÚlrv   rs   rí   r?   r?   r@   Ú
set_bounds  s    zRectangle.set_boundsc             C   s"   |   ¡ \}}}}tj ||||¡S )N)rÖ   r	   r×   rØ   )r:   rÚ   rÛ   rÜ   rÝ   r?   r?   r@   Úget_bbox  s    zRectangle.get_bboxN)rÎ   )r   rž   rŸ   r    r²   r   rÆ   r#   rB   rß   rà   rá   rÖ   r^   rä   rå   ræ   rç   rè   ré   rê   rë   rì   rî   rñ   rò   r¢   rÒ   r?   r?   r?   r@   r¤   q  s.   $
r¤   c               @   s¨   e Zd ZdZdd„ Zejddd„ƒZdd	„ Zd
d„ Z	dd„ Z
ee	e
ƒZdd„ Zdd„ ZeeeƒZdd„ Zdd„ ZeeeƒZdd„ Zdd„ ZeeeƒZdd„ Zdd„ ZdS ) r¦   z"
    A regular polygon patch.
    c             C   s(   d}|| j d | j d | j| j| jf S )Nz7RegularPolygon((%g, %g), %d, radius=%g, orientation=%g)r   r   )Ú_xyÚ_numVerticesrK   Ú_orientation)r:   r|   r?   r?   r@   r²     s    zRegularPolygon.__str__é   r   c             K   sH   || _ || _|| _|| _t |¡| _t ¡ | _	|  
¡  tj| f|Ž dS )af  
        Constructor arguments:

        *xy*
          A length 2 tuple (*x*, *y*) of the center.

        *numVertices*
          the number of vertices.

        *radius*
          The distance from the center to each of the vertices.

        *orientation*
          rotates the polygon (in radians).

        Valid kwargs are:
        %(Patch)s
        N)ró   rô   rõ   rK   r   Zunit_regular_polygonÚ_pathr	   r¶   Ú_poly_transformrÁ   r   r#   )r:   rÒ   ÚnumVerticesrJ   Úorientationr>   r?   r?   r@   r#   #  s    
zRegularPolygon.__init__c             C   s&   | j  ¡  | j¡ | j¡j| jŽ  d S )N)rø   r¿   ÚscalerJ   Úrotaterú   rÀ   rÒ   )r:   r?   r?   r@   rÁ   B  s    
z RegularPolygon._update_transformc             C   s   | j S )N)ró   )r:   r?   r?   r@   Ú_get_xyH  s    zRegularPolygon._get_xyc             C   s   || _ |  ¡  d S )N)ró   rÁ   )r:   rÒ   r?   r?   r@   Ú_set_xyK  s    zRegularPolygon._set_xyc             C   s   | j S )N)rõ   )r:   r?   r?   r@   Ú_get_orientationP  s    zRegularPolygon._get_orientationc             C   s   || _ |  ¡  d S )N)rõ   rÁ   )r:   rú   r?   r?   r@   Ú_set_orientationS  s    zRegularPolygon._set_orientationc             C   s   | j S )N)rK   )r:   r?   r?   r@   Ú_get_radiusX  s    zRegularPolygon._get_radiusc             C   s   || _ |  ¡  d S )N)rK   rÁ   )r:   rJ   r?   r?   r@   Ú_set_radius[  s    zRegularPolygon._set_radiusc             C   s   | j S )N)rô   )r:   r?   r?   r@   Ú_get_numvertices`  s    zRegularPolygon._get_numverticesc             C   s
   || _ d S )N)rô   )r:   rù   r?   r?   r@   Ú_set_numverticesc  s    zRegularPolygon._set_numverticesc             C   s   | j S )N)r÷   )r:   r?   r?   r@   rB   h  s    zRegularPolygon.get_pathc             C   s   |   ¡  | jS )N)rÁ   rø   )r:   r?   r?   r@   r^   k  s    z"RegularPolygon.get_patch_transformN)rö   r   )r   rž   rŸ   r    r²   r   rÆ   r#   rÁ   rý   rþ   r¢   rÒ   rÿ   r   rú   r  r  rJ   r  r  ZnumverticesrB   r^   r?   r?   r?   r@   r¦     s&   



r¦   c               @   s2   e Zd ZdZdZdd„ Zejdd„ ƒZdd„ Z	d	S )
Ú	PathPatchz)
    A general polycurve path patch.
    Tc             C   s&   d}|t | jjƒft| jjd ƒ˜ S )NzPathPatch%d((%g, %g) ...)r   )r8   r÷   ÚverticesÚtuple)r:   r|   r?   r?   r@   r²   v  s    zPathPatch.__str__c             K   s   t j| f|Ž || _dS )zÉ
        *path* is a :class:`matplotlib.path.Path` object.

        Valid kwargs are:
        %(Patch)s

        .. seealso::

            :class:`Patch`
                For additional kwargs

        N)r   r#   r÷   )r:   rD   r>   r?   r?   r@   r#   z  s    zPathPatch.__init__c             C   s   | j S )N)r÷   )r:   r?   r?   r@   rB   ‹  s    zPathPatch.get_pathN)
r   rž   rŸ   r    re   r²   r   rÆ   r#   rB   r?   r?   r?   r@   r  p  s
   r  c               @   sf   e Zd ZdZdd„ Zejddd„ƒZdd„ Zd	d
„ Z	dd„ Z
dd„ Zdd„ ZeZeZeeeddZdS )r§   z"
    A general polygon patch.
    c             C   s&   d}|t | jjƒft| jjd ƒ˜ S )NzPolygon%d((%g, %g) ...)r   )r8   r÷   r  r  )r:   r|   r?   r?   r@   r²   “  s    zPolygon.__str__Tc             K   s"   t j| f|Ž || _|  |¡ dS )a0  
        *xy* is a numpy array with shape Nx2.

        If *closed* is *True*, the polygon will be closed so the
        starting and ending points are the same.

        Valid kwargs are:
        %(Patch)s

        .. seealso::

            :class:`Patch`
                For additional kwargs

        N)r   r#   Ú_closedrë   )r:   rÒ   Úclosedr>   r?   r?   r@   r#   —  s    zPolygon.__init__c             C   s   | j S )z²
        Get the path of the polygon

        Returns
        -------
        path : Path
           The :class:`~matplotlib.path.Path` object for
           the polygon
        )r÷   )r:   r?   r?   r@   rB   ¬  s    
zPolygon.get_pathc             C   s   | j S )z‹
        Returns if the polygon is closed

        Returns
        -------
        closed : bool
            If the path is closed
        )r  )r:   r?   r?   r@   Ú
get_closed¸  s    	zPolygon.get_closedc             C   s4   | j t|ƒkrdS t|ƒ| _ |  |  ¡ ¡ d| _dS )z”
        Set if the polygon is closed

        Parameters
        ----------
        closed : bool
           True if the polygon is closed
        NT)r  ru   rë   ræ   rd   )r:   r	  r?   r?   r@   Ú
set_closedÃ  s
    	
zPolygon.set_closedc             C   s   | j jS )z£
        Get the vertices of the path.

        Returns
        -------
        vertices : (N, 2) numpy array
            The coordinates of the vertices.
        )r÷   r  )r:   r?   r?   r@   ræ   Ò  s    	zPolygon.get_xyc             C   sˆ   t  |¡}| jrBt|ƒrn|d |d k ¡ rnt  ||d gg¡}n,t|ƒdkrn|d |d k ¡ rn|dd… }t|| jd| _d| _	dS )z¥
        Set the vertices of the polygon.

        Parameters
        ----------
        xy : (N, 2) array-like
            The coordinates of the vertices.
        r   éÿÿÿÿé   N)r	  T)
r»   r½   r  r8   ÚanyÚconcatenateÚallr   r÷   rd   )r:   rÒ   r?   r?   r@   rë   Ý  s    	
 zPolygon.set_xyz/The vertices of the path as (N, 2) numpy array.)ÚdocN)T)r   rž   rŸ   r    r²   r   rÆ   r#   rB   r
  r  ræ   rë   rý   rþ   r¢   rÒ   r?   r?   r?   r@   r§     s   r§   c               @   s`   e Zd ZdZdd„ Zejddd„ƒZdd„ Zd	d
„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ ZdS )r¨   z
    Wedge shaped patch.
    c             C   s0   | j d | j d | j| j| j| jf}d}|| S )Nr   r   z<Wedge(center=(%g, %g), r=%g, theta1=%g, theta2=%g, width=%s))ÚcenterÚrÚtheta1Útheta2rÓ   )r:   rÌ   rÍ   r?   r?   r@   r²   ú  s    zWedge.__str__Nc             K   sF   t j| f|Ž || _|| | _| _|| | _| _t ¡ | _	|  
¡  dS )a(  
        Draw a wedge centered at *x*, *y* center with radius *r* that
        sweeps *theta1* to *theta2* (in degrees).  If *width* is given,
        then a partial wedge is drawn from inner radius *r* - *width*
        to outer radius *r*.

        Valid kwargs are:

        %(Patch)s
        N)r   r#   r  r  rÓ   r  r  r	   r7   Ú_patch_transformÚ_recompute_path)r:   r  r  r  r  rÓ   r>   r?   r?   r@   r#      s    
zWedge.__init__c       	      C   s&  t | j| j d ƒdkr(d\}}tj}n| j| j }}tj}t ||¡}| jd k	rÀ|j}|jd d d… | j	| j  | j	 }t
 |||dd d …f dg¡}t
 |j|j|tjg¡}||t|jƒ< n<t
 |jd|jdd d …f dgg¡}t
 |j||tjgg¡}|| j	9 }|t
 | j¡7 }t||ƒ| _d S )Nih  gê-™—q=)r   ih  r  r   )r   r   )Úabsr  r  r   ÚMOVETOÚLINETOÚarcrÓ   r  r  r»   ZvstackZhstackÚcodesÚ	CLOSEPOLYr8   r½   r  r÷   )	r:   r  r  Ú	connectorr  Zv1Zv2Úvrk   r?   r?   r@   r    s"    
"$
zWedge._recompute_pathc             C   s   d | _ || _d| _d S )NT)r÷   r  rd   )r:   r  r?   r?   r@   Ú
set_center1  s    zWedge.set_centerc             C   s   d | _ || _d| _d S )NT)r÷   r  rd   )r:   rJ   r?   r?   r@   Ú
set_radius6  s    zWedge.set_radiusc             C   s   d | _ || _d| _d S )NT)r÷   r  rd   )r:   r  r?   r?   r@   Ú
set_theta1;  s    zWedge.set_theta1c             C   s   d | _ || _d| _d S )NT)r÷   r  rd   )r:   r  r?   r?   r@   Ú
set_theta2@  s    zWedge.set_theta2c             C   s   d | _ || _d| _d S )NT)r÷   rÓ   rd   )r:   rÓ   r?   r?   r@   rì   E  s    zWedge.set_widthc             C   s   | j d kr|  ¡  | j S )N)r÷   r  )r:   r?   r?   r@   rB   J  s    
zWedge.get_path)N)r   rž   rŸ   r    r²   r   rÆ   r#   r  r   r!  r"  r#  rì   rB   r?   r?   r?   r@   r¨   ö  s   r¨   c            
   @   st   e Zd ZdZdd„ Zeddgddgddgddgd	dgdd
gddgddggddZejddd„ƒZ	dd„ Z
dd„ ZdS )r©   z
    An arrow patch.
    c             C   s   dS )NzArrow()r?   )r:   r?   r?   r@   r²   U  s    zArrow.__str__g        gš™™™™™¹?gš™™™™™¹¿gš™™™™™é?g333333Ó¿ç      ð?g333333Ó?T)r	  c             K   sŽ   t j| f|Ž t ||¡}|dkr4|| }|| }	nd\}}	t ¡  ||¡}
tj ||	|	 |dd¡}t ¡  ||¡}|
| | }| 	¡ | _
dS )aŠ  
        Draws an arrow from (*x*, *y*) to (*x* + *dx*, *y* + *dy*).
        The width of the arrow is scaled by *width*.

        Parameters
        ----------
        x : scalar
            x coordinate of the arrow tail
        y : scalar
            y coordinate of the arrow tail
        dx : scalar
            Arrow length in the x direction
        dy : scalar
            Arrow length in the y direction
        width : scalar, optional (default: 1)
            Scale factor for the width of the arrow. With a default value of
            1, the tail width is 0.2 and head width is 0.6.
        **kwargs :
            Keyword arguments control the :class:`~matplotlib.patches.Patch`
            properties:

            %(Patch)s

        See Also
        --------
        :class:`FancyArrow` :
            Patch that allows independent control of the head and tail
            properties
        r   )r   r   g        N)r   r#   r»   Úhypotr	   r¶   rû   Zfrom_valuesrÀ   Úfrozenr  )r:   rO   rP   ÚdxÚdyrÓ   r>   ÚLÚcxÚsxZtrans1Ztrans2Ztrans3rC   r?   r?   r@   r#   ^  s    
zArrow.__init__c             C   s   | j S )N)r÷   )r:   r?   r?   r@   rB     s    zArrow.get_pathc             C   s   | j S )N)r  )r:   r?   r?   r@   r^     s    zArrow.get_patch_transformN)r$  )r   rž   rŸ   r    r²   r   r÷   r   rÆ   r#   rB   r^   r?   r?   r?   r@   r©   Q  s   .r©   c                   s4   e Zd ZdZdZdd„ Zejd‡ fd
d„	ƒZ‡  Z	S )rª   zP
    Like Arrow, but lets you set head width and head height independently.
    Tc             C   s   dS )NzFancyArrow()r?   )r:   r?   r?   r@   r²   ›  s    zFancyArrow.__str__çü©ñÒMbP?FNÚfullr   c                sš  |dkrd| }|dkr d| }t  ||¡}|r6|}n|| }|sJg }n4|||
|f\}}}}t  ddg| | d g| d|  | d g| | d g| dgg¡}|s¸||dg7 }|rÌ||d dg7 }|	dkrÚ|}nR|dd	g }|	d
krô|}n8|	dkr t  |dd	… |ddd	… g¡}ntd|	 ƒ‚|dkrH|| }|| }nd\}}||g| |gg}t  ||¡|| || f }tƒ j|fddi|—Ž dS )aê  
        Constructor arguments
          *width*: float (default: 0.001)
            width of full arrow tail

          *length_includes_head*: bool (default: False)
            True if head is to be counted in calculating the length.

          *head_width*: float or None (default: 3*width)
            total width of the full arrow head

          *head_length*: float or None (default: 1.5 * head_width)
            length of arrow head

          *shape*: ['full', 'left', 'right'] (default: 'full')
            draw the left-half, right-half, or full arrow

          *overhang*: float (default: 0)
            fraction that the arrow is swept back (0 overhang means
            triangular shape). Can be negative or greater than one.

          *head_starts_at_zero*: bool (default: False)
            if True, the head starts being drawn at coordinate 0
            instead of ending at coordinate 0.

        Other valid kwargs (inherited from :class:`Patch`) are:
        %(Patch)s

        NrF   g      ø?g        r  r   r   Úleftr  Úrightr-  éþÿÿÿzGot unknown shape: %s)r   r   r	  T)r»   r%  Úarrayr  rz   ÚdotÚsuperr#   )r:   rO   rP   r'  r(  rÓ   Zlength_includes_headÚ
head_widthÚhead_lengthÚshapeZoverhangZhead_starts_at_zeror>   ZdistanceÚlengthZvertsZhwZhlZhsr   Zleft_half_arrowZcoordsZright_half_arrowr*  r+  ÚM)Ú	__class__r?   r@   r#   ž  sJ    !


zFancyArrow.__init__)r,  FNNr-  r   F)
r   rž   rŸ   r    re   r²   r   rÆ   r#   Ú__classcell__r?   r?   )r9  r@   rª   ”  s     rª   z3.0ÚFancyArrowPatch)Zalternativec               @   s@   e Zd ZdZdd„ Zejddd„ƒZd	d
„ Zdd„ Z	dd„ Z
dS )r«   z“
    Yet another arrow class.

    This is an arrow that is defined in display space and has a tip at
    *x1*, *y1* and a base at *x2*, *y2*.
    c             C   s   dS )Nz	YAArrow()r?   )r:   r?   r?   r@   r²     s    zYAArrow.__str__é   çš™™™™™¹?é   c             K   s6   || _ || _|| _|| _|| _tj| f|Ž || _dS )a	  
        Constructor arguments:

        *xytip*
          (*x*, *y*) location of arrow tip

        *xybase*
          (*x*, *y*) location the arrow base mid point

        *figure*
          The `Figure` instance (used to get the dpi setting).

        *width*
          The width of the arrow in points

        *frac*
          The fraction of the arrow length occupied by the head

        *headwidth*
          The width of the base of the arrow head in points

        Valid kwargs are:
        %(Patch)s

        N)ÚxytipÚxybaserÓ   ÚfracÚ	headwidthr   r#   Úfigure)r:   rC  r?  r@  rÓ   rA  rB  r>   r?   r?   r@   r#     s    zYAArrow.__init__c          
   C   s:  | j \}}| j\}}| j| jj d d }| j| jj d d }|  |||||¡\}}}	}
t || || ¡}t 	|| d || d  ¡}|| j
| t |¡  }|| j
| t |¡  }|  |||||¡\}}}}|  |||||¡\}}}}|  ||	||||||g¡}|  ||
||||||g¡}tt ||g¡ddS )Ng      R@g       @T)r	  )r?  r@  rÓ   rC  ÚdpirB  Ú	getpointsÚmathÚatan2ÚsqrtrA  ÚcosÚsinrâ   rã   r   r»   Zcolumn_stack)r:   rÜ   rÝ   Úx2Úy2Zk1Zk2Zxb1Zyb1Zxb2Zyb2Úthetar  ZxmZymZxc1Zyc1Zxc2Zyc2Zxd1Zyd1Zxd2Zyd2ZxsZysr?   r?   r@   rB   +  s    

zYAArrow.get_pathc             C   s   t  ¡ S )N)r	   r7   )r:   r?   r?   r@   r^   C  s    zYAArrow.get_patch_transformc             C   s"  t t|||||fƒ\}}}}}|| dkr>||| ||| fS || dkr^|| ||| |fS || ||  }d| }d}d| }	|d |d |d  d|d    }
|	 t |	d d| |
  ¡ d|  }|| | | }|	 t |	d d| |
  ¡ d|  }|| | | }||||fS )	a  
        For line segment defined by (*x1*, *y1*) and (*x2*, *y2*)
        return the points on the line that is perpendicular to the
        line and intersects (*x2*, *y2*) and the distance from (*x2*,
        *y2*) of the returned points is *k*.
        r   g      ð¿r   r0  g       @g      ð?r  r<  )Úmaprl   rF  rH  )r:   rÜ   rÝ   rK  rL  ÚkÚmZpmÚarv   rk   Zy3aZx3aZy3bZx3br?   r?   r@   rE  F  s    $((zYAArrow.getpointsN)r<  r=  r>  )r   rž   rŸ   r    r²   r   rÆ   r#   rB   r^   rE  r?   r?   r?   r@   r«   ú  s   $r«   c               @   s(   e Zd ZdZdd„ Zejd	dd„ƒZdS )
r¬   z4
    A polygon-approximation of a circle patch.
    c             C   s$   d}|| j d | j d | j| jf S )Nz1CirclePolygon((%g, %g), radius=%g, resolution=%d)r   r   )ró   rK   rô   )r:   r|   r?   r?   r@   r²   f  s    zCirclePolygon.__str__rö   é   c             K   s    t j| |||fddi|—Ž dS )a/  
        Create a circle at *xy* = (*x*, *y*) with given *radius*.
        This circle is approximated by a regular polygon with
        *resolution* sides.  For a smoother circle drawn with splines,
        see :class:`~matplotlib.patches.Circle`.

        Valid kwargs are:
        %(Patch)s

        rú   r   N)r¦   r#   )r:   rÒ   rJ   Z
resolutionr>   r?   r?   r@   r#   j  s
    zCirclePolygon.__init__N)rö   rR  )r   rž   rŸ   r    r²   r   rÆ   r#   r?   r?   r?   r@   r¬   b  s
    r¬   c               @   sZ   e Zd ZdZdd„ Zejddd„ƒZdd„ Zd	d
„ Z	dd„ Z
dd„ Zdd„ ZeeeƒZdS )r­   z
    A scale-free ellipse.
    c             C   s,   | j d | j d | j| j| jf}d}|| S )Nr   r   z3Ellipse(xy=(%s, %s), width=%s, height=%s, angle=%s))Ú_centerrÓ   rÔ   rË   )r:   rÌ   rÍ   r?   r?   r@   r²   ƒ  s    zEllipse.__str__r   c             K   s@   t j| f|Ž || _|| | _| _|| _t ¡ | _t	 
¡ | _dS )a¸  
        Parameters
        ----------
        xy : (float, float)
            xy coordinates of ellipse centre.
        width : float
            Total length (diameter) of horizontal axis.
        height : float
            Total length (diameter) of vertical axis.
        angle : scalar, optional
            Rotation in degrees anti-clockwise.

        Notes
        -----
        Valid keyword arguments are
        %(Patch)s
        N)r   r#   rS  rÓ   rÔ   rË   r   Zunit_circler÷   r	   r7   r  )r:   rÒ   rÓ   rÔ   rË   r>   r?   r?   r@   r#   ‰  s    
zEllipse.__init__c             C   sd   |   | jd ¡|  | jd ¡f}|   | j¡}|  | j¡}t ¡  |d |d ¡ | j	¡j
|Ž | _dS )a  NOTE: This cannot be called until after this has been added
                 to an Axes, otherwise unit conversion will fail. This
                 makes it very important to call the accessor method and
                 not directly access the transformation member variable.
        r   r   g      à?N)râ   rS  rã   rÓ   rÔ   r	   r¶   rû   Z
rotate_degrË   rÀ   r  )r:   r  rÓ   rÔ   r?   r?   r@   Ú_recompute_transform¥  s    zEllipse._recompute_transformc             C   s   | j S )z6
        Return the vertices of the rectangle
        )r÷   )r:   r?   r?   r@   rB   ´  s    zEllipse.get_pathc             C   s   |   ¡  | jS )N)rT  r  )r:   r?   r?   r@   r^   º  s    zEllipse.get_patch_transformc             C   s   || _ d| _dS )zs
        Set the center of the ellipse.

        Parameters
        ----------
        xy : (float, float)
        TN)rS  rd   )r:   rÒ   r?   r?   r@   r   ¾  s    zEllipse.set_centerc             C   s   | j S )z2
        Return the center of the ellipse
        )rS  )r:   r?   r?   r@   Ú
get_centerÉ  s    zEllipse.get_centerN)r   )r   rž   rŸ   r    r²   r   rÆ   r#   rT  rB   r^   r   rU  r¢   r  r?   r?   r?   r@   r­     s   r­   c               @   sB   e Zd ZdZdd„ Zejddd„ƒZdd„ Zd	d
„ Z	e
e	eƒZdS )r¥   z
    A circle patch.
    c             C   s$   | j d | j d | jf}d}|| S )Nr   r   zCircle(xy=(%g, %g), radius=%g))r  rJ   )r:   rÌ   rÍ   r?   r?   r@   r²   Ö  s    zCircle.__str__rö   c             K   s&   t j| ||d |d f|Ž || _dS )a6  
        Create true circle at center *xy* = (*x*, *y*) with given
        *radius*.  Unlike :class:`~matplotlib.patches.CirclePolygon`
        which is a polygonal approximation, this uses Bezier splines
        and is much closer to a scale-free circle.

        Valid kwargs are:
        %(Patch)s

        r  N)r­   r#   rJ   )r:   rÒ   rJ   r>   r?   r?   r@   r#   Û  s    zCircle.__init__c             C   s   d|  | _ | _d| _dS )zl
        Set the radius of the circle

        Parameters
        ----------
        radius : float
        r  TN)rÓ   rÔ   rd   )r:   rJ   r?   r?   r@   r!  ê  s    zCircle.set_radiusc             C   s
   | j d S )z1
        Return the radius of the circle
        g       @)rÓ   )r:   r?   r?   r@   Ú
get_radiusõ  s    zCircle.get_radiusN)rö   )r   rž   rŸ   r    r²   r   rÆ   r#   r!  rV  r¢   rJ   r?   r?   r?   r@   r¥   Ò  s   r¥   c               @   s6   e Zd ZdZdd„ Zejddd„ƒZej	dd	„ ƒZ
d
S )r®   a˜  
    An elliptical arc, i.e. a segment of an ellipse.

    Due to internal optimizations, there are certain restrictions on using Arc:

    - The arc cannot be filled.

    - The arc must be used in an :class:`~.axes.Axes` instance---it can not be
      added directly to a `.Figure`---because it is optimized to only render
      the segments that are inside the axes bounding box with high resolution.
    c             C   s4   | j d | j d | j| j| j| j| jf}d}|| S )Nr   r   zEArc(xy=(%g, %g), width=%g, height=%g, angle=%g, theta1=%g, theta2=%g))r  rÓ   rÔ   rË   r  r  )r:   rÌ   rÍ   r?   r?   r@   r²   
  s    zArc.__str__ç        ç     €v@c       	      K   s>   |  dd¡}|rtdƒ‚tj| ||||f|Ž || _|| _dS )a°  
        Parameters
        ----------
        xy : (float, float)
            The center of the ellipse.

        width : float
            The length of the horizontal axis.

        height : float
            The length of the vertical axis.

        angle : float
            Rotation of the ellipse in degrees (anti-clockwise).

        theta1, theta2 : float, optional
            Starting and ending angles of the arc in degrees. These values
            are relative to *angle*, .e.g. if *angle* = 45 and *theta1* = 90
            the absolute starting angle is 135.
            Default *theta1* = 0, *theta2* = 360, i.e. a complete ellipse.

        Other Parameters
        ----------------
        **kwargs : `.Patch` properties
            Most `.Patch` properties are supported as keyword arguments,
            with the exception of *fill* and *facecolor* because filling is
            not supported.

        %(Patch)s

        r=   FzArc objects can not be filledN)Ú
setdefaultrz   r­   r#   r  r  )	r:   rÒ   rÓ   rÔ   rË   r  r  r>   r=   r?   r?   r@   r#     s    "zArc.__init__c                s  t | dƒstdƒ‚|  ¡  |  | j¡}|  | j¡}dd„ }|| j|| ƒ}|| j|| ƒ}|  	¡  
||f¡\}}d}||k rž||k ržt ||¡| _t | |¡S dd„ ‰ ‡ fdd	„}t ¡ }	t | jj¡|  	¡  ¡  }
|	 |
¡}	tƒ }x¬t|	jd
d… |	jdd
… ƒD ]Š\}}|\}}|\}}xn|||||ƒD ]\\}}t |¡}|dk rVdtj | }t |¡}||  k rx|k r,n n
| |¡ q,W qW t|ƒ|g }|}t  |¡}|	 !t "|¡t #|¡f¡}| j}x>|D ]6}|r t ||d¡| _t | |¡ d}nd}|}qÔW || _d
S )a
  
        Draw the arc to the given *renderer*.

        Notes
        -----
        Ellipses are normally drawn using an approximation that uses
        eight cubic Bezier splines.  The error of this approximation
        is 1.89818e-6, according to this unverified source:

          Lancaster, Don.  *Approximating a Circle or an Ellipse Using
          Four Bezier Cubic Splines.*

          http://www.tinaja.com/glib/ellipse4.pdf

        There is a use case where very large ellipses must be drawn
        with very high accuracy, and it is too expensive to render the
        entire ellipse with enough segments (either splines or line
        segments).  Therefore, in the case where either radius of the
        ellipse is large enough that the error of the spline
        approximation will be visible (greater than one pixel offset
        from the ideal), a different technique is used.

        In that case, only the visible parts of the ellipse are drawn,
        with each visible arc using a fixed number of spline segments
        (8).  The algorithm proceeds as follows:

        1. The points where the ellipse intersects the axes bounding
           box are located.  (This is done be performing an inverse
           transformation on the axes bbox such that it is relative
           to the unit circle -- this makes the intersection
           calculation much easier than doing rotated ellipse
           intersection directly).

           This uses the "line intersecting a circle" algorithm
           from:

               Vince, John.  *Geometry for Computer Graphics: Formulae,
               Examples & Proofs.*  London: Springer-Verlag, 2005.

        2. The angles of each of the intersection points are
           calculated.

        3. Proceeding counterclockwise starting in the positive
           x-direction, each of the visible arc-segments between the
           pairs of vertices are drawn using the Bezier arc
           approximation technique implemented in
           :meth:`matplotlib.path.Path.arc`.
        Úaxesz'Arcs can only be used in Axes instancesc             S   s4   t  | ¡} t  | ¡}t  | ¡}t  t  || |¡¡S )N)r»   Údeg2radrI  rJ  Úrad2degZarctan2)rM  rû   rO   rP   r?   r?   r@   Útheta_stretchx  s    


zArc.draw.<locals>.theta_stretchgø\!ÛÈAc             s   sê   ||  }|| }|| ||  }| | ||  }|| }|| }	|	dkrn|| | }
| | | }|
|fV  nx|	dkræ|dk r„d}nd}t  |	¡}xRdD ]J}|| || | |  | }
| | |t  |¡ |  | }|
|fV  q˜W d S )Ng        g      ð¿g      ð?)g      ð?g      ð¿)r»   rH  r  )rÚ   rÛ   rÜ   rÝ   r'  r(  Zdr2ÚDZD2ZdiscrimrO   rP   Zsign_dyZsqrt_discrimZsignr?   r?   r@   Úiter_circle_intersect_on_line‡  s&    

 z/Arc.draw.<locals>.iter_circle_intersect_on_linec             3   sº   d}|| k r||  }}n
| | }}||k r6|| }}n
|| }}||8 }||8 }||7 }||7 }xTˆ | |||ƒD ]B\}	}
||	  krŒ|krpn qp||
  kr¤|krpn qp|	|
fV  qpW d S )Ng•Ö&è.>r?   )rÚ   rÛ   rÜ   rÝ   ÚepsilonZx0eZx1eZy0eZy1erO   rP   )r_  r?   r@   Ú!iter_circle_intersect_on_line_seg¡  s    

0z3Arc.draw.<locals>.iter_circle_intersect_on_line_segNr  r   r   r  é   FT)$ÚhasattrÚRuntimeErrorrT  râ   rÓ   rã   rÔ   r  r  rA   Útransform_pointr   r  r÷   r   rš   rÕ   r	   rÙ   rZ  rÞ   ÚinvertedZtransformedÚsetÚzipr  r»   ZarccosZpir\  ÚaddÚsortedr[  rN   rI  rJ  )r:   r–   rÓ   rÔ   r]  r  r  Z	inv_errorra  Zbox_pathZbox_path_transformZthetasZp0Zp1rÚ   rÛ   rÜ   rÝ   rO   rP   rM  Z
last_thetaZ
theta1_radrQ   Zpath_originalr?   )r_  r@   rš   <  sX    2

(





zArc.drawN)rW  rW  rX  )r   rž   rŸ   r    r²   r   rÆ   r#   r   r£   rš   r?   r?   r?   r@   r®   þ  s    )r®   Tc             C   s®   |dkri }|  ¡ }| dd¡}| |¡}|  |¡}|j\}}}}	||d 8 }||d 8 }||7 }|	|7 }	t||f||	|d}
|
 t ¡ ¡ |
 	d¡ |
 
|¡ |
 |¡ dS )ad  
    This is a debug function to draw a rectangle around the bounding
    box returned by
    :meth:`~matplotlib.artist.Artist.get_window_extent` of an artist,
    to test whether the artist is returning the correct bbox.

    *props* is a dict of rectangle props with the additional property
    'pad' that sets the padding around the bbox in points.
    NÚpadr<  g       @)rÒ   rÓ   rÔ   r=   F)ÚcopyÚpopr¾   rœ   Úboundsr¤   rZ   r	   r7   Úset_clip_onr9   rš   )r   r–   r³   r=   rk  rÞ   rð   rv   rs   rí   r  r?   r?   r@   Úbbox_artistÞ  s&    




rp  rO  c       	      C   sN   | j \}}}}t||f|||dd}|dk	r6| |¡ | d¡ | |¡ dS )zâ
    This is a debug function to draw a rectangle around the bounding
    box returned by
    :meth:`~matplotlib.artist.Artist.get_window_extent` of an artist,
    to test whether the artist is returning the correct bbox.
    F)rÒ   rÓ   rÔ   r   r=   N)rn  r¤   rZ   ro  rš   )	rÞ   r–   r;   rC   rð   rv   rs   rí   r  r?   r?   r@   Ú	draw_bboxþ  s    

rq  r  c                s‚   dd„ t | Ž D ƒ‰ d dd„ ˆ D ƒ¡}d|d dd„ t | d ˆ ƒD ƒ¡|f‡ fd	d„| d
d… D ƒ|df•}t d |¡d| ¡S )zR
    Given the list of list of strings, return a string of REST table format.
    c             S   s   g | ]}t d d„ |D ƒƒ‘qS )c             s   s   | ]}t |ƒV  qd S )N)r8   )Ú.0Úcellr?   r?   r@   ú	<genexpr>  s    z+_pprint_table.<locals>.<listcomp>.<genexpr>)Úmax)rr  Úcolumnr?   r?   r@   ú
<listcomp>  s    z!_pprint_table.<locals>.<listcomp>z   c             s   s   | ]}d | V  qdS )ú=Nr?   )rr  Úclr?   r?   r@   rt    s    z _pprint_table.<locals>.<genexpr>Ú c             s   s   | ]\}}|  |¡V  qd S )N)Úljust)rr  rs  ry  r?   r?   r@   rt    s    r   c                s&   g | ]}d   dd„ t|ˆ ƒD ƒ¡‘qS )z   c             s   s   | ]\}}|  |¡V  qd S )N)r{  )rr  rs  ry  r?   r?   r@   rt    s    z+_pprint_table.<locals>.<listcomp>.<genexpr>)Újoinrh  )rr  Úrow)Úcol_lenr?   r@   rw    s   r   NÚ
ú )rh  r|  ÚtextwrapÚindent)ÚtableZleadingspaceZtable_formatstrr   r?   )r~  r@   Ú_pprint_table  s    
r„  c             C   sŒ   ddl }dddgg}xnt|  ¡ ƒD ]^\}}| |j¡}|jrfd tdj|j	t
|jƒ d… |jƒ¡}nd}| |jd	| |g¡ q"W t|ƒS )
z¿
    A helper function for the _Style class.  Given the dictionary of
    {stylename: styleclass}, return a formatted string listing all the
    styles. Used to update the documentation.
    r   NZClassÚNameZAttrsz, z{}={}ÚNonez``%s``)Úinspectrj  ÚitemsZgetfullargspecr#   Údefaultsr|  rN  Úformatrï   r8   Úappendr   r„  )Ú_stylesr‡  Z_tableÚnameÚclsÚspecZargstrr?   r?   r@   Ú_pprint_styles&  s    $r  c             C   s   d  d tdj t| ƒƒ¡¡S )z¶
    A helper function for the _Style class.  Given the dictionary of
    {stylename: styleclass}, return a string rep of the list of keys.
    Used to update the documentation.
    z[{}]ú|z '{}' )rŠ  r|  rN  rj  )rŒ  r?   r?   r@   Ú_simpleprint_styles>  s    r’  c               @   s<   e Zd ZdZdd„ Zedd„ ƒZedd„ ƒZedd	„ ƒZd
S )Ú_Stylez®
    A base class for the Styles. It is meant to be a container class,
    where actual styles are declared as subclass of it, and it
    provides some helper functions.
    c             K   s¬   |  dd¡ d¡}|d  ¡ }y| j| }W n  tk
rL   td| ƒ‚Y nX y(dd„ |dd	… D ƒ}d
d„ |D ƒ}W n  tk
r–   td| ƒ‚Y nX | |¡ |f |ŽS )zP
        return the instance of the subclass with the given style name.
        r€  rz  ú,r   zUnknown style : %sc             S   s   g | ]}|  d ¡‘qS )rx  )Úsplit)rr  Zcsr?   r?   r@   rw  ]  s    z"_Style.__new__.<locals>.<listcomp>r   Nc             S   s   i | ]\}}t |ƒ|“qS r?   )rl   )rr  rO  r  r?   r?   r@   ú
<dictcomp>^  s    z"_Style.__new__.<locals>.<dictcomp>zIncorrect style argument : %s)Úreplacer•  rx   Ú_style_listÚKeyErrorrz   r9   )rŽ  Z	stylenameÚkwZ_listÚ_nameÚ_clsZ
_args_pairZ_argsr?   r?   r@   Ú__new__M  s    
z_Style.__new__c             C   s   | j S )zP
        A class method which returns a dictionary of available styles.
        )r˜  )rŽ  r?   r?   r@   Ú
get_stylese  s    z_Style.get_stylesc             C   s
   t | jƒS )zP
        A class method which returns a string of the available styles.
        )r  r˜  )rŽ  r?   r?   r@   Úpprint_stylesl  s    z_Style.pprint_stylesc             C   s,   t || jƒstd|| jf ƒ‚|| j|< dS )z'
        Register a new style.
        z%s must be a subclass of %sN)Ú
issubclassÚ_Baserz   r˜  )rŽ  r  Zstyler?   r?   r@   Úregisters  s    z_Style.registerN)	r   rž   rŸ   r    r  Úclassmethodrž  rŸ  r¢  r?   r?   r?   r@   r“  G  s
   r“  )r  c            C   s.   |dkrt jt| |dS || |p(|j ¡ < |S )z=Class decorator that stashes a class in a (style) dictionary.N)r  )Ú	functoolsÚpartialÚ_register_styler   rx   )Z
style_listrŽ  r  r?   r?   r@   r¦    s    r¦  c               @   s  e Zd ZdZi ZG dd„ deƒZeeƒG dd„ deƒƒZeeƒG dd„ deƒƒZ	eeƒG dd	„ d	eƒƒZ
eeƒG d
d„ de
ƒƒZeeƒG dd„ deƒƒZeeƒG dd„ deƒƒZeeƒG dd„ deƒƒZeeƒG dd„ deƒƒZeeƒG dd„ deƒƒZere e¡deeƒi ZdS )ÚBoxStylea„  
    :class:`BoxStyle` is a container class which defines several
    boxstyle classes, which are used for :class:`FancyBboxPatch`.

    A style object can be created as::

           BoxStyle.Round(pad=0.2)

    or::

           BoxStyle("Round", pad=0.2)

    or::

           BoxStyle("Round, pad=0.2")

    Following boxstyle classes are defined.

    %(AvailableBoxstyles)s

    An instance of any boxstyle class is an callable object,
    whose call signature is::

       __call__(self, x0, y0, width, height, mutation_size, aspect_ratio=1.)

    and returns a :class:`Path` instance. *x0*, *y0*, *width* and
    *height* specify the location and size of the box to be
    drawn. *mutation_scale* determines the overall size of the
    mutation (by which I mean the transformation of the rectangle to
    the fancy box).  *mutation_aspect* determines the aspect-ratio of
    the mutation.
    c               @   s"   e Zd ZdZdd„ Zddd„ZdS )	zBoxStyle._Basea_  
        :class:`BBoxTransmuterBase` and its derivatives are used to make a
        fancy box around a given rectangle. The :meth:`__call__` method
        returns the :class:`~matplotlib.path.Path` of the fancy box. This
        class is not an artist and actual drawing of the fancy box is done
        by the :class:`FancyBboxPatch` class.
        c             C   s   t dƒ‚dS )aƒ  
            The transmute method is a very core of the
            :class:`BboxTransmuter` class and must be overridden in the
            subclasses. It receives the location and size of the
            rectangle, and the mutation_size, with which the amount of
            padding and etc. will be scaled. It returns a
            :class:`~matplotlib.path.Path` instance.
            zDerived must overrideN)r›   )r:   rÚ   rÛ   rÓ   rÔ   Úmutation_sizer?   r?   r@   Ú	transmute¸  s    	zBoxStyle._Base.transmuteç      ð?c       
      C   sz   |dk	rd|| ||  }}|   |||||¡}|j|j }}	|dd…df | |dd…df< t||	ƒS |   |||||¡S dS )aH  
            Given the location and size of the box, return the path of
            the box around it.

              - *x0*, *y0*, *width*, *height* : location and size of the box
              - *mutation_size* : a reference scale for the mutation.
              - *aspect_ratio* : aspect-ration for the mutation.
            Nr   )r©  r  r  r   )
r:   rÚ   rÛ   rÓ   rÔ   r¨  Úaspect_ratiorD   r  r  r?   r?   r@   Ú__call__Ã  s     
zBoxStyle._Base.__call__N)rª  )r   rž   rŸ   r    r©  r¬  r?   r?   r?   r@   r¡  «  s   r¡  c                   s*   e Zd ZdZd‡ fdd„	Zdd„ Z‡  ZS )zBoxStyle.Squarez&
        A simple square box.
        ç333333Ó?c                s   || _ tƒ  ¡  dS )zB
             *pad*
                amount of padding
            N)rk  r3  r#   )r:   rk  )r9  r?   r@   r#   â  s    zBoxStyle.Square.__init__c             C   s   || j  }|d|  |d|   }}|| ||  }}|| ||  }}||f||f||f||f||fg}	tjgtjgd  tjg }
t|	|
ƒS )Nr  rF   )rk  r   r  r  r  )r:   rÚ   rÛ   rÓ   rÔ   r¨  rk  rÜ   rÝ   r  r  r?   r?   r@   r©  ë  s    
"zBoxStyle.Square.transmute)r­  )r   rž   rŸ   r    r#   r©  r:  r?   r?   )r9  r@   ÚSquareÜ  s   	r®  c                   s*   e Zd ZdZd‡ fdd„	Zdd„ Z‡  ZS )zBoxStyle.CirclezA simple circle box.ç333333Ó?c                s   || _ tƒ  ¡  dS )z’
            Parameters
            ----------
            pad : float
                The amount of padding around the original box.
            N)rk  r3  r#   )r:   rk  )r9  r?   r@   r#   ü  s    zBoxStyle.Circle.__init__c             C   s`   || j  }|d|  |d|   }}|| ||  }}t ||d  ||d  ft||ƒd ¡S )Nr  )rk  r   Zcircleru  )r:   rÚ   rÛ   rÓ   rÔ   r¨  rk  r?   r?   r@   r©    s
    
zBoxStyle.Circle.transmute)r¯  )r   rž   rŸ   r    r#   r©  r:  r?   r?   )r9  r@   r¥   ù  s   
r¥   c                   s*   e Zd ZdZd‡ fdd„	Zdd„ Z‡  ZS )zBoxStyle.LArrowz"
        (left) Arrow Box
        ç333333Ó?c                s   || _ tƒ  ¡  d S )N)rk  r3  r#   )r:   rk  )r9  r?   r@   r#     s    zBoxStyle.LArrow.__init__c          
   C   s   || j  }|d|  |d|   }}|| ||  }}|| ||  }}|| d }	|	d }
||d  }||
 |f||f||f||
 |f||
 ||
 f||	 ||	 f||
 ||
 f||
 |f||
 |fg	}tjtjtjtjtjtjtjtjtjg	}t||ƒ}|S )Ng       @g      à?gffffffö?)rk  r   r  r  r  )r:   rÚ   rÛ   rÓ   rÔ   r¨  rk  rÜ   rÝ   r'  ÚdxxÚcpÚcomrD   r?   r?   r@   r©    s     
 
zBoxStyle.LArrow.transmute)r°  )r   rž   rŸ   r    r#   r©  r:  r?   r?   )r9  r@   ÚLArrow  s   r´  c                   s*   e Zd ZdZd‡ fdd„	Zdd„ Z‡  ZS )zBoxStyle.RArrowz#
        (right) Arrow Box
        ç333333Ó?c                s   t ƒ  |¡ d S )N)r3  r#   )r:   rk  )r9  r?   r@   r#   ;  s    zBoxStyle.RArrow.__init__c             C   sF   t j | |||||¡}d| | |jd d …df  |jd d …df< |S )Nr  r   )r§  r´  r©  r  )r:   rÚ   rÛ   rÓ   rÔ   r¨  Úpr?   r?   r@   r©  >  s    
,zBoxStyle.RArrow.transmute)rµ  )r   rž   rŸ   r    r#   r©  r:  r?   r?   )r9  r@   ÚRArrow5  s   r·  c                   s*   e Zd ZdZd‡ fdd„	Zdd„ Z‡  ZS )zBoxStyle.DArrowz$
        (Double) Arrow Box
        ç333333Ó?c                s   || _ tƒ  ¡  d S )N)rk  r3  r#   )r:   rk  )r9  r?   r@   r#   L  s    zBoxStyle.DArrow.__init__c             C   s$  || j  }|d|  }|| ||  }}|| ||  }}|| d }	|	d }
||d  }||
 |f||f|||
 f||	 |
 ||	 f|||
 f||f||
 |f||
 ||
 f||	 ||	 f||
 ||
 f||
 |f||
 |fg}tjtjtjtjtjtjtjtjtjtjtjtjg}t||ƒ}|S )Ng       @r  g      à?gffffffö?)rk  r   r  r  r  )r:   rÚ   rÛ   rÓ   rÔ   r¨  rk  rÜ   rÝ   r'  r±  r²  r³  rD   r?   r?   r@   r©  P  s.    


zBoxStyle.DArrow.transmute)r¸  )r   rž   rŸ   r    r#   r©  r:  r?   r?   )r9  r@   ÚDArrowD  s   r¹  c                   s*   e Zd ZdZd‡ fdd„	Zdd„ Z‡  ZS )	zBoxStyle.Roundz+
        A box with round corners.
        ç333333Ó?Nc                s   || _ || _tƒ  ¡  dS )z”
            *pad*
              amount of padding

            *rounding_size*
              rounding radius of corners. *pad* if None
            N)rk  Úrounding_sizer3  r#   )r:   rk  r»  )r9  r?   r@   r#   |  s    zBoxStyle.Round.__init__c             C   s(  || j  }| jr|| j }n|}|d|  |d|   }}|| ||  }}|| ||  }}	|| |f|| |f||f||| f||	| f||	f|| |	f|| |	f||	f||	| f||| f||f|| |f|| |fg}
tjtjtjtjtjtjtjtjtjtjtjtjtjtjg}t|
|ƒ}|S )Ng       @)rk  r»  r   r  r  ÚCURVE3r  )r:   rÚ   rÛ   rÓ   rÔ   r¨  rk  ÚdrrÜ   rÝ   r²  r³  rD   r?   r?   r@   r©  ˆ  s:    






zBoxStyle.Round.transmute)rº  N)r   rž   rŸ   r    r#   r©  r:  r?   r?   )r9  r@   ÚRoundv  s   r¾  c                   s*   e Zd ZdZd‡ fdd„	Zdd„ Z‡  ZS )	zBoxStyle.Round4z/
        Another box with round edges.
        ç333333Ó?Nc                s   || _ || _tƒ  ¡  dS )z
            *pad*
              amount of padding

            *rounding_size*
              rounding size of edges. *pad* if None
            N)rk  r»  r3  r#   )r:   rk  r»  )r9  r?   r@   r#   º  s    zBoxStyle.Round4.__init__c             C   s\  || j  }| jr|| j }n|d }|d|  d|  |d|  d|   }}|| | || |  }}|| ||  }}	||f|| || f|| || f||f|| || f|| |	| f||	f|| |	| f|| |	| f||	f|| |	| f|| || f||f||fg}
tjtjtjtjtjtjtjtjtjtjtjtjtjtjg}t|
|ƒ}|S )Ng       @r  )rk  r»  r   r  ZCURVE4r  )r:   rÚ   rÛ   rÓ   rÔ   r¨  rk  r½  rÜ   rÝ   r²  r³  rD   r?   r?   r@   r©  Æ  s,    
""""

zBoxStyle.Round4.transmute)r¿  N)r   rž   rŸ   r    r#   r©  r:  r?   r?   )r9  r@   ÚRound4´  s   rÀ  c                   s2   e Zd ZdZd
‡ fdd„	Zdd„ Zdd	„ Z‡  ZS )zBoxStyle.Sawtoothz!
        A sawtooth box.
        ç333333Ó?Nc                s   || _ || _tƒ  ¡  dS )zŠ
            *pad*
              amount of padding

            *tooth_size*
              size of the sawtooth. pad* if None
            N)rk  Ú
tooth_sizer3  r#   )r:   rk  rÂ  )r9  r?   r@   r#   ï  s    zBoxStyle.Sawtooth.__init__c             C   sX  || j  }| jd kr$| j d | }n
| j| }|d }|d|  | |d|  |  }}tt || |d  ¡ƒd }	|| |	 }
tt || |d  ¡ƒd }|| | }|| | || |  }}|| ||  }}|f|| |
d t |	d ¡  || f•}|f|| ||| |g|	 || f•}|f|| ||| |g|	 || f•}|f|| |d t |d ¡  || f•}|f|| |
d t |	d ¡  || f•}|f|| ||| |g|	 || f•}|f|| ||| |g| || f•}|f|| |d t |d ¡  || f•}t||ƒt||ƒt||ƒt||ƒ|d |d ff•}|S )Ng      à?g       @r  r   )rk  rÂ  Úintr»   r   Zarangerh  )r:   rÚ   rÛ   rÓ   rÔ   r¨  rk  rÂ  Ztooth_size2Zdsx_nZdsxZdsy_nZdsyrÜ   rÝ   Zbottom_saw_xZbottom_saw_yZright_saw_xZright_saw_yZ	top_saw_xZ	top_saw_yZ
left_saw_xZ
left_saw_yÚsaw_verticesr?   r?   r@   Ú_get_sawtooth_verticesû  sV    


z(BoxStyle.Sawtooth._get_sawtooth_verticesc             C   s"   |   |||||¡}t|dd}|S )NT)r	  )rÅ  r   )r:   rÚ   rÛ   rÓ   rÔ   r¨  rÄ  rD   r?   r?   r@   r©  E	  s    
zBoxStyle.Sawtooth.transmute)rÁ  N)r   rž   rŸ   r    r#   rÅ  r©  r:  r?   r?   )r9  r@   ÚSawtoothé  s   JrÆ  c                   s*   e Zd ZdZd‡ fdd„	Zdd„ Z‡  ZS )	zBoxStyle.RoundtoothzA rounded tooth box.ç333333Ó?Nc                s   t ƒ  ||¡ dS )zŠ
            *pad*
              amount of padding

            *tooth_size*
              size of the sawtooth. pad* if None
            N)r3  r#   )r:   rk  rÂ  )r9  r?   r@   r#   N	  s    zBoxStyle.Roundtooth.__init__c             C   sf   |   |||||¡}tjt |¡|d ggdd}tjgtjtjgt|ƒd d   tjg }t||ƒS )Nr   )Zaxisr   r  )	rÅ  r»   r  r1  r   r  r¼  r8   r  )r:   rÚ   rÛ   rÓ   rÔ   r¨  rÄ  r  r?   r?   r@   r©  X	  s    "
zBoxStyle.Roundtooth.transmute)rÇ  N)r   rž   rŸ   r    r#   r©  r:  r?   r?   )r9  r@   Ú
RoundtoothK	  s   
rÈ  ÚAvailableBoxstylesN)r   rž   rŸ   r    r˜  Úobjectr¡  r¦  r®  r¥   r´  r·  r¹  r¾  rÀ  rÆ  rÈ  r   Údedentr  r?   r?   r?   r@   r§  ‡  s0    1%1=4ar§  )rÉ  ZListBoxstylesc               @   s¼   e Zd ZdZdZdd„ Zejd,dd	„ƒZejd-d
d„ƒZ	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd d!„ Zd"d#„ Zd$d%„ Zd&d'„ Zd(d)„ Zd*d+„ ZdS ).r¯   a}  
    Draw a fancy box around a rectangle with lower left at *xy*=(*x*,
    *y*) with specified width and height.

    :class:`FancyBboxPatch` class is similar to :class:`Rectangle`
    class, but it draws a fancy box around the rectangle. The
    transformation of the rectangle box to the fancy box is delegated
    to the :class:`BoxTransmuterBase` and its derived classes.

    Tc             C   s$   | j jd }|| j| j| j| jf S )Nz((%g, %g), width=%g, height=%g))r9  r   Ú_xÚ_yrÉ   rÊ   )r:   r|   r?   r?   r@   r²   {	  s    zFancyBboxPatch.__str__r   Nç      ð?c       	      K   sn   t j| f|Ž |d | _|d | _|| _|| _|dkrN|dkrFtdƒ‚|| _n
|  |¡ || _	|| _
d| _dS )aº  
        *xy* = lower left corner

        *width*, *height*

        *boxstyle* determines what kind of fancy box will be drawn. It
        can be a string of the style name with a comma separated
        attribute, or an instance of :class:`BoxStyle`. Following box
        styles are available.

        %(AvailableBoxstyles)s

        *mutation_scale* : a value with which attributes of boxstyle
        (e.g., pad) will be scaled. default=1.

        *mutation_aspect* : The height of the rectangle will be
        squeezed by this value before the mutation and the mutated
        box will be stretched by the inverse of it. default=None.

        Valid kwargs are:
        %(Patch)s
        r   r   ZcustomNz7bbox_transmuter argument is needed with custom boxstyleT)r   r#   rÌ  rÍ  rÉ   rÊ   rz   Ú_bbox_transmuterÚset_boxstyleÚ_mutation_scaleÚ_mutation_aspectrd   )	r:   rÒ   rÓ   rÔ   ÚboxstyleZbbox_transmuterÚmutation_scaleÚmutation_aspectr>   r?   r?   r@   r#   	  s    


zFancyBboxPatch.__init__c             K   sD   |dkrt  ¡ S t|t jƒs$t|ƒr,|| _nt |f|Ž| _d| _dS )a  
        Set the box style.

        *boxstyle* can be a string with boxstyle name with optional
        comma-separated attributes. Alternatively, the attrs can
        be provided as keywords::

            set_boxstyle("round,pad=0.2")
            set_boxstyle("round", pad=0.2)

        Old attrs simply are forgotten.

        Without argument (or with *boxstyle* = None), it returns
        available box styles.

        The following boxstyles are available:
        %(AvailableBoxstyles)s

        ACCEPTS: %(ListBoxstyles)s

        NT)r§  rŸ  rG   r¡  rM   rÏ  rd   )r:   rÓ  rš  r?   r?   r@   rÐ  ±	  s    zFancyBboxPatch.set_boxstylec             C   s   || _ d| _dS )zf
        Set the mutation scale.

        Parameters
        ----------
        scale : float
        TN)rÑ  rd   )r:   rû   r?   r?   r@   Úset_mutation_scaleÑ	  s    z!FancyBboxPatch.set_mutation_scalec             C   s   | j S )z,
        Return the mutation scale.
        )rÑ  )r:   r?   r?   r@   Úget_mutation_scaleÜ	  s    z!FancyBboxPatch.get_mutation_scalec             C   s   || _ d| _dS )zz
        Set the aspect ratio of the bbox mutation.

        Parameters
        ----------
        aspect : float
        TN)rÒ  rd   )r:   Úaspectr?   r?   r@   Úset_mutation_aspectâ	  s    z"FancyBboxPatch.set_mutation_aspectc             C   s   | j S )z?
        Return the aspect ratio of the bbox mutation.
        )rÒ  )r:   r?   r?   r@   Úget_mutation_aspectí	  s    z"FancyBboxPatch.get_mutation_aspectc             C   s   | j S )zReturn the boxstyle object)rÏ  )r:   r?   r?   r@   Úget_boxstyleó	  s    zFancyBboxPatch.get_boxstylec             C   s*   |   ¡ | j| j| j| j|  ¡ |  ¡ ƒ}|S )z:
        Return the mutated path of the rectangle
        )rÛ  rÌ  rÍ  rÉ   rÊ   r×  rÚ  )r:   r÷   r?   r?   r@   rB   ÷	  s
    
zFancyBboxPatch.get_pathc             C   s   | j S )z&Return the left coord of the rectangle)rÌ  )r:   r?   r?   r@   rä   
  s    zFancyBboxPatch.get_xc             C   s   | j S )z(Return the bottom coord of the rectangle)rÍ  )r:   r?   r?   r@   rå   
  s    zFancyBboxPatch.get_yc             C   s   | j S )z!Return the width of the rectangle)rÉ   )r:   r?   r?   r@   rç   
  s    zFancyBboxPatch.get_widthc             C   s   | j S )z"Return the height of the rectangle)rÊ   )r:   r?   r?   r@   rè   
  s    zFancyBboxPatch.get_heightc             C   s   || _ d| _dS )zo
        Set the left coord of the rectangle.

        Parameters
        ----------
        x : float
        TN)rÌ  rd   )r:   rO   r?   r?   r@   ré   
  s    zFancyBboxPatch.set_xc             C   s   || _ d| _dS )zq
        Set the bottom coord of the rectangle.

        Parameters
        ----------
        y : float
        TN)rÍ  rd   )r:   rP   r?   r?   r@   rê   
  s    zFancyBboxPatch.set_yc             C   s   || _ d| _dS )zc
        Set the rectangle width.

        Parameters
        ----------
        w : float
        TN)rÉ   rd   )r:   rs   r?   r?   r@   rì   *
  s    zFancyBboxPatch.set_widthc             C   s   || _ d| _dS )zd
        Set the rectangle height.

        Parameters
        ----------
        h : float
        TN)rÊ   rd   )r:   rí   r?   r?   r@   rî   5
  s    zFancyBboxPatch.set_heightc             G   sL   t |ƒdkr|d \}}}}n|\}}}}|| _|| _|| _|| _d| _dS )zj
        Set the bounds of the rectangle: l,b,w,h

        ACCEPTS: (left, bottom, width, height)
        r   r   TN)r8   rÌ  rÍ  rÉ   rÊ   rd   )r:   rï   rð   rv   rs   rí   r?   r?   r@   rñ   @
  s    zFancyBboxPatch.set_boundsc             C   s   t j | j| j| j| j¡S )N)r	   r×   Zfrom_boundsrÌ  rÍ  rÉ   rÊ   )r:   r?   r?   r@   rò   P
  s    zFancyBboxPatch.get_bbox)r   NrÎ  N)N)r   rž   rŸ   r    re   r²   r   rÆ   r#   rÐ  rÖ  r×  rÙ  rÚ  rÛ  rB   rä   rå   rç   rè   ré   rê   rì   rî   rñ   rò   r?   r?   r?   r@   r¯   m	  s4   
   -r¯   c               @   s¶   e Zd ZdZi ZG dd„ deƒZeeƒG dd„ deƒƒZeeƒG dd„ deƒƒZ	eeƒG dd	„ d	eƒƒZ
eeƒG d
d„ deƒƒZeeƒG dd„ deƒƒZer²e e¡deeƒi ZdS )ÚConnectionStylea0  
    :class:`ConnectionStyle` is a container class which defines
    several connectionstyle classes, which is used to create a path
    between two points. These are mainly used with
    :class:`FancyArrowPatch`.

    A connectionstyle object can be either created as::

           ConnectionStyle.Arc3(rad=0.2)

    or::

           ConnectionStyle("Arc3", rad=0.2)

    or::

           ConnectionStyle("Arc3, rad=0.2")

    The following classes are defined

    %(AvailableConnectorstyles)s


    An instance of any connection style class is an callable object,
    whose call signature is::

        __call__(self, posA, posB,
                 patchA=None, patchB=None,
                 shrinkA=2., shrinkB=2.)

    and it returns a :class:`Path` instance. *posA* and *posB* are
    tuples of x,y coordinates of the two points to be
    connected. *patchA* (or *patchB*) is given, the returned path is
    clipped so that it start (or end) from the boundary of the
    patch. The path is further shrunk by *shrinkA* (or *shrinkB*)
    which is given in points.

    c               @   s8   e Zd ZdZG dd„ dƒZdd„ Zdd„ Zdd
d„Zd	S )zConnectionStyle._Basea“  
        A base class for connectionstyle classes. The subclass needs
        to implement a *connect* method whose call signature is::

          connect(posA, posB)

        where posA and posB are tuples of x, y coordinates to be
        connected.  The method needs to return a path connecting two
        points. This base class defines a __call__ method, and a few
        helper methods.
        c               @   s   e Zd Zdd„ ZdS )z!ConnectionStyle._Base.SimpleEventc             C   s   |\| _ | _d S )N)rO   rP   )r:   rÒ   r?   r?   r@   r#   
  s    z*ConnectionStyle._Base.SimpleEvent.__init__N)r   rž   rŸ   r#   r?   r?   r?   r@   ÚSimpleEventŒ
  s   rÝ  c                s„   ˆ r@‡ fdd„}yt ||ƒ\}}W n tk
r:   |}Y nX |}ˆr€‡fdd„}yt ||ƒ\}}W n tk
rz   |}Y nX |}|S )aI  
            Clip the path to the boundary of the patchA and patchB.
            The starting point of the path needed to be inside of the
            patchA and the end point inside the patch B. The *contains*
            methods of each patch object is utilized to test if the point
            is inside the path.
            c                s   t j | ¡}ˆ  |¡d S )Nr   )rÜ  r¡  rÝ  rR   )Ú
xy_displayÚxy_event)ÚpatchAr?   r@   ÚinsideAš
  s    z,ConnectionStyle._Base._clip.<locals>.insideAc                s   t j | ¡}ˆ  |¡d S )Nr   )rÜ  r¡  rÝ  rR   )rÞ  rß  )ÚpatchBr?   r@   ÚinsideB¦
  s    z,ConnectionStyle._Base._clip.<locals>.insideB)r   rz   )r:   rD   rà  râ  rá  r.  r/  rã  r?   )rà  râ  r@   Ú_clip
  s    	

zConnectionStyle._Base._clipc       
      C   s˜   |rJ|j d \}}t|||ƒ}yt||ƒ\}}|}W n tk
rH   Y nX |r”|j d \}}t|||ƒ}	yt||	ƒ\}}|}W n tk
r’   Y nX |S )z\
            Shrink the path by fixed size (in points) with shrinkA and shrinkB
            r   r  )r  r   r   rz   )
r:   rD   ÚshrinkAÚshrinkBrO   rP   rá  r.  r/  rã  r?   r?   r@   Ú_shrink³
  s"    zConnectionStyle._Base._shrinkç       @Nc       
      C   s,   |   ||¡}|  |||¡}|  |||¡}	|	S )z
            Calls the *connect* method to create a path between *posA*
             and *posB*. The path is clipped and shrunken.
            )Úconnecträ  rç  )
r:   ÚposAÚposBrå  ræ  rà  râ  rD   Zclipped_pathZshrunk_pathr?   r?   r@   r¬  Í
  s    zConnectionStyle._Base.__call__)rè  rè  NN)r   rž   rŸ   r    rÝ  rä  rç  r¬  r?   r?   r?   r@   r¡  
  s
   #r¡  c               @   s"   e Zd ZdZddd„Zdd„ ZdS )	zConnectionStyle.Arc3aM  
        Creates a simple quadratic Bezier curve between two
        points. The curve is created so that the middle control point
        (C1) is located at the same distance from the start (C0) and
        end points(C2) and the distance of the C1 to the line
        connecting C0-C2 is *rad* times the distance of C0-C2.
        ç        c             C   s
   || _ dS )zE
            *rad*
              curvature of the curve.
            N)Úrad)r:   rí  r?   r?   r@   r#   å
  s    zConnectionStyle.Arc3.__init__c             C   sŒ   |\}}|\}}|| d || d  }}|| ||  }	}
| j }|||
  |||	   }}||f||f||fg}tjtjtjg}t||ƒS )Ng       @)rí  r   r  r¼  )r:   rê  rë  rÜ   rÝ   rK  rL  Zx12Zy12r'  r(  Úfr*  Úcyr  r  r?   r?   r@   ré  ì
  s    
zConnectionStyle.Arc3.connectN)rì  )r   rž   rŸ   r    r#   ré  r?   r?   r?   r@   ÚArc3Û
  s   
rð  c               @   s"   e Zd ZdZd	dd„Zdd„ ZdS )
zConnectionStyle.Angle3a
  
        Creates a simple quadratic Bezier curve between two
        points. The middle control points is placed at the
        intersecting point of two lines which cross the start and
        end point, and have a slope of angleA and angleB, respectively.
        éZ   r   c             C   s   || _ || _dS )zˆ
            *angleA*
              starting angle of the path

            *angleB*
              ending angle of the path
            N)ÚangleAÚangleB)r:   rò  ró  r?   r?   r@   r#     s    	zConnectionStyle.Angle3.__init__c          	   C   s¢   |\}}|\}}t  t  | j¡¡}t  t  | j¡¡}t  t  | j¡¡}	t  t  | j¡¡}
t|||||||	|
ƒ\}}||f||f||fg}tjtj	tj	g}t||ƒS )N)
rF  rI  Úradiansrò  rJ  ró  r   r   r  r¼  )r:   rê  rë  rÜ   rÝ   rK  rL  ÚcosAÚsinAÚcosBÚsinBr*  rï  r  r  r?   r?   r@   ré    s    
zConnectionStyle.Angle3.connectN)rñ  r   )r   rž   rŸ   r    r#   ré  r?   r?   r?   r@   ÚAngle3ÿ
  s   
rù  c               @   s"   e Zd ZdZd
dd„Zdd„ Zd	S )zConnectionStyle.AngleaX  
        Creates a piecewise continuous quadratic Bezier path between
        two points. The path has a one passing-through point placed at
        the intersecting point of two lines which cross the start
        and end point, and have a slope of angleA and angleB, respectively.
        The connecting edges are rounded with *rad*.
        rñ  r   ç        c             C   s   || _ || _|| _dS )zÅ
            *angleA*
              starting angle of the path

            *angleB*
              ending angle of the path

            *rad*
              rounding radius of the edge
            N)rò  ró  rí  )r:   rò  ró  rí  r?   r?   r@   r#   /  s    zConnectionStyle.Angle.__init__c          	   C   s€  |\}}|\}}t  t  | j¡¡}t  t  | j¡¡}t  t  | j¡¡}	t  t  | j¡¡}
t|||||||	|
ƒ\}}||fg}tjg}| j	dkrª| 
||f¡ | 
tj¡ n²|| ||  }}|d |d  d }| j	| }|| ||  }}|d |d  d }| j	| }| |||  |||  f||f|||  |||  fg¡ | tjtjtjg¡ | 
||f¡ | 
tj¡ t||ƒS )Ng        r  g      à?)rF  rI  rô  rò  rJ  ró  r   r   r  rí  r‹  r  Úextendr¼  )r:   rê  rë  rÜ   rÝ   rK  rL  rõ  rö  r÷  rø  r*  rï  r  r  Údx1Údy1Zd1Úf1Údx2Údy2Zd2Úf2r?   r?   r@   ré  @  s4    




zConnectionStyle.Angle.connectN)rñ  r   rú  )r   rž   rŸ   r    r#   ré  r?   r?   r?   r@   ÚAngle%  s   
r  c               @   s"   e Zd ZdZd	dd„Zdd„ ZdS )
zConnectionStyle.Arca:  
        Creates a piecewise continuous quadratic Bezier path between
        two points. The path can have two passing-through points, a
        point placed at the distance of armA and angle of angleA from
        point A, another point with respect to point B. The edges are
        rounded with *rad*.
        r   Nç        c             C   s"   || _ || _|| _|| _|| _dS )aH  
            *angleA* :
              starting angle of the path

            *angleB* :
              ending angle of the path

            *armA* :
              length of the starting arm

            *armB* :
              length of the ending arm

            *rad* :
              rounding radius of the edges
            N)rò  ró  ÚarmAÚarmBrí  )r:   rò  ró  r  r  rí  r?   r?   r@   r#   m  s
    zConnectionStyle.Arc.__init__c             C   sv  |\}}|\}}||fg}g }t jg}	| jržt t | j¡¡}
t t | j¡¡}| j| j }| 	|||
  |||  f¡ | j}| 	|||
  |||  f¡ | j
rÐt t | j¡¡}t t | j¡¡}|| j
|  || j
|   }}|rl|d \}}|| ||  }}|| ||  d }| 	|| j| |  || j| |  f¡ | |¡ |	 t jt jt jg¡ n2|d \}}|| ||  }}|| ||  d }|| j }||| |  ||| |  f||fg}|rR|d \}}|| ||  }}|| ||  d }| 	|| j| |  || j| |  f¡ | |¡ |	 t jt jt jg¡ | 	||f¡ |	 	t j¡ t ||	ƒS )Nr  g      à?)r   r  r  rF  rI  rô  rò  rJ  rí  r‹  r  ró  rû  r  r¼  )r:   rê  rë  rÜ   rÝ   rK  rL  r  Zroundedr  rõ  rö  Údr÷  rø  Zx_armBZy_armBZxpZypr'  r(  Úddr?   r?   r@   ré  †  sZ    





zConnectionStyle.Arc.connect)r   r   NNr  )r   rž   rŸ   r    r#   ré  r?   r?   r?   r@   r®   c  s   
r®   c               @   s"   e Zd ZdZd	dd„Zdd„ ZdS )
zConnectionStyle.Bara  
        A line with *angle* between A and B with *armA* and
        *armB*. One of the arms is extended so that they are connected in
        a right angle. The length of armA is determined by (*armA*
        + *fraction* x AB distance). Same for armB.
        ç        ç333333Ó?Nc             C   s   || _ || _|| _|| _dS )aÌ  
            Parameters
            ----------
            armA : float
                minimum length of armA

            armB : float
                minimum length of armB

            fraction : float
                a fraction of the distance between two points that
                will be added to armA and armB.

            angle : float or None
                angle of the connecting line (if None, parallel
                to A and B)
            N)r  r  ÚfractionrË   )r:   r  r  r
  rË   r?   r?   r@   r#   Ê  s    zConnectionStyle.Bar.__init__c             C   s   |\}}| \}}\}}t  || || ¡}	|| ||  }
}|
|
 ||  d }|
| ||  }}| j| j }}| jd k	rt | j¡}|	| }|t  |¡ }|t  |¡ }||t  |¡  ||t  |¡   }}|| }|| ||  }
}|
|
 ||  d }|
| ||  }}nd}t	||ƒ}| j
| | }|||  |||   }}|||  |||   }}||f||f||f||fg}tjtjtjtjg}t||ƒS )Ng      à?g        )rF  rG  r  r  rË   r»   r[  rJ  rI  ru  r
  r   r  r  )r:   rê  rë  rÜ   rÝ   Zx20Zy20rK  rL  r  r'  r(  r  ÚddxÚddyr  r  Ztheta0ZdthetaZdlZdLZdd2Zarmrî  Zcx1Zcy1Zcx2Zcy2r  r  r?   r?   r@   ré  á  s>    &

zConnectionStyle.Bar.connect)r  r  r	  N)r   rž   rŸ   r    r#   ré  r?   r?   r?   r@   ÚBarÁ  s   
r  ÚAvailableConnectorstylesN)r   rž   rŸ   r    r˜  rÊ  r¡  r¦  rð  rù  r  r®   r  r   rË  r  r?   r?   r?   r@   rÜ  U
  s    &\#%=]KrÜ  c       
      C   sL   | | ||  }}||| ||  d  }| ||  |||   }}	||	fS )zj
    find a point along a line connecting (x0, y0) -- (x1, y1) whose
    distance from (x0, y0) is d.
    g      à?r?   )
rÚ   rÛ   rÜ   rÝ   r  r'  r(  ZffrK  rL  r?   r?   r@   Ú_point_along_a_line  s    r  c               @   sÜ  e Zd ZdZi ZG dd„ deƒZG dd„ deƒZeeddG dd	„ d	eƒƒZ	eed
dG dd„ deƒƒZ
eeddG dd„ deƒƒZeeddG dd„ deƒƒZeeddG dd„ deƒƒZeeddG dd„ deƒƒZeeddG dd„ deƒƒZG dd„ deƒZeeddG dd „ d eƒƒZeed!dG d"d#„ d#eƒƒZeed$dG d%d&„ d&eƒƒZeed'dG d(d)„ d)eƒƒZeeƒG d*d+„ d+eƒƒZeeƒG d,d-„ d-eƒƒZeeƒG d.d/„ d/eƒƒZerØe e¡d0eeƒi Zd1S )2Ú
ArrowStylea«  
    :class:`ArrowStyle` is a container class which defines several
    arrowstyle classes, which is used to create an arrow path along a
    given path. These are mainly used with :class:`FancyArrowPatch`.

    A arrowstyle object can be either created as::

           ArrowStyle.Fancy(head_length=.4, head_width=.4, tail_width=.4)

    or::

           ArrowStyle("Fancy", head_length=.4, head_width=.4, tail_width=.4)

    or::

           ArrowStyle("Fancy, head_length=.4, head_width=.4, tail_width=.4")

    The following classes are defined

    %(AvailableArrowstyles)s


    An instance of any arrow style class is a callable object,
    whose call signature is::

        __call__(self, path, mutation_size, linewidth, aspect_ratio=1.)

    and it returns a tuple of a :class:`Path` instance and a boolean
    value. *path* is a :class:`Path` instance along which the arrow
    will be drawn. *mutation_size* and *aspect_ratio* have the same
    meaning as in :class:`BoxStyle`. *linewidth* is a line width to be
    stroked. This is meant to be used to correct the location of the
    head so that it does not overshoot the destination point, but not all
    classes support it.
    c               @   s.   e Zd ZdZedd„ ƒZdd„ Zd
dd„Zd	S )zArrowStyle._BaseaÆ  
        Arrow Transmuter Base class

        ArrowTransmuterBase and its derivatives are used to make a fancy
        arrow around a given path. The __call__ method returns a path
        (which will be used to create a PathPatch instance) and a boolean
        value indicating the path is open therefore is not fillable.  This
        class is not an artist and actual drawing of the fancy arrow is
        done by the FancyArrowPatch class.

        c             C   s\   t |  ¡ ƒ}t|ƒdks<|d d tjks<|d d tjkrDtdƒ‚|d d |d d •S )a3  
            Some ArrowStyle class only works with a simple quadratic Bezier
            curve (created with Arc3Connetion or Angle3Connector). This static
            method is to check if the provided path is a simple quadratic
            Bezier curve and returns its control points if true.
            r  r   r   z,'path' is not a valid quadratic Bezier curve)ÚlistZiter_segmentsr8   r   r  r¼  rz   )rD   Zsegmentsr?   r?   r@   Úensure_quadratic_bezierV  s    z(ArrowStyle._Base.ensure_quadratic_bezierc             C   s   t dƒ‚dS )a’  
            The transmute method is the very core of the ArrowStyle class and
            must be overridden in the subclasses. It receives the path object
            along which the arrow will be drawn, and the mutation_size, with
            which the arrow head etc. will be scaled. The linewidth may be
            used to adjust the path so that it does not pass beyond the given
            points. It returns a tuple of a Path instance and a boolean. The
            boolean value indicate whether the path can be filled or not. The
            return value can also be a list of paths and list of booleans of a
            same length.
            zDerived must overrideN)r›   )r:   rD   r¨  r   r?   r?   r@   r©  e  s    zArrowStyle._Base.transmuteç      ð?c             C   sì   t |ƒ}|dk	rÚ|jdd… |jdd…  }}|dd…df | |dd…df< t||ƒ}|  |||¡\}}	t |	¡rÐg }
xNt|ƒD ]B}|j|j }}|dd…df | |dd…df< |
 t||ƒ¡ q‚W |
|	fS ||	fS n|  |||¡S dS )z‹
            The __call__ method is a thin wrapper around the transmute method
            and takes care of the aspect ratio.
            Nr   )	r   r  r  r   r©  r   Úiterablerh  r‹  )r:   rD   r¨  r   r«  r  r  Zpath_shrunkZpath_mutatedÚfillableÚ	path_listr¶  r  rk   r?   r?   r@   r¬  s  s"     


 
zArrowStyle._Base.__call__N)r  )r   rž   rŸ   r    Ústaticmethodr  r©  r¬  r?   r?   r?   r@   r¡  E  s   r¡  c                   s2   e Zd ZdZd‡ fdd„	Zdd	„ Zd
d„ Z‡  ZS )zArrowStyle._Curvea*  
        A simple arrow which will work with any path instance. The
        returned path is simply concatenation of the original path + at
        most two paths representing the arrow head at the begin point and the
        at the end point. The arrow heads can be either open or closed.
        NFçš™™™™™É?çš™™™™™¹?c                s8   || | _ | _|| | _| _|| | _| _tƒ  ¡  dS )a>  
            The arrows are drawn if *beginarrow* and/or *endarrow* are
            true. *head_length* and *head_width* determines the size
            of the arrow relative to the *mutation scale*.  The
            arrowhead at the begin (or end) is closed if fillbegin (or
            fillend) is True.
            N)Ú
beginarrowÚendarrowr5  r4  Ú	fillbeginÚfillendr3  r#   )r:   r  r  r  r  r5  r4  )r9  r?   r@   r#   œ  s    
zArrowStyle._Curve.__init__c	             C   s  || ||  }	}
t  |	|
¡}d| | }|dkr6d}||	 | }||
 | }|	| | }	|
| | }
||	 ||
  | |	 ||
   }}||	 ||
  ||	 ||
   }}|| | || | f|| || f|| | || | fg}tjtjtjg}||||fS )a  
            Return the paths for arrow heads. Since arrow lines are
            drawn with capstyle=projected, The arrow goes beyond the
            desired point. This method also returns the amount of the path
            to be shrunken so that it does not overshoot.
            g      à?r   r   )r»   r%  r   r  r  )r:   rÚ   rÛ   rÜ   rÝ   Ú	head_distÚcos_tÚsin_tr   r'  r(  Zcp_distanceZpad_projectedr  r  rü  rý  rÿ  r   Úvertices_arrowÚcodes_arrowr?   r?   r@   Ú_get_arrow_wedge«  s$    $"z"ArrowStyle._Curve._get_arrow_wedgec          
   C   sL  | j | }| j| }t |d |d  ¡}|| ||  }}|jd \}	}
|jd \}}| jon|	|kol|
|k }|r–|  |||	|
||||¡\}}}}ng g  }}d\}}|jd \}}|jd \}}| joÚ||koØ||k }|r|  ||||||||¡\}}}}ng g  }}d\}}tt	 
|	| |
| fg|jdd… || || fgg¡|jƒg}dg}|rÐ| jr¶t	 
||d |d gg¡}t	 
|tjtjgg¡}| t||ƒ¡ | d¡ n| t||ƒ¡ | d¡ |rD| jr*| d¡ t	 
||d |d gg¡}t	 
|tjtjgg¡}| t||ƒ¡ n| d¡ | t||ƒ¡ ||fS )	Nr  r   r   )g        g        r0  r  FT)r5  r4  rF  rH  r  r  r#  r  r   r»   r  r  r  r  r  r‹  r  )r:   rD   r¨  r   r5  r4  r  r  r   rÚ   rÛ   rÜ   rÝ   Zhas_begin_arrowÚ	verticesAÚcodesAZddxAZddyArK  rL  Zx3Zy3Zhas_end_arrowÚ	verticesBÚcodesBZddxBZddyBr÷   Z	_fillabler¶  rk   r?   r?   r@   r©  Ö  s\    







zArrowStyle._Curve.transmute)NNFFr  r  )r   rž   rŸ   r    r#   r#  r©  r:  r?   r?   )r9  r@   Ú_Curve”  s     +r(  ú-)r  c                   s    e Zd ZdZ‡ fdd„Z‡  ZS )zArrowStyle.Curvez8
        A simple curve without any arrow head.
        c                s   t ƒ jddd d S )NF)r  r  )r3  r#   )r:   )r9  r?   r@   r#   !  s    zArrowStyle.Curve.__init__)r   rž   rŸ   r    r#   r:  r?   r?   )r9  r@   ÚCurve  s   r*  z<-c                   s"   e Zd ZdZd‡ fdd„	Z‡  ZS )zArrowStyle.CurveAz:
        An arrow with a head at its begin point.
        çš™™™™™Ù?çš™™™™™É?c                s   t ƒ jdd||d dS )zþ
            Parameters
            ----------
            head_length : float, optional, default : 0.4
                Length of the arrow head

            head_width : float, optional, default : 0.2
                Width of the arrow head
            TF)r  r  r5  r4  N)r3  r#   )r:   r5  r4  )r9  r?   r@   r#   *  s    

zArrowStyle.CurveA.__init__)r+  r,  )r   rž   rŸ   r    r#   r:  r?   r?   )r9  r@   ÚCurveA$  s   r-  z->c                   s"   e Zd ZdZd‡ fdd„	Z‡  ZS )zArrowStyle.CurveBz8
        An arrow with a head at its end point.
        çš™™™™™Ù?çš™™™™™É?c                s   t ƒ jdd||d dS )zþ
            Parameters
            ----------
            head_length : float, optional, default : 0.4
                Length of the arrow head

            head_width : float, optional, default : 0.2
                Width of the arrow head
            FT)r  r  r5  r4  N)r3  r#   )r:   r5  r4  )r9  r?   r@   r#   =  s    

zArrowStyle.CurveB.__init__)r.  r/  )r   rž   rŸ   r    r#   r:  r?   r?   )r9  r@   ÚCurveB7  s   r0  z<->c                   s"   e Zd ZdZd‡ fdd„	Z‡  ZS )zArrowStyle.CurveABzJ
        An arrow with heads both at the begin and the end point.
        çš™™™™™Ù?çš™™™™™É?c                s   t ƒ jdd||d dS )zþ
            Parameters
            ----------
            head_length : float, optional, default : 0.4
                Length of the arrow head

            head_width : float, optional, default : 0.2
                Width of the arrow head
            T)r  r  r5  r4  N)r3  r#   )r:   r5  r4  )r9  r?   r@   r#   P  s    

zArrowStyle.CurveAB.__init__)r1  r2  )r   rž   rŸ   r    r#   r:  r?   r?   )r9  r@   ÚCurveABJ  s   r3  z<|-c                   s"   e Zd ZdZd‡ fdd„	Z‡  ZS )zArrowStyle.CurveFilledAzB
        An arrow with filled triangle head at the begin.
        çš™™™™™Ù?çš™™™™™É?c                s   t ƒ jdddd||d dS )zþ
            Parameters
            ----------
            head_length : float, optional, default : 0.4
                Length of the arrow head

            head_width : float, optional, default : 0.2
                Width of the arrow head
            TF)r  r  r  r  r5  r4  N)r3  r#   )r:   r5  r4  )r9  r?   r@   r#   c  s    

z ArrowStyle.CurveFilledA.__init__)r4  r5  )r   rž   rŸ   r    r#   r:  r?   r?   )r9  r@   ÚCurveFilledA]  s   r6  z-|>c                   s"   e Zd ZdZd‡ fdd„	Z‡  ZS )zArrowStyle.CurveFilledBz@
        An arrow with filled triangle head at the end.
        çš™™™™™Ù?çš™™™™™É?c                s   t ƒ jdddd||d dS )zþ
            Parameters
            ----------
            head_length : float, optional, default : 0.4
                Length of the arrow head

            head_width : float, optional, default : 0.2
                Width of the arrow head
            FT)r  r  r  r  r5  r4  N)r3  r#   )r:   r5  r4  )r9  r?   r@   r#   w  s    

z ArrowStyle.CurveFilledB.__init__)r7  r8  )r   rž   rŸ   r    r#   r:  r?   r?   )r9  r@   ÚCurveFilledBq  s   r9  z<|-|>c                   s"   e Zd ZdZd‡ fdd„	Z‡  ZS )zArrowStyle.CurveFilledABzC
        An arrow with filled triangle heads at both ends.
        çš™™™™™Ù?çš™™™™™É?c                s   t ƒ jdddd||d dS )zþ
            Parameters
            ----------
            head_length : float, optional, default : 0.4
                Length of the arrow head

            head_width : float, optional, default : 0.2
                Width of the arrow head
            T)r  r  r  r  r5  r4  N)r3  r#   )r:   r5  r4  )r9  r?   r@   r#   ‹  s    

z!ArrowStyle.CurveFilledAB.__init__)r:  r;  )r   rž   rŸ   r    r#   r:  r?   r?   )r9  r@   ÚCurveFilledAB…  s   r<  c            
   @   s&   e Zd Zd
dd„Zdd„ Zdd	„ ZdS )zArrowStyle._BracketNç      ð?çš™™™™™É?c             C   sJ   || | _ | _|| | _| _|| | _| _|| | _| _|	|
 | _| _	d S )N)
ÚbracketAÚbracketBÚwidthAÚwidthBÚlengthAÚlengthBrò  ró  ÚscaleAÚscaleB)r:   r?  r@  rA  rB  rC  rD  rò  ró  rE  rF  r?   r?   r@   r#   ›  s
    zArrowStyle._Bracket.__init__c             C   s~   ddl m} ||||||ƒ\}}	}
}|| ||  }}|| |	| f||	f|
|f|
| || fg}tjtjtjtjg}||fS )Nr   )Úget_normal_points)Zmatplotlib.bezierrG  r   r  r  )r:   rÚ   rÛ   r  r   rÓ   r7  rG  rÜ   rÝ   rK  rL  r'  r(  r!  r"  r?   r?   r@   Ú_get_bracket¦  s    z ArrowStyle._Bracket._get_bracketc          	   C   sN  | j d kr|}n| j }| jd kr&|}n| j}g g  }}| jr¢|jd \}}	|jd \}
}t|
|||	ƒ\}}|  ||	||| j| | j| ¡\}}| |¡ | |¡ | |j¡ | |j	¡ | j
r(|jd \}}	|jd \}
}t|
|||	ƒ\}}|  ||	||| j| | j| ¡\}}| |¡ | |¡ t |¡}t |¡}t||ƒ}|dfS )Nr   r   r  r0  F)rE  rF  r?  r  r   rH  rA  rC  r‹  r  r@  rB  rD  r»   r  r   )r:   rD   r¨  r   rE  rF  Zvertices_listZ
codes_listrÚ   rÛ   rÜ   rÝ   r  r   r$  r%  r&  r'  r  r  r¶  r?   r?   r@   r©  º  s>    









zArrowStyle._Bracket.transmute)
NNr=  r=  r>  r>  NNNN)r   rž   rŸ   r#   rH  r©  r?   r?   r?   r@   Ú_Bracket™  s       
rI  z]-[c                   s"   e Zd ZdZd‡ fdd„	Z‡  ZS )zArrowStyle.BracketABz:
        An arrow with a bracket(]) at both ends.
        ç      ð?çš™™™™™É?Nc          
      s    t ƒ jdd||||||d dS )a€  
            Parameters
            ----------
            widthA : float, optional, default : 1.0
                Width of the bracket

            lengthA : float, optional, default : 0.2
                Length of the bracket

            angleA : float, optional, default : None
                Angle between the bracket and the line

            widthB : float, optional, default : 1.0
                Width of the bracket

            lengthB : float, optional, default : 0.2
                Length of the bracket

            angleB : float, optional, default : None
                Angle between the bracket and the line
            T)rA  rC  rò  rB  rD  ró  N)r3  r#   )r:   rA  rC  rò  rB  rD  ró  )r9  r?   r@   r#   ì  s    
zArrowStyle.BracketAB.__init__)rJ  rK  NrJ  rK  N)r   rž   rŸ   r    r#   r:  r?   r?   )r9  r@   Ú	BracketABæ  s    rL  z]-c                   s"   e Zd ZdZd‡ fdd„	Z‡  ZS )zArrowStyle.BracketAz9
        An arrow with a bracket(])  at its end.
        ç      ð?çš™™™™™É?Nc                s   t ƒ jdd|||d dS )a]  
            Parameters
            ----------
            widthA : float, optional, default : 1.0
                Width of the bracket

            lengthA : float, optional, default : 0.2
                Length of the bracket

            angleA : float, optional, default : None
                Angle between the bracket and the line
            TN)rA  rC  rò  )r3  r#   )r:   rA  rC  rò  )r9  r?   r@   r#     s    
zArrowStyle.BracketA.__init__)rM  rN  N)r   rž   rŸ   r    r#   r:  r?   r?   )r9  r@   ÚBracketA  s   rO  z-[c                   s"   e Zd ZdZd‡ fdd„	Z‡  ZS )zArrowStyle.BracketBz9
        An arrow with a bracket([)  at its end.
        ç      ð?çš™™™™™É?Nc                s   t ƒ jdd|||d dS )a]  
            Parameters
            ----------
            widthB : float, optional, default : 1.0
                Width of the bracket

            lengthB : float, optional, default : 0.2
                Length of the bracket

            angleB : float, optional, default : None
                Angle between the bracket and the line
            NT)rB  rD  ró  )r3  r#   )r:   rB  rD  ró  )r9  r?   r@   r#   $  s    
zArrowStyle.BracketB.__init__)rP  rQ  N)r   rž   rŸ   r    r#   r:  r?   r?   )r9  r@   ÚBracketB  s   rR  z|-|c                   s"   e Zd ZdZd‡ fdd„	Z‡  ZS )zArrowStyle.BarABz6
        An arrow with a bar(|) at both ends.
        ç      ð?Nc          
      s    t ƒ jdd|d||d|d dS )aÈ  
            Parameters
            ----------
            widthA : float, optional, default : 1.0
                Width of the bracket

            angleA : float, optional, default : None
                Angle between the bracket and the line

            widthB : float, optional, default : 1.0
                Width of the bracket

            angleB : float, optional, default : None
                Angle between the bracket and the line
            Tr   )rA  rC  rò  rB  rD  ró  N)r3  r#   )r:   rA  rò  rB  ró  )r9  r?   r@   r#   :  s    
zArrowStyle.BarAB.__init__)rS  NrS  N)r   rž   rŸ   r    r#   r:  r?   r?   )r9  r@   ÚBarAB4  s    rT  c                   s*   e Zd ZdZd‡ fdd„	Zdd„ Z‡  ZS )	zArrowStyle.SimplezK
        A simple arrow. Only works with a quadratic Bezier curve.
        ç      à?çš™™™™™É?c                s$   |||  | _ | _| _tƒ  ¡  dS )a_  
            Parameters
            ----------
            head_length : float, optional, default : 0.5
                Length of the arrow head

            head_width : float, optional, default : 0.5
                Width of the arrow head

            tail_width : float, optional, default : 0.2
                Width of the arrow tail
            N)r5  r4  Ú
tail_widthr3  r#   )r:   r5  r4  rW  )r9  r?   r@   r#   V  s    zArrowStyle.Simple.__init__c             C   s  |   |¡\}}}}}}	| j| }
t||	|
ƒ}||f||f||	fg}yt||dd\}}W n\ tk
r´   t||	|||
ƒ\}}d||  d||	   }}||f||f||	fg}d }Y nX | j| }t||d dd\}}|d k	rž| j| }t	||d ƒ\}}t
j|d ft
j|d ft
j|d ft
j|d ft
j|d ft
j|d ft
j|d ft
j|d ft
j|d ft
j|d ft
j|d ft
j|d ft
j|d fg}nLt
j|d ft
j|d ft
j|d ft
j|d ft
j|d ft
j|d fg}t
d	d
„ |D ƒdd
„ |D ƒƒ}|dfS )Ng{®Gáz„?)Ú	tolerenceg      à?g       @)Úwmr   r   r  c             S   s   g | ]\}}|‘qS r?   r?   )rr  rk   r¶  r?   r?   r@   rw  Ÿ  s    z/ArrowStyle.Simple.transmute.<locals>.<listcomp>c             S   s   g | ]\}}|‘qS r?   r?   )rr  rk   r¶  r?   r?   r@   rw  Ÿ  s    T)r  r5  r   r   r
   r  r4  r   rW  r   r   r  r¼  r  r  )r:   rD   r¨  r   rÚ   rÛ   rÜ   rÝ   rK  rL  r5  Úin_fÚ
arrow_pathZ	arrow_outZarrow_inÚx1nÚy1nr4  Ú	head_leftÚ
head_rightrW  Ú	tail_leftÚ
tail_rightÚ
patch_pathr?   r?   r@   r©  g  sR    




zArrowStyle.Simple.transmute)rU  rU  rV  )r   rž   rŸ   r    r#   r©  r:  r?   r?   )r9  r@   ÚSimpleP  s   rc  c                   s*   e Zd ZdZd‡ fdd„	Zdd„ Z‡  ZS )zArrowStyle.FancyzJ
        A fancy arrow. Only works with a quadratic Bezier curve.
        çš™™™™™Ù?c                s$   |||  | _ | _| _tƒ  ¡  dS )a_  
            Parameters
            ----------
            head_length : float, optional, default : 0.4
                Length of the arrow head

            head_width : float, optional, default : 0.4
                Width of the arrow head

            tail_width : float, optional, default : 0.4
                Width of the arrow tail
            N)r5  r4  rW  r3  r#   )r:   r5  r4  rW  )r9  r?   r@   r#   ©  s    zArrowStyle.Fancy.__init__c             C   s  |   |¡\}}}}}}	| j| }
||f||f||	fg}t||	|
ƒ}yt||dd\}}W n\ tk
r´   t||	|||
ƒ\}}d||  d||	   }}||f||f||	fg}|}Y nX |}t||	|
d ƒ}t||dd\}}|}| j| }t||d dd\}}| j| }t||d ddd	d
\}}t|||d	 ƒ}t||dd\}}|d }|| }}t	j
|ft	j|d ft	j|d ft	j|d ft	j|d ft	j|d ft	j|d ft	j|d ft	j|d ft	j|d ft	j|d ft	j|d ft	j|ft	j|fg}t	dd„ |D ƒdd„ |D ƒƒ}|dfS )Ng{®Gáz„?)rX  g      à?gš™™™™™é?g       @g333333ã?)rY  g      ð?g333333Ó?)Zw1rY  Zw2r  r   r   r  c             S   s   g | ]\}}|‘qS r?   r?   )rr  rk   r¶  r?   r?   r@   rw    s    z.ArrowStyle.Fancy.transmute.<locals>.<listcomp>c             S   s   g | ]\}}|‘qS r?   r?   )rr  rk   r¶  r?   r?   r@   rw    s    T)r  r5  r   r   r
   r  r4  r   rW  r   r  r  r¼  r  )r:   rD   r¨  r   rÚ   rÛ   rÜ   rÝ   rK  rL  r5  r[  rZ  Zpath_outZpath_inr\  r]  Z	path_headZ	path_tailr4  Zhead_lZhead_rrW  r`  ra  Z
tail_startr_  r^  rb  r?   r?   r@   r©  º  sh    




zArrowStyle.Fancy.transmute)rd  rd  rd  )r   rž   rŸ   r    r#   r©  r:  r?   r?   )r9  r@   ÚFancy£  s   re  c                   s*   e Zd ZdZd‡ fdd„	Zdd„ Z‡  ZS )	zArrowStyle.Wedgezä
        Wedge(?) shape. Only works with a quadratic Bezier curve.  The
        begin point has a width of the tail_width and the end point has a
        width of 0. At the middle, the width is shrink_factor*tail_width.
        ç333333Ó?ç      à?c                s   || _ || _tƒ  ¡  dS )a  
            Parameters
            ----------
            tail_width : float, optional, default : 0.3
                Width of the tail

            shrink_factor : float, optional, default : 0.5
                Fraction of the arrow width at the middle point
            N)rW  Úshrink_factorr3  r#   )r:   rW  rh  )r9  r?   r@   r#     s    
zArrowStyle.Wedge.__init__c          	   C   sÈ   |   |¡\}}}}}}	||f||f||	fg}
t|
| j| d | jd\}}tj|d ftj|d ftj|d ftj|d ftj|d ftj|d ftj|d fg}tdd„ |D ƒdd„ |D ƒƒ}|d	fS )
Ng       @)rY  r   r   r  c             S   s   g | ]\}}|‘qS r?   r?   )rr  rk   r¶  r?   r?   r@   rw  .  s    z.ArrowStyle.Wedge.transmute.<locals>.<listcomp>c             S   s   g | ]\}}|‘qS r?   r?   )rr  rk   r¶  r?   r?   r@   rw  .  s    T)	r  r   rW  rh  r   r  r¼  r  r  )r:   rD   r¨  r   rÚ   rÛ   rÜ   rÝ   rK  rL  r[  Zb_plusZb_minusrb  r?   r?   r@   r©    s    zArrowStyle.Wedge.transmute)rf  rg  )r   rž   rŸ   r    r#   r©  r:  r?   r?   )r9  r@   r¨     s   r¨   ÚAvailableArrowstylesN)r   rž   rŸ   r    r˜  rÊ  r¡  r(  r¦  r*  r-  r0  r3  r6  r9  r<  rI  rL  rO  rR  rT  rc  re  r¨   r   rË  r  r?   r?   r?   r@   r    sJ   #O M!Rb+r  )ri  r  c               @   s®   e Zd ZdZdZdd„ Zejd,d
d„ƒZdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd-dd„Zdd„ Zdd„ Zd d!„ Zd"d#„ Zd$d%„ Zd&d'„ Zd(d)„ Zd*d+„ ZdS ).r;  a%  
    A fancy arrow patch. It draws an arrow using the :class:`ArrowStyle`.

    The head and tail positions are fixed at the specified start and end points
    of the arrow, but the size and shape (in display coordinates) of the arrow
    does not change when the axis is moved or zoomed.
    Tc             C   sP   | j d k	r4| j \\}}\}}| jjd||||f  S | jjdt| jƒf  S d S )Nz((%g, %g)->(%g, %g))z(%s))Ú
_posA_posBr9  r   r±   Ú_path_original)r:   rÜ   rÝ   rK  rL  r?   r?   r@   r²   G  s    
zFancyArrowPatch.__str__NÚsimpleÚarc3r  r   c             K   sì   |dk	rt jddddd |dk	r4t jddddd tj| f|Ž |dk	r||dk	r||dkr|||g| _|dkrpd	}|  |¡ n.|dkr¢|dkr¢|dk	r¢d| _d| _ntd
ƒ‚|| _|	| _	|
| _
|| _|| _|  |¡ || _|| _|  |¡ dS )a  
        If *posA* and *posB* are given, a path connecting two points is
        created according to *connectionstyle*. The path will be
        clipped with *patchA* and *patchB* and further shrunken by
        *shrinkA* and *shrinkB*. An arrow is drawn along this
        resulting path using the *arrowstyle* parameter.

        Alternatively if *path* is provided, an arrow is drawn along this path
        and *patchA*, *patchB*, *shrinkA*, and *shrinkB* are ignored.

        Parameters
        ----------

        posA, posB : None, tuple, optional (default: None)
            (x,y) coordinates of arrow tail and arrow head respectively.

        path : None, Path (default: None)
            :class:`matplotlib.path.Path` instance. If provided, an arrow is
            drawn along this path and *patchA*, *patchB*, *shrinkA*, and
            *shrinkB* are ignored.

        arrowstyle : str or ArrowStyle, optional (default: 'simple')
            Describes how the fancy arrow will be
            drawn. It can be string of the available arrowstyle names,
            with optional comma-separated attributes, or an
            :class:`ArrowStyle` instance. The optional attributes are meant to
            be scaled with the *mutation_scale*. The following arrow styles are
            available:

            %(AvailableArrowstyles)s

        arrow_transmuter :
            Ignored

        connectionstyle : str, ConnectionStyle, or None, optional
        (default: 'arc3')
            Describes how *posA* and *posB* are connected. It can be an
            instance of the :class:`ConnectionStyle` class or a string of the
            connectionstyle name, with optional comma-separated attributes. The
            following connection styles are available:

            %(AvailableConnectorstyles)s

        connector :
            Ignored

        patchA, patchB : None, Patch, optional (default: None)
            Head and tail patch respectively. :class:`matplotlib.patch.Patch`
            instance.

        shrinkA, shrinkB : scalar, optional (default: 2)
            Shrinking factor of the tail and head of the arrow respectively

        mutation_scale : scalar, optional (default: 1)
            Value with which attributes of *arrowstyle* (e.g., *head_length*)
            will be scaled.

        mutation_aspect : None, scalar, optional (default: None)
            The height of the rectangle will be squeezed by this value before
            the mutation and the mutated box will be stretched by the inverse
            of it.

        dpi_cor : scalar, optional (default: 1)
            dpi_cor is currently used for linewidth-related things and shrink
            factor. Mutation scale is affected by this.

        Notes
        -----
        Valid kwargs are:
        %(Patch)s
        Ng      @zZThe "arrow_transmuter" keyword argument is not used, and will be removed in Matplotlib 3.1Úarrow_transmuterzkeyword argument)Úmessager  Zobj_typezSThe "connector" keyword argument is not used, and will be removed in Matplotlib 3.1r  rm  z.either posA and posB, or path need to provided)r   Zwarn_deprecatedr   r#   rj  Úset_connectionstyleZ
_connetorsrz   rà  râ  rå  ræ  rk  Úset_arrowstylerÑ  rÒ  Úset_dpi_cor)r:   rê  rë  rD   Ú
arrowstylern  Úconnectionstyler  rà  râ  rå  ræ  rÔ  rÕ  Údpi_corr>   r?   r?   r@   r#   Q  s>    V

zFancyArrowPatch.__init__c             C   s   || _ d| _dS )zÇ
        dpi_cor is currently used for linewidth-related things and
        shrink factor. Mutation scale is affected by this.

        Parameters
        ----------
        dpi_cor : scalar
        TN)Ú_dpi_corrd   )r:   ru  r?   r?   r@   rr  Ò  s    	zFancyArrowPatch.set_dpi_corc             C   s   | j S )zÁ
        dpi_cor is currently used for linewidth-related things and
        shrink factor. Mutation scale is affected by this.

        Returns
        -------
        dpi_cor : scalar
        )rv  )r:   r?   r?   r@   Úget_dpi_corÞ  s    	zFancyArrowPatch.get_dpi_corc             C   s.   |dk	r|| j d< |dk	r$|| j d< d| _dS )a  
        Set the begin and end positions of the connecting path.

        Parameters
        ----------
        posA, posB : None, tuple
            (x,y) coordinates of arrow tail and arrow head respectively. If
            `None` use current value.
        Nr   r   T)rj  rd   )r:   rê  rë  r?   r?   r@   Úset_positionsé  s
    


zFancyArrowPatch.set_positionsc             C   s   || _ d| _dS )z™
        Set the tail patch.

        Parameters
        ----------
        patchA : Patch
            :class:`matplotlib.patch.Patch` instance.
        TN)rà  rd   )r:   rà  r?   r?   r@   Ú
set_patchAù  s    	zFancyArrowPatch.set_patchAc             C   s   || _ d| _dS )z™
        Set the head patch.

        Parameters
        ----------
        patchB : Patch
            :class:`matplotlib.patch.Patch` instance.
        TN)râ  rd   )r:   râ  r?   r?   r@   Ú
set_patchB  s    	zFancyArrowPatch.set_patchBc             K   sD   |dkrt  ¡ S t|t jƒs$t|ƒr,|| _nt |f|Ž| _d| _dS )a€  
        Set the connection style. Old attributes are forgotten.

        Parameters
        ----------
        connectionstyle : None, ConnectionStyle instance, or string
            Can be a string with connectionstyle name with
            optional comma-separated attributes, e.g.::

                set_connectionstyle("arc,angleA=0,armA=30,rad=10")

            Alternatively, the attributes can be provided as keywords, e.g.::

                set_connectionstyle("arc", angleA=0,armA=30,rad=10)

            Without any arguments (or with ``connectionstyle=None``), return
            available styles as a list of strings.
        NT)rÜ  rŸ  rG   r¡  rM   Ú
_connectorrd   )r:   rt  rš  r?   r?   r@   rp    s    z#FancyArrowPatch.set_connectionstylec             C   s   | j S )z?
        Return the :class:`ConnectionStyle` instance.
        )r{  )r:   r?   r?   r@   Úget_connectionstyle/  s    z#FancyArrowPatch.get_connectionstylec             K   s<   |dkrt  ¡ S t|t jƒr$|| _nt |f|Ž| _d| _dS )aO  
        Set the arrow style. Old attributes are forgotten. Without arguments
        (or with ``arrowstyle=None``) returns available box styles as a list of
        strings.

        Parameters
        ----------
        arrowstyle : None, ArrowStyle, str, optional (default: None)
            Can be a string with arrowstyle name with optional comma-separated
            attributes, e.g.::

                set_arrowstyle("Fancy,head_length=0.2")

            Alternatively attributes can be provided as keywords, e.g.::

                set_arrowstyle("fancy", head_length=0.2)

        NT)r  rŸ  rG   r¡  Ú_arrow_transmuterrd   )r:   rs  rš  r?   r?   r@   rq  5  s    zFancyArrowPatch.set_arrowstylec             C   s   | j S )z/
        Return the arrowstyle object.
        )r}  )r:   r?   r?   r@   Úget_arrowstyleR  s    zFancyArrowPatch.get_arrowstylec             C   s   || _ d| _dS )zg
        Set the mutation scale.

        Parameters
        ----------
        scale : scalar
        TN)rÑ  rd   )r:   rû   r?   r?   r@   rÖ  X  s    z"FancyArrowPatch.set_mutation_scalec             C   s   | j S )zd
        Return the mutation scale.

        Returns
        -------
        scale : scalar
        )rÑ  )r:   r?   r?   r@   r×  c  s    z"FancyArrowPatch.get_mutation_scalec             C   s   || _ d| _dS )z{
        Set the aspect ratio of the bbox mutation.

        Parameters
        ----------
        aspect : scalar
        TN)rÒ  rd   )r:   rØ  r?   r?   r@   rÙ  m  s    z#FancyArrowPatch.set_mutation_aspectc             C   s   | j S )z?
        Return the aspect ratio of the bbox mutation.
        )rÒ  )r:   r?   r?   r@   rÚ  x  s    z#FancyArrowPatch.get_mutation_aspectc             C   s0   |   ¡ \}}t |¡rt|ƒ}|  ¡  ¡  |¡S )z°
        Return the path of the arrow in the data coordinates. Use
        get_path_in_displaycoord() method to retrieve the arrow path
        in display coordinates.
        )Úget_path_in_displaycoordr   r  r   rA   rf  Útransform_path)r:   r÷   r  r?   r?   r@   rB   ~  s    
zFancyArrowPatch.get_pathc             C   s¦   |   ¡ }| jdk	rd|  ¡  | jd ¡}|  ¡  | jd ¡}|  ¡ ||| j| j| j| | j| d}n|  ¡  	| j
¡}|  ¡ ||  ¡ | |  ¡ | |  ¡ ƒ\}}||fS )zN
        Return the mutated path of the arrow in display coordinates.
        Nr   r   )rà  râ  rå  ræ  )rw  rj  rA   re  r|  rà  râ  rå  ræ  r€  rk  r~  r×  rI   rÚ  )r:   ru  rê  rë  r÷   r  r?   r?   r@   r  ‹  s     



z(FancyArrowPatch.get_path_in_displaycoordc             C   sâ  |   ¡ sd S | d|  ¡ ¡ | ¡ }|j| jdd | j}| jd dkrLd}| |¡ | | j	| j
¡ | | j¡ |  |¡ | d¡ | |  ¡ ¡ | j}|d dkrªd }| | j¡ | jr| | j¡ | jd k	ry| | j¡ W n  tk
r   t d¡ Y nX |  ¡ d k	r$|j|  ¡ Ž  |  | d¡¡ |  ¡ \}}t  !|¡sX|g}|g}t" #¡ }|  $¡ r„dd	l%m&} ||  $¡ |ƒ}x@t'||ƒD ]2\}	}
|
r°| (||	||¡ n| (||	|d ¡ qW | )¡  | *d¡ d
| _+d S )Nr‚   T)rƒ   rF   r   r   z6Your backend does not support setting the hatch color.g      ð?)r„   F),r…   r†   r‡   rˆ   r‰   rU   r/   r2   rŠ   rq   rr   r3   r_   r‹   r5   rŒ   r   rV   rn   rf   rY   r4   r'   rg   rŽ   r)   r*   r   r   rr  r¾   r  r   r  r	   r7   r‘   r’   r„   rh  r“   r”   r•   rd   )r:   r–   r—   r   r˜   rD   r  r™   r„   r¶  rî  r?   r?   r@   rš   ©  sV    




zFancyArrowPatch.draw)NNNrl  Nrm  NNNr  r  r   Nr   )N)r   rž   rŸ   r    re   r²   r   rÆ   r#   rr  rw  rx  ry  rz  rp  r|  rq  r~  rÖ  r×  rÙ  rÚ  rB   r  rš   r?   r?   r?   r@   r;  =  sB   
            t

c               @   sZ   e Zd ZdZdd„ Zejddd„ƒZddd„Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ ZdS )ÚConnectionPatchz
    A :class:`~matplotlib.patches.ConnectionPatch` class is to make
    connecting lines between two points (possibly in different axes).
    c             C   s(   d| j d | j d | jd | jd f S )Nz#ConnectionPatch((%g, %g), (%g, %g))r   r   )Úxy1Úxy2)r:   r?   r?   r@   r²   ñ  s    zConnectionPatch.__str__Nr)  rm  ç        ç      $@Fç      ð?c             K   sj   |dkr|}|| _ || _|| _|| _|| _|| _tj| fdd|||	|
||||||||dœ|—Ž d| _dS )a 	  
        Connect point *xyA* in *coordsA* with point *xyB* in *coordsB*


        Valid keys are


        ===============  ======================================================
        Key              Description
        ===============  ======================================================
        arrowstyle       the arrow style
        connectionstyle  the connection style
        relpos           default is (0.5, 0.5)
        patchA           default is bounding box of the text
        patchB           default is None
        shrinkA          default is 2 points
        shrinkB          default is 2 points
        mutation_scale   default is text size (in points)
        mutation_aspect  default is 1.
        ?                any key for :class:`matplotlib.patches.PathPatch`
        ===============  ======================================================


        *coordsA* and *coordsB* are strings that indicate the
        coordinates of *xyA* and *xyB*.

        =================   ===================================================
        Property            Description
        =================   ===================================================
        'figure points'     points from the lower left corner of the figure
        'figure pixels'     pixels from the lower left corner of the figure
        'figure fraction'   0,0 is lower left of figure and 1,1 is upper, right
        'axes points'       points from lower left corner of axes
        'axes pixels'       pixels from lower left corner of axes
        'axes fraction'     0,1 is lower left of axes and 1,1 is upper right
        'data'              use the coordinate system of the object being
                            annotated (default)
        'offset points'     Specify an offset (in points) from the *xy* value

        'polar'             you can specify *theta*, *r* for the annotation,
                            even in cartesian plots.  Note that if you
                            are using a polar axes, you do not need
                            to specify polar for the coordinate
                            system since that is the native "data" coordinate
                            system.
        =================   ===================================================

        N)r   r   )r   r   )rê  rë  rs  rn  rt  r  rà  râ  rå  ræ  rÔ  rÕ  Úclip_onru  )	r‚  rƒ  Úcoords1Úcoords2ÚaxesAÚaxesBr;  r#   Ú_annotation_clip)r:   ZxyAZxyBZcoordsAZcoordsBrŠ  r‹  rs  rn  rt  r  rà  râ  rå  ræ  rÔ  rÕ  r‡  ru  r>   r?   r?   r@   r#   õ  s0    @zConnectionPatch.__init__c             C   s  |dkr| j }|dkrF|j}t|  |¡ƒ}t|  |¡ƒ}| ||f¡S |dkr¾| j\}}| jdkrp|  ||d¡S |  ||| j¡\}}| j	 
¡ }||d 9 }||d 9 }||7 }||7 }||fS |dkr|| }	}
|
t |	¡ }|
t |	¡ }|j}| ||f¡S |dkrz| j	j}| j	jj\}}}}|| }
|| }||d 9 }||d 9 }|dk r`|
| }|dk rr|| }||fS |dkrÒ| j	jj\}}}}|| }
|| }|dk r¸|
| }|dk rÊ|| }||fS |d	krò| j	j}| ||f¡S |d
kr„| j	j}|jj\}}}}|| }
|| }|dk r@|
|| d  }n||| d  }|dk rl||| d  }n||| d  }||fS |dkrî|jj\}}}}|| }
|| }|dk rÂ|
| }n|| }|dk rÞ|| }n|| }||fS |dkr|j}| ||f¡S dS )z=
        calculate the pixel position of given point
        NÚdatazoffset pointsg      R@Zpolarzfigure pointsr   zfigure pixelszfigure fractionzaxes pointszaxes pixelszaxes fraction)rZ  Z	transDatarl   râ   rã   re  rÒ   Zxycoordsrý   rC  Zget_dpir»   rI  rJ  rD  rÞ   rn  ZtransFigureZ	transAxes)r:   rO   rP   r|   rZ  rC   r'  r(  rD  rM  r  rð   rv   rs   rí   Útr?   r?   r@   rý   S  s”    




















zConnectionPatch._get_xyc             C   s   || _ d| _dS )aM  
        set *annotation_clip* attribute.

          * True: the annotation will only be drawn when self.xy is inside the
                   axes.
          * False: the annotation will always be drawn regardless of its
                    position.
          * None: the self.xy will be checked only if *xycoords* is "data"
        TN)rŒ  rd   )r:   rv   r?   r?   r@   Úset_annotation_clip¹  s    
z#ConnectionPatch.set_annotation_clipc             C   s   | j S )z
        Return *annotation_clip* attribute.
        See :meth:`set_annotation_clip` for the meaning of return values.
        )rŒ  )r:   r?   r?   r@   Úget_annotation_clipÆ  s    z#ConnectionPatch.get_annotation_clipc             C   sž   |   ¡ }| j\}}|  ||| j| j¡}| j\}}|  ||| j| j¡}|  ¡ ||| j	| j
| j| | j| d}|  ¡ ||  ¡ | |  ¡ | |  ¡ ƒ\}}||fS )zK
        Return the mutated path of the arrow in the display coord
        )rà  râ  rå  ræ  )rw  r‚  rý   rˆ  rŠ  rƒ  r‰  r‹  r|  rà  râ  rå  ræ  r~  r×  rI   rÚ  )r:   ru  rO   rP   rê  rë  r÷   r  r?   r?   r@   r  Í  s     




z(ConnectionPatch.get_path_in_displaycoordc             C   sª   |   ¡ }|s|dkrL| jdkrL| j\}}|  ||| j| j¡}| j |¡sLdS |sb|dkr¦| jdkr¦| j\}}|  ||| j| j	¡}| j	dkr’| j}n| j	}| |¡s¦dS dS )z/Check whether the annotation needs to be drawn.Nr  FT)
r  rˆ  r‚  rý   rŠ  rZ  rN   r‰  rƒ  r‹  )r:   r–   rv   rO   rP   Zxy_pixelrZ  r?   r?   r@   Ú	_check_xyê  s    



zConnectionPatch._check_xyc             C   s4   |d k	r|| _ |  ¡ r |  |¡s$d S t | |¡ d S )N)Z	_rendererr…   r‘  r;  rš   )r:   r–   r?   r?   r@   rš     s
    zConnectionPatch.draw)NNNr)  Nrm  NNNr„  r„  r…  NFr†  )N)r   rž   rŸ   r    r²   r   rÆ   r#   rý   r  r  r  r‘  rš   r?   r?   r?   r@   r  ì  s.                P
fr  )NT)rO  N)r  )N)Hr¤  rF  Znumbersr   r  r)   Znumpyr»   Z
matplotlibr$   rz  r   r   r   r   r   ro   r	   Zbezierr
   r   r   r   r   r   r   r   r   r   rD   r   Z_define_aliasesr"   r   ZkwdocZpatchdocrO  Zinterpdr9   rÆ   r#   r°   r¤   r¦   r  r§   r¨   r©   rª   r    Z
deprecatedr«   r¬   r­   r¥   r®   rp  rq  r„  r  r’  rÊ  r“  r¦  r§  r˜  r¯   rÜ  r  r  r;  r  r?   r?   r?   r@   Ú<module>   sš    0
    

@ *Vg[CcgS, a
 

	8   d i   @         2