Advertisement
Guest User

Untitled

a guest
Dec 13th, 2013
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.04 KB | None | 0 0
  1. ## Add a new entry to the illumination settings, merging entries as
  2. # necessary.
  3. def onAdd(start, stop):
  4.     # Go through our list of sequences and see if we need to merge them
  5.     # together.
  6.     sequence.append([start, stop])
  7.     indexToDelete = len(sequence) - 1
  8.     didChange = True
  9.     while didChange:
  10.         print sequence, indexToDelete
  11.         didChange = False
  12.         for i, (altStart, altStop) in enumerate(sequence):
  13.             # Check for overlap.
  14.             if ((start < altStart and stop > altStart) or
  15.                     (stop > altStop and start < altStop)):
  16.                 # Merge the two entries.
  17.                 start = min(start, altStart)
  18.                 stop = max(stop, altStop)
  19.                 sequence[i] = [start, stop]
  20.                 didChange = True
  21.                 if indexToDelete is not None:
  22.                     # Destroy the old sequence as it's been merged with
  23.                     # this one.
  24.                     del sequence[indexToDelete]
  25.                 indexToDelete = i
  26.                 break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement