Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

poisson-disc-sampler

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

poisson-disc-sampler - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

9

package.json
{
"name": "poisson-disc-sampler",
"version": "1.0.0",
"version": "1.1.0",
"description": "A simple Poisson disc sampler",

@@ -18,3 +18,3 @@ "main": "poisson-disc-sampler.js",

"author": "Beau Gunderson <beau@beaugunderson.com>",
"license": "BSD",
"license": "MIT",
"bugs": {

@@ -25,5 +25,6 @@ "url": "https://github.com/beaugunderson/node-poisson-disc-sampler/issues"

"devDependencies": {
"chai": "^1.10.0",
"mocha": "^2.0.1"
"chai": "^3.2.0",
"mocha": "^2.3.2",
"xorshift": "^0.2.0"
}
}
'use strict';
module.exports = function poissonDiscSampler(width, height, radius) {
module.exports = function poissonDiscSampler(width, height, radius, rng) {
var k = 30; // maximum number of samples before rejection

@@ -19,2 +19,4 @@ var radius2 = radius * radius;

rng = rng || Math.random;
function far(x, y) {

@@ -64,3 +66,3 @@ var i = x / cellSize | 0;

if (!sampleSize) {
return sample(Math.random() * width, Math.random() * height);
return sample(rng() * width, rng() * height);
}

@@ -70,3 +72,3 @@

while (queueSize) {
var i = Math.random() * queueSize | 0;
var i = rng() * queueSize | 0;
var s = queue[i];

@@ -77,4 +79,4 @@

for (var j = 0; j < k; ++j) {
var a = 2 * Math.PI * Math.random();
var r = Math.sqrt(Math.random() * R + radius2);
var a = 2 * Math.PI * rng();
var r = Math.sqrt(rng() * R + radius2);
var x = s[0] + r * Math.cos(a);

@@ -81,0 +83,0 @@ var y = s[1] + r * Math.sin(a);

require('chai').should();
var poissonDiscSampler = require('..');
var XorShift = require('xorshift').constructor;

@@ -25,2 +26,31 @@ describe('poisson-disc-sampler', function () {

});
it('should sample points correctly with a specified RNG', function () {
var WIDTH = 1000;
var HEIGHT = 500;
var xorshift = new XorShift([1, 0, 2, 0]);
// wrap this because we can't just pass the xorshift.random function to the
// sampler since it relies on the rest of the object (it calls
// this.randomint);
function random() {
return xorshift.random();
}
var sampler = poissonDiscSampler(WIDTH, HEIGHT, 10, random);
var sample;
var points = 0;
while ((sample = sampler())) {
points++;
sample[0].should.be.within(0, WIDTH);
sample[1].should.be.within(0, HEIGHT);
}
points.should.be.at.least(2500);
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc