o
    hG                     @   s   d Z ddlmZ ddlmZ ddlmZ ddlmZ	 ddl
mZ ddlZG dd	 d	ZG d
d deZG dd deZdd ZG dd deZeedZG dd deZeedZG dd deZG dd deZG dd deZeedZdS )z
Defines classes for path effects. The path effects are supported in `.Text`,
`.Line2D` and `.Patch`.

.. seealso::
   :ref:`patheffects_guide`
    )RendererBase)colors)patches)
transforms)PathNc                   @   s4   e Zd ZdZdddZdd Zdd Zdd
dZd	S )AbstractPathEffectz
    A base class for path effects.

    Subclasses should override the ``draw_path`` method to add effect
    functionality.
            r	   c                 C   s
   || _ dS )z
        Parameters
        ----------
        offset : (float, float), default: (0, 0)
            The (x, y) offset to apply to the path, measured in points.
        N)_offset)selfoffset r   j/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/matplotlib/patheffects.py__init__   s   
zAbstractPathEffect.__init__c                 C   s   t  jt|j| j S )z(Apply the offset to the given transform.)mtransformsAffine2D	translatemappoints_to_pixelsr
   )r   rendererr   r   r   _offset_transform"   s   z$AbstractPathEffect._offset_transformc                 C   sl   |  }|dd}|r|jdi | | D ]\}}t|d| d}t|s/td| || q|S )z
        Update the given GraphicsContext with the given dict of properties.

        The keys in the dictionary are used to identify the appropriate
        ``set_`` method on the *gc*.
        dashesNset_zUnknown property r   )copypop
set_dashesitemsgetattrcallableAttributeError)r   gcnew_gc_dictr   kv
set_methodr   r   r   
_update_gc'   s   
zAbstractPathEffect._update_gcNc                 C   s    t |tr|j}|||||S )z
        Derived should override this method. The arguments are the same
        as :meth:`matplotlib.backend_bases.RendererBase.draw_path`
        except the first argument is a renderer.
        )
isinstancePathEffectRenderer	_renderer	draw_pathr   r   r    tpathaffinergbFacer   r   r   r)   ;   s   
zAbstractPathEffect.draw_path)r   N)__name__
__module____qualname____doc__r   r   r%   r)   r   r   r   r   r      s    
	r   c                       s`   e Zd ZdZdd Zdd Zdd Zdd	d
Z fddZ fddZ	dddZ
dd Z  ZS )r'   aw  
    Implements a Renderer which contains another renderer.

    This proxy then intercepts draw calls, calling the appropriate
    :class:`AbstractPathEffect` draw method.

    .. note::
        Not all methods have been overridden on this RendererBase subclass.
        It may be necessary to add further methods to extend the PathEffects
        capabilities further.
    c                 C   s   || _ || _dS )z
        Parameters
        ----------
        path_effects : iterable of :class:`AbstractPathEffect`
            The path effects which this renderer represents.
        renderer : `~matplotlib.backend_bases.RendererBase` subclass

        N)_path_effectsr(   )r   path_effectsr   r   r   r   r   T   s   	
zPathEffectRenderer.__init__c                 C   s   |  || jS r.   )	__class__r(   )r   r4   r   r   r   copy_with_path_effect`      z(PathEffectRenderer.copy_with_path_effectc                 C   s    |dv r
t | j|S t| |S )N)flipyget_canvas_width_heightnew_gcr   
_text2pathheightwidth)r   r(   object__getattribute__)r   namer   r   r   r?   c   s   z#PathEffectRenderer.__getattribute__Nc                 C   s$   | j D ]}|| j|||| qd S r.   )r3   r)   r(   )r   r    r+   r,   r-   path_effectr   r   r   r)   j   s
   
zPathEffectRenderer.draw_pathc           	         sh   t | jdkrt j||||g|R i |S | jD ]}| |g}|j||||g|R i | qd S N   )lenr3   superdraw_markersr6   )	r   r    marker_pathmarker_transpathargskwargsrA   r   r5   r   r   rF   o   s   
zPathEffectRenderer.draw_markersc                    sd   t | jdkrt j|||g|R i |S | jD ]}| |g}|j|||g|R i | qd S rB   )rD   r3   rE   draw_path_collectionr6   )r   r    master_transformpathsrJ   rK   rA   r   rL   r   r   rM      s   
z'PathEffectRenderer.draw_path_collectionc                 C   s   | j ||S r.   )r(   
open_group)r   sgidr   r   r   rP      r7   zPathEffectRenderer.open_groupc                 C   s   | j |S r.   )r(   close_group)r   rQ   r   r   r   rS      s   zPathEffectRenderer.close_groupr.   )r/   r0   r1   r2   r   r6   r?   r)   rF   rM   rP   rS   __classcell__r   r   rL   r   r'   G   s    

