Created
August 2, 2024 16:28
-
-
Save nkint/a1ecbd65084bf16e691d3e219466a3a6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { KdTreeSet } from "@thi.ng/geom-accel"; | |
import { samplePoisson } from "@thi.ng/poisson"; | |
import { randMinMax2 } from "@thi.ng/vectors"; | |
import PoissonDiskSampling from "poisson-disk-sampling"; | |
import FastPoissonDiskSampling from "fast-2d-poisson-disk-sampling"; | |
import { DVMesh } from "@thi.ng/geom-voronoi"; | |
import Delaunator from "delaunator"; | |
const spacing = 1.5; | |
console.time('thi.ng/poisson'); | |
const index = new KdTreeSet(2); | |
const pts1 = samplePoisson({ | |
index, | |
points: () => randMinMax2(null, [0, 0], [1000, 1000]), | |
density: spacing, | |
iter: 5, | |
max: 500000, | |
quality: 500, | |
}); | |
console.timeEnd('thi.ng/poisson'); | |
console.time('poisson-disk-sampling'); | |
var p = new PoissonDiskSampling({ | |
shape: [1000, 1000], | |
minDistance: spacing, // try to make the two libraries produce a similar number of outputs | |
maxDistance: 1.5 * spacing, | |
tries: 5 | |
}); | |
var pts2 = p.fill(); | |
console.timeEnd('poisson-disk-sampling'); | |
console.time('fast-2d-poisson-disk-sampling'); | |
var p = new FastPoissonDiskSampling({ | |
shape: [1000, 1000], | |
radius: spacing * 1.1, // try to make the two libraries produce a similar number of outputs | |
tries: 5 | |
}); | |
var pts3 = p.fill(); | |
console.timeEnd('fast-2d-poisson-disk-sampling'); | |
console.time('thi.ng/geom-voronoi'); | |
const mesh1 = new DVMesh(pts1); | |
mesh1.delaunay(); | |
console.timeEnd('thi.ng/geom-voronoi'); | |
console.time('delaunator'); | |
const mesh2 = Delaunator.from(pts2); | |
console.timeEnd('delaunator'); | |
console.log(pts1.length, 'points from thi.ng'); | |
console.log(pts2.length, 'points from poisson-disk-sampling'); | |
console.log(pts3.length, 'points from fast-2d-poisson-disk-sampling'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment