def test_eq(self): box2d_1 = Box2D(1, 2, 3, 4) box2d_2 = Box2D(1, 2, 3, 4) assert (box2d_1 == box2d_2) == True box2d_3 = Box2D(2, 3, 4, 5) assert (box2d_1 == box2d_3) == False
def test_and(self): box2d_1 = Box2D(1, 2, 3, 4) box2d_2 = Box2D(2, 3, 4, 5) vector2d = Vector2D(1, 2) user_sequence = UserSequence() user_sequence._data = ["a", "b", "c", "d"] assert (box2d_1 & box2d_2) == Box2D(2, 3, 3, 4) assert box2d_1.__and__([1, 2, 3]) == NotImplemented assert box2d_1.__and__(vector2d) == NotImplemented assert box2d_1.__and__(user_sequence) == NotImplemented
def __init__( self, xmin: float, ymin: float, xmax: float, ymax: float, *, category: Optional[str] = None, attributes: Optional[Dict[str, Any]] = None, instance: Optional[str] = None, ): Box2D.__init__(self, xmin, ymin, xmax, ymax) _LabelBase.__init__(self, category, attributes, instance)
def test_init(self): with pytest.raises(TypeError): Box2D() with pytest.raises(TypeError): Box2D(1) with pytest.raises(TypeError): Box2D(x=0) with pytest.raises(TypeError): Box2D() with pytest.raises(TypeError): Box2D([1, 2, 3, 4]) assert Box2D(*[1, 2, 3, 4]) == Box2D(1, 2, 3, 4) box2d = Box2D(1, 2, 3, 4) assert box2d.xmin == 1 assert box2d.ymin == 2 assert box2d.xmax == 3 assert box2d.ymax == 4 assert box2d.tl == Vector2D(1, 2) assert box2d.br == Vector2D(3, 4) assert box2d.width == 2 assert box2d.height == 2
def test_bounds(self): keypoints = Keypoints2D([[1, 2], [2, 3]]) assert keypoints.bounds() == Box2D(1, 2, 2, 3)
def test_bounds(self): assert _MULTI_POLYLINE.bounds() == Box2D(1, 1, 6, 5)
def test_bounds(self): assert _POLYLINE_1.bounds() == Box2D(1, 1, 5, 5) assert _POLYLINE_2.bounds() == Box2D(2, 1, 6, 5)
def test_area(self): box2d = Box2D(1, 2, 3, 4) assert box2d.area() == 4
def test_dumps(self): box2d = Box2D(1, 2, 3, 4) assert box2d.dumps() == _DATA_2D
def test_loads(self): box2d = Box2D.loads(_DATA_2D) assert box2d._data == (1, 2, 3, 4)
def test_from_xywh(self): assert Box2D.from_xywh(x=1, y=2, width=3, height=4) == Box2D(1, 2, 4, 6) assert Box2D.from_xywh(x=1, y=2, width=-1, height=2) == Box2D(0, 0, 0, 0)
def test_iou(self): box2d_1 = Box2D(1, 2, 3, 4) box2d_2 = Box2D(2, 2, 3, 4) assert Box2D.iou(box2d_1, box2d_2) == 0.5
def test_repr_head(self): box2d = Box2D(1, 2, 3, 4) assert box2d._repr_head() == "Box2D(1, 2, 3, 4)"
def test_len(self): box2d = Box2D(1, 2, 3, 4) assert len(box2d) == 4