0
0
Fork 0
mirror of https://github.com/liabru/matter-js.git synced 2024-11-23 09:26:51 -05:00

optimised Grid._bucketRemoveBody

This commit is contained in:
liabru 2021-05-02 23:05:43 +01:00
parent 5e3c629b90
commit 84136de6a4

View file

@ -264,16 +264,20 @@ var Common = require('../core/Common');
* @param {} body
*/
Grid._bucketRemoveBody = function(grid, bucket, body) {
var gridPairs = grid.pairs,
pairId = Pair.id,
i;
// remove from bucket
bucket.splice(Common.indexOf(bucket, body), 1);
var bucketLength = bucket.length;
// update pair counts
for (var i = 0; i < bucket.length; i++) {
for (i = 0; i < bucketLength; i++) {
// keep track of the number of buckets the pair exists in
// important for _createActivePairsList to work
var bodyB = bucket[i],
pairId = Pair.id(body, bodyB),
pair = grid.pairs[pairId];
var pair = gridPairs[pairId(body, bucket[i])];
if (pair)
pair[2] -= 1;