§
    >²¸jÖX  ã                   ón  — U 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ej        ej                 deeef         dej        ej                 fd	„Z	 d-dej        ej                 d
ededz  dej        ej                 fd„Z e	ej        ddddi¬¦  «        	 	 d.dej        ej                 deeef         dedej        ej                 dz  dej        ej                 f
d„¦   «         Zdej        ej                 dej        ej                 fd„Zdej        ej                 dej        ej                 dej        ej                 fd„Zdej        ej                 dej        ej                 dej        ej                 fd„Zdej        ej                 dej        ej                 fd„Zdej        ej                 dej        ej                 fd„Zej        dej        dej         dej!        dej"        d ej#        d!ej$        d"ej%        d#ej&        d$i	Z'e(eeeef         f         e)d%<   dej        ej                 d&edej        ej                 fd'„Z*dej        ej                 d(edej        ej+                 fd)„Z,	 d/dej        ej                 d+edej        ej                 fd,„Z-dS )0é    )ÚAnyÚcastN)Ú
TargetModeÚ
deprecated)Úbox_iou_batch)ÚPositionÚxyxyÚresolution_whÚreturnc                 óä   — t          j        | ¦  «        }|\  }}|dd…ddgf                              d|¦  «        |dd…ddgf<   |dd…ddgf                              d|¦  «        |dd…ddgf<   |S )aÝ  
    Clips bounding boxes coordinates to fit within the frame resolution.

    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 of the form
            `(width, height)` representing the resolution of the frame.

    Returns:
        A numpy array of shape `(N, 4)` where each row
            corresponds to a bounding box with coordinates clipped to fit
            within the frame resolution.

    Examples:
        ```pycon
        >>> import numpy as np
        >>> import supervision as sv
        >>> xyxy = np.array([
        ...     [10, 20, 300, 200],
        ...     [15, 25, 350, 450],
        ...     [-10, -20, 30, 40]
        ... ])
        >>> sv.clip_boxes(xyxy=xyxy, resolution_wh=(320, 240))
        array([[ 10,  20, 300, 200],
               [ 15,  25, 320, 240],
               [  0,   0,  30,  40]])

        ```
    Nr   é   é   é   )ÚnpÚcopyÚclip)r	   r
   ÚresultÚwidthÚheights        úq/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/supervision/detection/utils/boxes.pyÚ
