MCPcopy Create free account
hub / github.com/melonjs/melonJS / insert

Method insert

packages/melonjs/src/physics/broadphase/octree.ts:352–384  ·  view source on GitHub ↗

* Insert the given object into the node. If this node exceeds * `max_objects`, it splits and redistributes existing items into * subnodes. Mirrors `QuadTree.insert` — same subtree-count * accounting (bump on insert, no bump on redistribution). * @param item - object to be added

(item: OctreeItem)

Source from the content-addressed store, hash-verified

350 * @param item - object to be added
351 */
352 insert(item: OctreeItem) {
353 this._subtreeCount++;
354
355 if (this.nodes.length > 0) {
356 const index = this.getIndex(item);
357 if (index !== -1) {
358 this.nodes[index].insert(item);
359 return;
360 }
361 }
362
363 this.objects.push(item);
364
365 if (
366 this.objects.length > this.max_objects &&
367 this.level < this.max_levels
368 ) {
369 if (this.nodes.length === 0) {
370 this.split();
371 }
372
373 let writeIdx = 0;
374 for (let i = 0, len = this.objects.length; i < len; i++) {
375 const subIndex = this.getIndex(this.objects[i]);
376 if (subIndex !== -1) {
377 this.nodes[subIndex].insert(this.objects[i]);
378 } else {
379 this.objects[writeIdx++] = this.objects[i];
380 }
381 }
382 this.objects.length = writeIdx;
383 }
384 }
385
386 /**
387 * Recursively remove the given container and its descendants from

Callers 1

insertContainerMethod · 0.95

Calls 4

getIndexMethod · 0.95
splitMethod · 0.95
insertMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected