o
    ohJ                     @   sb   d Z ddlZddlmZmZmZmZmZmZm	Z	 ddl
mZ dZG dd dZG dd	 d	eZdS )
a  Prettyprinter by Jurjen Bos.
(I hate spammers: mail me at pietjepuk314 at the reverse of ku.oc.oohay).
All objects have a method that create a "stringPict",
that can be used in the str method for pretty printing.

Updates by Jason Gedge (email <my last name> at cs mun ca)
    - terminal_string() method
    - minor fixes and changes (mostly to prettyForm)

TODO:
    - Allow left/center/right alignment options for above/below and
      top/center/bottom alignment options for left/right
    N   )hobjvobjxsymxobjpretty_use_unicode
line_widthcenter)sympy_deprecation_warningc                       s   e Zd ZdZdZd2ddZedd Zdd	 Zd
d Z	edd Z
dd Zdd Zedd Zdd Zdd Zd3ddZdd Zd4d d!Zd"d# Zd$d% Zd&d' Z fd(d)Zd*d+ Zd,d- Zd.d/ Zd0d1 Z  ZS )5
stringPictzZAn ASCII picture.
    The pictures are represented as a list of equal length strings.
    liner   c                 C   s&   || _ t| | _|| _d| _dS )zHInitialize from string.
        Multiline strings are centered.
        N)sr   equalLengths
splitlinespicturebaselinebinding)selfr   r    r   t/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/sympy/printing/pretty/stringpict.py__init__   s   
zstringPict.__init__c                    s.   | sdgS t dd | D   fdd| D S )N c                 s   s    | ]}t |V  qd S N)r   .0r   r   r   r   	<genexpr>.   s    z*stringPict.equalLengths.<locals>.<genexpr>c                    s   g | ]}t | qS r   )r	   r   widthr   r   
<listcomp>/       z+stringPict.equalLengths.<locals>.<listcomp>)max)linesr   r   r   r   (   s   zstringPict.equalLengthsc                 C   
   t | jS )z(The height of the picture in characters.)lenr   r   r   r   r   height1   s   
zstringPict.heightc                 C   s   t | jd S )z'The width of the picture in characters.r   )r   r   r$   r   r   r   r   5   s   zstringPict.widthc                  G   s   g }| D ]}t |trt|}|| qtdd |D }tdd |D }|| }g }|D ]$}d|  g}||j }	||  }
|||	 |j ||
|	    q/dd t	| D }d
||fS )zsPut a string of stringPicts next to each other.
        Returns string, baseline arguments for stringPict.
        c                 s   s    | ]}|j V  qd S r   r   r   objr   r   r   r   F   s    z"stringPict.next.<locals>.<genexpr>c                 s   s    | ]
}|  |j V  qd S r   )r%   r   r'   r   r   r   r   G   s
    
 c                 S      g | ]}d  |qS )r   join)r   r!   r   r   r   r   V   r   z#stringPict.next.<locals>.<listcomp>
)
isinstancestrr   appendr    r   r   r%   r   zipr,   )argsobjectsargnewBaselinenewHeightBelowBaseline	newHeightpicturesr(   oneEmptyLinebasePaddingtotalPaddingresultr   r   r   next9   s0   


zstringPict.nextc                 G   s   t j| g|R  S )a  Put pictures next to this one.
        Returns string, baseline arguments for stringPict.
        (Multiline) strings are allowed, and are given a baseline of 0.

        Examples
        ========

        >>> from sympy.printing.pretty.stringpict import stringPict
        >>> print(stringPict("10").right(" + ",stringPict("1\r-\r2",1))[0])
             1
        10 + -
             2

        r   r=   r   r2   r   r   r   rightY   s   zstringPict.rightc                 G   s   t j|| f  S )ziPut pictures (left to right) at left.
        Returns string, baseline arguments for stringPict.
        r>   r?   r   r   r   leftj   s   zstringPict.leftc                     s   g }| D ]}|t jurt|trt |}|| qtdd |D  t td }t|D ]\}}|t ju r;|||< q. fdd|D }|d  |d j	 }d
||fS )	a  Put pictures on top of each other,
        from top to bottom.
        Returns string, baseline arguments for stringPict.
        The baseline is the baseline of the second picture.
        Everything is centered.
        Baseline is the baseline of the second picture.
        Strings are allowed.
        The special value stringPict.LINE is a row of '-' extended to the width.
        c                 s   s"    | ]}|t jur| V  qd S r   )r   LINEr   r'   r   r   r   r      s    
