extend Evoral::Range<T> to offer ::length() and ::squish()
The latter maps a T into a range, using loop semantics
This commit is contained in:
parent
c578fc724b
commit
e05cb11bb0
@ -138,6 +138,18 @@ struct /*LIBEVORAL_API*/ Range {
|
||||
T from; ///< start of the range
|
||||
T to; ///< end of the range (inclusive: to lies inside the range)
|
||||
bool empty() const { return from == to; }
|
||||
T length() const { return to - from + 1; }
|
||||
|
||||
/** for a T, return a mapping of it into the range (used for
|
||||
* looping). If the argument is earlier than or equal to the end of
|
||||
* this range, do nothing.
|
||||
*/
|
||||
T squish (T t) const {
|
||||
if (t > to) {
|
||||
t = (from + ((t - from) % length()));
|
||||
}
|
||||
return t;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
|
Loading…
Reference in New Issue
Block a user