1+ from typing import Literal
2+
13import numpy as np
4+ import pytest
25
36import imgviz
47
@@ -15,3 +18,31 @@ def test_text_in_rectangle() -> None:
1518 assert res .shape == img .shape
1619 assert res .dtype == np .uint8
1720 assert not np .array_equal (res , img )
21+
22+
23+ @pytest .mark .parametrize ("loc" , ["lt" , "lt+" , "lb" , "lb-" ])
24+ def test_text_in_rectangle_aabb_left_aligns_to_x1 (
25+ loc : Literal ["lt" , "lt+" , "lb" , "lb-" ],
26+ ) -> None :
27+ yx1 = (20 , 50 )
28+ yx2 = (80 , 150 )
29+
30+ aabb = imgviz .draw .text_in_rectangle_aabb (
31+ yx1 = yx1 , yx2 = yx2 , loc = loc , text = "Hi" , size = 10
32+ )
33+
34+ assert aabb .x1 == yx1 [1 ]
35+
36+
37+ @pytest .mark .parametrize ("loc" , ["rt" , "rt+" , "rb" , "rb-" ])
38+ def test_text_in_rectangle_aabb_right_aligns_to_x2 (
39+ loc : Literal ["rt" , "rt+" , "rb" , "rb-" ],
40+ ) -> None :
41+ yx1 = (20 , 50 )
42+ yx2 = (80 , 150 )
43+
44+ aabb = imgviz .draw .text_in_rectangle_aabb (
45+ yx1 = yx1 , yx2 = yx2 , loc = loc , text = "Hi" , size = 10
46+ )
47+
48+ assert aabb .x2 == yx2 [1 ] - 1 # text right edge sits one pixel inside x2
0 commit comments