§
    >²¸j$M  ã                   óœ  — d dl Z d dlZd dlmZ d dlmZmZ d dlZd dl	mZ
 d dlmZmZ d dlmZ d dlmZ d dlmZmZ d dlmZ ej        Zd	Z G d
„ de¦  «        Zej        fdededee
j        ej                 z  defd„Zde eef         de eef         dede eeeef         fd„Z!deez  dedefd„Z"ej        fdeez  dededee
j        ej                 z  def
d„Z#d4de$dedz  de%e&         fd„Z'de%e&         dz  deddfd„Z( ee(dd¬ ¦  «        de%e&         dz  deddfd!„¦   «         Z)ded"e%e&         dz  de%e&         fd#„Z*d$e
j        ej+                 d%e eef         de
j        ej+                 fd&„Z, G d'„ d(¦  «        Z-d)e&de eeeef         fd*„Z.d+e eeeef         de&fd,„Z/d)e&de0fd-„Z1d.ed/ed0ed1edef
d2„Z2d.ed/ed0ed1edef
d3„Z3dS )5é    N)ÚEnum)ÚAnyÚcast)Ú
deprecatedÚvoid)ÚCLASS_NAME_DATA_FIELD)Ú
Detections)ÚColorÚColorPalette)ÚPositionéÿÿÿÿc                   óF   — e Zd ZdZdZdZdZedee	         fd„¦   «         ZdS )ÚColorLookupaŽ  
    Enumeration class to define strategies for mapping colors to annotations.

    This enum supports three different lookup strategies:
        - `INDEX`: Colors are determined by the index of the detection within the scene.
        - `CLASS`: Colors are determined by the class label of the detected object.
        - `TRACK`: Colors are determined by the tracking identifier of the object.
    ÚindexÚclassÚtrackÚreturnc                 ó>   — t          t          d„ | ¦  «        ¦  «        S )Nc                 ó   — | j         S ©N)Úvalue)Úcs    úl/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/supervision/annotators/utils.pyú<lambda>z"ColorLookup.list.<locals>.<lambda>#   s   €  !¤'€ ó    )ÚlistÚmap)Úclss    r   r   zColorLookup.list!   s   € å•CÐ)Ð)¨3Ñ/Ô/Ñ0Ô0Ð0r   N)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚINDEXÚCLASSÚTRACKÚclassmethodr   Ústr© r   r   r   r      sX   € € € € € ðð ð €EØ€EØ€Eàð1�T˜#”Yð 1ð 1ð 1ñ „[ð1ð 1ð 1r   r   Ú
detectionsÚdetection_idxÚcolor_lookupr   c                 ó°  — |t          | ¦  «        k    r"t          d|› dt          | ¦  «        › �¦  «        ‚t          |t          j        ¦  «        rdt          |¦  «        t          | ¦  «        k    r/t          dt          |¦  «        › dt          | ¦  «        › �¦  «        ‚t          ||         ¦  «        S |t          j        k    r|S |t          j        k    r0| j	        €t          d¦  «        ‚t          | j	        |         ¦  «        S |t          j
        k    r0| j        €t          d¦  «        ‚t          | j        |         ¦  «        S t          d|› �¦  «        ‚)NzDetection index z+ is out of bounds for detections of length zLength of color lookup z% does not match length of detections zªCould not resolve color by class because Detections do not have class_id. If using an annotator, try setting color_lookup to sv.ColorLookup.INDEX or sv.ColorLookup.TRACK.z�Could not resolve color by track because Detections do not have tracker_id. Did you call tracker.update_with_detections(...) before annotating?z#Unsupported color lookup strategy: )ÚlenÚ
ValueErrorÚ
isinstanceÚnpÚndarrayÚintr   r#   r$   Úclass_idr%   Ú
tracker_id©r)   r*   r+   s      r   Úresolve_color_idxr6   &   s�  € ð
 �˜J™œÒ'Ð'ÝðK˜}ð Kð KÝ9<¸Z¹¼ðKð Kñ
ô 
ð 	
õ
 �,¥¤
