How to use d3-delaunay - 7 common examples

To help you get started, we’ve selected a few d3-delaunay 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 openplannerteam / planner.js / src / analytics / footpaths / main.ts View on Github external
const stops = await stopsProvider.getAllStops();
        // using the WGS84 coordinates as-is
        function getX(p: ILocation) {
            return p.longitude;
        }

        function getY(p: ILocation) {
            return p.latitude;
        }

        function nextHalfedge(e: number) {
            // from https://mapbox.github.io/delaunator/
            return (e % 3 === 2) ? e - 2 : e + 1;
        }

        const delaunay = Delaunay.from(stops, getX, getY);
        let pairs = [];
        for (let e = 0; e < delaunay.triangles.length; e++) {
            if (e > delaunay.halfedges[e]) {
                // this will create a single triangulation
                // extra checks can be added here to calculate edges between different operators
                const p = stops[delaunay.triangles[e]];
                const q = stops[delaunay.triangles[nextHalfedge(e)]];

                pairs.push([p, q]); // in both directions of course
                pairs.push([q, p]);
                // todo, replace with yielding dicts instead of pairs
            }
        }

        // because of practical reasons, shortest distances require less data
        pairs = pairs.sort((a, b) => Geo.getDistanceBetweenLocations(a[0], a[1]) -
github Fil / d3-geo-voronoi / src / delaunay.js View on Github external
for (let i = 0, n = points.length; i < n; i++) {
    let m = points[i][0] ** 2 + points[i][1] ** 2;
    if (!isFinite(m) || m > 1e32) zeros.push(i);
    else if (m > max2) max2 = m;
  }

  const FAR = 1e6 * sqrt(max2);

  zeros.forEach(i => (points[i] = [FAR, 0]));

  // Add infinite horizon points
  points.push([0,FAR]);
  points.push([-FAR,0]);
  points.push([0,-FAR]);

  const delaunay = Delaunay.from(points);

  delaunay.projection = projection;

  // clean up the triangulation
  const {triangles, halfedges, inedges} = delaunay;
  const degenerate = [];
  for (let i = 0, l = halfedges.length; i < l; i++) {
    if (halfedges[i] < 0) {
      const j = i % 3 == 2 ? i - 2 : i + 1;
      const k = i % 3 == 0 ? i + 2 : i - 1;
      const a = halfedges[j];
      const b = halfedges[k];
      halfedges[a] = b;
      halfedges[b] = a;
      halfedges[j] = halfedges[k] = -1;
      triangles[i] = triangles[j] = triangles[k] = pivot;
github winkerVSbecks / sketchbook / 4d.js View on Github external
//   };
      // });

      // // Poisson Disc Sampler Polygons
      // const polygons = [
      //   ...poissonDiscSampler(0, 0, width, height, width * 0.2),
      // ].map(location => {
      //   return {
      //     polygon: randomPolygon(height * 0.125, height * 0.25, location),
      //     draw: getFill(),
      //   };
      // });

      // Poisson Disc Sampler Polygons + Voronoi
      const pts = [...poissonDiscSampler(0, 0, width, height, width * 0.1)];
      const delaunay = Delaunay.from(pts);
      const voronoi = delaunay.voronoi([0, 0, width, height]);
      const polygons = [...voronoi.cellPolygons()].map(polygon => ({
        polygon,
        draw: getFill(),
      }));

      polygons.forEach(({ polygon, draw }) => {
        draw(context, polygon, width * 0.01);
      });
    },
  };
github openplannerteam / planner.js / src / analytics / isochrones / visualize.ts View on Github external
function createTriangulation(nodes: ILocation[]): Delaunay {
    function getX(p: ILocation) {
        return p.longitude;
    }

    function getY(p: ILocation) {
        return p.latitude;
    }

    return Delaunay.from(nodes, getX, getY);
}
github anvaka / playground / top-history / animate / src / lib / createSceneRenderer.js View on Github external
function renderPosts(posts) {
    currentPosts = posts;
    let points = posts.map(post => {
      let pos = getMouseCoordinatesFromBandAndScore({
        band: post.band,
        score: post.score
      });
      return [pos.x, pos.y];
    });
    
    postIndex = Delaunay.from(points);
    redraw();
  }
github plouc / nivo / packages / voronoi / src / enhance.js View on Github external
({ scaledPoints, width, height }) => {
                const delaunay = Delaunay.from(scaledPoints.map(p => [p.x, p.y]))
                const voronoi = delaunay.voronoi([0, 0, width, height])

                return {
                    delaunay,
                    voronoi,
                }
            }
        ),
github openplannerteam / planner.js / src / planner / stops / ReachableStopsFinderDelaunay.ts View on Github external
this.triangles = this.stopsProvider.getAllStops().then((stops) => {
      this.trianglePoints = stops;

      function getX(p: ILocation) {
        return p.longitude;
      }

      function getY(p: ILocation) {
        return p.latitude;
      }

      return Delaunay.from(stops, getX, getY);
    });
  }

d3-delaunay

Compute the Voronoi diagram of a set of two-dimensional points.

ISC
Latest version published 1 year ago

Package Health Score

71 / 100
Full package analysis

Popular d3-delaunay functions