From a38ae3f840955f6409bc06af1bc4a064089a9145 Mon Sep 17 00:00:00 2001 From: sharingan000 Date: Tue, 2 Apr 2024 16:54:34 +1000 Subject: [PATCH] Change the method of finding polygon center and create test for new function --- test/geometry/test_utils.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 test/geometry/test_utils.py diff --git a/test/geometry/test_utils.py b/test/geometry/test_utils.py new file mode 100644 index 00000000..39c45216 --- /dev/null +++ b/test/geometry/test_utils.py @@ -0,0 +1,24 @@ +import pytest + +import numpy as np +from supervision.geometry.core import Point, Vector +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)), + ], +) +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