
    sgL7                     t    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
e      Zd Zy)   )PlotInterval)
PlotObject)parse_option_string    Symbol)sympify)GeometryEntity)is_sequencec                       e Zd ZdZd\  ZZg Zg ZdZd Z	g Z
i i di i di i ddZi i i dZd\  ZZd Zed	        Zedd
       Zedd       Zed        Zed        ZdZed        Zd Zd Zed        Zed        Zy)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                     t               N)NotImplementedError)selfs    V/var/www/html/venv/lib/python3.12/site-packages/sympy/plotting/pygletplot/plot_mode.pydrawzPlotMode.draw%   s    !##    )r      )r   r      )r   r   c                    t         j                  ||      \  }}|j                  dd      }t         j                  |      \  }}t         j	                  ||      }t        t        |      t        |      g      t        |      }
}	t         j                  ||	|
      }t        j                  |      }||_
        |j                  |       |j                  |       ||_        |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os                r   r"   zPlotMode.__new__<   s     &66tVD==, %44W=	&&vy9CKY013v;1 ##Ha3 NN6" 	v	)$	r   c                    	 d}t        | t              r| }r|j                  s&t	        d|j
                  d|j
                  d      ||j                  k7  r$t	        d|j
                  |j                  fz        ||j                  kD  r$t	        d|j
                  |j                  fz        |S t        | t              r||}}|t        j                  kD  rt	        t        dd            |t        j                  kD  rt	        t        dd            | st        j                  ||      S t        j                  | ||      S t	        d	      # t        $ r Y Fw xY w)
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).
        NzTo use unregistered plot mode z you must first call z._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,   r:   r9   mr/   r0   s         r   r    zPlotMode._get_modeZ   sl   @	A(H- %% $%JJ

"< = = amm+  #A$%JJ%&]]$4"4 5 5 Q]]*  #/ %&JJ%&]]$4"4 5 5
 Hh$qA8&&& t!<==8&&& !=>> 11!Q77  11(AqAA 3 4 4G  		s   E 	EEc                     |dk(  r| }	 t         j                  |   |    S # t        $ r@ | t         j                  k  rt         j	                  | dz   ||      cY S t        d||fz        w xY w)Nr   zKCouldn't find a default mode for %i independent and %i dependent variables.)r   _mode_default_mapKeyErrorr=   r@   r7   )r/   r0   r.   s      r   r@   zPlotMode._get_default_mode   s    R<F	I--a033 		I 8&&&11!a%FCC  #9=CQK"H I I		Is    6A(A(c                 b   |dk(  r|}| t         j                  vr/t        d| ddj                  t         j                        d      	 t         j                  |   |   |    S # t
        $ rB |t         j                  k  rt         j                  | |dz   ||      cY S t        d| ||fz        w xY w)NrD   zCouldn't find a mode called z. Known modes: z, .r   zFCouldn't find a %s mode for %i independent and %i dependent variables.)r   _mode_alias_listr7   join	_mode_mapr5   r=   rA   )aliasr/   r0   r.   s       r   rA   zPlotMode._get_aliased_mode   s    R<F111 %tyy1J1J'KM N N	7%%a(+E22 
	7 8&&&11%Q6JJ  #9 %*61#5"6 7 7
	7s   
A# #7B.B.c           	         | j                   }| j                          	 | j                  | j                  }}| j                  D ]L  }|t
        j                  vrt
        j                  j                  |       | t
        j                  |   |   |<   N | j                  r| t
        j                  |   |<   yy# t        $ r}t        d|dt        |            d}~ww xY 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 z
. Reason: N)r8   
_init_moder:   r9   aliasesr   rI   appendrK   
is_defaultrE   	ExceptionRuntimeErrorr<   )r'   namer/   r0   aes         r   	_registerzPlotMode._register   s     ||	3??COOqA [[ 2H555 --44Q7.1""1%a(+2 ~~ 47**1-a0	   	3"&Q 2 3 3	3s   BB5 5	C>CCc                    d } || j                         | _          || j                        | _        t        | j                         | _        t        | j                        | _        | j                  t
        j                  kD  rt        t        dd            | j                  t
        j                  kD  rt        t        dd            t        | j                        dkD  r| j                  d   | _        n| j                  | _        | j                  }t        |      | j                  k7  rt        d      t        | j                        D ]0  }t        ||         dk7  rt        d      t        dg||    ||<   2 d| _        y)	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                 >    | D cg c]  }t        |       c}S c c}w r   r   )
symbol_strss     r   symbols_listz)PlotMode._init_mode.<locals>.symbols_list   s    '12!F1I222s   TFr   z9Plot mode must provide a default interval for each i_var.r   zlength should be equal to 3N)r.   r#   r   r:   r9   r   r=   r7   r>   r?   rO   primary_aliasr8   r-   ranger   r6   )r'   r\   dir/   s       r   rN   zPlotMode._init_mode   sF   	3
 "#**-
!#**-
 cjj/cjj/??X000_T59::??X000_UE:;; s{{a #AC #C]]r7coo% @ A As' 		/A 2a5zQ !>??
 !.1.BqE		/  $r   c                 "   g }|D ]Y  }|j                   |j                   |v r!t        dt        |j                         z        |j                  |j                          [ | D ])  }|j                  D ]  }||vs|j                  |        + |S )Nz Multiple intervals given for %s.)vr7   r<   rP   free_symbols)	functionsr-   r.   r/   frU   s         r   r   zPlotMode._find_i_vars$  s    
  	Ass{  #,03ACC": ; ;MM!##	  	%A^^ %F?MM!$%	%
 r   c                     | j                   D cg c]  }t        t        |             c}| _         t        t	        |            D ]  }||   | j                   |<    y c c}w r   )r.   r   r<   r^   r   )r   r.   r/   s      r   r$   zPlotMode._fill_i_vars=  sN    /3{{;!vc!f~;s6{# 	'A#AYDKKN	' <s   Ac                    | j                   D cg c]  }t        |       c}| _         g }t        t        |            D ]e  }| j                   |   j	                  ||          | j                   |   j
                  >|j                  | j                   |   j
                         g t        t        | j                               D ]~  }| j                   |   j
                  | j                  D cg c]	  }||vs| }}t        |      dk(  rt        d      |d   | j                   |   _        |j                  |d           y c c}w c c}w )Nr   zlength should not be equal to 0)	r-   r   r^   r   	fill_fromra   rP   r.   r7   )r   r-   r/   v_usedra   us         r   r%   zPlotMode._fill_intervalsD  s   37>>Ba,q/B s9~& 	3ANN1''	!5~~a "".dnnQ/112	3 s4>>*+ 	$A~~a ""* $?1qQ??q6Q;$%FGG&'dq!#ad#	$ C @s   E0	E:Ec                    d}d}g g }}t        | d   t              rkt        | d   j                               D ]  }|j	                  |        |j	                  t        j                  | d   j                                      ||fS | D ]  }t        j                  |      }|7t        |      dk(  rt        |t        |      z        |j	                  |       Qt        |t              rt        |t        |      z        	 t        |      }|j	                  |        ||fS # t        $ r t        |t        |      z        w xY w)Nz1PlotInterval %s was given before any function(s).z1Could not interpret %s as a function or interval.r   )include)r;   r
   listarbitrary_pointrP   r   	try_parseplot_intervalr   r7   r<   r   r	   r5   )	r(   interval_wrong_orderinterpret_errorrc   r-   coordsrU   r/   rd   s	            r   r   zPlotMode._interpret_argsY  sL   RM!29	d1g~.tAw6689 )  ()\33DG4I4I4KLM$ )##!  C **1-=9~*()=Q)HII!((+"1c2(CF)CDDC#AJ!((+C  )## % C(3q6)ABBCs   D%%!Ec                     i g }}| D ]9  }t        |t              rt        |fi t        |      })|j	                  |       ; t        |fi |}||fS r   )r;   r<   dictr   rP   )r(   r)   r+   r*   rU   s        r   r   zPlotMode._extract_optionsv  sa    7	 	"A!S! E.A!.DE	q!		"
 -f-		!!r   N)rD   )r8   
__module____qualname____doc__r.   r#   r-   rO   rQ   r   rI   rK   rE   r=   r?   r"   staticmethodr    r@   rA   classmethodrW   rN   r6   r   r$   r%   r   r    r   r   r   r   
   s&   
" NFFIGJ$ b>b>b>I 
 "J
< G4 G4R I I  7 7* 3 3> 2$ 2$h   0'$* $ $8 " "r   r   c                 n    |rd}nd}| rt         j                  d}}nt         j                  d}}d|||fz  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   r=   r?   )is_independentis_plottingra   nr[   s        r   r>   r>     sJ    
 $""M1""K1 $%q!9- -r   N)ro   r   plot_objectr   utilr   sympy.core.symbolr   sympy.core.sympifyr	   sympy.geometry.entityr
   sympy.utilities.iterablesr   r   r>   rz   r   r   <module>r      s.    ' # % $ & 0 1u"z u"p-r   