z#stringPict.stack.<locals>.<genexpr>-c                    s"   g | ]}|j D ]}t| qqS r   )r   r	   )r   r(   r   newWidthr   r   r      s   " z$stringPict.stack.<locals>.<listcomp>r   r   r-   )r   rB   r.   r/   r0   r    r   	enumerater%   r   r,   )r2   r3   r4   lineObjir(   
newPicturer5   r   rD   r   stackp   s    
zstringPict.stackc                 G   s    t j| g|R  \}}|| jfS )a  Put pictures under this picture.
        Returns string, baseline arguments for stringPict.
        Baseline is baseline of top picture

        Examples
        ========

        >>> from sympy.printing.pretty.stringpict import stringPict
        >>> print(stringPict("x+3").below(
        ...       stringPict.LINE, '3')[0]) #doctest: +NORMALIZE_WHITESPACE
        x+3
        ---
         3

        )r   rJ   r   )r   r2   r   r   r   r   r   below   s   
zstringPict.belowc                 G   s6   t j|| f  \}}t| |   | j }||fS )zPut pictures above this picture.
        Returns string, baseline arguments for stringPict.
        Baseline is baseline of bottom picture.
        )r   rJ   r#   r   r%   r   )r   r2   stringr   r   r   r   above   s   zstringPict.above()Fc           	      C   s~   |   }| j}|rt sd}d}| }|r$tt|||d}t||  }|r6tt|||d}t|| }d|j|jfS )zPut parentheses around self.
        Returns string, baseline arguments for stringPict.

        left or right can be None or empty string which means 'no paren from
        that side'
        r   r   r&   r-   )r%   r   r   r   r   r@   r,   r   )	r   rA   r@   ifascii_nouglyhbreslparenrparenr   r   r   parens   s   
zstringPict.parensc                    sR   t | j|  d | j d d  d fddt D }| t| d S )z6Precede object by a slash of the proper size.
        r      r-   c                 3   s2    | ]}d  | d  t dd d |  V  qdS r)   r   /N)r   r   rH   r%   r   r   r      s
     
z'stringPict.leftslash.<locals>.<genexpr>)r    r   r%   r,   rangerA   r   )r   slashr   r[   r   	leftslash   s   zstringPict.leftslashNc                    s   |  d|   }|   d fddt D }t| d } dkr,tdd}ntd}|d	urN| | krN|d
| |   }| |}||}|j|  |  |_||S )zUProduce a nice root symbol.
        Produces ugly results for big n inserts.
        _r-   c                 3   s,    | ]}d  | d  d d |  V  qdS rX   r   rZ   r[   r   r   r      s
    
z"stringPict.root.<locals>.<genexpr>r   rW   z\ 
 \\Nr)   )	rM   r   r%   r,   r\   r   rA   r@   r   )r   nr<   r]   downlinerootr   r[   r   rc      s   


zstringPict.rootc                    s   t durt |d< |d du rd| jS |d dur|d  n|    dkr)d |   kr8t| jd | S 	 d|d	 sBt rGd
dndd fdd}tt|| j }dd |D }d|S )zReturn the string form of self.

           Unless the argument line_break is set to False, it will
           break the expression in a form that can be printed
           on the terminal without being broken up.
         N	wrap_lineFr-   num_columnsr   P   r   use_unicodeu   ↪ u    ↪z> z >c                 3   s    }t | d}}t| D ](\}}t |}||  kr4|| ||   V  }t | |}}||7 }q|| |d  V  dS )z-Yields consecutive chunks of line_width ncolsr   N)r   rF   )r   prefixr   startrH   xwxncolsoverflow_endoverflow_firstoverflow_startr   r   chunks-  s   
z!stringPict.render.<locals>.chunksc                 S   r*   )r-   r+   )r   r   r   r   r   r   @  r   z%stringPict.render.<locals>.<listcomp>z

)	_GLOBAL_WRAP_LINEr,   r   terminal_widthr   typer   r1   map)r   r2   kwargsrq   r8   r   rl   r   render   s,   

zstringPict.renderc                 C   s   t jdd}|jS )zCReturn the terminal width if possible, otherwise return 0.
        )r   r   )fallback)shutilget_terminal_sizecolumns)r   sizer   r   r   rs   E  s   zstringPict.terminal_widthc                 C   s4   t |trd| j|kS t |tr|j| jkS dS )Nr-   F)r.   r/   r,   r   r   )r   or   r   r   __eq__K  s
   

zstringPict.__eq__c                    s
   t   S r   )super__hash__r$   	__class__r   r   r   R     
zstringPict.__hash__c                 C   s   d | jS )Nr-   )r,   r   r$   r   r   r   __str__U  s   zstringPict.__str__c                 C   s   dd | j| jf S )NzstringPict(%r,%d)r-   )r,   r   r   r$   r   r   r   __repr__X  s   zstringPict.__repr__c                 C   s
   | j | S r   )r   )r   indexr   r   r   __getitem__[  r   zstringPict.__getitem__c                 C   r"   r   )r#   r   r$   r   r   r   __len__^  r   zstringPict.__len__)r   )rN   rO   Fr   )__name__
__module____qualname____doc__rB   r   staticmethodr   r%   r   r=   r@   rA   rJ   rK   rM   rV   r^   rc   rw   rs   r~   r   r   r   r   r   __classcell__r   r   r   r   r      s6    



#
	
"Lr   c                   @   s|   e Zd ZdZed\ZZZZZ	Z
ZZdddZedd Zd	d
 ZdddZdd Zdd Zdd Zg dZedd ZdS )
prettyForma  
    Extension of the stringPict class that knows about basic math applications,
    optimizing double minus signs.

    "Binding" is interpreted as follows::

        ATOM this is an atom: never needs to be parenthesized
        FUNC this is a function application: parenthesize if added (?)
        DIV  this is a division: make wider division if divided
        POW  this is a power: only parenthesize if exponent
        MUL  this is a multiplication: parenthesize if powered
        ADD  this is an addition: parenthesize if multiplied or powered
        NEG  this is a negative number: optimize if added, parenthesize if
             multiplied or powered
        OPEN this is an open object: parenthesize if added, multiplied, or
             powered (example: Piecewise)
       r   Nc                 C   s8   t | || || _|durtdddd |p|| _dS )z-Initialize from stringPict and binding power.Nz
                The unicode argument to prettyForm is deprecated. Only the s
                argument (the first positional argument) should be passed.
                1.7$deprecated-pretty-printing-functionsdeprecated_since_versionactive_deprecations_target)r   r   r   r
   _unicode)r   r   r   r   unicoder   r   r   r   v  s   zprettyForm.__init__c                 C   s   t dddd | jS )Nz}
            The prettyForm.unicode attribute is deprecated. Use the
            prettyForm.s attribute instead.
            r   r   r   )r
   r   r$   r   r   r   r     s   zprettyForm.unicodec                 G   sz   | }|j tjkrt|  }|g}|D ]}|j tjkr!t|  }|j tjkr,|d || qttj| dtjiS )zTMake a pretty addition.
        Addition of negative numbers is simplified.
        z + r   )r   r   NEGr   rV   r0   r=   ADD)r   othersr4   r<   r   r   r   __add__  s   
zprettyForm.__add__Fc                 C   sv   |rt d| }|jtjkrt|  }|jtjkr t|  }|jtjkr-|dd }tt|tj	|dtjiS )z4Make a pretty division; stacked or slashed.
        zCan't do slashed fraction yetr)   r   r   )
NotImplementedErrorr   r   DIVr   rV   r   r@   rJ   rB   )r   denslashednumr   r   r   __truediv__  s   zprettyForm.__truediv__c           	      G   sb  ddi}t |dkr| S | }|jtjkr |jtjkr t|  }|g}|D ])}|jd | vr7|	t
d |jtjkrI|jtjkrIt|  }|	| q%t |}t|D ](}||d k r|| dkr||d  t
dkr|| || ||d qW|d d dkrtj}|d dkr|d }|j|j d dkrd|d< ntj}ttj| d	|iS )
zZMake a pretty multiplication.
        Parentheses are needed around +, - and neg.
        degree   °r   *r   z-1rC   z- r   )r#   r   r   MULr   r   rV   r   valuesr0   r   r\   popinsertr   r=   )	r   r   quantityr4   r<   len_resrH   binr@   r   r   r   __mul__  s<   ,

zprettyForm.__mul__c                 C   s   dd | j| j| jf S )NzprettyForm(%r,%d,%d)r-   )r,   r   r   r   r$   r   r   r   r     s
   
zprettyForm.__repr__c                 C   s   | }d}|j tjkrt|  }|j tjkrt|  }n|j tjkr2| dkr0t|  }nd}|rM|jj|  |_t|j	| }t|	|j
 S t|d|   }t|	d|   }t||dtjiS )zMake a pretty power.
        Fr   Tr)   r   )r   r   POWr   rV   FUNCr%   
prettyFuncr   r@   
prettyArgsrA   r   rM   )r   rR   ause_inline_func_formfunctopbotr   r   r   __pow__  s"   zprettyForm.__pow__)sincostanc                 G   s   | t jv r*t|dksJ d|  |d  }|jt jkr*t || d dt jiS g }|D ]}|d ||  q.t	t	j
|dd   }t	|  }t || dt jiS )z,Functions of one or more variables.
        r   z'Simple function %s must have 1 argumentr   r)   r   ,N)r   simpleFunctionsr#   
__pretty__r   r   rA   r   r0   r   r=   rV   ATOM)functionr2   r4   argumentListr   r   r   apply  s$   

zprettyForm.apply)r   r   N)F)r   r   r   r   r\   r   r   r   r   r   r   r   OPENr   propertyr   r   r   r   r   r   r   r   r   r   r   r   r   r   b  s    


+r   )r   ry   pretty_symbologyr   r   r   r   r   r   r	   sympy.utilities.exceptionsr
   rr   r   r   r   r   r   r   <module>   s    $  N