kchapelier / poisson-disk-sampling Goto Github PK
View Code? Open in Web Editor NEWPoisson disk sampling in arbitrary dimensions
License: MIT License
Poisson disk sampling in arbitrary dimensions
License: MIT License
This would be a nice enhancement, to be able to limit the maximum number of points that can be placed. It could go in the constructor or as a value for fill (as in fill(30) to fill in a max of 30 points).
It could be a nice alternative to a for loop calling pds.next() 30 times.
Hi, thanks for useful library, I am trying to set a different RNG but without success, this is what I do
var pds = new PoissonDiskSampling({
shape: [3*detX, 2*detY],
minDistance: 25,
maxDistance: 300,
tries: 20,
distanceFunction: function (p) {
return getMaskValue(p[0], p[1]); // value between 0 and 1
},
rng: fxrand()
});
points = pds.fill();
Where am i wrong?
The ndarray dependency and related dependencies (zeros, is-buffer and iota-array) are responsible for more than 60% of this package size ( https://bundlephobia.com/[email protected] ). It should be evaluated whether this can be replaced by a more size efficient solution which would be as maintainable and as performant.
Using the lib in the browser didn't seem to be an option yet so I put together a quick build to get it working with JSDelivr for now. Maybe that can be leveraged as a starting point.
Hi, thanks for this really nice lib!
I just tested both this implementation and the fast-2d-poisson-disk-sampling implementation.
With the fast implementation, I can generate normalized positions values in the 0-1 range, but cannot with this implementation: using fill()
only returns 1 point, trying to use next()
returns null
code used:
var pds = new PoissonDiskSampling({
shape: [1, 1],
minDistance: 0.05,
tries: 10,
});
I want to use a distanceFunction, so my workaround will be to use shape: [10, 10]
and divide everything back, but it's not elegant and might lead to errors.
Do you see a reason why it fails?
Hi,
I was looking at the code to find wether the algorithm is the same as here: https://bl.ocks.org/mbostock/19168c663618b7f07158 (is it?).
Then I noticed there is an easy way to speed up things a little bit: since your compute distances only for the sake of comparison, you could work with squared numbers everywhere. That way, you initially square the distances (1-time operation) and when you compute euclideanDistanceN
, you omit the square root.
I don't think it will offer an amazing boost, but it is an obvious and easy tweak.
Example code that frequently shows the behavior:
var pds1D = new PoissonDiskSampling({
shape: [300],
minDistance: 30,
maxDistance: 50,
tries: 10
});
pds1D.addPoint([0]);
pds1D.addPoint([300]);
console.log(pds1D.fill());
And a sample output from this: (rounded)
[ 0, 300, 34.983, 252.519, 78.478, 299.370, 214.373, 122.566, 178.245 ]
Clearly, point 5 (299.370) is not respecting the minDistance from point 1 (300). From my testing, it does seem to respect the distance to point 0.
I'm looking at implementing poisson disk sampling but using noise values for distances, as described under "Applications" in this article: http://devmag.org.za/2009/05/03/poisson-disk-sampling/
I need that type of distribution for a project. This project seems the most mature so I figured I'd file it as an issue.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.