Skip to content

Commit da73830

Browse files
author
SentienceDev
committed
fix tests
1 parent fbdf7b0 commit da73830

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

sentience/canonicalization.py

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -75,49 +75,47 @@ def round_bbox(bbox: dict[str, float], precision: int = 2) -> dict[str, int]:
7575
}
7676

7777

78-
def bbox_equal(bbox1: dict[str, Any], bbox2: dict[str, Any], precision: int = 2) -> bool:
78+
def bbox_equal(bbox1: dict[str, Any], bbox2: dict[str, Any], threshold: float = 5.0) -> bool:
7979
"""
80-
Check if two bboxes are equal after rounding.
80+
Check if two bboxes are equal within a threshold.
8181
8282
Args:
8383
bbox1: First bounding box
8484
bbox2: Second bounding box
85-
precision: Grid size for rounding (default: 2)
85+
threshold: Maximum allowed difference in pixels (default: 5.0)
8686
8787
Returns:
88-
True if bboxes are equal after rounding
88+
True if all bbox properties differ by less than threshold
8989
9090
Examples:
9191
>>> bbox_equal({"x": 100, "y": 200, "width": 50, "height": 25},
92-
... {"x": 101, "y": 200, "width": 50, "height": 25})
93-
True
92+
... {"x": 102, "y": 200, "width": 50, "height": 25})
93+
True # 2px difference is below 5px threshold
9494
"""
95-
r1 = round_bbox(bbox1, precision)
96-
r2 = round_bbox(bbox2, precision)
9795
return (
98-
r1["x"] == r2["x"]
99-
and r1["y"] == r2["y"]
100-
and r1["width"] == r2["width"]
101-
and r1["height"] == r2["height"]
96+
abs(bbox1.get("x", 0) - bbox2.get("x", 0)) <= threshold
97+
and abs(bbox1.get("y", 0) - bbox2.get("y", 0)) <= threshold
98+
and abs(bbox1.get("width", 0) - bbox2.get("width", 0)) <= threshold
99+
and abs(bbox1.get("height", 0) - bbox2.get("height", 0)) <= threshold
102100
)
103101

104102

105-
def bbox_changed(bbox1: dict[str, Any], bbox2: dict[str, Any], precision: int = 2) -> bool:
103+
def bbox_changed(bbox1: dict[str, Any], bbox2: dict[str, Any], threshold: float = 5.0) -> bool:
106104
"""
107-
Check if two bboxes differ after rounding.
105+
Check if two bboxes differ beyond the threshold.
108106
109107
This is the inverse of bbox_equal, provided for semantic clarity
110108
in diff detection code.
111109
112110
Args:
113111
bbox1: First bounding box
114112
bbox2: Second bounding box
115-
precision: Grid size for rounding (default: 2)
113+
threshold: Maximum allowed difference in pixels (default: 5.0)
116114
117115
Returns:
118-
True if bboxes differ after rounding
116+
True if any bbox property differs by more than threshold
119117
"""
120-
return not bbox_equal(bbox1, bbox2, precision)
118+
return not bbox_equal(bbox1, bbox2, threshold)
121119

122120

123121
def canonicalize_element(elem: dict[str, Any]) -> dict[str, Any]:

0 commit comments

Comments
 (0)