Repository: roboflow/supervision
File: supervision/detection/utils.py (Python)

Code before:
        `n[[x1, y1], [x2, y2],[x3, y3], [x4, y4]]`
        offset (np.array): An array of shape `(2,)` containing offset values
        in format is `[dx, dy]`.

    Returns:
        npt.NDArray[np.float64]: Repositioned oriented bounding boxes.

    Examples:
        ```python
        import numpy as np
        import supervision as sv

        xyxyxyxy: np.array([[[10., 10.],
                            [20., 20.],
                            [30., 30.],
                            [40., 40.]]])
        offset = np.array([5, 10])

        sv.move_obb_boxes(xyss, offset=offset)
        #[[[15., 20.],
        #[25., 30.],
        #[35., 40.],
        #[45., 50.]]]
        ```
    """
    return [
        xys + np.hstack([offset, offset, offset, offset]).reshape(xys.shape)
        for xys in xyxyxyxy
    ]


def move_masks(
    masks: npt.NDArray[np.bool_],
    offset: npt.NDArray[np.int32],
    resolution_wh: Tuple[int, int],
) -> npt.NDArray[np.bool_]:
    """
    Offset the masks in an array by the specified (x, y) amount.

    Args:
        masks (npt.NDArray[np.bool_]): A 3D array of binary masks corresponding to the
            predictions. Shape: `(N, H, W)`, where N is the number of predictions, and
            H, W are the dimensions of each mask.
        offset (npt.NDArray[np.int32]): An array of shape `(2,)` containing non-negative
            int values `[dx, dy]`.
        resolution_wh (Tuple[int, int]): The width and height of the desired mask
            resolution.

    Returns:
        (npt.NDArray[np.bool_]) repositioned masks, optionally padded to the specified
            shape.

Review comment (suggestion):
I just wanted to let you know that you don't need to do it like this. Numpy supports broadcasting. Broadcasting allows NumPy to perform element-wise operations on arrays of different shapes by automatically expanding the smaller array to match the shape of the larger one.

You can simply `xyxyxyxy + offset`.

You can learn more from this colab: https://colab.research.google.com/drive/10FVlOMQaStrg7yUo-_x4l_NEBafHzUqI?usp=sharing

Code after:
    `[[x1, y1], [x2, y2], [x3, y3], [x3, y3]]`
    offset (np.array): An array of shape `(2,)` containing offset values in format
        is `[dx, dy]`.

    Returns:
    npt.NDArray[np.float64]: Repositioned bounding boxes.

    Examples:
    ```python
    import numpy as np
    import supervision as sv

    xyxyxyxy = np.array([
        [
            [20, 10],
            [10, 20],
            [20, 30],
            [30, 20]
        ],
        [
            [30 ,30],
            [20, 40],
            [30, 50],
            [40, 40]
        ]
    ])
    offset = np.array([5, 5])

    sv.move_oriented_boxes(xyxy=xyxy, offset=offset)
    # array([
    #     [
    #         [25, 15],
    #         [15, 25],
    #         [25, 35],
    #         [35, 25]
    #     ],
    #     [
    #         [35, 35],
    #         [25, 45],
    #         [35, 55],
    #         [45, 45]
    #     ]
    # ])
    ```
    """
    return xyxyxyxy + offset


def move_masks(
    masks: npt.NDArray[np.bool_],
    offset: npt.NDArray[np.int32],