IntersectionBox now uses a list of selections rather than just two

This commit is contained in:
David Vierra 2016-01-31 23:10:07 -10:00
parent 483ab6ca05
commit ee16ede402

View File

@ -224,7 +224,7 @@ class UnionBox(CombinationBox):
def contains_coords(self, x, y, z): def contains_coords(self, x, y, z):
contains = [s.contains_coords(x, y, z) for s in self.selections] contains = [s.contains_coords(x, y, z) for s in self.selections]
return reduce(self.oper, contains, False) return reduce(self.oper, contains)
def box_mask(self, box): def box_mask(self, box):
masks = [s.box_mask(box) for s in self.selections] masks = [s.box_mask(box) for s in self.selections]
@ -246,27 +246,31 @@ class IntersectionBox(CombinationBox):
boundsmaxoper = min boundsmaxoper = min
def contains_coords(self, x, y, z): def contains_coords(self, x, y, z):
left = self.left.contains_coords(x, y, z) contains = [s.contains_coords(x, y, z) for s in self.selections]
if not left: return reduce(self.oper, contains)
return False
right = self.right.contains_coords(x, y, z)
return self.oper(left, right)
def box_mask(self, box): def box_mask(self, box):
left = self.left.box_mask(box) masks = [s.box_mask(box) for s in self.selections]
if left is None: if None in masks:
return None return None
right = self.right.box_mask(box)
if right is None: m = masks.pop()
return None
return self.oper(left, right) while len(masks):
numpy.logical_and(m, masks.pop(), m)
return m
class DifferenceBox(CombinationBox): class DifferenceBox(CombinationBox):
oper = lambda a, b: a & (~b) def oper(self, a, b):
boundsminoper = lambda a, b: a return a & (~b)
boundsmaxoper = lambda a, b: a
def boundsmaxoper(self, a, b):
return a
def boundsmaxoper(self, a, b):
return a
def contains_coords(self, x, y, z): def contains_coords(self, x, y, z):
left = self.left.contains_coords(x, y, z) left = self.left.contains_coords(x, y, z)