Skip to content

Commit

Permalink
removed Detector.bruteForce
Browse files Browse the repository at this point in the history
  • Loading branch information
liabru committed Dec 5, 2015
1 parent ce478cb commit e04de5f
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 73 deletions.
6 changes: 1 addition & 5 deletions demo/js/lib/matter-tools/matter-tools-dev.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* matter-tools-dev.min.js 0.5.0-dev 2015-07-27
* matter-tools-dev.min.js 0.5.0-dev 2015-12-05
* https://github.com/liabru/matter-tools
* License: MIT
*/
Expand Down Expand Up @@ -195,10 +195,6 @@
gravity.open();
var physics = datGui.addFolder("Engine");
physics.add(engine, "enableSleeping");
physics.add(gui, "broadphase", [ "grid", "bruteForce" ]).onFinishChange(function(value) {
engine.broadphase = gui.broadphaseCache[value];
Composite.setModified(engine.world, true, false, false);
});
physics.add(engine.timing, "timeScale", 0, 1.2).step(.05).listen();
physics.add(engine, "velocityIterations", 1, 10).step(1);
physics.add(engine, "positionIterations", 1, 10).step(1);
Expand Down
68 changes: 0 additions & 68 deletions src/collision/Detector.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,74 +89,6 @@ var Bounds = require('../geometry/Bounds');
return collisions;
};

/**
* Description
* @method bruteForce
* @param {body[]} bodies
* @param {engine} engine
* @return {array} collisions
*/
Detector.bruteForce = function(bodies, engine) {
var collisions = [],
pairsTable = engine.pairs.table;

// @if DEBUG
var metrics = engine.metrics;
// @endif

for (var i = 0; i < bodies.length; i++) {
for (var j = i + 1; j < bodies.length; j++) {
var bodyA = bodies[i],
bodyB = bodies[j];

// NOTE: could share a function for the below, but may drop performance?

if ((bodyA.isStatic || bodyA.isSleeping) && (bodyB.isStatic || bodyB.isSleeping))
continue;

if (!Detector.canCollide(bodyA.collisionFilter, bodyB.collisionFilter))
continue;

// @if DEBUG
metrics.midphaseTests += 1;
// @endif

// mid phase
if (Bounds.overlaps(bodyA.bounds, bodyB.bounds)) {

// find a previous collision we could reuse
var pairId = Pair.id(bodyA, bodyB),
pair = pairsTable[pairId],
previousCollision;

if (pair && pair.isActive) {
previousCollision = pair.collision;
} else {
previousCollision = null;
}

// narrow phase
var collision = SAT.collides(bodyA, bodyB, previousCollision);

// @if DEBUG
metrics.narrowphaseTests += 1;
if (collision.reused)
metrics.narrowReuseCount += 1;
// @endif

if (collision.collided) {
collisions.push(collision);
// @if DEBUG
metrics.narrowDetections += 1;
// @endif
}
}
}
}

return collisions;
};

/**
* Returns `true` if both supplied collision filters will allow a collision to occur.
* See `body.collisionFilter` for more information.
Expand Down

0 comments on commit e04de5f

Please sign in to comment.