o
    e9                     @   s\   d dl mZ d dlmZ d dlmZ d dlZdd Zdd Zd	d
 Z	dddZ
dddZdS )    )Float)Dummy)lambdifyNc                 C   s2   | du rdS t | trdS t|  ot|  S )z)Check if a floating point number is validNF)
isinstancecomplexmathisinfisnan)x r   GD:\Projects\ConvertPro\env\Lib\site-packages\sympy/plotting/textplot.pyis_valid   s
   
r   c                 C   s   g }|| }|| d }t |D ];}t| | rF| | | | }	t|	s*|d qt|	| |d  |d  |  }
t|
}
||
 q|d q|S )zRescale the given array `y` to fit into the integer values
    between `0` and `H-1` for the values between ``mi`` and ``ma``.
       N   )ranger   appendr   roundint)yWHmimaZy_newZnormoffsetr
   
normalizedZrescaledr   r   r   rescale   s   $r   c                    s    fddt  D S )Nc                    s$   g | ]} |  d    qS )r   r   ).0r
   numstartstopr   r   
<listcomp>)   s   $ zlinspace.<locals>.<listcomp>)r   )r   r    r   r   r   r   linspace(   s   r"   7      c                 c   sD   | j }t|dkrtd||r| nt }t|g| }t|}t|}t|||}g }|D ]}	z	|	||	 W q2 tt
tfyN   |	d Y q2w ttt|}
|
rvt|
}t|
}||kru|rqtdd| g\}}n	d\}}nd\}}|| }tt|dd }|d9 }t||}t||}t|||||}t|||}d	}t|d ddD ]}d
g| }t|D ]V}|| |kr|dks||d  |d kr||d ks||d  |d krd||< q|dks||d  |d kr||d ks||d  |d krd||< qd||< q|dkr"t|D ]}d||< q|d|d |d fv r<d||  |d| }nd
| }d|}||d krR|d
d}|d | V  qd
|d  }|d|d  |d 7 }|d dkr|d||d   |d 7 }n|d||d   |d d 7 }|d|d  7 }|V  dS )z#Generator for the lines of the plotr   z4The expression must have a single variable. (Got {})Nr   r   )r   
   r%       /\._z%g -z |)Zfree_symbolslen
ValueErrorformatpopr   r   floatr"   r   	TypeErrorZeroDivisionErrorlistfilterr   maxminsortedr   floorlogr   r   r   rjustjoinreplaceljust)exprabr   r   freer
   fr   valZy_validr   r   Zy_range	precisionZy_binsmarginhsiprefixbottomr   r   r   textplot_str,   s   


<
B


 "
rN   c                 C   s"   t | ||||D ]}t| qdS )a  
    Print a crude ASCII art plot of the SymPy expression 'expr' (which
    should contain a single symbol, e.g. x or something else) over the
    interval [a, b].

    Examples
    ========

    >>> from sympy import Symbol, sin
    >>> from sympy.plotting import textplot
    >>> t = Symbol('t')
    >>> textplot(sin(t)*t, 0, 15)
     14 |                                                  ...
        |                                                     .
        |                                                 .
        |                                                      .
        |                                                .
        |                            ...
        |                           /   .               .
        |                          /
        |                         /      .
        |                        .        .            .
    1.5 |----.......--------------------------------------------
        |....       \           .          .
        |            \         /                      .
        |             ..      /             .
        |               \    /                       .
        |                ....
        |                                    .
        |                                     .     .
        |
        |                                      .   .
    -11 |_______________________________________________________
         0                          7.5                        15
    N)rN   print)rA   rB   rC   r   r   liner   r   r   textplot}   s   $
rQ   )r#   r$   )Zsympy.core.numbersr   Zsympy.core.symbolr   Zsympy.utilities.lambdifyr   r   r   r   r"   rN   rQ   r   r   r   r   <module>   s    	
Q