Class segment
object --+
|
tuple --+
|
segment
The segment class defines objects that represent a range of values. A
segment has a start and an end, and is taken to represent the range of
values in the semi-open interval [start, end). Some limited arithmetic
operations are possible with segments, but because the set of (single)
segments is not closed under the sensible definitions of the standard
arithmetic operations, the behaviour of the arithmetic operators on
segments may not be as you would expect. For general arithmetic on
segments, use segmentlist objects. The methods for this class exist
mostly for purpose of simplifying the implementation of the segmentlist
class.
The segment class is a subclass of the tuple built-in class provided
by Python. This means segments are immutable --- you cannot modify a
segment object after creating it, to change the boundaries of a segment
you must create a new segment object with the desired boundaries. Like
tuples, segments can be used as dictionary keys, and like tuples the
comparison used to find a segment in the dictionary is done by value not
by ID. And, like tuples, a segment can be created from any sequence-like
object by passing it to the constructor (the sequence must have exactly
two elements in it).
Example:
>>> segment(0, 10) & segment(5, 15)
segment(5, 10)
>>> segment(0, 10) | segment(5, 15)
segment(0, 15)
>>> segment(0, 10) - segment(5, 15)
segment(0, 5)
>>> segment(0, 10) < segment(5, 15)
True
>>> segment(1, 2) in segment(0, 10)
True
>>> segment(1, 11) in segment(0, 10)
False
>>> segment(0, 1)
segment(0, 1)
>>> segment(1, 0)
segment(0, 1)
>>> bool(segment(0, 1))
True
>>> bool(segment(0, 0))
False
>>> segment("AAA Towing", "York University") & segment("Pool", "Zoo")
segment('Pool', 'York University')
>>> x = [0, 1]
>>> segment(x)
segment(0, 1)
>>> y = segment(0, 1)
>>> y == x
True
>>> y is x
False
>>> z = {x: ["/path/to/file1", "/path/to/file2"]}
>>> y in z
True
>>> z[y]
['/path/to/file1', '/path/to/file2']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
a new object with type S, a subtype of T
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
contract(...)
Return a new segment whose bounds are given by adding x to the
segment's lower bound and subtracting x from the segment's upper
bound. |
|
|
|
disjoint(...)
Returns >0 if self covers an interval above other's interval,
<0 if self covers an interval below other's, or 0 if the two
intervals are not disjoint (intersect or touch). |
|
|
|
intersects(...)
Return True if the intersection of self and other is not a null
segment. |
|
|
|
protract(...)
Return a new segment whose bounds are given by subtracting x from the
segment's lower bound and adding x to the segment's upper bound. |
|
|
|
shift(...)
Return a new segment whose bounds are given by adding x to the
segment's upper and lower bounds. |
|
|
Inherited from tuple :
__getattribute__ ,
__getitem__ ,
__getnewargs__ ,
__getslice__ ,
__iter__ ,
__len__ ,
__mul__ ,
__rmul__ ,
__sizeof__ ,
count ,
index
Inherited from object :
__delattr__ ,
__format__ ,
__init__ ,
__reduce__ ,
__reduce_ex__ ,
__setattr__ ,
__subclasshook__
|
Inherited from object :
__class__
|
__add__(x,
y)
(Addition operator)
|
|
x+y
- Overrides:
tuple.__add__
|
__contains__(x,
y)
(In operator)
|
|
y in x
- Overrides:
tuple.__contains__
|
__eq__(x,
y)
(Equality operator)
|
|
x==y
- Overrides:
tuple.__eq__
|
__ge__(x,
y)
(Greater-than-or-equals operator)
|
|
x>=y
- Overrides:
tuple.__ge__
|
__gt__(x,
y)
(Greater-than operator)
|
|
x>y
- Overrides:
tuple.__gt__
|
__hash__(x)
(Hashing function)
|
|
hash(x)
- Overrides:
object.__hash__
|
__le__(x,
y)
(Less-than-or-equals operator)
|
|
x<=y
- Overrides:
tuple.__le__
|
__lt__(x,
y)
(Less-than operator)
|
|
x<y
- Overrides:
tuple.__lt__
|
x!=y
- Overrides:
tuple.__ne__
|
- Returns: a new object with type S, a subtype of T
- Overrides:
object.__new__
|
__repr__(x)
(Representation operator)
|
|
repr(x)
- Overrides:
object.__repr__
|
__str__(x)
(Informal representation operator)
|
|
str(x)
- Overrides:
object.__str__
|
Returns >0 if self covers an interval above other's interval, <0
if self covers an interval below other's, or 0 if the two intervals are
not disjoint (intersect or touch). A return value of 0 indicates the two
segments would coalesce.
|