o
    §ƒðjL7  ã                   @   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   ú¥/tmp/claude-1000/-var-www-html-academy/3f42efd1-c2b7-4d08-9b05-30d86bb35479/scratchpad/piper/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_modeéÿÿÿÿc                 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