예제 #1
0
 def findOverlap(self, a, b, dur):
     """Utility for returning the fraction of given duration that
     is spent in the overlap of the two given tuples.
     """
     a1, a2 = a
     b1, b2 = b
     # what's the overlap between them (like the Galactice Center)?
     if AnalogSet.overlaps(a, b):
         ints = AnalogSet.intersect(a, b)
         # if our range is entirely in overlap, avoid calculations
         if self.fltEqual(ints[0], a1) \
             and self.fltEqual(ints[1], a2):
             overlap = dur
             nonOverlap = 0
         else:    
            # otherwise we need to convert back to duration - 
            # one way to do this is via fractions
            frac = (ints[1] - ints[0]) / (a2 - a1)
            overlap = dur * frac
            nonOverlap = (1.0 - frac) * dur
     else:
         overlap = 0
         nonOverlap = dur
         
     return (overlap, nonOverlap)