function decimateIndex(index, [X, Y], Z, { pixelSize = 0.5, curve } = {}) {
if (typeof curve === "string" && curve.match(/^(bump|linear|monotone|step)/))
curve = false;
const J = [];
const pixel = [];
for (const I of Z ? d3.group(index, (i) => Z[i]).values() : [index]) {
let x0;
for (const i of I) {
const x = Math.floor(X[i] / pixelSize);
if (x !== x0) pick(), (x0 = x);
pixel.push(i);
}
pick();
}
return J;
function pick() {
const n = pixel.length;
if (!n) return;
let x1 = Infinity;
let y1 = Infinity;
let x2 = -Infinity;
let y2 = -Infinity;
let ix1, ix2, iy1, iy2;
for (let j = 0; j < n; ++j) {
const x = X[pixel[j]];
const y = Y[pixel[j]];
if (x < x1) (ix1 = j), (x1 = x);
if (x > x2) (ix2 = j), (x2 = x);
if (y < y1) (iy1 = j), (y1 = y);
if (y > y2) (iy2 = j), (y2 = y);
}
for (let j = 0; j < n; ++j) {
if (
j === 0 ||
j === n - 1 ||
j === ix1 ||
j === ix2 ||
j === iy1 ||
j === iy2 ||
(curve && (j === 1 || j === n - 2))
)
J.push(pixel[j]);
}
pixel.length = 0;
}
}