Git Product home page Git Product logo

poisson-disk-sampling's People

Contributors

kchapelier avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

poisson-disk-sampling's Issues

cannot distribute in 0-1 range? (contrary to fast implementation)

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?

Minimum distance is not respected for points added manually.

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.

Easy perf tweak

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.

Problem with setting rng

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?

Remove ndarray dependency

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.

Add maxPoints value to constructor or fill()

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.

Browser build

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.