Ñ+Ô+ð 9Ýˆ|ÑÔ¥ J¡¤Ò/Ð/ÝðI­#¨lÑ*;Ô*;ð Ið IÝ7:¸:±´ðIð Iñô ð õ �< Ô.Ñ/Ô/Ð/Ø	�Ô*Ò	*Ð	*ØÐØ	�Ô*Ò	*Ð	*ØÔÐ&Ýð(ñô ð õ �:Ô& }Ô5Ñ6Ô6Ð6Ø	�Ô*Ò	*Ð	*ØÔ Ð(ÝðIñô ð õ
 �:Ô(¨Ô7Ñ8Ô8Ð8Ý
ÐI¸<ÐIÐIÑ
JÔ
JÐJr   Úcenter_coordinatesÚtext_whÚpositionc                 ó¾  — | \  }}|\  }}|t           j        k    r|||z
  ||z   |fS |t           j        k    r||z
  ||z
  ||fS |t           j        k    r||dz  z
  ||z
  ||dz  z   |fS |t           j        k    s|t           j        k    r||dz  z
  ||dz  z
  ||dz  z   ||dz  z   fS |t           j        k    r||||z   ||z   fS |t           j        k    r||z
  ||||z   fS |t           j        k    r||dz  z
  |||dz  z   ||z   fS |t           j	        k    r||z
  ||dz  z
  |||dz  z   fS |t           j
        k    r|||dz  z
  ||z   ||dz  z   fS t          d|› �¦  «        ‚)z;Compute the background box for text anchored at `position`.é   zUnsupported position: )r   ÚTOP_LEFTÚ	TOP_RIGHTÚ
TOP_CENTERÚCENTERÚCENTER_OF_MASSÚBOTTOM_LEFTÚBOTTOM_RIGHTÚBOTTOM_CENTERÚCENTER_LEFTÚCENTER_RIGHTr.   )r7   r8   r9   Úcenter_xÚcenter_yÚtext_wÚtext_hs          r   Úresolve_text_background_xyxyrJ   N   s  € ð ,Ñ€HˆhØ�N€FˆFà•8Ô$Ò$Ð$Ø˜ FÑ*¨H°vÑ,=¸xÐGÐGØ	•XÔ'Ò	'Ð	'Ø˜&Ñ  (¨VÑ"3°X¸xÐGÐGØ	•XÔ(Ò	(Ð	(à�v ‘{Ñ"Ø�vÑØ�v ‘{Ñ"Øð	
ð 	
ð 
•X”_Ò	$Ð	$¨µHÔ4KÒ(KÐ(Kà�v ‘{Ñ"Ø�v ‘{Ñ"Ø�v ‘{Ñ"Ø�v ‘{Ñ"ð	
ð 	
ð 
•XÔ)Ò	)Ð	)Ø˜ 8¨fÑ#4°hÀÑ6GÐGÐGØ	•XÔ*Ò	*Ð	*Ø˜&Ñ  (¨H°hÀÑ6GÐGÐGØ	•XÔ+Ò	+Ð	+à�v ‘{Ñ"ØØ�v ‘{Ñ"Ø�vÑð	
ð 	
ð 
•XÔ)Ò	)Ð	)à�vÑØ�v ‘{Ñ"ØØ�v ‘{Ñ"ð	
ð 	
ð 
•XÔ*Ò	*Ð	*àØ�v ‘{Ñ"Ø�vÑØ�v ‘{Ñ"ð	
ð 	
õ Ð8¨hÐ8Ð8Ñ
9Ô
9Ð9r   ÚcolorÚidxc                 óŠ  — t          t          | ¦  «        }t          t          |dd¦  «        ¦  «        r|                     |¦  «        }t          |t          ¦  «        r|S t          t          |j        ¦  «        t          |j	        ¦  «        t          |j
        ¦  «        t          t          |dd¦  «        ¦  «        ¬¦  «        S )z?Resolve a color-like object to a concrete `Color` for an index.Úby_idxNÚaéÿ   )ÚrÚgÚbrO   )r   r   ÚcallableÚgetattrrN   r/   r
   r2   rQ   rR   rS   )rK   rL   Ú
color_likes      r   Úget_color_by_indexrW   …   s­   € å•c˜5Ñ!Ô!€Jå•˜
 H¨dÑ3Ô3Ñ4Ô4ð ,Ø×&Ò& sÑ+Ô+ˆ
