Skip to content

Commit 64be5a5

Browse files
committed
moved all private functions to module namespaces
1 parent 2dc7a0b commit 64be5a5

8 files changed

Lines changed: 42 additions & 42 deletions

File tree

src/body/Body.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ var Axes = require('../geometry/Axes');
399399
}
400400

401401
// sum the properties of all compound parts of the parent body
402-
var total = _totalProperties(body);
402+
var total = Body._totalProperties(body);
403403

404404
body.area = total.area;
405405
body.parent = body;
@@ -658,7 +658,7 @@ var Axes = require('../geometry/Axes');
658658
* @param {body} body
659659
* @return {}
660660
*/
661-
var _totalProperties = function(body) {
661+
Body._totalProperties = function(body) {
662662
// from equations at:
663663
// https://ecourses.ou.edu/cgi-bin/ebook.cgi?doc=&topic=st&chap_sec=07.2&page=theory
664664
// http://output.to/sideway/default.asp?qno=121100087

src/collision/Grid.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ var Common = require('../core/Common');
8282
|| body.bounds.max.y < world.bounds.min.y || body.bounds.min.y > world.bounds.max.y)
8383
continue;
8484

85-
var newRegion = _getRegion(grid, body);
85+
var newRegion = Grid._getRegion(grid, body);
8686

8787
// if the body has changed grid region
8888
if (!body.region || newRegion.id !== body.region.id || forceUpdate) {
@@ -94,13 +94,13 @@ var Common = require('../core/Common');
9494
if (!body.region || forceUpdate)
9595
body.region = newRegion;
9696

97-
var union = _regionUnion(newRegion, body.region);
97+
var union = Grid._regionUnion(newRegion, body.region);
9898

9999
// update grid buckets affected by region change
100100
// iterate over the union of both regions
101101
for (col = union.startCol; col <= union.endCol; col++) {
102102
for (row = union.startRow; row <= union.endRow; row++) {
103-
bucketId = _getBucketId(col, row);
103+
bucketId = Grid._getBucketId(col, row);
104104
bucket = buckets[bucketId];
105105

106106
var isInsideNewRegion = (col >= newRegion.startCol && col <= newRegion.endCol
@@ -113,15 +113,15 @@ var Common = require('../core/Common');
113113
if (!isInsideNewRegion && isInsideOldRegion) {
114114
if (isInsideOldRegion) {
115115
if (bucket)
116-
_bucketRemoveBody(grid, bucket, body);
116+
Grid._bucketRemoveBody(grid, bucket, body);
117117
}
118118
}
119119

120120
// add to new region buckets
121121
if (body.region === newRegion || (isInsideNewRegion && !isInsideOldRegion) || forceUpdate) {
122122
if (!bucket)
123-
bucket = _createBucket(buckets, bucketId);
124-
_bucketAddBody(grid, bucket, body);
123+
bucket = Grid._createBucket(buckets, bucketId);
124+
Grid._bucketAddBody(grid, bucket, body);
125125
}
126126
}
127127
}
@@ -136,7 +136,7 @@ var Common = require('../core/Common');
136136

137137
// update pairs list only if pairs changed (i.e. a body changed region)
138138
if (gridChanged)
139-
grid.pairsList = _createActivePairsList(grid);
139+
grid.pairsList = Grid._createActivePairsList(grid);
140140
};
141141

142142
/**
@@ -158,13 +158,13 @@ var Common = require('../core/Common');
158158
* @param {} regionB
159159
* @return {} region
160160
*/
161-
var _regionUnion = function(regionA, regionB) {
161+
Grid._regionUnion = function(regionA, regionB) {
162162
var startCol = Math.min(regionA.startCol, regionB.startCol),
163163
endCol = Math.max(regionA.endCol, regionB.endCol),
164164
startRow = Math.min(regionA.startRow, regionB.startRow),
165165
endRow = Math.max(regionA.endRow, regionB.endRow);
166166

167-
return _createRegion(startCol, endCol, startRow, endRow);
167+
return Grid._createRegion(startCol, endCol, startRow, endRow);
168168
};
169169

170170
/**
@@ -175,14 +175,14 @@ var Common = require('../core/Common');
175175
* @param {} body
176176
* @return {} region
177177
*/
178-
var _getRegion = function(grid, body) {
178+
Grid._getRegion = function(grid, body) {
179179
var bounds = body.bounds,
180180
startCol = Math.floor(bounds.min.x / grid.bucketWidth),
181181
endCol = Math.floor(bounds.max.x / grid.bucketWidth),
182182
startRow = Math.floor(bounds.min.y / grid.bucketHeight),
183183
endRow = Math.floor(bounds.max.y / grid.bucketHeight);
184184

185-
return _createRegion(startCol, endCol, startRow, endRow);
185+
return Grid._createRegion(startCol, endCol, startRow, endRow);
186186
};
187187

188188
/**
@@ -195,7 +195,7 @@ var Common = require('../core/Common');
195195
* @param {} endRow
196196
* @return {} region
197197
*/
198-
var _createRegion = function(startCol, endCol, startRow, endRow) {
198+
Grid._createRegion = function(startCol, endCol, startRow, endRow) {
199199
return {
200200
id: startCol + ',' + endCol + ',' + startRow + ',' + endRow,
201201
startCol: startCol,
@@ -213,7 +213,7 @@ var Common = require('../core/Common');
213213
* @param {} row
214214
* @return {string} bucket id
215215
*/
216-
var _getBucketId = function(column, row) {
216+
Grid._getBucketId = function(column, row) {
217217
return 'C' + column + 'R' + row;
218218
};
219219

@@ -225,7 +225,7 @@ var Common = require('../core/Common');
225225
* @param {} bucketId
226226
* @return {} bucket
227227
*/
228-
var _createBucket = function(buckets, bucketId) {
228+
Grid._createBucket = function(buckets, bucketId) {
229229
var bucket = buckets[bucketId] = [];
230230
return bucket;
231231
};
@@ -238,7 +238,7 @@ var Common = require('../core/Common');
238238
* @param {} bucket
239239
* @param {} body
240240
*/
241-
var _bucketAddBody = function(grid, bucket, body) {
241+
Grid._bucketAddBody = function(grid, bucket, body) {
242242
// add new pairs
243243
for (var i = 0; i < bucket.length; i++) {
244244
var bodyB = bucket[i];
@@ -270,7 +270,7 @@ var Common = require('../core/Common');
270270
* @param {} bucket
271271
* @param {} body
272272
*/
273-
var _bucketRemoveBody = function(grid, bucket, body) {
273+
Grid._bucketRemoveBody = function(grid, bucket, body) {
274274
// remove from bucket
275275
bucket.splice(Common.indexOf(bucket, body), 1);
276276

@@ -294,7 +294,7 @@ var Common = require('../core/Common');
294294
* @param {} grid
295295
* @return [] pairs
296296
*/
297-
var _createActivePairsList = function(grid) {
297+
Grid._createActivePairsList = function(grid) {
298298
var pairKeys,
299299
pair,
300300
pairs = [];

src/collision/Pairs.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ var Common = require('../core/Common');
1313

1414
(function() {
1515

16-
var _pairMaxIdleLife = 1000;
16+
Pairs._pairMaxIdleLife = 1000;
1717

1818
/**
1919
* Creates a new pairs structure.
@@ -124,7 +124,7 @@ var Common = require('../core/Common');
124124
}
125125

126126
// if pair is inactive for too long, mark it to be removed
127-
if (timestamp - pair.timeUpdated > _pairMaxIdleLife) {
127+
if (timestamp - pair.timeUpdated > Pairs._pairMaxIdleLife) {
128128
indexesToRemove.push(i);
129129
}
130130
}

src/collision/SAT.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ var Vector = require('../geometry/Vector');
5454
axisBodyB = axisBodyA === bodyA ? bodyB : bodyA,
5555
axes = [axisBodyA.axes[previousCollision.axisNumber]];
5656

57-
minOverlap = _overlapAxes(axisBodyA.vertices, axisBodyB.vertices, axes);
57+
minOverlap = SAT._overlapAxes(axisBodyA.vertices, axisBodyB.vertices, axes);
5858
collision.reused = true;
5959

6060
if (minOverlap.overlap <= 0) {
@@ -64,14 +64,14 @@ var Vector = require('../geometry/Vector');
6464
} else {
6565
// if we can't reuse a result, perform a full SAT test
6666

67-
overlapAB = _overlapAxes(bodyA.vertices, bodyB.vertices, bodyA.axes);
67+
overlapAB = SAT._overlapAxes(bodyA.vertices, bodyB.vertices, bodyA.axes);
6868

6969
if (overlapAB.overlap <= 0) {
7070
collision.collided = false;
7171
return collision;
7272
}
7373

74-
overlapBA = _overlapAxes(bodyB.vertices, bodyA.vertices, bodyB.axes);
74+
overlapBA = SAT._overlapAxes(bodyB.vertices, bodyA.vertices, bodyB.axes);
7575

7676
if (overlapBA.overlap <= 0) {
7777
collision.collided = false;
@@ -120,7 +120,7 @@ var Vector = require('../geometry/Vector');
120120
collision.penetration.y = collision.normal.y * collision.depth;
121121

122122
// find support points, there is always either exactly one or two
123-
var verticesB = _findSupports(bodyA, bodyB, collision.normal),
123+
var verticesB = SAT._findSupports(bodyA, bodyB, collision.normal),
124124
supports = [];
125125

126126
// find the supports from bodyB that are inside bodyA
@@ -132,7 +132,7 @@ var Vector = require('../geometry/Vector');
132132

133133
// find the supports from bodyA that are inside bodyB
134134
if (supports.length < 2) {
135-
var verticesA = _findSupports(bodyB, bodyA, Vector.neg(collision.normal));
135+
var verticesA = SAT._findSupports(bodyB, bodyA, Vector.neg(collision.normal));
136136

137137
if (Vertices.contains(bodyB.vertices, verticesA[0]))
138138
supports.push(verticesA[0]);
@@ -159,7 +159,7 @@ var Vector = require('../geometry/Vector');
159159
* @param {} axes
160160
* @return result
161161
*/
162-
var _overlapAxes = function(verticesA, verticesB, axes) {
162+
SAT._overlapAxes = function(verticesA, verticesB, axes) {
163163
var projectionA = Vector._temp[0],
164164
projectionB = Vector._temp[1],
165165
result = { overlap: Number.MAX_VALUE },
@@ -169,8 +169,8 @@ var Vector = require('../geometry/Vector');
169169
for (var i = 0; i < axes.length; i++) {
170170
axis = axes[i];
171171

172-
_projectToAxis(projectionA, verticesA, axis);
173-
_projectToAxis(projectionB, verticesB, axis);
172+
SAT._projectToAxis(projectionA, verticesA, axis);
173+
SAT._projectToAxis(projectionB, verticesB, axis);
174174

175175
overlap = Math.min(projectionA.max - projectionB.min, projectionB.max - projectionA.min);
176176

@@ -197,7 +197,7 @@ var Vector = require('../geometry/Vector');
197197
* @param {} vertices
198198
* @param {} axis
199199
*/
200-
var _projectToAxis = function(projection, vertices, axis) {
200+
SAT._projectToAxis = function(projection, vertices, axis) {
201201
var min = Vector.dot(vertices[0], axis),
202202
max = min;
203203

@@ -224,7 +224,7 @@ var Vector = require('../geometry/Vector');
224224
* @param {} normal
225225
* @return [vector]
226226
*/
227-
var _findSupports = function(bodyA, bodyB, normal) {
227+
SAT._findSupports = function(bodyA, bodyB, normal) {
228228
var nearestDistance = Number.MAX_VALUE,
229229
vertexToBody = Vector._temp[0],
230230
vertices = bodyB.vertices,

src/constraint/MouseConstraint.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ var Bounds = require('../geometry/Bounds');
7777
Events.on(engine, 'beforeUpdate', function() {
7878
var allBodies = Composite.allBodies(engine.world);
7979
MouseConstraint.update(mouseConstraint, allBodies);
80-
_triggerEvents(mouseConstraint);
80+
MouseConstraint._triggerEvents(mouseConstraint);
8181
});
8282

8383
return mouseConstraint;
@@ -136,7 +136,7 @@ var Bounds = require('../geometry/Bounds');
136136
* @private
137137
* @param {mouse} mouseConstraint
138138
*/
139-
var _triggerEvents = function(mouseConstraint) {
139+
MouseConstraint._triggerEvents = function(mouseConstraint) {
140140
var mouse = mouseConstraint.mouse,
141141
mouseEvents = mouse.sourceEvents;
142142

src/core/Common.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -424,14 +424,14 @@ module.exports = Common;
424424

425425
for (var node in graph) {
426426
if (!visited[node] && !temp[node]) {
427-
_topologicalSort(node, visited, temp, graph, result);
427+
Common._topologicalSort(node, visited, temp, graph, result);
428428
}
429429
}
430430

431431
return result;
432432
};
433433

434-
var _topologicalSort = function(node, visited, temp, graph, result) {
434+
Common._topologicalSort = function(node, visited, temp, graph, result) {
435435
var neighbors = graph[node] || [];
436436
temp[node] = true;
437437

@@ -444,7 +444,7 @@ module.exports = Common;
444444
}
445445

446446
if (!visited[neighbor]) {
447-
_topologicalSort(neighbor, visited, temp, graph, result);
447+
Common._topologicalSort(neighbor, visited, temp, graph, result);
448448
}
449449
}
450450

src/core/Mouse.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ var Common = require('../core/Common');
4444
};
4545

4646
mouse.mousemove = function(event) {
47-
var position = _getRelativeMousePosition(event, mouse.element, mouse.pixelRatio),
47+
var position = Mouse._getRelativeMousePosition(event, mouse.element, mouse.pixelRatio),
4848
touches = event.changedTouches;
4949

5050
if (touches) {
@@ -60,7 +60,7 @@ var Common = require('../core/Common');
6060
};
6161

6262
mouse.mousedown = function(event) {
63-
var position = _getRelativeMousePosition(event, mouse.element, mouse.pixelRatio),
63+
var position = Mouse._getRelativeMousePosition(event, mouse.element, mouse.pixelRatio),
6464
touches = event.changedTouches;
6565

6666
if (touches) {
@@ -80,7 +80,7 @@ var Common = require('../core/Common');
8080
};
8181

8282
mouse.mouseup = function(event) {
83-
var position = _getRelativeMousePosition(event, mouse.element, mouse.pixelRatio),
83+
var position = Mouse._getRelativeMousePosition(event, mouse.element, mouse.pixelRatio),
8484
touches = event.changedTouches;
8585

8686
if (touches) {
@@ -176,7 +176,7 @@ var Common = require('../core/Common');
176176
* @param {number} pixelRatio
177177
* @return {}
178178
*/
179-
var _getRelativeMousePosition = function(event, element, pixelRatio) {
179+
Mouse._getRelativeMousePosition = function(event, element, pixelRatio) {
180180
var elementBounds = element.getBoundingClientRect(),
181181
rootNode = (document.documentElement || document.body.parentNode || document.body),
182182
scrollX = (window.pageXOffset !== undefined) ? window.pageXOffset : rootNode.scrollLeft,

src/geometry/Svg.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ var Bounds = require('../geometry/Bounds');
9797
};
9898

9999
// ensure path is absolute
100-
_svgPathToAbsolute(path);
100+
Svg._svgPathToAbsolute(path);
101101

102102
// get total length
103103
total = path.getTotalLength();
@@ -149,7 +149,7 @@ var Bounds = require('../geometry/Bounds');
149149
return points;
150150
};
151151

152-
var _svgPathToAbsolute = function(path) {
152+
Svg._svgPathToAbsolute = function(path) {
153153
// http://phrogz.net/convert-svg-path-to-all-absolute-commands
154154
// Copyright (c) Gavin Kistner
155155
// http://phrogz.net/js/_ReuseLicense.txt

0 commit comments

Comments
 (0)