o
    ohL7                     @   sp   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
mZ ddlmZ G d	d
 d
eZdd ZdS )   PlotInterval)
PlotObject)parse_option_string    Symbol)sympify)GeometryEntity)is_sequencec                   @   s   e Zd ZdZd\ZZg Zg ZdZdd Z	g Z
i i di i di i ddZi i i dZd\ZZd	d
 Zedd Zed!ddZed!ddZedd Zedd ZdZedd Zdd Zdd Zedd Zedd Zd S )"PlotModez
    Grandparent class for plotting
    modes. Serves as interface for
    registration, lookup, and init
    of modes.

    To create a new plot mode,
    inherit from PlotModeBase
    or one of its children, such
    as PlotSurface or PlotCurve.
    ) r   Fc                 C   s   t  N)NotImplementedError)self r   w/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/sympy/plotting/pygletplot/plot_mode.pydraw%   s   zPlotMode.draw)r      )r   r      )r   r   c                 O   s   t ||\}}|dd}t |\}}t ||}tt|t|gt|}	}
t ||	|
}t	|}||_
|| || ||_|S )z
        This is the function which interprets
        arguments given to Plot.__init__ and
        Plot.__setattr__. Returns an initialized
        instance of the appropriate child class.
        moder   )r   _extract_optionsget_interpret_args_find_i_varsmaxlen	_get_modeobject__new__d_vars_fill_i_vars_fill_intervalsoptions)clsargskwargsnewargs	newkwargsmode_argr    	intervalsi_varsidsubclsor   r   r   r   <   s   


zPlotMode.__new__c                 C   s   zd}t | tr
| }W n	 ty   Y nw |rD|js$td|j|jf ||jkr3td|j|jf ||jkrBtd|j|jf |S t| t	ru||}}|tj
krZttdd|tjkrfttdd| snt||S t| ||S td)a  
        Tries to return an appropriate mode class.
        Intended to be called only by __new__.

        mode_arg
            Can be a string or a class. If it is a
            PlotMode subclass, it is simply returned.
            If it is a string, it can an alias for
            a mode or an empty string. In the latter
            case, we try to find a default mode for
            the i_var_count and d_var_count.

        i_var_count
            The number of independent variables
            needed to evaluate the d_vars.

        d_var_count
            The number of dependent variables;
            usually the number of functions to
            be evaluated in plotting.

        For example, a Cartesian function y = f(x) has
        one i_var (x) and one d_var (y). A parametric
        form x,y,z = f(u,v), f(u,v), f(u,v) has two
        two i_vars (u,v) and three d_vars (x,y,z).
        NzETo use unregistered plot mode %s you must first call %s._init_mode().z7%s can only plot functions with %i dependent variables.zA%s cannot plot functions with more than %i independent variables.TFz-PlotMode argument must be a class or a string)
issubclassr   	TypeError_was_initialized
ValueError__name__d_var_counti_var_count
isinstancestr
_i_var_maxvar_count_error
_d_var_max_get_default_mode_get_aliased_mode)r)   r6   r5   mr,   r-   r   r   r   r   Z   sH    







zPlotMode._get_modec                 C   s\   |dkr| }zt j| |  W S  ty-   | t jk r%t | d || Y S td||f w )Nr?   r   zKCouldn't find a default mode for %i independent and %i dependent variables.)r   _mode_default_mapKeyErrorr9   r<   r3   )r,   r-   r+   r   r   r   r<      s   
zPlotMode._get_default_modec              	   C   s   |dkr|}| t jvrtd| dt jf z
t j| | |  W S  tyB   |t jk r9t | |d || Y S td| ||f w )Nr?   z0Couldn't find a mode called %s. Known modes: %s.z, r   zFCouldn't find a %s mode for %i independent and %i dependent variables.)r   _mode_alias_listr3   join	_mode_mapr1   r9   r=   )aliasr,   r-   r+   r   r   r   r=      s   

zPlotMode._get_aliased_modec              
   C   s   | j }|   z1| j| j}}| jD ]}|tjvrtj| | tj| | |< q| j	r6| tj
| |< W dS W dS  tyN } z
td|t|f d}~ww )z
        Called once for each user-usable plot mode.
        For Cartesian2D, it is invoked after the
        class definition: Cartesian2D._register()
        z+Failed to register plot mode %s. Reason: %sN)r4   
_init_moder6   r5   aliasesr   rB   appendrD   
is_defaultr@   	ExceptionRuntimeErrorr8   )r$   namer,   r-   aer   r   r   	_register   s"   


