0
0
Fork 0
mirror of https://github.com/liabru/matter-js.git synced 2024-11-30 10:20:52 -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 * @param {} body
*/ */
Grid._bucketRemoveBody = function(grid, bucket, body) { Grid._bucketRemoveBody = function(grid, bucket, body) {
var gridPairs = grid.pairs,
pairId = Pair.id,
i;
// remove from bucket // remove from bucket
bucket.splice(Common.indexOf(bucket, body), 1); bucket.splice(Common.indexOf(bucket, body), 1);
var bucketLength = bucket.length;
// update pair counts // 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 // keep track of the number of buckets the pair exists in
// important for _createActivePairsList to work // important for _createActivePairsList to work
var bodyB = bucket[i], var pair = gridPairs[pairId(body, bucket[i])];
pairId = Pair.id(body, bodyB),
pair = grid.pairs[pairId];
if (pair) if (pair)
pair[2] -= 1; pair[2] -= 1;