Ý�*�eÑ$Ô$ð ØÐÝÝ
ˆjŒlÑ
Ô
Ý
ˆjŒlÑ
Ô
Ý
ˆjŒlÑ
Ô
Ý
�g�j # sÑ+Ô+Ñ
,Ô
,ð	ñ ô ð r   c                 ó¶   — t          |||¬¦  «        }t          |t          ¦  «        r"|t          j        k    r|t          k    rt
          S t          | |¬¦  «        S )Nr5   )rK   rL   )r6   r/   r   r%   ÚPENDING_TRACK_IDÚPENDING_TRACK_COLORrW   )rK   r)   r*   r+   rL   s        r   Úresolve_colorr[   •   sh   € õ ØØ#Ø!ðñ ô €Cõ 	�<¥Ñ-Ô-ð#à�KÔ-Ò-Ð-ØÕ#Ò#Ð#å"Ð"Ý E¨sÐ3Ñ3Ô3Ð3r   ÚtextÚmax_line_lengthc                 óŒ  — | sdgS t          | t          ¦  «        st          | ¦  «        } |€|                      ¦   «         pdgS |dk    rt          d¦  «        ‚|                      d¦  «        }g }|D ]O}|dk    r|                     d¦  «         Œt          j        ||ddd¬¦  «        }|                     |pdg¦  «         ŒP|pdgS )	a.  
    Wrap `text` to the specified maximum line length, respecting existing
    newlines. Falls back to str() if `text` is not already a string.

    Args:
        text: The text (or object) to wrap.
        max_line_length: Maximum width for each wrapped line.

    Returns:
        Wrapped lines.
    Ú Nr   z*max_line_length must be a positive integerú
TF)ÚwidthÚbreak_long_wordsÚreplace_whitespaceÚdrop_whitespace)	r/   r'   Ú
splitlinesr.   ÚsplitÚappendÚtextwrapÚwrapÚextend)r\   r]   Ú
paragraphsÚ	all_linesÚ	paragraphÚwrappeds         r   Ú	wrap_textro   ©   sý   € ð ð Øˆtˆå�d�CÑ Ô ð Ý�4‰yŒyˆàÐØ�ŠÑ Ô Ð( R DÐ(à˜!ÒÐÝÐEÑFÔFÐFà—’˜DÑ!Ô!€JØ€Iàð *ð *ˆ	Ø˜Š?ˆ?Ø×Ò˜RÑ Ô Ð Øå”-ØØ!Ø!Ø$Ø ð
ñ 
ô 
ˆð 	×Ò˜˜ R DÑ)Ô)Ð)Ð)àÐ˜˜Ðr   Úlabelsc                 ó®   — | �Pt          | ¦  «        t          |¦  «        k    r2t          dt          | ¦  «        › dt          |¦  «        › d�¦  «        ‚dS dS )ae  
    Validates that the number of provided labels matches the number of detections.

    Args:
        labels: A list of labels, one for each detection. Can
            be None.
        detections: The detections to be labeled.

    Raises:
        ValueError: If `labels` is not None and its length does not match the number
            of detections.
    NzThe number of labels (z+) does not match the number of detections (z.). Each detection should have exactly 1 label.)r-   r.   ©rp   r)   s     r   Ú_validate_labelsrs   ×   so   € ð Ð�c &™kœk­S°©_¬_Ò<Ð<Ýð,¥S¨¡[¤[ð ,ð ,Ý%(¨¡_¤_ð,ð ,ð ,ñ
ô 
ð 	
ð ÐÐ<Ð<r   z0.29.0z0.32.0)ÚtargetÚdeprecated_inÚ	remove_inc                 ó&   — t          | |¦  «         d S r   )r   rr   s     r   Úvalidate_labelsrx   ì   s   € õ 	ˆ�ÑÔÐÐÐr   Úcustom_labelsc           
      óB  — |�|S t           | j        v rv| j        t                    }t          |¦  «        t          | ¦  «        k    r8t          dt           › dt          |¦  «        › dt          | ¦  «        › d�¦  «        ‚d„ |D ¦   «         S | j        �kt          | j        ¦  «        t          | ¦  «        k    r5t          dt          | j        ¦  «        › dt          | ¦  «        › d�¦  «        ‚d„ | j        D ¦   «         S d	„ t          t          | ¦  «        ¦  «        D ¦   «         S )