r'   c                   @   s   e Zd ZdZdS )Normalz
    The "identity" PathEffect.

    The Normal PathEffect's sole purpose is to draw the original artist with
    no special path effect.
    N)r/   r0   r1   r2   r   r   r   r   rU      s    rU   c                 C   s\   G dd d| }d| j  |_ d| j  |_d| j  d| j  d| j  d|_| jj|j_|S )zO
    Create a PathEffect class combining *effect_class* and a normal draw.
    c                       s   e Zd Z fddZ  ZS )z)_subclass_with_normal.<locals>.withEffectc                    s(   t  ||||| ||||| d S r.   )rE   r)   r*   rL   r   r   r)      s   z3_subclass_with_normal.<locals>.withEffect.draw_path)r/   r0   r1   r)   rT   r   r   rL   r   
withEffect   s    rV   withz*
    A shortcut PathEffect for applying `.z` and then
    drawing the original Artist.

    With this class you can use ::

        artist.set_path_effects([patheffects.withzM()])

    as a shortcut for ::

        artist.set_path_effects([patheffects.z@(),
                                 patheffects.Normal()])
    )r/   r1   r2   r)   )effect_classrV   r   r   r   _subclass_with_normal   s   

rY   c                       *   e Zd ZdZd fdd	Zdd Z  ZS )Strokez0A line based PathEffect which re-draws a stroke.r   r   c                    s   t  | || _dS )z
        The path will be stroked with its gc updated with the given
        keyword arguments, i.e., the keyword arguments should be valid
        gc parameter values.
        N)rE   r   _gcr   r   rK   rL   r   r   r      s   
zStroke.__init__c                 C   sF   |  }|| | || j}||||| | | |  dS )Draw the path with updated gc.N)r:   copy_propertiesr%   r]   r)   r   restore)r   r   r    r+   r,   r-   gc0r   r   r   r)      s   
zStroke.draw_pathr\   r/   r0   r1   r2   r   r)   rT   r   r   rL   r   r[      s    	r[   )rX   c                       s0   e Zd ZdZ			d	 fdd	Zdd Z  ZS )
SimplePatchShadowz#A simple shadow via a filled patch.   N333333?c                    sJ   t  | |du r|| _nt|| _|du rd}|| _|| _|| _dS )aR  
        Parameters
        ----------
        offset : (float, float), default: (2, -2)
            The (x, y) offset of the shadow in points.
        shadow_rgbFace : :mpltype:`color`
            The shadow color.
        alpha : float, default: 0.3
            The alpha transparency of the created shadow patch.
        rho : float, default: 0.3
            A scale factor to apply to the rgbFace color if *shadow_rgbFace*
            is not specified.
        **kwargs
            Extra keywords are stored and passed through to
            :meth:`AbstractPathEffect._update_gc`.

        Nri   )rE   r   _shadow_rgbFacemcolorsto_rgba_alpha_rhor]   )r   r   shadow_rgbFacealpharhorK   rL   r   r   r      s   
zSimplePatchShadow.__init__c                 C   s   |  }|| | jdu r(|pddd \}}}	|| j || j |	| j f}
n| j}
|d || j |d | || j	}|
|||| | |
 |  dS )
        Overrides the standard draw_path to add the shadow offset and
        necessary color changes for the shadow.
        N      ?rt   rt      noner   )r:   r`   rj   rn   set_foreground	set_alpharm   set_linewidthr%   r]   r)   r   ra   r   r   r    r+   r,   r-   rb   rgbro   r   r   r   r)     s   



zSimplePatchShadow.draw_path)rf   NNri   rd   r   r   rL   r   re      s    $re   c                       s.   e Zd ZdZ		d	 fdd	Zdd Z  ZS )
SimpleLineShadowzA simple shadow via a line.rf   r"   ri   c                    s>   t  | |du r|| _nt|| _|| _|| _|| _dS )a  
        Parameters
        ----------
        offset : (float, float), default: (2, -2)
            The (x, y) offset to apply to the path, in points.
        shadow_color : :mpltype:`color`, default: 'black'
            The shadow color.
            A value of ``None`` takes the original artist's color
            with a scale factor of *rho*.
        alpha : float, default: 0.3
            The alpha transparency of the created shadow patch.
        rho : float, default: 0.3
            A scale factor to apply to the rgbFace color if *shadow_color*
            is ``None``.
        **kwargs
            Extra keywords are stored and passed through to
            :meth:`AbstractPathEffect._update_gc`.
        N)rE   r   _shadow_colorrk   rl   rm   rn   r]   )r   r   shadow_colorrp   rq   rK   rL   r   r   r   !  s   
zSimpleLineShadow.__init__c                 C   s   |  }|| | jdu r*| pddd \}}}	|| j || j |	| j f}
n| j}
||
 || j | || j	}|
|||| |  |  dS )rr   Nrs   ru   )r:   r`   r   get_foregroundrn   rw   rx   rm   r%   r]   r)   r   ra   rz   r   r   r   r)   ?  s   


