From 5888ffcaf65864f8eb24ad4f9996149a89bdf7ee Mon Sep 17 00:00:00 2001 From: liabru Date: Thu, 1 Jan 2015 17:52:18 +0000 Subject: [PATCH] cleanup --- demo/js/Demo.js | 61 +++++-------------------------- src/body/Body.js | 1 - src/collision/Contact.js | 4 +- src/collision/Pair.js | 4 +- src/collision/SAT.js | 3 +- src/constraint/MouseConstraint.js | 4 +- src/core/Metrics.js | 4 +- src/factory/Bodies.js | 10 ++--- src/factory/Composites.js | 2 +- src/geometry/Vertices.js | 7 ++-- src/render/Render.js | 8 +--- 11 files changed, 30 insertions(+), 78 deletions(-) diff --git a/demo/js/Demo.js b/demo/js/Demo.js index d5e4e5c1..f9bd0ead 100644 --- a/demo/js/Demo.js +++ b/demo/js/Demo.js @@ -9,11 +9,9 @@ Composites = Matter.Composites, Common = Matter.Common, Constraint = Matter.Constraint, - RenderPixi = Matter.RenderPixi, Events = Matter.Events, Bounds = Matter.Bounds, Vector = Matter.Vector, - Vertices = Matter.Vertices, MouseConstraint = Matter.MouseConstraint, Mouse = Matter.Mouse, Query = Matter.Query; @@ -91,7 +89,6 @@ var sides = Math.round(Common.random(1, 8)); // triangles can be a little unstable, so avoid until fixed - // TODO: make triangles more stable sides = (sides === 3) ? 4 : sides; // round the edges of some bodies @@ -117,7 +114,7 @@ World.add(_world, stack); - var renderOptions = _engine.render.options; + var renderOptions = _engine.render.options; }; Demo.slingshot = function() { @@ -160,7 +157,7 @@ World.add(_engine.world, [ground, pyramid, ground2, pyramid2, rock, elastic]); - Events.on(_engine, 'tick', function(event) { + Events.on(_engine, 'tick', function() { if (_mouseConstraint.mouse.button === -1 && (rock.position.x > 190 || rock.position.y < 430)) { rock = Bodies.polygon(170, 450, 7, 20, rockOptions); World.add(_engine.world, rock); @@ -181,51 +178,35 @@ World.add(_world, [ Bodies.rectangle(200, 200, 100, 100, { - chamfer: { - radius: 20 - } + chamfer: { radius: 20 } }), Bodies.rectangle(300, 200, 100, 100, { - chamfer: { - radius: [90, 0, 0, 0] - } + chamfer: { radius: [90, 0, 0, 0] } }), Bodies.rectangle(400, 200, 200, 200, { - chamfer: { - radius: [150, 20, 40, 20] - } + chamfer: { radius: [150, 20, 40, 20] } }), Bodies.rectangle(200, 200, 200, 200, { - chamfer: { - radius: [150, 20, 150, 20] - } + chamfer: { radius: [150, 20, 150, 20] } }), Bodies.rectangle(300, 200, 200, 50, { - chamfer: { - radius: [25, 25, 0, 0] - } + chamfer: { radius: [25, 25, 0, 0] } }), Bodies.polygon(200, 100, 8, 80, { - chamfer: { - radius: 30 - } + chamfer: { radius: 30 } }), Bodies.polygon(300, 100, 5, 80, { - chamfer: { - radius: [10, 40, 20, 40, 10] - } + chamfer: { radius: [10, 40, 20, 40, 10] } }), Bodies.polygon(400, 200, 3, 50, { - chamfer: { - radius: [20, 0, 20] - } + chamfer: { radius: [20, 0, 20] } }) ]); @@ -639,8 +620,6 @@ World.add(_world, stack); _engine.enableSleeping = true; - - var renderOptions = _engine.render.options; }; Demo.broadphase = function() { @@ -694,8 +673,6 @@ }); World.add(_world, stack); - - var renderOptions = _engine.render.options; }; Demo.avalanche = function() { @@ -811,8 +788,6 @@ } })); - - var renderOptions = _engine.render.options; }; Demo.stack = function() { @@ -825,8 +800,6 @@ }); World.add(_world, stack); - - var renderOptions = _engine.render.options; }; Demo.circleStack = function() { @@ -839,8 +812,6 @@ }); World.add(_world, stack); - - var renderOptions = _engine.render.options; }; Demo.wreckingBall = function() { @@ -887,8 +858,6 @@ Bodies.polygon(400, 560, 5, 60), Bodies.rectangle(600, 560, 80, 80) ]); - - var renderOptions = _engine.render.options; }; Demo.stress = function() { @@ -931,8 +900,6 @@ }); World.add(_world, stack); - - var renderOptions = _engine.render.options; }; Demo.restitution = function() { @@ -1287,15 +1254,12 @@ context.fill(); }) ); - - var renderOptions = _engine.render.options; }; Demo.collisionFiltering = function() { var _world = _engine.world; // define our categories (as bit fields, there are up to 32 available) - var defaultCategory = 0x0001, redCategory = 0x0002, greenCategory = 0x0004, @@ -1308,7 +1272,6 @@ Demo.reset(); // create a stack with varying body categories (but these bodies can all collide with each other) - World.add(_world, Composites.stack(275, 150, 5, 10, 10, 10, function(x, y, column, row) { var category = redCategory, @@ -1335,7 +1298,6 @@ ); // this body will only collide with the walls and the green bodies - World.add(_world, Bodies.circle(310, 40, 30, { collisionFilter: { @@ -1349,7 +1311,6 @@ ); // this body will only collide with the walls and the red bodies - World.add(_world, Bodies.circle(400, 40, 30, { collisionFilter: { @@ -1363,7 +1324,6 @@ ); // this body will only collide with the walls and the blue bodies - World.add(_world, Bodies.circle(480, 40, 30, { collisionFilter: { @@ -1377,7 +1337,6 @@ ); // red category objects should not be draggable with the mouse - _mouseConstraint.collisionFilter.mask = defaultCategory | blueCategory | greenCategory; var renderOptions = _engine.render.options; diff --git a/src/body/Body.js b/src/body/Body.js index fdec254c..12aa8ec3 100644 --- a/src/body/Body.js +++ b/src/body/Body.js @@ -446,7 +446,6 @@ var Body = {}; continue; // don't update out of world bodies - // TODO: viewports if (body.bounds.max.x < worldBounds.min.x || body.bounds.min.x > worldBounds.max.x || body.bounds.max.y < worldBounds.min.y || body.bounds.min.y > worldBounds.max.y) continue; diff --git a/src/collision/Contact.js b/src/collision/Contact.js index 5c0a237c..be2c6ddf 100644 --- a/src/collision/Contact.js +++ b/src/collision/Contact.js @@ -27,10 +27,10 @@ var Contact = {}; * Description * @method id * @param {vertex} vertex - * @return {Number} Unique contactID + * @return {string} Unique contactID */ Contact.id = function(vertex) { return vertex.body.id + '_' + vertex.index; }; -})(); \ No newline at end of file +})(); diff --git a/src/collision/Pair.js b/src/collision/Pair.js index 206d2fcc..086c10d5 100644 --- a/src/collision/Pair.js +++ b/src/collision/Pair.js @@ -99,7 +99,7 @@ var Pair = {}; * @method id * @param {body} bodyA * @param {body} bodyB - * @return {number} Unique pairId + * @return {string} Unique pairId */ Pair.id = function(bodyA, bodyB) { if (bodyA.id < bodyB.id) { @@ -109,4 +109,4 @@ var Pair = {}; } }; -})(); \ No newline at end of file +})(); diff --git a/src/collision/SAT.js b/src/collision/SAT.js index f933ef87..a3557d05 100644 --- a/src/collision/SAT.js +++ b/src/collision/SAT.js @@ -248,11 +248,10 @@ var SAT = {}; vertexToBody.y = vertex.y - bodyAPosition.y; distance = -Vector.dot(normal, vertexToBody); if (distance < nearestDistance) { - nearestDistance = distance; vertexB = vertex; } return [vertexA, vertexB]; }; -})(); \ No newline at end of file +})(); diff --git a/src/constraint/MouseConstraint.js b/src/constraint/MouseConstraint.js index 6f740d53..21844385 100644 --- a/src/constraint/MouseConstraint.js +++ b/src/constraint/MouseConstraint.js @@ -51,7 +51,7 @@ var MouseConstraint = {}; var mouseConstraint = Common.extend(defaults, options); - Events.on(engine, 'tick', function(event) { + Events.on(engine, 'tick', function() { var allBodies = Composite.allBodies(engine.world); MouseConstraint.update(mouseConstraint, allBodies); _triggerEvents(mouseConstraint); @@ -229,4 +229,4 @@ var MouseConstraint = {}; * @type object */ -})(); \ No newline at end of file +})(); diff --git a/src/core/Metrics.js b/src/core/Metrics.js index 5edc88ac..6da79ba9 100644 --- a/src/core/Metrics.js +++ b/src/core/Metrics.js @@ -64,7 +64,6 @@ var Metrics = {}; Metrics.update = function(metrics, engine) { if (metrics.extended) { var world = engine.world, - broadphase = engine.broadphase[engine.broadphase.current], bodies = Composite.allBodies(world); metrics.collisions = metrics.narrowDetections; @@ -74,9 +73,10 @@ var Metrics = {}; metrics.narrowEff = (metrics.narrowDetections / (metrics.narrowphaseTests || 1)).toFixed(2); metrics.broadEff = (1 - (metrics.broadphaseTests / (bodies.length || 1))).toFixed(2); metrics.narrowReuse = (metrics.narrowReuseCount / (metrics.narrowphaseTests || 1)).toFixed(2); + //var broadphase = engine.broadphase[engine.broadphase.current]; //if (broadphase.instance) // metrics.buckets = Common.keys(broadphase.instance.buckets).length; } }; -})(); \ No newline at end of file +})(); diff --git a/src/factory/Bodies.js b/src/factory/Bodies.js index 96def7c6..25d2aa2a 100644 --- a/src/factory/Bodies.js +++ b/src/factory/Bodies.js @@ -17,7 +17,7 @@ var Bodies = {}; /** * Creates a new rigid body model with a rectangle hull. * The options parameter is an object that specifies any properties you wish to override the defaults. - * See the properites section of the `Matter.Body` module for detailed information on what you can pass via the `options` object. + * See the properties section of the `Matter.Body` module for detailed information on what you can pass via the `options` object. * @method rectangle * @param {number} x * @param {number} y @@ -48,7 +48,7 @@ var Bodies = {}; /** * Creates a new rigid body model with a trapezoid hull. * The options parameter is an object that specifies any properties you wish to override the defaults. - * See the properites section of the `Matter.Body` module for detailed information on what you can pass via the `options` object. + * See the properties section of the `Matter.Body` module for detailed information on what you can pass via the `options` object. * @method trapezoid * @param {number} x * @param {number} y @@ -87,7 +87,7 @@ var Bodies = {}; /** * Creates a new rigid body model with a circle hull. * The options parameter is an object that specifies any properties you wish to override the defaults. - * See the properites section of the `Matter.Body` module for detailed information on what you can pass via the `options` object. + * See the properties section of the `Matter.Body` module for detailed information on what you can pass via the `options` object. * @method circle * @param {number} x * @param {number} y @@ -118,7 +118,7 @@ var Bodies = {}; /** * Creates a new rigid body model with a regular polygon hull with the given number of sides. * The options parameter is an object that specifies any properties you wish to override the defaults. - * See the properites section of the `Matter.Body` module for detailed information on what you can pass via the `options` object. + * See the properties section of the `Matter.Body` module for detailed information on what you can pass via the `options` object. * @method polygon * @param {number} x * @param {number} y @@ -161,4 +161,4 @@ var Bodies = {}; return Body.create(Common.extend({}, polygon, options)); }; -})(); \ No newline at end of file +})(); diff --git a/src/factory/Composites.js b/src/factory/Composites.js index fea5eb7f..e57af9c0 100644 --- a/src/factory/Composites.js +++ b/src/factory/Composites.js @@ -303,7 +303,7 @@ var Composites = {}; particleOptions = Common.extend({ inertia: Infinity }, particleOptions); constraintOptions = Common.extend({ stiffness: 0.4 }, constraintOptions); - var softBody = Composites.stack(xx, yy, columns, rows, columnGap, rowGap, function(x, y, column, row) { + var softBody = Composites.stack(xx, yy, columns, rows, columnGap, rowGap, function(x, y) { return Bodies.circle(x, y, particleRadius, particleOptions); }); diff --git a/src/geometry/Vertices.js b/src/geometry/Vertices.js index 384c311b..bc73bd81 100644 --- a/src/geometry/Vertices.js +++ b/src/geometry/Vertices.js @@ -60,7 +60,7 @@ var Vertices = {}; points = []; path.replace(pathPattern, function(match, x, y) { - points.push({ x: parseFloat(x, 10), y: parseFloat(y, 10) }); + points.push({ x: parseFloat(x), y: parseFloat(y) }); }); return Vertices.create(points, body); @@ -254,8 +254,7 @@ var Vertices = {}; qualityMin = qualityMin || 2; qualityMax = qualityMax || 14; - var centre = Vertices.centre(vertices), - newVertices = []; + var newVertices = []; for (var i = 0; i < vertices.length; i++) { var prevVertex = vertices[i - 1 >= 0 ? i - 1 : vertices.length - 1], @@ -307,4 +306,4 @@ var Vertices = {}; return newVertices; }; -})(); \ No newline at end of file +})(); diff --git a/src/render/Render.js b/src/render/Render.js index cb6abec5..e90301b3 100644 --- a/src/render/Render.js +++ b/src/render/Render.js @@ -351,8 +351,7 @@ var Render = {}; */ Render.bodyShadows = function(engine, bodies, context) { var c = context, - render = engine.render, - options = render.options; + render = engine.render; for (var i = 0; i < bodies.length; i++) { var body = bodies[i]; @@ -640,9 +639,7 @@ var Render = {}; * @param {RenderingContext} context */ Render.bodyVelocity = function(engine, bodies, context) { - var c = context, - render = engine.render, - options = render.options; + var c = context; c.beginPath(); @@ -800,7 +797,6 @@ var Render = {}; Render.inspector = function(inspector, context) { var engine = inspector.engine, selected = inspector.selected, - c = context, render = engine.render, options = render.options, bounds;