Home | Trees | Indices | Help |
|
---|
|
object --+ | list --+ | segmentlist
The segmentlist class defines a list of segments, and is an extension of the built-in list class. This class provides addtional methods that assist in the manipulation of lists of segments. In particular, arithmetic operations such as union and intersection are provided. Unlike the segment class, the segmentlist class is closed under all supported arithmetic operations.
All standard Python sequence-like operations are supported, like slicing, iteration and so on, but the arithmetic and other methods in this class generally expect the segmentlist to be in what is refered to as a "coalesced" state --- consisting solely of disjoint segments listed in ascending order. Using the standard Python sequence-like operations, a segmentlist can be easily constructed that is not in this state; for example by simply appending a segment to the end of the list that overlaps some other segment already in the list. The class provides a coalesce() method that can be called to put it in the coalesced state. Following application of the coalesce method, all arithmetic operations will function reliably. All arithmetic methods themselves return coalesced results, so there is never a need to call the coalesce method when manipulating segmentlists exclusively via the arithmetic operators.
Example:
>>> x = segmentlist([segment(-10, 10)]) >>> x |= segmentlist([segment(20, 30)]) >>> x -= segmentlist([segment(-5, 5)]) >>> print(x) [segment(-10, -5), segment(5, 10), segment(20, 30)] >>> print(~x) [segment(-infinity, -10), segment(-5, 5), segment(10, 20), segment(30, infinity)]
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
Inherited from Inherited from |
|
|||
Inherited from |
|
|||
Inherited from |
|
x+y
|
y in x
|
x+=y
|
Sort the elements of a list into ascending order, and merge continuous segments into single segments. This operation is O(n log n). |
Execute the .contract() method on each segment in the list and coalesce the result. Segmentlist is modified in place. |
Return the segment whose end-points denote the maximum and minimum extent of the segmentlist. Does not require the segmentlist to be coalesced. |
Return the smallest i such that i is the index of an element that wholly contains item. Raises ValueError if no such element exists. Does not require the segmentlist to be coalesced. |
Returns True if the intersection of self and the segmentlist other is not the null set, otherwise returns False. The algorithm is O(n), but faster than explicit calculation of the intersection, i.e. by testing bool(self & other). Requires both lists to be coalesced. |
Returns True if the intersection of self and the segment other is not the null set, otherwise returns False. The algorithm is O(log n). Requires the list to be coalesced. |
Execute the .protract() method on each segment in the list and coalesce the result. Segmentlist is modified in place. |
Execute the .shift() method on each segment in the list. The algorithm is O(n) and does not require the list to be coalesced nor does it coalesce the list. Segmentlist is modified in place. |
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Tue Dec 12 00:34:18 2017 | http://epydoc.sourceforge.net |