Welcome | Get started | Dive | Contribute | Topics | Reference | Changes | More
lino.utils.ranges¶
The lino.utils.ranges
module contains utility methods for
working with “ranges”.
A range is basically a tuple of two values a and b, called also limits, who indicate the start and the end of the range.
An open range is a range that has at least one limit set to None.
Functions
|
Test whether value is within the range (highest, lowest). |
|
Test whether range a encompasses (is wider than) range b. |
|
Return True if the passed tuple (a,b) is a valid range (that is, a may not be greater than b). |
|
Test whether two value ranges overlap. |
|
Same as |
- lino.utils.ranges.constrain(value, lowest, highest)¶
Test whether value is within the range (highest, lowest). Return value if it is inside the range, otherwise return highest if the value is above the range or lowest it the value is below the range.
Examples in Lino utilities.
- lino.utils.ranges.encompass(a, b)¶
Test whether range a encompasses (is wider than) range b.
Examples in Lino utilities.
- lino.utils.ranges.isrange(a, b)¶
Return True if the passed tuple (a,b) is a valid range (that is, a may not be greater than b).
- lino.utils.ranges.overlap(a1, a2, b1, b2)¶
Test whether two value ranges overlap.
This function is typically used with date values, but it also works with integers or other comparable values. The following examples use integer values to be more readable.
Unlike the test presented in Determing whether two ranges overlap, this works also with “open” ranges (the open end being indicated by a None value).
Types of constellations:
- o---o o---o - o---o o---> - <---o o---o - <---o o---> - o-------------> o---o - o---o o---o - o---o o---> - <---------o o---o
NB: Ranges that “only touch” each other are not considered overlapping.
Examples in Lino utilities.