@tsparticles/plugin-poisson-disc 4.0.0-alpha.8 → 4.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/56.min.js +1 -0
- package/960.min.js +1 -0
- package/964.min.js +1 -0
- package/browser/Options/Classes/Poisson.js +5 -0
- package/browser/PoissonDisc.js +79 -67
- package/browser/PoissonDiscPlugin.js +1 -3
- package/browser/PoissonDiscPluginInstance.js +9 -2
- package/browser/index.js +1 -1
- package/cjs/Options/Classes/Poisson.js +5 -0
- package/cjs/PoissonDisc.js +79 -67
- package/cjs/PoissonDiscPlugin.js +1 -3
- package/cjs/PoissonDiscPluginInstance.js +9 -2
- package/cjs/index.js +1 -1
- package/dist_browser_PoissonDiscPluginInstance_js.js +2 -12
- package/dist_browser_PoissonDiscPlugin_js.js +3 -3
- package/dist_browser_PoissonDisc_js.js +30 -0
- package/esm/Options/Classes/Poisson.js +5 -0
- package/esm/PoissonDisc.js +79 -67
- package/esm/PoissonDiscPlugin.js +1 -3
- package/esm/PoissonDiscPluginInstance.js +9 -2
- package/esm/index.js +1 -1
- package/package.json +2 -2
- package/report.html +1 -1
- package/tsparticles.plugin.poisson.js +31 -19
- package/tsparticles.plugin.poisson.min.js +2 -2
- package/types/PoissonDisc.d.ts +1 -1
- package/types/PoissonDiscPlugin.d.ts +1 -2
- package/types/PoissonDiscPluginInstance.d.ts +1 -1
- package/umd/Options/Classes/Poisson.js +5 -0
- package/umd/PoissonDisc.js +79 -67
- package/umd/PoissonDiscPlugin.js +1 -3
- package/umd/PoissonDiscPluginInstance.js +45 -4
- package/umd/index.js +1 -1
- package/336.min.js +0 -2
- package/336.min.js.LICENSE.txt +0 -1
- package/879.min.js +0 -2
- package/879.min.js.LICENSE.txt +0 -1
- package/tsparticles.plugin.poisson.min.js.LICENSE.txt +0 -1
package/umd/PoissonDisc.js
CHANGED
|
@@ -12,6 +12,17 @@
|
|
|
12
12
|
exports.PoissonDisc = void 0;
|
|
13
13
|
const engine_1 = require("@tsparticles/engine");
|
|
14
14
|
class PoissonDisc {
|
|
15
|
+
active;
|
|
16
|
+
cellSize;
|
|
17
|
+
cols;
|
|
18
|
+
dimensions;
|
|
19
|
+
firstPoint;
|
|
20
|
+
grid;
|
|
21
|
+
points;
|
|
22
|
+
radius;
|
|
23
|
+
retries;
|
|
24
|
+
rows;
|
|
25
|
+
size;
|
|
15
26
|
constructor(size, radius, retries, dimensions, firstPoint) {
|
|
16
27
|
this.size = { ...size };
|
|
17
28
|
this.radius = radius;
|
|
@@ -74,18 +85,22 @@
|
|
|
74
85
|
}
|
|
75
86
|
async run() {
|
|
76
87
|
this.reset();
|
|
77
|
-
const minCount = 0, step = 1;
|
|
88
|
+
const minCount = 0, step = 1, yieldEvery = 100, yieldStepModule = 0;
|
|
89
|
+
let iterations = 0;
|
|
78
90
|
while (this.active.length > minCount) {
|
|
79
|
-
|
|
91
|
+
this.steps(step);
|
|
92
|
+
if (++iterations % yieldEvery === yieldStepModule) {
|
|
93
|
+
await new Promise(resolve => setTimeout(resolve));
|
|
94
|
+
}
|
|
80
95
|
}
|
|
81
96
|
}
|
|
82
|
-
|
|
97
|
+
steps(steps) {
|
|
83
98
|
const minCount = 0;
|
|
84
99
|
for (let i = 0; i < steps; i++) {
|
|
85
100
|
if (this.active.length <= minCount) {
|
|
86
101
|
continue;
|
|
87
102
|
}
|
|
88
|
-
|
|
103
|
+
this._step();
|
|
89
104
|
}
|
|
90
105
|
}
|
|
91
106
|
_getNewPoint(currentPoint, tries) {
|
|
@@ -99,79 +114,76 @@
|
|
|
99
114
|
x: Math.floor(newPoint.x / this.cellSize),
|
|
100
115
|
y: Math.floor(newPoint.y / this.cellSize),
|
|
101
116
|
};
|
|
102
|
-
if (newPoint.x
|
|
103
|
-
newPoint.x
|
|
104
|
-
newPoint.y
|
|
105
|
-
newPoint.y
|
|
106
|
-
|
|
107
|
-
if (!row) {
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
const point = row[newGridCoords.x];
|
|
111
|
-
if (point === undefined) {
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
if (point < gridMinValue) {
|
|
115
|
-
for (let i = -1; i <= maxNeighbourIndex; i++) {
|
|
116
|
-
for (let j = -1; j <= maxNeighbourIndex; j++) {
|
|
117
|
-
const neighbourGrid = {
|
|
118
|
-
x: newGridCoords.x + j,
|
|
119
|
-
y: newGridCoords.y + i,
|
|
120
|
-
};
|
|
121
|
-
if (neighbourGrid.x >= minCoordinate &&
|
|
122
|
-
neighbourGrid.y >= minCoordinate &&
|
|
123
|
-
neighbourGrid.x < this.cols &&
|
|
124
|
-
neighbourGrid.y < this.rows &&
|
|
125
|
-
(neighbourGrid.x !== newGridCoords.x || neighbourGrid.y !== newGridCoords.y)) {
|
|
126
|
-
if (point >= gridMinValue) {
|
|
127
|
-
const neighbourIndex = point, neighbour = this.points[neighbourIndex];
|
|
128
|
-
if (!neighbour) {
|
|
129
|
-
continue;
|
|
130
|
-
}
|
|
131
|
-
const dist = (0, engine_1.getDistance)(newPoint, neighbour.position);
|
|
132
|
-
if (dist < this.radius) {
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
else {
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
117
|
+
if (newPoint.x <= minCoordinate ||
|
|
118
|
+
newPoint.x >= this.size.width ||
|
|
119
|
+
newPoint.y <= minCoordinate ||
|
|
120
|
+
newPoint.y >= this.size.height) {
|
|
121
|
+
return;
|
|
143
122
|
}
|
|
144
|
-
|
|
123
|
+
const row = this.grid[newGridCoords.y];
|
|
124
|
+
if (!row) {
|
|
145
125
|
return;
|
|
146
126
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
127
|
+
const cellValue = row[newGridCoords.x];
|
|
128
|
+
if (cellValue === undefined) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
if (cellValue >= gridMinValue) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
for (let i = -1; i <= maxNeighbourIndex; i++) {
|
|
135
|
+
for (let j = -1; j <= maxNeighbourIndex; j++) {
|
|
136
|
+
if (!i && !j) {
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
const neighbourGrid = {
|
|
140
|
+
x: newGridCoords.x + j,
|
|
141
|
+
y: newGridCoords.y + i,
|
|
142
|
+
};
|
|
143
|
+
if (neighbourGrid.x < minCoordinate ||
|
|
144
|
+
neighbourGrid.y < minCoordinate ||
|
|
145
|
+
neighbourGrid.x >= this.cols ||
|
|
146
|
+
neighbourGrid.y >= this.rows) {
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
const neighbourCellValue = this.grid[neighbourGrid.y]?.[neighbourGrid.x];
|
|
150
|
+
if (neighbourCellValue === undefined || neighbourCellValue < gridMinValue) {
|
|
156
151
|
continue;
|
|
157
152
|
}
|
|
158
|
-
const
|
|
159
|
-
if (!
|
|
153
|
+
const neighbour = this.points[neighbourCellValue];
|
|
154
|
+
if (!neighbour) {
|
|
160
155
|
continue;
|
|
161
156
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
foundNewPoint = true;
|
|
165
|
-
this.addPoint(newPoint);
|
|
166
|
-
break;
|
|
157
|
+
if ((0, engine_1.getDistance)(newPoint, neighbour.position) < this.radius) {
|
|
158
|
+
return;
|
|
167
159
|
}
|
|
168
160
|
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
161
|
+
}
|
|
162
|
+
return newPoint;
|
|
163
|
+
}
|
|
164
|
+
_step() {
|
|
165
|
+
const minCount = 0, randomActive = this.getRandom(minCount, this.active.length);
|
|
166
|
+
let foundNewPoint = false;
|
|
167
|
+
for (let tries = 0; tries < this.retries; tries++) {
|
|
168
|
+
const randomActivePointIndex = this.active[randomActive];
|
|
169
|
+
if (randomActivePointIndex === undefined) {
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
const point = this.points[randomActivePointIndex];
|
|
173
|
+
if (!point) {
|
|
174
|
+
continue;
|
|
172
175
|
}
|
|
173
|
-
|
|
174
|
-
|
|
176
|
+
const newPoint = this._getNewPoint(point, tries);
|
|
177
|
+
if (newPoint) {
|
|
178
|
+
foundNewPoint = true;
|
|
179
|
+
this.addPoint(newPoint);
|
|
180
|
+
break;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
if (!foundNewPoint) {
|
|
184
|
+
const deleteCount = 1;
|
|
185
|
+
this.active.splice(randomActive, deleteCount);
|
|
186
|
+
}
|
|
175
187
|
}
|
|
176
188
|
}
|
|
177
189
|
exports.PoissonDisc = PoissonDisc;
|
package/umd/PoissonDiscPlugin.js
CHANGED
|
@@ -46,9 +46,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
46
46
|
exports.PoissonDiscPlugin = void 0;
|
|
47
47
|
const Poisson_js_1 = require("./Options/Classes/Poisson.js");
|
|
48
48
|
class PoissonDiscPlugin {
|
|
49
|
-
|
|
50
|
-
this.id = "poisson";
|
|
51
|
-
}
|
|
49
|
+
id = "poisson";
|
|
52
50
|
async getPlugin(container) {
|
|
53
51
|
const { PoissonDiscPluginInstance } = await (__syncRequire ? Promise.resolve().then(() => __importStar(require("./PoissonDiscPluginInstance.js"))) : new Promise((resolve_1, reject_1) => { require(["./PoissonDiscPluginInstance.js"], resolve_1, reject_1); }).then(__importStar));
|
|
54
52
|
return new PoissonDiscPluginInstance(container);
|
|
@@ -1,18 +1,55 @@
|
|
|
1
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
2
|
+
if (k2 === undefined) k2 = k;
|
|
3
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
4
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
5
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
6
|
+
}
|
|
7
|
+
Object.defineProperty(o, k2, desc);
|
|
8
|
+
}) : (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
o[k2] = m[k];
|
|
11
|
+
}));
|
|
12
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
13
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
14
|
+
}) : function(o, v) {
|
|
15
|
+
o["default"] = v;
|
|
16
|
+
});
|
|
17
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
18
|
+
var ownKeys = function(o) {
|
|
19
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
20
|
+
var ar = [];
|
|
21
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
22
|
+
return ar;
|
|
23
|
+
};
|
|
24
|
+
return ownKeys(o);
|
|
25
|
+
};
|
|
26
|
+
return function (mod) {
|
|
27
|
+
if (mod && mod.__esModule) return mod;
|
|
28
|
+
var result = {};
|
|
29
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
30
|
+
__setModuleDefault(result, mod);
|
|
31
|
+
return result;
|
|
32
|
+
};
|
|
33
|
+
})();
|
|
1
34
|
(function (factory) {
|
|
2
35
|
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
36
|
var v = factory(require, exports);
|
|
4
37
|
if (v !== undefined) module.exports = v;
|
|
5
38
|
}
|
|
6
39
|
else if (typeof define === "function" && define.amd) {
|
|
7
|
-
define(["require", "exports", "@tsparticles/engine"
|
|
40
|
+
define(["require", "exports", "@tsparticles/engine"], factory);
|
|
8
41
|
}
|
|
9
42
|
})(function (require, exports) {
|
|
10
43
|
"use strict";
|
|
44
|
+
var __syncRequire = typeof module === "object" && typeof module.exports === "object";
|
|
11
45
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
46
|
exports.PoissonDiscPluginInstance = void 0;
|
|
13
47
|
const engine_1 = require("@tsparticles/engine");
|
|
14
|
-
const PoissonDisc_js_1 = require("./PoissonDisc.js");
|
|
15
48
|
class PoissonDiscPluginInstance {
|
|
49
|
+
poissonDisc;
|
|
50
|
+
redrawTimeout;
|
|
51
|
+
_container;
|
|
52
|
+
_currentIndex;
|
|
16
53
|
constructor(container) {
|
|
17
54
|
this._container = container;
|
|
18
55
|
this._currentIndex = 0;
|
|
@@ -38,6 +75,9 @@
|
|
|
38
75
|
const timeout = 250;
|
|
39
76
|
this.redrawTimeout = setTimeout(() => {
|
|
40
77
|
void (async () => {
|
|
78
|
+
if (this._container.destroyed) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
41
81
|
await this._initData();
|
|
42
82
|
await container.particles.redraw();
|
|
43
83
|
})();
|
|
@@ -52,12 +92,13 @@
|
|
|
52
92
|
return;
|
|
53
93
|
}
|
|
54
94
|
this._currentIndex = 0;
|
|
55
|
-
|
|
95
|
+
const { PoissonDisc } = await (__syncRequire ? Promise.resolve().then(() => __importStar(require("./PoissonDisc.js"))) : new Promise((resolve_1, reject_1) => { require(["./PoissonDisc.js"], resolve_1, reject_1); }).then(__importStar));
|
|
96
|
+
this.poissonDisc = new PoissonDisc(canvasSize, poissonOptions.radius
|
|
56
97
|
? poissonOptions.radius * pixelRatio
|
|
57
98
|
: Math.max((0, engine_1.getRangeMax)(particlesOptions.size.value) * pixelRatio, Math.sqrt((canvasSize.width * canvasSize.height) / particlesOptions.number.value)), poissonOptions.retries, poissonOptions.dimensions);
|
|
58
99
|
const noSteps = 0;
|
|
59
100
|
if (poissonOptions.steps > noSteps) {
|
|
60
|
-
|
|
101
|
+
this.poissonDisc.steps(poissonOptions.steps);
|
|
61
102
|
}
|
|
62
103
|
else {
|
|
63
104
|
await this.poissonDisc.run();
|
package/umd/index.js
CHANGED
|
@@ -45,7 +45,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
45
45
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
46
|
exports.loadPoissonDiscPlugin = loadPoissonDiscPlugin;
|
|
47
47
|
async function loadPoissonDiscPlugin(engine) {
|
|
48
|
-
engine.checkVersion("4.0.0-
|
|
48
|
+
engine.checkVersion("4.0.0-beta.0");
|
|
49
49
|
await engine.register(async (e) => {
|
|
50
50
|
const { PoissonDiscPlugin } = await (__syncRequire ? Promise.resolve().then(() => __importStar(require("./PoissonDiscPlugin.js"))) : new Promise((resolve_1, reject_1) => { require(["./PoissonDiscPlugin.js"], resolve_1, reject_1); }).then(__importStar));
|
|
51
51
|
e.addPlugin(new PoissonDiscPlugin());
|
package/336.min.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
/*! For license information please see 336.min.js.LICENSE.txt */
|
|
2
|
-
(this.webpackChunk_tsparticles_plugin_poisson_disc=this.webpackChunk_tsparticles_plugin_poisson_disc||[]).push([[336],{336(i,t,s){s.d(t,{PoissonDiscPluginInstance:()=>n});var e=s(303);class o{constructor(i,t,s,e,o){this.size={...i},this.radius=t,this.retries=s,this.dimensions=e,this.cellSize=Math.floor(this.radius/Math.sqrt(this.dimensions)),this.cols=Math.floor(this.size.width/this.cellSize),this.rows=Math.floor(this.size.height/this.cellSize),this.points=[],this.active=[],this.grid=[],this.firstPoint=o?{...o}:void 0,this.reset()}addPoint(i){const t={position:{...i},gridPosition:{x:Math.floor(i.x/this.cellSize),y:Math.floor(i.y/this.cellSize)}},s=this.points.length,e=this.grid[t.gridPosition.y];e&&(this.points.push(t),e[t.gridPosition.x]=s,this.active.push(s))}getRandom(i,t){return Math.floor((0,e.getRandom)()*(t-i))+i}initialiseGrid(){for(let i=0;i<=this.rows;i++){this.grid[i]=[];const t=this.grid[i];if(t)for(let i=0;i<=this.cols;i++)t[i]=-1}}reset(){if(this.points=[],this.active=[],this.grid=[],this.initialiseGrid(),this.firstPoint)this.addPoint(this.firstPoint);else{const i=0;this.addPoint({x:this.getRandom(i,this.size.width),y:this.getRandom(i,this.size.height)})}}async run(){this.reset();for(;this.active.length>0;)await this.steps(1)}async steps(i){for(let t=0;t<i;t++)this.active.length<=0||await this._step()}_getNewPoint(i,t){const s=t*(e.doublePI/this.retries),o=this.getRandom(this.radius,this.radius*e.double),n=Math.cos(s)*o,h=Math.sin(s)*o,r={x:Math.floor(i.position.x+n),y:Math.floor(i.position.y+h)},a=Math.floor(r.x/this.cellSize),c=Math.floor(r.y/this.cellSize);if(r.x>0&&r.x<this.size.width&&r.y>0&&r.y<this.size.height){{const i=this.grid[c];if(!i)return;const t=i[a];if(void 0===t)return;if(!(t<0))return;for(let i=-1;i<=1;i++)for(let s=-1;s<=1;s++){const o={x:a+s,y:c+i};if(o.x>=0&&o.y>=0&&o.x<this.cols&&o.y<this.rows&&(o.x!==a||o.y!==c)&&t>=0){const i=t,s=this.points[i];if(!s)continue;if((0,e.getDistance)(r,s.position)<this.radius)return}}}return r}}async _step(){const i=this.getRandom(0,this.active.length);return new Promise((t=>{let s=!1;for(let t=0;t<this.retries;t++){const e=this.active[i];if(void 0===e)continue;const o=this.points[e];if(!o)continue;const n=this._getNewPoint(o,t);if(n){s=!0,this.addPoint(n);break}}if(!s){const t=1;this.active.splice(i,t)}t()}))}}class n{constructor(i){this._container=i,this._currentIndex=0}async init(){await this._initData()}particlePosition(i){const t=this._container.actualOptions.poisson;if(this.poissonDisc&&t?.enable&&!(this._currentIndex>=this.poissonDisc.points.length))return i??this.poissonDisc.points[this._currentIndex++]?.position}resize(){const i=this._container,t=i.actualOptions.poisson;if(!t?.enable)return;this.redrawTimeout&&clearTimeout(this.redrawTimeout);this.redrawTimeout=setTimeout((()=>{(async()=>{await this._initData(),await i.particles.redraw()})()}),250)}stop(){delete this.poissonDisc}async _initData(){const i=this._container,t=i.actualOptions.poisson,s=i.actualOptions.particles,n=i.canvas.size,h=i.retina.pixelRatio;if(!t?.enable)return;this._currentIndex=0,this.poissonDisc=new o(n,t.radius?t.radius*h:Math.max((0,e.getRangeMax)(s.size.value)*h,Math.sqrt(n.width*n.height/s.number.value)),t.retries,t.dimensions);t.steps>0?await this.poissonDisc.steps(t.steps):await this.poissonDisc.run()}}}}]);
|
package/336.min.js.LICENSE.txt
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
/*! tsParticles Poisson Disc Plugin v4.0.0-alpha.8 by Matteo Bruni */
|
package/879.min.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
/*! For license information please see 879.min.js.LICENSE.txt */
|
|
2
|
-
(this.webpackChunk_tsparticles_plugin_poisson_disc=this.webpackChunk_tsparticles_plugin_poisson_disc||[]).push([[879],{879(s,i,n){n.d(i,{PoissonDiscPlugin:()=>t});var e=n(303);class o{constructor(){this.enable=!1,this.dimensions=2,this.radius=0,this.retries=30,this.steps=0}load(s){(0,e.isNull)(s)||(void 0!==s.enable&&(this.enable=s.enable),void 0!==s.dimensions&&(this.dimensions=s.dimensions),void 0!==s.radius&&(this.radius=s.radius),void 0!==s.retries&&(this.retries=s.retries))}}class t{constructor(){this.id="poisson"}async getPlugin(s){const{PoissonDiscPluginInstance:i}=await n.e(336).then(n.bind(n,336));return new i(s)}loadOptions(s,i,n){if(!this.needsPlugin(i)&&!this.needsPlugin(n))return;let e=i.poisson;void 0===e?.load&&(i.poisson=e=new o),e.load(n?.poisson)}needsPlugin(s){return s?.poisson?.enable??!1}}}}]);
|
package/879.min.js.LICENSE.txt
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
/*! tsParticles Poisson Disc Plugin v4.0.0-alpha.8 by Matteo Bruni */
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
/*! tsParticles Poisson Disc Plugin v4.0.0-alpha.8 by Matteo Bruni */
|