@tsparticles/engine 3.7.0 → 3.8.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/browser/Core/Canvas.js +51 -36
- package/browser/Core/Container.js +10 -13
- package/browser/Core/Engine.js +15 -11
- package/browser/Core/Particle.js +8 -11
- package/browser/Core/Particles.js +10 -14
- package/browser/Core/Retina.js +1 -1
- package/browser/Core/Utils/Constants.js +10 -16
- package/browser/Core/Utils/EventListeners.js +5 -8
- package/browser/Core/Utils/QuadTree.js +1 -1
- package/browser/Core/Utils/Ranges.js +1 -1
- package/browser/Core/Utils/Vectors.js +10 -15
- package/browser/Options/Classes/ManualParticle.js +3 -3
- package/browser/Utils/CanvasUtils.js +8 -14
- package/browser/Utils/ColorUtils.js +12 -17
- package/browser/Utils/EventDispatcher.js +2 -2
- package/browser/Utils/NumberUtils.js +2 -4
- package/browser/Utils/Utils.js +58 -9
- package/cjs/Core/Canvas.js +52 -37
- package/cjs/Core/Container.js +14 -17
- package/cjs/Core/Engine.js +21 -17
- package/cjs/Core/Particle.js +18 -21
- package/cjs/Core/Particles.js +22 -26
- package/cjs/Core/Retina.js +5 -5
- package/cjs/Core/Utils/Constants.js +12 -17
- package/cjs/Core/Utils/EventListeners.js +8 -11
- package/cjs/Core/Utils/QuadTree.js +4 -4
- package/cjs/Core/Utils/Ranges.js +4 -4
- package/cjs/Core/Utils/Vectors.js +11 -16
- package/cjs/Options/Classes/ManualParticle.js +3 -3
- package/cjs/Utils/CanvasUtils.js +14 -20
- package/cjs/Utils/ColorUtils.js +47 -52
- package/cjs/Utils/EventDispatcher.js +5 -5
- package/cjs/Utils/NumberUtils.js +11 -13
- package/cjs/Utils/Utils.js +60 -10
- package/esm/Core/Canvas.js +51 -36
- package/esm/Core/Container.js +10 -13
- package/esm/Core/Engine.js +15 -11
- package/esm/Core/Particle.js +8 -11
- package/esm/Core/Particles.js +10 -14
- package/esm/Core/Retina.js +1 -1
- package/esm/Core/Utils/Constants.js +10 -16
- package/esm/Core/Utils/EventListeners.js +5 -8
- package/esm/Core/Utils/QuadTree.js +1 -1
- package/esm/Core/Utils/Ranges.js +1 -1
- package/esm/Core/Utils/Vectors.js +10 -15
- package/esm/Options/Classes/ManualParticle.js +3 -3
- package/esm/Utils/CanvasUtils.js +8 -14
- package/esm/Utils/ColorUtils.js +12 -17
- package/esm/Utils/EventDispatcher.js +2 -2
- package/esm/Utils/NumberUtils.js +2 -4
- package/esm/Utils/Utils.js +58 -9
- package/package.json +1 -1
- package/report.html +1 -1
- package/tsparticles.engine.js +20 -20
- package/tsparticles.engine.min.js +1 -1
- package/tsparticles.engine.min.js.LICENSE.txt +1 -1
- package/types/Core/Canvas.d.ts +1 -1
- package/types/Core/Engine.d.ts +5 -4
- package/types/Core/Utils/Constants.d.ts +7 -16
- package/types/Utils/ColorUtils.d.ts +1 -1
- package/types/Utils/Utils.d.ts +2 -2
- package/umd/Core/Canvas.js +53 -38
- package/umd/Core/Container.js +14 -17
- package/umd/Core/Engine.js +21 -17
- package/umd/Core/Particle.js +19 -22
- package/umd/Core/Particles.js +23 -27
- package/umd/Core/Retina.js +6 -6
- package/umd/Core/Utils/Constants.js +11 -17
- package/umd/Core/Utils/EventListeners.js +9 -12
- package/umd/Core/Utils/QuadTree.js +5 -5
- package/umd/Core/Utils/Ranges.js +5 -5
- package/umd/Core/Utils/Vectors.js +11 -16
- package/umd/Options/Classes/ManualParticle.js +4 -4
- package/umd/Utils/CanvasUtils.js +15 -21
- package/umd/Utils/ColorUtils.js +48 -53
- package/umd/Utils/EventDispatcher.js +6 -6
- package/umd/Utils/NumberUtils.js +12 -14
- package/umd/Utils/Utils.js +60 -10
package/cjs/Core/Container.js
CHANGED
|
@@ -14,11 +14,10 @@ const OptionsUtils_js_1 = require("../Utils/OptionsUtils.js");
|
|
|
14
14
|
function guardCheck(container) {
|
|
15
15
|
return container && !container.destroyed;
|
|
16
16
|
}
|
|
17
|
-
|
|
18
|
-
function initDelta(value, fpsLimit = defaultFps, smooth = false) {
|
|
17
|
+
function initDelta(value, fpsLimit = Constants_js_1.defaultFps, smooth = false) {
|
|
19
18
|
return {
|
|
20
19
|
value,
|
|
21
|
-
factor: smooth ? defaultFps / fpsLimit : (defaultFps * value) / Constants_js_1.millisecondsToSeconds,
|
|
20
|
+
factor: smooth ? Constants_js_1.defaultFps / fpsLimit : (Constants_js_1.defaultFps * value) / Constants_js_1.millisecondsToSeconds,
|
|
22
21
|
};
|
|
23
22
|
}
|
|
24
23
|
function loadContainerOptions(engine, container, ...sourceOptionsArr) {
|
|
@@ -142,8 +141,8 @@ class Container {
|
|
|
142
141
|
const mouseEvent = e, pos = {
|
|
143
142
|
x: mouseEvent.offsetX || mouseEvent.clientX,
|
|
144
143
|
y: mouseEvent.offsetY || mouseEvent.clientY,
|
|
145
|
-
}
|
|
146
|
-
clickOrTouchHandler(e, pos,
|
|
144
|
+
};
|
|
145
|
+
clickOrTouchHandler(e, pos, Constants_js_1.clickRadius);
|
|
147
146
|
}, touchStartHandler = () => {
|
|
148
147
|
if (!guardCheck(this)) {
|
|
149
148
|
return;
|
|
@@ -160,17 +159,17 @@ class Container {
|
|
|
160
159
|
return;
|
|
161
160
|
}
|
|
162
161
|
if (touched && !touchMoved) {
|
|
163
|
-
const touchEvent = e
|
|
164
|
-
let lastTouch = touchEvent.touches[touchEvent.touches.length -
|
|
162
|
+
const touchEvent = e;
|
|
163
|
+
let lastTouch = touchEvent.touches[touchEvent.touches.length - Constants_js_1.touchEndLengthOffset];
|
|
165
164
|
if (!lastTouch) {
|
|
166
|
-
lastTouch = touchEvent.changedTouches[touchEvent.changedTouches.length -
|
|
165
|
+
lastTouch = touchEvent.changedTouches[touchEvent.changedTouches.length - Constants_js_1.touchEndLengthOffset];
|
|
167
166
|
if (!lastTouch) {
|
|
168
167
|
return;
|
|
169
168
|
}
|
|
170
169
|
}
|
|
171
|
-
const element = this.canvas.element, canvasRect = element ? element.getBoundingClientRect() : undefined,
|
|
172
|
-
x: lastTouch.clientX - (canvasRect ? canvasRect.left : minCoordinate),
|
|
173
|
-
y: lastTouch.clientY - (canvasRect ? canvasRect.top : minCoordinate),
|
|
170
|
+
const element = this.canvas.element, canvasRect = element ? element.getBoundingClientRect() : undefined, pos = {
|
|
171
|
+
x: lastTouch.clientX - (canvasRect ? canvasRect.left : Constants_js_1.minCoordinate),
|
|
172
|
+
y: lastTouch.clientY - (canvasRect ? canvasRect.top : Constants_js_1.minCoordinate),
|
|
174
173
|
};
|
|
175
174
|
clickOrTouchHandler(e, pos, Math.max(lastTouch.radiusX, lastTouch.radiusY));
|
|
176
175
|
}
|
|
@@ -238,10 +237,9 @@ class Container {
|
|
|
238
237
|
this._engine.clearPlugins(this);
|
|
239
238
|
this.destroyed = true;
|
|
240
239
|
if (remove) {
|
|
241
|
-
const mainArr = this._engine.items, idx = mainArr.findIndex(t => t === this)
|
|
242
|
-
if (idx >=
|
|
243
|
-
|
|
244
|
-
mainArr.splice(idx, deleteCount);
|
|
240
|
+
const mainArr = this._engine.items, idx = mainArr.findIndex(t => t === this);
|
|
241
|
+
if (idx >= Constants_js_1.removeMinIndex) {
|
|
242
|
+
mainArr.splice(idx, Constants_js_1.removeDeleteCount);
|
|
245
243
|
}
|
|
246
244
|
}
|
|
247
245
|
this._engine.dispatchEvent(EventType_js_1.EventType.containerDestroyed, { container: this });
|
|
@@ -317,8 +315,7 @@ class Container {
|
|
|
317
315
|
this._duration = (0, NumberUtils_js_1.getRangeValue)(duration) * Constants_js_1.millisecondsToSeconds;
|
|
318
316
|
this._delay = (0, NumberUtils_js_1.getRangeValue)(delay) * Constants_js_1.millisecondsToSeconds;
|
|
319
317
|
this._lifeTime = 0;
|
|
320
|
-
|
|
321
|
-
this.fpsLimit = fpsLimit > minFpsLimit ? fpsLimit : defaultFpsLimit;
|
|
318
|
+
this.fpsLimit = fpsLimit > Constants_js_1.minFpsLimit ? fpsLimit : Constants_js_1.defaultFpsLimit;
|
|
322
319
|
this._smooth = smooth;
|
|
323
320
|
for (const drawer of this.effectDrawers.values()) {
|
|
324
321
|
await drawer.init?.(this);
|
package/cjs/Core/Engine.js
CHANGED
|
@@ -27,24 +27,23 @@ async function getDataFromUrl(data) {
|
|
|
27
27
|
(0, Utils_js_1.getLogger)().error(`${Constants_js_1.errorPrefix} ${response.status} while retrieving config file`);
|
|
28
28
|
return data.fallback;
|
|
29
29
|
}
|
|
30
|
-
const
|
|
30
|
+
const getCanvasFromContainer = (domContainer) => {
|
|
31
31
|
let canvasEl;
|
|
32
|
-
if (domContainer instanceof HTMLCanvasElement || domContainer.tagName.toLowerCase() === canvasTag) {
|
|
32
|
+
if (domContainer instanceof HTMLCanvasElement || domContainer.tagName.toLowerCase() === Constants_js_1.canvasTag) {
|
|
33
33
|
canvasEl = domContainer;
|
|
34
34
|
if (!canvasEl.dataset[Constants_js_1.generatedAttribute]) {
|
|
35
|
-
canvasEl.dataset[Constants_js_1.generatedAttribute] = generatedFalse;
|
|
35
|
+
canvasEl.dataset[Constants_js_1.generatedAttribute] = Constants_js_1.generatedFalse;
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
else {
|
|
39
|
-
const existingCanvases = domContainer.getElementsByTagName(canvasTag);
|
|
39
|
+
const existingCanvases = domContainer.getElementsByTagName(Constants_js_1.canvasTag);
|
|
40
40
|
if (existingCanvases.length) {
|
|
41
|
-
|
|
42
|
-
canvasEl =
|
|
43
|
-
canvasEl.dataset[Constants_js_1.generatedAttribute] = generatedFalse;
|
|
41
|
+
canvasEl = existingCanvases[Constants_js_1.canvasFirstIndex];
|
|
42
|
+
canvasEl.dataset[Constants_js_1.generatedAttribute] = Constants_js_1.generatedFalse;
|
|
44
43
|
}
|
|
45
44
|
else {
|
|
46
|
-
canvasEl = document.createElement(canvasTag);
|
|
47
|
-
canvasEl.dataset[Constants_js_1.generatedAttribute] = generatedTrue;
|
|
45
|
+
canvasEl = document.createElement(Constants_js_1.canvasTag);
|
|
46
|
+
canvasEl.dataset[Constants_js_1.generatedAttribute] = Constants_js_1.generatedTrue;
|
|
48
47
|
domContainer.appendChild(canvasEl);
|
|
49
48
|
}
|
|
50
49
|
}
|
|
@@ -63,7 +62,7 @@ const generatedTrue = "true", generatedFalse = "false", canvasTag = "canvas", ge
|
|
|
63
62
|
}
|
|
64
63
|
domContainer = document.createElement("div");
|
|
65
64
|
domContainer.id = id;
|
|
66
|
-
domContainer.dataset[Constants_js_1.generatedAttribute] = generatedTrue;
|
|
65
|
+
domContainer.dataset[Constants_js_1.generatedAttribute] = Constants_js_1.generatedTrue;
|
|
67
66
|
document.body.append(domContainer);
|
|
68
67
|
return domContainer;
|
|
69
68
|
};
|
|
@@ -100,7 +99,7 @@ class Engine {
|
|
|
100
99
|
return this._domArray;
|
|
101
100
|
}
|
|
102
101
|
get version() {
|
|
103
|
-
return "3.
|
|
102
|
+
return "3.8.0";
|
|
104
103
|
}
|
|
105
104
|
async addColorManager(manager, refresh = true) {
|
|
106
105
|
this.colorManagers.set(manager.key, manager);
|
|
@@ -168,6 +167,12 @@ class Engine {
|
|
|
168
167
|
}
|
|
169
168
|
await this.refresh(refresh);
|
|
170
169
|
}
|
|
170
|
+
checkVersion(pluginVersion) {
|
|
171
|
+
if (this.version === pluginVersion) {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
throw new Error(`The tsParticles version is different from the loaded plugins version. Engine version: ${this.version}. Plugin version: ${pluginVersion}`);
|
|
175
|
+
}
|
|
171
176
|
clearPlugins(container) {
|
|
172
177
|
this.updaters.delete(container);
|
|
173
178
|
this.movers.delete(container);
|
|
@@ -233,17 +238,16 @@ class Engine {
|
|
|
233
238
|
item(index) {
|
|
234
239
|
const { items } = this, item = items[index];
|
|
235
240
|
if (!item || item.destroyed) {
|
|
236
|
-
|
|
237
|
-
items.splice(index, deleteCount);
|
|
241
|
+
items.splice(index, Constants_js_1.removeDeleteCount);
|
|
238
242
|
return;
|
|
239
243
|
}
|
|
240
244
|
return item;
|
|
241
245
|
}
|
|
242
246
|
async load(params) {
|
|
243
|
-
const
|
|
244
|
-
const currentOptions = (0, Utils_js_1.itemFromSingleOrMultiple)(options, index), { items } = this, oldIndex = items.findIndex(v => v.id.description === id),
|
|
245
|
-
if (oldIndex >=
|
|
246
|
-
const old = this.item(oldIndex),
|
|
247
|
+
const id = params.id ?? params.element?.id ?? `tsparticles${Math.floor((0, NumberUtils_js_1.getRandom)() * Constants_js_1.loadRandomFactor)}`, { index, url } = params, options = url ? await getDataFromUrl({ fallback: params.options, url, index }) : params.options;
|
|
248
|
+
const currentOptions = (0, Utils_js_1.itemFromSingleOrMultiple)(options, index), { items } = this, oldIndex = items.findIndex(v => v.id.description === id), newItem = new Container_js_1.Container(this, id, currentOptions);
|
|
249
|
+
if (oldIndex >= Constants_js_1.loadMinIndex) {
|
|
250
|
+
const old = this.item(oldIndex), deleteCount = old ? Constants_js_1.one : Constants_js_1.none;
|
|
247
251
|
if (old && !old.destroyed) {
|
|
248
252
|
old.destroy(false);
|
|
249
253
|
}
|
package/cjs/Core/Particle.js
CHANGED
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Particle = void 0;
|
|
4
4
|
const Vectors_js_1 = require("./Utils/Vectors.js");
|
|
5
5
|
const NumberUtils_js_1 = require("../Utils/NumberUtils.js");
|
|
6
|
-
const Utils_js_1 = require("../Utils/Utils.js");
|
|
7
6
|
const Constants_js_1 = require("./Utils/Constants.js");
|
|
7
|
+
const Utils_js_1 = require("../Utils/Utils.js");
|
|
8
8
|
const ColorUtils_js_1 = require("../Utils/ColorUtils.js");
|
|
9
9
|
const EventType_js_1 = require("../Enums/Types/EventType.js");
|
|
10
10
|
const Interactivity_js_1 = require("../Options/Classes/Interactivity/Interactivity.js");
|
|
@@ -14,7 +14,6 @@ const ParticleOutType_js_1 = require("../Enums/Types/ParticleOutType.js");
|
|
|
14
14
|
const PixelMode_js_1 = require("../Enums/Modes/PixelMode.js");
|
|
15
15
|
const CanvasUtils_js_1 = require("../Utils/CanvasUtils.js");
|
|
16
16
|
const OptionsUtils_js_1 = require("../Utils/OptionsUtils.js");
|
|
17
|
-
const defaultRetryCount = 0, double = 2, half = 0.5, squareExp = 2, randomString = "random";
|
|
18
17
|
function loadEffectData(effect, effectOptions, id, reduceDuplicates) {
|
|
19
18
|
const effectData = effectOptions.options[effect];
|
|
20
19
|
if (!effectData) {
|
|
@@ -39,7 +38,7 @@ function fixOutMode(data) {
|
|
|
39
38
|
if (!(0, Utils_js_1.isInArray)(data.outMode, data.checkModes)) {
|
|
40
39
|
return;
|
|
41
40
|
}
|
|
42
|
-
const diameter = data.radius * double;
|
|
41
|
+
const diameter = data.radius * Constants_js_1.double;
|
|
43
42
|
if (data.coord > data.maxCoord - diameter) {
|
|
44
43
|
data.setCb(-data.radius);
|
|
45
44
|
}
|
|
@@ -50,7 +49,7 @@ function fixOutMode(data) {
|
|
|
50
49
|
class Particle {
|
|
51
50
|
constructor(engine, container) {
|
|
52
51
|
this.container = container;
|
|
53
|
-
this._calcPosition = (container, position, zIndex, tryCount = defaultRetryCount) => {
|
|
52
|
+
this._calcPosition = (container, position, zIndex, tryCount = Constants_js_1.defaultRetryCount) => {
|
|
54
53
|
for (const plugin of container.plugins.values()) {
|
|
55
54
|
const pluginPos = plugin.particlePosition !== undefined ? plugin.particlePosition(position, this) : undefined;
|
|
56
55
|
if (pluginPos) {
|
|
@@ -84,8 +83,7 @@ class Particle {
|
|
|
84
83
|
fixVertical(outModes.top ?? outModes.default);
|
|
85
84
|
fixVertical(outModes.bottom ?? outModes.default);
|
|
86
85
|
if (this._checkOverlap(pos, tryCount)) {
|
|
87
|
-
|
|
88
|
-
return this._calcPosition(container, undefined, zIndex, tryCount + increment);
|
|
86
|
+
return this._calcPosition(container, undefined, zIndex, tryCount + Constants_js_1.tryCountIncrement);
|
|
89
87
|
}
|
|
90
88
|
return pos;
|
|
91
89
|
};
|
|
@@ -95,8 +93,8 @@ class Particle {
|
|
|
95
93
|
return res;
|
|
96
94
|
}
|
|
97
95
|
const rad = (0, NumberUtils_js_1.degToRad)((0, NumberUtils_js_1.getRangeValue)(moveOptions.angle.value)), radOffset = (0, NumberUtils_js_1.degToRad)((0, NumberUtils_js_1.getRangeValue)(moveOptions.angle.offset)), range = {
|
|
98
|
-
left: radOffset - rad * half,
|
|
99
|
-
right: radOffset + rad * half,
|
|
96
|
+
left: radOffset - rad * Constants_js_1.half,
|
|
97
|
+
right: radOffset + rad * Constants_js_1.half,
|
|
100
98
|
};
|
|
101
99
|
if (!moveOptions.straight) {
|
|
102
100
|
res.angle += (0, NumberUtils_js_1.randomInRange)((0, NumberUtils_js_1.setRangeValue)(range.left, range.right));
|
|
@@ -106,7 +104,7 @@ class Particle {
|
|
|
106
104
|
}
|
|
107
105
|
return res;
|
|
108
106
|
};
|
|
109
|
-
this._checkOverlap = (pos, tryCount = defaultRetryCount) => {
|
|
107
|
+
this._checkOverlap = (pos, tryCount = Constants_js_1.defaultRetryCount) => {
|
|
110
108
|
const collisionsOptions = this.options.collisions, radius = this.getRadius();
|
|
111
109
|
if (!collisionsOptions.enable) {
|
|
112
110
|
return false;
|
|
@@ -115,8 +113,8 @@ class Particle {
|
|
|
115
113
|
if (overlapOptions.enable) {
|
|
116
114
|
return false;
|
|
117
115
|
}
|
|
118
|
-
const retries = overlapOptions.retries
|
|
119
|
-
if (retries >= minRetries && tryCount > retries) {
|
|
116
|
+
const retries = overlapOptions.retries;
|
|
117
|
+
if (retries >= Constants_js_1.minRetries && tryCount > retries) {
|
|
120
118
|
throw new Error(`${Constants_js_1.errorPrefix} particle is overlapping and can't be placed`);
|
|
121
119
|
}
|
|
122
120
|
return !!this.container.particles.find(particle => (0, NumberUtils_js_1.getDistance)(pos, particle.position) < radius + particle.getRadius());
|
|
@@ -125,7 +123,7 @@ class Particle {
|
|
|
125
123
|
if (!color || !this.roll || (!this.backColor && !this.roll.alter)) {
|
|
126
124
|
return color;
|
|
127
125
|
}
|
|
128
|
-
const
|
|
126
|
+
const backFactor = this.roll.horizontal && this.roll.vertical ? Constants_js_1.double * Constants_js_1.rollFactor : Constants_js_1.rollFactor, backSum = this.roll.horizontal ? Math.PI * Constants_js_1.half : Constants_js_1.none, rolled = Math.floor(((this.roll.angle ?? Constants_js_1.none) + backSum) / (Math.PI / backFactor)) % Constants_js_1.double;
|
|
129
127
|
if (!rolled) {
|
|
130
128
|
return color;
|
|
131
129
|
}
|
|
@@ -138,13 +136,13 @@ class Particle {
|
|
|
138
136
|
return color;
|
|
139
137
|
};
|
|
140
138
|
this._initPosition = position => {
|
|
141
|
-
const container = this.container, zIndexValue = (0, NumberUtils_js_1.getRangeValue)(this.options.zIndex.value)
|
|
142
|
-
this.position = this._calcPosition(container, position, (0, NumberUtils_js_1.clamp)(zIndexValue, minZ, container.zLayers));
|
|
139
|
+
const container = this.container, zIndexValue = (0, NumberUtils_js_1.getRangeValue)(this.options.zIndex.value);
|
|
140
|
+
this.position = this._calcPosition(container, position, (0, NumberUtils_js_1.clamp)(zIndexValue, Constants_js_1.minZ, container.zLayers));
|
|
143
141
|
this.initialPosition = this.position.copy();
|
|
144
|
-
const canvasSize = container.canvas.size
|
|
142
|
+
const canvasSize = container.canvas.size;
|
|
145
143
|
this.moveCenter = {
|
|
146
144
|
...(0, Utils_js_1.getPosition)(this.options.move.center, canvasSize),
|
|
147
|
-
radius: this.options.move.center.radius ?? defaultRadius,
|
|
145
|
+
radius: this.options.move.center.radius ?? Constants_js_1.defaultRadius,
|
|
148
146
|
mode: this.options.move.center.mode ?? PixelMode_js_1.PixelMode.percent,
|
|
149
147
|
};
|
|
150
148
|
this.direction = (0, NumberUtils_js_1.getParticleDirectionAngle)(this.options.move.direction, this.position, this.moveCenter);
|
|
@@ -194,7 +192,7 @@ class Particle {
|
|
|
194
192
|
return this._getRollColor(this.bubble.color ?? (0, ColorUtils_js_1.getHslFromAnimation)(this.color));
|
|
195
193
|
}
|
|
196
194
|
getMass() {
|
|
197
|
-
return this.getRadius() ** squareExp * Math.PI * half;
|
|
195
|
+
return this.getRadius() ** Constants_js_1.squareExp * Math.PI * Constants_js_1.half;
|
|
198
196
|
}
|
|
199
197
|
getPosition() {
|
|
200
198
|
return {
|
|
@@ -249,11 +247,11 @@ class Particle {
|
|
|
249
247
|
}
|
|
250
248
|
}
|
|
251
249
|
}
|
|
252
|
-
if (this.effect ===
|
|
250
|
+
if (this.effect === Constants_js_1.randomColorValue) {
|
|
253
251
|
const availableEffects = [...this.container.effectDrawers.keys()];
|
|
254
252
|
this.effect = availableEffects[Math.floor(Math.random() * availableEffects.length)];
|
|
255
253
|
}
|
|
256
|
-
if (this.shape ===
|
|
254
|
+
if (this.shape === Constants_js_1.randomColorValue) {
|
|
257
255
|
const availableShapes = [...this.container.shapeDrawers.keys()];
|
|
258
256
|
this.shape = availableShapes[Math.floor(Math.random() * availableShapes.length)];
|
|
259
257
|
}
|
|
@@ -297,8 +295,7 @@ class Particle {
|
|
|
297
295
|
this._initPosition(position);
|
|
298
296
|
this.initialVelocity = this._calculateVelocity();
|
|
299
297
|
this.velocity = this.initialVelocity.copy();
|
|
300
|
-
|
|
301
|
-
this.moveDecay = decayOffset - (0, NumberUtils_js_1.getRangeValue)(this.options.move.decay);
|
|
298
|
+
this.moveDecay = Constants_js_1.decayOffset - (0, NumberUtils_js_1.getRangeValue)(this.options.move.decay);
|
|
302
299
|
const particles = container.particles;
|
|
303
300
|
particles.setLastZIndex(this.position.z);
|
|
304
301
|
this.zIndexFactor = this.position.z / container.zLayers;
|
package/cjs/Core/Particles.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Particles = void 0;
|
|
4
|
+
const Constants_js_1 = require("./Utils/Constants.js");
|
|
4
5
|
const Utils_js_1 = require("../Utils/Utils.js");
|
|
5
6
|
const EventType_js_1 = require("../Enums/Types/EventType.js");
|
|
6
7
|
const InteractionManager_js_1 = require("./Utils/InteractionManager.js");
|
|
@@ -9,11 +10,9 @@ const Particle_js_1 = require("./Particle.js");
|
|
|
9
10
|
const Point_js_1 = require("./Utils/Point.js");
|
|
10
11
|
const QuadTree_js_1 = require("./Utils/QuadTree.js");
|
|
11
12
|
const Ranges_js_1 = require("./Utils/Ranges.js");
|
|
12
|
-
const Constants_js_1 = require("./Utils/Constants.js");
|
|
13
|
-
const qTreeCapacity = 4, squareExp = 2, defaultRemoveQuantity = 1;
|
|
14
13
|
const qTreeRectangle = (canvasSize) => {
|
|
15
|
-
const { height, width } = canvasSize
|
|
16
|
-
return new Ranges_js_1.Rectangle(posOffset * width, posOffset * height, sizeFactor * width, sizeFactor * height);
|
|
14
|
+
const { height, width } = canvasSize;
|
|
15
|
+
return new Ranges_js_1.Rectangle(Constants_js_1.posOffset * width, Constants_js_1.posOffset * height, Constants_js_1.sizeFactor * width, Constants_js_1.sizeFactor * height);
|
|
17
16
|
};
|
|
18
17
|
class Particles {
|
|
19
18
|
constructor(engine, container) {
|
|
@@ -31,7 +30,7 @@ class Particles {
|
|
|
31
30
|
}
|
|
32
31
|
return;
|
|
33
32
|
}
|
|
34
|
-
const densityFactor = this._initDensityFactor(numberOptions.density), optParticlesNumber = numberOptions.value,
|
|
33
|
+
const densityFactor = this._initDensityFactor(numberOptions.density), optParticlesNumber = numberOptions.value, optParticlesLimit = numberOptions.limit.value > Constants_js_1.minLimit ? numberOptions.limit.value : optParticlesNumber, particlesNumber = Math.min(optParticlesNumber, optParticlesLimit) * densityFactor + manualCount, particlesCount = Math.min(this.count, this.filter(t => t.group === group).length);
|
|
35
34
|
if (group === undefined) {
|
|
36
35
|
this._limit = numberOptions.limit.value * densityFactor;
|
|
37
36
|
}
|
|
@@ -46,12 +45,12 @@ class Particles {
|
|
|
46
45
|
}
|
|
47
46
|
};
|
|
48
47
|
this._initDensityFactor = densityOptions => {
|
|
49
|
-
const container = this._container
|
|
48
|
+
const container = this._container;
|
|
50
49
|
if (!container.canvas.element || !densityOptions.enable) {
|
|
51
|
-
return
|
|
50
|
+
return Constants_js_1.defaultDensityFactor;
|
|
52
51
|
}
|
|
53
52
|
const canvas = container.canvas.element, pxRatio = container.retina.pixelRatio;
|
|
54
|
-
return (canvas.width * canvas.height) / (densityOptions.height * densityOptions.width * pxRatio ** squareExp);
|
|
53
|
+
return (canvas.width * canvas.height) / (densityOptions.height * densityOptions.width * pxRatio ** Constants_js_1.squareExp);
|
|
55
54
|
};
|
|
56
55
|
this._pushParticle = (position, overrideOptions, group, initializer) => {
|
|
57
56
|
try {
|
|
@@ -87,9 +86,9 @@ class Particles {
|
|
|
87
86
|
if (!particle || particle.group !== group) {
|
|
88
87
|
return false;
|
|
89
88
|
}
|
|
90
|
-
const zIdx = this._zArray.indexOf(particle)
|
|
91
|
-
this._array.splice(index, deleteCount);
|
|
92
|
-
this._zArray.splice(zIdx, deleteCount);
|
|
89
|
+
const zIdx = this._zArray.indexOf(particle);
|
|
90
|
+
this._array.splice(index, Constants_js_1.deleteCount);
|
|
91
|
+
this._zArray.splice(zIdx, Constants_js_1.deleteCount);
|
|
93
92
|
particle.destroy(override);
|
|
94
93
|
this._engine.dispatchEvent(EventType_js_1.EventType.particleRemoved, {
|
|
95
94
|
container: this._container,
|
|
@@ -113,7 +112,7 @@ class Particles {
|
|
|
113
112
|
this._interactionManager = new InteractionManager_js_1.InteractionManager(engine, container);
|
|
114
113
|
this._pluginsInitialized = false;
|
|
115
114
|
const canvasSize = container.canvas.size;
|
|
116
|
-
this.quadTree = new QuadTree_js_1.QuadTree(qTreeRectangle(canvasSize), qTreeCapacity);
|
|
115
|
+
this.quadTree = new QuadTree_js_1.QuadTree(qTreeRectangle(canvasSize), Constants_js_1.qTreeCapacity);
|
|
117
116
|
this.movers = [];
|
|
118
117
|
this.updaters = [];
|
|
119
118
|
}
|
|
@@ -125,12 +124,12 @@ class Particles {
|
|
|
125
124
|
options.manualParticles.forEach(p => this.addParticle(p.position ? (0, Utils_js_1.getPosition)(p.position, container.canvas.size) : undefined, p.options));
|
|
126
125
|
}
|
|
127
126
|
addParticle(position, overrideOptions, group, initializer) {
|
|
128
|
-
const limitMode = this._container.actualOptions.particles.number.limit.mode, limit = group === undefined ? this._limit : (this._groupLimits.get(group) ?? this._limit), currentCount = this.count
|
|
129
|
-
if (limit > minLimit) {
|
|
127
|
+
const limitMode = this._container.actualOptions.particles.number.limit.mode, limit = group === undefined ? this._limit : (this._groupLimits.get(group) ?? this._limit), currentCount = this.count;
|
|
128
|
+
if (limit > Constants_js_1.minLimit) {
|
|
130
129
|
switch (limitMode) {
|
|
131
130
|
case LimitMode_js_1.LimitMode.delete: {
|
|
132
|
-
const
|
|
133
|
-
if (countToRemove > minCount) {
|
|
131
|
+
const countToRemove = currentCount + Constants_js_1.countOffset - limit;
|
|
132
|
+
if (countToRemove > Constants_js_1.minCount) {
|
|
134
133
|
this.removeQuantity(countToRemove);
|
|
135
134
|
}
|
|
136
135
|
break;
|
|
@@ -229,9 +228,8 @@ class Particles {
|
|
|
229
228
|
remove(particle, group, override) {
|
|
230
229
|
this.removeAt(this._array.indexOf(particle), undefined, group, override);
|
|
231
230
|
}
|
|
232
|
-
removeAt(index, quantity = defaultRemoveQuantity, group, override) {
|
|
233
|
-
|
|
234
|
-
if (index < minIndex || index > this.count) {
|
|
231
|
+
removeAt(index, quantity = Constants_js_1.defaultRemoveQuantity, group, override) {
|
|
232
|
+
if (index < Constants_js_1.minIndex || index > this.count) {
|
|
235
233
|
return;
|
|
236
234
|
}
|
|
237
235
|
let deleted = 0;
|
|
@@ -243,13 +241,12 @@ class Particles {
|
|
|
243
241
|
}
|
|
244
242
|
}
|
|
245
243
|
removeQuantity(quantity, group) {
|
|
246
|
-
|
|
247
|
-
this.removeAt(defaultIndex, quantity, group);
|
|
244
|
+
this.removeAt(Constants_js_1.minIndex, quantity, group);
|
|
248
245
|
}
|
|
249
246
|
setDensity() {
|
|
250
|
-
const options = this._container.actualOptions, groups = options.particles.groups
|
|
247
|
+
const options = this._container.actualOptions, groups = options.particles.groups;
|
|
251
248
|
for (const group in groups) {
|
|
252
|
-
this._applyDensity(groups[group], manualCount, group);
|
|
249
|
+
this._applyDensity(groups[group], Constants_js_1.manualCount, group);
|
|
253
250
|
}
|
|
254
251
|
this._applyDensity(options.particles, options.manualParticles.length);
|
|
255
252
|
}
|
|
@@ -262,7 +259,7 @@ class Particles {
|
|
|
262
259
|
}
|
|
263
260
|
update(delta) {
|
|
264
261
|
const container = this._container, particlesToDelete = new Set();
|
|
265
|
-
this.quadTree = new QuadTree_js_1.QuadTree(qTreeRectangle(container.canvas.size), qTreeCapacity);
|
|
262
|
+
this.quadTree = new QuadTree_js_1.QuadTree(qTreeRectangle(container.canvas.size), Constants_js_1.qTreeCapacity);
|
|
266
263
|
for (const pathGenerator of container.pathGenerators.values()) {
|
|
267
264
|
pathGenerator.update();
|
|
268
265
|
}
|
|
@@ -323,8 +320,7 @@ class Particles {
|
|
|
323
320
|
if (this._needsSort) {
|
|
324
321
|
const zArray = this._zArray;
|
|
325
322
|
zArray.sort((a, b) => b.position.z - a.position.z || a.id - b.id);
|
|
326
|
-
|
|
327
|
-
this._lastZIndex = zArray[zArray.length - lengthOffset].position.z;
|
|
323
|
+
this._lastZIndex = zArray[zArray.length - Constants_js_1.lengthOffset].position.z;
|
|
328
324
|
this._needsSort = false;
|
|
329
325
|
}
|
|
330
326
|
}
|
package/cjs/Core/Retina.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Retina = void 0;
|
|
4
|
+
const Constants_js_1 = require("./Utils/Constants.js");
|
|
4
5
|
const NumberUtils_js_1 = require("../Utils/NumberUtils.js");
|
|
5
6
|
const Utils_js_1 = require("../Utils/Utils.js");
|
|
6
|
-
const defaultRatio = 1, defaultReduceFactor = 1;
|
|
7
7
|
class Retina {
|
|
8
8
|
constructor(container) {
|
|
9
9
|
this.container = container;
|
|
10
|
-
this.pixelRatio = defaultRatio;
|
|
11
|
-
this.reduceFactor = defaultReduceFactor;
|
|
10
|
+
this.pixelRatio = Constants_js_1.defaultRatio;
|
|
11
|
+
this.reduceFactor = Constants_js_1.defaultReduceFactor;
|
|
12
12
|
}
|
|
13
13
|
init() {
|
|
14
14
|
const container = this.container, options = container.actualOptions;
|
|
15
|
-
this.pixelRatio = !options.detectRetina || (0, Utils_js_1.isSsr)() ? defaultRatio : window.devicePixelRatio;
|
|
16
|
-
this.reduceFactor = defaultReduceFactor;
|
|
15
|
+
this.pixelRatio = !options.detectRetina || (0, Utils_js_1.isSsr)() ? Constants_js_1.defaultRatio : window.devicePixelRatio;
|
|
16
|
+
this.reduceFactor = Constants_js_1.defaultReduceFactor;
|
|
17
17
|
const ratio = this.pixelRatio, canvas = container.canvas;
|
|
18
18
|
if (canvas.element) {
|
|
19
19
|
const element = canvas.element;
|
|
@@ -1,19 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.millisecondsToSeconds = exports.
|
|
4
|
-
exports.
|
|
5
|
-
exports.mouseDownEvent = "pointerdown"
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
exports.
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
exports.
|
|
15
|
-
exports.visibilityChangeEvent = "visibilitychange";
|
|
16
|
-
exports.errorPrefix = "tsParticles - Error";
|
|
17
|
-
exports.percentDenominator = 100;
|
|
18
|
-
exports.halfRandom = 0.5;
|
|
19
|
-
exports.millisecondsToSeconds = 1000;
|
|
3
|
+
exports.zIndexFactorOffset = exports.minimumLength = exports.minimumSize = exports.defaultTransformValue = exports.minVelocity = exports.threeQuarter = exports.quarter = exports.empty = exports.hPhase = exports.sMin = exports.hMin = exports.lMax = exports.sMax = exports.hMax = exports.rgbMax = exports.inverseFactorNumerator = exports.subdivideCount = exports.defaultReduceFactor = exports.defaultRatio = exports.defaultRemoveQuantity = exports.qTreeCapacity = exports.squareExp = exports.defaultRetryCount = exports.canvasTag = exports.generatedFalse = exports.generatedTrue = exports.defaultAlpha = exports.defaultFps = exports.doublePI = exports.double = exports.midColorValue = exports.randomColorValue = exports.defaultTransform = exports.originPoint = exports.millisecondsToSeconds = exports.half = exports.percentDenominator = exports.errorPrefix = exports.visibilityChangeEvent = exports.resizeEvent = exports.touchCancelEvent = exports.touchMoveEvent = exports.touchEndEvent = exports.touchStartEvent = exports.mouseMoveEvent = exports.mouseOutEvent = exports.mouseLeaveEvent = exports.mouseUpEvent = exports.mouseDownEvent = exports.generatedAttribute = void 0;
|
|
4
|
+
exports.defaultTime = exports.defaultLoops = exports.defaultVelocity = exports.defaultRgbMin = exports.phaseNumerator = exports.sNormalizedOffset = exports.sextuple = exports.triple = exports.rgbFactor = exports.lMin = exports.lFactor = exports.minStrokeWidth = exports.identity = exports.defaultAngle = exports.manualDefaultPosition = exports.touchDelay = exports.deleteCount = exports.defaultDensityFactor = exports.lengthOffset = exports.manualCount = exports.minIndex = exports.minCount = exports.countOffset = exports.minLimit = exports.sizeFactor = exports.posOffset = exports.defaultRadius = exports.minZ = exports.rollFactor = exports.minRetries = exports.tryCountIncrement = exports.decayOffset = exports.none = exports.one = exports.loadMinIndex = exports.loadRandomFactor = exports.canvasFirstIndex = exports.minFpsLimit = exports.defaultFpsLimit = exports.removeMinIndex = exports.removeDeleteCount = exports.minCoordinate = exports.touchEndLengthOffset = exports.clickRadius = exports.defaultOpacity = void 0;
|
|
5
|
+
exports.generatedAttribute = "generated", exports.mouseDownEvent = "pointerdown", exports.mouseUpEvent = "pointerup", exports.mouseLeaveEvent = "pointerleave", exports.mouseOutEvent = "pointerout", exports.mouseMoveEvent = "pointermove", exports.touchStartEvent = "touchstart", exports.touchEndEvent = "touchend", exports.touchMoveEvent = "touchmove", exports.touchCancelEvent = "touchcancel", exports.resizeEvent = "resize", exports.visibilityChangeEvent = "visibilitychange", exports.errorPrefix = "tsParticles - Error", exports.percentDenominator = 100, exports.half = 0.5, exports.millisecondsToSeconds = 1000, exports.originPoint = {
|
|
6
|
+
x: 0,
|
|
7
|
+
y: 0,
|
|
8
|
+
z: 0,
|
|
9
|
+
}, exports.defaultTransform = {
|
|
10
|
+
a: 1,
|
|
11
|
+
b: 0,
|
|
12
|
+
c: 0,
|
|
13
|
+
d: 1,
|
|
14
|
+
}, exports.randomColorValue = "random", exports.midColorValue = "mid", exports.double = 2, exports.doublePI = Math.PI * exports.double, exports.defaultFps = 60, exports.defaultAlpha = 1, exports.generatedTrue = "true", exports.generatedFalse = "false", exports.canvasTag = "canvas", exports.defaultRetryCount = 0, exports.squareExp = 2, exports.qTreeCapacity = 4, exports.defaultRemoveQuantity = 1, exports.defaultRatio = 1, exports.defaultReduceFactor = 1, exports.subdivideCount = 4, exports.inverseFactorNumerator = 1.0, exports.rgbMax = 255, exports.hMax = 360, exports.sMax = 100, exports.lMax = 100, exports.hMin = 0, exports.sMin = 0, exports.hPhase = 60, exports.empty = 0, exports.quarter = 0.25, exports.threeQuarter = exports.half + exports.quarter, exports.minVelocity = 0, exports.defaultTransformValue = 1, exports.minimumSize = 0, exports.minimumLength = 0, exports.zIndexFactorOffset = 1, exports.defaultOpacity = 1, exports.clickRadius = 1, exports.touchEndLengthOffset = 1, exports.minCoordinate = 0, exports.removeDeleteCount = 1, exports.removeMinIndex = 0, exports.defaultFpsLimit = 120, exports.minFpsLimit = 0, exports.canvasFirstIndex = 0, exports.loadRandomFactor = 10000, exports.loadMinIndex = 0, exports.one = 1, exports.none = 0, exports.decayOffset = 1, exports.tryCountIncrement = 1, exports.minRetries = 0, exports.rollFactor = 1, exports.minZ = 0, exports.defaultRadius = 0, exports.posOffset = -exports.quarter, exports.sizeFactor = 1.5, exports.minLimit = 0, exports.countOffset = 1, exports.minCount = 0, exports.minIndex = 0, exports.manualCount = 0, exports.lengthOffset = 1, exports.defaultDensityFactor = 1, exports.deleteCount = 1, exports.touchDelay = 500, exports.manualDefaultPosition = 50, exports.defaultAngle = 0, exports.identity = 1, exports.minStrokeWidth = 0, exports.lFactor = 1, exports.lMin = 0, exports.rgbFactor = 255, exports.triple = 3, exports.sextuple = 6, exports.sNormalizedOffset = 1, exports.phaseNumerator = 1, exports.defaultRgbMin = 0, exports.defaultVelocity = 0, exports.defaultLoops = 0, exports.defaultTime = 0;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.EventListeners = void 0;
|
|
4
|
-
const Utils_js_1 = require("../../Utils/Utils.js");
|
|
5
4
|
const Constants_js_1 = require("./Constants.js");
|
|
5
|
+
const Utils_js_1 = require("../../Utils/Utils.js");
|
|
6
6
|
const InteractivityDetect_js_1 = require("../../Enums/InteractivityDetect.js");
|
|
7
7
|
const TypeUtils_js_1 = require("../../Utils/TypeUtils.js");
|
|
8
|
-
const double = 2;
|
|
9
8
|
function manageListener(element, event, handler, add, options) {
|
|
10
9
|
if (add) {
|
|
11
10
|
let addOptions = { passive: true };
|
|
@@ -38,8 +37,7 @@ class EventListeners {
|
|
|
38
37
|
(0, Utils_js_1.executeOnSingleOrMultiple)(onClick.mode, mode => this.container.handleClickMode(mode));
|
|
39
38
|
}
|
|
40
39
|
if (e.type === "touchend") {
|
|
41
|
-
|
|
42
|
-
setTimeout(() => this._mouseTouchFinish(), touchDelay);
|
|
40
|
+
setTimeout(() => this._mouseTouchFinish(), Constants_js_1.touchDelay);
|
|
43
41
|
}
|
|
44
42
|
};
|
|
45
43
|
this._handleThemeChange = (e) => {
|
|
@@ -80,8 +78,7 @@ class EventListeners {
|
|
|
80
78
|
this._resizeTimeout = setTimeout(() => void handleResize(), this.container.actualOptions.interactivity.events.resize.delay * Constants_js_1.millisecondsToSeconds);
|
|
81
79
|
};
|
|
82
80
|
this._manageInteractivityListeners = (mouseLeaveTmpEvent, add) => {
|
|
83
|
-
const handlers = this._handlers, container = this.container, options = container.actualOptions;
|
|
84
|
-
const interactivityEl = container.interactivity.element;
|
|
81
|
+
const handlers = this._handlers, container = this.container, options = container.actualOptions, interactivityEl = container.interactivity.element;
|
|
85
82
|
if (!interactivityEl) {
|
|
86
83
|
return;
|
|
87
84
|
}
|
|
@@ -241,8 +238,8 @@ class EventListeners {
|
|
|
241
238
|
if (source && target && canvasEl) {
|
|
242
239
|
const sourceRect = source.getBoundingClientRect(), targetRect = target.getBoundingClientRect(), canvasRect = canvasEl.getBoundingClientRect();
|
|
243
240
|
pos = {
|
|
244
|
-
x: mouseEvent.offsetX + double * sourceRect.left - (targetRect.left + canvasRect.left),
|
|
245
|
-
y: mouseEvent.offsetY + double * sourceRect.top - (targetRect.top + canvasRect.top),
|
|
241
|
+
x: mouseEvent.offsetX + Constants_js_1.double * sourceRect.left - (targetRect.left + canvasRect.left),
|
|
242
|
+
y: mouseEvent.offsetY + Constants_js_1.double * sourceRect.top - (targetRect.top + canvasRect.top),
|
|
246
243
|
};
|
|
247
244
|
}
|
|
248
245
|
else {
|
|
@@ -262,10 +259,10 @@ class EventListeners {
|
|
|
262
259
|
else {
|
|
263
260
|
this._canPush = e.type !== "touchmove";
|
|
264
261
|
if (canvasEl) {
|
|
265
|
-
const touchEvent = e,
|
|
262
|
+
const touchEvent = e, lastTouch = touchEvent.touches[touchEvent.touches.length - Constants_js_1.lengthOffset], canvasRect = canvasEl.getBoundingClientRect();
|
|
266
263
|
pos = {
|
|
267
|
-
x: lastTouch.clientX - (canvasRect.left ??
|
|
268
|
-
y: lastTouch.clientY - (canvasRect.top ??
|
|
264
|
+
x: lastTouch.clientX - (canvasRect.left ?? Constants_js_1.minCoordinate),
|
|
265
|
+
y: lastTouch.clientY - (canvasRect.top ?? Constants_js_1.minCoordinate),
|
|
269
266
|
};
|
|
270
267
|
}
|
|
271
268
|
}
|
|
@@ -2,17 +2,17 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.QuadTree = void 0;
|
|
4
4
|
const Ranges_js_1 = require("./Ranges.js");
|
|
5
|
+
const Constants_js_1 = require("./Constants.js");
|
|
5
6
|
const NumberUtils_js_1 = require("../../Utils/NumberUtils.js");
|
|
6
|
-
const half = 0.5, double = 2, subdivideCount = 4;
|
|
7
7
|
class QuadTree {
|
|
8
8
|
constructor(rectangle, capacity) {
|
|
9
9
|
this.rectangle = rectangle;
|
|
10
10
|
this.capacity = capacity;
|
|
11
11
|
this._subdivide = () => {
|
|
12
12
|
const { x, y } = this.rectangle.position, { width, height } = this.rectangle.size, { capacity } = this;
|
|
13
|
-
for (let i = 0; i < subdivideCount; i++) {
|
|
14
|
-
const fixedIndex = i % double;
|
|
15
|
-
this._subs.push(new QuadTree(new Ranges_js_1.Rectangle(x + width * half * fixedIndex, y + height * half * (Math.round(i * half) - fixedIndex), width * half, height * half), capacity));
|
|
13
|
+
for (let i = 0; i < Constants_js_1.subdivideCount; i++) {
|
|
14
|
+
const fixedIndex = i % Constants_js_1.double;
|
|
15
|
+
this._subs.push(new QuadTree(new Ranges_js_1.Rectangle(x + width * Constants_js_1.half * fixedIndex, y + height * Constants_js_1.half * (Math.round(i * Constants_js_1.half) - fixedIndex), width * Constants_js_1.half, height * Constants_js_1.half), capacity));
|
|
16
16
|
}
|
|
17
17
|
this._divided = true;
|
|
18
18
|
};
|
package/cjs/Core/Utils/Ranges.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Rectangle = exports.Circle = exports.BaseRange = void 0;
|
|
4
4
|
const RangeType_js_1 = require("../../Types/RangeType.js");
|
|
5
5
|
const NumberUtils_js_1 = require("../../Utils/NumberUtils.js");
|
|
6
|
-
const
|
|
6
|
+
const Constants_js_1 = require("./Constants.js");
|
|
7
7
|
class BaseRange {
|
|
8
8
|
constructor(x, y, type) {
|
|
9
9
|
this.position = {
|
|
@@ -25,12 +25,12 @@ class Circle extends BaseRange {
|
|
|
25
25
|
intersects(range) {
|
|
26
26
|
const pos1 = this.position, pos2 = range.position, distPos = { x: Math.abs(pos2.x - pos1.x), y: Math.abs(pos2.y - pos1.y) }, r = this.radius;
|
|
27
27
|
if (range instanceof Circle || range.type === RangeType_js_1.RangeType.circle) {
|
|
28
|
-
const circleRange = range, rSum = r + circleRange.radius, dist = Math.sqrt(distPos.x ** squareExp + distPos.y ** squareExp);
|
|
28
|
+
const circleRange = range, rSum = r + circleRange.radius, dist = Math.sqrt(distPos.x ** Constants_js_1.squareExp + distPos.y ** Constants_js_1.squareExp);
|
|
29
29
|
return rSum > dist;
|
|
30
30
|
}
|
|
31
31
|
else if (range instanceof Rectangle || range.type === RangeType_js_1.RangeType.rectangle) {
|
|
32
|
-
const rectRange = range, { width, height } = rectRange.size, edges = Math.pow(distPos.x - width, squareExp) + Math.pow(distPos.y - height, squareExp);
|
|
33
|
-
return (edges <= r ** squareExp ||
|
|
32
|
+
const rectRange = range, { width, height } = rectRange.size, edges = Math.pow(distPos.x - width, Constants_js_1.squareExp) + Math.pow(distPos.y - height, Constants_js_1.squareExp);
|
|
33
|
+
return (edges <= r ** Constants_js_1.squareExp ||
|
|
34
34
|
(distPos.x <= r + width && distPos.y <= r + height) ||
|
|
35
35
|
distPos.x <= width ||
|
|
36
36
|
distPos.y <= height);
|