def test_overlapping_bbox_2(): b1 = BoundingBox(north=90, west=-200, south=-90, east=-130) b2 = BoundingBox(north=90, west=-180, south=-90, east=-90) b0 = b1.merge(b2) assert b0.width == 110, b0.width b3 = BoundingBox(north=90, west=-210, south=-90, east=-160) b0 = b0.merge(b3) assert b0.width == 120, b0.width # ---------------------- # --------------------- # --------------------- for i in range(-365, 365): b1 = BoundingBox(north=90, west=10 + i, south=-90, east=80 + i) b2 = BoundingBox(north=90, west=30 + i, south=-90, east=120 + i) b3 = BoundingBox(north=90, west=0 + i, south=-90, east=50 + i) b0 = BoundingBox.multi_merge([b1, b2, b3]) assert b0.width == 120, (b0.width, b0) # -------------------------------- # --------------------- # --------------------- for i in range(-365, 365): b1 = BoundingBox(north=90, west=-10 + i, south=-90, east=200 + i) b2 = BoundingBox(north=90, west=30 + i, south=-90, east=120 + i) b3 = BoundingBox(north=90, west=0 + i, south=-90, east=50 + i) b0 = BoundingBox.multi_merge([b1, b2, b3]) assert b0.width == 210, (b0.width, b0) # -------------------------------- # -------------------------- # --------------------- for i in range(-365, 365): b1 = BoundingBox(north=90, west=-10 + i, south=-90, east=200 + i) b2 = BoundingBox(north=90, west=30 + i, south=-90, east=300 + i) b3 = BoundingBox(north=90, west=0 + i, south=-90, east=50 + i) b0 = BoundingBox.multi_merge([b1, b2, b3]) assert b0.width == 310, (b0.width, b0)
def to_bounding_box(self): return BoundingBox.multi_merge([s.to_bounding_box() for s in self.get_fields()])
def test_overlapping_bbox_1(): for offset in range(-500, 500, 10): one = BoundingBox(north=90, west=offset + 10, east=offset + 20, south=-90) two = BoundingBox(north=90, west=offset + 40, east=offset + 60, south=-90) three = BoundingBox(north=90, west=offset + 15, east=offset + 35, south=-90) sets = [] sets.append([one, two, three]) sets.append([two, one, three]) sets.append([one, three, two]) sets.append([one, three, two, one, three]) sets.append([one, one, one, two, one, two, one, three]) for i, s in enumerate(sets): merged = BoundingBox.multi_merge(s) expected = BoundingBox(east=offset + 60, west=offset + 10, north=90, south=-90) assert merged.east == expected.east, ( i, merged.east, expected.east, merged, s, ) assert merged.west == expected.west, ( i, merged.west, expected.west, merged, s, ) four = BoundingBox(north=90, west=offset - 200, east=offset + 10, south=-90) sets = [] sets.append([one, two, three, four]) sets.append([two, one, four, three]) sets.append([one, three, four, two]) sets.append([one, three, two, four, one, three]) sets.append([one, one, one, two, four, one, two, one, three]) for i, s in enumerate(sets): merged = BoundingBox.multi_merge(s) expected = BoundingBox(east=offset + 60, west=offset - 200, north=90, south=-90) assert merged.east % 360 == expected.east % 360, ( i, offset, merged.east, expected.east, merged, s, ) assert merged.west % 360 == expected.west % 360, ( i, merged.west, expected.west, merged, s, ) assert merged.west < merged.east
def to_bounding_box(self): return BoundingBox.multi_merge([s.to_bounding_box() for s in self])