aÏ  
    Retrieves the text labels for the detections.

    If `custom_labels` are provided, they are used. Otherwise, the labels are
    extracted from the `detections` object, prioritizing the 'class_name' field,
    then the `class_id`, and finally using the detection index as a string.

    Args:
        detections: The detections to get labels for.
        custom_labels: An optional list of custom labels.

    Returns:
        A list of text labels for each detection.

    Raises:
        ValueError: If `class_name` or `class_id` is present but its length
            does not match the number of detections (e.g. `detections.data`
            was mutated directly, bypassing `Detections` alignment checks).
    Nú'z' has z entries but detections has z - the two must stay aligned.c                 ó,   — g | ]}t          |¦  «        ‘ŒS r(   ©r'   ©Ú.0Úvs     r   ú
<listcomp>z#get_labels_text.<locals>.<listcomp>  s   € Ð,Ð,Ð,˜1•�A‘”Ð,Ð,Ð,r   z'class_id' has c                 ó,   — g | ]}t          |¦  «        ‘ŒS r(   r}   r~   s     r   r�   z#get_labels_text.<locals>.<listcomp>"  s   € Ð4Ð4Ð4˜1•�A‘”Ð4Ð4Ð4r   c                 ó,   — g | ]}t          |¦  «        ‘ŒS r(   r}   )r   Úis     r   r�   z#get_labels_text.<locals>.<listcomp>#  s   € Ð3Ð3Ð3�q�C�‰FŒFÐ3Ð3Ð3r   )r   Údatar-   r.   r3   Úrange)r)   ry   Úclass_namess      r   Úget_labels_textrˆ   õ   sQ  € ð, Ð ØÐå 
¤Ð/Ð/Ø ”oÕ&;Ô<ˆõ
 ˆ{ÑÔ�s :™œÒ.Ð.ÝðÕ)ð ð µ°[Ñ1AÔ1Að ð Ý&)¨*¡o¤oðð ð ñô ð ð
 -Ð, Ð,Ñ,Ô,Ð,ØÔÐ&ÝˆzÔ"Ñ#Ô#¥s¨:¡¤Ò6Ð6Ýð¥# jÔ&9Ñ":Ô":ð ð Ý"% j¡/¤/ðð ð ñô ð ð
 5Ð4 
Ô 3Ð4Ñ4Ô4Ð4Ø3Ð3�E¥# j¡/¤/Ñ2Ô2Ð3Ñ3Ô3Ð3r   ÚxyxyÚresolution_whc                 óÄ  — t          j        | t           j        d¬¦  «        }|\  }}|dd…df         dk     }||ddd…fxx         ||dd…f         z  cc<   | |dd…df         |k    z  }|||df         z
  }||ddd…fxx         |dd…t           j        f         z  cc<   |dd…df         dk     }||ddd…fxx         ||dd…f         z  cc<   | |dd…df         |k    z  }	|||	df         z
  }
||	ddd…fxx         |
dd…t           j        f         z  cc<   t	          t
          j        t           j                 |                     t           j        d	¬
¦  «        ¦  «        S )a8  
    Shifts `label` bounding boxes into the frame so that they are fully contained
    within the given resolution, prioritizing the top/left edge.
    Unlike `clip_boxes`, this function does not crop boxes.
    It moves them entirely if they exceed the frame boundaries.

    Args:
        xyxy: A numpy array of shape `(N, 4)` where each
            row corresponds to a bounding box in the format
            `(x_min, y_min, x_max, y_max)`.
        resolution_wh: A tuple `(width, height)`
            representing the resolution of the frame.

    Returns:
        A numpy array of shape `(N, 4)` with boxes shifted into frame.

    Examples:
        ```pycon
        >>> import numpy as np
        >>> from supervision.annotators.utils import snap_boxes
        >>> xyxy = np.array([
        ...     [-10, 10, 30, 50],     # Off left edge
        ...     [310, 200, 350, 250],  # Off right edge
        ...     [100, -20, 150, 30],   # Off top edge
        ...     [200, 220, 250, 270],  # Off bottom edge
        ...     [-20, 10, 350, 50],    # Wider than frame (370 vs 320)
        ...     [10, -20, 30, 260]     # Taller than frame (280 vs 240)
        ... ])
        >>> resolution_wh = (320, 240)
        >>> snapped_boxes = snap_boxes(xyxy=xyxy, resolution_wh=resolution_wh)
        >>> snapped_boxes
        array([[  0.,  10.,  40.,  50.],
               [280., 190., 320., 240.],
               [100.,   0., 150.,  50.],
               [200., 190., 250., 240.],
               [  0.,  10., 370.,  50.],
               [ 10.,   0.,  30., 280.]], dtype=float32)

        ```
    T)ÚdtypeÚcopyNr   é   r;   é   é   F)r�   )r0   ÚarrayÚfloat32Únewaxisr   ÚnptÚNDArrayÚastype)r‰   rŠ   Úresultra   ÚheightÚleft_overflowÚright_overflowÚright_shiftÚtop_overflowÚbottom_overflowÚbottom_shifts              r   Ú
