DurationRange.linspace constructor
Returns an iterable of count
integers from start
inclusive to stop
inclusive.
print(IntRange.linspace(1, 10, 5)); => (1, 3, 5, 7, 9)
Implementation
factory DurationRange.linspace(Duration start, Duration stop, int count) {
if (count <= 0) {
throw ArgumentError.value(count, 'count', 'Must be a positive integer');
} else if (count == 1) {
return DurationRange(start, start, stop - start);
}
Duration step;
if (stop > start) {
step = Duration(
microseconds: ((stop - start).inMicroseconds) ~/ (count - 1));
} else {
step = Duration(
microseconds: ((start - stop).inMicroseconds) ~/ (count - 1));
}
if (step == Duration()) step = Duration(microseconds: 1);
if (stop < start) {
step = -step;
}
return DurationRange(start, stop, step);
}