U
    L?h                     @   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krdS t | trdS t|  o0t|  S )z)Check if a floating point number is validNF)
isinstancecomplexmathisinfisnan)x r   I/var/www/html/venv/lib/python3.8/site-packages/sympy/plotting/textplot.pyis_valid   s
    
r   c                 C   s   g }|| }|| d }t |D ]v}t| | r| | | | }	t|	sT|d qt|	| |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   s  | j }t|dkr td||r,| nt }t|g| }t|trX|j	dkrX|j
}t|trr|j	dkrr|j
}t|}t|}t|||}g }|D ]<}	z|||	 W q tttfk
r   |d Y qX qttt|}
|
r(t|
}t|
}||kr0|rtdd| g\}}nd\}}nd\}}|| }tt|d }|d9 }t||}t||}t|||||}t|||}d}t|d ddD ]b}d	g| }t|D ]}|| |kr|dks||d  |d kr||d ks||d  |d krd
||< nV|dks0||d  |d kr^||d ksT||d  |d kr^d||< nd||< q|dkrt|D ]}d||< q||d|d |d fkrd||  |d| }nd	| }d|}||d kr|d	d}|d | V  qd	|d  }|d|d  |d 7 }|d dkrR|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 {})r   Nr   )r   r%       /\._z%g -z |) Zfree_symbolslen
ValueErrorformatpopr   r   r   r   imagrealfloatr"   r   	TypeErrorZeroDivisionErrorlistfilterr   maxminsortedr   floorlog10r   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    








D
D


 "rO   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)rO   print)rB   rC   rD   r   r   liner   r   r   textplot   s    $rR   )r#   r$   )r#   r$   )Zsympy.core.numbersr   Zsympy.core.symbolr   Zsympy.utilities.lambdifyr   r   r   r   r"   rO   rR   r   r   r   r   <module>   s   	
W