def merge(self, other): """ Return merge of this and other box. Two boxes need not overlap. """ # min/max corners vmin = minimum(self._min, other._min) vmax = maximum(self._max, other._max) return Box(vmin, vmax)
def intersect(self, other): """Return intersection between this and other box, if overlaps.""" if self.overlaps(other): # min/max corners vmin = maximum(self._min, other._min) vmax = minimum(self._max, other._max) return Box(vmin, vmax) else: return None
def set_coords(self, v1, v2): """Reset the box coordinates.""" self._min = minimum(v1, v2) self._max = maximum(v1, v2) self._size = self._max - self._min