buildResizeStepsPx static method

List<double> buildResizeStepsPx(
  1. double minPx,
  2. double maxPx,
  3. double stepPx
)

Builds the ascending candidate table [minPx … maxPx] by stepPx.

Implementation

static List<double> buildResizeStepsPx(
    double minPx, double maxPx, double stepPx) {
  var lo = minPx;
  var hi = maxPx;
  if (lo > hi) {
    final t = lo;
    lo = hi;
    hi = t;
  }
  if (stepPx <= 0) return [lo];
  final capacity =
      (((hi - lo) / stepPx).truncate() + 2).clamp(1, maxResizeSteps);
  final out = List<double>.filled(capacity, 0, growable: true);
  var count = 0;
  final epsilon = stepPx * 1e-4;
  var x = lo;
  while (x <= hi + epsilon && count < capacity) {
    out[count++] = x < hi ? x : hi;
    x += stepPx;
  }
  if (count > 0 && out[count - 1] < hi - epsilon && count < capacity) {
    out[count++] = hi;
  }
  return out.sublist(0, count);
}