snap_boxesrŸ   &  s¹  € õX ')¤h¨t½2¼:ÈDÐ&QÑ&QÔ&Q€FØ!�M€Eˆ6ð ˜1˜1˜1˜a˜4”L 1Ò$€MØ
ˆ=˜!˜A˜a˜%ÐÐ Ð Ô  F¨=¸!¸A¸#Ð+=Ô$>Ñ>Ð Ð Ñ à$�n¨°°°°1°¬¸Ò)=Ñ>€NØ˜& °Ð!2Ô3Ñ3€KØ
ˆ>˜1˜Q˜q˜5Ð Ð!Ð!Ô! [°°°µB´J°Ô%?Ñ?Ð!Ð!Ñ!ð ˜!˜!˜!˜Q˜$”< !Ò#€LØ
ˆ<˜˜1˜Q˜ÐÐÐÔ 6¨,¸¸!¸Ð*;Ô#<Ñ<ÐÐÑà$�}¨°°°°1°¬¸Ò)>Ñ?€OØ˜F ?°AÐ#5Ô6Ñ6€LØ
ˆ?˜A˜a ˜EÐ!Ð"Ð"Ô" l°1°1°1µb´j°=Ô&AÑAÐ"Ð"Ñ"å•”�BœJÔ'¨¯ªµr´zÈ¨Ñ)NÔ)NÑOÔOÐOr   c            	       ó†   — e Zd Zddej        fdedz  dededdfd„Zdeddfd	„Zd
ede	j
        ej                 fd„Zdd„ZdS )ÚTraceNr   Úmax_sizeÚstart_frame_idÚanchorr   c                 óú   — || _         || _        || _        t          j        g t
          ¬¦  «        | _        t          j        dt          j        ¬¦  «        | _	        t          j        g t
          ¬¦  «        | _
        d S )N©rŒ   ©r   r;   )Úcurrent_frame_idr¢   r¤   r0   r‘   r2   Úframe_idÚemptyr’   Úxyr4   )Úselfr¢   r£   r¤   s       r   Ú__init__zTrace.__init__i  sb   € ð !/ˆÔØ ˆŒØˆŒå.0¬h°rÅÐ.EÑ.EÔ.EˆŒÝ+-¬8°FÅ"Ä*Ð+MÑ+MÔ+MˆŒÝ02´¸Å3Ð0GÑ0GÔ0GˆŒˆˆr   r)   c                 óæ  — t          |¦  «        dk    r<t          j        dt          j        ¬¦  «        }t          j        g t
          ¬¦  «        }nn|j        €t          d¦  «        ‚t          j        | 	                    | j
        ¦  «        t          j        ¬¦  «        }t          j        |j        t
          ¬¦  «        }t          j        t          |¦  «        | j        t
          ¬¦  «        }t          j        | j        |g¦  «        | _        t          j        | j        |g¦  «        | _        t          j        | j        |g¦  «        | _        t          j        | j        ¦  «        }| j        �ud| j        cxk     rt          |¦  «        k     rVn nS| j        | j        z
  dz   }| j        |k    }| j        |         | _        | j        |         | _        | j        |         | _        | xj        dz  c_        dS )u)  Append a frame of detections to the trace history.

        A frame that detected nothing contributes no points but still advances
        the frame counter, keeping `max_size` a window over elapsed frames
        rather than over populated ones. An empty frame has no anchors and no
        `tracker_id`, so only frames that carry detections require one.

        Pruning runs on the next frame that does carry detections, measures
        the window from the advanced counter, and only fires once the distinct
        frames held in the history â€” counting the frame that triggers it â€”
        outnumber `max_size`. A track that had filled the window before a long
        gap therefore starts a fresh trail, while a track whose stored history
        stayed shorter than the window is still joined to its pre-gap points.

        History is normalised on the way in: anchor points are stored as
        `float32` and tracker ids are cast to NumPy's default integer dtype
        (`np.int_`), so tracker ids outside that dtype's range are unsupported.
        r   r§   r¦   NzNCould not put detections into Trace because Detections do not have tracker_id.r�   )r-   r0   rª   r’   r‘   r2   r4   r.   ÚasarrayÚget_anchors_coordinatesr¤   Úfullr¨   Úconcatenater©   r«   Úuniquer¢   )r¬   r)   r«   r4   r©   Úunique_frame_idÚmax_allowed_frame_idÚfiltering_masks           r   Úputz	Trace.putw  sÂ  € õ& ˆz‰?Œ?˜aÒÐÝ*,¬(°6ÅÄÐ*LÑ*LÔ*LˆBÝ/1¬x¸Å#Ð/FÑ/FÔ/FˆJˆJàÔ$Ð,Ý ð9ñô ð õ ”Ø×2Ò2°4´;Ñ?Ô?ÅrÄzðñ ô ˆBõ œ JÔ$9ÅÐEÑEÔEˆJå)+¬Ý�
‰OŒO˜TÔ2½#ð*
ñ *
ô *
ˆõ œ¨¬°xÐ'@ÑAÔAˆŒÝ”. $¤'¨2 Ñ/Ô/ˆŒÝœ.¨$¬/¸:Ð)FÑGÔGˆŒåœ) D¤MÑ2Ô2ˆàŒ=Ð$¨¨T¬]Ð)QÐ)QÒ)QÐ)Q½SÀÑ=QÔ=QÒ)QÐ)QÐ)QÐ)QÐ)QØ#'Ô#8¸4¼=Ñ#HÈ1Ñ#LÐ Ø!œ]Ð.BÒBˆNØ œM¨.Ô9ˆDŒMØ”g˜nÔ-ˆDŒGØ"œo¨nÔ=ˆDŒOàÐÔ Ñ"ÐÔÐÐr   r4   c                 ón   — t          j        | j        | j        |k             t           j        ¬¦  «        }|S )Nr¦   )r0   r¯   r«   r4   r’   )r¬   r4   r«   s      r   Úgetz	Trace.getª  s4   € Ý&(¤jØŒG�D”O zÒ1Ô2½"¼*ð'
ñ '
ô '
ˆð ˆ	r   c                 óÞ   — d| _         t          j        g t          ¬¦  «        | _        t          j        dt          j        ¬¦  «        | _        t          j        g t          ¬¦  «        | _        dS )a*  Restore the trace buffers to their initial empty state.

        Clears the accumulated `frame_id`, `xy`, and `tracker_id` history and
        rewinds `current_frame_id` to `0`, so the trace can be reused across
        independent streams without carrying over points from a previous run.
        r   r¦   r§   N)	r¨   r0   r‘   r2   r©   rª   r’   r«   r4   )r¬   s    r   ÚresetzTrace.reset°  sT   € ð !"ˆÔÝœ ­3Ð/Ñ/Ô/ˆŒÝ”(˜6­¬Ð4Ñ4Ô4ˆŒÝœ( 2­SÐ1Ñ1Ô1ˆŒˆˆr   )r   N)r   r    r!   r   r?   r2   r­   r	   r·   r”   r•   r0   r’   r¹   r»   r(   r   r   r¡   r¡   h  sÏ   € € € € € ð  $ØØ#œ?ð	Hð Hà˜‘*ðHð ðHð ð	Hð
 
ðHð Hð Hð Hð1#˜jð 1#¨Tð 1#ð 1#ð 1#ð 1#ðf˜cð  c¤k°"´*Ô&=ð ð ð ð ð
2ð 
2ð 
2ð 
2ð 
2ð 
2r   r¡   Ú	hex_colorc                 óä  — |                       ¦   «                              d¦  «        } t          | ¦  «        dk    r| dz  } t          | ¦  «        dk    rt          d| › �¦  «        ‚	 t	          | dd…         d¦  «        }t	          | dd	…         d¦  «        }t	          | d	d…         d¦  «        }t	          | dd…         d¦  «        }n%# t          $ r}t          d
| › �¦  «        |‚d}~ww xY w||||fS )aâ  
    Converts a hex color string (e.g. "#FF00FF" or "#FF00FF80") to an RGBA tuple.

    Args:
        hex_color: A hex color string.

    Returns:
        RGBA values in range 0-255.

    Raises:
        ValueError: If the format is invalid.

    Examples:
        ```pycon
        >>> from supervision.annotators.utils import hex_to_rgba
        >>> hex_to_rgba("#FF00FF")
        (255, 0, 255, 255)
        >>> hex_to_rgba("#FF00FF80")
        (255, 0, 255, 128)

        ```
    ú#é   ÚFFé   zInvalid hex color format: r   r;   é   r�   zInvalid hex digits in N)ÚstripÚremoveprefixr-   r.   r2   )r¼   rQ   rR   rS   rO   Úexcs         r   Úhex_to_rgbarÆ   ½  s  € ð. —’Ñ!Ô!×.Ò.¨sÑ3Ô3€IÝ
