Skip to content

Commit 2f380ab

Browse files
maxmnemonicMaksym Lysak
andauthored
fix: DivisionByZero in intersection_over_self (#224)
Preventing intersection_over_self to trhow DivisionByZero when area of the element is zero Signed-off-by: Maksym Lysak <[email protected]> Co-authored-by: Maksym Lysak <[email protected]>
1 parent 57d26ee commit 2f380ab

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

docling_core/types/doc/base.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,10 @@ def intersection_over_self(
182182
) -> float:
183183
"""intersection_over_self."""
184184
intersection_area = self.intersection_area_with(other=other)
185-
return intersection_area / self.area()
185+
if self.area() > 0:
186+
return intersection_area / self.area()
187+
else:
188+
return 0.0
186189

187190
def to_bottom_left_origin(self, page_height: float) -> "BoundingBox":
188191
"""to_bottom_left_origin.

0 commit comments

Comments
 (0)