split_interval_at_values¶
- emlib.mathlib.split_interval_at_values(start, end, offsets)[source]¶
Split interval (start, end) at the given offsets
- Parameters:
start (
TypeVar
(T
, bound=Union
[Rational
,float
])) – start of the intervalend (
TypeVar
(T
, bound=Union
[Rational
,float
])) – end of the intervaloffsets (
Sequence
[TypeVar
(T
, bound=Union
[Rational
,float
])]) – offsets to split the interval at. Must be sorted
- Return type:
list
[tuple
[TypeVar
(T
, bound=Union
[Rational
,float
]),TypeVar
(T
, bound=Union
[Rational
,float
])]]- Returns:
a list of (start, end) segments where no segment extends over any of the given offsets
Example
>>> split_interval_at_values(1, 3, [1.5, 2]) [(1, 1.5), (1.5, 2), (2, 3)]
>>> split_interval_at_values(0.2, 4.3, list(range(10))) [(0.2, 1), (1, 2), (2, 3), (3, 4), (4, 4.3)]