| Home | Trees | Index | Help |
|---|
| Module interval :: Class Interval |
|
Represents a continuous range of values
An Interval is composed of the lower bound, a closed lower bound flag, an upper bound, and a closed upper bound flag. The attributes are called lower_bound, lower_closed, upper_bound, and upper_closed, respectively. For an infinite interval, the bound is set to inf or -inf. IntervalSets are composed of zero to many Intervals.| Method Summary | |
|---|---|
Initializes an interval | |
Returns the intersection of two intervals | |
Compares two intervals for ordering purposes | |
Returns True if obj lies wholly within the Interval. | |
Test if an interval is equivalent to the object | |
Returns a hashed value of the object | |
Tells whether the interval is empty | |
Returns an evaluable expression that can reproduce the object | |
Returns a string representation of the object | |
Tells whether an Interval is adjacent to the object without overlap | |
Returns an interval encompassing all values (Class method) | |
Returns an interval between two values (Class method) | |
Tells whether an interval lies before the object | |
Returns an point interval (Class method) | |
Returns interval of all values greater than the given value (Class method) | |
Returns interval of all values greater than or equal to the given value (Class method) | |
Combines two continous Intervals | |
Returns interval of all values less than the given value (Class method) | |
Returns an interval containing the given values and everything less (Class method) | |
Returns an empty interval (Class method) | |
Tells whether the given interval overlaps the object | |
| Instance Method Details |
|---|
__init__(self,
lower_bound=-Inf,
upper_bound=Inf,
**kwargs)
Initializes an interval
|
__and__(self,
other)
Returns the intersection of two intervals
|
__cmp__(self,
other)
Compares two intervals for ordering purposes
|
__contains__(self,
obj)
Returns True if obj lies wholly within the Interval.
|
__eq__(self,
other)
Test if an interval is equivalent to the object
|
__hash__(self)
|
__nonzero__(self)
Tells whether the interval is empty
|
__repr__(self)
Returns an evaluable expression that can reproduce the object
|
__str__(self)
|
adjacent_to(self, other)Tells whether an Interval is adjacent to the object without overlap Returns True if self is adjacent to other, meaning that if they were joined, there would be no discontinuity. They cannot overlap.>>> r1 = Interval.less_than(-100) >>> r2 = Interval.less_than_or_equal_to(-100) >>> r3 = Interval.less_than(100) >>> r4 = Interval.less_than_or_equal_to(100) >>> r5 = Interval.all() >>> r6 = Interval.between(-100, 100, False) >>> r7 = Interval(-100, 100, lower_closed=False) >>> r8 = Interval.greater_than(-100) >>> r9 = Interval.equal_to(-100) >>> r10 = Interval(-100, 100, upper_closed=False) >>> r11 = Interval.between(-100, 100) >>> r12 = Interval.greater_than_or_equal_to(-100) >>> r13 = Interval.greater_than(100) >>> r14 = Interval.equal_to(100) >>> r15 = Interval.greater_than_or_equal_to(100) >>> r1.adjacent_to(r6) False >>> r6.adjacent_to(r11) False >>> r7.adjacent_to(r9) True >>> r3.adjacent_to(r10) False >>> r5.adjacent_to(r14) False >>> r6.adjacent_to(r15) True >>> r1.adjacent_to(r8) False >>> r12.adjacent_to(r14) False >>> r6.adjacent_to(r13) False >>> r2.adjacent_to(r15) False >>> r1.adjacent_to(r4) False |
comes_before(self, other)Tells whether an interval lies before the object self comes before other when sorted if its lower bound is less than other's smallest value. If the smallest value is the same, then the Interval with the smallest upper bound comes first. Otherwise, they are equal.>>> Interval.equal_to(1).comes_before(Interval.equal_to(4)) True >>> Interval.less_than_or_equal_to(1).comes_before(Interval.equal_to(4)) True >>> Interval.less_than_or_equal_to(5).comes_before( ... Interval.less_than(5)) False >>> Interval.less_than(5).comes_before( ... Interval.less_than_or_equal_to(5)) True >>> Interval.all().comes_before(Interval.all()) False |
join(self, other)Combines two continous Intervals Combines two continuous Intervals into one Interval. If the two Intervals are disjoint, then an exception is raised.>>> r1 = Interval.less_than(-100) >>> r2 = Interval.less_than_or_equal_to(-100) >>> r3 = Interval.less_than(100) >>> r4 = Interval.less_than_or_equal_to(100) >>> r5 = Interval.all() >>> r6 = Interval.between(-100, 100, False) >>> r7 = Interval(-100, 100, lower_closed=False) >>> r8 = Interval.greater_than(-100) >>> r9 = Interval.equal_to(-100) >>> r10 = Interval(-100, 100, upper_closed=False) >>> r11 = Interval.between(-100, 100) >>> r12 = Interval.greater_than_or_equal_to(-100) >>> r13 = Interval.greater_than(100) >>> r14 = Interval.equal_to(100) >>> r15 = Interval.greater_than_or_equal_to(100) >>> print r13.join(r15) [100...) >>> print r7.join(r6) (-100..100] >>> print r11.join(r2) (...100] >>> print r4.join(r15) (...) >>> print r8.join(r8) (-100...) >>> print r3.join(r7) (...100] >>> print r5.join(r10) (...) >>> print r9.join(r1) (...-100] >>> print r12.join(r5) (...) >>> print r13.join(r1) Traceback (most recent call last): ... ArithmeticError: The Intervals are disjoint. >>> print r14.join(r2) Traceback (most recent call last): ... ArithmeticError: The Intervals are disjoint. |
overlaps(self, other)Tells whether the given interval overlaps the object Returns True if the one Interval overlaps another. If they are immediately adjacent, then this returns False. Use the adjacent_to function for testing for adjacent Intervals.>>> r1 = Interval.less_than(-100) >>> r2 = Interval.less_than_or_equal_to(-100) >>> r3 = Interval.less_than(100) >>> r4 = Interval.less_than_or_equal_to(100) >>> r5 = Interval.all() >>> r6 = Interval.between(-100, 100, False) >>> r7 = Interval(-100, 100, lower_closed=False) >>> r8 = Interval.greater_than(-100) >>> r9 = Interval.equal_to(-100) >>> r10 = Interval(-100, 100, upper_closed=False) >>> r11 = Interval.between(-100, 100) >>> r12 = Interval.greater_than_or_equal_to(-100) >>> r13 = Interval.greater_than(100) >>> r14 = Interval.equal_to(100) >>> r15 = Interval.greater_than_or_equal_to(100) >>> r8.overlaps(r9) False >>> r12.overlaps(r6) True >>> r7.overlaps(r8) True >>> r8.overlaps(r4) True >>> r14.overlaps(r11) True >>> r10.overlaps(r13) False >>> r5.overlaps(r1) True >>> r5.overlaps(r2) True >>> r15.overlaps(r6) False >>> r3.overlaps(r1) True |
| Class Method Details |
|---|
all(cls)Returns an interval encompassing all values>>> print Interval.all() (...) |
between(cls, a, b, closed=True)Returns an interval between two values Returns an interval between values a and b. If closed is True, then the endpoints are included. Otherwise, the endpoints are excluded.>>> print Interval.between(2, 4) [2..4] >>> print Interval.between(2, 4, False) (2..4) |
equal_to(cls, a)Returns an point interval Returns an interval containing only a.>>> print Interval.equal_to(32) 32 |
greater_than(cls, a)Returns interval of all values greater than the given value>>> print Interval.greater_than(32) (32...) |
greater_than_or_equal_to(cls, a)Returns interval of all values greater than or equal to the given value>>> print Interval.greater_than_or_equal_to(32) [32...) |
less_than(cls, a)Returns interval of all values less than the given value Returns an interval containing all values less than a. If closed is True, then all values less than or equal to a are returned.>>> print Interval.less_than(32) (...32) |
less_than_or_equal_to(cls, a)Returns an interval containing the given values and everything less>>> print Interval.less_than_or_equal_to(32) (...32] |
none(cls)Returns an empty interval>>> print Interval.none() <Empty> |
| Home | Trees | Index | Help |
|---|
| Generated by Epydoc 2.1 on Wed Nov 9 22:22:38 2005 | http://epydoc.sf.net |