Repository: lapix-ufsc/lapixdl

Issue:
Division by zero at calculate_bbox_iou
I can't reproduce the error with tests, but, some moments at https://github.com/lapix-ufsc/lapixdl/blob/ee3faf20b2beab7bbb794328f724b7b8044ac1b1/lapixdl/evaluation/evaluate.py#L211

The union it's equals zero and raise the error. To solve just need:
```python
if union_area == 0:
    return 0
```

I don't PR this because I can't reproduce this when i try 

Discussion:

Patch:
diff --git a/lapixdl/formats/annotation.py b/lapixdl/formats/annotation.py
index 919f70a..a0e2eb1 100644
--- a/lapixdl/formats/annotation.py
+++ b/lapixdl/formats/annotation.py
@@ -26,6 +26,16 @@ class BBox:
     cls: int
     score: float | None = None
 
+    def __post_init__(self):
+        if self.upper_left_x < 0 or self.upper_left_y < 0:
+            raise ValueError(f'The upper left (x, y) should be positive values. Got ({self.upper_left_x}, {self.upper_left_y})')
+
+        if self.width <= 0:
+            raise ValueError(f'The width should be bigger than zero. Got {self.width}')
+
+        if self.height <= 0:
+            raise ValueError(f'The height should be bigger than zero. Got {self.height}')
+
     @property
     def upper_left_point(self) -> tuple[int, int]:
         """Tuple[int, int]: (X,Y) of the upper left point of the Bounding Box."""


Test patch:
diff --git a/tests/formats/annotation_test.py b/tests/formats/annotation_test.py
index aa25429..202ba3a 100644
--- a/tests/formats/annotation_test.py
+++ b/tests/formats/annotation_test.py
@@ -28,6 +28,20 @@ def test_bbox():
     assert bbox.slice_y == slice(0, 14)
 
 
+def test_invalid_bbox():
+    with pytest.raises(ValueError):
+        BBox(0, -1, 1, 1, 0)
+
+    with pytest.raises(ValueError):
+        BBox(-1, 0, 1, 1, 0)
+
+    with pytest.raises(ValueError):
+        BBox(0, 0, 0, 1, 0)
+
+    with pytest.raises(ValueError):
+        BBox(0, 0, 1, 0, 0)
+
+
 def test_bbox_intersection_and_union_area_with():
     bbox_A = BBox(0, 0, 10, 15, 0)
     bbox_B = BBox(5, 5, 20, 25, 0)