clip_boxesr      sŽ   € õF &(¤W¨T¡]¤]€FØ!�M€Eˆ6Ø˜q˜q˜q 1 a &˜yÔ)×.Ò.¨q°%Ñ8Ô8€Fˆ1ˆ1ˆ1ˆq�!ˆfˆ9ÑØ˜q˜q˜q 1 a &˜yÔ)×.Ò.¨q°&Ñ9Ô9€Fˆ1ˆ1ˆ1ˆq�!ˆfˆ9ÑØ€Mó    ÚpxÚpyc                 óÜ  — |€|}t          j        | j        t           j        ¦  «        }||g}|�rt	          |¦  «        t	          |¦  «        }}t          j        t           j        ¦  «        j        dz  }t          t          |¦  «        t          |¦  «        ¦  «        |k    oIt          j	        t          j        | j        t           j
        ¦  «        r| |k    n| | k    | |k    z  ¦  «        }|                      |rt           j        nt          ¦  «        }t          j        ||g|j        ¬¦  «        }n7t          t          j        t"                   |                      ¦   «         ¦  «        }|dd…ddgfxx         |z  cc<   |dd…ddgfxx         |z  cc<   |r­|j        t          k    r�t          j        t           j        ¦  «        }t          j	        ||j        k    ||j        k    z  ¦  «        }	t          t          j        t           j                 t          j        ||	rt           j        nt           j        ¬¦  «        ¦  «        S t          t          j        t           j                 |¦  «        S )aÈ  
    Pads bounding boxes coordinates with a constant padding.

    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)`.
        px: The padding value to be added to both the left and right sides of
            each bounding box.
        py: The padding value to be added to both the top and bottom
            sides of each bounding box. If not provided, `px` will be used for both
            dimensions.

    Returns:
        A numpy array of shape `(N, 4)` where each row corresponds to a
            bounding box with coordinates padded according to the provided padding
            values. Integer inputs produce `int64` output, or `float64` if a padded
            coordinate exceeds the `int64` range. Floating-point inputs preserve
            their dtype.

    Examples:
        ```pycon
        >>> import numpy as np
        >>> import supervision as sv
        >>> xyxy = np.array([
        ...     [10, 20, 30, 40],
        ...     [15, 25, 35, 45]
        ... ])
        >>> sv.pad_boxes(xyxy=xyxy, px=5, py=10)
        array([[ 5, 10, 35, 50],
               [10, 15, 40, 55]])

        ```
    Nr   ©Údtyper   r   r   )r   Ú
issubdtyper   ÚintegerÚintÚiinfoÚint64ÚmaxÚabsÚallÚunsignedintegerÚastypeÚobjectÚasarrayr   ÚnptÚNDArrayr   r   ÚminÚnumberÚfloat64)
r	   r   r   Úinteger_inputÚpaddingÚexact_integer_limitÚis_safe_to_castr   ÚlimitsÚ
fits_int64s
             r   Ú	pad_boxesr5   8   s  € ðN 
€zØˆå”M $¤*­b¬jÑ9Ô9€MØ-/°¨H€GØñ 5Ý�R‘”�#˜b™'œ'ˆBˆÝ œh¥r¤xÑ0Ô0Ô4¸Ñ9ÐÝ�c "™gœg¥s¨2¡w¤wÑ/Ô/Ð3FÒFð 
Í2Ì6åŒ}˜TœZ­Ô);Ñ<Ô<ðPˆDÐ'Ò'Ð'àÐ.Ð.Ò.°4Ð;NÒ3NÑOñL
ô L
ˆð —’¨ÐD�RœX˜X½fÑEÔEˆÝ”*˜b "˜X¨V¬\Ð:Ñ:Ô:ˆˆå•c”k¥#Ô&¨¯	ª	©¬Ñ4Ô4ˆØ
ˆ1ˆ1ˆ1ˆq�!ˆfˆ9ÐÐÔ˜Ñ ÐÐÑØ
ˆ1ˆ1ˆ1ˆq�!ˆfˆ9ÐÐÔ˜Ñ ÐÐÑàð 
˜œ­Ò/Ð/Ý”�"œ(Ñ#Ô#ˆÝ”V˜V v¤zÒ1°fÀÄ
Ò6JÑKÑLÔLˆ
ÝÝŒK�œ	Ô"ÝŒJ�v°Ð%K¥R¤X XÅÄÐLÑLÔLñ
ô 
ð 	
õ •”�BœIÔ&¨Ñ/Ô/Ð/r   z0.27.0z0.31.0Únormalized_xyxy)ÚtargetÚdeprecated_inÚ	remove_inÚargs_mappingç      ð?Únormalization_factorc                 óæ   — |\  }}t          j        | j        t           j        ¦  «        r| j        nt          j        t           j        ¦  «        }t          j        ||||g|¬¦  «        }||z  }| |z  S )a¹  
    Convert normalized bounding box coordinates to absolute pixel coordinates.

    Multiplies each bounding box coordinate by image size and divides by
    `normalization_factor`, mapping values from normalized `[0, normalization_factor]`
    to absolute pixel values for a given resolution.

    Args:
        xyxy: Normalized bounding boxes of shape `(N, 4)`,
            where each row is `(x_min, y_min, x_max, y_max)`, values in
            `[0, normalization_factor]`.
        resolution_wh: Target image resolution as `(width, height)`.
        normalization_factor: Maximum value of input coordinate range.
            Defaults to `1.0`.

    Returns:
        Array of shape `(N, 4)` with absolute coordinates in
            `(x_min, y_min, x_max, y_max)` format.

    Examples:
        ```pycon
        >>> import numpy as np
        >>> import supervision as sv
        >>> xyxy = np.array([
        ...     [0.1, 0.2, 0.5, 0.6],
        ...     [0.3, 0.4, 0.7, 0.8],
        ...     [0.2, 0.1, 0.6, 0.5]
        ... ])
        >>> sv.denormalize_boxes(xyxy, (1280, 720))
        array([[128., 144., 640., 432.],
               [384., 288., 896., 576.],
               [256.,  72., 768., 360.]])

        ```

        ```pycon
        >>> xyxy = np.array([
        ...     [256., 128., 768., 640.]
        ... ])
        >>> sv.denormalize_boxes(xyxy, (1280, 720), normalization_factor=1024.0)
        array([[320.,  90., 960., 450.]])

        ```
    r   )r   r   r   Úinexactr.   Úarray)r	   r
   r<   r6   r   r   Úscale_dtypeÚscales           r   Údenormalize_boxesrB   ~   ss   € ðp "�M€Eˆ6õ
 ”m D¤Jµ´
Ñ;Ô;ÐUˆŒ
ˆ
ÅÄÍ"Ì*ÑAUÔAUð õ ŒH�e˜V U¨FÐ3¸;ÐGÑGÔG€EØ	Ð!Ñ!€Eà�%‰<Ðr   c           	      ó  — t          j        | ¦  «        } | j        dk    r| S t          j        | dd…df         | dd…df         ¦  «        }t          j        | dd…df         | dd…df         ¦  «        }t          j        | dd…df         | dd…df         ¦  «        }t          j        | dd…df         | dd…df         ¦  «        }t          t          j        t           j                 t          j	        ||||gd¬¦  «        ¦  «        S )aZ  Order each box's corners so that `x_min <= x_max` and `y_min <= y_max`.

    `Detections.xyxy` is defined as `(x_min, y_min, x_max, y_max)`, and every
    box operation in the library relies on that ordering: `box_iou_batch`
    clamps its intersection widths at zero, so a box whose corners arrive
    swapped scores an IoU of `0` even against itself. `box_area` hides the
    problem rather than surfacing it, because negating both sides leaves their
    product positive. Sorting the corner pairs restores the invariant without
    moving the region a box describes; a correctly ordered box is unchanged.

    Args:
        xyxy: Boxes of shape `(N, 4)`, each row `(x_min, y_min, x_max, y_max)`,
            possibly with either corner pair transposed.

    Returns:
        Boxes of shape `(N, 4)` with both corner pairs in ascending order.

    Examples:
        ```pycon
        >>> import numpy as np
        >>> from supervision.detection.utils.boxes import _sort_box_corners
        >>> _sort_box_corners(np.array([[300.0, 320.0, 200.0, 80.0]]))
        array([[200.,  80., 300., 320.]])

        ```
    r   Nr   r   r   éÿÿÿÿ©Úaxis)
r   r)   ÚsizeÚminimumÚmaximumr   r*   r+   r-   Ústack)r	   Úx_minÚx_maxÚy_minÚy_maxs        r   Ú_sort_box_cornersrO   Ã   sù   € õ: Œ:�dÑÔ€DØ„y�A‚~€~ØˆÝŒJ�t˜A˜A˜A˜q˜D”z 4¨¨¨¨1¨¤:Ñ.Ô.€EÝŒJ�t˜A˜A˜A˜q˜D”z 4¨¨¨¨1¨¤:Ñ.Ô.€EÝŒJ�t˜A˜A˜A˜q˜D”z 4¨¨¨¨1¨¤:Ñ.Ô.€EÝŒJ�t˜A˜A˜A˜q˜D”z 4¨¨¨¨1¨¤:Ñ.Ô.€EÝ•”�BœIÔ&­¬°%¸ÀÀuÐ1MÐTVÐ(WÑ(WÔ(WÑXÔXÐXr   Úoffsetc                 ó4   — | t          j        ||g¦  «        z   S )a£  
    Args:
        xyxy: An array of shape `(n, 4)` containing the
            bounding boxes coordinates in format `[x1, y1, x2, y2]`
        offset: An array of shape `(2,)` containing offset values in format
            is `[dx, dy]`.

    Returns:
        Repositioned bounding boxes.

    Examples:
        ```pycon
        >>> import numpy as np
        >>> import supervision as sv
        >>> xyxy = np.array([
        ...     [10, 10, 20, 20],
        ...     [30, 30, 40, 40]
        ... ])
        >>> offset = np.array([5, 5])
        >>> sv.move_boxes(xyxy=xyxy, offset=offset)
        array([[15, 15, 25, 25],
               [35, 35, 45, 45]])

        ```
    )r   Úhstack)r	   rP   s     r   Ú
move_boxesrS   ê   s   € ð8 •"”)˜V VÐ,Ñ-Ô-Ñ-Ð-r   Úxyxyxyxyc                 ó   — | |z   S )a¢  
    Args:
        xyxyxyxy: An array of shape `(n, 4, 2)` containing the
        oriented bounding boxes coordinates in format
        `[[x1, y1], [x2, y2], [x3, y3], [x3, y3]]`
        offset: An array of shape `(2,)` containing offset values in format
            is `[dx, dy]`.

    Returns:
        Repositioned bounding boxes.

    Examples:
        ```pycon
        >>> import numpy as np
        >>> from supervision.detection.utils.boxes import move_oriented_boxes
        >>> xyxyxyxy = np.array([
        ...     [
        ...         [20, 10],
        ...         [10, 20],
        ...         [20, 30],
        ...         [30, 20]
        ...     ],
        ...     [
        ...         [30, 30],
        ...         [20, 40],
        ...         [30, 50],
        ...         [40, 40]
        ...     ]
        ... ])
        >>> offset = np.array([5, 5])
        >>> move_oriented_boxes(xyxyxyxy=xyxyxyxy, offset=offset)
        array([[[25, 15],
                [15, 25],
                [25, 35],
                [35, 25]],
        <BLANKLINE>
               [[35, 35],
                [25, 45],
                [35, 55],
                [45, 45]]])

        ```
    © )rT   rP   s     r   Úmove_oriented_boxesrW   	  s   € ð\ �fÑÐr   Úcornersc           
      ó¬  — t          t          j        t          j                 t          j        | ¦  «        ¦  «        } | j        dk    s| j        dd…         dk    rt          d| j        › �¦  «        ‚| dd…dd…dd…f         }t          j	        | j
        t          j        ¦  «        rTt          j        |                      t          ¦  «        |                     t          ¦  «        z
  t          j        ¬¦  «        }nC|                      t          j        d	¬
¦  «        |                     t          j        d	¬
¦  «        z
  }|d         }|d         }|t          j        |dd¬¦  «        z  |t          j        |dd¬¦  «        z  z
  }t          t          j        t          j                 dt          j        t          j        |d¬¦  «        ¦  «        z  ¦  «        S )a`  Compute the area of N oriented bounding boxes using the shoelace formula.

    Args:
        corners: OBB corner coordinates with shape `(N, 4, 2)`.

    Returns:
        Area of each box as a 1-D float64 array of shape `(N,)`.

    Raises:
        ValueError: If `corners` does not have shape `(N, 4, 2)`.

    Examples:
        ```pycon
        >>> import numpy as np
        >>> from supervision.detection.utils.boxes import obb_polygon_area
        >>> corners = np.array([[[0, 5], [5, 10], [10, 5], [5, 0]]], dtype=np.float32)
        >>> obb_polygon_area(corners)
        array([50.])

        ```
    r   éþÿÿÿN©é   r   z'corners must have shape (N, 4, 2); got r   r   r   F)r   ©.r   ©.r   rD   rE   g      à?)r   r*   r+   r   r-   r)   ÚndimÚshapeÚ
