o
    jĎi`	                     @   s<   d dl mZmZ d dlmZ d dlmZ G dd deZdS )    )TupleUnion)BaseBoundingBox)BoundingBoxc                       s   e Zd Z	ddededededeeef def fdd	Zd
d Zddede	eeeeef df fddZ
e		ddededededeeef dedd fddZ  ZS )FiftyoneBoundingBoxFx_tly_tlwh
image_sizestrictc                    s    t t| j||||||d d S )Nr   r   )superr   __init__)selfr   r   r	   r
   r   r   	__class__ `/home/jeff/fluffinator/venv/lib/python3.10/site-packages/pybboxes/boxes/fiftyone_bounding_box.pyr      s    	zFiftyoneBoundingBox.__init__c                 G   s   |\}}}}d|  k rdkr#n t dd|  k r"dks't d t dd|  kr8||   k r8dkrLn nd|  krK||   k rKdksXn | jrSt dd| _d S d| _d S )Nr      z2Given width and height must be in the range (0,1].zeGiven bounding box values is out of bounds. To silently skip out of bounds cases pass 'strict=False'.TF)
ValueErrorr   _is_oob)r   valuesr   r   r	   r
   r   r   r   _validate_values   s   J

z$FiftyoneBoundingBox._validate_valuesreturn_valuesreturnr   c           
      C   s   |   rtd| j\}}}}| j\}}||9 }||9 }||9 }||9 }|| }|| }	t|t|t|t|	f\}}}}	|rF||||	fS t||||	| j| jdS )Nz('image_size' is required for conversion.r   )is_image_size_nullr   r   r   roundr   r   )
r   r   r   r   r	   r
   image_widthimage_heightx_bry_brr   r   r   to_voc!   s   
$zFiftyoneBoundingBox.to_vocNTr    r!   c                 C   s\   |d u rt d|\}}|| }	|| }
|| }|| }|	| }	|
| }
| |||	|
||dS )NzCYoloBounding box requires `image_size` to normalize the box values.r   )r   )clsr   r   r    r!   r   r   r   r   r	   r
   r   r   r   from_voc1   s   
zFiftyoneBoundingBox.from_voc)F)NT)__name__
__module____qualname__floatr   intboolr   r   r   r"   classmethodr$   __classcell__r   r   r   r   r      sF    
(
r   N)typingr   r   pybboxes.boxes.baser   pybboxes.boxes.bboxr   r   r   r   r   r   <module>   s    