Change the method of finding polygon center and create test for new function

This commit is contained in:
sharingan000 2024-04-02 16:54:34 +10:00
parent 175dd7d0f5
commit a38ae3f840
1 changed files with 24 additions and 0 deletions

View File

@ -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