ValueErrorr   r   r   r'   r(   r.   Úrollr$   Úsum)rX   ÚoriginÚ
translatedÚxÚyÚcrosss         r   Úobb_polygon_areari   :  s“  € õ, •3”;�rœyÔ)­2¬:°gÑ+>Ô+>Ñ?Ô?€GØ„|�qÒÐ˜GœM¨"¨#¨#Ô.°&Ò8Ð8ÝÐRÀ7Ä=ÐRÐRÑSÔSÐSð
 �Q�Q�Q˜˜!˜˜Q˜Q˜Q�YÔ€FÝ	„}�W”]¥B¤JÑ/Ô/ð 	
õ ”ZØ�NŠN�6Ñ"Ô" V§]¢]µ6Ñ%:Ô%:Ñ:Å"Ä*ð
ñ 
ô 
ˆ
ˆ
ð —^’^¥B¤J°U�^Ñ;Ô;¸f¿mºmÝŒJ˜Uð ?Lñ ?
ô ?
ñ 
ˆ
ð 	�6Ô€AØ�6Ô€AØ•”˜˜2 BÐ'Ñ'Ô'Ñ'¨!­b¬g°a¸À"Ð.EÑ.EÔ.EÑ*EÑE€EÝ•”�BœJÔ'¨­r¬vµb´f¸UÈÐ6LÑ6LÔ6LÑ/MÔ/MÑ)MÑNÔNÐNr   c           	      óH  — t          t          j        t          j                 t          j        | ¦  «        ¦  «        } | j        dk    s| j        dd…         dk    rt          d| j        › �¦  «        ‚| d          	                    d¬¦  «        }| d	          	                    d¬¦  «        }| d          
                    d¬¦  «        }| d	          
                    d¬¦  «        }t          t          j        t          j                 t          j        ||||gd¬¦  «        ¦  «        S )