zSimpleLineShadow.draw_path)rf   r"   ri   ri   rd   r   r   rL   r   r~     s    r~   c                       rZ   )PathPatchEffectza
    Draws a `.PathPatch` instance whose Path comes from the original
    PathEffect artist.
    r\   c                    s&   t  j|d tjg fi || _dS )a  
        Parameters
        ----------
        offset : (float, float), default: (0, 0)
            The (x, y) offset to apply to the path, in points.
        **kwargs
            All keyword arguments are passed through to the
            :class:`~matplotlib.patches.PathPatch` constructor. The
            properties which cannot be overridden are "path", "clip_box"
            "transform" and "clip_path".
        )r   N)rE   r   mpatches	PathPatchpatchr^   rL   r   r   r   ]  s   zPathPatchEffect.__init__c                 C   sd   || j _| j || |  | j |  | }|r*| j  d u r*| j j|  | j | d S r.   )	r   _pathset_transformr   set_clip_boxget_clip_rectangleget_clip_pathset_clip_pathdraw)r   r   r    r+   r,   r-   	clip_pathr   r   r   r)   l  s   zPathPatchEffect.draw_pathrc   rd   r   r   rL   r   r   W  s    r   c                       s8   e Zd ZdZdddedf fdd	Zdd	 Z  ZS )
TickedStrokea  
    A line-based PathEffect which draws a path with a ticked style.

    This line style is frequently used to represent constraints in
    optimization.  The ticks may be used to indicate that one side
    of the line is invalid or to represent a closed boundary of a
    domain (i.e. a wall or the edge of a pipe).

    The spacing, length, and angle of ticks can be controlled.

    This line style is sometimes referred to as a hatched line.

    See also the :doc:`/gallery/misc/tickedstroke_demo` example.
    r\   g      $@g     F@rg   c                    s(   t  | || _|| _|| _|| _dS )a%  
        Parameters
        ----------
        offset : (float, float), default: (0, 0)
            The (x, y) offset to apply to the path, in points.
        spacing : float, default: 10.0
            The spacing between ticks in points.
        angle : float, default: 45.0
            The angle between the path and the tick in degrees.  The angle
            is measured as if you were an ant walking along the curve, with
            zero degrees pointing directly ahead, 90 to your left, -90
            to your right, and 180 behind you. To change side of the ticks,
            change sign of the angle.
        length : float, default: 1.414
            The length of the tick relative to spacing.
            Recommended length = 1.414 (sqrt(2)) when angle=45, length=1.0
            when angle=90 and length=2.0 when angle=60.
        **kwargs
            Extra keywords are stored and passed through to
            :meth:`AbstractPathEffect._update_gc`.

        Examples
        --------
        See :doc:`/gallery/misc/tickedstroke_demo`.
        N)rE   r   _spacing_angle_lengthr]   )r   r   spacinganglelengthrK   rL   r   r   r     s
   
zTickedStroke.__init__c           #      C   s  |  }|| | || j}|| | }t| j }tt	|t
| gt
|t	|gg}	|| j}
||}|jdd}|D ]}|dddf }|dddf }|jdk rbqIt|dd |dd  |dd |dd  }tdgt|f}|d }tt||
 d }t|
d ||
d  |}t|||}t|||}| jd	 }t|| ||| | }t|| ||| | }t||}|dk}d
||< t|| || gj}tddgj||< t||	| j |
 }||dddf  }||dddf  }tjd| df|jd} || ddddf< || ddddf< || ddddf< || ddddf< ttjtjg|}!t| |!}"| ||"|! | | qI|"  dS )r_   F)closed_onlyNr   rC   rg   r	   gMbP?rt   )dtype)#r:   r`   r%   r]   r   npradiansr   arraycossinr   r   transform_pathto_polygonssizehypotconcatenatecumsumintceillinspaceinterpTdotr   emptyr   tiler   MOVETOLINETOr)   invertedra   )#r   r   r    r+   r,   r-   rb   transthetatrans_matrix
spacing_px	transpathpolyspxydsrQ   s_totalnums_tickx_ticky_tickdelta_sur#   nmaskuvdxyx_endy_endxytcodeshr   r   r   r)     sV   



4

zTickedStroke.draw_path)	r/   r0   r1   r2   r   sqrtr   r)   rT   r   r   rL   r   r   v  s    #r   )r2   matplotlib.backend_basesr   
matplotlibr   rk   r   r   r   r   matplotlib.pathr   numpyr   r   r'   rU   rY   r[   
withStrokere   withSimplePatchShadowr~   r   r   withTickedStroker   r   r   r   <module>   s(    6S	

A9 