ˆ9�~„~˜ÒÐØ�TÑˆ	Ý
ˆ9�~„~˜ÒÐÝÐA°iÐAÐAÑBÔBÐBðHÝ�	˜!˜A˜#” Ñ#Ô#ˆÝ�	˜!˜A˜#” Ñ#Ô#ˆÝ�	˜!˜A˜#” Ñ#Ô#ˆÝ�	˜!˜A˜#” Ñ#Ô#ˆˆøÝð Hð Hð HÝÐ=°)Ð=Ð=Ñ>Ô>ÀCÐGøøøøðHøøøàˆq�!�Qˆ<Ðs   Á&A C Ã
C)ÃC$Ã$C)Úrgbac                 óŒ   — t          | ¦  «        dk    st          d„ | D ¦   «         ¦  «        st          d¦  «        ‚ dj        | Ž S )aÇ  
    Converts an RGBA tuple (0-255 each) to a hex color string.

    Args:
        rgba: RGBA values in range 0-255.

    Returns:
        Hex color string in the format "#RRGGBBAA".

    Raises:
        ValueError: If `rgba` is not a 4-tuple or contains values outside 0-255.

    Examples:
        ```pycon
        >>> from supervision.annotators.utils import rgba_to_hex
        >>> rgba_to_hex((255, 0, 255, 128))
        '#FF00FF80'

        ```
    r�   c              3   ó6   K  — | ]}d |cxk    odk    nc V — ŒdS )r   rP   Nr(   )r   r   s     r   ú	<genexpr>zrgba_to_hex.<locals>.<genexpr>ø  s6   è è € Ð =Ð =°1  a  ¢ ¨3¢   Ð =Ð =Ð =Ð =Ð =Ð =r   z1RGBA must be a 4-tuple with values between 0-255.z#{:02X}{:02X}{:02X}{:02X})r-   Úallr.   Úformat)rÇ   s    r   Úrgba_to_hexrÍ   ã  sN   € õ* ˆ4�y„y�A‚~€~�SÐ =Ð =¸Ð =Ñ =Ô =Ñ=Ô=€~ÝÐLÑMÔMÐMØ-Ð&Ô-¨tÐ4Ð4r   c                 ój   — t          t          j        d|                      ¦   «         ¦  «        ¦  «        S )aù  
    Checks if a given string is a valid hex color.

    Args:
        hex_color: A hex color string with an optional leading "#". Supports
            6-digit (RGB) or 8-digit (RGBA) formats.

    Returns:
        True if the string is a valid 6- or 8-digit hex color, otherwise False.

    Examples:
        ```pycon
        >>> from supervision.annotators.utils import is_valid_hex
        >>> is_valid_hex("#FF00FF")
        True
        >>> is_valid_hex("not-a-color")
        False

        ```
    z!#?[0-9A-Fa-f]{6}([0-9A-Fa-f]{2})?)ÚboolÚreÚ	fullmatchrÃ   )r¼   s    r   Úis_valid_hexrÒ   ý  s)   € õ* •”ÐAÀ9Ç?Â?ÑCTÔCTÑUÔUÑVÔVÐVr   Úx1Úy1Úx2Úy2c                 óP   — t          dt          ||z
  || z
  ¦  «        dz  ¦  «        S )aÖ  
    Computes a blur kernel size proportional to the shorter side of a bounding box.

    Args:
        x1: Left edge of the bounding box.
        y1: Top edge of the bounding box.
        x2: Right edge of the bounding box.
        y2: Bottom edge of the bounding box.

    Returns:
        Kernel size as one-third of the shorter dimension, minimum 1.

    Examples:
        ```pycon
        >>> calculate_dynamic_kernel_size(0, 0, 90, 60)
        20

        ```
    r�   rŽ   ©ÚmaxÚmin©rÓ   rÔ   rÕ   rÖ   s       r   Úcalculate_dynamic_kernel_sizerÜ     ó+   € õ( ˆq•#�b˜2‘g˜r B™wÑ'Ô'¨1Ñ,Ñ-Ô-Ð-r   c                 óP   — t          dt          ||z
  || z
  ¦  «        dz  ¦  «        S )aÒ  
    Computes a pixelation size proportional to the shorter side of a bounding box.

    Args:
        x1: Left edge of the bounding box.
        y1: Top edge of the bounding box.
        x2: Right edge of the bounding box.
        y2: Bottom edge of the bounding box.

    Returns:
        Pixel size as one-half of the shorter dimension, minimum 1.

    Examples:
        ```pycon
        >>> calculate_dynamic_pixel_size(0, 0, 90, 60)
        30

        ```
    r�   r;   rØ   rÛ   s       r   Úcalculate_dynamic_pixel_sizerß   ,  rÝ   r   r   )4rÐ   rh   Úenumr   Útypingr   r   Únumpyr0   Únumpy.typingr”   Ú	deprecater   r   Úsupervision.configr   Úsupervision.detection.corer	   Úsupervision.draw.colorr
   r   Úsupervision.geometry.corer   ÚGREYrZ   rY   r   r$   r2   r•   Úint_r6   ÚtuplerJ   rW   r[   Úobjectr   r'   ro   rs   rx   rˆ   r’   rŸ   r¡   rÆ   rÍ   rÏ   rÒ   rÜ   rß   r(   r   r   ú<module>rí      sÃ  ðØ 	€	€	€	Ø €€€Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð Ð Ð à Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø &Ð &Ð &Ð &Ð &Ð &Ð &Ð &à 4Ð 4Ð 4Ð 4Ð 4Ð 4Ø 1Ð 1Ð 1Ð 1Ð 1Ð 1Ø 6Ð 6Ð 6Ð 6Ð 6Ð 6Ð 6Ð 6Ø .Ð .Ð .Ð .Ð .Ð .à”jÐ ØÐ ð1ð 1ð 1ð 1ð 1�$ñ 1ô 1ð 1ð, 8CÔ7Hð%Kð %KØð%Kàð%Kð  ¤¨B¬GÔ 4Ñ4ð%Kð 	ð	%Kð %Kð %Kð %KðP4:Ø˜c 3˜hœð4:à�3˜�8Œ_ð4:ð ð4:ð ˆ3��S˜#ÐÔð	4:ð 4:ð 4:ð 4:ðn˜e lÑ2ð ¸ð Àð ð ð ð ð( 8CÔ7Hð	4ð 4Ø�<Ñð4àð4ð ð4ð  ¤¨B¬GÔ 4Ñ4ð	4ð
 ð4ð 4ð 4ð 4ð(+ð +�Fð +¨S°4©Zð +À4ÈÄ9ð +ð +ð +ð +ð\
˜T #œY¨Ñ-ð 
¸:ð 
È$ð 
ð 
ð 
ð 
ð* €ØØØðñ ô ð
˜D œI¨Ñ,ð ¸*ð Èð ð ð ñô ð
ð.4Øð.4Ø+/°¬9°tÑ+;ð.4à	ˆ#„Yð.4ð .4ð .4ð .4ðb?PØ
Œ+�b”jÔ
!ð?Pà˜˜c˜”?ð?Pð 	„[�”Ôð?Pð ?Pð ?Pð ?PðDR2ð R2ð R2ð R2ð R2ñ R2ô R2ð R2ðj#˜3ð # 5¨¨c°3¸Ð);Ô#<ð #ð #ð #ð #ðL5�e˜C  c¨3Ð.Ô/ð 5°Cð 5ð 5ð 5ð 5ð4W˜Cð W Dð Wð Wð Wð Wð0. cð .¨sð .¸ð .Àð .Èð .ð .ð .ð .ð.. Sð .¨cð .°sð .Àð .Èð .ð .ð .ð .ð .ð .r   