73 lines
2.2 KiB
Python
73 lines
2.2 KiB
Python
from contextlib import ExitStack as DoesNotRaise
|
|
from typing import Optional, Tuple
|
|
|
|
import pytest
|
|
|
|
from supervision import LineZone
|
|
from supervision.geometry.core import Point, Vector
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"vector, expected_result, exception",
|
|
[
|
|
(
|
|
Vector(start=Point(x=0.0, y=0.0), end=Point(x=0.0, y=0.0)),
|
|
None,
|
|
pytest.raises(ValueError),
|
|
),
|
|
(
|
|
Vector(start=Point(x=1.0, y=1.0), end=Point(x=1.0, y=1.0)),
|
|
None,
|
|
pytest.raises(ValueError),
|
|
),
|
|
(
|
|
Vector(start=Point(x=0.0, y=0.0), end=Point(x=0.0, y=4.0)),
|
|
(
|
|
Vector(start=Point(x=0.0, y=0.0), end=Point(x=-1.0, y=0.0)),
|
|
Vector(start=Point(x=0.0, y=4.0), end=Point(x=1.0, y=4.0)),
|
|
),
|
|
DoesNotRaise(),
|
|
),
|
|
(
|
|
Vector(Point(0.0, 0.0), Point(4.0, 0.0)),
|
|
(
|
|
Vector(start=Point(x=0.0, y=0.0), end=Point(x=0.0, y=1.0)),
|
|
Vector(start=Point(x=4.0, y=0.0), end=Point(x=4.0, y=-1.0)),
|
|
),
|
|
DoesNotRaise(),
|
|
),
|
|
(
|
|
Vector(Point(0.0, 0.0), Point(3.0, 4.0)),
|
|
(
|
|
Vector(start=Point(x=0, y=0), end=Point(x=-0.8, y=0.6)),
|
|
Vector(start=Point(x=3, y=4), end=Point(x=3.8, y=3.4)),
|
|
),
|
|
DoesNotRaise(),
|
|
),
|
|
(
|
|
Vector(Point(0.0, 0.0), Point(4.0, 3.0)),
|
|
(
|
|
Vector(start=Point(x=0, y=0), end=Point(x=-0.6, y=0.8)),
|
|
Vector(start=Point(x=4, y=3), end=Point(x=4.6, y=2.2)),
|
|
),
|
|
DoesNotRaise(),
|
|
),
|
|
(
|
|
Vector(Point(0.0, 0.0), Point(3.0, -4.0)),
|
|
(
|
|
Vector(start=Point(x=0, y=0), end=Point(x=0.8, y=0.6)),
|
|
Vector(start=Point(x=3, y=-4), end=Point(x=2.2, y=-4.6)),
|
|
),
|
|
DoesNotRaise(),
|
|
),
|
|
],
|
|
)
|
|
def test_calculate_region_of_interest_limits(
|
|
vector: Vector,
|
|
expected_result: Optional[Tuple[Vector, Vector]],
|
|
exception: Exception,
|
|
) -> None:
|
|
with exception:
|
|
result = LineZone.calculate_region_of_interest_limits(vector=vector)
|
|
assert result == expected_result
|