Permalink
Browse files

Renamed exports.* to cp.* internally, to fix nodejs suppport

  • Loading branch information...
josephg committed Jan 14, 2012
1 parent e034661 commit 73dcff56d3fa66643ac4a043284306bce43bb19a
View
141 cp.js

Large diffs are not rendered by default.

Oops, something went wrong.
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -27,14 +27,17 @@ Object.create = Object.create || function(o) {
//var VERSION = CP_VERSION_MAJOR + "." + CP_VERSION_MINOR + "." + CP_VERSION_RELEASE;
+var cp;
if(typeof exports === 'undefined'){
- var exports = {};
+ cp = {};
+} else {
+ cp = exports;
}
+
if(typeof window === 'object'){
- window.cp = exports;
+ window.cp = cp;
}
-
var assert = function(value, message)
{
if (!value) {
@@ -92,30 +95,30 @@ var deleteObjFromList = function(arr, obj)
}
};
-var momentForCircle = exports.momentForCircle = function(m, r1, r2, offset)
+var momentForCircle = cp.momentForCircle = function(m, r1, r2, offset)
{
return m*(0.5*(r1*r1 + r2*r2) + vlengthsq(offset));
};
-var areaForCircle = exports.areaForCircle = function(r1, r2)
+var areaForCircle = cp.areaForCircle = function(r1, r2)
{
return Math.PI*Math.abs(r1*r1 - r2*r2);
};
-var momentForSegment = exports.momentForSegment = function(m, a, b)
+var momentForSegment = cp.momentForSegment = function(m, a, b)
{
var length = vlength(vsub(b, a));
var offset = vmult(vadd(a, b), 1/2);
return m*(length*length/12 + vlengthsq(offset));
};
-var areaForSegment = exports.areaForSegment = function(a, b, r)
+var areaForSegment = cp.areaForSegment = function(a, b, r)
{
return r*(Math.PI*r + 2*vdist(a, b));
};
-var momentForPoly = exports.momentForPoly = function(m, verts, offset)
+var momentForPoly = cp.momentForPoly = function(m, verts, offset)
{
var sum1 = 0;
var sum2 = 0;
@@ -136,7 +139,7 @@ var momentForPoly = exports.momentForPoly = function(m, verts, offset)
return (m*sum1)/(6*sum2);
};
-var areaForPoly = exports.areaForPoly = function(verts)
+var areaForPoly = cp.areaForPoly = function(verts)
{
throw new Error('Not updated for flat verts');
var area = 0;
@@ -147,7 +150,7 @@ var areaForPoly = exports.areaForPoly = function(verts)
return -area/2;
};
-var centroidForPoly = exports.centroidForPoly = function(verts)
+var centroidForPoly = cp.centroidForPoly = function(verts)
{
throw new Error('Not updated for flat verts');
var sum = 0;
@@ -165,7 +168,7 @@ var centroidForPoly = exports.centroidForPoly = function(verts)
return vmult(vsum, 1/(3*sum));
};
-var recenterPoly = exports.recenterPoly = function(verts)
+var recenterPoly = cp.recenterPoly = function(verts)
{
throw new Error('Not updated for flat verts');
var centroid = centroidForPoly(verts);
@@ -175,12 +178,12 @@ var recenterPoly = exports.recenterPoly = function(verts)
}
};
-var momentForBox = exports.momentForBox = function(m, width, height)
+var momentForBox = cp.momentForBox = function(m, width, height)
{
return m*(width*width + height*height)/12;
};
-var momentForBox2 = exports.momentForBox2 = function(m, box)
+var momentForBox2 = cp.momentForBox2 = function(m, box)
{
width = box.r - box.l;
height = box.t - box.b;
@@ -22,7 +22,7 @@
// TODO: Comment me!
// a and b are bodies that the constraint applies to.
-var Constraint = exports.Constraint = function(a, b)
+var Constraint = cp.Constraint = function(a, b)
{
/// The first body connected to this constraint.
this.a = a;
@@ -23,7 +23,7 @@ var defaultSpringTorque = function(spring, relativeAngle){
return (relativeAngle - spring.restAngle)*spring.stiffness;
}
-var DampedRotarySpring = exports.DampedRotarySpring = function(a, b, restAngle, stiffness, damping)
+var DampedRotarySpring = cp.DampedRotarySpring = function(a, b, restAngle, stiffness, damping)
{
Constraint.call(this, a, b);
@@ -23,7 +23,7 @@ var defaultSpringForce = function(spring, dist){
return (spring.restLength - dist)*spring.stiffness;
};
-var DampedSpring = exports.DampedSpring = function(a, b, anchr1, anchr2, restLength, stiffness, damping)
+var DampedSpring = cp.DampedSpring = function(a, b, anchr1, anchr2, restLength, stiffness, damping)
{
Constraint.call(this, a, b);
@@ -19,7 +19,7 @@
* SOFTWARE.
*/
-var GearJoint = exports.GearJoint = function(a, b, phase, ratio)
+var GearJoint = cp.GearJoint = function(a, b, phase, ratio)
{
Constraint.call(this, a, b);
@@ -19,7 +19,7 @@
* SOFTWARE.
*/
-var GrooveJoint = exports.GrooveJoint = function(a, b, groove_a, groove_b, anchr2)
+var GrooveJoint = cp.GrooveJoint = function(a, b, groove_a, groove_b, anchr2)
{
Constraint.call(this, a, b);
@@ -19,7 +19,7 @@
* SOFTWARE.
*/
-var PinJoint = exports.PinJoint = function(a, b, anchr1, anchr2)
+var PinJoint = cp.PinJoint = function(a, b, anchr1, anchr2)
{
Constraint.call(this, a, b);
@@ -20,7 +20,7 @@
*/
// Pivot joints can also be created with (a, b, pivot);
-var PivotJoint = exports.PivotJoint = function(a, b, anchr1, anchr2)
+var PivotJoint = cp.PivotJoint = function(a, b, anchr1, anchr2)
{
Constraint.call(this, a, b);
@@ -19,7 +19,7 @@
* SOFTWARE.
*/
-var RatchetJoint = exports.RatchetJoint = function(a, b, phase, ratchet)
+var RatchetJoint = cp.RatchetJoint = function(a, b, phase, ratchet)
{
Constraint.call(this, a, b);
@@ -19,7 +19,7 @@
* SOFTWARE.
*/
-var RotaryLimitJoint = exports.RotaryLimitJoint = function(a, b, min, max)
+var RotaryLimitJoint = cp.RotaryLimitJoint = function(a, b, min, max)
{
Constraint.call(this, a, b);
@@ -19,7 +19,7 @@
* SOFTWARE.
*/
-var SimpleMotor = exports.SimpleMotor = function(a, b, rate)
+var SimpleMotor = cp.SimpleMotor = function(a, b, rate)
{
Constraint.call(this, a, b);
@@ -19,7 +19,7 @@
* SOFTWARE.
*/
-var SlideJoint = exports.SlideJoint = function(a, b, anchr1, anchr2, min, max)
+var SlideJoint = cp.SlideJoint = function(a, b, anchr1, anchr2, min, max)
{
Constraint.call(this, a, b);
View
@@ -29,7 +29,7 @@
//
// Collision handlers are user-defined objects to describe the behaviour of colliding
// objects.
-var CollisionHandler = exports.CollisionHandler = function()
+var CollisionHandler = cp.CollisionHandler = function()
{
// The collision type
this.a = this.b = 0;
View
@@ -21,7 +21,7 @@
// This file implements a modified AABB tree for collision detection.
-var BBTree = exports.BBTree = function(staticIndex)
+var BBTree = cp.BBTree = function(staticIndex)
{
SpatialIndex.call(this, staticIndex);
View
@@ -25,7 +25,7 @@
/// They are given a shape by creating collision shapes (cpShape) that point to the body.
/// @{
-var Body = exports.Body = function(m, i) {
+var Body = cp.Body = function(m, i) {
/// Function that is called to update the body's velocity.
/// Override this to customize movement. Defaults to body.updateVelocity
/// body.velocity_func(gravity, damping, dt);
View
@@ -365,7 +365,7 @@ PolyShape.prototype.collisionTable = [
poly2poly
];
-var collideShapes = exports.collideShapes = function(a, b)
+var collideShapes = cp.collideShapes = function(a, b)
{
assert(a.collisionCode <= b.collisionCode, 'Collided shapes must be sorted by type');
return a.collisionTable[b.collisionCode](a, b);
View
@@ -42,7 +42,7 @@ var polyValidate = function(verts)
/// Initialize a polygon shape.
/// The vertexes must be convex and have a clockwise winding.
-var PolyShape = exports.PolyShape = function(body, verts, offset)
+var PolyShape = cp.PolyShape = function(body, verts, offset)
{
assert(verts.length >= 4, "Polygons require some verts");
assert(typeof(verts[0]) === 'number', 'Polygon verticies should be specified in a flattened list');
@@ -92,7 +92,7 @@ PolyShape.prototype.setVerts = function(verts, offset)
};
/// Initialize a box shaped polygon shape.
-var BoxShape = exports.BoxShape = function(body, width, height)
+var BoxShape = cp.BoxShape = function(body, width, height)
{
var hw = width/2;
var hh = height/2;
@@ -101,7 +101,7 @@ var BoxShape = exports.BoxShape = function(body, width, height)
};
/// Initialize an offset box shaped polygon shape.
-var BoxShape2 = exports.BoxShape2 = function(body, box)
+var BoxShape2 = cp.BoxShape2 = function(body, box)
{
var verts = [
box.l, box.b,
View
@@ -33,10 +33,10 @@ typedef struct cpSegmentQueryInfo {
var shapeIDCounter = 0;
-var CP_NO_GROUP = exports.NO_GROUP = 0;
-var CP_ALL_LAYERS = exports.ALL_LAYERS = ~0;
+var CP_NO_GROUP = cp.NO_GROUP = 0;
+var CP_ALL_LAYERS = cp.ALL_LAYERS = ~0;
-exports.resetShapeIdCounter = function()
+cp.resetShapeIdCounter = function()
{
shapeIDCounter = 0;
};
@@ -45,7 +45,7 @@ exports.resetShapeIdCounter = function()
//
/// Opaque collision shape struct. Do not create directly - instead use
/// PolyShape, CircleShape and SegmentShape.
-var Shape = exports.Shape = function(body) {
+var Shape = cp.Shape = function(body) {
/// The rigid body this collision shape is attached to.
this.body = body;
@@ -160,7 +160,7 @@ SegmentQueryInfo.prototype.hitDist = function(start, end)
// Circles.
-var CircleShape = exports.CircleShape = function(body, radius, offset)
+var CircleShape = cp.CircleShape = function(body, radius, offset)
{
this.c = this.tc = offset;
this.r = radius;
@@ -242,7 +242,7 @@ CircleShape.prototype.setOffset = function(offset)
// Segment shape
-var SegmentShape = exports.SegmentShape = function(body, a, b, r)
+var SegmentShape = cp.SegmentShape = function(body, a, b, r)
{
this.a = a;
this.b = b;
View
@@ -22,7 +22,7 @@
var defaultCollisionHandler = new CollisionHandler();
/// Basic Unit of Simulation in Chipmunk
-var Space = exports.Space = function() {
+var Space = cp.Space = function() {
this.stamp = 0;
this.curr_dt = 0;
View
@@ -78,7 +78,7 @@
reindexQuery(func);
*/
-var SpatialIndex = exports.SpatialIndex = function(staticIndex)
+var SpatialIndex = cp.SpatialIndex = function(staticIndex)
{
this.staticIndex = staticIndex;
Oops, something went wrong.

0 comments on commit 73dcff5

Please sign in to comment.