ad  Convert oriented bounding box corners to axis-aligned bounding boxes.

    Args:
        xyxyxyxy: OBB corner coordinates with shape `(N, 4, 2)` where each
            box is represented as `[[x1, y1], [x2, y2], [x3, y3], [x4, y4]]`.

    Returns:
        Axis-aligned bounding boxes as an array of shape `(N, 4)`
            in `(x_min, y_min, x_max, y_max)` format.

    Raises:
        ValueError: If `xyxyxyxy` does not have shape `(N, 4, 2)`.

    Examples:
        ```pycon
        >>> import numpy as np
        >>> import supervision as sv
        >>> corners = np.array([
        ...     [[0, 0], [10, 0], [10, 5], [0, 5]],
        ...     [[5, 5], [15, 5], [15, 10], [5, 10]],
        ... ], dtype=np.float32)
        >>> sv.xyxyxyxy_to_xyxy(corners)
        array([[ 0.,  0., 10.,  5.],
               [ 5.,  5., 15., 10.]], dtype=float32)

        ```
    r   rZ   Nr[   ú(xyxyxyxy must have shape (N, 4, 2); got r]   rD   rE   r^   )r   r*   r+   r   r-   r)   r_   r`   ra   r,   r#   rJ   )rT   rK   rM   rL   rN   s        r   Úxyxyxyxy_to_xyxyrl   h  sÿ   € õ< •C”K¥¤	Ô*­B¬J°xÑ,@Ô,@ÑAÔA€HØ„}˜ÒÐ˜Xœ^¨B¨C¨CÔ0°FÒ:Ð:ÝÐTÀHÄNÐTÐTÑUÔUÐUØ�VÔ× Ò  bÐ Ñ)Ô)€EØ�VÔ× Ò  bÐ Ñ)Ô)€EØ�VÔ× Ò  bÐ Ñ)Ô)€EØ�VÔ× Ò  bÐ Ñ)Ô)€EÝ•”�BœIÔ&­¬°%¸ÀÀuÐ1MÐTVÐ(WÑ(WÔ(WÑXÔXÐXr   )ç        rm   )ç      ð¿rm   )r;   rm   )rm   rn   )rm   r;   )rn   rn   )r;   rn   )rn   r;   )r;   r;   Ú_ANCHOR_OFFSETSÚanchorc                 óÂ  — t          j        | t           j        ¬¦  «        }|j        dk    s|j        dd…         dk    rt          d|j        › �¦  «        ‚|t          vrt          |› d�¦  «        ‚t          |         \  }}|                     d¬	¦  «        }|dd…df         |dd…d
f         z
  dz  }|dd…df         |dd…df         z
  dz  }t          j        |dd…d
f         ¦  «        t          j        |dd…d
f         ¦  «        k    }t          j	        |dd…df         ||¦  «        }	t          j	        |dd…df         ||¦  «        }
t          j	        |	dd…d
f         d
k     dd…df         |	 |	¦  «        }	t          j	        |
dd…df         d
k     dd…df         |
 |
¦  «        }
t          t          j        t           j                 |||	z  z   ||
z  z   ¦  «        S )aÁ  Locate an anchor point on each oriented bounding box.

    The returned point always lies on the oriented rectangle itself: corners map
    to corners, side anchors to side midpoints, and `CENTER` to the box center.
    For an axis-aligned box the result matches the anchor derived from the
    envelope, so this is a drop-in replacement that stops the anchor from drifting
    off a rotated body.

    Args:
        xyxyxyxy: OBB corner coordinates with shape `(N, 4, 2)` in winding order,
            each box as `[[x1, y1], [x2, y2], [x3, y3], [x4, y4]]`.
        anchor: The anchor position to locate. `Position.CENTER_OF_MASS` is not
            supported here, as it is defined on a mask rather than a box.

    Returns:
        Anchor coordinates as an array of shape `(N, 2)`.

    Raises:
        ValueError: If `xyxyxyxy` does not have shape `(N, 4, 2)`, or the anchor
            is not supported.

    Note:
        Corners must be in consecutive winding order (clockwise or
        counter-clockwise). Non-sequential ordering (e.g. diagonal pairs)
        silently produces incorrect results.

        Width and height are determined by x-axis projection of each half-side
        vector. When a box rotates past ``arctan(w/h)`` (approx. 68 deg for a
        10 x 4 box) the assigned *width* side flips discontinuously, producing
        a jump in anchor position (~``|w - h|`` pixels for ``BOTTOM_CENTER``).
        The anchor always lies on the box; the effect is cosmetic for static
        images but visible on rotating objects in video.

    Examples:
        ```pycon
        >>> import numpy as np
        >>> from supervision.detection.utils.boxes import _oriented_box_anchors
        >>> from supervision.geometry.core import Position
        >>> corners = np.array(
        ...     [[[0, 0], [10, 0], [10, 4], [0, 4]]], dtype=np.float32
        ... )
        >>> _oriented_box_anchors(corners, Position.BOTTOM_CENTER)
        array([[5., 4.]])

        ```
    r   r   rZ   Nr[   rk   z is not supported.r   rE   r   r   )r   r)   r.   r_   r`   ra   ro   Úmeanr$   Úwherer   r*   r+   )rT   rp   rX   ÚsxÚsyÚcenterÚhalf_side_aÚhalf_side_bÚis_widthr   r   s              r   Ú_oriented_box_anchorsrz   Ÿ  sñ  € õb Œj˜­¬Ð4Ñ4Ô4€GØ„|�qÒÐ˜GœM¨"¨#¨#Ô.°&Ò8Ð8ÝÐSÀGÄMÐSÐSÑTÔTÐTØ•_Ð$Ð$Ý˜FÐ6Ð6Ð6Ñ7Ô7Ð7Ý˜VÔ$�F€Bˆà�\Š\˜qˆ\Ñ!Ô!€Fà˜1˜1˜1˜a˜4”= 7¨1¨1¨1¨a¨4¤=Ñ0°AÑ5€KØ˜1˜1˜1˜a˜4”= 7¨1¨1¨1¨a¨4¤=Ñ0°AÑ5€Kõ
 Œv�k ! ! ! Q $Ô'Ñ(Ô(­B¬F°;¸q¸q¸qÀ!¸tÔ3DÑ,EÔ,EÒE€HÝŒH�X˜a˜a˜a ˜gÔ&¨°[ÑAÔA€EÝŒX�h˜q˜q˜q $˜wÔ'¨°kÑBÔB€FåŒH�e˜A˜A˜A˜q˜D”k A’o q q q¨$ wÔ/°%°¸Ñ?Ô?€EÝŒX�v˜a˜a˜a ˜d”| aÒ'¨¨¨¨D¨Ô1°F°7¸FÑCÔC€Få•”�BœJÔ'¨°"°u±*Ñ)<¸rÀF¹{Ñ)JÑKÔKÐKr   Úfactorc           	      óZ  — t          j        | j        t           j        ¦  «        �r«d}t          j        t          j        | j        t           j        ¦  «        r| |k    n| | k    | |k    z  ¦  «        }|r!|                      t           j        ¦  «        } �n<t          j        |¦  «        �r| 	                    ¦   «         \  }}|                      t          ¦  «        }|dd…dd…f         |dd…dd…f         z   }|dd…dd…f         |dd…dd…f         z
  }d|z  }	t          j        ||z  ||z  z
  |	z  t           j        ¬¦  «        }
