mirror of
https://github.com/liabru/matter-js.git
synced 2024-12-25 13:39:06 -05:00
moved all private functions to module namespaces
This commit is contained in:
parent
2dc7a0bf5e
commit
64be5a5e3e
8 changed files with 42 additions and 42 deletions
|
@ -399,7 +399,7 @@ var Axes = require('../geometry/Axes');
|
|||
}
|
||||
|
||||
// sum the properties of all compound parts of the parent body
|
||||
var total = _totalProperties(body);
|
||||
var total = Body._totalProperties(body);
|
||||
|
||||
body.area = total.area;
|
||||
body.parent = body;
|
||||
|
@ -658,7 +658,7 @@ var Axes = require('../geometry/Axes');
|
|||
* @param {body} body
|
||||
* @return {}
|
||||
*/
|
||||
var _totalProperties = function(body) {
|
||||
Body._totalProperties = function(body) {
|
||||
// from equations at:
|
||||
// https://ecourses.ou.edu/cgi-bin/ebook.cgi?doc=&topic=st&chap_sec=07.2&page=theory
|
||||
// http://output.to/sideway/default.asp?qno=121100087
|
||||
|
|
|
@ -82,7 +82,7 @@ var Common = require('../core/Common');
|
|||
|| body.bounds.max.y < world.bounds.min.y || body.bounds.min.y > world.bounds.max.y)
|
||||
continue;
|
||||
|
||||
var newRegion = _getRegion(grid, body);
|
||||
var newRegion = Grid._getRegion(grid, body);
|
||||
|
||||
// if the body has changed grid region
|
||||
if (!body.region || newRegion.id !== body.region.id || forceUpdate) {
|
||||
|
@ -94,13 +94,13 @@ var Common = require('../core/Common');
|
|||
if (!body.region || forceUpdate)
|
||||
body.region = newRegion;
|
||||
|
||||
var union = _regionUnion(newRegion, body.region);
|
||||
var union = Grid._regionUnion(newRegion, body.region);
|
||||
|
||||
// update grid buckets affected by region change
|
||||
// iterate over the union of both regions
|
||||
for (col = union.startCol; col <= union.endCol; col++) {
|
||||
for (row = union.startRow; row <= union.endRow; row++) {
|
||||
bucketId = _getBucketId(col, row);
|
||||
bucketId = Grid._getBucketId(col, row);
|
||||
bucket = buckets[bucketId];
|
||||
|
||||
var isInsideNewRegion = (col >= newRegion.startCol && col <= newRegion.endCol
|
||||
|
@ -113,15 +113,15 @@ var Common = require('../core/Common');
|
|||
if (!isInsideNewRegion && isInsideOldRegion) {
|
||||
if (isInsideOldRegion) {
|
||||
if (bucket)
|
||||
_bucketRemoveBody(grid, bucket, body);
|
||||
Grid._bucketRemoveBody(grid, bucket, body);
|
||||
}
|
||||
}
|
||||
|
||||
// add to new region buckets
|
||||
if (body.region === newRegion || (isInsideNewRegion && !isInsideOldRegion) || forceUpdate) {
|
||||
if (!bucket)
|
||||
bucket = _createBucket(buckets, bucketId);
|
||||
_bucketAddBody(grid, bucket, body);
|
||||
bucket = Grid._createBucket(buckets, bucketId);
|
||||
Grid._bucketAddBody(grid, bucket, body);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -136,7 +136,7 @@ var Common = require('../core/Common');
|
|||
|
||||
// update pairs list only if pairs changed (i.e. a body changed region)
|
||||
if (gridChanged)
|
||||
grid.pairsList = _createActivePairsList(grid);
|
||||
grid.pairsList = Grid._createActivePairsList(grid);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -158,13 +158,13 @@ var Common = require('../core/Common');
|
|||
* @param {} regionB
|
||||
* @return {} region
|
||||
*/
|
||||
var _regionUnion = function(regionA, regionB) {
|
||||
Grid._regionUnion = function(regionA, regionB) {
|
||||
var startCol = Math.min(regionA.startCol, regionB.startCol),
|
||||
endCol = Math.max(regionA.endCol, regionB.endCol),
|
||||
startRow = Math.min(regionA.startRow, regionB.startRow),
|
||||
endRow = Math.max(regionA.endRow, regionB.endRow);
|
||||
|
||||
return _createRegion(startCol, endCol, startRow, endRow);
|
||||
return Grid._createRegion(startCol, endCol, startRow, endRow);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -175,14 +175,14 @@ var Common = require('../core/Common');
|
|||
* @param {} body
|
||||
* @return {} region
|
||||
*/
|
||||
var _getRegion = function(grid, body) {
|
||||
Grid._getRegion = function(grid, body) {
|
||||
var bounds = body.bounds,
|
||||
startCol = Math.floor(bounds.min.x / grid.bucketWidth),
|
||||
endCol = Math.floor(bounds.max.x / grid.bucketWidth),
|
||||
startRow = Math.floor(bounds.min.y / grid.bucketHeight),
|
||||
endRow = Math.floor(bounds.max.y / grid.bucketHeight);
|
||||
|
||||
return _createRegion(startCol, endCol, startRow, endRow);
|
||||
return Grid._createRegion(startCol, endCol, startRow, endRow);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -195,7 +195,7 @@ var Common = require('../core/Common');
|
|||
* @param {} endRow
|
||||
* @return {} region
|
||||
*/
|
||||
var _createRegion = function(startCol, endCol, startRow, endRow) {
|
||||
Grid._createRegion = function(startCol, endCol, startRow, endRow) {
|
||||
return {
|
||||
id: startCol + ',' + endCol + ',' + startRow + ',' + endRow,
|
||||
startCol: startCol,
|
||||
|
@ -213,7 +213,7 @@ var Common = require('../core/Common');
|
|||
* @param {} row
|
||||
* @return {string} bucket id
|
||||
*/
|
||||
var _getBucketId = function(column, row) {
|
||||
Grid._getBucketId = function(column, row) {
|
||||
return 'C' + column + 'R' + row;
|
||||
};
|
||||
|
||||
|
@ -225,7 +225,7 @@ var Common = require('../core/Common');
|
|||
* @param {} bucketId
|
||||
* @return {} bucket
|
||||
*/
|
||||
var _createBucket = function(buckets, bucketId) {
|
||||
Grid._createBucket = function(buckets, bucketId) {
|
||||
var bucket = buckets[bucketId] = [];
|
||||
return bucket;
|
||||
};
|
||||
|
@ -238,7 +238,7 @@ var Common = require('../core/Common');
|
|||
* @param {} bucket
|
||||
* @param {} body
|
||||
*/
|
||||
var _bucketAddBody = function(grid, bucket, body) {
|
||||
Grid._bucketAddBody = function(grid, bucket, body) {
|
||||
// add new pairs
|
||||
for (var i = 0; i < bucket.length; i++) {
|
||||
var bodyB = bucket[i];
|
||||
|
@ -270,7 +270,7 @@ var Common = require('../core/Common');
|
|||
* @param {} bucket
|
||||
* @param {} body
|
||||
*/
|
||||
var _bucketRemoveBody = function(grid, bucket, body) {
|
||||
Grid._bucketRemoveBody = function(grid, bucket, body) {
|
||||
// remove from bucket
|
||||
bucket.splice(Common.indexOf(bucket, body), 1);
|
||||
|
||||
|
@ -294,7 +294,7 @@ var Common = require('../core/Common');
|
|||
* @param {} grid
|
||||
* @return [] pairs
|
||||
*/
|
||||
var _createActivePairsList = function(grid) {
|
||||
Grid._createActivePairsList = function(grid) {
|
||||
var pairKeys,
|
||||
pair,
|
||||
pairs = [];
|
||||
|
|
|
@ -13,7 +13,7 @@ var Common = require('../core/Common');
|
|||
|
||||
(function() {
|
||||
|
||||
var _pairMaxIdleLife = 1000;
|
||||
Pairs._pairMaxIdleLife = 1000;
|
||||
|
||||
/**
|
||||
* Creates a new pairs structure.
|
||||
|
@ -124,7 +124,7 @@ var Common = require('../core/Common');
|
|||
}
|
||||
|
||||
// if pair is inactive for too long, mark it to be removed
|
||||
if (timestamp - pair.timeUpdated > _pairMaxIdleLife) {
|
||||
if (timestamp - pair.timeUpdated > Pairs._pairMaxIdleLife) {
|
||||
indexesToRemove.push(i);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ var Vector = require('../geometry/Vector');
|
|||
axisBodyB = axisBodyA === bodyA ? bodyB : bodyA,
|
||||
axes = [axisBodyA.axes[previousCollision.axisNumber]];
|
||||
|
||||
minOverlap = _overlapAxes(axisBodyA.vertices, axisBodyB.vertices, axes);
|
||||
minOverlap = SAT._overlapAxes(axisBodyA.vertices, axisBodyB.vertices, axes);
|
||||
collision.reused = true;
|
||||
|
||||
if (minOverlap.overlap <= 0) {
|
||||
|
@ -64,14 +64,14 @@ var Vector = require('../geometry/Vector');
|
|||
} else {
|
||||
// if we can't reuse a result, perform a full SAT test
|
||||
|
||||
overlapAB = _overlapAxes(bodyA.vertices, bodyB.vertices, bodyA.axes);
|
||||
overlapAB = SAT._overlapAxes(bodyA.vertices, bodyB.vertices, bodyA.axes);
|
||||
|
||||
if (overlapAB.overlap <= 0) {
|
||||
collision.collided = false;
|
||||
return collision;
|
||||
}
|
||||
|
||||
overlapBA = _overlapAxes(bodyB.vertices, bodyA.vertices, bodyB.axes);
|
||||
overlapBA = SAT._overlapAxes(bodyB.vertices, bodyA.vertices, bodyB.axes);
|
||||
|
||||
if (overlapBA.overlap <= 0) {
|
||||
collision.collided = false;
|
||||
|
@ -120,7 +120,7 @@ var Vector = require('../geometry/Vector');
|
|||
collision.penetration.y = collision.normal.y * collision.depth;
|
||||
|
||||
// find support points, there is always either exactly one or two
|
||||
var verticesB = _findSupports(bodyA, bodyB, collision.normal),
|
||||
var verticesB = SAT._findSupports(bodyA, bodyB, collision.normal),
|
||||
supports = [];
|
||||
|
||||
// find the supports from bodyB that are inside bodyA
|
||||
|
@ -132,7 +132,7 @@ var Vector = require('../geometry/Vector');
|
|||
|
||||
// find the supports from bodyA that are inside bodyB
|
||||
if (supports.length < 2) {
|
||||
var verticesA = _findSupports(bodyB, bodyA, Vector.neg(collision.normal));
|
||||
var verticesA = SAT._findSupports(bodyB, bodyA, Vector.neg(collision.normal));
|
||||
|
||||
if (Vertices.contains(bodyB.vertices, verticesA[0]))
|
||||
supports.push(verticesA[0]);
|
||||
|
@ -159,7 +159,7 @@ var Vector = require('../geometry/Vector');
|
|||
* @param {} axes
|
||||
* @return result
|
||||
*/
|
||||
var _overlapAxes = function(verticesA, verticesB, axes) {
|
||||
SAT._overlapAxes = function(verticesA, verticesB, axes) {
|
||||
var projectionA = Vector._temp[0],
|
||||
projectionB = Vector._temp[1],
|
||||
result = { overlap: Number.MAX_VALUE },
|
||||
|
@ -169,8 +169,8 @@ var Vector = require('../geometry/Vector');
|
|||
for (var i = 0; i < axes.length; i++) {
|
||||
axis = axes[i];
|
||||
|
||||
_projectToAxis(projectionA, verticesA, axis);
|
||||
_projectToAxis(projectionB, verticesB, axis);
|
||||
SAT._projectToAxis(projectionA, verticesA, axis);
|
||||
SAT._projectToAxis(projectionB, verticesB, axis);
|
||||
|
||||
overlap = Math.min(projectionA.max - projectionB.min, projectionB.max - projectionA.min);
|
||||
|
||||
|
@ -197,7 +197,7 @@ var Vector = require('../geometry/Vector');
|
|||
* @param {} vertices
|
||||
* @param {} axis
|
||||
*/
|
||||
var _projectToAxis = function(projection, vertices, axis) {
|
||||
SAT._projectToAxis = function(projection, vertices, axis) {
|
||||
var min = Vector.dot(vertices[0], axis),
|
||||
max = min;
|
||||
|
||||
|
@ -224,7 +224,7 @@ var Vector = require('../geometry/Vector');
|
|||
* @param {} normal
|
||||
* @return [vector]
|
||||
*/
|
||||
var _findSupports = function(bodyA, bodyB, normal) {
|
||||
SAT._findSupports = function(bodyA, bodyB, normal) {
|
||||
var nearestDistance = Number.MAX_VALUE,
|
||||
vertexToBody = Vector._temp[0],
|
||||
vertices = bodyB.vertices,
|
||||
|
|
|
@ -77,7 +77,7 @@ var Bounds = require('../geometry/Bounds');
|
|||
Events.on(engine, 'beforeUpdate', function() {
|
||||
var allBodies = Composite.allBodies(engine.world);
|
||||
MouseConstraint.update(mouseConstraint, allBodies);
|
||||
_triggerEvents(mouseConstraint);
|
||||
MouseConstraint._triggerEvents(mouseConstraint);
|
||||
});
|
||||
|
||||
return mouseConstraint;
|
||||
|
@ -136,7 +136,7 @@ var Bounds = require('../geometry/Bounds');
|
|||
* @private
|
||||
* @param {mouse} mouseConstraint
|
||||
*/
|
||||
var _triggerEvents = function(mouseConstraint) {
|
||||
MouseConstraint._triggerEvents = function(mouseConstraint) {
|
||||
var mouse = mouseConstraint.mouse,
|
||||
mouseEvents = mouse.sourceEvents;
|
||||
|
||||
|
|
|
@ -424,14 +424,14 @@ module.exports = Common;
|
|||
|
||||
for (var node in graph) {
|
||||
if (!visited[node] && !temp[node]) {
|
||||
_topologicalSort(node, visited, temp, graph, result);
|
||||
Common._topologicalSort(node, visited, temp, graph, result);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
var _topologicalSort = function(node, visited, temp, graph, result) {
|
||||
Common._topologicalSort = function(node, visited, temp, graph, result) {
|
||||
var neighbors = graph[node] || [];
|
||||
temp[node] = true;
|
||||
|
||||
|
@ -444,7 +444,7 @@ module.exports = Common;
|
|||
}
|
||||
|
||||
if (!visited[neighbor]) {
|
||||
_topologicalSort(neighbor, visited, temp, graph, result);
|
||||
Common._topologicalSort(neighbor, visited, temp, graph, result);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ var Common = require('../core/Common');
|
|||
};
|
||||
|
||||
mouse.mousemove = function(event) {
|
||||
var position = _getRelativeMousePosition(event, mouse.element, mouse.pixelRatio),
|
||||
var position = Mouse._getRelativeMousePosition(event, mouse.element, mouse.pixelRatio),
|
||||
touches = event.changedTouches;
|
||||
|
||||
if (touches) {
|
||||
|
@ -60,7 +60,7 @@ var Common = require('../core/Common');
|
|||
};
|
||||
|
||||
mouse.mousedown = function(event) {
|
||||
var position = _getRelativeMousePosition(event, mouse.element, mouse.pixelRatio),
|
||||
var position = Mouse._getRelativeMousePosition(event, mouse.element, mouse.pixelRatio),
|
||||
touches = event.changedTouches;
|
||||
|
||||
if (touches) {
|
||||
|
@ -80,7 +80,7 @@ var Common = require('../core/Common');
|
|||
};
|
||||
|
||||
mouse.mouseup = function(event) {
|
||||
var position = _getRelativeMousePosition(event, mouse.element, mouse.pixelRatio),
|
||||
var position = Mouse._getRelativeMousePosition(event, mouse.element, mouse.pixelRatio),
|
||||
touches = event.changedTouches;
|
||||
|
||||
if (touches) {
|
||||
|
@ -176,7 +176,7 @@ var Common = require('../core/Common');
|
|||
* @param {number} pixelRatio
|
||||
* @return {}
|
||||
*/
|
||||
var _getRelativeMousePosition = function(event, element, pixelRatio) {
|
||||
Mouse._getRelativeMousePosition = function(event, element, pixelRatio) {
|
||||
var elementBounds = element.getBoundingClientRect(),
|
||||
rootNode = (document.documentElement || document.body.parentNode || document.body),
|
||||
scrollX = (window.pageXOffset !== undefined) ? window.pageXOffset : rootNode.scrollLeft,
|
||||
|
|
|
@ -97,7 +97,7 @@ var Bounds = require('../geometry/Bounds');
|
|||
};
|
||||
|
||||
// ensure path is absolute
|
||||
_svgPathToAbsolute(path);
|
||||
Svg._svgPathToAbsolute(path);
|
||||
|
||||
// get total length
|
||||
total = path.getTotalLength();
|
||||
|
@ -149,7 +149,7 @@ var Bounds = require('../geometry/Bounds');
|
|||
return points;
|
||||
};
|
||||
|
||||
var _svgPathToAbsolute = function(path) {
|
||||
Svg._svgPathToAbsolute = function(path) {
|
||||
// http://phrogz.net/convert-svg-path-to-all-absolute-commands
|
||||
// Copyright (c) Gavin Kistner
|
||||
// http://phrogz.net/js/_ReuseLicense.txt
|
||||
|
|
Loading…
Reference in a new issue