o
    môjÍ  ã                   @   s   d dl mZ d dlmZ d dlmZmZmZmZm	Z	 G dd„ de	ƒZ
dedee
 dee fd	d
„Zdedee dee dee dee f
dd„Z	ddedee deee  dee fdd„ZedkrŽd dlmZ eG dd„ dƒƒZededddƒedddƒedddƒgƒZeeeƒƒ dS dS )é    )ÚFraction)Úceil)ÚcastÚListÚOptionalÚSequenceÚProtocolc                   @   s:   e Zd ZU dZdZee ed< dZeed< dZ	eed< dS )ÚEdgez1Any object that defines an edge (such as Layout).NÚsizeé   ÚratioÚminimum_size)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r
   r   ÚintÚ__annotations__r   r   © r   r   ú\/var/www/html/academy/tools/voices/clone/sv-venv/lib/python3.10/site-packages/rich/_ratio.pyr	      s
   
 r	   ÚtotalÚedgesÚreturnc                 C   sö   dd„ |D ƒ}t }d|v rtdd„ tt||ƒƒD ƒ}| tdd„ |D ƒƒ }|dkr2dd„ t||ƒD ƒS ||td	d„ |D ƒƒƒ}|D ]\}}||j |jkrS|j||<  nq@|dƒ}	|D ]\}}t||j |	 d
ƒ\}
}	|
||< qZnd|v sttt	 |ƒS )aŒ  Divide total space to satisfy size, ratio, and minimum_size, constraints.

    The returned list of integers should add up to total in most cases, unless it is
    impossible to satisfy all the constraints. For instance, if there are two edges
    with a minimum size of 20 each and `total` is 30 then the returned list will be
    greater than total. In practice, this would mean that a Layout object would
    clip the rows that would overflow the screen height.

    Args:
        total (int): Total number of characters.
        edges (List[Edge]): Edges within total space.

    Returns:
        List[int]: Number of characters for each edge.
    c                 S   s   g | ]}|j pd ‘qS ©N)r
   )Ú.0Úedger   r   r   Ú
<listcomp>   s    z!ratio_resolve.<locals>.<listcomp>Nc                 S   s$   g | ]\}\}}|d u r||f‘qS r   r   )r   Úindexr
   r   r   r   r   r   &   s
    
þc                 s   s   � | ]}|pd V  qdS )r   Nr   )r   r
   r   r   r   Ú	<genexpr>,   s   € z ratio_resolve.<locals>.<genexpr>r   c                 S   s&   g | ]\}}|d u r|j pdn|‘qS )Nr   )r   )r   r
   r   r   r   r   r   /   s    ÿ€ ÿc                 s   s   � | ]
\}}|j p
d V  qdS )r   N)r   )r   Ú_r   r   r   r   r   5   s   € r   )
r   Ú	enumerateÚzipÚsumr   r   Údivmodr   r   r   )r   r   ÚsizesZ	_FractionZflexible_edgesÚ	remainingZportionr   r   Ú	remainderr
   r   r   r   Úratio_resolve   s4   þþÿ
ý
Þ$r'   ÚratiosÚmaximumsÚvaluesc                 C   sž   dd„ t ||ƒD ƒ}t|ƒ}|s|dd… S | }g }|j}t |||ƒD ])\}}	}
|rH|dkrHt|	t|| | ƒƒ}||
| ƒ ||8 }||8 }q#||
ƒ q#|S )ad  Divide an integer total in to parts based on ratios.

    Args:
        total (int): The total to divide.
        ratios (List[int]): A list of integer ratios.
        maximums (List[int]): List of maximums values for each slot.
        values (List[int]): List of values

    Returns:
        List[int]: A list of integers guaranteed to sum to total.
    c                 S   ó   g | ]
\}}|r
|nd ‘qS ©r   r   )r   r   Ú_maxr   r   r   r   Y   ó    z ratio_reduce.<locals>.<listcomp>Nr   )r!   r"   ÚappendÚminÚround)r   r(   r)   r*   Útotal_ratioÚtotal_remainingÚresultr/   r   ÚmaximumÚvalueÚdistributedr   r   r   Úratio_reduceK   s   

r8   NÚminimumsc                 C   s®   |rdd„ t ||ƒD ƒ}t|ƒ}|dksJ dƒ‚| }g }|j}|du r+dgt|ƒ }n|}t ||ƒD ]"\}}	|dkrFt|	t|| | ƒƒ}
n|}
||
ƒ ||8 }||
8 }q2|S )a<  Distribute an integer total in to parts based on ratios.

    Args:
        total (int): The total to divide.
        ratios (List[int]): A list of integer ratios.
        minimums (List[int]): List of minimum values for each slot.

    Returns:
        List[int]: A list of integers guaranteed to sum to total.
    c                 S   r+   r,   r   )r   r   Ú_minr   r   r   r   y   r.   z$ratio_distribute.<locals>.<listcomp>r   zSum of ratios must be > 0N)r!   r"   r/   ÚlenÚmaxr   )r   r(   r9   r2   r3   Zdistributed_totalr/   Z	_minimumsr   Úminimumr7   r   r   r   Úratio_distributek   s$   
r>   Ú__main__)Ú	dataclassc                   @   s6   e Zd ZU dZee ed< dZeed< dZeed< dS )ÚENr
   r   r   r   )	r   r   r   r
   r   r   r   r   r   r   r   r   r   rA   ’   s   
 rA   én   r   r   )Ú	fractionsr   Úmathr   Útypingr   r   r   r   r   r	   r   r'   r8   r>   r   Údataclassesr@   rA   ÚresolvedÚprintr"   r   r   r   r   Ú<module>   sB    =ÿÿÿÿ
þ!ÿÿÿ
ÿ
þ$(ö