t          j        ||z  ||z  z   |	z  t           j        ¬¦  «        }t          t          j        t           j                 t          j        |
|fd¬¦  «        ¦  «        S |                      t           j        ¦  «        } t          t          j        t           j                 | dd…dd…f         | dd…dd…f         z   dz  ¦  «        }t          t          j        t           j                 | dd…dd…f         | dd…dd…f         z
  |z  ¦  «        }t          t          j        t           j                 t          j        ||dz  z
  ||dz  z   fd¬¦  «        ¦  «        S )a—  
    Scale the dimensions of bounding boxes.

    Args:
        xyxy: An integer or floating-point array of shape `(n, 4)` containing
            bounding box coordinates in format `[x1, y1, x2, y2]`.
        factor: A float value representing the factor by which the box
            dimensions are scaled. A factor greater than 1 enlarges the boxes, while a
            factor less than 1 shrinks them.

    Returns:
        Scaled bounding boxes. Integer input arrays produce `float64` output;
        floating-point inputs preserve their existing dtype.

    Examples:
        ```pycon
        >>> import numpy as np
        >>> import supervision as sv
        >>> xyxy = np.array([
        ...     [10, 10, 20, 20],
        ...     [30, 30, 40, 40]
        ... ])
        >>> sv.scale_boxes(xyxy=xyxy, factor=1.5)
        array([[ 7.5,  7.5, 22.5, 22.5],
               [27.5, 27.5, 42.5, 42.5]])

        ```
    l         € Nr   r   r   rE   )r   r   r   r   r%   r&   r'   r.   ÚisfiniteÚas_integer_ratior(   r)   r   r*   r+   ÚfloatingÚconcatenate)r	   r{   r1   r2   Úfactor_numeratorÚfactor_denominatorÚinteger_coordinatesÚcoordinate_sumÚcoordinate_sizeÚdenominatorÚlowerÚupperÚcentersÚ	new_sizess                 r   Úscale_boxesr‹   é  sË  € õ> 
