2929themselves.
3030"""
3131
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+
3236from __future__ import (absolute_import , division , print_function ,
3337 unicode_literals )
3438
@@ -716,10 +720,10 @@ def union(bboxes):
716720 """
717721 if not len (bboxes ):
718722 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 ] )
723727 return Bbox ([[x0 , y0 ], [x1 , y1 ]])
724728
725729 @staticmethod
@@ -728,10 +732,10 @@ def intersection(bbox1, bbox2):
728732 Return the intersection of the two bboxes or None
729733 if they do not intersect.
730734 """
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 )
735739 return Bbox ([[x0 , y0 ], [x1 , y1 ]]) if x0 <= x1 and y0 <= y1 else None
736740
737741
0 commit comments