function dotbin(x, step, smooth = false) {
x = x.slice();
const n = x.length;
let left = 0;
for (let j = 1; j < n; ++j) {
if (x[j] >= x[left] + step) {
const xmid = Math.min((x[left] + x[j-1]) / 2, x[j] - step);
x.fill(xmid, left, j);
left = j;
}
}
x.fill((x[left] + x[n-1]) / 2, left, n);
if (smooth) {
const thresh = step + step / 4;
let a = 0, b = 1;
while (x[a] === x[b]) ++b;
while (b < n) {
let c = b + 1;
while (x[b] === x[c]) ++c;
if (x[b] - x[a] < thresh) {
const mid = (a + c) >> 1;
x.fill(x[b], mid, b);
x.fill(x[a], b, mid);
}
a = b, b = c;
}
}
return x;
}