„}�T”Z¥¤Ñ,Ô,ñ &+Ø#ÐÝœ&åŒ}˜TœZ­Ô);Ñ<Ô<ðPˆDÐ'Ò'Ð'àÐ.Ð.Ò.°4Ð;NÒ3NÑOñ
ô 
ˆð
 ð 	+Ø—;’;�rœzÑ*Ô*ˆD‰DÝŒ[˜Ñ Ô ñ 	+ð 4:×3JÒ3JÑ3LÔ3LÑ0ÐÐ0Ø"&§+¢+­fÑ"5Ô"5ÐØ0°°°°B°Q°B°Ô7Ð:MÈaÈaÈaÐQRÐQSÐQSÈeÔ:TÑTˆNØ1°!°!°!°Q°R°R°%Ô8Ð;NÈqÈqÈqÐRTÐSTÐRTÈuÔ;UÑUˆOØÐ0Ñ0ˆKÝ”Jà"Ð%7Ñ7Ø%Ð(8Ñ8ñ9ð ñ	õ
 ”jðñ ô ˆEõ ”Jà"Ð%7Ñ7Ø%Ð(8Ñ8ñ9ð ñ	õ
 ”jðñ ô ˆEõ Ý”�BœKÔ(­"¬.¸%À¸ÈaÐ*PÑ*PÔ*Pñô ð ð —;’;�rœzÑ*Ô*ˆDå•3”;�rœ{Ô+¨d°1°1°1°b°q°b°5¬k¸DÀÀÀÀAÀBÀBÀ¼KÑ.GÈ1Ñ-LÑMÔM€GÝ•S”[¥¤Ô-°°Q°Q°Q¸¸¸°U´¸dÀ1À1À1ÀbÀqÀbÀ5¼kÑ0IÈVÑ/SÑTÔT€IÝÝŒ•B”KÔ Ý
Œ˜ )¨a¡-Ñ/°¸9Àq¹=Ñ1HÐIÐPQÐRÑRÔRñô ð r   éd   Úmax_iterationsc                 óH  — t          | ¦  «        dk    r| S t          t          j        t                   t          | d¬¦  «        ¦  «        }t          |¦  «        D �]¸}t          ||¦  «        }t          j	        |d¦  «         t          j
        |dk    ¦  «        r �nw|dk    }|dd…dd…f         |dd…dd…f         z   dz  }|dd…t          j        dd…f         |t          j        dd…dd…f         z
  }||dd…dd…t          j        f         z  }t          j        |d¬¦  «        }t          j                             |dd¬¦  «        }	t          j        ||	t          j        |¦  «        |	dk    ¬	¦  «        }
