How to use the kdbush.default 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 mattdesl / canvas-sketch / examples / canvas-kdbush.js View on Github external
function makeShapes (props) {
    Random.setSeed(config.seed);
    const count = config.count;
    points = Array.from(new Array(count)).map(() => {
      const center = [ width / 2, height / 2 ];
      const radius = width * config.radius;
      return vec2.add([], center, Random.insideCircle(radius));
    });

    const index = kdbush(points);

    lines.length = 0;
    edges.length = 0;
    const ignorePoints = [];
    points.forEach(point => {
      // skip some targets entirely
      if (Random.chance(config.skipChance)) return;

      const stepCount = config.stepCount;
      let curPoint = point;
      let steps = [ curPoint ];
      for (let i = 0; i < stepCount; i++) {
        const previous = steps.length > 1 ? steps[i - 1] : null;
        const next = walk(index, curPoint, previous, ignorePoints);
        if (!next) break;
        curPoint = next;
github mattdesl / canvas-sketch / examples / experimental / canvas-constellations.js View on Github external
function generate () {
    Random.setSeed(config.seed);
    stars = Array.from(new Array(config.starCount)).map(() => {
      return {
        position: vec2.add([], Random.insideCircle(config.mapSize), [ width / 2, height / 2 ]),
        walked: false,
        radius: Math.abs(Random.gaussian(config.starSizeMean, config.starSizeDeviation))
      };
    });

    // spatial index of all stars
    index = kdbush(stars.map(p => p.position));

    const maxConstellations = Math.floor(stars.length * config.nConstellations);
    const targets = Random.shuffle(stars).slice(0, maxConstellations);

    // for each point, walk to others around it
    constellations = targets.map(initialStar => {
      const stepCount = config.stepCount;
      let maxSteps = stepCount + Math.trunc(Random.gaussian(0, 3));

      let currentStar = initialStar;
      const steps = [ currentStar ];

      const minDegree = 0;
      const maxDegree = 40;
      const minSearchDist = config.minSearchDist;
      const constellationSearchRadius = Math.max(0, config.searchRadius + Random.gaussian(0, 0.1));

kdbush

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

ISC
Latest version published 2 years ago

Package Health Score

73 / 100
Full package analysis

Popular kdbush functions