29
29
themselves.
30
30
"""
31
31
32
+ # Note: There are a number of places in the code where we use `np.min` or
33
+ # `np.minimum` instead of the builtin `min`, and likewise for `max`. This is
34
+ # done so that `nan`s are propagated, instead of being silently dropped.
35
+
32
36
from __future__ import (absolute_import , division , print_function ,
33
37
unicode_literals )
34
38
@@ -716,10 +720,10 @@ def union(bboxes):
716
720
"""
717
721
if not len (bboxes ):
718
722
raise ValueError ("'bboxes' cannot be empty" )
719
- x0 = min (bbox .xmin for bbox in bboxes )
720
- x1 = max (bbox .xmax for bbox in bboxes )
721
- y0 = min (bbox .ymin for bbox in bboxes )
722
- y1 = max (bbox .ymax for bbox in bboxes )
723
+ x0 = np . min ([ bbox .xmin for bbox in bboxes ] )
724
+ x1 = np . max ([ bbox .xmax for bbox in bboxes ] )
725
+ y0 = np . min ([ bbox .ymin for bbox in bboxes ] )
726
+ y1 = np . max ([ bbox .ymax for bbox in bboxes ] )
723
727
return Bbox ([[x0 , y0 ], [x1 , y1 ]])
724
728
725
729
@staticmethod
@@ -728,10 +732,10 @@ def intersection(bbox1, bbox2):
728
732
Return the intersection of the two bboxes or None
729
733
if they do not intersect.
730
734
"""
731
- x0 = max (bbox1 .xmin , bbox2 .xmin )
732
- x1 = min (bbox1 .xmax , bbox2 .xmax )
733
- y0 = max (bbox1 .ymin , bbox2 .ymin )
734
- y1 = min (bbox1 .ymax , bbox2 .ymax )
735
+ x0 = np . maximum (bbox1 .xmin , bbox2 .xmin )
736
+ x1 = np . minimum (bbox1 .xmax , bbox2 .xmax )
737
+ y0 = np . maximum (bbox1 .ymin , bbox2 .ymin )
738
+ y1 = np . minimum (bbox1 .ymax , bbox2 .ymax )
735
739
return Bbox ([[x0 , y0 ], [x1 , y1 ]]) if x0 <= x1 and y0 <= y1 else None
736
740
737
741
0 commit comments