function makeLocator(nodes) {
const deltas = nodes.map(getDelta);
deltas.map(checkDeltaMonotonic);
const coordinator = function (coords) {
if (coords.length !== nodes.length) {
throw "Error: coords length does not equal nodes length.";
}
const interval = coords.map((x, i) =>
Math.min(d3.bisect(nodes[i], x), nodes[i].length - 1)
);
if (!interval.every((x) => x > 0)) {
}
const dist = coords.map(
(x, i) => (x - nodes[i][interval[i] - 1]) / deltas[i][interval[i] - 1]
);
if (!dist.every((x) => x <= 1)) {
}
const locations = interval.map((x, i) => ({
interval: x,
weight: [1 - dist[i], dist[i]]
}));
return locations;
};
return coordinator;
}