@woosh/meep-engine 2.133.2 → 2.133.3
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/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"description": "Pure JavaScript game engine. Fully featured and production ready.",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"author": "Alexander Goldring",
|
|
8
|
-
"version": "2.133.
|
|
8
|
+
"version": "2.133.3",
|
|
9
9
|
"main": "build/meep.module.js",
|
|
10
10
|
"module": "build/meep.module.js",
|
|
11
11
|
"exports": {
|
|
@@ -40,6 +40,11 @@ export class QuadTreeNode<D> extends AABB2 {
|
|
|
40
40
|
* @type {QuadTreeDatum<D>[]}
|
|
41
41
|
*/
|
|
42
42
|
data: QuadTreeDatum<D>[];
|
|
43
|
+
/**
|
|
44
|
+
* Internal method. Assesses whether splitting this node would be beneficial.
|
|
45
|
+
* @returns {boolean}
|
|
46
|
+
*/
|
|
47
|
+
isSplitMeaningful(): boolean;
|
|
43
48
|
balance(): 0 | 1 | 2;
|
|
44
49
|
balanceBubbleUp(): void;
|
|
45
50
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QuadTreeNode.d.ts","sourceRoot":"","sources":["../../../../../../src/core/geom/2d/quad-tree/QuadTreeNode.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"QuadTreeNode.d.ts","sourceRoot":"","sources":["../../../../../../src/core/geom/2d/quad-tree/QuadTreeNode.js"],"names":[],"mappings":"AAqBA;;;GAGG;AACH;IApBK,4DACE;IAAA,cAAqB;IAoBxB;;;OAGG;IACH,SAFU,oBAAa,IAAI,CAEZ;IACf;;;OAGG;IACH,UAFU,oBAAa,IAAI,CAEX;IAChB;;;OAGG;IACH,YAFU,oBAAa,IAAI,CAET;IAClB;;;OAGG;IACH,aAFU,oBAAa,IAAI,CAER;IAEnB;;;OAGG;IACH,YAFU,oBAAa,IAAI,CAET;IAElB;;;OAGG;IACH,eAFU,MAAM,CAEE;IAGlB;;;OAGG;IACH,MAFU,cAAc,CAAC,CAAC,EAAE,CAElB;IAEV;;;OAGG;IACH,qBAFa,OAAO,CAmEnB;IAED,qBAcC;IAED,wBAYC;IAED;;;;;;OAMG;IACH,WALW,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,QAkBhB;IAED;;;;;;;;OAQG;IACH,oBANW,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,sBAWhB;IAED;;;OAGG;IACH,6CAuEC;IAED;;;OAGG;IACH,iBAaC;IAED;;;OAGG;IACH,WAFY,OAAO,CAIlB;IAED,cA8BC;IAED;;OAEG;IACH,mBAKC;IAED;;;OAGG;IACH,8CAiBC;IAED;;OAEG;IACH,qBA2DC;IAED,cASC;IAED,cAQC;IAED;;OAEG;IACH,mBAFW,CAAC,EAAE,QAUb;IAED;;;;OAIG;IACH,6BAHoB,cAAc,CAAC,CAAC,+BAgBnC;IAED;;;;OAIG;IACH,iCAHoB,aAAa,CAAC,CAAC,KAAE,OAAO,uBAiB3C;IAED;;;;;;OAMG;IACH,uCALW,MAAM,cAAc,CAAC,CAAC,CAAC,KACvB,MAAM,KACN,MAAM,GACJ,MAAM,CAIlB;IAED;;;;;;;;OAQG;IACH,2CAPW,MAAM,cAAc,CAAC,CAAC,CAAC,MACvB,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,GACJ,MAAM,CAIlB;IAED;;;;;;;;;OASG;IACH,mCAPW,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,kBACG,cAAc,CAAC,CAAC,+BA2CnC;IAIL;;;OAGG;IACH,yBAFU,OAAO,CAEoB;CANpC;kBAhlBiB,wBAAwB;8BAGZ,oBAAoB"}
|
|
@@ -7,7 +7,16 @@ import { qt_collect_by_point } from "./qt_collect_by_point.js";
|
|
|
7
7
|
import { QuadTreeDatum } from "./QuadTreeDatum.js";
|
|
8
8
|
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* Must have at least this many items before splitting makes sense.
|
|
12
|
+
* @type {number}
|
|
13
|
+
*/
|
|
10
14
|
const THRESHOLD_SPLIT = 16;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Must have at least this many items before merging makes sense.
|
|
18
|
+
* @type {number}
|
|
19
|
+
*/
|
|
11
20
|
const THRESHOLD_MERGE = 8;
|
|
12
21
|
|
|
13
22
|
/**
|
|
@@ -55,11 +64,81 @@ export class QuadTreeNode extends AABB2 {
|
|
|
55
64
|
*/
|
|
56
65
|
data = [];
|
|
57
66
|
|
|
67
|
+
/**
|
|
68
|
+
* Internal method. Assesses whether splitting this node would be beneficial.
|
|
69
|
+
* @returns {boolean}
|
|
70
|
+
*/
|
|
71
|
+
isSplitMeaningful() {
|
|
72
|
+
|
|
73
|
+
const data = this.data;
|
|
74
|
+
const data_size = data.length;
|
|
75
|
+
|
|
76
|
+
if (data_size < THRESHOLD_SPLIT) {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const x0 = this.x0;
|
|
81
|
+
const x1 = this.x1;
|
|
82
|
+
const y0 = this.y0;
|
|
83
|
+
const y1 = this.y1;
|
|
84
|
+
|
|
85
|
+
if (x0 === x1 && y0 === y1) {
|
|
86
|
+
// zero area, splitting will do nothing useful
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const xm = (x0 + x1) * 0.5;
|
|
91
|
+
const ym = (y0 + y1) * 0.5;
|
|
92
|
+
|
|
93
|
+
// simulate split and count how many items are in each quadrant
|
|
94
|
+
let count_tl = 0;
|
|
95
|
+
let count_tr = 0;
|
|
96
|
+
let count_bl = 0;
|
|
97
|
+
let count_br = 0;
|
|
98
|
+
for (let i = 0; i < data_size; i++) {
|
|
99
|
+
const datum = data[i];
|
|
100
|
+
|
|
101
|
+
if (datum.y1 < ym) {
|
|
102
|
+
//top
|
|
103
|
+
if (datum.x1 < xm) {
|
|
104
|
+
//left
|
|
105
|
+
count_tl++;
|
|
106
|
+
} else if (datum.x0 >= xm) {
|
|
107
|
+
//right
|
|
108
|
+
count_tr++;
|
|
109
|
+
}
|
|
110
|
+
} else if (datum.y0 >= ym) {
|
|
111
|
+
//top
|
|
112
|
+
if (datum.x1 < xm) {
|
|
113
|
+
//left
|
|
114
|
+
count_bl++;
|
|
115
|
+
} else if (datum.x0 >= xm) {
|
|
116
|
+
//right
|
|
117
|
+
count_br++;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const refined_sum = count_tl + count_tr + count_bl + count_br;
|
|
123
|
+
|
|
124
|
+
if (refined_sum === 0) {
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const refined_max = Math.max(count_tl, count_tr, count_bl, count_br);
|
|
129
|
+
|
|
130
|
+
if (refined_max === data_size) {
|
|
131
|
+
// all children would go quadrant, this is pointless recursion
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return true;
|
|
136
|
+
}
|
|
137
|
+
|
|
58
138
|
balance() {
|
|
59
|
-
const dataLength = this.data.length;
|
|
60
139
|
const is_split = this.isSplit();
|
|
61
140
|
|
|
62
|
-
if (
|
|
141
|
+
if (!is_split && this.isSplitMeaningful()) {
|
|
63
142
|
this.split();
|
|
64
143
|
|
|
65
144
|
return 1;
|
|
@@ -166,7 +245,7 @@ export class QuadTreeNode extends AABB2 {
|
|
|
166
245
|
} else {
|
|
167
246
|
|
|
168
247
|
if (!this.isSplit()) {
|
|
169
|
-
if (this.treeDataCount >= THRESHOLD_SPLIT) {
|
|
248
|
+
if (this.treeDataCount >= THRESHOLD_SPLIT && this.isSplitMeaningful()) {
|
|
170
249
|
//node is too large and should be split
|
|
171
250
|
this.split();
|
|
172
251
|
} else {
|