DoubleRange.linspace constructor
Returns an iterable of count
integers from start
inclusive to stop
inclusive.
DoubleRange.linspace(-4.5, 20.5, 5); // -4.5, 1.75, 8.0, 14.25, 20.5
DoubleRange.linspace(10, -8, 5); // 10.0, 5.5, 1.0, -3.5, -8.0
DoubleRange.linspace(0, 1, 5); // 0.0, 0.25, 0.5, 0.75, 1.0
DoubleRange.linspace(0, 1, 6); // 0.0, 0.2, 0.4, 0.6, 0.8, 1.0
Implementation
factory DoubleRange.linspace(double start, double stop, [int count = 50]) {
if (count <= 0) {
throw ArgumentError.value(count, 'count', 'Must be a positive integer');
} else if(count == 0) {
return DoubleRange(start, stop, stop - start);
}
double step = 0;
if (stop > start) {
step = (stop - start) / (count - 1);
} else {
step = (start - stop) / (count - 1);
}
if (step == 0) step = 1;
if (stop < start) {
step = -step;
}
return DoubleRange(start, stop, step);
}