Ejemplo n.º 1
0
    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
Ejemplo n.º 2
0
 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
Ejemplo n.º 3
0
 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)
Ejemplo n.º 4
0
    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
Ejemplo n.º 5
0
 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)
Ejemplo n.º 8
0
 def test_area(self):
     box2d = Box2D(1, 2, 3, 4)
     assert box2d.area() == 4
Ejemplo n.º 9
0
 def test_dumps(self):
     box2d = Box2D(1, 2, 3, 4)
     assert box2d.dumps() == _DATA_2D
Ejemplo n.º 10
0
 def test_loads(self):
     box2d = Box2D.loads(_DATA_2D)
     assert box2d._data == (1, 2, 3, 4)
Ejemplo n.º 11
0
 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)
Ejemplo n.º 12
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
Ejemplo n.º 13
0
 def test_repr_head(self):
     box2d = Box2D(1, 2, 3, 4)
     assert box2d._repr_head() == "Box2D(1, 2, 3, 4)"
Ejemplo n.º 14
0
 def test_len(self):
     box2d = Box2D(1, 2, 3, 4)
     assert len(box2d) == 4