How to use the kdbush function in kdbush

To help you get started, we’ve selected a few kdbush examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jasonwebb / 2d-space-colonization-experiments / core / Network.js View on Github external
buildSpatialIndices() {
    this.nodesIndex = new KDBush(this.nodes, p => p.position.x, p => p.position.y);
  }
github flekschas / regl-scatterplot / src / index.js View on Github external
const setPoints = newPoints => {
    isInit = false;

    numPoints = newPoints.length;

    stateTex = createStateTexture(newPoints);
    normalPointsIndexBuffer({
      usage: 'static',
      type: 'float',
      data: createPointIndex(numPoints)
    });

    searchIndex = new KDBush(newPoints, p => p[0], p => p[1], 16);

    isInit = true;
  };
github sakitam-fdd / HMap / src / layer / GLLayer.js View on Github external
addFeatures (features) {
    this.features = this.features.concat(features);
    this.originData = kdbush(this.features, (p) => p.getGeometry().getCoordinates()[0], (p) => p.getGeometry().getCoordinates()[1]);
  }
github bcrumbs / booben / app / src / containers / Canvas / content / containers / CanvasContent.js View on Github external
async _getPossibleSnapPoints(x, y) {
    const snapPoints = await this._getAllSnapPoints();
    let possibleSnapPoints;

    if (snapPoints.length < 2) {
      possibleSnapPoints = snapPoints;
    } else {
      if (this._snapPointsIndex === null) {
        this._snapPointsIndex = kdbush(
          snapPoints,
          p => p.x,
          p => p.y,
          64,
          Int32Array,
        );
      }

      const pointsWithinSnapDistance = this._snapPointsIndex
        .within(x, y, SNAP_DISTANCE)
        .map(id => snapPoints[id]);

      if (pointsWithinSnapDistance.length > 0) {
        const closestPoint = _minBy(
          pointsWithinSnapDistance,
          point => distance(x, y, point.x, point.y),
github sakitam-fdd / HMap / src / layer / DozensLayer.js View on Github external
addFeatures (features) {
    this.features = this.features.concat(features);
    this.originData = kdbush(this.features, (p) => p.getGeometry().getCoordinates()[0], (p) => p.getGeometry().getCoordinates()[1]);
  }
github anvaka / playground / nb-layout / src / nbLayout.js View on Github external
function forceMove() {
    var before = getGraphBBox();
    const points = new KDBush(nodeArr, p => p.x, p => p.y);
    nodeArr.forEach((pos, idx) => {
      var sx = 0, sy = 0, count = 0;
      var neighbors = points.within(pos.x, pos.y, edgeLength/2);
      neighbors.forEach(otherIndex => {
        if (otherIndex === idx) return;

        var other = nodeArr[otherIndex];
        var dx = pos.x - other.x;
        var dy = pos.y - other.y;
        var l = Math.sqrt(dx * dx + dy * dy);
        if (l < 1e-10) l = 1;

        var tR = 1;
        pos.incX += pos.x + k4 * (edgeLength - l) * dx/l * tR;
        pos.incY += pos.y + k4 * (edgeLength - l) * dy/l * tR;
        pos.incLength += 1;

kdbush

A very fast static 2D index for points based on kd-tree.

ISC
Latest version published 1 year ago

Package Health Score

67 / 100
Full package analysis

Popular kdbush functions