From dcad812c5c923252d2f8860dfebeb042e7fd3305 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 2 Apr 2024 07:15:13 +0000 Subject: [PATCH] =?UTF-8?q?fix(pre=5Fcommit):=20=F0=9F=8E=A8=20auto=20form?= =?UTF-8?q?at=20pre-commit=20hooks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- supervision/geometry/utils.py | 2 +- test/geometry/test_utils.py | 40 +++++++++++++++++++++-------------- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/supervision/geometry/utils.py b/supervision/geometry/utils.py index 3d5668fb..5748cfa0 100644 --- a/supervision/geometry/utils.py +++ b/supervision/geometry/utils.py @@ -9,7 +9,7 @@ def get_polygon_center(polygon: np.ndarray) -> Point: This function takes in a polygon as a 2-dimensional numpy ndarray and returns the center of the polygon as a Point object. - + The center is calculated as center of frame. polygon -> polygon, where p[i] = p[i + 1] + p[i] / 2, with mass = length of vector p[i + 1] - p[i] diff --git a/test/geometry/test_utils.py b/test/geometry/test_utils.py index 39c45216..5457463b 100644 --- a/test/geometry/test_utils.py +++ b/test/geometry/test_utils.py @@ -1,24 +1,32 @@ +import numpy as np import pytest -import numpy as np -from supervision.geometry.core import Point, Vector +from supervision.geometry.core import Point from supervision.geometry.utils import get_polygon_center @pytest.mark.parametrize( - "polygon, expected_result", - [ - (np.array([[0, 0], [0, 2], [2, 2], [2, 0]]), Point(x=1, y=1)), - (np.array([[0, 0], [3, 4], [6, 0]]), Point(x=3, y=1)), - (np.array([[0, 0], [0, 1], [0, 2], [0, 3], [0, 4], [5, 2]]), Point(x=2, y=2)), - (np.array([[0, 0], [0, 1], [0, 2], [0, 3], [0, 4], [4, 4], [4, 0]]), Point(x=2, y=2)), - (np.array([[0, 2], [2, 4], [4, 2], [2, 0]]), Point(x=2, y=2)), - (np.array([[0, 0], [0, 1], [0, 2], [0, 3], [0, 4], [0, 1000]]), Point(x=0, y=500)), - (np.array([[0, 0], [13, 200], [0, 150]]), Point(x=4, y=100)), - (np.array([[0, 0], [0, 1], [1, 1], [1, 2], [2, 2], [2, 3], [3, 3], [3, 0]]), Point(x=2, y=1)), - ], + "polygon, expected_result", + [ + (np.array([[0, 0], [0, 2], [2, 2], [2, 0]]), Point(x=1, y=1)), + (np.array([[0, 0], [3, 4], [6, 0]]), Point(x=3, y=1)), + (np.array([[0, 0], [0, 1], [0, 2], [0, 3], [0, 4], [5, 2]]), Point(x=2, y=2)), + ( + np.array([[0, 0], [0, 1], [0, 2], [0, 3], [0, 4], [4, 4], [4, 0]]), + Point(x=2, y=2), + ), + (np.array([[0, 2], [2, 4], [4, 2], [2, 0]]), Point(x=2, y=2)), + ( + np.array([[0, 0], [0, 1], [0, 2], [0, 3], [0, 4], [0, 1000]]), + Point(x=0, y=500), + ), + (np.array([[0, 0], [13, 200], [0, 150]]), Point(x=4, y=100)), + ( + np.array([[0, 0], [0, 1], [1, 1], [1, 2], [2, 2], [2, 3], [3, 3], [3, 0]]), + Point(x=2, y=1), + ), + ], ) def test_get_polygon_center(polygon: np.ndarray, expected_result: Point) -> None: - result = get_polygon_center(polygon) - assert result == expected_result - \ No newline at end of file + result = get_polygon_center(polygon) + assert result == expected_result