def test_minus_self(self): is1 = IntervalSet([ Interval(Bounds3D(2, 2.5)), Interval(Bounds3D(2, 2.7)), Interval(Bounds3D(2.9, 3.5)), Interval(Bounds3D(3.5, 3.6)), Interval(Bounds3D(5, 7)), Interval(Bounds3D(9, 12)), ]) is1 = is1.minus(is1) self.assertIntervalSetEq(is1, IntervalSet([]), eq)
def test_minus_with_single_frame(self): is1 = IntervalSet([ Interval(Bounds3D(1, 1)), Interval(Bounds3D(3, 3)), Interval(Bounds3D(4, 4)), Interval(Bounds3D(7, 7)), Interval(Bounds3D(10, 10)), ]) is2 = IntervalSet([ Interval(Bounds3D(1, 3)), Interval(Bounds3D(5, 8)), Interval(Bounds3D(9, 9)), ]) is3 = is1.minus(is2) target = IntervalSet([ Interval(Bounds3D(4, 4)), Interval(Bounds3D(10, 10)), ]) self.assertIntervalSetEq(is3, target) is4 = is2.minus(is1) self.assertIntervalSetEq(is4, is2)
def test_minus_everything(self): is1 = IntervalSet( [Interval(Bounds3D(1, 10)), Interval(Bounds3D(3, 15))]) is2 = IntervalSet([ Interval(Bounds3D(2, 2.5)), Interval(Bounds3D(2, 2.7)), Interval(Bounds3D(2.9, 3.5)), Interval(Bounds3D(3.5, 3.6)), Interval(Bounds3D(5, 7)), Interval(Bounds3D(9, 12)), ]) is3 = is2.minus(is1) self.assertIntervalSetEq(is3, IntervalSet([]), eq)
def test_minus_against_nothing(self): is1 = IntervalSet([ Interval(Bounds3D(1, 10, 0, 0.5, 0.2, 0.8), 1), Interval(Bounds3D(3, 15, 0, 1, 0, 1), 2) ]) is2 = IntervalSet([ Interval(Bounds3D(20, 20.5)), Interval(Bounds3D(20, 20.7)), Interval(Bounds3D(20.9, 23.5)), Interval(Bounds3D(23.5, 23.6)), Interval(Bounds3D(25, 27)), Interval(Bounds3D(29, 32)), ]) is3 = is1.minus(is2) self.assertIntervalSetEq(is3, is1, eq)
def test_minus_predicate(self): is1 = IntervalSet([ Interval(Bounds3D(1, 10, 0, 0.5, 0.2, 0.8), 1), Interval(Bounds3D(3, 15, 0, 1, 0, 1), 2) ]) is2 = IntervalSet([ Interval(Bounds3D(2, 2.5), 1), Interval(Bounds3D(2, 2.7), 1), Interval(Bounds3D(2.9, 3.5), 1), Interval(Bounds3D(3.5, 3.6), 1), Interval(Bounds3D(5, 7), 2), Interval(Bounds3D(9, 12), 2), ]) is3 = is1.minus(is2, predicate=payload_satisfies(lambda p1, p2: p1 == p2)) target = IntervalSet([ Interval(Bounds3D(1, 2, 0, 0.5, 0.2, 0.8), 1), Interval(Bounds3D(2.7, 2.9, 0, 0.5, 0.2, 0.8), 1), Interval(Bounds3D(3.6, 10, 0, 0.5, 0.2, 0.8), 1), Interval(Bounds3D(3, 5), payload=2), Interval(Bounds3D(7, 9), payload=2), Interval(Bounds3D(12, 15), payload=2), ]) self.assertIntervalSetEq(is3, target, eq)
def test_minus(self): is1 = IntervalSet([ Interval(Bounds3D(1, 10, 0, 0.5, 0.2, 0.8), 1), Interval(Bounds3D(3, 15, 0, 1, 0, 1), 2) ]) is2 = IntervalSet([ Interval(Bounds3D(2, 2.5)), Interval(Bounds3D(2, 2.7)), Interval(Bounds3D(2.9, 3.5)), Interval(Bounds3D(3.5, 3.6)), Interval(Bounds3D(5, 7)), Interval(Bounds3D(9, 12)), ]) is3 = is1.minus(is2) target = IntervalSet([ Interval(Bounds3D(1, 2, 0, 0.5, 0.2, 0.8), 1), Interval(Bounds3D(2.7, 2.9, 0, 0.5, 0.2, 0.8), 1), Interval(Bounds3D(3.6, 5, 0, 0.5, 0.2, 0.8), 1), Interval(Bounds3D(7, 9, 0, 0.5, 0.2, 0.8), 1), Interval(Bounds3D(3.6, 5), payload=2), Interval(Bounds3D(7, 9), payload=2), Interval(Bounds3D(12, 15), payload=2), ]) self.assertIntervalSetEq(is3, target, eq)
def main(): ''' Examples of minus (anti-semi-join). The first example subtracts out all the parts of the Intervals in the left set that overlap with any part of an interval in the right set. The second example uses a predicate to only subtract Intervals with the same payload. ''' is1 = IntervalSet([ Interval(Bounds3D(1, 10,0,0.5,0.2,0.8),1), Interval(Bounds3D(3, 15,0,1,0,1),2) ]) is2 = IntervalSet([ Interval(Bounds3D(2,2.5),1), Interval(Bounds3D(2,2.7),1), Interval(Bounds3D(2.9,3.5),1), Interval(Bounds3D(3.5,3.6),1), Interval(Bounds3D(5,7),2), Interval(Bounds3D(9,12),2), ]) is3 = is1.minus(is2) # is3 is equal to target target = IntervalSet([ Interval(Bounds3D(1,2,0,0.5,0.2,0.8),1), Interval(Bounds3D(2.7, 2.9, 0,0.5,0.2,0.8),1), Interval(Bounds3D(3.6,5,0,0.5,0.2,0.8),1), Interval(Bounds3D(7,9,0,0.5,0.2,0.8),1), Interval(Bounds3D(3.6,5), payload=2), Interval(Bounds3D(7,9), payload=2), Interval(Bounds3D(12,15), payload=2), ]) is4 = is1.minus(is2, predicate=payload_satisfies( lambda p1, p2: p1 == p2 )) # is4 is equal to target2 target2 = IntervalSet([ Interval(Bounds3D(1,2,0,0.5,0.2,0.8),1), Interval(Bounds3D(2.7, 2.9, 0,0.5,0.2,0.8),1), Interval(Bounds3D(3.6,10,0,0.5,0.2,0.8),1), Interval(Bounds3D(3,5), payload=2), Interval(Bounds3D(7,9), payload=2), Interval(Bounds3D(12,15), payload=2), ]) print('is1:') print(is1) print('is2:') print(is2) print() print('is1 minus is2:') print(is3) print() print('is1 minus is2 filtering on the payload:') print(is4)