t          j        |d¬¦  «        }|dd…t          j        f         |
z  }|d
z  }d||dk    |dk     z  <   d||dk     |dk    z  <   |                     t$          ¦  «        }|dd…ddgfxx         |z  cc<   |dd…ddgfxx         |z  cc<   �Œºt          |d¬¦  «        S )aö  
    Spread out boxes that overlap with each other.

    Args:
        xyxy: Numpy array of shape (N, 4) where N is the number of boxes.
        max_iterations: Maximum number of iterations to run the algorithm for.

    Example:
        ```pycon
        >>> import numpy as np
        >>> from supervision.detection.utils.boxes import spread_out_boxes
        >>> xyxy = np.array([
        ...     [10, 10, 20, 20],
        ...     [12, 12, 22, 22]
        ... ])
        >>> spread_out = spread_out_boxes(xyxy=xyxy, max_iterations=10)
        >>> # The boxes should be moved apart
        >>> bool(spread_out[0, 0] < 10 and spread_out[0, 1] < 10)
        True
        >>> bool(spread_out[1, 0] > 12 and spread_out[1, 1] > 12)
        True

        ```
    r   r   )r   Nr   rE   T)rF   Úkeepdims)Úoutrs   é
   rZ   r   rD   )Úlenr   r*   r+   r   r5   Úranger   r   Úfill_diagonalr%   Únewaxisrc   ÚlinalgÚnormÚdivideÚ
