轻量化kd-tree搜索方法
npm install simple-kd-tree
const points = [
{ z: 1, y: 2, x: 110 },
{ z: 1, y: 2, x: 222 },
{ z: 1, y: 2, x: 333 },
];
function distance(a, b) {
var dx = a.x - b.x;
var dz = a.z - b.z;
return Math.sqrt(dx dx + dz dz);
}
const tree = new SimpleKDTree(points, distance, ["x", "z"]);
const searchTarget = {x:0,y:0,z:0}
const result = tree.nearest(searchTarget,300) // [[Node, 110.00454536063498],[Node, 222.00225224082752]]
``