microboard-temp 0.12.3 → 0.12.4
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/dist/cjs/browser.js +39 -33
- package/dist/cjs/index.js +39 -33
- package/dist/cjs/node.js +39 -33
- package/dist/esm/browser.js +39 -33
- package/dist/esm/index.js +39 -33
- package/dist/esm/node.js +39 -33
- package/package.json +1 -1
package/dist/cjs/browser.js
CHANGED
|
@@ -54345,52 +54345,58 @@ class GravityEngine {
|
|
|
54345
54345
|
const items = this.board.items.listAll().filter((item) => !item.transformation.isLocked && !EXCLUDED_ITEM_TYPES.has(item.itemType));
|
|
54346
54346
|
if (items.length < 1)
|
|
54347
54347
|
return;
|
|
54348
|
+
const snapshot = items.map((item) => {
|
|
54349
|
+
const pos = item.transformation.getTranslation();
|
|
54350
|
+
const mbr = item.getMbr();
|
|
54351
|
+
const w = Math.max(mbr.getWidth(), 1);
|
|
54352
|
+
const h2 = Math.max(mbr.getHeight(), 1);
|
|
54353
|
+
return {
|
|
54354
|
+
id: item.getId(),
|
|
54355
|
+
cx: pos.x + w * 0.5,
|
|
54356
|
+
cy: pos.y + h2 * 0.5,
|
|
54357
|
+
w,
|
|
54358
|
+
h: h2,
|
|
54359
|
+
mass: w * h2
|
|
54360
|
+
};
|
|
54361
|
+
});
|
|
54348
54362
|
let sumX = 0;
|
|
54349
54363
|
let sumY = 0;
|
|
54350
|
-
for (const
|
|
54351
|
-
|
|
54352
|
-
|
|
54353
|
-
|
|
54354
|
-
|
|
54355
|
-
const
|
|
54356
|
-
|
|
54357
|
-
|
|
54358
|
-
|
|
54359
|
-
|
|
54360
|
-
|
|
54361
|
-
|
|
54362
|
-
const vel = this.velocities.get(id);
|
|
54363
|
-
const mbr1 = item.getMbr();
|
|
54364
|
-
const w1 = mbr1.getWidth();
|
|
54365
|
-
const h1 = mbr1.getHeight();
|
|
54364
|
+
for (const s2 of snapshot) {
|
|
54365
|
+
sumX += s2.cx;
|
|
54366
|
+
sumY += s2.cy;
|
|
54367
|
+
}
|
|
54368
|
+
const centerX = sumX / snapshot.length;
|
|
54369
|
+
const centerY = sumY / snapshot.length;
|
|
54370
|
+
for (let i = 0;i < snapshot.length; i++) {
|
|
54371
|
+
const s1 = snapshot[i];
|
|
54372
|
+
if (!this.velocities.has(s1.id)) {
|
|
54373
|
+
this.velocities.set(s1.id, { vx: 0, vy: 0 });
|
|
54374
|
+
}
|
|
54375
|
+
const vel = this.velocities.get(s1.id);
|
|
54366
54376
|
let ax = 0;
|
|
54367
54377
|
let ay = 0;
|
|
54368
|
-
const
|
|
54369
|
-
const
|
|
54370
|
-
const dcx = centerX - cx1;
|
|
54371
|
-
const dcy = centerY - cy1;
|
|
54378
|
+
const dcx = centerX - s1.cx;
|
|
54379
|
+
const dcy = centerY - s1.cy;
|
|
54372
54380
|
const distCenter = Math.sqrt(dcx * dcx + dcy * dcy) + 1;
|
|
54373
54381
|
ax += this.G_CENTER * dcx / distCenter;
|
|
54374
54382
|
ay += this.G_CENTER * dcy / distCenter;
|
|
54375
|
-
|
|
54376
|
-
|
|
54377
|
-
|
|
54378
|
-
const
|
|
54379
|
-
const
|
|
54380
|
-
const
|
|
54381
|
-
const cx2 = mbr2.left + w2 * 0.5;
|
|
54382
|
-
const cy2 = mbr2.top + h2 * 0.5;
|
|
54383
|
-
const dx = cx2 - cx1;
|
|
54384
|
-
const dy = cy2 - cy1;
|
|
54383
|
+
for (let j = 0;j < snapshot.length; j++) {
|
|
54384
|
+
if (i === j)
|
|
54385
|
+
continue;
|
|
54386
|
+
const s2 = snapshot[j];
|
|
54387
|
+
const dx = s2.cx - s1.cx;
|
|
54388
|
+
const dy = s2.cy - s1.cy;
|
|
54385
54389
|
const distSq = dx * dx + dy * dy;
|
|
54386
54390
|
const dist = Math.sqrt(distSq) + 0.001;
|
|
54387
|
-
|
|
54391
|
+
if (dist > this.MAX_DISTANCE)
|
|
54392
|
+
continue;
|
|
54393
|
+
const minDist = (s1.w + s2.w + s1.h + s2.h) * 0.25;
|
|
54388
54394
|
if (dist < minDist) {
|
|
54389
54395
|
const repAcc = this.REPULSION / (distSq + this.SOFTENING_SQ);
|
|
54390
54396
|
ax -= repAcc * dx / dist;
|
|
54391
54397
|
ay -= repAcc * dy / dist;
|
|
54392
54398
|
} else {
|
|
54393
|
-
const gravAcc = this.G *
|
|
54399
|
+
const gravAcc = this.G * s2.mass / (distSq + this.SOFTENING_SQ);
|
|
54394
54400
|
ax += gravAcc * dx / dist;
|
|
54395
54401
|
ay += gravAcc * dy / dist;
|
|
54396
54402
|
}
|
|
@@ -54400,7 +54406,7 @@ class GravityEngine {
|
|
|
54400
54406
|
const moveX = vel.vx * dt;
|
|
54401
54407
|
const moveY = vel.vy * dt;
|
|
54402
54408
|
if (Math.abs(moveX) >= this.MIN_MOVE_PX || Math.abs(moveY) >= this.MIN_MOVE_PX) {
|
|
54403
|
-
|
|
54409
|
+
items[i].transformation.applyMatrixSilent({
|
|
54404
54410
|
translateX: moveX,
|
|
54405
54411
|
translateY: moveY,
|
|
54406
54412
|
scaleX: 1,
|
package/dist/cjs/index.js
CHANGED
|
@@ -54345,52 +54345,58 @@ class GravityEngine {
|
|
|
54345
54345
|
const items = this.board.items.listAll().filter((item) => !item.transformation.isLocked && !EXCLUDED_ITEM_TYPES.has(item.itemType));
|
|
54346
54346
|
if (items.length < 1)
|
|
54347
54347
|
return;
|
|
54348
|
+
const snapshot = items.map((item) => {
|
|
54349
|
+
const pos = item.transformation.getTranslation();
|
|
54350
|
+
const mbr = item.getMbr();
|
|
54351
|
+
const w = Math.max(mbr.getWidth(), 1);
|
|
54352
|
+
const h2 = Math.max(mbr.getHeight(), 1);
|
|
54353
|
+
return {
|
|
54354
|
+
id: item.getId(),
|
|
54355
|
+
cx: pos.x + w * 0.5,
|
|
54356
|
+
cy: pos.y + h2 * 0.5,
|
|
54357
|
+
w,
|
|
54358
|
+
h: h2,
|
|
54359
|
+
mass: w * h2
|
|
54360
|
+
};
|
|
54361
|
+
});
|
|
54348
54362
|
let sumX = 0;
|
|
54349
54363
|
let sumY = 0;
|
|
54350
|
-
for (const
|
|
54351
|
-
|
|
54352
|
-
|
|
54353
|
-
|
|
54354
|
-
|
|
54355
|
-
const
|
|
54356
|
-
|
|
54357
|
-
|
|
54358
|
-
|
|
54359
|
-
|
|
54360
|
-
|
|
54361
|
-
|
|
54362
|
-
const vel = this.velocities.get(id);
|
|
54363
|
-
const mbr1 = item.getMbr();
|
|
54364
|
-
const w1 = mbr1.getWidth();
|
|
54365
|
-
const h1 = mbr1.getHeight();
|
|
54364
|
+
for (const s2 of snapshot) {
|
|
54365
|
+
sumX += s2.cx;
|
|
54366
|
+
sumY += s2.cy;
|
|
54367
|
+
}
|
|
54368
|
+
const centerX = sumX / snapshot.length;
|
|
54369
|
+
const centerY = sumY / snapshot.length;
|
|
54370
|
+
for (let i = 0;i < snapshot.length; i++) {
|
|
54371
|
+
const s1 = snapshot[i];
|
|
54372
|
+
if (!this.velocities.has(s1.id)) {
|
|
54373
|
+
this.velocities.set(s1.id, { vx: 0, vy: 0 });
|
|
54374
|
+
}
|
|
54375
|
+
const vel = this.velocities.get(s1.id);
|
|
54366
54376
|
let ax = 0;
|
|
54367
54377
|
let ay = 0;
|
|
54368
|
-
const
|
|
54369
|
-
const
|
|
54370
|
-
const dcx = centerX - cx1;
|
|
54371
|
-
const dcy = centerY - cy1;
|
|
54378
|
+
const dcx = centerX - s1.cx;
|
|
54379
|
+
const dcy = centerY - s1.cy;
|
|
54372
54380
|
const distCenter = Math.sqrt(dcx * dcx + dcy * dcy) + 1;
|
|
54373
54381
|
ax += this.G_CENTER * dcx / distCenter;
|
|
54374
54382
|
ay += this.G_CENTER * dcy / distCenter;
|
|
54375
|
-
|
|
54376
|
-
|
|
54377
|
-
|
|
54378
|
-
const
|
|
54379
|
-
const
|
|
54380
|
-
const
|
|
54381
|
-
const cx2 = mbr2.left + w2 * 0.5;
|
|
54382
|
-
const cy2 = mbr2.top + h2 * 0.5;
|
|
54383
|
-
const dx = cx2 - cx1;
|
|
54384
|
-
const dy = cy2 - cy1;
|
|
54383
|
+
for (let j = 0;j < snapshot.length; j++) {
|
|
54384
|
+
if (i === j)
|
|
54385
|
+
continue;
|
|
54386
|
+
const s2 = snapshot[j];
|
|
54387
|
+
const dx = s2.cx - s1.cx;
|
|
54388
|
+
const dy = s2.cy - s1.cy;
|
|
54385
54389
|
const distSq = dx * dx + dy * dy;
|
|
54386
54390
|
const dist = Math.sqrt(distSq) + 0.001;
|
|
54387
|
-
|
|
54391
|
+
if (dist > this.MAX_DISTANCE)
|
|
54392
|
+
continue;
|
|
54393
|
+
const minDist = (s1.w + s2.w + s1.h + s2.h) * 0.25;
|
|
54388
54394
|
if (dist < minDist) {
|
|
54389
54395
|
const repAcc = this.REPULSION / (distSq + this.SOFTENING_SQ);
|
|
54390
54396
|
ax -= repAcc * dx / dist;
|
|
54391
54397
|
ay -= repAcc * dy / dist;
|
|
54392
54398
|
} else {
|
|
54393
|
-
const gravAcc = this.G *
|
|
54399
|
+
const gravAcc = this.G * s2.mass / (distSq + this.SOFTENING_SQ);
|
|
54394
54400
|
ax += gravAcc * dx / dist;
|
|
54395
54401
|
ay += gravAcc * dy / dist;
|
|
54396
54402
|
}
|
|
@@ -54400,7 +54406,7 @@ class GravityEngine {
|
|
|
54400
54406
|
const moveX = vel.vx * dt;
|
|
54401
54407
|
const moveY = vel.vy * dt;
|
|
54402
54408
|
if (Math.abs(moveX) >= this.MIN_MOVE_PX || Math.abs(moveY) >= this.MIN_MOVE_PX) {
|
|
54403
|
-
|
|
54409
|
+
items[i].transformation.applyMatrixSilent({
|
|
54404
54410
|
translateX: moveX,
|
|
54405
54411
|
translateY: moveY,
|
|
54406
54412
|
scaleX: 1,
|
package/dist/cjs/node.js
CHANGED
|
@@ -56818,52 +56818,58 @@ class GravityEngine {
|
|
|
56818
56818
|
const items = this.board.items.listAll().filter((item) => !item.transformation.isLocked && !EXCLUDED_ITEM_TYPES.has(item.itemType));
|
|
56819
56819
|
if (items.length < 1)
|
|
56820
56820
|
return;
|
|
56821
|
+
const snapshot = items.map((item) => {
|
|
56822
|
+
const pos = item.transformation.getTranslation();
|
|
56823
|
+
const mbr = item.getMbr();
|
|
56824
|
+
const w = Math.max(mbr.getWidth(), 1);
|
|
56825
|
+
const h2 = Math.max(mbr.getHeight(), 1);
|
|
56826
|
+
return {
|
|
56827
|
+
id: item.getId(),
|
|
56828
|
+
cx: pos.x + w * 0.5,
|
|
56829
|
+
cy: pos.y + h2 * 0.5,
|
|
56830
|
+
w,
|
|
56831
|
+
h: h2,
|
|
56832
|
+
mass: w * h2
|
|
56833
|
+
};
|
|
56834
|
+
});
|
|
56821
56835
|
let sumX = 0;
|
|
56822
56836
|
let sumY = 0;
|
|
56823
|
-
for (const
|
|
56824
|
-
|
|
56825
|
-
|
|
56826
|
-
|
|
56827
|
-
|
|
56828
|
-
const
|
|
56829
|
-
|
|
56830
|
-
|
|
56831
|
-
|
|
56832
|
-
|
|
56833
|
-
|
|
56834
|
-
|
|
56835
|
-
const vel = this.velocities.get(id);
|
|
56836
|
-
const mbr1 = item.getMbr();
|
|
56837
|
-
const w1 = mbr1.getWidth();
|
|
56838
|
-
const h1 = mbr1.getHeight();
|
|
56837
|
+
for (const s2 of snapshot) {
|
|
56838
|
+
sumX += s2.cx;
|
|
56839
|
+
sumY += s2.cy;
|
|
56840
|
+
}
|
|
56841
|
+
const centerX = sumX / snapshot.length;
|
|
56842
|
+
const centerY = sumY / snapshot.length;
|
|
56843
|
+
for (let i = 0;i < snapshot.length; i++) {
|
|
56844
|
+
const s1 = snapshot[i];
|
|
56845
|
+
if (!this.velocities.has(s1.id)) {
|
|
56846
|
+
this.velocities.set(s1.id, { vx: 0, vy: 0 });
|
|
56847
|
+
}
|
|
56848
|
+
const vel = this.velocities.get(s1.id);
|
|
56839
56849
|
let ax = 0;
|
|
56840
56850
|
let ay = 0;
|
|
56841
|
-
const
|
|
56842
|
-
const
|
|
56843
|
-
const dcx = centerX - cx1;
|
|
56844
|
-
const dcy = centerY - cy1;
|
|
56851
|
+
const dcx = centerX - s1.cx;
|
|
56852
|
+
const dcy = centerY - s1.cy;
|
|
56845
56853
|
const distCenter = Math.sqrt(dcx * dcx + dcy * dcy) + 1;
|
|
56846
56854
|
ax += this.G_CENTER * dcx / distCenter;
|
|
56847
56855
|
ay += this.G_CENTER * dcy / distCenter;
|
|
56848
|
-
|
|
56849
|
-
|
|
56850
|
-
|
|
56851
|
-
const
|
|
56852
|
-
const
|
|
56853
|
-
const
|
|
56854
|
-
const cx2 = mbr2.left + w2 * 0.5;
|
|
56855
|
-
const cy2 = mbr2.top + h2 * 0.5;
|
|
56856
|
-
const dx = cx2 - cx1;
|
|
56857
|
-
const dy = cy2 - cy1;
|
|
56856
|
+
for (let j = 0;j < snapshot.length; j++) {
|
|
56857
|
+
if (i === j)
|
|
56858
|
+
continue;
|
|
56859
|
+
const s2 = snapshot[j];
|
|
56860
|
+
const dx = s2.cx - s1.cx;
|
|
56861
|
+
const dy = s2.cy - s1.cy;
|
|
56858
56862
|
const distSq = dx * dx + dy * dy;
|
|
56859
56863
|
const dist = Math.sqrt(distSq) + 0.001;
|
|
56860
|
-
|
|
56864
|
+
if (dist > this.MAX_DISTANCE)
|
|
56865
|
+
continue;
|
|
56866
|
+
const minDist = (s1.w + s2.w + s1.h + s2.h) * 0.25;
|
|
56861
56867
|
if (dist < minDist) {
|
|
56862
56868
|
const repAcc = this.REPULSION / (distSq + this.SOFTENING_SQ);
|
|
56863
56869
|
ax -= repAcc * dx / dist;
|
|
56864
56870
|
ay -= repAcc * dy / dist;
|
|
56865
56871
|
} else {
|
|
56866
|
-
const gravAcc = this.G *
|
|
56872
|
+
const gravAcc = this.G * s2.mass / (distSq + this.SOFTENING_SQ);
|
|
56867
56873
|
ax += gravAcc * dx / dist;
|
|
56868
56874
|
ay += gravAcc * dy / dist;
|
|
56869
56875
|
}
|
|
@@ -56873,7 +56879,7 @@ class GravityEngine {
|
|
|
56873
56879
|
const moveX = vel.vx * dt;
|
|
56874
56880
|
const moveY = vel.vy * dt;
|
|
56875
56881
|
if (Math.abs(moveX) >= this.MIN_MOVE_PX || Math.abs(moveY) >= this.MIN_MOVE_PX) {
|
|
56876
|
-
|
|
56882
|
+
items[i].transformation.applyMatrixSilent({
|
|
56877
56883
|
translateX: moveX,
|
|
56878
56884
|
translateY: moveY,
|
|
56879
56885
|
scaleX: 1,
|
package/dist/esm/browser.js
CHANGED
|
@@ -54174,52 +54174,58 @@ class GravityEngine {
|
|
|
54174
54174
|
const items = this.board.items.listAll().filter((item) => !item.transformation.isLocked && !EXCLUDED_ITEM_TYPES.has(item.itemType));
|
|
54175
54175
|
if (items.length < 1)
|
|
54176
54176
|
return;
|
|
54177
|
+
const snapshot = items.map((item) => {
|
|
54178
|
+
const pos = item.transformation.getTranslation();
|
|
54179
|
+
const mbr = item.getMbr();
|
|
54180
|
+
const w = Math.max(mbr.getWidth(), 1);
|
|
54181
|
+
const h2 = Math.max(mbr.getHeight(), 1);
|
|
54182
|
+
return {
|
|
54183
|
+
id: item.getId(),
|
|
54184
|
+
cx: pos.x + w * 0.5,
|
|
54185
|
+
cy: pos.y + h2 * 0.5,
|
|
54186
|
+
w,
|
|
54187
|
+
h: h2,
|
|
54188
|
+
mass: w * h2
|
|
54189
|
+
};
|
|
54190
|
+
});
|
|
54177
54191
|
let sumX = 0;
|
|
54178
54192
|
let sumY = 0;
|
|
54179
|
-
for (const
|
|
54180
|
-
|
|
54181
|
-
|
|
54182
|
-
|
|
54183
|
-
|
|
54184
|
-
const
|
|
54185
|
-
|
|
54186
|
-
|
|
54187
|
-
|
|
54188
|
-
|
|
54189
|
-
|
|
54190
|
-
|
|
54191
|
-
const vel = this.velocities.get(id);
|
|
54192
|
-
const mbr1 = item.getMbr();
|
|
54193
|
-
const w1 = mbr1.getWidth();
|
|
54194
|
-
const h1 = mbr1.getHeight();
|
|
54193
|
+
for (const s2 of snapshot) {
|
|
54194
|
+
sumX += s2.cx;
|
|
54195
|
+
sumY += s2.cy;
|
|
54196
|
+
}
|
|
54197
|
+
const centerX = sumX / snapshot.length;
|
|
54198
|
+
const centerY = sumY / snapshot.length;
|
|
54199
|
+
for (let i = 0;i < snapshot.length; i++) {
|
|
54200
|
+
const s1 = snapshot[i];
|
|
54201
|
+
if (!this.velocities.has(s1.id)) {
|
|
54202
|
+
this.velocities.set(s1.id, { vx: 0, vy: 0 });
|
|
54203
|
+
}
|
|
54204
|
+
const vel = this.velocities.get(s1.id);
|
|
54195
54205
|
let ax = 0;
|
|
54196
54206
|
let ay = 0;
|
|
54197
|
-
const
|
|
54198
|
-
const
|
|
54199
|
-
const dcx = centerX - cx1;
|
|
54200
|
-
const dcy = centerY - cy1;
|
|
54207
|
+
const dcx = centerX - s1.cx;
|
|
54208
|
+
const dcy = centerY - s1.cy;
|
|
54201
54209
|
const distCenter = Math.sqrt(dcx * dcx + dcy * dcy) + 1;
|
|
54202
54210
|
ax += this.G_CENTER * dcx / distCenter;
|
|
54203
54211
|
ay += this.G_CENTER * dcy / distCenter;
|
|
54204
|
-
|
|
54205
|
-
|
|
54206
|
-
|
|
54207
|
-
const
|
|
54208
|
-
const
|
|
54209
|
-
const
|
|
54210
|
-
const cx2 = mbr2.left + w2 * 0.5;
|
|
54211
|
-
const cy2 = mbr2.top + h2 * 0.5;
|
|
54212
|
-
const dx = cx2 - cx1;
|
|
54213
|
-
const dy = cy2 - cy1;
|
|
54212
|
+
for (let j = 0;j < snapshot.length; j++) {
|
|
54213
|
+
if (i === j)
|
|
54214
|
+
continue;
|
|
54215
|
+
const s2 = snapshot[j];
|
|
54216
|
+
const dx = s2.cx - s1.cx;
|
|
54217
|
+
const dy = s2.cy - s1.cy;
|
|
54214
54218
|
const distSq = dx * dx + dy * dy;
|
|
54215
54219
|
const dist = Math.sqrt(distSq) + 0.001;
|
|
54216
|
-
|
|
54220
|
+
if (dist > this.MAX_DISTANCE)
|
|
54221
|
+
continue;
|
|
54222
|
+
const minDist = (s1.w + s2.w + s1.h + s2.h) * 0.25;
|
|
54217
54223
|
if (dist < minDist) {
|
|
54218
54224
|
const repAcc = this.REPULSION / (distSq + this.SOFTENING_SQ);
|
|
54219
54225
|
ax -= repAcc * dx / dist;
|
|
54220
54226
|
ay -= repAcc * dy / dist;
|
|
54221
54227
|
} else {
|
|
54222
|
-
const gravAcc = this.G *
|
|
54228
|
+
const gravAcc = this.G * s2.mass / (distSq + this.SOFTENING_SQ);
|
|
54223
54229
|
ax += gravAcc * dx / dist;
|
|
54224
54230
|
ay += gravAcc * dy / dist;
|
|
54225
54231
|
}
|
|
@@ -54229,7 +54235,7 @@ class GravityEngine {
|
|
|
54229
54235
|
const moveX = vel.vx * dt;
|
|
54230
54236
|
const moveY = vel.vy * dt;
|
|
54231
54237
|
if (Math.abs(moveX) >= this.MIN_MOVE_PX || Math.abs(moveY) >= this.MIN_MOVE_PX) {
|
|
54232
|
-
|
|
54238
|
+
items[i].transformation.applyMatrixSilent({
|
|
54233
54239
|
translateX: moveX,
|
|
54234
54240
|
translateY: moveY,
|
|
54235
54241
|
scaleX: 1,
|
package/dist/esm/index.js
CHANGED
|
@@ -54167,52 +54167,58 @@ class GravityEngine {
|
|
|
54167
54167
|
const items = this.board.items.listAll().filter((item) => !item.transformation.isLocked && !EXCLUDED_ITEM_TYPES.has(item.itemType));
|
|
54168
54168
|
if (items.length < 1)
|
|
54169
54169
|
return;
|
|
54170
|
+
const snapshot = items.map((item) => {
|
|
54171
|
+
const pos = item.transformation.getTranslation();
|
|
54172
|
+
const mbr = item.getMbr();
|
|
54173
|
+
const w = Math.max(mbr.getWidth(), 1);
|
|
54174
|
+
const h2 = Math.max(mbr.getHeight(), 1);
|
|
54175
|
+
return {
|
|
54176
|
+
id: item.getId(),
|
|
54177
|
+
cx: pos.x + w * 0.5,
|
|
54178
|
+
cy: pos.y + h2 * 0.5,
|
|
54179
|
+
w,
|
|
54180
|
+
h: h2,
|
|
54181
|
+
mass: w * h2
|
|
54182
|
+
};
|
|
54183
|
+
});
|
|
54170
54184
|
let sumX = 0;
|
|
54171
54185
|
let sumY = 0;
|
|
54172
|
-
for (const
|
|
54173
|
-
|
|
54174
|
-
|
|
54175
|
-
|
|
54176
|
-
|
|
54177
|
-
const
|
|
54178
|
-
|
|
54179
|
-
|
|
54180
|
-
|
|
54181
|
-
|
|
54182
|
-
|
|
54183
|
-
|
|
54184
|
-
const vel = this.velocities.get(id);
|
|
54185
|
-
const mbr1 = item.getMbr();
|
|
54186
|
-
const w1 = mbr1.getWidth();
|
|
54187
|
-
const h1 = mbr1.getHeight();
|
|
54186
|
+
for (const s2 of snapshot) {
|
|
54187
|
+
sumX += s2.cx;
|
|
54188
|
+
sumY += s2.cy;
|
|
54189
|
+
}
|
|
54190
|
+
const centerX = sumX / snapshot.length;
|
|
54191
|
+
const centerY = sumY / snapshot.length;
|
|
54192
|
+
for (let i = 0;i < snapshot.length; i++) {
|
|
54193
|
+
const s1 = snapshot[i];
|
|
54194
|
+
if (!this.velocities.has(s1.id)) {
|
|
54195
|
+
this.velocities.set(s1.id, { vx: 0, vy: 0 });
|
|
54196
|
+
}
|
|
54197
|
+
const vel = this.velocities.get(s1.id);
|
|
54188
54198
|
let ax = 0;
|
|
54189
54199
|
let ay = 0;
|
|
54190
|
-
const
|
|
54191
|
-
const
|
|
54192
|
-
const dcx = centerX - cx1;
|
|
54193
|
-
const dcy = centerY - cy1;
|
|
54200
|
+
const dcx = centerX - s1.cx;
|
|
54201
|
+
const dcy = centerY - s1.cy;
|
|
54194
54202
|
const distCenter = Math.sqrt(dcx * dcx + dcy * dcy) + 1;
|
|
54195
54203
|
ax += this.G_CENTER * dcx / distCenter;
|
|
54196
54204
|
ay += this.G_CENTER * dcy / distCenter;
|
|
54197
|
-
|
|
54198
|
-
|
|
54199
|
-
|
|
54200
|
-
const
|
|
54201
|
-
const
|
|
54202
|
-
const
|
|
54203
|
-
const cx2 = mbr2.left + w2 * 0.5;
|
|
54204
|
-
const cy2 = mbr2.top + h2 * 0.5;
|
|
54205
|
-
const dx = cx2 - cx1;
|
|
54206
|
-
const dy = cy2 - cy1;
|
|
54205
|
+
for (let j = 0;j < snapshot.length; j++) {
|
|
54206
|
+
if (i === j)
|
|
54207
|
+
continue;
|
|
54208
|
+
const s2 = snapshot[j];
|
|
54209
|
+
const dx = s2.cx - s1.cx;
|
|
54210
|
+
const dy = s2.cy - s1.cy;
|
|
54207
54211
|
const distSq = dx * dx + dy * dy;
|
|
54208
54212
|
const dist = Math.sqrt(distSq) + 0.001;
|
|
54209
|
-
|
|
54213
|
+
if (dist > this.MAX_DISTANCE)
|
|
54214
|
+
continue;
|
|
54215
|
+
const minDist = (s1.w + s2.w + s1.h + s2.h) * 0.25;
|
|
54210
54216
|
if (dist < minDist) {
|
|
54211
54217
|
const repAcc = this.REPULSION / (distSq + this.SOFTENING_SQ);
|
|
54212
54218
|
ax -= repAcc * dx / dist;
|
|
54213
54219
|
ay -= repAcc * dy / dist;
|
|
54214
54220
|
} else {
|
|
54215
|
-
const gravAcc = this.G *
|
|
54221
|
+
const gravAcc = this.G * s2.mass / (distSq + this.SOFTENING_SQ);
|
|
54216
54222
|
ax += gravAcc * dx / dist;
|
|
54217
54223
|
ay += gravAcc * dy / dist;
|
|
54218
54224
|
}
|
|
@@ -54222,7 +54228,7 @@ class GravityEngine {
|
|
|
54222
54228
|
const moveX = vel.vx * dt;
|
|
54223
54229
|
const moveY = vel.vy * dt;
|
|
54224
54230
|
if (Math.abs(moveX) >= this.MIN_MOVE_PX || Math.abs(moveY) >= this.MIN_MOVE_PX) {
|
|
54225
|
-
|
|
54231
|
+
items[i].transformation.applyMatrixSilent({
|
|
54226
54232
|
translateX: moveX,
|
|
54227
54233
|
translateY: moveY,
|
|
54228
54234
|
scaleX: 1,
|
package/dist/esm/node.js
CHANGED
|
@@ -56635,52 +56635,58 @@ class GravityEngine {
|
|
|
56635
56635
|
const items = this.board.items.listAll().filter((item) => !item.transformation.isLocked && !EXCLUDED_ITEM_TYPES.has(item.itemType));
|
|
56636
56636
|
if (items.length < 1)
|
|
56637
56637
|
return;
|
|
56638
|
+
const snapshot = items.map((item) => {
|
|
56639
|
+
const pos = item.transformation.getTranslation();
|
|
56640
|
+
const mbr = item.getMbr();
|
|
56641
|
+
const w = Math.max(mbr.getWidth(), 1);
|
|
56642
|
+
const h2 = Math.max(mbr.getHeight(), 1);
|
|
56643
|
+
return {
|
|
56644
|
+
id: item.getId(),
|
|
56645
|
+
cx: pos.x + w * 0.5,
|
|
56646
|
+
cy: pos.y + h2 * 0.5,
|
|
56647
|
+
w,
|
|
56648
|
+
h: h2,
|
|
56649
|
+
mass: w * h2
|
|
56650
|
+
};
|
|
56651
|
+
});
|
|
56638
56652
|
let sumX = 0;
|
|
56639
56653
|
let sumY = 0;
|
|
56640
|
-
for (const
|
|
56641
|
-
|
|
56642
|
-
|
|
56643
|
-
|
|
56644
|
-
|
|
56645
|
-
const
|
|
56646
|
-
|
|
56647
|
-
|
|
56648
|
-
|
|
56649
|
-
|
|
56650
|
-
|
|
56651
|
-
|
|
56652
|
-
const vel = this.velocities.get(id);
|
|
56653
|
-
const mbr1 = item.getMbr();
|
|
56654
|
-
const w1 = mbr1.getWidth();
|
|
56655
|
-
const h1 = mbr1.getHeight();
|
|
56654
|
+
for (const s2 of snapshot) {
|
|
56655
|
+
sumX += s2.cx;
|
|
56656
|
+
sumY += s2.cy;
|
|
56657
|
+
}
|
|
56658
|
+
const centerX = sumX / snapshot.length;
|
|
56659
|
+
const centerY = sumY / snapshot.length;
|
|
56660
|
+
for (let i = 0;i < snapshot.length; i++) {
|
|
56661
|
+
const s1 = snapshot[i];
|
|
56662
|
+
if (!this.velocities.has(s1.id)) {
|
|
56663
|
+
this.velocities.set(s1.id, { vx: 0, vy: 0 });
|
|
56664
|
+
}
|
|
56665
|
+
const vel = this.velocities.get(s1.id);
|
|
56656
56666
|
let ax = 0;
|
|
56657
56667
|
let ay = 0;
|
|
56658
|
-
const
|
|
56659
|
-
const
|
|
56660
|
-
const dcx = centerX - cx1;
|
|
56661
|
-
const dcy = centerY - cy1;
|
|
56668
|
+
const dcx = centerX - s1.cx;
|
|
56669
|
+
const dcy = centerY - s1.cy;
|
|
56662
56670
|
const distCenter = Math.sqrt(dcx * dcx + dcy * dcy) + 1;
|
|
56663
56671
|
ax += this.G_CENTER * dcx / distCenter;
|
|
56664
56672
|
ay += this.G_CENTER * dcy / distCenter;
|
|
56665
|
-
|
|
56666
|
-
|
|
56667
|
-
|
|
56668
|
-
const
|
|
56669
|
-
const
|
|
56670
|
-
const
|
|
56671
|
-
const cx2 = mbr2.left + w2 * 0.5;
|
|
56672
|
-
const cy2 = mbr2.top + h2 * 0.5;
|
|
56673
|
-
const dx = cx2 - cx1;
|
|
56674
|
-
const dy = cy2 - cy1;
|
|
56673
|
+
for (let j = 0;j < snapshot.length; j++) {
|
|
56674
|
+
if (i === j)
|
|
56675
|
+
continue;
|
|
56676
|
+
const s2 = snapshot[j];
|
|
56677
|
+
const dx = s2.cx - s1.cx;
|
|
56678
|
+
const dy = s2.cy - s1.cy;
|
|
56675
56679
|
const distSq = dx * dx + dy * dy;
|
|
56676
56680
|
const dist = Math.sqrt(distSq) + 0.001;
|
|
56677
|
-
|
|
56681
|
+
if (dist > this.MAX_DISTANCE)
|
|
56682
|
+
continue;
|
|
56683
|
+
const minDist = (s1.w + s2.w + s1.h + s2.h) * 0.25;
|
|
56678
56684
|
if (dist < minDist) {
|
|
56679
56685
|
const repAcc = this.REPULSION / (distSq + this.SOFTENING_SQ);
|
|
56680
56686
|
ax -= repAcc * dx / dist;
|
|
56681
56687
|
ay -= repAcc * dy / dist;
|
|
56682
56688
|
} else {
|
|
56683
|
-
const gravAcc = this.G *
|
|
56689
|
+
const gravAcc = this.G * s2.mass / (distSq + this.SOFTENING_SQ);
|
|
56684
56690
|
ax += gravAcc * dx / dist;
|
|
56685
56691
|
ay += gravAcc * dy / dist;
|
|
56686
56692
|
}
|
|
@@ -56690,7 +56696,7 @@ class GravityEngine {
|
|
|
56690
56696
|
const moveX = vel.vx * dt;
|
|
56691
56697
|
const moveY = vel.vy * dt;
|
|
56692
56698
|
if (Math.abs(moveX) >= this.MIN_MOVE_PX || Math.abs(moveY) >= this.MIN_MOVE_PX) {
|
|
56693
|
-
|
|
56699
|
+
items[i].transformation.applyMatrixSilent({
|
|
56694
56700
|
translateX: moveX,
|
|
56695
56701
|
translateY: moveY,
|
|
56696
56702
|
scaleX: 1,
|