o
    h                     @  s,   d dl mZ d dlZdddZdddZdS )    )annotationsN
chunk_sizeint | tuple[int, int] | Nonechunk_counttotal_chunk_count
int | Nonenyintnxreturntuple[int, int]c                 C  st  t | du|du|dugdkrtd|dk s|dk r&td| d| d|dur[|d |d  }tt|d|}|dkrAd} n||krHd	} nt|}||krS|}n|d |d f}|durt|tri|\}}n| }}tt|d|d }tt|d|d }t|d | t|d | f} | du rd }	}
nt| tr| \}	}
n|  }	}
|
dk s|	dk rtd
|	|
fS )a1  Calculate chunk sizes.

    Args:
        chunk_size (int or tuple(int, int), optional): Chunk size in (y, x) directions, or the same
            size in both directions if only one is specified. Cannot be negative.
        chunk_count (int or tuple(int, int), optional): Chunk count in (y, x) directions, or the
            same count in both directions if only one is specified. If less than 1, set to 1.
        total_chunk_count (int, optional): Total number of chunks. If less than 1, set to 1.
        ny (int): Number of grid points in y-direction.
        nx (int): Number of grid points in x-direction.

    Return:
        tuple(int, int): Chunk sizes (y_chunk_size, x_chunk_size).

    Note:
        Zero or one of ``chunk_size``, ``chunk_count`` and ``total_chunk_count`` should be
        specified.
    N   zGOnly one of chunk_size, chunk_count and total_chunk_count should be set   z'(ny, nx) must be at least (2, 2), not (z, )r   )r   r   zchunk_size cannot be negative)	sum
ValueErrorminmaxtwo_factors
isinstancetuplemathceil)r   r   r   r   r
   max_chunk_countfactorsy_chunk_countx_chunk_county_chunk_sizex_chunk_size r   c/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/contourpy/chunk.pycalc_chunk_sizes   s<   

$


r!   nc                 C  sf   | dk rt d|  tt| }| | dkr#|d8 }| | dks| | }||kr/||fS ||fS )aR  Split an integer into two integer factors.

    The two factors will be as close as possible to the sqrt of n, and are returned in decreasing
    order.  Worst case returns (n, 1).

    Args:
        n (int): The integer to factorize, must be positive.

    Return:
        tuple(int, int): The two factors of n, in decreasing order.
    r   z)two_factors expects positive integer not r   )r   r   r   sqrt)r"   ijr   r   r    r   I   s   r   )r   r   r   r   r   r   r   r	   r
   r	   r   r   )r"   r	   r   r   )
__future__r   r   r!   r   r   r   r   r    <module>   s    
C