zeros_liker'   r    )r	   r�   Úxyxy_paddedÚ_ÚiouÚoverlap_maskr‰   Údelta_centersÚ	delta_sumÚdelta_magnitudeÚdirection_vectorsÚforce_vectorss               r   Úspread_out_boxesr£   8  si  € õ8 ˆ4�y„y�A‚~€~Øˆå•s”{¥3Ô'­°4¸AÐ)>Ñ)>Ô)>Ñ?Ô?€KÝ�>Ñ"Ô"ð $0ñ $0ˆå˜K¨Ñ5Ô5ˆÝ
Ô˜˜aÑ Ô Ð ÝŒ6�#˜’(ÑÔð 	Ø‰Eà˜Q’wˆð ˜q˜q˜q " 1 "˜uÔ%¨°A°A°A°q°r°r°EÔ(:Ñ:¸aÑ?ˆð     ¥2¤:¨q¨q¨qÐ 0Ô1°G½B¼JÈÈÈÈ1È1È1Ð<LÔ4MÑMˆØ˜ a a a¨¨¨­B¬JÐ&6Ô7Ñ7ˆõ ”F˜=¨qÐ1Ñ1Ô1ˆ	Ýœ)Ÿ.š.¨¸ÀT˜.ÑJÔJˆÝœIØØÝ”˜iÑ(Ô(Ø! QÒ&ð	
ñ 
ô 
Ðõ œ˜s¨Ð+Ñ+Ô+ˆØ% a a a­¬ mÔ4Ð7HÑHˆà˜ÑˆØCDˆ�} qÒ(¨]¸QÒ->Ñ?Ñ@ØDFˆ�} qÒ(¨]¸RÒ-?Ñ@ÑAà%×,Ò,­SÑ1Ô1ˆà�A�A�A˜˜1�v�IÐÐÔ -Ñ/ÐÐÑØ�A�A�A˜˜1�v�IÐÐÔ -Ñ/ÐÐÑÑå�[ RÐ(Ñ(Ô(Ð(r   )N)r;   N)rŒ   ).Útypingr   r   Únumpyr   Únumpy.typingr*   Ú	deprecater   r   Ú'supervision.detection.utils.iou_and_nmsr   Úsupervision.geometry.corer   r+   r-   Útupler    r   r5   Ú
ARGS_REMAPÚfloatrB   rO   r   rS   rW   r.   ri   rl   ÚCENTERÚCENTER_LEFTÚCENTER_RIGHTÚ
TOP_CENTERÚBOTTOM_CENTERÚTOP_LEFTÚ	TOP_RIGHTÚBOTTOM_LEFTÚBOTTOM_RIGHTro   ÚdictÚ__annotations__rz   r   r‹   r£   rV   r   r   ú<module>r¸      s�  ðØ Ð Ð Ð Ð Ð Ð Ð Ð à Ð Ð Ð Ø Ð Ð Ð Ð Ð ðð ð ð ð ð ð ð ð
 BÐ AÐ AÐ AÐ AÐ AØ .Ð .Ð .Ð .Ð .Ð .ð'Ø
Œ+�b”iÔ
 ð'à˜˜c˜”?ð'ð 	„[�”Ôð'ð 'ð 'ð 'ðZ ðC0ð C0Ø
Œ+�b”iÔ
 ðC0àðC0ð 	ˆd‰
ðC0ð 	„[�”Ôð	C0ð C0ð C0ð C0ðL €ØÔ ØØØ# VÐ,ð	ñ ô ð #&Ø59ð	<ð <Ø
Œ+�b”iÔ
 ð<à˜˜c˜”?ð<ð  ð<ð ”[ ¤Ô+¨dÑ2ð	<ð
 	„[�”Ôð<ð <ð <ñô ð<ð~$YØ
Œ+�b”iÔ
 ð$Yà„[�”Ôð$Yð $Yð $Yð $YðN.Ø
Œ+�b”iÔ
 ð.Ø*-¬+°b´jÔ*Að.à„[�”Ôð.ð .ð .ð .ð>.ØŒk˜"œ)Ô$ð.Ø.1¬k¸"¼*Ô.Eð.à„[�”Ôð.ð .ð .ð .ðb+O˜cœk¨"¬)Ô4ð +O¸¼ÀRÄZÔ9Pð +Oð +Oð +Oð +Oð\%YØŒk˜"œ)Ô$ð%Yà„[�”Ôð%Yð %Yð %Yð %YðV „O�ZØÔ˜+ØÔ˜:ØÔ˜ØÔ˜JØÔ�|ØÔ˜ØÔ˜+ØÔ˜:ð
8€��h  e¨U lÔ 3Ð3Ô4ð 
ð 
ñ 
ðGLØŒk˜"œ)Ô$ðGLØ.6ðGLà„[�”ÔðGLð GLð GLð GLðTLØ
Œ+�b”iÔ
 ðLØ*/ðLà„[�”ÔðLð Lð Lð Lðb ðF)ð F)Ø
Œ+�b”iÔ
 ðF)àðF)ð 	„[�”ÔðF)ð F)ð F)ð F)ð F)ð F)r   