zPlotMode._registerc                 C   s   dd }|| j | _ || j| _t| j | _t| j| _| jtjkr)ttdd| jtj	kr6ttddt| j
dkrD| j
d | _n| j| _| j}t|| jkrVtdt| jD ]}t|| dkritdtd	g|| R  ||< q[d| _d	S )
a  
        Initializes the plot mode based on
        the 'mode-specific parameters' above.
        Only intended to be called by
        PlotMode._register(). To use a mode without
        registering it, you can directly call
        ModeSubclass._init_mode().
        c                 S   s   dd | D S )Nc                 S      g | ]}t |qS r   r   ).0sr   r   r   
<listcomp>       z=PlotMode._init_mode.<locals>.symbols_list.<locals>.<listcomp>r   )
symbol_strr   r   r   symbols_list   s   z)PlotMode._init_mode.<locals>.symbols_listTFr   z9Plot mode must provide a default interval for each i_var.r   zlength should be equal to 3N)r+   r    r   r6   r5   r   r9   r3   r:   r;   rG   primary_aliasr4   r*   ranger   r2   )r$   rV   dir,   r   r   r   rF      s(   

zPlotMode._init_modec                 C   sn   g }|D ]}|j d u rq|j |v rtdt|j  ||j  q| D ]}|jD ]}||vr3|| q(q#|S )Nz Multiple intervals given for %s.)vr3   r8   rH   free_symbols)	functionsr*   r+   r,   frM   r   r   r   r   $  s    



zPlotMode._find_i_varsc                 C   s6   dd | j D | _ tt|D ]	}|| | j |< qd S )Nc                 S   s   g | ]}t t|qS r   )r   r8   rQ   r,   r   r   r   rS   ?      z)PlotMode._fill_i_vars.<locals>.<listcomp>)r+   rX   r   )r   r+   r,   r   r   r   r!   =  s   zPlotMode._fill_i_varsc                    s   dd | j D | _ g  tt|D ]}| j | ||  | j | jd ur. | j | j qtt| j D ]-}| j | jd u rc fdd| jD }t|dkrTtd|d | j | _ |d  q6d S )Nc                 S   rP   r   r   r^   r   r   r   rS   F  rT   z,PlotMode._fill_intervals.<locals>.<listcomp>c                    s   g | ]}| vr|qS r   r   )rQ   rZ   v_usedr   r   rS   S  r_   r   zlength should not be equal to 0)r*   rX   r   	fill_fromrZ   rH   r+   r3   )r   r*   r,   ur   r`   r   r"   D  s    zPlotMode._fill_intervalsc           	   	   C   s   d}d}g g }}t | d tr0t| d  D ]}|| q|t| d   ||fS | D ]G}t|}|d urQt|dkrKt	|t
| || q2t|t
dr_t	|t
| zt|}|| W q2 tyy   t	|t
| w ||fS )Nz1PlotInterval %s was given before any function(s).z1Could not interpret %s as a function or interval.r   )include)r7   r
   listarbitrary_pointrH   r   	try_parseplot_intervalr   r3   r8   r   r	   r1   )	r%   interval_wrong_orderinterpret_errorr\   r*   coordsrM   r,   r]   r   r   r   r   Y  s.   

zPlotMode._interpret_argsc                 C   sV   i g }}| D ]}t |trt|fi t|}q|| qt|fi |}||fS r   )r7   r8   dictr   rH   )r%   r&   r(   r'   rM   r   r   r   r   v  s   

zPlotMode._extract_optionsN)r?   )r4   
__module____qualname____doc__r+   r    r*   rG   rI   r   rB   rD   r@   r9   r;   r   staticmethodr   r<   r=   classmethodrO   rF   r2   r   r!   r"   r   r   r   r   r   r   r   
   sJ    

I

4

r   c                 C   s:   |rd}nd}| rt jd}}nt jd}}d|||f S )zQ
    Used to format an error message which differs
    slightly in 4 places.
    PlottingzRegistering plot modesindependent	dependentz3%s with more than %i %s variables is not supported.)r   r9   r;   )is_independentis_plottingrZ   nrR   r   r   r   r:     s   r:   N)rh   r   plot_objectr   utilr   sympy.core.symbolr   sympy.core.sympifyr	   sympy.geometry.entityr
   sympy.utilities.iterablesr   r   r:   r   r   r   r   <module>   s      z