window.b2DW = (function() {
   "use strict"; 
   console.log("b2DW _*-*_");
   
   /*
   * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
   *
   * This software is provided 'as-is', without any express or implied
   * warranty.  In no event will the authors be held liable for any damages
   * arising from the use of this software.
   * Permission is granted to anyone to use this software for any purpose,
   * including commercial applications, and to alter it and redistribute it
   * freely, subject to the following restrictions:
   * 1. The origin of this software must not be misrepresented; you must not
   * claim that you wrote the original software. If you use this software
   * in a product, an acknowledgment in the product documentation would be
   * appreciated but is not required.
   * 2. Altered source versions must be plainly marked as such, and must not be
   * misrepresented as being the original software.
   * 3. This notice may not be removed or altered from any source distribution.
   */

   /* 
      JDM:  1:02 PM Thu July 20, 2023
      * Modified the code relating to mixed restitution. Colliding bodies now use the 
        lowest restitution of the two bodies. Search on JDM to find the related changes.
      * Implemented the bug fix related to Object.defineProperty as discussed on GitHub.
      * Ran ESLint on this code. It found a few minor issues that I have commented on.
      * Put everything in a closure. See public references that are revealed at the end
        (more can be added).
   */

   // beginning of original code
   
   var Box2D = {};

   (function (a2j, undefined) {
      
      // JDM: in next line, changed Object.prototype.defineProperty to Object.defineProperty
      if ( ! (Object.defineProperty instanceof Function)
         && Object.prototype.__defineGetter__ instanceof Function
         && Object.prototype.__defineSetter__ instanceof Function)
      {
         Object.defineProperty = function(obj, p, cfg) {
            if (cfg.get instanceof Function)
               obj.__defineGetter__(p, cfg.get);
            if (cfg.set instanceof Function)
               obj.__defineSetter__(p, cfg.set);
         }
      }
      
      function emptyFn() {};
      a2j.inherit = function(cls, base) {
         var tmpCtr = cls;
         emptyFn.prototype = base.prototype;
         cls.prototype = new emptyFn;
         cls.prototype.constructor = tmpCtr;
      };
      
      a2j.generateCallback = function generateCallback(context, cb) {
         return function () {
            cb.apply(context, arguments);
         };
      };
      
      a2j.NVector = function NVector(length) {
         if (length === undefined) length = 0;
         var tmp = new Array(length || 0);
         for (var i = 0; i < length; ++i)
         tmp[i] = 0;
         return tmp;
      };
      
      a2j.is = function is(o1, o2) {
         if (o1 === null) return false;
         if ((o2 instanceof Function) && (o1 instanceof o2)) return true;
         if ((o1.constructor.__implements != undefined) && (o1.constructor.__implements[o2])) return true;
         return false;
      };
      
      a2j.parseUInt = function(v) {
         return Math.abs(parseInt(v));
      }
      
   })(Box2D);

   //#TODO remove assignments from global namespace
   var Vector = Array;
   var Vector_a2j_Number = Box2D.NVector;
   //package structure
   if (typeof(Box2D) === "undefined") Box2D = {};
   if (typeof(Box2D.Collision) === "undefined") Box2D.Collision = {};
   if (typeof(Box2D.Collision.Shapes) === "undefined") Box2D.Collision.Shapes = {};
   if (typeof(Box2D.Common) === "undefined") Box2D.Common = {};
   if (typeof(Box2D.Common.Math) === "undefined") Box2D.Common.Math = {};
   if (typeof(Box2D.Dynamics) === "undefined") Box2D.Dynamics = {};
   if (typeof(Box2D.Dynamics.Contacts) === "undefined") Box2D.Dynamics.Contacts = {};
   if (typeof(Box2D.Dynamics.Controllers) === "undefined") Box2D.Dynamics.Controllers = {};
   if (typeof(Box2D.Dynamics.Joints) === "undefined") Box2D.Dynamics.Joints = {};
   //pre-definitions
   (function () {
      Box2D.Collision.IBroadPhase = 'Box2D.Collision.IBroadPhase';

      function b2AABB() {
         b2AABB.b2AABB.apply(this, arguments);
      };
      Box2D.Collision.b2AABB = b2AABB;

      function b2Bound() {
         b2Bound.b2Bound.apply(this, arguments);
      };
      Box2D.Collision.b2Bound = b2Bound;

      function b2BoundValues() {
         b2BoundValues.b2BoundValues.apply(this, arguments);
         if (this.constructor === b2BoundValues) this.b2BoundValues.apply(this, arguments);
      };
      Box2D.Collision.b2BoundValues = b2BoundValues;

      function b2Collision() {
         b2Collision.b2Collision.apply(this, arguments);
      };
      Box2D.Collision.b2Collision = b2Collision;

      function b2ContactID() {
         b2ContactID.b2ContactID.apply(this, arguments);
         if (this.constructor === b2ContactID) this.b2ContactID.apply(this, arguments);
      };
      Box2D.Collision.b2ContactID = b2ContactID;

      function b2ContactPoint() {
         b2ContactPoint.b2ContactPoint.apply(this, arguments);
      };
      Box2D.Collision.b2ContactPoint = b2ContactPoint;

      function b2Distance() {
         b2Distance.b2Distance.apply(this, arguments);
      };
      Box2D.Collision.b2Distance = b2Distance;

      function b2DistanceInput() {
         b2DistanceInput.b2DistanceInput.apply(this, arguments);
      };
      Box2D.Collision.b2DistanceInput = b2DistanceInput;

      function b2DistanceOutput() {
         b2DistanceOutput.b2DistanceOutput.apply(this, arguments);
      };
      Box2D.Collision.b2DistanceOutput = b2DistanceOutput;

      function b2DistanceProxy() {
         b2DistanceProxy.b2DistanceProxy.apply(this, arguments);
      };
      Box2D.Collision.b2DistanceProxy = b2DistanceProxy;

      function b2DynamicTree() {
         b2DynamicTree.b2DynamicTree.apply(this, arguments);
         if (this.constructor === b2DynamicTree) this.b2DynamicTree.apply(this, arguments);
      };
      Box2D.Collision.b2DynamicTree = b2DynamicTree;

      function b2DynamicTreeBroadPhase() {
         b2DynamicTreeBroadPhase.b2DynamicTreeBroadPhase.apply(this, arguments);
      };
      Box2D.Collision.b2DynamicTreeBroadPhase = b2DynamicTreeBroadPhase;

      function b2DynamicTreeNode() {
         b2DynamicTreeNode.b2DynamicTreeNode.apply(this, arguments);
      };
      Box2D.Collision.b2DynamicTreeNode = b2DynamicTreeNode;

      function b2DynamicTreePair() {
         b2DynamicTreePair.b2DynamicTreePair.apply(this, arguments);
      };
      Box2D.Collision.b2DynamicTreePair = b2DynamicTreePair;

      function b2Manifold() {
         b2Manifold.b2Manifold.apply(this, arguments);
         if (this.constructor === b2Manifold) this.b2Manifold.apply(this, arguments);
      };
      Box2D.Collision.b2Manifold = b2Manifold;

      function b2ManifoldPoint() {
         b2ManifoldPoint.b2ManifoldPoint.apply(this, arguments);
         if (this.constructor === b2ManifoldPoint) this.b2ManifoldPoint.apply(this, arguments);
      };
      Box2D.Collision.b2ManifoldPoint = b2ManifoldPoint;

      function b2Point() {
         b2Point.b2Point.apply(this, arguments);
      };
      Box2D.Collision.b2Point = b2Point;

      function b2RayCastInput() {
         b2RayCastInput.b2RayCastInput.apply(this, arguments);
         if (this.constructor === b2RayCastInput) this.b2RayCastInput.apply(this, arguments);
      };
      Box2D.Collision.b2RayCastInput = b2RayCastInput;

      function b2RayCastOutput() {
         b2RayCastOutput.b2RayCastOutput.apply(this, arguments);
      };
      Box2D.Collision.b2RayCastOutput = b2RayCastOutput;

      function b2Segment() {
         b2Segment.b2Segment.apply(this, arguments);
      };
      Box2D.Collision.b2Segment = b2Segment;

      function b2SeparationFunction() {
         b2SeparationFunction.b2SeparationFunction.apply(this, arguments);
      };
      Box2D.Collision.b2SeparationFunction = b2SeparationFunction;

      function b2Simplex() {
         b2Simplex.b2Simplex.apply(this, arguments);
         if (this.constructor === b2Simplex) this.b2Simplex.apply(this, arguments);
      };
      Box2D.Collision.b2Simplex = b2Simplex;

      function b2SimplexCache() {
         b2SimplexCache.b2SimplexCache.apply(this, arguments);
      };
      Box2D.Collision.b2SimplexCache = b2SimplexCache;

      function b2SimplexVertex() {
         b2SimplexVertex.b2SimplexVertex.apply(this, arguments);
      };
      Box2D.Collision.b2SimplexVertex = b2SimplexVertex;

      function b2TimeOfImpact() {
         b2TimeOfImpact.b2TimeOfImpact.apply(this, arguments);
      };
      Box2D.Collision.b2TimeOfImpact = b2TimeOfImpact;

      function b2TOIInput() {
         b2TOIInput.b2TOIInput.apply(this, arguments);
      };
      Box2D.Collision.b2TOIInput = b2TOIInput;

      function b2WorldManifold() {
         b2WorldManifold.b2WorldManifold.apply(this, arguments);
         if (this.constructor === b2WorldManifold) this.b2WorldManifold.apply(this, arguments);
      };
      Box2D.Collision.b2WorldManifold = b2WorldManifold;

      function ClipVertex() {
         ClipVertex.ClipVertex.apply(this, arguments);
      };
      Box2D.Collision.ClipVertex = ClipVertex;

      function Features() {
         Features.Features.apply(this, arguments);
      };
      Box2D.Collision.Features = Features;

      function b2CircleShape() {
         b2CircleShape.b2CircleShape.apply(this, arguments);
         if (this.constructor === b2CircleShape) this.b2CircleShape.apply(this, arguments);
      };
      Box2D.Collision.Shapes.b2CircleShape = b2CircleShape;

      function b2EdgeChainDef() {
         b2EdgeChainDef.b2EdgeChainDef.apply(this, arguments);
         if (this.constructor === b2EdgeChainDef) this.b2EdgeChainDef.apply(this, arguments);
      };
      Box2D.Collision.Shapes.b2EdgeChainDef = b2EdgeChainDef;

      function b2EdgeShape() {
         b2EdgeShape.b2EdgeShape.apply(this, arguments);
         if (this.constructor === b2EdgeShape) this.b2EdgeShape.apply(this, arguments);
      };
      Box2D.Collision.Shapes.b2EdgeShape = b2EdgeShape;

      function b2MassData() {
         b2MassData.b2MassData.apply(this, arguments);
      };
      Box2D.Collision.Shapes.b2MassData = b2MassData;

      function b2PolygonShape() {
         b2PolygonShape.b2PolygonShape.apply(this, arguments);
         if (this.constructor === b2PolygonShape) this.b2PolygonShape.apply(this, arguments);
      };
      Box2D.Collision.Shapes.b2PolygonShape = b2PolygonShape;

      function b2Shape() {
         b2Shape.b2Shape.apply(this, arguments);
         if (this.constructor === b2Shape) this.b2Shape.apply(this, arguments);
      };
      Box2D.Collision.Shapes.b2Shape = b2Shape;
      Box2D.Common.b2internal = 'Box2D.Common.b2internal';

      function b2Color() {
         b2Color.b2Color.apply(this, arguments);
         if (this.constructor === b2Color) this.b2Color.apply(this, arguments);
      };
      Box2D.Common.b2Color = b2Color;

      function b2Settings() {
         b2Settings.b2Settings.apply(this, arguments);
      };
      Box2D.Common.b2Settings = b2Settings;

      function b2Mat22() {
         b2Mat22.b2Mat22.apply(this, arguments);
         if (this.constructor === b2Mat22) this.b2Mat22.apply(this, arguments);
      };
      Box2D.Common.Math.b2Mat22 = b2Mat22;

      function b2Mat33() {
         b2Mat33.b2Mat33.apply(this, arguments);
         if (this.constructor === b2Mat33) this.b2Mat33.apply(this, arguments);
      };
      Box2D.Common.Math.b2Mat33 = b2Mat33;

      function b2Math() {
         b2Math.b2Math.apply(this, arguments);
      };
      Box2D.Common.Math.b2Math = b2Math;

      function b2Sweep() {
         b2Sweep.b2Sweep.apply(this, arguments);
      };
      Box2D.Common.Math.b2Sweep = b2Sweep;

      function b2Transform() {
         b2Transform.b2Transform.apply(this, arguments);
         if (this.constructor === b2Transform) this.b2Transform.apply(this, arguments);
      };
      Box2D.Common.Math.b2Transform = b2Transform;

      function b2Vec2() {
         b2Vec2.b2Vec2.apply(this, arguments);
         if (this.constructor === b2Vec2) this.b2Vec2.apply(this, arguments);
      };
      Box2D.Common.Math.b2Vec2 = b2Vec2;

      function b2Vec3() {
         b2Vec3.b2Vec3.apply(this, arguments);
         if (this.constructor === b2Vec3) this.b2Vec3.apply(this, arguments);
      };
      Box2D.Common.Math.b2Vec3 = b2Vec3;

      function b2Body() {
         b2Body.b2Body.apply(this, arguments);
         if (this.constructor === b2Body) this.b2Body.apply(this, arguments);
      };
      Box2D.Dynamics.b2Body = b2Body;

      function b2BodyDef() {
         b2BodyDef.b2BodyDef.apply(this, arguments);
         if (this.constructor === b2BodyDef) this.b2BodyDef.apply(this, arguments);
      };
      Box2D.Dynamics.b2BodyDef = b2BodyDef;

      function b2ContactFilter() {
         b2ContactFilter.b2ContactFilter.apply(this, arguments);
      };
      Box2D.Dynamics.b2ContactFilter = b2ContactFilter;

      function b2ContactImpulse() {
         b2ContactImpulse.b2ContactImpulse.apply(this, arguments);
      };
      Box2D.Dynamics.b2ContactImpulse = b2ContactImpulse;

      function b2ContactListener() {
         b2ContactListener.b2ContactListener.apply(this, arguments);
      };
      Box2D.Dynamics.b2ContactListener = b2ContactListener;

      function b2ContactManager() {
         b2ContactManager.b2ContactManager.apply(this, arguments);
         if (this.constructor === b2ContactManager) this.b2ContactManager.apply(this, arguments);
      };
      Box2D.Dynamics.b2ContactManager = b2ContactManager;

      function b2DebugDraw() {
         b2DebugDraw.b2DebugDraw.apply(this, arguments);
         if (this.constructor === b2DebugDraw) this.b2DebugDraw.apply(this, arguments);
      };
      Box2D.Dynamics.b2DebugDraw = b2DebugDraw;

      function b2DestructionListener() {
         b2DestructionListener.b2DestructionListener.apply(this, arguments);
      };
      Box2D.Dynamics.b2DestructionListener = b2DestructionListener;

      function b2FilterData() {
         b2FilterData.b2FilterData.apply(this, arguments);
      };
      Box2D.Dynamics.b2FilterData = b2FilterData;

      function b2Fixture() {
         b2Fixture.b2Fixture.apply(this, arguments);
         if (this.constructor === b2Fixture) this.b2Fixture.apply(this, arguments);
      };
      Box2D.Dynamics.b2Fixture = b2Fixture;

      function b2FixtureDef() {
         b2FixtureDef.b2FixtureDef.apply(this, arguments);
         if (this.constructor === b2FixtureDef) this.b2FixtureDef.apply(this, arguments);
      };
      Box2D.Dynamics.b2FixtureDef = b2FixtureDef;

      function b2Island() {
         b2Island.b2Island.apply(this, arguments);
         if (this.constructor === b2Island) this.b2Island.apply(this, arguments);
      };
      Box2D.Dynamics.b2Island = b2Island;

      function b2TimeStep() {
         b2TimeStep.b2TimeStep.apply(this, arguments);
      };
      Box2D.Dynamics.b2TimeStep = b2TimeStep;

      function b2World() {
         b2World.b2World.apply(this, arguments);
         if (this.constructor === b2World) this.b2World.apply(this, arguments);
      };
      Box2D.Dynamics.b2World = b2World;

      function b2CircleContact() {
         b2CircleContact.b2CircleContact.apply(this, arguments);
      };
      Box2D.Dynamics.Contacts.b2CircleContact = b2CircleContact;

      function b2Contact() {
         b2Contact.b2Contact.apply(this, arguments);
         if (this.constructor === b2Contact) this.b2Contact.apply(this, arguments);
      };
      Box2D.Dynamics.Contacts.b2Contact = b2Contact;

      function b2ContactConstraint() {
         b2ContactConstraint.b2ContactConstraint.apply(this, arguments);
         if (this.constructor === b2ContactConstraint) this.b2ContactConstraint.apply(this, arguments);
      };
      Box2D.Dynamics.Contacts.b2ContactConstraint = b2ContactConstraint;

      function b2ContactConstraintPoint() {
         b2ContactConstraintPoint.b2ContactConstraintPoint.apply(this, arguments);
      };
      Box2D.Dynamics.Contacts.b2ContactConstraintPoint = b2ContactConstraintPoint;

      function b2ContactEdge() {
         b2ContactEdge.b2ContactEdge.apply(this, arguments);
      };
      Box2D.Dynamics.Contacts.b2ContactEdge = b2ContactEdge;

      function b2ContactFactory() {
         b2ContactFactory.b2ContactFactory.apply(this, arguments);
         if (this.constructor === b2ContactFactory) this.b2ContactFactory.apply(this, arguments);
      };
      Box2D.Dynamics.Contacts.b2ContactFactory = b2ContactFactory;

      function b2ContactRegister() {
         b2ContactRegister.b2ContactRegister.apply(this, arguments);
      };
      Box2D.Dynamics.Contacts.b2ContactRegister = b2ContactRegister;

      function b2ContactResult() {
         b2ContactResult.b2ContactResult.apply(this, arguments);
      };
      Box2D.Dynamics.Contacts.b2ContactResult = b2ContactResult;

      function b2ContactSolver() {
         b2ContactSolver.b2ContactSolver.apply(this, arguments);
         if (this.constructor === b2ContactSolver) this.b2ContactSolver.apply(this, arguments);
      };
      Box2D.Dynamics.Contacts.b2ContactSolver = b2ContactSolver;

      function b2EdgeAndCircleContact() {
         b2EdgeAndCircleContact.b2EdgeAndCircleContact.apply(this, arguments);
      };
      Box2D.Dynamics.Contacts.b2EdgeAndCircleContact = b2EdgeAndCircleContact;

      function b2NullContact() {
         b2NullContact.b2NullContact.apply(this, arguments);
         if (this.constructor === b2NullContact) this.b2NullContact.apply(this, arguments);
      };
      Box2D.Dynamics.Contacts.b2NullContact = b2NullContact;

      function b2PolyAndCircleContact() {
         b2PolyAndCircleContact.b2PolyAndCircleContact.apply(this, arguments);
      };
      Box2D.Dynamics.Contacts.b2PolyAndCircleContact = b2PolyAndCircleContact;

      function b2PolyAndEdgeContact() {
         b2PolyAndEdgeContact.b2PolyAndEdgeContact.apply(this, arguments);
      };
      Box2D.Dynamics.Contacts.b2PolyAndEdgeContact = b2PolyAndEdgeContact;

      function b2PolygonContact() {
         b2PolygonContact.b2PolygonContact.apply(this, arguments);
      };
      Box2D.Dynamics.Contacts.b2PolygonContact = b2PolygonContact;

      function b2PositionSolverManifold() {
         b2PositionSolverManifold.b2PositionSolverManifold.apply(this, arguments);
         if (this.constructor === b2PositionSolverManifold) this.b2PositionSolverManifold.apply(this, arguments);
      };
      Box2D.Dynamics.Contacts.b2PositionSolverManifold = b2PositionSolverManifold;

      function b2BuoyancyController() {
         b2BuoyancyController.b2BuoyancyController.apply(this, arguments);
      };
      Box2D.Dynamics.Controllers.b2BuoyancyController = b2BuoyancyController;

      function b2ConstantAccelController() {
         b2ConstantAccelController.b2ConstantAccelController.apply(this, arguments);
      };
      Box2D.Dynamics.Controllers.b2ConstantAccelController = b2ConstantAccelController;

      function b2ConstantForceController() {
         b2ConstantForceController.b2ConstantForceController.apply(this, arguments);
      };
      Box2D.Dynamics.Controllers.b2ConstantForceController = b2ConstantForceController;

      function b2Controller() {
         b2Controller.b2Controller.apply(this, arguments);
      };
      Box2D.Dynamics.Controllers.b2Controller = b2Controller;

      function b2ControllerEdge() {
         b2ControllerEdge.b2ControllerEdge.apply(this, arguments);
      };
      Box2D.Dynamics.Controllers.b2ControllerEdge = b2ControllerEdge;

      function b2GravityController() {
         b2GravityController.b2GravityController.apply(this, arguments);
      };
      Box2D.Dynamics.Controllers.b2GravityController = b2GravityController;

      function b2TensorDampingController() {
         b2TensorDampingController.b2TensorDampingController.apply(this, arguments);
      };
      Box2D.Dynamics.Controllers.b2TensorDampingController = b2TensorDampingController;

      function b2DistanceJoint() {
         b2DistanceJoint.b2DistanceJoint.apply(this, arguments);
         if (this.constructor === b2DistanceJoint) this.b2DistanceJoint.apply(this, arguments);
      };
      Box2D.Dynamics.Joints.b2DistanceJoint = b2DistanceJoint;

      function b2DistanceJointDef() {
         b2DistanceJointDef.b2DistanceJointDef.apply(this, arguments);
         if (this.constructor === b2DistanceJointDef) this.b2DistanceJointDef.apply(this, arguments);
      };
      Box2D.Dynamics.Joints.b2DistanceJointDef = b2DistanceJointDef;

      function b2FrictionJoint() {
         b2FrictionJoint.b2FrictionJoint.apply(this, arguments);
         if (this.constructor === b2FrictionJoint) this.b2FrictionJoint.apply(this, arguments);
      };
      Box2D.Dynamics.Joints.b2FrictionJoint = b2FrictionJoint;

      function b2FrictionJointDef() {
         b2FrictionJointDef.b2FrictionJointDef.apply(this, arguments);
         if (this.constructor === b2FrictionJointDef) this.b2FrictionJointDef.apply(this, arguments);
      };
      Box2D.Dynamics.Joints.b2FrictionJointDef = b2FrictionJointDef;

      function b2GearJoint() {
         b2GearJoint.b2GearJoint.apply(this, arguments);
         if (this.constructor === b2GearJoint) this.b2GearJoint.apply(this, arguments);
      };
      Box2D.Dynamics.Joints.b2GearJoint = b2GearJoint;

      function b2GearJointDef() {
         b2GearJointDef.b2GearJointDef.apply(this, arguments);
         if (this.constructor === b2GearJointDef) this.b2GearJointDef.apply(this, arguments);
      };
      Box2D.Dynamics.Joints.b2GearJointDef = b2GearJointDef;

      function b2Jacobian() {
         b2Jacobian.b2Jacobian.apply(this, arguments);
      };
      Box2D.Dynamics.Joints.b2Jacobian = b2Jacobian;

      function b2Joint() {
         b2Joint.b2Joint.apply(this, arguments);
         if (this.constructor === b2Joint) this.b2Joint.apply(this, arguments);
      };
      Box2D.Dynamics.Joints.b2Joint = b2Joint;

      function b2JointDef() {
         b2JointDef.b2JointDef.apply(this, arguments);
         if (this.constructor === b2JointDef) this.b2JointDef.apply(this, arguments);
      };
      Box2D.Dynamics.Joints.b2JointDef = b2JointDef;

      function b2JointEdge() {
         b2JointEdge.b2JointEdge.apply(this, arguments);
      };
      Box2D.Dynamics.Joints.b2JointEdge = b2JointEdge;

      function b2LineJoint() {
         b2LineJoint.b2LineJoint.apply(this, arguments);
         if (this.constructor === b2LineJoint) this.b2LineJoint.apply(this, arguments);
      };
      Box2D.Dynamics.Joints.b2LineJoint = b2LineJoint;

      function b2LineJointDef() {
         b2LineJointDef.b2LineJointDef.apply(this, arguments);
         if (this.constructor === b2LineJointDef) this.b2LineJointDef.apply(this, arguments);
      };
      Box2D.Dynamics.Joints.b2LineJointDef = b2LineJointDef;

      function b2MouseJoint() {
         b2MouseJoint.b2MouseJoint.apply(this, arguments);
         if (this.constructor === b2MouseJoint) this.b2MouseJoint.apply(this, arguments);
      };
      Box2D.Dynamics.Joints.b2MouseJoint = b2MouseJoint;

      function b2MouseJointDef() {
         b2MouseJointDef.b2MouseJointDef.apply(this, arguments);
         if (this.constructor === b2MouseJointDef) this.b2MouseJointDef.apply(this, arguments);
      };
      Box2D.Dynamics.Joints.b2MouseJointDef = b2MouseJointDef;

      function b2PrismaticJoint() {
         b2PrismaticJoint.b2PrismaticJoint.apply(this, arguments);
         if (this.constructor === b2PrismaticJoint) this.b2PrismaticJoint.apply(this, arguments);
      };
      Box2D.Dynamics.Joints.b2PrismaticJoint = b2PrismaticJoint;

      function b2PrismaticJointDef() {
         b2PrismaticJointDef.b2PrismaticJointDef.apply(this, arguments);
         if (this.constructor === b2PrismaticJointDef) this.b2PrismaticJointDef.apply(this, arguments);
      };
      Box2D.Dynamics.Joints.b2PrismaticJointDef = b2PrismaticJointDef;

      function b2PulleyJoint() {
         b2PulleyJoint.b2PulleyJoint.apply(this, arguments);
         if (this.constructor === b2PulleyJoint) this.b2PulleyJoint.apply(this, arguments);
      };
      Box2D.Dynamics.Joints.b2PulleyJoint = b2PulleyJoint;

      function b2PulleyJointDef() {
         b2PulleyJointDef.b2PulleyJointDef.apply(this, arguments);
         if (this.constructor === b2PulleyJointDef) this.b2PulleyJointDef.apply(this, arguments);
      };
      Box2D.Dynamics.Joints.b2PulleyJointDef = b2PulleyJointDef;

      function b2RevoluteJoint() {
         b2RevoluteJoint.b2RevoluteJoint.apply(this, arguments);
         if (this.constructor === b2RevoluteJoint) this.b2RevoluteJoint.apply(this, arguments);
      };
      Box2D.Dynamics.Joints.b2RevoluteJoint = b2RevoluteJoint;

      function b2RevoluteJointDef() {
         b2RevoluteJointDef.b2RevoluteJointDef.apply(this, arguments);
         if (this.constructor === b2RevoluteJointDef) this.b2RevoluteJointDef.apply(this, arguments);
      };
      Box2D.Dynamics.Joints.b2RevoluteJointDef = b2RevoluteJointDef;

      function b2WeldJoint() {
         b2WeldJoint.b2WeldJoint.apply(this, arguments);
         if (this.constructor === b2WeldJoint) this.b2WeldJoint.apply(this, arguments);
      };
      Box2D.Dynamics.Joints.b2WeldJoint = b2WeldJoint;

      function b2WeldJointDef() {
         b2WeldJointDef.b2WeldJointDef.apply(this, arguments);
         if (this.constructor === b2WeldJointDef) this.b2WeldJointDef.apply(this, arguments);
      };
      Box2D.Dynamics.Joints.b2WeldJointDef = b2WeldJointDef;
   })(); //definitions
   Box2D.postDefs = [];
   (function () {
      var b2CircleShape = Box2D.Collision.Shapes.b2CircleShape,
         b2EdgeChainDef = Box2D.Collision.Shapes.b2EdgeChainDef,
         b2EdgeShape = Box2D.Collision.Shapes.b2EdgeShape,
         b2MassData = Box2D.Collision.Shapes.b2MassData,
         b2PolygonShape = Box2D.Collision.Shapes.b2PolygonShape,
         b2Shape = Box2D.Collision.Shapes.b2Shape,
         b2Color = Box2D.Common.b2Color,
         b2internal = Box2D.Common.b2internal,
         b2Settings = Box2D.Common.b2Settings,
         b2Mat22 = Box2D.Common.Math.b2Mat22,
         b2Mat33 = Box2D.Common.Math.b2Mat33,
         b2Math = Box2D.Common.Math.b2Math,
         b2Sweep = Box2D.Common.Math.b2Sweep,
         b2Transform = Box2D.Common.Math.b2Transform,
         b2Vec2 = Box2D.Common.Math.b2Vec2,
         b2Vec3 = Box2D.Common.Math.b2Vec3,
         b2AABB = Box2D.Collision.b2AABB,
         b2Bound = Box2D.Collision.b2Bound,
         b2BoundValues = Box2D.Collision.b2BoundValues,
         b2Collision = Box2D.Collision.b2Collision,
         b2ContactID = Box2D.Collision.b2ContactID,
         b2ContactPoint = Box2D.Collision.b2ContactPoint,
         b2Distance = Box2D.Collision.b2Distance,
         b2DistanceInput = Box2D.Collision.b2DistanceInput,
         b2DistanceOutput = Box2D.Collision.b2DistanceOutput,
         b2DistanceProxy = Box2D.Collision.b2DistanceProxy,
         b2DynamicTree = Box2D.Collision.b2DynamicTree,
         b2DynamicTreeBroadPhase = Box2D.Collision.b2DynamicTreeBroadPhase,
         b2DynamicTreeNode = Box2D.Collision.b2DynamicTreeNode,
         b2DynamicTreePair = Box2D.Collision.b2DynamicTreePair,
         b2Manifold = Box2D.Collision.b2Manifold,
         b2ManifoldPoint = Box2D.Collision.b2ManifoldPoint,
         b2Point = Box2D.Collision.b2Point,
         b2RayCastInput = Box2D.Collision.b2RayCastInput,
         b2RayCastOutput = Box2D.Collision.b2RayCastOutput,
         b2Segment = Box2D.Collision.b2Segment,
         b2SeparationFunction = Box2D.Collision.b2SeparationFunction,
         b2Simplex = Box2D.Collision.b2Simplex,
         b2SimplexCache = Box2D.Collision.b2SimplexCache,
         b2SimplexVertex = Box2D.Collision.b2SimplexVertex,
         b2TimeOfImpact = Box2D.Collision.b2TimeOfImpact,
         b2TOIInput = Box2D.Collision.b2TOIInput,
         b2WorldManifold = Box2D.Collision.b2WorldManifold,
         ClipVertex = Box2D.Collision.ClipVertex,
         Features = Box2D.Collision.Features,
         IBroadPhase = Box2D.Collision.IBroadPhase;

      b2AABB.b2AABB = function () {
         this.lowerBound = new b2Vec2();
         this.upperBound = new b2Vec2();
      };
      b2AABB.prototype.IsValid = function () {
         var dX = this.upperBound.x - this.lowerBound.x;
         var dY = this.upperBound.y - this.lowerBound.y;
         var valid = dX >= 0.0 && dY >= 0.0;
         valid = valid && this.lowerBound.IsValid() && this.upperBound.IsValid();
         return valid;
      }
      b2AABB.prototype.GetCenter = function () {
         return new b2Vec2((this.lowerBound.x + this.upperBound.x) / 2, (this.lowerBound.y + this.upperBound.y) / 2);
      }
      b2AABB.prototype.GetExtents = function () {
         return new b2Vec2((this.upperBound.x - this.lowerBound.x) / 2, (this.upperBound.y - this.lowerBound.y) / 2);
      }
      b2AABB.prototype.Contains = function (aabb) {
         var result = true;
         result = result && this.lowerBound.x <= aabb.lowerBound.x;
         result = result && this.lowerBound.y <= aabb.lowerBound.y;
         result = result && aabb.upperBound.x <= this.upperBound.x;
         result = result && aabb.upperBound.y <= this.upperBound.y;
         return result;
      }
      b2AABB.prototype.RayCast = function (output, input) {
         var tmin = (-Number.MAX_VALUE);
         var tmax = Number.MAX_VALUE;
         var pX = input.p1.x;
         var pY = input.p1.y;
         var dX = input.p2.x - input.p1.x;
         var dY = input.p2.y - input.p1.y;
         var absDX = Math.abs(dX);
         var absDY = Math.abs(dY);
         var normal = output.normal;
         var inv_d = 0;
         var t1 = 0;
         var t2 = 0;
         var t3 = 0;
         var s = 0; {
            if (absDX < Number.MIN_VALUE) {
               if (pX < this.lowerBound.x || this.upperBound.x < pX) return false;
            }
            else {
               inv_d = 1.0 / dX;
               t1 = (this.lowerBound.x - pX) * inv_d;
               t2 = (this.upperBound.x - pX) * inv_d;
               s = (-1.0);
               if (t1 > t2) {
                  t3 = t1;
                  t1 = t2;
                  t2 = t3;
                  s = 1.0;
               }
               if (t1 > tmin) {
                  normal.x = s;
                  normal.y = 0;
                  tmin = t1;
               }
               tmax = Math.min(tmax, t2);
               if (tmin > tmax) return false;
            }
         } {
            if (absDY < Number.MIN_VALUE) {
               if (pY < this.lowerBound.y || this.upperBound.y < pY) return false;
            }
            else {
               inv_d = 1.0 / dY;
               t1 = (this.lowerBound.y - pY) * inv_d;
               t2 = (this.upperBound.y - pY) * inv_d;
               s = (-1.0);
               if (t1 > t2) {
                  t3 = t1;
                  t1 = t2;
                  t2 = t3;
                  s = 1.0;
               }
               if (t1 > tmin) {
                  normal.y = s;
                  normal.x = 0;
                  tmin = t1;
               }
               tmax = Math.min(tmax, t2);
               if (tmin > tmax) return false;
            }
         }
         output.fraction = tmin;
         return true;
      }
      b2AABB.prototype.TestOverlap = function (other) {
         var d1X = other.lowerBound.x - this.upperBound.x;
         var d1Y = other.lowerBound.y - this.upperBound.y;
         var d2X = this.lowerBound.x - other.upperBound.x;
         var d2Y = this.lowerBound.y - other.upperBound.y;
         if (d1X > 0.0 || d1Y > 0.0) return false;
         if (d2X > 0.0 || d2Y > 0.0) return false;
         return true;
      }
      b2AABB.Combine = function (aabb1, aabb2) {
         var aabb = new b2AABB();
         aabb.Combine(aabb1, aabb2);
         return aabb;
      }
      b2AABB.prototype.Combine = function (aabb1, aabb2) {
         this.lowerBound.x = Math.min(aabb1.lowerBound.x, aabb2.lowerBound.x);
         this.lowerBound.y = Math.min(aabb1.lowerBound.y, aabb2.lowerBound.y);
         this.upperBound.x = Math.max(aabb1.upperBound.x, aabb2.upperBound.x);
         this.upperBound.y = Math.max(aabb1.upperBound.y, aabb2.upperBound.y);
      }
      b2Bound.b2Bound = function () {};
      b2Bound.prototype.IsLower = function () {
         return (this.value & 1) == 0;
      }
      b2Bound.prototype.IsUpper = function () {
         return (this.value & 1) == 1;
      }
      b2Bound.prototype.Swap = function (b) {
         var tempValue = this.value;
         var tempProxy = this.proxy;
         var tempStabbingCount = this.stabbingCount;
         this.value = b.value;
         this.proxy = b.proxy;
         this.stabbingCount = b.stabbingCount;
         b.value = tempValue;
         b.proxy = tempProxy;
         b.stabbingCount = tempStabbingCount;
      }
      b2BoundValues.b2BoundValues = function () {};
      b2BoundValues.prototype.b2BoundValues = function () {
         this.lowerValues = new Vector_a2j_Number();
         this.lowerValues[0] = 0.0;
         this.lowerValues[1] = 0.0;
         this.upperValues = new Vector_a2j_Number();
         this.upperValues[0] = 0.0;
         this.upperValues[1] = 0.0;
      }
      b2Collision.b2Collision = function () {};
      b2Collision.ClipSegmentToLine = function (vOut, vIn, normal, offset) {
         if (offset === undefined) offset = 0;
         var cv;
         var numOut = 0;
         cv = vIn[0];
         var vIn0 = cv.v;
         cv = vIn[1];
         var vIn1 = cv.v;
         var distance0 = normal.x * vIn0.x + normal.y * vIn0.y - offset;
         var distance1 = normal.x * vIn1.x + normal.y * vIn1.y - offset;
         if (distance0 <= 0.0) vOut[numOut++].Set(vIn[0]);
         if (distance1 <= 0.0) vOut[numOut++].Set(vIn[1]);
         if (distance0 * distance1 < 0.0) {
            var interp = distance0 / (distance0 - distance1);
            cv = vOut[numOut];
            var tVec = cv.v;
            tVec.x = vIn0.x + interp * (vIn1.x - vIn0.x);
            tVec.y = vIn0.y + interp * (vIn1.y - vIn0.y);
            cv = vOut[numOut];
            var cv2;
            if (distance0 > 0.0) {
               cv2 = vIn[0];
               cv.id = cv2.id;
            }
            else {
               cv2 = vIn[1];
               cv.id = cv2.id;
            }++numOut;
         }
         return numOut;
      }
      b2Collision.EdgeSeparation = function (poly1, xf1, edge1, poly2, xf2) {
         if (edge1 === undefined) edge1 = 0;
         var count1 = parseInt(poly1.m_vertexCount);
         var vertices1 = poly1.m_vertices;
         var normals1 = poly1.m_normals;
         var count2 = parseInt(poly2.m_vertexCount);
         var vertices2 = poly2.m_vertices;
         var tMat;
         var tVec;
         tMat = xf1.R;
         tVec = normals1[edge1];
         var normal1WorldX = (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);
         var normal1WorldY = (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);
         tMat = xf2.R;
         var normal1X = (tMat.col1.x * normal1WorldX + tMat.col1.y * normal1WorldY);
         var normal1Y = (tMat.col2.x * normal1WorldX + tMat.col2.y * normal1WorldY);
         var index = 0;
         var minDot = Number.MAX_VALUE;
         for (var i = 0; i < count2; ++i) {
            tVec = vertices2[i];
            var dot = tVec.x * normal1X + tVec.y * normal1Y;
            if (dot < minDot) {
               minDot = dot;
               index = i;
            }
         }
         tVec = vertices1[edge1];
         tMat = xf1.R;
         var v1X = xf1.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);
         var v1Y = xf1.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);
         tVec = vertices2[index];
         tMat = xf2.R;
         var v2X = xf2.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);
         var v2Y = xf2.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);
         v2X -= v1X;
         v2Y -= v1Y;
         var separation = v2X * normal1WorldX + v2Y * normal1WorldY;
         return separation;
      }
      b2Collision.FindMaxSeparation = function (edgeIndex, poly1, xf1, poly2, xf2) {
         var count1 = parseInt(poly1.m_vertexCount);
         var normals1 = poly1.m_normals;
         var tVec;
         var tMat;
         tMat = xf2.R;
         tVec = poly2.m_centroid;
         var dX = xf2.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);
         var dY = xf2.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);
         tMat = xf1.R;
         tVec = poly1.m_centroid;
         dX -= xf1.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);
         dY -= xf1.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);
         var dLocal1X = (dX * xf1.R.col1.x + dY * xf1.R.col1.y);
         var dLocal1Y = (dX * xf1.R.col2.x + dY * xf1.R.col2.y);
         var edge = 0;
         var maxDot = (-Number.MAX_VALUE);
         for (var i = 0; i < count1; ++i) {
            tVec = normals1[i];
            var dot = (tVec.x * dLocal1X + tVec.y * dLocal1Y);
            if (dot > maxDot) {
               maxDot = dot;
               edge = i;
            }
         }
         var s = b2Collision.EdgeSeparation(poly1, xf1, edge, poly2, xf2);
         var prevEdge = parseInt(edge - 1 >= 0 ? edge - 1 : count1 - 1);
         var sPrev = b2Collision.EdgeSeparation(poly1, xf1, prevEdge, poly2, xf2);
         var nextEdge = parseInt(edge + 1 < count1 ? edge + 1 : 0);
         var sNext = b2Collision.EdgeSeparation(poly1, xf1, nextEdge, poly2, xf2);
         var bestEdge = 0;
         var bestSeparation = 0;
         var increment = 0;
         if (sPrev > s && sPrev > sNext) {
            increment = (-1);
            bestEdge = prevEdge;
            bestSeparation = sPrev;
         }
         else if (sNext > s) {
            increment = 1;
            bestEdge = nextEdge;
            bestSeparation = sNext;
         }
         else {
            edgeIndex[0] = edge;
            return s;
         }
         while (true) {  // JDM: ESLint warning = constant condition
            if (increment == (-1)) edge = bestEdge - 1 >= 0 ? bestEdge - 1 : count1 - 1;
            else edge = bestEdge + 1 < count1 ? bestEdge + 1 : 0;s = b2Collision.EdgeSeparation(poly1, xf1, edge, poly2, xf2);
            if (s > bestSeparation) {
               bestEdge = edge;
               bestSeparation = s;
            }
            else {
               break;
            }
         }
         edgeIndex[0] = bestEdge;
         return bestSeparation;
      }
      b2Collision.FindIncidentEdge = function (c, poly1, xf1, edge1, poly2, xf2) {
         if (edge1 === undefined) edge1 = 0;
         var count1 = parseInt(poly1.m_vertexCount);
         var normals1 = poly1.m_normals;
         var count2 = parseInt(poly2.m_vertexCount);
         var vertices2 = poly2.m_vertices;
         var normals2 = poly2.m_normals;
         var tMat;
         var tVec;
         tMat = xf1.R;
         tVec = normals1[edge1];
         var normal1X = (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);
         var normal1Y = (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);
         tMat = xf2.R;
         var tX = (tMat.col1.x * normal1X + tMat.col1.y * normal1Y);
         normal1Y = (tMat.col2.x * normal1X + tMat.col2.y * normal1Y);
         normal1X = tX;
         var index = 0;
         var minDot = Number.MAX_VALUE;
         for (var i = 0; i < count2; ++i) {
            tVec = normals2[i];
            var dot = (normal1X * tVec.x + normal1Y * tVec.y);
            if (dot < minDot) {
               minDot = dot;
               index = i;
            }
         }
         var tClip;
         var i1 = parseInt(index);
         var i2 = parseInt(i1 + 1 < count2 ? i1 + 1 : 0);
         tClip = c[0];
         tVec = vertices2[i1];
         tMat = xf2.R;
         tClip.v.x = xf2.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);
         tClip.v.y = xf2.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);
         tClip.id.features.referenceEdge = edge1;
         tClip.id.features.incidentEdge = i1;
         tClip.id.features.incidentVertex = 0;
         tClip = c[1];
         tVec = vertices2[i2];
         tMat = xf2.R;
         tClip.v.x = xf2.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);
         tClip.v.y = xf2.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);
         tClip.id.features.referenceEdge = edge1;
         tClip.id.features.incidentEdge = i2;
         tClip.id.features.incidentVertex = 1;
      }
      b2Collision.MakeClipPointVector = function () {
         var r = new Vector(2);
         r[0] = new ClipVertex();
         r[1] = new ClipVertex();
         return r;
      }
      b2Collision.CollidePolygons = function (manifold, polyA, xfA, polyB, xfB) {
         var cv;
         manifold.m_pointCount = 0;
         var totalRadius = polyA.m_radius + polyB.m_radius;
         var edgeA = 0;
         b2Collision.s_edgeAO[0] = edgeA;
         var separationA = b2Collision.FindMaxSeparation(b2Collision.s_edgeAO, polyA, xfA, polyB, xfB);
         edgeA = b2Collision.s_edgeAO[0];
         if (separationA > totalRadius) return;
         var edgeB = 0;
         b2Collision.s_edgeBO[0] = edgeB;
         var separationB = b2Collision.FindMaxSeparation(b2Collision.s_edgeBO, polyB, xfB, polyA, xfA);
         edgeB = b2Collision.s_edgeBO[0];
         if (separationB > totalRadius) return;
         var poly1;
         var poly2;
         var xf1;
         var xf2;
         var edge1 = 0;
         var flip = 0;
         var k_relativeTol = 0.98;
         var k_absoluteTol = 0.001;
         var tMat;
         if (separationB > k_relativeTol * separationA + k_absoluteTol) {
            poly1 = polyB;
            poly2 = polyA;
            xf1 = xfB;
            xf2 = xfA;
            edge1 = edgeB;
            manifold.m_type = b2Manifold.e_faceB;
            flip = 1;
         }
         else {
            poly1 = polyA;
            poly2 = polyB;
            xf1 = xfA;
            xf2 = xfB;
            edge1 = edgeA;
            manifold.m_type = b2Manifold.e_faceA;
            flip = 0;
         }
         var incidentEdge = b2Collision.s_incidentEdge;
         b2Collision.FindIncidentEdge(incidentEdge, poly1, xf1, edge1, poly2, xf2);
         var count1 = parseInt(poly1.m_vertexCount);
         var vertices1 = poly1.m_vertices;
         var local_v11 = vertices1[edge1];
         var local_v12;
         if (edge1 + 1 < count1) {
            local_v12 = vertices1[parseInt(edge1 + 1)];
         }
         else {
            local_v12 = vertices1[0];
         }
         var localTangent = b2Collision.s_localTangent;
         localTangent.Set(local_v12.x - local_v11.x, local_v12.y - local_v11.y);
         localTangent.Normalize();
         var localNormal = b2Collision.s_localNormal;
         localNormal.x = localTangent.y;
         localNormal.y = (-localTangent.x);
         var planePoint = b2Collision.s_planePoint;
         planePoint.Set(0.5 * (local_v11.x + local_v12.x), 0.5 * (local_v11.y + local_v12.y));
         var tangent = b2Collision.s_tangent;
         tMat = xf1.R;
         tangent.x = (tMat.col1.x * localTangent.x + tMat.col2.x * localTangent.y);
         tangent.y = (tMat.col1.y * localTangent.x + tMat.col2.y * localTangent.y);
         var tangent2 = b2Collision.s_tangent2;
         tangent2.x = (-tangent.x);
         tangent2.y = (-tangent.y);
         var normal = b2Collision.s_normal;
         normal.x = tangent.y;
         normal.y = (-tangent.x);
         var v11 = b2Collision.s_v11;
         var v12 = b2Collision.s_v12;
         v11.x = xf1.position.x + (tMat.col1.x * local_v11.x + tMat.col2.x * local_v11.y);
         v11.y = xf1.position.y + (tMat.col1.y * local_v11.x + tMat.col2.y * local_v11.y);
         v12.x = xf1.position.x + (tMat.col1.x * local_v12.x + tMat.col2.x * local_v12.y);
         v12.y = xf1.position.y + (tMat.col1.y * local_v12.x + tMat.col2.y * local_v12.y);
         var frontOffset = normal.x * v11.x + normal.y * v11.y;
         var sideOffset1 = (-tangent.x * v11.x) - tangent.y * v11.y + totalRadius;
         var sideOffset2 = tangent.x * v12.x + tangent.y * v12.y + totalRadius;
         var clipPoints1 = b2Collision.s_clipPoints1;
         var clipPoints2 = b2Collision.s_clipPoints2;
         var np = 0;
         np = b2Collision.ClipSegmentToLine(clipPoints1, incidentEdge, tangent2, sideOffset1);
         if (np < 2) return;
         np = b2Collision.ClipSegmentToLine(clipPoints2, clipPoints1, tangent, sideOffset2);
         if (np < 2) return;
         manifold.m_localPlaneNormal.SetV(localNormal);
         manifold.m_localPoint.SetV(planePoint);
         var pointCount = 0;
         for (var i = 0; i < b2Settings.b2_maxManifoldPoints; ++i) {
            cv = clipPoints2[i];
            var separation = normal.x * cv.v.x + normal.y * cv.v.y - frontOffset;
            if (separation <= totalRadius) {
               var cp = manifold.m_points[pointCount];
               tMat = xf2.R;
               var tX = cv.v.x - xf2.position.x;
               var tY = cv.v.y - xf2.position.y;
               cp.m_localPoint.x = (tX * tMat.col1.x + tY * tMat.col1.y);
               cp.m_localPoint.y = (tX * tMat.col2.x + tY * tMat.col2.y);
               cp.m_id.Set(cv.id);
               cp.m_id.features.flip = flip;
               ++pointCount;
            }
         }
         manifold.m_pointCount = pointCount;
      }
      b2Collision.CollideCircles = function (manifold, circle1, xf1, circle2, xf2) {
         manifold.m_pointCount = 0;
         var tMat;
         var tVec;
         tMat = xf1.R;
         tVec = circle1.m_p;
         var p1X = xf1.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);
         var p1Y = xf1.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);
         tMat = xf2.R;
         tVec = circle2.m_p;
         var p2X = xf2.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);
         var p2Y = xf2.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);
         var dX = p2X - p1X;
         var dY = p2Y - p1Y;
         var distSqr = dX * dX + dY * dY;
         var radius = circle1.m_radius + circle2.m_radius;
         if (distSqr > radius * radius) {
            return;
         }
         manifold.m_type = b2Manifold.e_circles;
         manifold.m_localPoint.SetV(circle1.m_p);
         manifold.m_localPlaneNormal.SetZero();
         manifold.m_pointCount = 1;
         manifold.m_points[0].m_localPoint.SetV(circle2.m_p);
         manifold.m_points[0].m_id.key = 0;
      }
      b2Collision.CollidePolygonAndCircle = function (manifold, polygon, xf1, circle, xf2) {
         manifold.m_pointCount = 0;
         var tPoint;
         var dX = 0;
         var dY = 0;
         var positionX = 0;
         var positionY = 0;
         var tVec;
         var tMat;
         tMat = xf2.R;
         tVec = circle.m_p;
         var cX = xf2.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);
         var cY = xf2.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);
         dX = cX - xf1.position.x;
         dY = cY - xf1.position.y;
         tMat = xf1.R;
         var cLocalX = (dX * tMat.col1.x + dY * tMat.col1.y);
         var cLocalY = (dX * tMat.col2.x + dY * tMat.col2.y);
         var dist = 0;
         var normalIndex = 0;
         var separation = (-Number.MAX_VALUE);
         var radius = polygon.m_radius + circle.m_radius;
         var vertexCount = parseInt(polygon.m_vertexCount);
         var vertices = polygon.m_vertices;
         var normals = polygon.m_normals;
         for (var i = 0; i < vertexCount; ++i) {
            tVec = vertices[i];
            dX = cLocalX - tVec.x;
            dY = cLocalY - tVec.y;
            tVec = normals[i];
            var s = tVec.x * dX + tVec.y * dY;
            if (s > radius) {
               return;
            }
            if (s > separation) {
               separation = s;
               normalIndex = i;
            }
         }
         var vertIndex1 = parseInt(normalIndex);
         var vertIndex2 = parseInt(vertIndex1 + 1 < vertexCount ? vertIndex1 + 1 : 0);
         var v1 = vertices[vertIndex1];
         var v2 = vertices[vertIndex2];
         if (separation < Number.MIN_VALUE) {
            manifold.m_pointCount = 1;
            manifold.m_type = b2Manifold.e_faceA;
            manifold.m_localPlaneNormal.SetV(normals[normalIndex]);
            manifold.m_localPoint.x = 0.5 * (v1.x + v2.x);
            manifold.m_localPoint.y = 0.5 * (v1.y + v2.y);
            manifold.m_points[0].m_localPoint.SetV(circle.m_p);
            manifold.m_points[0].m_id.key = 0;
            return;
         }
         var u1 = (cLocalX - v1.x) * (v2.x - v1.x) + (cLocalY - v1.y) * (v2.y - v1.y);
         var u2 = (cLocalX - v2.x) * (v1.x - v2.x) + (cLocalY - v2.y) * (v1.y - v2.y);
         if (u1 <= 0.0) {
            if ((cLocalX - v1.x) * (cLocalX - v1.x) + (cLocalY - v1.y) * (cLocalY - v1.y) > radius * radius) return;
            manifold.m_pointCount = 1;
            manifold.m_type = b2Manifold.e_faceA;
            manifold.m_localPlaneNormal.x = cLocalX - v1.x;
            manifold.m_localPlaneNormal.y = cLocalY - v1.y;
            manifold.m_localPlaneNormal.Normalize();
            manifold.m_localPoint.SetV(v1);
            manifold.m_points[0].m_localPoint.SetV(circle.m_p);
            manifold.m_points[0].m_id.key = 0;
         }
         else if (u2 <= 0) {
            if ((cLocalX - v2.x) * (cLocalX - v2.x) + (cLocalY - v2.y) * (cLocalY - v2.y) > radius * radius) return;
            manifold.m_pointCount = 1;
            manifold.m_type = b2Manifold.e_faceA;
            manifold.m_localPlaneNormal.x = cLocalX - v2.x;
            manifold.m_localPlaneNormal.y = cLocalY - v2.y;
            manifold.m_localPlaneNormal.Normalize();
            manifold.m_localPoint.SetV(v2);
            manifold.m_points[0].m_localPoint.SetV(circle.m_p);
            manifold.m_points[0].m_id.key = 0;
         }
         else {
            var faceCenterX = 0.5 * (v1.x + v2.x);
            var faceCenterY = 0.5 * (v1.y + v2.y);
            separation = (cLocalX - faceCenterX) * normals[vertIndex1].x + (cLocalY - faceCenterY) * normals[vertIndex1].y;
            if (separation > radius) return;
            manifold.m_pointCount = 1;
            manifold.m_type = b2Manifold.e_faceA;
            manifold.m_localPlaneNormal.x = normals[vertIndex1].x;
            manifold.m_localPlaneNormal.y = normals[vertIndex1].y;
            manifold.m_localPlaneNormal.Normalize();
            manifold.m_localPoint.Set(faceCenterX, faceCenterY);
            manifold.m_points[0].m_localPoint.SetV(circle.m_p);
            manifold.m_points[0].m_id.key = 0;
         }
      }
      b2Collision.TestOverlap = function (a, b) {
         var t1 = b.lowerBound;
         var t2 = a.upperBound;
         var d1X = t1.x - t2.x;
         var d1Y = t1.y - t2.y;
         t1 = a.lowerBound;
         t2 = b.upperBound;
         var d2X = t1.x - t2.x;
         var d2Y = t1.y - t2.y;
         if (d1X > 0.0 || d1Y > 0.0) return false;
         if (d2X > 0.0 || d2Y > 0.0) return false;
         return true;
      }
      Box2D.postDefs.push(function () {
         Box2D.Collision.b2Collision.s_incidentEdge = b2Collision.MakeClipPointVector();
         Box2D.Collision.b2Collision.s_clipPoints1 = b2Collision.MakeClipPointVector();
         Box2D.Collision.b2Collision.s_clipPoints2 = b2Collision.MakeClipPointVector();
         Box2D.Collision.b2Collision.s_edgeAO = new Vector_a2j_Number(1);
         Box2D.Collision.b2Collision.s_edgeBO = new Vector_a2j_Number(1);
         Box2D.Collision.b2Collision.s_localTangent = new b2Vec2();
         Box2D.Collision.b2Collision.s_localNormal = new b2Vec2();
         Box2D.Collision.b2Collision.s_planePoint = new b2Vec2();
         Box2D.Collision.b2Collision.s_normal = new b2Vec2();
         Box2D.Collision.b2Collision.s_tangent = new b2Vec2();
         Box2D.Collision.b2Collision.s_tangent2 = new b2Vec2();
         Box2D.Collision.b2Collision.s_v11 = new b2Vec2();
         Box2D.Collision.b2Collision.s_v12 = new b2Vec2();
         Box2D.Collision.b2Collision.b2CollidePolyTempVec = new b2Vec2();
         Box2D.Collision.b2Collision.b2_nullFeature = 0x000000ff;
      });
      b2ContactID.b2ContactID = function () {
         this.features = new Features();
      };
      b2ContactID.prototype.b2ContactID = function () {
         this.features._m_id = this;
      }
      b2ContactID.prototype.Set = function (id) {
         this.key = id._key;
      }
      b2ContactID.prototype.Copy = function () {
         var id = new b2ContactID();
         id.key = this.key;
         return id;
      }
      Object.defineProperty(b2ContactID.prototype, 'key', {
         enumerable: false,
         configurable: true,
         get: function () {
            return this._key;
         }
      });
      Object.defineProperty(b2ContactID.prototype, 'key', {
         enumerable: false,
         configurable: true,
         set: function (value) {
            if (value === undefined) value = 0;
            this._key = value;
            this.features._referenceEdge = this._key & 0x000000ff;
            this.features._incidentEdge = ((this._key & 0x0000ff00) >> 8) & 0x000000ff;
            this.features._incidentVertex = ((this._key & 0x00ff0000) >> 16) & 0x000000ff;
            this.features._flip = ((this._key & 0xff000000) >> 24) & 0x000000ff;
         }
      });
      b2ContactPoint.b2ContactPoint = function () {
         this.position = new b2Vec2();
         this.velocity = new b2Vec2();
         this.normal = new b2Vec2();
         this.id = new b2ContactID();
      };
      b2Distance.b2Distance = function () {};
      b2Distance.Distance = function (output, cache, input) {
         ++b2Distance.b2_gjkCalls;
         var proxyA = input.proxyA;
         var proxyB = input.proxyB;
         var transformA = input.transformA;
         var transformB = input.transformB;
         var simplex = b2Distance.s_simplex;
         simplex.ReadCache(cache, proxyA, transformA, proxyB, transformB);
         var vertices = simplex.m_vertices;
         var k_maxIters = 20;
         var saveA = b2Distance.s_saveA;
         var saveB = b2Distance.s_saveB;
         var saveCount = 0;
         var closestPoint = simplex.GetClosestPoint();
         var distanceSqr1 = closestPoint.LengthSquared();
         var distanceSqr2 = distanceSqr1;
         var i = 0;
         var p;
         var iter = 0;
         while (iter < k_maxIters) {
            saveCount = simplex.m_count;
            for (i = 0;
            i < saveCount; i++) {
               saveA[i] = vertices[i].indexA;
               saveB[i] = vertices[i].indexB;
            }
            switch (simplex.m_count) {
            case 1:
               break;
            case 2:
               simplex.Solve2();
               break;
            case 3:
               simplex.Solve3();
               break;
            default:
               b2Settings.b2Assert(false);
            }
            if (simplex.m_count == 3) {
               break;
            }
            p = simplex.GetClosestPoint();
            distanceSqr2 = p.LengthSquared();
            if (distanceSqr2 > distanceSqr1) {} // JDM: ESLint warning = empty block
            distanceSqr1 = distanceSqr2;
            var d = simplex.GetSearchDirection();
            if (d.LengthSquared() < Number.MIN_VALUE * Number.MIN_VALUE) {
               break;
            }
            var vertex = vertices[simplex.m_count];
            vertex.indexA = proxyA.GetSupport(b2Math.MulTMV(transformA.R, d.GetNegative()));
            vertex.wA = b2Math.MulX(transformA, proxyA.GetVertex(vertex.indexA));
            vertex.indexB = proxyB.GetSupport(b2Math.MulTMV(transformB.R, d));
            vertex.wB = b2Math.MulX(transformB, proxyB.GetVertex(vertex.indexB));
            vertex.w = b2Math.SubtractVV(vertex.wB, vertex.wA);
            ++iter;
            ++b2Distance.b2_gjkIters;
            var duplicate = false;
            for (i = 0;
            i < saveCount; i++) {
               if (vertex.indexA == saveA[i] && vertex.indexB == saveB[i]) {
                  duplicate = true;
                  break;
               }
            }
            if (duplicate) {
               break;
            }++simplex.m_count;
         }
         b2Distance.b2_gjkMaxIters = b2Math.Max(b2Distance.b2_gjkMaxIters, iter);
         simplex.GetWitnessPoints(output.pointA, output.pointB);
         output.distance = b2Math.SubtractVV(output.pointA, output.pointB).Length();
         output.iterations = iter;
         simplex.WriteCache(cache);
         if (input.useRadii) {
            var rA = proxyA.m_radius;
            var rB = proxyB.m_radius;
            if (output.distance > rA + rB && output.distance > Number.MIN_VALUE) {
               output.distance -= rA + rB;
               var normal = b2Math.SubtractVV(output.pointB, output.pointA);
               normal.Normalize();
               output.pointA.x += rA * normal.x;
               output.pointA.y += rA * normal.y;
               output.pointB.x -= rB * normal.x;
               output.pointB.y -= rB * normal.y;
            }
            else {
               p = new b2Vec2();
               p.x = .5 * (output.pointA.x + output.pointB.x);
               p.y = .5 * (output.pointA.y + output.pointB.y);
               output.pointA.x = output.pointB.x = p.x;
               output.pointA.y = output.pointB.y = p.y;
               output.distance = 0.0;
            }
         }
      }
      Box2D.postDefs.push(function () {
         Box2D.Collision.b2Distance.s_simplex = new b2Simplex();
         Box2D.Collision.b2Distance.s_saveA = new Vector_a2j_Number(3);
         Box2D.Collision.b2Distance.s_saveB = new Vector_a2j_Number(3);
      });
      b2DistanceInput.b2DistanceInput = function () {};
      b2DistanceOutput.b2DistanceOutput = function () {
         this.pointA = new b2Vec2();
         this.pointB = new b2Vec2();
      };
      b2DistanceProxy.b2DistanceProxy = function () {};
      b2DistanceProxy.prototype.Set = function (shape) {
         switch (shape.GetType()) {
         case b2Shape.e_circleShape:
            {
               var circle = (shape instanceof b2CircleShape ? shape : null);
               this.m_vertices = new Vector(1, true);
               this.m_vertices[0] = circle.m_p;
               this.m_count = 1;
               this.m_radius = circle.m_radius;
            }
            break;
         case b2Shape.e_polygonShape:
            {
               var polygon = (shape instanceof b2PolygonShape ? shape : null);
               this.m_vertices = polygon.m_vertices;
               this.m_count = polygon.m_vertexCount;
               this.m_radius = polygon.m_radius;
            }
            break;
         default:
            b2Settings.b2Assert(false);
         }
      }
      b2DistanceProxy.prototype.GetSupport = function (d) {
         var bestIndex = 0;
         var bestValue = this.m_vertices[0].x * d.x + this.m_vertices[0].y * d.y;
         for (var i = 1; i < this.m_count; ++i) {
            var value = this.m_vertices[i].x * d.x + this.m_vertices[i].y * d.y;
            if (value > bestValue) {
               bestIndex = i;
               bestValue = value;
            }
         }
         return bestIndex;
      }
      b2DistanceProxy.prototype.GetSupportVertex = function (d) {
         var bestIndex = 0;
         var bestValue = this.m_vertices[0].x * d.x + this.m_vertices[0].y * d.y;
         for (var i = 1; i < this.m_count; ++i) {
            var value = this.m_vertices[i].x * d.x + this.m_vertices[i].y * d.y;
            if (value > bestValue) {
               bestIndex = i;
               bestValue = value;
            }
         }
         return this.m_vertices[bestIndex];
      }
      b2DistanceProxy.prototype.GetVertexCount = function () {
         return this.m_count;
      }
      b2DistanceProxy.prototype.GetVertex = function (index) {
         if (index === undefined) index = 0;
         b2Settings.b2Assert(0 <= index && index < this.m_count);
         return this.m_vertices[index];
      }
      b2DynamicTree.b2DynamicTree = function () {};
      b2DynamicTree.prototype.b2DynamicTree = function () {
         this.m_root = null;
         this.m_freeList = null;
         this.m_path = 0;
         this.m_insertionCount = 0;
      }
      b2DynamicTree.prototype.CreateProxy = function (aabb, userData) {
         var node = this.AllocateNode();
         var extendX = b2Settings.b2_aabbExtension;
         var extendY = b2Settings.b2_aabbExtension;
         node.aabb.lowerBound.x = aabb.lowerBound.x - extendX;
         node.aabb.lowerBound.y = aabb.lowerBound.y - extendY;
         node.aabb.upperBound.x = aabb.upperBound.x + extendX;
         node.aabb.upperBound.y = aabb.upperBound.y + extendY;
         node.userData = userData;
         this.InsertLeaf(node);
         return node;
      }
      b2DynamicTree.prototype.DestroyProxy = function (proxy) {
         this.RemoveLeaf(proxy);
         this.FreeNode(proxy);
      }
      b2DynamicTree.prototype.MoveProxy = function (proxy, aabb, displacement) {
         b2Settings.b2Assert(proxy.IsLeaf());
         if (proxy.aabb.Contains(aabb)) {
            return false;
         }
         this.RemoveLeaf(proxy);
         var extendX = b2Settings.b2_aabbExtension + b2Settings.b2_aabbMultiplier * (displacement.x > 0 ? displacement.x : (-displacement.x));
         var extendY = b2Settings.b2_aabbExtension + b2Settings.b2_aabbMultiplier * (displacement.y > 0 ? displacement.y : (-displacement.y));
         proxy.aabb.lowerBound.x = aabb.lowerBound.x - extendX;
         proxy.aabb.lowerBound.y = aabb.lowerBound.y - extendY;
         proxy.aabb.upperBound.x = aabb.upperBound.x + extendX;
         proxy.aabb.upperBound.y = aabb.upperBound.y + extendY;
         this.InsertLeaf(proxy);
         return true;
      }
      b2DynamicTree.prototype.Rebalance = function (iterations) {
         if (iterations === undefined) iterations = 0;
         if (this.m_root == null) return;
         for (var i = 0; i < iterations; i++) {
            var node = this.m_root;
            var bit = 0;
            while (node.IsLeaf() == false) {
               node = (this.m_path >> bit) & 1 ? node.child2 : node.child1;
               bit = (bit + 1) & 31;
            }++this.m_path;
            this.RemoveLeaf(node);
            this.InsertLeaf(node);
         }
      }
      b2DynamicTree.prototype.GetFatAABB = function (proxy) {
         return proxy.aabb;
      }
      b2DynamicTree.prototype.GetUserData = function (proxy) {
         return proxy.userData;
      }
      b2DynamicTree.prototype.Query = function (callback, aabb) {
         if (this.m_root == null) return;
         var stack = new Vector();
         var count = 0;
         stack[count++] = this.m_root;
         while (count > 0) {
            var node = stack[--count];
            if (node.aabb.TestOverlap(aabb)) {
               if (node.IsLeaf()) {
                  var proceed = callback(node);
                  if (!proceed) return;
               }
               else {
                  stack[count++] = node.child1;
                  stack[count++] = node.child2;
               }
            }
         }
      }
      b2DynamicTree.prototype.RayCast = function (callback, input) {
         if (this.m_root == null) return;
         var p1 = input.p1;
         var p2 = input.p2;
         var r = b2Math.SubtractVV(p1, p2);
         r.Normalize();
         var v = b2Math.CrossFV(1.0, r);
         var abs_v = b2Math.AbsV(v);
         var maxFraction = input.maxFraction;
         var segmentAABB = new b2AABB();
         var tX = 0;
         var tY = 0; {
            tX = p1.x + maxFraction * (p2.x - p1.x);
            tY = p1.y + maxFraction * (p2.y - p1.y);
            segmentAABB.lowerBound.x = Math.min(p1.x, tX);
            segmentAABB.lowerBound.y = Math.min(p1.y, tY);
            segmentAABB.upperBound.x = Math.max(p1.x, tX);
            segmentAABB.upperBound.y = Math.max(p1.y, tY);
         }
         var stack = new Vector();
         var count = 0;
         stack[count++] = this.m_root;
         while (count > 0) {
            var node = stack[--count];
            if (node.aabb.TestOverlap(segmentAABB) == false) {
               continue;
            }
            var c = node.aabb.GetCenter();
            var h = node.aabb.GetExtents();
            var separation = Math.abs(v.x * (p1.x - c.x) + v.y * (p1.y - c.y)) - abs_v.x * h.x - abs_v.y * h.y;
            if (separation > 0.0) continue;
            if (node.IsLeaf()) {
               var subInput = new b2RayCastInput();
               subInput.p1 = input.p1;
               subInput.p2 = input.p2;
               subInput.maxFraction = input.maxFraction;
               maxFraction = callback(subInput, node);
               if (maxFraction == 0.0) return;
               if (maxFraction > 0.0) {
                  tX = p1.x + maxFraction * (p2.x - p1.x);
                  tY = p1.y + maxFraction * (p2.y - p1.y);
                  segmentAABB.lowerBound.x = Math.min(p1.x, tX);
                  segmentAABB.lowerBound.y = Math.min(p1.y, tY);
                  segmentAABB.upperBound.x = Math.max(p1.x, tX);
                  segmentAABB.upperBound.y = Math.max(p1.y, tY);
               }
            }
            else {
               stack[count++] = node.child1;
               stack[count++] = node.child2;
            }
         }
      }
      b2DynamicTree.prototype.AllocateNode = function () {
         if (this.m_freeList) {
            var node = this.m_freeList;
            this.m_freeList = node.parent;
            node.parent = null;
            node.child1 = null;
            node.child2 = null;
            return node;
         }
         return new b2DynamicTreeNode();
      }
      b2DynamicTree.prototype.FreeNode = function (node) {
         node.parent = this.m_freeList;
         this.m_freeList = node;
      }
      b2DynamicTree.prototype.InsertLeaf = function (leaf) {
         ++this.m_insertionCount;
         if (this.m_root == null) {
            this.m_root = leaf;
            this.m_root.parent = null;
            return;
         }
         var center = leaf.aabb.GetCenter();
         var sibling = this.m_root;
         if (sibling.IsLeaf() == false) {
            do {
               var child1 = sibling.child1;
               var child2 = sibling.child2;
               var norm1 = Math.abs((child1.aabb.lowerBound.x + child1.aabb.upperBound.x) / 2 - center.x) + Math.abs((child1.aabb.lowerBound.y + child1.aabb.upperBound.y) / 2 - center.y);
               var norm2 = Math.abs((child2.aabb.lowerBound.x + child2.aabb.upperBound.x) / 2 - center.x) + Math.abs((child2.aabb.lowerBound.y + child2.aabb.upperBound.y) / 2 - center.y);
               if (norm1 < norm2) {
                  sibling = child1;
               }
               else {
                  sibling = child2;
               }
            }
            while (sibling.IsLeaf() == false)
         }
         var node1 = sibling.parent;
         var node2 = this.AllocateNode();
         node2.parent = node1;
         node2.userData = null;
         node2.aabb.Combine(leaf.aabb, sibling.aabb);
         if (node1) {
            if (sibling.parent.child1 == sibling) {
               node1.child1 = node2;
            }
            else {
               node1.child2 = node2;
            }
            node2.child1 = sibling;
            node2.child2 = leaf;
            sibling.parent = node2;
            leaf.parent = node2;
            do {
               if (node1.aabb.Contains(node2.aabb)) break;
               node1.aabb.Combine(node1.child1.aabb, node1.child2.aabb);
               node2 = node1;
               node1 = node1.parent;
            }
            while (node1)
         }
         else {
            node2.child1 = sibling;
            node2.child2 = leaf;
            sibling.parent = node2;
            leaf.parent = node2;
            this.m_root = node2;
         }
      }
      b2DynamicTree.prototype.RemoveLeaf = function (leaf) {
         if (leaf == this.m_root) {
            this.m_root = null;
            return;
         }
         var node2 = leaf.parent;
         var node1 = node2.parent;
         var sibling;
         if (node2.child1 == leaf) {
            sibling = node2.child2;
         }
         else {
            sibling = node2.child1;
         }
         if (node1) {
            if (node1.child1 == node2) {
               node1.child1 = sibling;
            }
            else {
               node1.child2 = sibling;
            }
            sibling.parent = node1;
            this.FreeNode(node2);
            while (node1) {
               var oldAABB = node1.aabb;
               node1.aabb = b2AABB.Combine(node1.child1.aabb, node1.child2.aabb);
               if (oldAABB.Contains(node1.aabb)) break;
               node1 = node1.parent;
            }
         }
         else {
            this.m_root = sibling;
            sibling.parent = null;
            this.FreeNode(node2);
         }
      }
      b2DynamicTreeBroadPhase.b2DynamicTreeBroadPhase = function () {
         this.m_tree = new b2DynamicTree();
         this.m_moveBuffer = new Vector();
         this.m_pairBuffer = new Vector();
         this.m_pairCount = 0;
      };
      b2DynamicTreeBroadPhase.prototype.CreateProxy = function (aabb, userData) {
         var proxy = this.m_tree.CreateProxy(aabb, userData);
         ++this.m_proxyCount;
         this.BufferMove(proxy);
         return proxy;
      }
      b2DynamicTreeBroadPhase.prototype.DestroyProxy = function (proxy) {
         this.UnBufferMove(proxy);
         --this.m_proxyCount;
         this.m_tree.DestroyProxy(proxy);
      }
      b2DynamicTreeBroadPhase.prototype.MoveProxy = function (proxy, aabb, displacement) {
         var buffer = this.m_tree.MoveProxy(proxy, aabb, displacement);
         if (buffer) {
            this.BufferMove(proxy);
         }
      }
      b2DynamicTreeBroadPhase.prototype.TestOverlap = function (proxyA, proxyB) {
         var aabbA = this.m_tree.GetFatAABB(proxyA);
         var aabbB = this.m_tree.GetFatAABB(proxyB);
         return aabbA.TestOverlap(aabbB);
      }
      b2DynamicTreeBroadPhase.prototype.GetUserData = function (proxy) {
         return this.m_tree.GetUserData(proxy);
      }
      b2DynamicTreeBroadPhase.prototype.GetFatAABB = function (proxy) {
         return this.m_tree.GetFatAABB(proxy);
      }
      b2DynamicTreeBroadPhase.prototype.GetProxyCount = function () {
         return this.m_proxyCount;
      }
      b2DynamicTreeBroadPhase.prototype.UpdatePairs = function (callback) {
         var __this = this;
         __this.m_pairCount = 0;
         var i = 0,
            queryProxy;
         for (i = 0;
         i < __this.m_moveBuffer.length; ++i) {
            queryProxy = __this.m_moveBuffer[i];

            function QueryCallback(proxy) {  // JDM: ESLint warning = Move function declaration to function body root.
               if (proxy == queryProxy) return true;
               if (__this.m_pairCount == __this.m_pairBuffer.length) {
                  __this.m_pairBuffer[__this.m_pairCount] = new b2DynamicTreePair();
               }
               var pair = __this.m_pairBuffer[__this.m_pairCount];
               pair.proxyA = proxy < queryProxy ? proxy : queryProxy;
               pair.proxyB = proxy >= queryProxy ? proxy : queryProxy;++__this.m_pairCount;
               return true;
            };
            var fatAABB = __this.m_tree.GetFatAABB(queryProxy);
            __this.m_tree.Query(QueryCallback, fatAABB);
         }
         __this.m_moveBuffer.length = 0;
         for (var i = 0; i < __this.m_pairCount;) { // JDM: ESLint warning = i is already defined
            var primaryPair = __this.m_pairBuffer[i];
            var userDataA = __this.m_tree.GetUserData(primaryPair.proxyA);
            var userDataB = __this.m_tree.GetUserData(primaryPair.proxyB);
            callback(userDataA, userDataB);
            ++i;
            while (i < __this.m_pairCount) {
               var pair = __this.m_pairBuffer[i];
               if (pair.proxyA != primaryPair.proxyA || pair.proxyB != primaryPair.proxyB) {
                  break;
               }++i;
            }
         }
      }
      b2DynamicTreeBroadPhase.prototype.Query = function (callback, aabb) {
         this.m_tree.Query(callback, aabb);
      }
      b2DynamicTreeBroadPhase.prototype.RayCast = function (callback, input) {
         this.m_tree.RayCast(callback, input);
      }
      b2DynamicTreeBroadPhase.prototype.Validate = function () {}
      b2DynamicTreeBroadPhase.prototype.Rebalance = function (iterations) {
         if (iterations === undefined) iterations = 0;
         this.m_tree.Rebalance(iterations);
      }
      b2DynamicTreeBroadPhase.prototype.BufferMove = function (proxy) {
         this.m_moveBuffer[this.m_moveBuffer.length] = proxy;
      }
      b2DynamicTreeBroadPhase.prototype.UnBufferMove = function (proxy) {
         var i = parseInt(this.m_moveBuffer.indexOf(proxy));
         this.m_moveBuffer.splice(i, 1);
      }
      b2DynamicTreeBroadPhase.prototype.ComparePairs = function (pair1, pair2) {
         return 0;
      }
      b2DynamicTreeBroadPhase.__implements = {};
      b2DynamicTreeBroadPhase.__implements[IBroadPhase] = true;
      b2DynamicTreeNode.b2DynamicTreeNode = function () {
         this.aabb = new b2AABB();
      };
      b2DynamicTreeNode.prototype.IsLeaf = function () {
         return this.child1 == null;
      }
      b2DynamicTreePair.b2DynamicTreePair = function () {};
      b2Manifold.b2Manifold = function () {
         this.m_pointCount = 0;
      };
      b2Manifold.prototype.b2Manifold = function () {
         this.m_points = new Vector(b2Settings.b2_maxManifoldPoints);
         for (var i = 0; i < b2Settings.b2_maxManifoldPoints; i++) {
            this.m_points[i] = new b2ManifoldPoint();
         }
         this.m_localPlaneNormal = new b2Vec2();
         this.m_localPoint = new b2Vec2();
      }
      b2Manifold.prototype.Reset = function () {
         for (var i = 0; i < b2Settings.b2_maxManifoldPoints; i++) {
            ((this.m_points[i] instanceof b2ManifoldPoint ? this.m_points[i] : null)).Reset();
         }
         this.m_localPlaneNormal.SetZero();
         this.m_localPoint.SetZero();
         this.m_type = 0;
         this.m_pointCount = 0;
      }
      b2Manifold.prototype.Set = function (m) {
         this.m_pointCount = m.m_pointCount;
         for (var i = 0; i < b2Settings.b2_maxManifoldPoints; i++) {
            ((this.m_points[i] instanceof b2ManifoldPoint ? this.m_points[i] : null)).Set(m.m_points[i]);
         }
         this.m_localPlaneNormal.SetV(m.m_localPlaneNormal);
         this.m_localPoint.SetV(m.m_localPoint);
         this.m_type = m.m_type;
      }
      b2Manifold.prototype.Copy = function () {
         var copy = new b2Manifold();
         copy.Set(this);
         return copy;
      }
      Box2D.postDefs.push(function () {
         Box2D.Collision.b2Manifold.e_circles = 0x0001;
         Box2D.Collision.b2Manifold.e_faceA = 0x0002;
         Box2D.Collision.b2Manifold.e_faceB = 0x0004;
      });
      b2ManifoldPoint.b2ManifoldPoint = function () {
         this.m_localPoint = new b2Vec2();
         this.m_id = new b2ContactID();
      };
      b2ManifoldPoint.prototype.b2ManifoldPoint = function () {
         this.Reset();
      }
      b2ManifoldPoint.prototype.Reset = function () {
         this.m_localPoint.SetZero();
         this.m_normalImpulse = 0.0;
         this.m_tangentImpulse = 0.0;
         this.m_id.key = 0;
      }
      b2ManifoldPoint.prototype.Set = function (m) {
         this.m_localPoint.SetV(m.m_localPoint);
         this.m_normalImpulse = m.m_normalImpulse;
         this.m_tangentImpulse = m.m_tangentImpulse;
         this.m_id.Set(m.m_id);
      }
      b2Point.b2Point = function () {
         this.p = new b2Vec2();
      };
      b2Point.prototype.Support = function (xf, vX, vY) {
         if (vX === undefined) vX = 0;
         if (vY === undefined) vY = 0;
         return this.p;
      }
      b2Point.prototype.GetFirstVertex = function (xf) {
         return this.p;
      }
      b2RayCastInput.b2RayCastInput = function () {
         this.p1 = new b2Vec2();
         this.p2 = new b2Vec2();
      };
      b2RayCastInput.prototype.b2RayCastInput = function (p1, p2, maxFraction) {
         if (p1 === undefined) p1 = null;
         if (p2 === undefined) p2 = null;
         if (maxFraction === undefined) maxFraction = 1;
         if (p1) this.p1.SetV(p1);
         if (p2) this.p2.SetV(p2);
         this.maxFraction = maxFraction;
      }
      b2RayCastOutput.b2RayCastOutput = function () {
         this.normal = new b2Vec2();
      };
      b2Segment.b2Segment = function () {
         this.p1 = new b2Vec2();
         this.p2 = new b2Vec2();
      };
      b2Segment.prototype.TestSegment = function (lambda, normal, segment, maxLambda) {
         if (maxLambda === undefined) maxLambda = 0;
         var s = segment.p1;
         var rX = segment.p2.x - s.x;
         var rY = segment.p2.y - s.y;
         var dX = this.p2.x - this.p1.x;
         var dY = this.p2.y - this.p1.y;
         var nX = dY;
         var nY = (-dX);
         var k_slop = 100.0 * Number.MIN_VALUE;
         var denom = (-(rX * nX + rY * nY));
         if (denom > k_slop) {
            var bX = s.x - this.p1.x;
            var bY = s.y - this.p1.y;
            var a = (bX * nX + bY * nY);
            if (0.0 <= a && a <= maxLambda * denom) {
               var mu2 = (-rX * bY) + rY * bX;
               if ((-k_slop * denom) <= mu2 && mu2 <= denom * (1.0 + k_slop)) {
                  a /= denom;
                  var nLen = Math.sqrt(nX * nX + nY * nY);
                  nX /= nLen;
                  nY /= nLen;
                  lambda[0] = a;
                  normal.Set(nX, nY);
                  return true;
               }
            }
         }
         return false;
      }
      b2Segment.prototype.Extend = function (aabb) {
         this.ExtendForward(aabb);
         this.ExtendBackward(aabb);
      }
      b2Segment.prototype.ExtendForward = function (aabb) {
         var dX = this.p2.x - this.p1.x;
         var dY = this.p2.y - this.p1.y;
         var lambda = Math.min(dX > 0 ? (aabb.upperBound.x - this.p1.x) / dX : dX < 0 ? (aabb.lowerBound.x - this.p1.x) / dX : Number.POSITIVE_INFINITY,
         dY > 0 ? (aabb.upperBound.y - this.p1.y) / dY : dY < 0 ? (aabb.lowerBound.y - this.p1.y) / dY : Number.POSITIVE_INFINITY);
         this.p2.x = this.p1.x + dX * lambda;
         this.p2.y = this.p1.y + dY * lambda;
      }
      b2Segment.prototype.ExtendBackward = function (aabb) {
         var dX = (-this.p2.x) + this.p1.x;
         var dY = (-this.p2.y) + this.p1.y;
         var lambda = Math.min(dX > 0 ? (aabb.upperBound.x - this.p2.x) / dX : dX < 0 ? (aabb.lowerBound.x - this.p2.x) / dX : Number.POSITIVE_INFINITY,
         dY > 0 ? (aabb.upperBound.y - this.p2.y) / dY : dY < 0 ? (aabb.lowerBound.y - this.p2.y) / dY : Number.POSITIVE_INFINITY);
         this.p1.x = this.p2.x + dX * lambda;
         this.p1.y = this.p2.y + dY * lambda;
      }
      b2SeparationFunction.b2SeparationFunction = function () {
         this.m_localPoint = new b2Vec2();
         this.m_axis = new b2Vec2();
      };
      b2SeparationFunction.prototype.Initialize = function (cache, proxyA, transformA, proxyB, transformB) {
         this.m_proxyA = proxyA;
         this.m_proxyB = proxyB;
         var count = parseInt(cache.count);
         b2Settings.b2Assert(0 < count && count < 3);
         var localPointA;
         var localPointA1;
         var localPointA2;
         var localPointB;
         var localPointB1;
         var localPointB2;
         var pointAX = 0;
         var pointAY = 0;
         var pointBX = 0;
         var pointBY = 0;
         var normalX = 0;
         var normalY = 0;
         var tMat;
         var tVec;
         var s = 0;
         var sgn = 0;
         if (count == 1) {
            this.m_type = b2SeparationFunction.e_points;
            localPointA = this.m_proxyA.GetVertex(cache.indexA[0]);
            localPointB = this.m_proxyB.GetVertex(cache.indexB[0]);
            tVec = localPointA;
            tMat = transformA.R;
            pointAX = transformA.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);
            pointAY = transformA.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);
            tVec = localPointB;
            tMat = transformB.R;
            pointBX = transformB.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);
            pointBY = transformB.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);
            this.m_axis.x = pointBX - pointAX;
            this.m_axis.y = pointBY - pointAY;
            this.m_axis.Normalize();
         }
         else if (cache.indexB[0] == cache.indexB[1]) {
            this.m_type = b2SeparationFunction.e_faceA;
            localPointA1 = this.m_proxyA.GetVertex(cache.indexA[0]);
            localPointA2 = this.m_proxyA.GetVertex(cache.indexA[1]);
            localPointB = this.m_proxyB.GetVertex(cache.indexB[0]);
            this.m_localPoint.x = 0.5 * (localPointA1.x + localPointA2.x);
            this.m_localPoint.y = 0.5 * (localPointA1.y + localPointA2.y);
            this.m_axis = b2Math.CrossVF(b2Math.SubtractVV(localPointA2, localPointA1), 1.0);
            this.m_axis.Normalize();
            tVec = this.m_axis;
            tMat = transformA.R;
            normalX = tMat.col1.x * tVec.x + tMat.col2.x * tVec.y;
            normalY = tMat.col1.y * tVec.x + tMat.col2.y * tVec.y;
            tVec = this.m_localPoint;
            tMat = transformA.R;
            pointAX = transformA.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);
            pointAY = transformA.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);
            tVec = localPointB;
            tMat = transformB.R;
            pointBX = transformB.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);
            pointBY = transformB.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);
            s = (pointBX - pointAX) * normalX + (pointBY - pointAY) * normalY;
            if (s < 0.0) {
               this.m_axis.NegativeSelf();
            }
         }
         else if (cache.indexA[0] == cache.indexA[0]) {
            this.m_type = b2SeparationFunction.e_faceB;
            localPointB1 = this.m_proxyB.GetVertex(cache.indexB[0]);
            localPointB2 = this.m_proxyB.GetVertex(cache.indexB[1]);
            localPointA = this.m_proxyA.GetVertex(cache.indexA[0]);
            this.m_localPoint.x = 0.5 * (localPointB1.x + localPointB2.x);
            this.m_localPoint.y = 0.5 * (localPointB1.y + localPointB2.y);
            this.m_axis = b2Math.CrossVF(b2Math.SubtractVV(localPointB2, localPointB1), 1.0);
            this.m_axis.Normalize();
            tVec = this.m_axis;
            tMat = transformB.R;
            normalX = tMat.col1.x * tVec.x + tMat.col2.x * tVec.y;
            normalY = tMat.col1.y * tVec.x + tMat.col2.y * tVec.y;
            tVec = this.m_localPoint;
            tMat = transformB.R;
            pointBX = transformB.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);
            pointBY = transformB.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);
            tVec = localPointA;
            tMat = transformA.R;
            pointAX = transformA.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);
            pointAY = transformA.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);
            s = (pointAX - pointBX) * normalX + (pointAY - pointBY) * normalY;
            if (s < 0.0) {
               this.m_axis.NegativeSelf();
            }
         }
         else {
            localPointA1 = this.m_proxyA.GetVertex(cache.indexA[0]);
            localPointA2 = this.m_proxyA.GetVertex(cache.indexA[1]);
            localPointB1 = this.m_proxyB.GetVertex(cache.indexB[0]);
            localPointB2 = this.m_proxyB.GetVertex(cache.indexB[1]);
            var pA = b2Math.MulX(transformA, localPointA);
            var dA = b2Math.MulMV(transformA.R, b2Math.SubtractVV(localPointA2, localPointA1));
            var pB = b2Math.MulX(transformB, localPointB);
            var dB = b2Math.MulMV(transformB.R, b2Math.SubtractVV(localPointB2, localPointB1));
            var a = dA.x * dA.x + dA.y * dA.y;
            var e = dB.x * dB.x + dB.y * dB.y;
            var r = b2Math.SubtractVV(dB, dA);
            var c = dA.x * r.x + dA.y * r.y;
            var f = dB.x * r.x + dB.y * r.y;
            var b = dA.x * dB.x + dA.y * dB.y;
            var denom = a * e - b * b;
            s = 0.0;
            if (denom != 0.0) {
               s = b2Math.Clamp((b * f - c * e) / denom, 0.0, 1.0);
            }
            var t = (b * s + f) / e;
            if (t < 0.0) {
               t = 0.0;
               s = b2Math.Clamp((b - c) / a, 0.0, 1.0);
            }
            localPointA = new b2Vec2();
            localPointA.x = localPointA1.x + s * (localPointA2.x - localPointA1.x);
            localPointA.y = localPointA1.y + s * (localPointA2.y - localPointA1.y);
            localPointB = new b2Vec2();
            localPointB.x = localPointB1.x + s * (localPointB2.x - localPointB1.x);
            localPointB.y = localPointB1.y + s * (localPointB2.y - localPointB1.y);
            if (s == 0.0 || s == 1.0) {
               this.m_type = b2SeparationFunction.e_faceB;
               this.m_axis = b2Math.CrossVF(b2Math.SubtractVV(localPointB2, localPointB1), 1.0);
               this.m_axis.Normalize();
               this.m_localPoint = localPointB;
               tVec = this.m_axis;
               tMat = transformB.R;
               normalX = tMat.col1.x * tVec.x + tMat.col2.x * tVec.y;
               normalY = tMat.col1.y * tVec.x + tMat.col2.y * tVec.y;
               tVec = this.m_localPoint;
               tMat = transformB.R;
               pointBX = transformB.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);
               pointBY = transformB.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);
               tVec = localPointA;
               tMat = transformA.R;
               pointAX = transformA.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);
               pointAY = transformA.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);
               sgn = (pointAX - pointBX) * normalX + (pointAY - pointBY) * normalY;
               if (s < 0.0) {
                  this.m_axis.NegativeSelf();
               }
            }
            else {
               this.m_type = b2SeparationFunction.e_faceA;
               this.m_axis = b2Math.CrossVF(b2Math.SubtractVV(localPointA2, localPointA1), 1.0);
               this.m_localPoint = localPointA;
               tVec = this.m_axis;
               tMat = transformA.R;
               normalX = tMat.col1.x * tVec.x + tMat.col2.x * tVec.y;
               normalY = tMat.col1.y * tVec.x + tMat.col2.y * tVec.y;
               tVec = this.m_localPoint;
               tMat = transformA.R;
               pointAX = transformA.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);
               pointAY = transformA.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);
               tVec = localPointB;
               tMat = transformB.R;
               pointBX = transformB.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);
               pointBY = transformB.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);
               sgn = (pointBX - pointAX) * normalX + (pointBY - pointAY) * normalY;
               if (s < 0.0) {
                  this.m_axis.NegativeSelf();
               }
            }
         }
      }
      b2SeparationFunction.prototype.Evaluate = function (transformA, transformB) {
         var axisA;
         var axisB;
         var localPointA;
         var localPointB;
         var pointA;
         var pointB;
         var seperation = 0;
         var normal;
         switch (this.m_type) {
         case b2SeparationFunction.e_points:
            {
               axisA = b2Math.MulTMV(transformA.R, this.m_axis);
               axisB = b2Math.MulTMV(transformB.R, this.m_axis.GetNegative());
               localPointA = this.m_proxyA.GetSupportVertex(axisA);
               localPointB = this.m_proxyB.GetSupportVertex(axisB);
               pointA = b2Math.MulX(transformA, localPointA);
               pointB = b2Math.MulX(transformB, localPointB);
               seperation = (pointB.x - pointA.x) * this.m_axis.x + (pointB.y - pointA.y) * this.m_axis.y;
               return seperation;
            }
         case b2SeparationFunction.e_faceA:
            {
               normal = b2Math.MulMV(transformA.R, this.m_axis);
               pointA = b2Math.MulX(transformA, this.m_localPoint);
               axisB = b2Math.MulTMV(transformB.R, normal.GetNegative());
               localPointB = this.m_proxyB.GetSupportVertex(axisB);
               pointB = b2Math.MulX(transformB, localPointB);
               seperation = (pointB.x - pointA.x) * normal.x + (pointB.y - pointA.y) * normal.y;
               return seperation;
            }
         case b2SeparationFunction.e_faceB:
            {
               normal = b2Math.MulMV(transformB.R, this.m_axis);
               pointB = b2Math.MulX(transformB, this.m_localPoint);
               axisA = b2Math.MulTMV(transformA.R, normal.GetNegative());
               localPointA = this.m_proxyA.GetSupportVertex(axisA);
               pointA = b2Math.MulX(transformA, localPointA);
               seperation = (pointA.x - pointB.x) * normal.x + (pointA.y - pointB.y) * normal.y;
               return seperation;
            }
         default:
            b2Settings.b2Assert(false);
            return 0.0;
         }
      }
      Box2D.postDefs.push(function () {
         Box2D.Collision.b2SeparationFunction.e_points = 0x01;
         Box2D.Collision.b2SeparationFunction.e_faceA = 0x02;
         Box2D.Collision.b2SeparationFunction.e_faceB = 0x04;
      });
      b2Simplex.b2Simplex = function () {
         this.m_v1 = new b2SimplexVertex();
         this.m_v2 = new b2SimplexVertex();
         this.m_v3 = new b2SimplexVertex();
         this.m_vertices = new Vector(3);
      };
      b2Simplex.prototype.b2Simplex = function () {
         this.m_vertices[0] = this.m_v1;
         this.m_vertices[1] = this.m_v2;
         this.m_vertices[2] = this.m_v3;
      }
      b2Simplex.prototype.ReadCache = function (cache, proxyA, transformA, proxyB, transformB) {
         b2Settings.b2Assert(0 <= cache.count && cache.count <= 3);
         var wALocal;
         var wBLocal;
         this.m_count = cache.count;
         var vertices = this.m_vertices;
         for (var i = 0; i < this.m_count; i++) {
            var v = vertices[i];
            v.indexA = cache.indexA[i];
            v.indexB = cache.indexB[i];
            wALocal = proxyA.GetVertex(v.indexA);
            wBLocal = proxyB.GetVertex(v.indexB);
            v.wA = b2Math.MulX(transformA, wALocal);
            v.wB = b2Math.MulX(transformB, wBLocal);
            v.w = b2Math.SubtractVV(v.wB, v.wA);
            v.a = 0;
         }
         if (this.m_count > 1) {
            var metric1 = cache.metric;
            var metric2 = this.GetMetric();
            if (metric2 < .5 * metric1 || 2.0 * metric1 < metric2 || metric2 < Number.MIN_VALUE) {
               this.m_count = 0;
            }
         }
         if (this.m_count == 0) {
            v = vertices[0];
            v.indexA = 0;
            v.indexB = 0;
            wALocal = proxyA.GetVertex(0);
            wBLocal = proxyB.GetVertex(0);
            v.wA = b2Math.MulX(transformA, wALocal);
            v.wB = b2Math.MulX(transformB, wBLocal);
            v.w = b2Math.SubtractVV(v.wB, v.wA);
            this.m_count = 1;
         }
      }
      b2Simplex.prototype.WriteCache = function (cache) {
         cache.metric = this.GetMetric();
         cache.count = Box2D.parseUInt(this.m_count);
         var vertices = this.m_vertices;
         for (var i = 0; i < this.m_count; i++) {
            cache.indexA[i] = Box2D.parseUInt(vertices[i].indexA);
            cache.indexB[i] = Box2D.parseUInt(vertices[i].indexB);
         }
      }
      b2Simplex.prototype.GetSearchDirection = function () {
         switch (this.m_count) {
         case 1:
            return this.m_v1.w.GetNegative();
         case 2:
            {
               var e12 = b2Math.SubtractVV(this.m_v2.w, this.m_v1.w);
               var sgn = b2Math.CrossVV(e12, this.m_v1.w.GetNegative());
               if (sgn > 0.0) {
                  return b2Math.CrossFV(1.0, e12);
               }
               else {
                  return b2Math.CrossVF(e12, 1.0);
               }
            }
         default:
            b2Settings.b2Assert(false);
            return new b2Vec2();
         }
      }
      b2Simplex.prototype.GetClosestPoint = function () {
         switch (this.m_count) {
         case 0:
            b2Settings.b2Assert(false);
            return new b2Vec2();
         case 1:
            return this.m_v1.w;
         case 2:
            return new b2Vec2(this.m_v1.a * this.m_v1.w.x + this.m_v2.a * this.m_v2.w.x, this.m_v1.a * this.m_v1.w.y + this.m_v2.a * this.m_v2.w.y);
         default:
            b2Settings.b2Assert(false);
            return new b2Vec2();
         }
      }
      b2Simplex.prototype.GetWitnessPoints = function (pA, pB) {
         switch (this.m_count) {
         case 0:
            b2Settings.b2Assert(false);
            break;
         case 1:
            pA.SetV(this.m_v1.wA);
            pB.SetV(this.m_v1.wB);
            break;
         case 2:
            pA.x = this.m_v1.a * this.m_v1.wA.x + this.m_v2.a * this.m_v2.wA.x;
            pA.y = this.m_v1.a * this.m_v1.wA.y + this.m_v2.a * this.m_v2.wA.y;
            pB.x = this.m_v1.a * this.m_v1.wB.x + this.m_v2.a * this.m_v2.wB.x;
            pB.y = this.m_v1.a * this.m_v1.wB.y + this.m_v2.a * this.m_v2.wB.y;
            break;
         case 3:
            pB.x = pA.x = this.m_v1.a * this.m_v1.wA.x + this.m_v2.a * this.m_v2.wA.x + this.m_v3.a * this.m_v3.wA.x;
            pB.y = pA.y = this.m_v1.a * this.m_v1.wA.y + this.m_v2.a * this.m_v2.wA.y + this.m_v3.a * this.m_v3.wA.y;
            break;
         default:
            b2Settings.b2Assert(false);
            break;
         }
      }
      b2Simplex.prototype.GetMetric = function () {
         switch (this.m_count) {
         case 0:
            b2Settings.b2Assert(false);
            return 0.0;
         case 1:
            return 0.0;
         case 2:
            return b2Math.SubtractVV(this.m_v1.w, this.m_v2.w).Length();
         case 3:
            return b2Math.CrossVV(b2Math.SubtractVV(this.m_v2.w, this.m_v1.w), b2Math.SubtractVV(this.m_v3.w, this.m_v1.w));
         default:
            b2Settings.b2Assert(false);
            return 0.0;
         }
      }
      b2Simplex.prototype.Solve2 = function () {
         var w1 = this.m_v1.w;
         var w2 = this.m_v2.w;
         var e12 = b2Math.SubtractVV(w2, w1);
         var d12_2 = (-(w1.x * e12.x + w1.y * e12.y));
         if (d12_2 <= 0.0) {
            this.m_v1.a = 1.0;
            this.m_count = 1;
            return;
         }
         var d12_1 = (w2.x * e12.x + w2.y * e12.y);
         if (d12_1 <= 0.0) {
            this.m_v2.a = 1.0;
            this.m_count = 1;
            this.m_v1.Set(this.m_v2);
            return;
         }
         var inv_d12 = 1.0 / (d12_1 + d12_2);
         this.m_v1.a = d12_1 * inv_d12;
         this.m_v2.a = d12_2 * inv_d12;
         this.m_count = 2;
      }
      b2Simplex.prototype.Solve3 = function () {
         var w1 = this.m_v1.w;
         var w2 = this.m_v2.w;
         var w3 = this.m_v3.w;
         var e12 = b2Math.SubtractVV(w2, w1);
         var w1e12 = b2Math.Dot(w1, e12);
         var w2e12 = b2Math.Dot(w2, e12);
         var d12_1 = w2e12;
         var d12_2 = (-w1e12);
         var e13 = b2Math.SubtractVV(w3, w1);
         var w1e13 = b2Math.Dot(w1, e13);
         var w3e13 = b2Math.Dot(w3, e13);
         var d13_1 = w3e13;
         var d13_2 = (-w1e13);
         var e23 = b2Math.SubtractVV(w3, w2);
         var w2e23 = b2Math.Dot(w2, e23);
         var w3e23 = b2Math.Dot(w3, e23);
         var d23_1 = w3e23;
         var d23_2 = (-w2e23);
         var n123 = b2Math.CrossVV(e12, e13);
         var d123_1 = n123 * b2Math.CrossVV(w2, w3);
         var d123_2 = n123 * b2Math.CrossVV(w3, w1);
         var d123_3 = n123 * b2Math.CrossVV(w1, w2);
         if (d12_2 <= 0.0 && d13_2 <= 0.0) {
            this.m_v1.a = 1.0;
            this.m_count = 1;
            return;
         }
         if (d12_1 > 0.0 && d12_2 > 0.0 && d123_3 <= 0.0) {
            var inv_d12 = 1.0 / (d12_1 + d12_2);
            this.m_v1.a = d12_1 * inv_d12;
            this.m_v2.a = d12_2 * inv_d12;
            this.m_count = 2;
            return;
         }
         if (d13_1 > 0.0 && d13_2 > 0.0 && d123_2 <= 0.0) {
            var inv_d13 = 1.0 / (d13_1 + d13_2);
            this.m_v1.a = d13_1 * inv_d13;
            this.m_v3.a = d13_2 * inv_d13;
            this.m_count = 2;
            this.m_v2.Set(this.m_v3);
            return;
         }
         if (d12_1 <= 0.0 && d23_2 <= 0.0) {
            this.m_v2.a = 1.0;
            this.m_count = 1;
            this.m_v1.Set(this.m_v2);
            return;
         }
         if (d13_1 <= 0.0 && d23_1 <= 0.0) {
            this.m_v3.a = 1.0;
            this.m_count = 1;
            this.m_v1.Set(this.m_v3);
            return;
         }
         if (d23_1 > 0.0 && d23_2 > 0.0 && d123_1 <= 0.0) {
            var inv_d23 = 1.0 / (d23_1 + d23_2);
            this.m_v2.a = d23_1 * inv_d23;
            this.m_v3.a = d23_2 * inv_d23;
            this.m_count = 2;
            this.m_v1.Set(this.m_v3);
            return;
         }
         var inv_d123 = 1.0 / (d123_1 + d123_2 + d123_3);
         this.m_v1.a = d123_1 * inv_d123;
         this.m_v2.a = d123_2 * inv_d123;
         this.m_v3.a = d123_3 * inv_d123;
         this.m_count = 3;
      }
      b2SimplexCache.b2SimplexCache = function () {
         this.indexA = new Vector_a2j_Number(3);
         this.indexB = new Vector_a2j_Number(3);
      };
      b2SimplexVertex.b2SimplexVertex = function () {};
      b2SimplexVertex.prototype.Set = function (other) {
         this.wA.SetV(other.wA);
         this.wB.SetV(other.wB);
         this.w.SetV(other.w);
         this.a = other.a;
         this.indexA = other.indexA;
         this.indexB = other.indexB;
      }
      b2TimeOfImpact.b2TimeOfImpact = function () {};
      b2TimeOfImpact.TimeOfImpact = function (input) {
         ++b2TimeOfImpact.b2_toiCalls;
         var proxyA = input.proxyA;
         var proxyB = input.proxyB;
         var sweepA = input.sweepA;
         var sweepB = input.sweepB;
         b2Settings.b2Assert(sweepA.t0 == sweepB.t0);
         b2Settings.b2Assert(1.0 - sweepA.t0 > Number.MIN_VALUE);
         var radius = proxyA.m_radius + proxyB.m_radius;
         var tolerance = input.tolerance;
         var alpha = 0.0;
         var k_maxIterations = 1000;
         var iter = 0;
         var target = 0.0;
         b2TimeOfImpact.s_cache.count = 0;
         b2TimeOfImpact.s_distanceInput.useRadii = false;
         for (;;) {
            sweepA.GetTransform(b2TimeOfImpact.s_xfA, alpha);
            sweepB.GetTransform(b2TimeOfImpact.s_xfB, alpha);
            b2TimeOfImpact.s_distanceInput.proxyA = proxyA;
            b2TimeOfImpact.s_distanceInput.proxyB = proxyB;
            b2TimeOfImpact.s_distanceInput.transformA = b2TimeOfImpact.s_xfA;
            b2TimeOfImpact.s_distanceInput.transformB = b2TimeOfImpact.s_xfB;
            b2Distance.Distance(b2TimeOfImpact.s_distanceOutput, b2TimeOfImpact.s_cache, b2TimeOfImpact.s_distanceInput);
            if (b2TimeOfImpact.s_distanceOutput.distance <= 0.0) {
               alpha = 1.0;
               break;
            }
            b2TimeOfImpact.s_fcn.Initialize(b2TimeOfImpact.s_cache, proxyA, b2TimeOfImpact.s_xfA, proxyB, b2TimeOfImpact.s_xfB);
            var separation = b2TimeOfImpact.s_fcn.Evaluate(b2TimeOfImpact.s_xfA, b2TimeOfImpact.s_xfB);
            if (separation <= 0.0) {
               alpha = 1.0;
               break;
            }
            if (iter == 0) {
               if (separation > radius) {
                  target = b2Math.Max(radius - tolerance, 0.75 * radius);
               }
               else {
                  target = b2Math.Max(separation - tolerance, 0.02 * radius);
               }
            }
            if (separation - target < 0.5 * tolerance) {
               if (iter == 0) {
                  alpha = 1.0;
                  break;
               }
               break;
            }
            var newAlpha = alpha; {
               var x1 = alpha;
               var x2 = 1.0;
               var f1 = separation;
               sweepA.GetTransform(b2TimeOfImpact.s_xfA, x2);
               sweepB.GetTransform(b2TimeOfImpact.s_xfB, x2);
               var f2 = b2TimeOfImpact.s_fcn.Evaluate(b2TimeOfImpact.s_xfA, b2TimeOfImpact.s_xfB);
               if (f2 >= target) {
                  alpha = 1.0;
                  break;
               }
               var rootIterCount = 0;
               for (;;) {
                  var x = 0;
                  if (rootIterCount & 1) {
                     x = x1 + (target - f1) * (x2 - x1) / (f2 - f1);
                  }
                  else {
                     x = 0.5 * (x1 + x2);
                  }
                  sweepA.GetTransform(b2TimeOfImpact.s_xfA, x);
                  sweepB.GetTransform(b2TimeOfImpact.s_xfB, x);
                  var f = b2TimeOfImpact.s_fcn.Evaluate(b2TimeOfImpact.s_xfA, b2TimeOfImpact.s_xfB);
                  if (b2Math.Abs(f - target) < 0.025 * tolerance) {
                     newAlpha = x;
                     break;
                  }
                  if (f > target) {
                     x1 = x;
                     f1 = f;
                  }
                  else {
                     x2 = x;
                     f2 = f;
                  }++rootIterCount;
                  ++b2TimeOfImpact.b2_toiRootIters;
                  if (rootIterCount == 50) {
                     break;
                  }
               }
               b2TimeOfImpact.b2_toiMaxRootIters = b2Math.Max(b2TimeOfImpact.b2_toiMaxRootIters, rootIterCount);
            }
            if (newAlpha < (1.0 + 100.0 * Number.MIN_VALUE) * alpha) {
               break;
            }
            alpha = newAlpha;
            iter++;
            ++b2TimeOfImpact.b2_toiIters;
            if (iter == k_maxIterations) {
               break;
            }
         }
         b2TimeOfImpact.b2_toiMaxIters = b2Math.Max(b2TimeOfImpact.b2_toiMaxIters, iter);
         return alpha;
      }
      Box2D.postDefs.push(function () {
         Box2D.Collision.b2TimeOfImpact.b2_toiCalls = 0;
         Box2D.Collision.b2TimeOfImpact.b2_toiIters = 0;
         Box2D.Collision.b2TimeOfImpact.b2_toiMaxIters = 0;
         Box2D.Collision.b2TimeOfImpact.b2_toiRootIters = 0;
         Box2D.Collision.b2TimeOfImpact.b2_toiMaxRootIters = 0;
         Box2D.Collision.b2TimeOfImpact.s_cache = new b2SimplexCache();
         Box2D.Collision.b2TimeOfImpact.s_distanceInput = new b2DistanceInput();
         Box2D.Collision.b2TimeOfImpact.s_xfA = new b2Transform();
         Box2D.Collision.b2TimeOfImpact.s_xfB = new b2Transform();
         Box2D.Collision.b2TimeOfImpact.s_fcn = new b2SeparationFunction();
         Box2D.Collision.b2TimeOfImpact.s_distanceOutput = new b2DistanceOutput();
      });
      b2TOIInput.b2TOIInput = function () {
         this.proxyA = new b2DistanceProxy();
         this.proxyB = new b2DistanceProxy();
         this.sweepA = new b2Sweep();
         this.sweepB = new b2Sweep();
      };
      b2WorldManifold.b2WorldManifold = function () {
         this.m_normal = new b2Vec2();
      };
      b2WorldManifold.prototype.b2WorldManifold = function () {
         this.m_points = new Vector(b2Settings.b2_maxManifoldPoints);
         for (var i = 0; i < b2Settings.b2_maxManifoldPoints; i++) {
            this.m_points[i] = new b2Vec2();
         }
      }
      b2WorldManifold.prototype.Initialize = function (manifold, xfA, radiusA, xfB, radiusB) {
         if (radiusA === undefined) radiusA = 0;
         if (radiusB === undefined) radiusB = 0;
         if (manifold.m_pointCount == 0) {
            return;
         }
         var i = 0;
         var tVec;
         var tMat;
         var normalX = 0;
         var normalY = 0;
         var planePointX = 0;
         var planePointY = 0;
         var clipPointX = 0;
         var clipPointY = 0;
         switch (manifold.m_type) {
         case b2Manifold.e_circles:
            {
               tMat = xfA.R;
               tVec = manifold.m_localPoint;
               var pointAX = xfA.position.x + tMat.col1.x * tVec.x + tMat.col2.x * tVec.y;
               var pointAY = xfA.position.y + tMat.col1.y * tVec.x + tMat.col2.y * tVec.y;
               tMat = xfB.R;
               tVec = manifold.m_points[0].m_localPoint;
               var pointBX = xfB.position.x + tMat.col1.x * tVec.x + tMat.col2.x * tVec.y;
               var pointBY = xfB.position.y + tMat.col1.y * tVec.x + tMat.col2.y * tVec.y;
               var dX = pointBX - pointAX;
               var dY = pointBY - pointAY;
               var d2 = dX * dX + dY * dY;
               if (d2 > Number.MIN_VALUE * Number.MIN_VALUE) {
                  var d = Math.sqrt(d2);
                  this.m_normal.x = dX / d;
                  this.m_normal.y = dY / d;
               }
               else {
                  this.m_normal.x = 1;
                  this.m_normal.y = 0;
               }
               var cAX = pointAX + radiusA * this.m_normal.x;
               var cAY = pointAY + radiusA * this.m_normal.y;
               var cBX = pointBX - radiusB * this.m_normal.x;
               var cBY = pointBY - radiusB * this.m_normal.y;
               this.m_points[0].x = 0.5 * (cAX + cBX);
               this.m_points[0].y = 0.5 * (cAY + cBY);
            }
            break;
         case b2Manifold.e_faceA:
            {
               tMat = xfA.R;
               tVec = manifold.m_localPlaneNormal;
               normalX = tMat.col1.x * tVec.x + tMat.col2.x * tVec.y;
               normalY = tMat.col1.y * tVec.x + tMat.col2.y * tVec.y;
               tMat = xfA.R;
               tVec = manifold.m_localPoint;
               planePointX = xfA.position.x + tMat.col1.x * tVec.x + tMat.col2.x * tVec.y;
               planePointY = xfA.position.y + tMat.col1.y * tVec.x + tMat.col2.y * tVec.y;
               this.m_normal.x = normalX;
               this.m_normal.y = normalY;
               for (i = 0;
               i < manifold.m_pointCount; i++) {
                  tMat = xfB.R;
                  tVec = manifold.m_points[i].m_localPoint;
                  clipPointX = xfB.position.x + tMat.col1.x * tVec.x + tMat.col2.x * tVec.y;
                  clipPointY = xfB.position.y + tMat.col1.y * tVec.x + tMat.col2.y * tVec.y;
                  this.m_points[i].x = clipPointX + 0.5 * (radiusA - (clipPointX - planePointX) * normalX - (clipPointY - planePointY) * normalY - radiusB) * normalX;
                  this.m_points[i].y = clipPointY + 0.5 * (radiusA - (clipPointX - planePointX) * normalX - (clipPointY - planePointY) * normalY - radiusB) * normalY;
               }
            }
            break;
         case b2Manifold.e_faceB:
            {
               tMat = xfB.R;
               tVec = manifold.m_localPlaneNormal;
               normalX = tMat.col1.x * tVec.x + tMat.col2.x * tVec.y;
               normalY = tMat.col1.y * tVec.x + tMat.col2.y * tVec.y;
               tMat = xfB.R;
               tVec = manifold.m_localPoint;
               planePointX = xfB.position.x + tMat.col1.x * tVec.x + tMat.col2.x * tVec.y;
               planePointY = xfB.position.y + tMat.col1.y * tVec.x + tMat.col2.y * tVec.y;
               this.m_normal.x = (-normalX);
               this.m_normal.y = (-normalY);
               for (i = 0;
               i < manifold.m_pointCount; i++) {
                  tMat = xfA.R;
                  tVec = manifold.m_points[i].m_localPoint;
                  clipPointX = xfA.position.x + tMat.col1.x * tVec.x + tMat.col2.x * tVec.y;
                  clipPointY = xfA.position.y + tMat.col1.y * tVec.x + tMat.col2.y * tVec.y;
                  this.m_points[i].x = clipPointX + 0.5 * (radiusB - (clipPointX - planePointX) * normalX - (clipPointY - planePointY) * normalY - radiusA) * normalX;
                  this.m_points[i].y = clipPointY + 0.5 * (radiusB - (clipPointX - planePointX) * normalX - (clipPointY - planePointY) * normalY - radiusA) * normalY;
               }
            }
            break;
         }
      }
      ClipVertex.ClipVertex = function () {
         this.v = new b2Vec2();
         this.id = new b2ContactID();
      };
      ClipVertex.prototype.Set = function (other) {
         this.v.SetV(other.v);
         this.id.Set(other.id);
      }
      Features.Features = function () {};
      Object.defineProperty(Features.prototype, 'referenceEdge', {
         enumerable: false,
         configurable: true,
         get: function () {
            return this._referenceEdge;
         }
      });
      Object.defineProperty(Features.prototype, 'referenceEdge', {
         enumerable: false,
         configurable: true,
         set: function (value) {
            if (value === undefined) value = 0;
            this._referenceEdge = value;
            this._m_id._key = (this._m_id._key & 0xffffff00) | (this._referenceEdge & 0x000000ff);
         }
      });
      Object.defineProperty(Features.prototype, 'incidentEdge', {
         enumerable: false,
         configurable: true,
         get: function () {
            return this._incidentEdge;
         }
      });
      Object.defineProperty(Features.prototype, 'incidentEdge', {
         enumerable: false,
         configurable: true,
         set: function (value) {
            if (value === undefined) value = 0;
            this._incidentEdge = value;
            this._m_id._key = (this._m_id._key & 0xffff00ff) | ((this._incidentEdge << 8) & 0x0000ff00);
         }
      });
      Object.defineProperty(Features.prototype, 'incidentVertex', {
         enumerable: false,
         configurable: true,
         get: function () {
            return this._incidentVertex;
         }
      });
      Object.defineProperty(Features.prototype, 'incidentVertex', {
         enumerable: false,
         configurable: true,
         set: function (value) {
            if (value === undefined) value = 0;
            this._incidentVertex = value;
            this._m_id._key = (this._m_id._key & 0xff00ffff) | ((this._incidentVertex << 16) & 0x00ff0000);
         }
      });
      Object.defineProperty(Features.prototype, 'flip', {
         enumerable: false,
         configurable: true,
         get: function () {
            return this._flip;
         }
      });
      Object.defineProperty(Features.prototype, 'flip', {
         enumerable: false,
         configurable: true,
         set: function (value) {
            if (value === undefined) value = 0;
            this._flip = value;
            this._m_id._key = (this._m_id._key & 0x00ffffff) | ((this._flip << 24) & 0xff000000);
         }
      });
   })();
   (function () {
      var b2Color = Box2D.Common.b2Color,
         b2internal = Box2D.Common.b2internal,
         b2Settings = Box2D.Common.b2Settings,
         b2CircleShape = Box2D.Collision.Shapes.b2CircleShape,
         b2EdgeChainDef = Box2D.Collision.Shapes.b2EdgeChainDef,
         b2EdgeShape = Box2D.Collision.Shapes.b2EdgeShape,
         b2MassData = Box2D.Collision.Shapes.b2MassData,
         b2PolygonShape = Box2D.Collision.Shapes.b2PolygonShape,
         b2Shape = Box2D.Collision.Shapes.b2Shape,
         b2Mat22 = Box2D.Common.Math.b2Mat22,
         b2Mat33 = Box2D.Common.Math.b2Mat33,
         b2Math = Box2D.Common.Math.b2Math,
         b2Sweep = Box2D.Common.Math.b2Sweep,
         b2Transform = Box2D.Common.Math.b2Transform,
         b2Vec2 = Box2D.Common.Math.b2Vec2,
         b2Vec3 = Box2D.Common.Math.b2Vec3,
         b2Body = Box2D.Dynamics.b2Body,
         b2BodyDef = Box2D.Dynamics.b2BodyDef,
         b2ContactFilter = Box2D.Dynamics.b2ContactFilter,
         b2ContactImpulse = Box2D.Dynamics.b2ContactImpulse,
         b2ContactListener = Box2D.Dynamics.b2ContactListener,
         b2ContactManager = Box2D.Dynamics.b2ContactManager,
         b2DebugDraw = Box2D.Dynamics.b2DebugDraw,
         b2DestructionListener = Box2D.Dynamics.b2DestructionListener,
         b2FilterData = Box2D.Dynamics.b2FilterData,
         b2Fixture = Box2D.Dynamics.b2Fixture,
         b2FixtureDef = Box2D.Dynamics.b2FixtureDef,
         b2Island = Box2D.Dynamics.b2Island,
         b2TimeStep = Box2D.Dynamics.b2TimeStep,
         b2World = Box2D.Dynamics.b2World,
         b2AABB = Box2D.Collision.b2AABB,
         b2Bound = Box2D.Collision.b2Bound,
         b2BoundValues = Box2D.Collision.b2BoundValues,
         b2Collision = Box2D.Collision.b2Collision,
         b2ContactID = Box2D.Collision.b2ContactID,
         b2ContactPoint = Box2D.Collision.b2ContactPoint,
         b2Distance = Box2D.Collision.b2Distance,
         b2DistanceInput = Box2D.Collision.b2DistanceInput,
         b2DistanceOutput = Box2D.Collision.b2DistanceOutput,
         b2DistanceProxy = Box2D.Collision.b2DistanceProxy,
         b2DynamicTree = Box2D.Collision.b2DynamicTree,
         b2DynamicTreeBroadPhase = Box2D.Collision.b2DynamicTreeBroadPhase,
         b2DynamicTreeNode = Box2D.Collision.b2DynamicTreeNode,
         b2DynamicTreePair = Box2D.Collision.b2DynamicTreePair,
         b2Manifold = Box2D.Collision.b2Manifold,
         b2ManifoldPoint = Box2D.Collision.b2ManifoldPoint,
         b2Point = Box2D.Collision.b2Point,
         b2RayCastInput = Box2D.Collision.b2RayCastInput,
         b2RayCastOutput = Box2D.Collision.b2RayCastOutput,
         b2Segment = Box2D.Collision.b2Segment,
         b2SeparationFunction = Box2D.Collision.b2SeparationFunction,
         b2Simplex = Box2D.Collision.b2Simplex,
         b2SimplexCache = Box2D.Collision.b2SimplexCache,
         b2SimplexVertex = Box2D.Collision.b2SimplexVertex,
         b2TimeOfImpact = Box2D.Collision.b2TimeOfImpact,
         b2TOIInput = Box2D.Collision.b2TOIInput,
         b2WorldManifold = Box2D.Collision.b2WorldManifold,
         ClipVertex = Box2D.Collision.ClipVertex,
         Features = Box2D.Collision.Features,
         IBroadPhase = Box2D.Collision.IBroadPhase;

      Box2D.inherit(b2CircleShape, Box2D.Collision.Shapes.b2Shape);
      b2CircleShape.prototype.__super = Box2D.Collision.Shapes.b2Shape.prototype;
      b2CircleShape.b2CircleShape = function () {
         Box2D.Collision.Shapes.b2Shape.b2Shape.apply(this, arguments);
         this.m_p = new b2Vec2();
      };
      b2CircleShape.prototype.Copy = function () {
         var s = new b2CircleShape();
         s.Set(this);
         return s;
      }
      b2CircleShape.prototype.Set = function (other) {
         this.__super.Set.call(this, other);
         if (Box2D.is(other, b2CircleShape)) {
            var other2 = (other instanceof b2CircleShape ? other : null);
            this.m_p.SetV(other2.m_p);
         }
      }
      b2CircleShape.prototype.TestPoint = function (transform, p) {
         var tMat = transform.R;
         var dX = transform.position.x + (tMat.col1.x * this.m_p.x + tMat.col2.x * this.m_p.y);
         var dY = transform.position.y + (tMat.col1.y * this.m_p.x + tMat.col2.y * this.m_p.y);
         dX = p.x - dX;
         dY = p.y - dY;
         return (dX * dX + dY * dY) <= this.m_radius * this.m_radius;
      }
      b2CircleShape.prototype.RayCast = function (output, input, transform) {
         var tMat = transform.R;
         var positionX = transform.position.x + (tMat.col1.x * this.m_p.x + tMat.col2.x * this.m_p.y);
         var positionY = transform.position.y + (tMat.col1.y * this.m_p.x + tMat.col2.y * this.m_p.y);
         var sX = input.p1.x - positionX;
         var sY = input.p1.y - positionY;
         var b = (sX * sX + sY * sY) - this.m_radius * this.m_radius;
         var rX = input.p2.x - input.p1.x;
         var rY = input.p2.y - input.p1.y;
         var c = (sX * rX + sY * rY);
         var rr = (rX * rX + rY * rY);
         var sigma = c * c - rr * b;
         if (sigma < 0.0 || rr < Number.MIN_VALUE) {
            return false;
         }
         var a = (-(c + Math.sqrt(sigma)));
         if (0.0 <= a && a <= input.maxFraction * rr) {
            a /= rr;
            output.fraction = a;
            output.normal.x = sX + a * rX;
            output.normal.y = sY + a * rY;
            output.normal.Normalize();
            return true;
         }
         return false;
      }
      b2CircleShape.prototype.ComputeAABB = function (aabb, transform) {
         var tMat = transform.R;
         var pX = transform.position.x + (tMat.col1.x * this.m_p.x + tMat.col2.x * this.m_p.y);
         var pY = transform.position.y + (tMat.col1.y * this.m_p.x + tMat.col2.y * this.m_p.y);
         aabb.lowerBound.Set(pX - this.m_radius, pY - this.m_radius);
         aabb.upperBound.Set(pX + this.m_radius, pY + this.m_radius);
      }
      b2CircleShape.prototype.ComputeMass = function (massData, density) {
         if (density === undefined) density = 0;
         massData.mass = density * b2Settings.b2_pi * this.m_radius * this.m_radius;
         massData.center.SetV(this.m_p);
         massData.I = massData.mass * (0.5 * this.m_radius * this.m_radius + (this.m_p.x * this.m_p.x + this.m_p.y * this.m_p.y));
      }
      b2CircleShape.prototype.ComputeSubmergedArea = function (normal, offset, xf, c) {
         if (offset === undefined) offset = 0;
         var p = b2Math.MulX(xf, this.m_p);
         var l = (-(b2Math.Dot(normal, p) - offset));
         if (l < (-this.m_radius) + Number.MIN_VALUE) {
            return 0;
         }
         if (l > this.m_radius) {
            c.SetV(p);
            return Math.PI * this.m_radius * this.m_radius;
         }
         var r2 = this.m_radius * this.m_radius;
         var l2 = l * l;
         var area = r2 * (Math.asin(l / this.m_radius) + Math.PI / 2) + l * Math.sqrt(r2 - l2);
         var com = (-2 / 3 * Math.pow(r2 - l2, 1.5) / area);
         c.x = p.x + normal.x * com;
         c.y = p.y + normal.y * com;
         return area;
      }
      b2CircleShape.prototype.GetLocalPosition = function () {
         return this.m_p;
      }
      b2CircleShape.prototype.SetLocalPosition = function (position) {
         this.m_p.SetV(position);
      }
      b2CircleShape.prototype.GetRadius = function () {
         return this.m_radius;
      }
      b2CircleShape.prototype.SetRadius = function (radius) {
         if (radius === undefined) radius = 0;
         this.m_radius = radius;
      }
      b2CircleShape.prototype.b2CircleShape = function (radius) {
         if (radius === undefined) radius = 0;
         this.__super.b2Shape.call(this);
         this.m_type = b2Shape.e_circleShape;
         this.m_radius = radius;
      }
      b2EdgeChainDef.b2EdgeChainDef = function () {};
      b2EdgeChainDef.prototype.b2EdgeChainDef = function () {
         this.vertexCount = 0;
         this.isALoop = true;
         this.vertices = [];
      }
      Box2D.inherit(b2EdgeShape, Box2D.Collision.Shapes.b2Shape);
      b2EdgeShape.prototype.__super = Box2D.Collision.Shapes.b2Shape.prototype;
      b2EdgeShape.b2EdgeShape = function () {
         Box2D.Collision.Shapes.b2Shape.b2Shape.apply(this, arguments);
         this.s_supportVec = new b2Vec2();
         this.m_v1 = new b2Vec2();
         this.m_v2 = new b2Vec2();
         this.m_coreV1 = new b2Vec2();
         this.m_coreV2 = new b2Vec2();
         this.m_normal = new b2Vec2();
         this.m_direction = new b2Vec2();
         this.m_cornerDir1 = new b2Vec2();
         this.m_cornerDir2 = new b2Vec2();
      };
      b2EdgeShape.prototype.TestPoint = function (transform, p) {
         return false;
      }
      b2EdgeShape.prototype.RayCast = function (output, input, transform) {
         var tMat;
         var rX = input.p2.x - input.p1.x;
         var rY = input.p2.y - input.p1.y;
         tMat = transform.R;
         var v1X = transform.position.x + (tMat.col1.x * this.m_v1.x + tMat.col2.x * this.m_v1.y);
         var v1Y = transform.position.y + (tMat.col1.y * this.m_v1.x + tMat.col2.y * this.m_v1.y);
         var nX = transform.position.y + (tMat.col1.y * this.m_v2.x + tMat.col2.y * this.m_v2.y) - v1Y;
         var nY = (-(transform.position.x + (tMat.col1.x * this.m_v2.x + tMat.col2.x * this.m_v2.y) - v1X));
         var k_slop = 100.0 * Number.MIN_VALUE;
         var denom = (-(rX * nX + rY * nY));
         if (denom > k_slop) {
            var bX = input.p1.x - v1X;
            var bY = input.p1.y - v1Y;
            var a = (bX * nX + bY * nY);
            if (0.0 <= a && a <= input.maxFraction * denom) {
               var mu2 = (-rX * bY) + rY * bX;
               if ((-k_slop * denom) <= mu2 && mu2 <= denom * (1.0 + k_slop)) {
                  a /= denom;
                  output.fraction = a;
                  var nLen = Math.sqrt(nX * nX + nY * nY);
                  output.normal.x = nX / nLen;
                  output.normal.y = nY / nLen;
                  return true;
               }
            }
         }
         return false;
      }
      b2EdgeShape.prototype.ComputeAABB = function (aabb, transform) {
         var tMat = transform.R;
         var v1X = transform.position.x + (tMat.col1.x * this.m_v1.x + tMat.col2.x * this.m_v1.y);
         var v1Y = transform.position.y + (tMat.col1.y * this.m_v1.x + tMat.col2.y * this.m_v1.y);
         var v2X = transform.position.x + (tMat.col1.x * this.m_v2.x + tMat.col2.x * this.m_v2.y);
         var v2Y = transform.position.y + (tMat.col1.y * this.m_v2.x + tMat.col2.y * this.m_v2.y);
         if (v1X < v2X) {
            aabb.lowerBound.x = v1X;
            aabb.upperBound.x = v2X;
         }
         else {
            aabb.lowerBound.x = v2X;
            aabb.upperBound.x = v1X;
         }
         if (v1Y < v2Y) {
            aabb.lowerBound.y = v1Y;
            aabb.upperBound.y = v2Y;
         }
         else {
            aabb.lowerBound.y = v2Y;
            aabb.upperBound.y = v1Y;
         }
      }
      b2EdgeShape.prototype.ComputeMass = function (massData, density) {
         if (density === undefined) density = 0;
         massData.mass = 0;
         massData.center.SetV(this.m_v1);
         massData.I = 0;
      }
      b2EdgeShape.prototype.ComputeSubmergedArea = function (normal, offset, xf, c) {
         if (offset === undefined) offset = 0;
         var v0 = new b2Vec2(normal.x * offset, normal.y * offset);
         var v1 = b2Math.MulX(xf, this.m_v1);
         var v2 = b2Math.MulX(xf, this.m_v2);
         var d1 = b2Math.Dot(normal, v1) - offset;
         var d2 = b2Math.Dot(normal, v2) - offset;
         if (d1 > 0) {
            if (d2 > 0) {
               return 0;
            }
            else {
               v1.x = (-d2 / (d1 - d2) * v1.x) + d1 / (d1 - d2) * v2.x;
               v1.y = (-d2 / (d1 - d2) * v1.y) + d1 / (d1 - d2) * v2.y;
            }
         }
         else {
            if (d2 > 0) {
               v2.x = (-d2 / (d1 - d2) * v1.x) + d1 / (d1 - d2) * v2.x;
               v2.y = (-d2 / (d1 - d2) * v1.y) + d1 / (d1 - d2) * v2.y;
            }
            else {} // JDM: ESLint warning = empty block
         }
         c.x = (v0.x + v1.x + v2.x) / 3;
         c.y = (v0.y + v1.y + v2.y) / 3;
         return 0.5 * ((v1.x - v0.x) * (v2.y - v0.y) - (v1.y - v0.y) * (v2.x - v0.x));
      }
      b2EdgeShape.prototype.GetLength = function () {
         return this.m_length;
      }
      b2EdgeShape.prototype.GetVertex1 = function () {
         return this.m_v1;
      }
      b2EdgeShape.prototype.GetVertex2 = function () {
         return this.m_v2;
      }
      b2EdgeShape.prototype.GetCoreVertex1 = function () {
         return this.m_coreV1;
      }
      b2EdgeShape.prototype.GetCoreVertex2 = function () {
         return this.m_coreV2;
      }
      b2EdgeShape.prototype.GetNormalVector = function () {
         return this.m_normal;
      }
      b2EdgeShape.prototype.GetDirectionVector = function () {
         return this.m_direction;
      }
      b2EdgeShape.prototype.GetCorner1Vector = function () {
         return this.m_cornerDir1;
      }
      b2EdgeShape.prototype.GetCorner2Vector = function () {
         return this.m_cornerDir2;
      }
      b2EdgeShape.prototype.Corner1IsConvex = function () {
         return this.m_cornerConvex1;
      }
      b2EdgeShape.prototype.Corner2IsConvex = function () {
         return this.m_cornerConvex2;
      }
      b2EdgeShape.prototype.GetFirstVertex = function (xf) {
         var tMat = xf.R;
         return new b2Vec2(xf.position.x + (tMat.col1.x * this.m_coreV1.x + tMat.col2.x * this.m_coreV1.y), xf.position.y + (tMat.col1.y * this.m_coreV1.x + tMat.col2.y * this.m_coreV1.y));
      }
      b2EdgeShape.prototype.GetNextEdge = function () {
         return this.m_nextEdge;
      }
      b2EdgeShape.prototype.GetPrevEdge = function () {
         return this.m_prevEdge;
      }
      b2EdgeShape.prototype.Support = function (xf, dX, dY) {
         if (dX === undefined) dX = 0;
         if (dY === undefined) dY = 0;
         var tMat = xf.R;
         var v1X = xf.position.x + (tMat.col1.x * this.m_coreV1.x + tMat.col2.x * this.m_coreV1.y);
         var v1Y = xf.position.y + (tMat.col1.y * this.m_coreV1.x + tMat.col2.y * this.m_coreV1.y);
         var v2X = xf.position.x + (tMat.col1.x * this.m_coreV2.x + tMat.col2.x * this.m_coreV2.y);
         var v2Y = xf.position.y + (tMat.col1.y * this.m_coreV2.x + tMat.col2.y * this.m_coreV2.y);
         if ((v1X * dX + v1Y * dY) > (v2X * dX + v2Y * dY)) {
            this.s_supportVec.x = v1X;
            this.s_supportVec.y = v1Y;
         }
         else {
            this.s_supportVec.x = v2X;
            this.s_supportVec.y = v2Y;
         }
         return this.s_supportVec;
      }
      b2EdgeShape.prototype.b2EdgeShape = function (v1, v2) {
         this.__super.b2Shape.call(this);
         this.m_type = b2Shape.e_edgeShape;
         this.m_prevEdge = null;
         this.m_nextEdge = null;
         this.m_v1 = v1;
         this.m_v2 = v2;
         this.m_direction.Set(this.m_v2.x - this.m_v1.x, this.m_v2.y - this.m_v1.y);
         this.m_length = this.m_direction.Normalize();
         this.m_normal.Set(this.m_direction.y, (-this.m_direction.x));
         this.m_coreV1.Set((-b2Settings.b2_toiSlop * (this.m_normal.x - this.m_direction.x)) + this.m_v1.x, (-b2Settings.b2_toiSlop * (this.m_normal.y - this.m_direction.y)) + this.m_v1.y);
         this.m_coreV2.Set((-b2Settings.b2_toiSlop * (this.m_normal.x + this.m_direction.x)) + this.m_v2.x, (-b2Settings.b2_toiSlop * (this.m_normal.y + this.m_direction.y)) + this.m_v2.y);
         this.m_cornerDir1 = this.m_normal;
         this.m_cornerDir2.Set((-this.m_normal.x), (-this.m_normal.y));
      }
      b2EdgeShape.prototype.SetPrevEdge = function (edge, core, cornerDir, convex) {
         this.m_prevEdge = edge;
         this.m_coreV1 = core;
         this.m_cornerDir1 = cornerDir;
         this.m_cornerConvex1 = convex;
      }
      b2EdgeShape.prototype.SetNextEdge = function (edge, core, cornerDir, convex) {
         this.m_nextEdge = edge;
         this.m_coreV2 = core;
         this.m_cornerDir2 = cornerDir;
         this.m_cornerConvex2 = convex;
      }
      b2MassData.b2MassData = function () {
         this.mass = 0.0;
         this.center = new b2Vec2(0, 0);
         this.I = 0.0;
      };
      Box2D.inherit(b2PolygonShape, Box2D.Collision.Shapes.b2Shape);
      b2PolygonShape.prototype.__super = Box2D.Collision.Shapes.b2Shape.prototype;
      b2PolygonShape.b2PolygonShape = function () {
         Box2D.Collision.Shapes.b2Shape.b2Shape.apply(this, arguments);
      };
      b2PolygonShape.prototype.Copy = function () {
         var s = new b2PolygonShape();
         s.Set(this);
         return s;
      }
      b2PolygonShape.prototype.Set = function (other) {
         this.__super.Set.call(this, other);
         if (Box2D.is(other, b2PolygonShape)) {
            var other2 = (other instanceof b2PolygonShape ? other : null);
            this.m_centroid.SetV(other2.m_centroid);
            this.m_vertexCount = other2.m_vertexCount;
            this.Reserve(this.m_vertexCount);
            for (var i = 0; i < this.m_vertexCount; i++) {
               this.m_vertices[i].SetV(other2.m_vertices[i]);
               this.m_normals[i].SetV(other2.m_normals[i]);
            }
         }
      }
      b2PolygonShape.prototype.SetAsArray = function (vertices, vertexCount) {
         if (vertexCount === undefined) vertexCount = 0;
         var v = new Vector();
         var i = 0,
            tVec;
         for (i = 0;
         i < vertices.length; ++i) {
            tVec = vertices[i];
            v.push(tVec);
         }
         this.SetAsVector(v, vertexCount);
      }
      b2PolygonShape.AsArray = function (vertices, vertexCount) {
         if (vertexCount === undefined) vertexCount = 0;
         var polygonShape = new b2PolygonShape();
         polygonShape.SetAsArray(vertices, vertexCount);
         return polygonShape;
      }
      b2PolygonShape.prototype.SetAsVector = function (vertices, vertexCount) {
         if (vertexCount === undefined) vertexCount = 0;
         if (vertexCount == 0) vertexCount = vertices.length;
         b2Settings.b2Assert(2 <= vertexCount);
         this.m_vertexCount = vertexCount;
         this.Reserve(vertexCount);
         var i = 0;
         for (i = 0;
         i < this.m_vertexCount; i++) {
            this.m_vertices[i].SetV(vertices[i]);
         }
         for (i = 0;
         i < this.m_vertexCount; ++i) {
            var i1 = parseInt(i);
            var i2 = parseInt(i + 1 < this.m_vertexCount ? i + 1 : 0);
            var edge = b2Math.SubtractVV(this.m_vertices[i2], this.m_vertices[i1]);
            b2Settings.b2Assert(edge.LengthSquared() > Number.MIN_VALUE);
            this.m_normals[i].SetV(b2Math.CrossVF(edge, 1.0));
            this.m_normals[i].Normalize();
         }
         this.m_centroid = b2PolygonShape.ComputeCentroid(this.m_vertices, this.m_vertexCount);
      }
      b2PolygonShape.AsVector = function (vertices, vertexCount) {
         if (vertexCount === undefined) vertexCount = 0;
         var polygonShape = new b2PolygonShape();
         polygonShape.SetAsVector(vertices, vertexCount);
         return polygonShape;
      }
      b2PolygonShape.prototype.SetAsBox = function (hx, hy) {
         if (hx === undefined) hx = 0;
         if (hy === undefined) hy = 0;
         this.m_vertexCount = 4;
         this.Reserve(4);
         this.m_vertices[0].Set((-hx), (-hy));
         this.m_vertices[1].Set(hx, (-hy));
         this.m_vertices[2].Set(hx, hy);
         this.m_vertices[3].Set((-hx), hy);
         this.m_normals[0].Set(0.0, (-1.0));
         this.m_normals[1].Set(1.0, 0.0);
         this.m_normals[2].Set(0.0, 1.0);
         this.m_normals[3].Set((-1.0), 0.0);
         this.m_centroid.SetZero();
      }
      b2PolygonShape.AsBox = function (hx, hy) {
         if (hx === undefined) hx = 0;
         if (hy === undefined) hy = 0;
         var polygonShape = new b2PolygonShape();
         polygonShape.SetAsBox(hx, hy);
         return polygonShape;
      }
      b2PolygonShape.prototype.SetAsOrientedBox = function (hx, hy, center, angle) {
         if (hx === undefined) hx = 0;
         if (hy === undefined) hy = 0;
         if (center === undefined) center = null;
         if (angle === undefined) angle = 0.0;
         this.m_vertexCount = 4;
         this.Reserve(4);
         this.m_vertices[0].Set((-hx), (-hy));
         this.m_vertices[1].Set(hx, (-hy));
         this.m_vertices[2].Set(hx, hy);
         this.m_vertices[3].Set((-hx), hy);
         this.m_normals[0].Set(0.0, (-1.0));
         this.m_normals[1].Set(1.0, 0.0);
         this.m_normals[2].Set(0.0, 1.0);
         this.m_normals[3].Set((-1.0), 0.0);
         this.m_centroid = center;
         var xf = new b2Transform();
         xf.position = center;
         xf.R.Set(angle);
         for (var i = 0; i < this.m_vertexCount; ++i) {
            this.m_vertices[i] = b2Math.MulX(xf, this.m_vertices[i]);
            this.m_normals[i] = b2Math.MulMV(xf.R, this.m_normals[i]);
         }
      }
      b2PolygonShape.AsOrientedBox = function (hx, hy, center, angle) {
         if (hx === undefined) hx = 0;
         if (hy === undefined) hy = 0;
         if (center === undefined) center = null;
         if (angle === undefined) angle = 0.0;
         var polygonShape = new b2PolygonShape();
         polygonShape.SetAsOrientedBox(hx, hy, center, angle);
         return polygonShape;
      }
      b2PolygonShape.prototype.SetAsEdge = function (v1, v2) {
         this.m_vertexCount = 2;
         this.Reserve(2);
         this.m_vertices[0].SetV(v1);
         this.m_vertices[1].SetV(v2);
         this.m_centroid.x = 0.5 * (v1.x + v2.x);
         this.m_centroid.y = 0.5 * (v1.y + v2.y);
         this.m_normals[0] = b2Math.CrossVF(b2Math.SubtractVV(v2, v1), 1.0);
         this.m_normals[0].Normalize();
         this.m_normals[1].x = (-this.m_normals[0].x);
         this.m_normals[1].y = (-this.m_normals[0].y);
      }
      b2PolygonShape.AsEdge = function (v1, v2) {
         var polygonShape = new b2PolygonShape();
         polygonShape.SetAsEdge(v1, v2);
         return polygonShape;
      }
      b2PolygonShape.prototype.TestPoint = function (xf, p) {
         var tVec;
         var tMat = xf.R;
         var tX = p.x - xf.position.x;
         var tY = p.y - xf.position.y;
         var pLocalX = (tX * tMat.col1.x + tY * tMat.col1.y);
         var pLocalY = (tX * tMat.col2.x + tY * tMat.col2.y);
         for (var i = 0; i < this.m_vertexCount; ++i) {
            tVec = this.m_vertices[i];
            tX = pLocalX - tVec.x;
            tY = pLocalY - tVec.y;
            tVec = this.m_normals[i];
            var dot = (tVec.x * tX + tVec.y * tY);
            if (dot > 0.0) {
               return false;
            }
         }
         return true;
      }
      b2PolygonShape.prototype.RayCast = function (output, input, transform) {
         var lower = 0.0;
         var upper = input.maxFraction;
         var tX = 0;
         var tY = 0;
         var tMat;
         var tVec;
         tX = input.p1.x - transform.position.x;
         tY = input.p1.y - transform.position.y;
         tMat = transform.R;
         var p1X = (tX * tMat.col1.x + tY * tMat.col1.y);
         var p1Y = (tX * tMat.col2.x + tY * tMat.col2.y);
         tX = input.p2.x - transform.position.x;
         tY = input.p2.y - transform.position.y;
         tMat = transform.R;
         var p2X = (tX * tMat.col1.x + tY * tMat.col1.y);
         var p2Y = (tX * tMat.col2.x + tY * tMat.col2.y);
         var dX = p2X - p1X;
         var dY = p2Y - p1Y;
         var index = parseInt((-1));
         for (var i = 0; i < this.m_vertexCount; ++i) {
            tVec = this.m_vertices[i];
            tX = tVec.x - p1X;
            tY = tVec.y - p1Y;
            tVec = this.m_normals[i];
            var numerator = (tVec.x * tX + tVec.y * tY);
            var denominator = (tVec.x * dX + tVec.y * dY);
            if (denominator == 0.0) {
               if (numerator < 0.0) {
                  return false;
               }
            }
            else {
               if (denominator < 0.0 && numerator < lower * denominator) {
                  lower = numerator / denominator;
                  index = i;
               }
               else if (denominator > 0.0 && numerator < upper * denominator) {
                  upper = numerator / denominator;
               }
            }
            if (upper < lower - Number.MIN_VALUE) {
               return false;
            }
         }
         if (index >= 0) {
            output.fraction = lower;
            tMat = transform.R;
            tVec = this.m_normals[index];
            output.normal.x = (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);
            output.normal.y = (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);
            return true;
         }
         return false;
      }
      b2PolygonShape.prototype.ComputeAABB = function (aabb, xf) {
         var tMat = xf.R;
         var tVec = this.m_vertices[0];
         var lowerX = xf.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);
         var lowerY = xf.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);
         var upperX = lowerX;
         var upperY = lowerY;
         for (var i = 1; i < this.m_vertexCount; ++i) {
            tVec = this.m_vertices[i];
            var vX = xf.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);
            var vY = xf.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);
            lowerX = lowerX < vX ? lowerX : vX;
            lowerY = lowerY < vY ? lowerY : vY;
            upperX = upperX > vX ? upperX : vX;
            upperY = upperY > vY ? upperY : vY;
         }
         aabb.lowerBound.x = lowerX - this.m_radius;
         aabb.lowerBound.y = lowerY - this.m_radius;
         aabb.upperBound.x = upperX + this.m_radius;
         aabb.upperBound.y = upperY + this.m_radius;
      }
      b2PolygonShape.prototype.ComputeMass = function (massData, density) {
         if (density === undefined) density = 0;
         if (this.m_vertexCount == 2) {
            massData.center.x = 0.5 * (this.m_vertices[0].x + this.m_vertices[1].x);
            massData.center.y = 0.5 * (this.m_vertices[0].y + this.m_vertices[1].y);
            massData.mass = 0.0;
            massData.I = 0.0;
            return;
         }
         var centerX = 0.0;
         var centerY = 0.0;
         var area = 0.0;
         var I = 0.0;
         var p1X = 0.0;
         var p1Y = 0.0;
         var k_inv3 = 1.0 / 3.0;
         for (var i = 0; i < this.m_vertexCount; ++i) {
            var p2 = this.m_vertices[i];
            var p3 = i + 1 < this.m_vertexCount ? this.m_vertices[parseInt(i + 1)] : this.m_vertices[0];
            var e1X = p2.x - p1X;
            var e1Y = p2.y - p1Y;
            var e2X = p3.x - p1X;
            var e2Y = p3.y - p1Y;
            var D = e1X * e2Y - e1Y * e2X;
            var triangleArea = 0.5 * D;area += triangleArea;
            centerX += triangleArea * k_inv3 * (p1X + p2.x + p3.x);
            centerY += triangleArea * k_inv3 * (p1Y + p2.y + p3.y);
            var px = p1X;
            var py = p1Y;
            var ex1 = e1X;
            var ey1 = e1Y;
            var ex2 = e2X;
            var ey2 = e2Y;
            var intx2 = k_inv3 * (0.25 * (ex1 * ex1 + ex2 * ex1 + ex2 * ex2) + (px * ex1 + px * ex2)) + 0.5 * px * px;
            var inty2 = k_inv3 * (0.25 * (ey1 * ey1 + ey2 * ey1 + ey2 * ey2) + (py * ey1 + py * ey2)) + 0.5 * py * py;I += D * (intx2 + inty2);
         }
         massData.mass = density * area;
         centerX *= 1.0 / area;
         centerY *= 1.0 / area;
         massData.center.Set(centerX, centerY);
         massData.I = density * I;
      }
      b2PolygonShape.prototype.ComputeSubmergedArea = function (normal, offset, xf, c) {
         if (offset === undefined) offset = 0;
         var normalL = b2Math.MulTMV(xf.R, normal);
         var offsetL = offset - b2Math.Dot(normal, xf.position);
         var depths = new Vector_a2j_Number();
         var diveCount = 0;
         var intoIndex = parseInt((-1));
         var outoIndex = parseInt((-1));
         var lastSubmerged = false;
         var i = 0;
         for (i = 0;
         i < this.m_vertexCount; ++i) {
            depths[i] = b2Math.Dot(normalL, this.m_vertices[i]) - offsetL;
            var isSubmerged = depths[i] < (-Number.MIN_VALUE);
            if (i > 0) {
               if (isSubmerged) {
                  if (!lastSubmerged) {
                     intoIndex = i - 1;
                     diveCount++;
                  }
               }
               else {
                  if (lastSubmerged) {
                     outoIndex = i - 1;
                     diveCount++;
                  }
               }
            }
            lastSubmerged = isSubmerged;
         }
         switch (diveCount) {
         case 0:
            if (lastSubmerged) {
               var md = new b2MassData();
               this.ComputeMass(md, 1);
               c.SetV(b2Math.MulX(xf, md.center));
               return md.mass;
            }
            else {
               return 0;
            }
            break; // JDM: ESLint warning = unreachable code
         case 1:
            if (intoIndex == (-1)) {
               intoIndex = this.m_vertexCount - 1;
            }
            else {
               outoIndex = this.m_vertexCount - 1;
            }
            break;
         }
         var intoIndex2 = parseInt((intoIndex + 1) % this.m_vertexCount);
         var outoIndex2 = parseInt((outoIndex + 1) % this.m_vertexCount);
         var intoLamdda = (0 - depths[intoIndex]) / (depths[intoIndex2] - depths[intoIndex]);
         var outoLamdda = (0 - depths[outoIndex]) / (depths[outoIndex2] - depths[outoIndex]);
         var intoVec = new b2Vec2(this.m_vertices[intoIndex].x * (1 - intoLamdda) + this.m_vertices[intoIndex2].x * intoLamdda, this.m_vertices[intoIndex].y * (1 - intoLamdda) + this.m_vertices[intoIndex2].y * intoLamdda);
         var outoVec = new b2Vec2(this.m_vertices[outoIndex].x * (1 - outoLamdda) + this.m_vertices[outoIndex2].x * outoLamdda, this.m_vertices[outoIndex].y * (1 - outoLamdda) + this.m_vertices[outoIndex2].y * outoLamdda);
         var area = 0;
         var center = new b2Vec2();
         var p2 = this.m_vertices[intoIndex2];
         var p3;
         i = intoIndex2;
         while (i != outoIndex2) {
            i = (i + 1) % this.m_vertexCount;
            if (i == outoIndex2) p3 = outoVec;
            else p3 = this.m_vertices[i];
            var triangleArea = 0.5 * ((p2.x - intoVec.x) * (p3.y - intoVec.y) - (p2.y - intoVec.y) * (p3.x - intoVec.x));
            area += triangleArea;
            center.x += triangleArea * (intoVec.x + p2.x + p3.x) / 3;
            center.y += triangleArea * (intoVec.y + p2.y + p3.y) / 3;
            p2 = p3;
         }
         center.Multiply(1 / area);
         c.SetV(b2Math.MulX(xf, center));
         return area;
      }
      b2PolygonShape.prototype.GetVertexCount = function () {
         return this.m_vertexCount;
      }
      b2PolygonShape.prototype.GetVertices = function () {
         return this.m_vertices;
      }
      b2PolygonShape.prototype.GetNormals = function () {
         return this.m_normals;
      }
      b2PolygonShape.prototype.GetSupport = function (d) {
         var bestIndex = 0;
         var bestValue = this.m_vertices[0].x * d.x + this.m_vertices[0].y * d.y;
         for (var i = 1; i < this.m_vertexCount; ++i) {
            var value = this.m_vertices[i].x * d.x + this.m_vertices[i].y * d.y;
            if (value > bestValue) {
               bestIndex = i;
               bestValue = value;
            }
         }
         return bestIndex;
      }
      b2PolygonShape.prototype.GetSupportVertex = function (d) {
         var bestIndex = 0;
         var bestValue = this.m_vertices[0].x * d.x + this.m_vertices[0].y * d.y;
         for (var i = 1; i < this.m_vertexCount; ++i) {
            var value = this.m_vertices[i].x * d.x + this.m_vertices[i].y * d.y;
            if (value > bestValue) {
               bestIndex = i;
               bestValue = value;
            }
         }
         return this.m_vertices[bestIndex];
      }
      b2PolygonShape.prototype.Validate = function () {
         return false;
      }
      b2PolygonShape.prototype.b2PolygonShape = function () {
         this.__super.b2Shape.call(this);
         this.m_type = b2Shape.e_polygonShape;
         this.m_centroid = new b2Vec2();
         this.m_vertices = new Vector();
         this.m_normals = new Vector();
      }
      b2PolygonShape.prototype.Reserve = function (count) {
         if (count === undefined) count = 0;
         for (var i = parseInt(this.m_vertices.length); i < count; i++) {
            this.m_vertices[i] = new b2Vec2();
            this.m_normals[i] = new b2Vec2();
         }
      }
      b2PolygonShape.ComputeCentroid = function (vs, count) {
         if (count === undefined) count = 0;
         var c = new b2Vec2();
         var area = 0.0;
         var p1X = 0.0;
         var p1Y = 0.0;
         var inv3 = 1.0 / 3.0;
         for (var i = 0; i < count; ++i) {
            var p2 = vs[i];
            var p3 = i + 1 < count ? vs[parseInt(i + 1)] : vs[0];
            var e1X = p2.x - p1X;
            var e1Y = p2.y - p1Y;
            var e2X = p3.x - p1X;
            var e2Y = p3.y - p1Y;
            var D = (e1X * e2Y - e1Y * e2X);
            var triangleArea = 0.5 * D;area += triangleArea;
            c.x += triangleArea * inv3 * (p1X + p2.x + p3.x);
            c.y += triangleArea * inv3 * (p1Y + p2.y + p3.y);
         }
         c.x *= 1.0 / area;
         c.y *= 1.0 / area;
         return c;
      }
      b2PolygonShape.ComputeOBB = function (obb, vs, count) {
         if (count === undefined) count = 0;
         var i = 0;
         var p = new Vector(count + 1);
         for (i = 0;
         i < count; ++i) {
            p[i] = vs[i];
         }
         p[count] = p[0];
         var minArea = Number.MAX_VALUE;
         for (i = 1;
         i <= count; ++i) {
            var root = p[parseInt(i - 1)];
            var uxX = p[i].x - root.x;
            var uxY = p[i].y - root.y;
            var length = Math.sqrt(uxX * uxX + uxY * uxY);
            uxX /= length;
            uxY /= length;
            var uyX = (-uxY);
            var uyY = uxX;
            var lowerX = Number.MAX_VALUE;
            var lowerY = Number.MAX_VALUE;
            var upperX = (-Number.MAX_VALUE);
            var upperY = (-Number.MAX_VALUE);
            for (var j = 0; j < count; ++j) {
               var dX = p[j].x - root.x;
               var dY = p[j].y - root.y;
               var rX = (uxX * dX + uxY * dY);
               var rY = (uyX * dX + uyY * dY);
               if (rX < lowerX) lowerX = rX;
               if (rY < lowerY) lowerY = rY;
               if (rX > upperX) upperX = rX;
               if (rY > upperY) upperY = rY;
            }
            var area = (upperX - lowerX) * (upperY - lowerY);
            if (area < 0.95 * minArea) {
               minArea = area;
               obb.R.col1.x = uxX;
               obb.R.col1.y = uxY;
               obb.R.col2.x = uyX;
               obb.R.col2.y = uyY;
               var centerX = 0.5 * (lowerX + upperX);
               var centerY = 0.5 * (lowerY + upperY);
               var tMat = obb.R;
               obb.center.x = root.x + (tMat.col1.x * centerX + tMat.col2.x * centerY);
               obb.center.y = root.y + (tMat.col1.y * centerX + tMat.col2.y * centerY);
               obb.extents.x = 0.5 * (upperX - lowerX);
               obb.extents.y = 0.5 * (upperY - lowerY);
            }
         }
      }
      Box2D.postDefs.push(function () {
         Box2D.Collision.Shapes.b2PolygonShape.s_mat = new b2Mat22();
      });
      b2Shape.b2Shape = function () {};
      b2Shape.prototype.Copy = function () {
         return null;
      }
      b2Shape.prototype.Set = function (other) {
         this.m_radius = other.m_radius;
      }
      b2Shape.prototype.GetType = function () {
         return this.m_type;
      }
      b2Shape.prototype.TestPoint = function (xf, p) {
         return false;
      }
      b2Shape.prototype.RayCast = function (output, input, transform) {
         return false;
      }
      b2Shape.prototype.ComputeAABB = function (aabb, xf) {}
      b2Shape.prototype.ComputeMass = function (massData, density) {
         if (density === undefined) density = 0;
      }
      b2Shape.prototype.ComputeSubmergedArea = function (normal, offset, xf, c) {
         if (offset === undefined) offset = 0;
         return 0;
      }
      b2Shape.TestOverlap = function (shape1, transform1, shape2, transform2) {
         var input = new b2DistanceInput();
         input.proxyA = new b2DistanceProxy();
         input.proxyA.Set(shape1);
         input.proxyB = new b2DistanceProxy();
         input.proxyB.Set(shape2);
         input.transformA = transform1;
         input.transformB = transform2;
         input.useRadii = true;
         var simplexCache = new b2SimplexCache();
         simplexCache.count = 0;
         var output = new b2DistanceOutput();
         b2Distance.Distance(output, simplexCache, input);
         return output.distance < 10.0 * Number.MIN_VALUE;
      }
      b2Shape.prototype.b2Shape = function () {
         this.m_type = b2Shape.e_unknownShape;
         this.m_radius = b2Settings.b2_linearSlop;
      }
      Box2D.postDefs.push(function () {
         Box2D.Collision.Shapes.b2Shape.e_unknownShape = parseInt((-1));
         Box2D.Collision.Shapes.b2Shape.e_circleShape = 0;
         Box2D.Collision.Shapes.b2Shape.e_polygonShape = 1;
         Box2D.Collision.Shapes.b2Shape.e_edgeShape = 2;
         Box2D.Collision.Shapes.b2Shape.e_shapeTypeCount = 3;
         Box2D.Collision.Shapes.b2Shape.e_hitCollide = 1;
         Box2D.Collision.Shapes.b2Shape.e_missCollide = 0;
         Box2D.Collision.Shapes.b2Shape.e_startsInsideCollide = parseInt((-1));
      });
   })();
   (function () {
      var b2Color = Box2D.Common.b2Color,
         b2internal = Box2D.Common.b2internal,
         b2Settings = Box2D.Common.b2Settings,
         b2Mat22 = Box2D.Common.Math.b2Mat22,
         b2Mat33 = Box2D.Common.Math.b2Mat33,
         b2Math = Box2D.Common.Math.b2Math,
         b2Sweep = Box2D.Common.Math.b2Sweep,
         b2Transform = Box2D.Common.Math.b2Transform,
         b2Vec2 = Box2D.Common.Math.b2Vec2,
         b2Vec3 = Box2D.Common.Math.b2Vec3;

      b2Color.b2Color = function () {
         this._r = 0;
         this._g = 0;
         this._b = 0;
      };
      b2Color.prototype.b2Color = function (rr, gg, bb) {
         if (rr === undefined) rr = 0;
         if (gg === undefined) gg = 0;
         if (bb === undefined) bb = 0;
         this._r = Box2D.parseUInt(255 * b2Math.Clamp(rr, 0.0, 1.0));
         this._g = Box2D.parseUInt(255 * b2Math.Clamp(gg, 0.0, 1.0));
         this._b = Box2D.parseUInt(255 * b2Math.Clamp(bb, 0.0, 1.0));
      }
      b2Color.prototype.Set = function (rr, gg, bb) {
         if (rr === undefined) rr = 0;
         if (gg === undefined) gg = 0;
         if (bb === undefined) bb = 0;
         this._r = Box2D.parseUInt(255 * b2Math.Clamp(rr, 0.0, 1.0));
         this._g = Box2D.parseUInt(255 * b2Math.Clamp(gg, 0.0, 1.0));
         this._b = Box2D.parseUInt(255 * b2Math.Clamp(bb, 0.0, 1.0));
      }
      Object.defineProperty(b2Color.prototype, 'r', {
         enumerable: false,
         configurable: true,
         set: function (rr) {
            if (rr === undefined) rr = 0;
            this._r = Box2D.parseUInt(255 * b2Math.Clamp(rr, 0.0, 1.0));
         }
      });
      Object.defineProperty(b2Color.prototype, 'g', {
         enumerable: false,
         configurable: true,
         set: function (gg) {
            if (gg === undefined) gg = 0;
            this._g = Box2D.parseUInt(255 * b2Math.Clamp(gg, 0.0, 1.0));
         }
      });
      Object.defineProperty(b2Color.prototype, 'b', {
         enumerable: false,
         configurable: true,
         set: function (bb) {
            if (bb === undefined) bb = 0;
            this._b = Box2D.parseUInt(255 * b2Math.Clamp(bb, 0.0, 1.0));
         }
      });
      Object.defineProperty(b2Color.prototype, 'color', {
         enumerable: false,
         configurable: true,
         get: function () {
            return (this._r << 16) | (this._g << 8) | (this._b);
         }
      });
      b2Settings.b2Settings = function () {};
      b2Settings.b2MixFriction = function (friction1, friction2) {
         if (friction1 === undefined) friction1 = 0;
         if (friction2 === undefined) friction2 = 0;
         return Math.sqrt(friction1 * friction2);
      }
      b2Settings.b2MixRestitution = function (restitution1, restitution2) {
         /*
         if (restitution1 === undefined) restitution1 = 0;
         if (restitution2 === undefined) restitution2 = 0;
         return restitution1 > restitution2 ? restitution1 : restitution2;
         
         JDM: changed (see above in this comment) from "restitution1 : restitution2" to "restitution2 : restitution1" (see below), to take the lower of the two values.
         And made a corresponding change: all places where restitution was set to 0.0. Now set to 1.0. Search on JDM to find these changes.
         Restitution is undefined for walls, so they also yield 1.0 here, now (after these changes).
         */
         if (restitution1 === undefined) restitution1 = 1.0;  // JDM: changed 0 to 1.0
         if (restitution2 === undefined) restitution2 = 1.0;  // JDM: changed 0 to 1.0
         return restitution1 > restitution2 ? restitution2 : restitution1; 
      }
      b2Settings.b2Assert = function (a) {
         if (!a) {
            throw "Assertion Failed";
         }
      }
      Box2D.postDefs.push(function () {
         Box2D.Common.b2Settings.VERSION = "2.1alpha";
         Box2D.Common.b2Settings.USHRT_MAX = 0x0000ffff;
         Box2D.Common.b2Settings.b2_pi = Math.PI;
         Box2D.Common.b2Settings.b2_maxManifoldPoints = 2;
         Box2D.Common.b2Settings.b2_aabbExtension = 0.1;
         Box2D.Common.b2Settings.b2_aabbMultiplier = 2.0;
         Box2D.Common.b2Settings.b2_polygonRadius = 2.0 * b2Settings.b2_linearSlop;
         Box2D.Common.b2Settings.b2_linearSlop = 0.005;
         Box2D.Common.b2Settings.b2_angularSlop = 2.0 / 180.0 * b2Settings.b2_pi;
         Box2D.Common.b2Settings.b2_toiSlop = 8.0 * b2Settings.b2_linearSlop;
         Box2D.Common.b2Settings.b2_maxTOIContactsPerIsland = 32;
         Box2D.Common.b2Settings.b2_maxTOIJointsPerIsland = 32;
         Box2D.Common.b2Settings.b2_velocityThreshold = 1.0;
         Box2D.Common.b2Settings.b2_maxLinearCorrection = 0.2;
         Box2D.Common.b2Settings.b2_maxAngularCorrection = 8.0 / 180.0 * b2Settings.b2_pi;
         Box2D.Common.b2Settings.b2_maxTranslation = 2.0;
         Box2D.Common.b2Settings.b2_maxTranslationSquared = b2Settings.b2_maxTranslation * b2Settings.b2_maxTranslation;
         Box2D.Common.b2Settings.b2_maxRotation = 0.5 * b2Settings.b2_pi;
         Box2D.Common.b2Settings.b2_maxRotationSquared = b2Settings.b2_maxRotation * b2Settings.b2_maxRotation;
         Box2D.Common.b2Settings.b2_contactBaumgarte = 0.2;
         Box2D.Common.b2Settings.b2_timeToSleep = 0.5;
         Box2D.Common.b2Settings.b2_linearSleepTolerance = 0.01;
         Box2D.Common.b2Settings.b2_angularSleepTolerance = 2.0 / 180.0 * b2Settings.b2_pi;
      });
   })();
   (function () {
      var b2AABB = Box2D.Collision.b2AABB,
         b2Color = Box2D.Common.b2Color,
         b2internal = Box2D.Common.b2internal,
         b2Settings = Box2D.Common.b2Settings,
         b2Mat22 = Box2D.Common.Math.b2Mat22,
         b2Mat33 = Box2D.Common.Math.b2Mat33,
         b2Math = Box2D.Common.Math.b2Math,
         b2Sweep = Box2D.Common.Math.b2Sweep,
         b2Transform = Box2D.Common.Math.b2Transform,
         b2Vec2 = Box2D.Common.Math.b2Vec2,
         b2Vec3 = Box2D.Common.Math.b2Vec3;

      b2Mat22.b2Mat22 = function () {
         this.col1 = new b2Vec2();
         this.col2 = new b2Vec2();
      };
      b2Mat22.prototype.b2Mat22 = function () {
         this.SetIdentity();
      }
      b2Mat22.FromAngle = function (angle) {
         if (angle === undefined) angle = 0;
         var mat = new b2Mat22();
         mat.Set(angle);
         return mat;
      }
      b2Mat22.FromVV = function (c1, c2) {
         var mat = new b2Mat22();
         mat.SetVV(c1, c2);
         return mat;
      }
      b2Mat22.prototype.Set = function (angle) {
         if (angle === undefined) angle = 0;
         var c = Math.cos(angle);
         var s = Math.sin(angle);
         this.col1.x = c;
         this.col2.x = (-s);
         this.col1.y = s;
         this.col2.y = c;
      }
      b2Mat22.prototype.SetVV = function (c1, c2) {
         this.col1.SetV(c1);
         this.col2.SetV(c2);
      }
      b2Mat22.prototype.Copy = function () {
         var mat = new b2Mat22();
         mat.SetM(this);
         return mat;
      }
      b2Mat22.prototype.SetM = function (m) {
         this.col1.SetV(m.col1);
         this.col2.SetV(m.col2);
      }
      b2Mat22.prototype.AddM = function (m) {
         this.col1.x += m.col1.x;
         this.col1.y += m.col1.y;
         this.col2.x += m.col2.x;
         this.col2.y += m.col2.y;
      }
      b2Mat22.prototype.SetIdentity = function () {
         this.col1.x = 1.0;
         this.col2.x = 0.0;
         this.col1.y = 0.0;
         this.col2.y = 1.0;
      }
      b2Mat22.prototype.SetZero = function () {
         this.col1.x = 0.0;
         this.col2.x = 0.0;
         this.col1.y = 0.0;
         this.col2.y = 0.0;
      }
      b2Mat22.prototype.GetAngle = function () {
         return Math.atan2(this.col1.y, this.col1.x);
      }
      b2Mat22.prototype.GetInverse = function (out) {
         var a = this.col1.x;
         var b = this.col2.x;
         var c = this.col1.y;
         var d = this.col2.y;
         var det = a * d - b * c;
         if (det != 0.0) {
            det = 1.0 / det;
         }
         out.col1.x = det * d;
         out.col2.x = (-det * b);
         out.col1.y = (-det * c);
         out.col2.y = det * a;
         return out;
      }
      b2Mat22.prototype.Solve = function (out, bX, bY) {
         if (bX === undefined) bX = 0;
         if (bY === undefined) bY = 0;
         var a11 = this.col1.x;
         var a12 = this.col2.x;
         var a21 = this.col1.y;
         var a22 = this.col2.y;
         var det = a11 * a22 - a12 * a21;
         if (det != 0.0) {
            det = 1.0 / det;
         }
         out.x = det * (a22 * bX - a12 * bY);
         out.y = det * (a11 * bY - a21 * bX);
         return out;
      }
      b2Mat22.prototype.Abs = function () {
         this.col1.Abs();
         this.col2.Abs();
      }
      b2Mat33.b2Mat33 = function () {
         this.col1 = new b2Vec3();
         this.col2 = new b2Vec3();
         this.col3 = new b2Vec3();
      };
      b2Mat33.prototype.b2Mat33 = function (c1, c2, c3) {
         if (c1 === undefined) c1 = null;
         if (c2 === undefined) c2 = null;
         if (c3 === undefined) c3 = null;
         if (!c1 && !c2 && !c3) {
            this.col1.SetZero();
            this.col2.SetZero();
            this.col3.SetZero();
         }
         else {
            this.col1.SetV(c1);
            this.col2.SetV(c2);
            this.col3.SetV(c3);
         }
      }
      b2Mat33.prototype.SetVVV = function (c1, c2, c3) {
         this.col1.SetV(c1);
         this.col2.SetV(c2);
         this.col3.SetV(c3);
      }
      b2Mat33.prototype.Copy = function () {
         return new b2Mat33(this.col1, this.col2, this.col3);
      }
      b2Mat33.prototype.SetM = function (m) {
         this.col1.SetV(m.col1);
         this.col2.SetV(m.col2);
         this.col3.SetV(m.col3);
      }
      b2Mat33.prototype.AddM = function (m) {
         this.col1.x += m.col1.x;
         this.col1.y += m.col1.y;
         this.col1.z += m.col1.z;
         this.col2.x += m.col2.x;
         this.col2.y += m.col2.y;
         this.col2.z += m.col2.z;
         this.col3.x += m.col3.x;
         this.col3.y += m.col3.y;
         this.col3.z += m.col3.z;
      }
      b2Mat33.prototype.SetIdentity = function () {
         this.col1.x = 1.0;
         this.col2.x = 0.0;
         this.col3.x = 0.0;
         this.col1.y = 0.0;
         this.col2.y = 1.0;
         this.col3.y = 0.0;
         this.col1.z = 0.0;
         this.col2.z = 0.0;
         this.col3.z = 1.0;
      }
      b2Mat33.prototype.SetZero = function () {
         this.col1.x = 0.0;
         this.col2.x = 0.0;
         this.col3.x = 0.0;
         this.col1.y = 0.0;
         this.col2.y = 0.0;
         this.col3.y = 0.0;
         this.col1.z = 0.0;
         this.col2.z = 0.0;
         this.col3.z = 0.0;
      }
      b2Mat33.prototype.Solve22 = function (out, bX, bY) {
         if (bX === undefined) bX = 0;
         if (bY === undefined) bY = 0;
         var a11 = this.col1.x;
         var a12 = this.col2.x;
         var a21 = this.col1.y;
         var a22 = this.col2.y;
         var det = a11 * a22 - a12 * a21;
         if (det != 0.0) {
            det = 1.0 / det;
         }
         out.x = det * (a22 * bX - a12 * bY);
         out.y = det * (a11 * bY - a21 * bX);
         return out;
      }
      b2Mat33.prototype.Solve33 = function (out, bX, bY, bZ) {
         if (bX === undefined) bX = 0;
         if (bY === undefined) bY = 0;
         if (bZ === undefined) bZ = 0;
         var a11 = this.col1.x;
         var a21 = this.col1.y;
         var a31 = this.col1.z;
         var a12 = this.col2.x;
         var a22 = this.col2.y;
         var a32 = this.col2.z;
         var a13 = this.col3.x;
         var a23 = this.col3.y;
         var a33 = this.col3.z;
         var det = a11 * (a22 * a33 - a32 * a23) + a21 * (a32 * a13 - a12 * a33) + a31 * (a12 * a23 - a22 * a13);
         if (det != 0.0) {
            det = 1.0 / det;
         }
         out.x = det * (bX * (a22 * a33 - a32 * a23) + bY * (a32 * a13 - a12 * a33) + bZ * (a12 * a23 - a22 * a13));
         out.y = det * (a11 * (bY * a33 - bZ * a23) + a21 * (bZ * a13 - bX * a33) + a31 * (bX * a23 - bY * a13));
         out.z = det * (a11 * (a22 * bZ - a32 * bY) + a21 * (a32 * bX - a12 * bZ) + a31 * (a12 * bY - a22 * bX));
         return out;
      }
      b2Math.b2Math = function () {};
      b2Math.IsValid = function (x) {
         if (x === undefined) x = 0;
         return isFinite(x);
      }
      b2Math.Dot = function (a, b) {
         return a.x * b.x + a.y * b.y;
      }
      b2Math.CrossVV = function (a, b) {
         return a.x * b.y - a.y * b.x;
      }
      b2Math.CrossVF = function (a, s) {
         if (s === undefined) s = 0;
         var v = new b2Vec2(s * a.y, (-s * a.x));
         return v;
      }
      b2Math.CrossFV = function (s, a) {
         if (s === undefined) s = 0;
         var v = new b2Vec2((-s * a.y), s * a.x);
         return v;
      }
      b2Math.MulMV = function (A, v) {
         var u = new b2Vec2(A.col1.x * v.x + A.col2.x * v.y, A.col1.y * v.x + A.col2.y * v.y);
         return u;
      }
      b2Math.MulTMV = function (A, v) {
         var u = new b2Vec2(b2Math.Dot(v, A.col1), b2Math.Dot(v, A.col2));
         return u;
      }
      b2Math.MulX = function (T, v) {
         var a = b2Math.MulMV(T.R, v);
         a.x += T.position.x;
         a.y += T.position.y;
         return a;
      }
      b2Math.MulXT = function (T, v) {
         var a = b2Math.SubtractVV(v, T.position);
         var tX = (a.x * T.R.col1.x + a.y * T.R.col1.y);
         a.y = (a.x * T.R.col2.x + a.y * T.R.col2.y);
         a.x = tX;
         return a;
      }
      b2Math.AddVV = function (a, b) {
         var v = new b2Vec2(a.x + b.x, a.y + b.y);
         return v;
      }
      b2Math.SubtractVV = function (a, b) {
         var v = new b2Vec2(a.x - b.x, a.y - b.y);
         return v;
      }
      b2Math.Distance = function (a, b) {
         var cX = a.x - b.x;
         var cY = a.y - b.y;
         return Math.sqrt(cX * cX + cY * cY);
      }
      b2Math.DistanceSquared = function (a, b) {
         var cX = a.x - b.x;
         var cY = a.y - b.y;
         return (cX * cX + cY * cY);
      }
      b2Math.MulFV = function (s, a) {
         if (s === undefined) s = 0;
         var v = new b2Vec2(s * a.x, s * a.y);
         return v;
      }
      b2Math.AddMM = function (A, B) {
         var C = b2Mat22.FromVV(b2Math.AddVV(A.col1, B.col1), b2Math.AddVV(A.col2, B.col2));
         return C;
      }
      b2Math.MulMM = function (A, B) {
         var C = b2Mat22.FromVV(b2Math.MulMV(A, B.col1), b2Math.MulMV(A, B.col2));
         return C;
      }
      b2Math.MulTMM = function (A, B) {
         var c1 = new b2Vec2(b2Math.Dot(A.col1, B.col1), b2Math.Dot(A.col2, B.col1));
         var c2 = new b2Vec2(b2Math.Dot(A.col1, B.col2), b2Math.Dot(A.col2, B.col2));
         var C = b2Mat22.FromVV(c1, c2);
         return C;
      }
      b2Math.Abs = function (a) {
         if (a === undefined) a = 0;
         return a > 0.0 ? a : (-a);
      }
      b2Math.AbsV = function (a) {
         var b = new b2Vec2(b2Math.Abs(a.x), b2Math.Abs(a.y));
         return b;
      }
      b2Math.AbsM = function (A) {
         var B = b2Mat22.FromVV(b2Math.AbsV(A.col1), b2Math.AbsV(A.col2));
         return B;
      }
      b2Math.Min = function (a, b) {
         if (a === undefined) a = 0;
         if (b === undefined) b = 0;
         return a < b ? a : b;
      }
      b2Math.MinV = function (a, b) {
         var c = new b2Vec2(b2Math.Min(a.x, b.x), b2Math.Min(a.y, b.y));
         return c;
      }
      b2Math.Max = function (a, b) {
         if (a === undefined) a = 0;
         if (b === undefined) b = 0;
         return a > b ? a : b;
      }
      b2Math.MaxV = function (a, b) {
         var c = new b2Vec2(b2Math.Max(a.x, b.x), b2Math.Max(a.y, b.y));
         return c;
      }
      b2Math.Clamp = function (a, low, high) {
         if (a === undefined) a = 0;
         if (low === undefined) low = 0;
         if (high === undefined) high = 0;
         return a < low ? low : a > high ? high : a;
      }
      b2Math.ClampV = function (a, low, high) {
         return b2Math.MaxV(low, b2Math.MinV(a, high));
      }
      b2Math.Swap = function (a, b) {
         var tmp = a[0];
         a[0] = b[0];
         b[0] = tmp;
      }
      b2Math.Random = function () {
         return Math.random() * 2 - 1;
      }
      b2Math.RandomRange = function (lo, hi) {
         if (lo === undefined) lo = 0;
         if (hi === undefined) hi = 0;
         var r = Math.random();
         r = (hi - lo) * r + lo;
         return r;
      }
      b2Math.NextPowerOfTwo = function (x) {
         if (x === undefined) x = 0;
         x |= (x >> 1) & 0x7FFFFFFF;
         x |= (x >> 2) & 0x3FFFFFFF;
         x |= (x >> 4) & 0x0FFFFFFF;
         x |= (x >> 8) & 0x00FFFFFF;
         x |= (x >> 16) & 0x0000FFFF;
         return x + 1;
      }
      b2Math.IsPowerOfTwo = function (x) {
         if (x === undefined) x = 0;
         var result = x > 0 && (x & (x - 1)) == 0;
         return result;
      }
      Box2D.postDefs.push(function () {
         Box2D.Common.Math.b2Math.b2Vec2_zero = new b2Vec2(0.0, 0.0);
         Box2D.Common.Math.b2Math.b2Mat22_identity = b2Mat22.FromVV(new b2Vec2(1.0, 0.0), new b2Vec2(0.0, 1.0));
         Box2D.Common.Math.b2Math.b2Transform_identity = new b2Transform(b2Math.b2Vec2_zero, b2Math.b2Mat22_identity);
      });
      b2Sweep.b2Sweep = function () {
         this.localCenter = new b2Vec2();
         this.c0 = new b2Vec2;
         this.c = new b2Vec2();
      };
      b2Sweep.prototype.Set = function (other) {
         this.localCenter.SetV(other.localCenter);
         this.c0.SetV(other.c0);
         this.c.SetV(other.c);
         this.a0 = other.a0;
         this.a = other.a;
         this.t0 = other.t0;
      }
      b2Sweep.prototype.Copy = function () {
         var copy = new b2Sweep();
         copy.localCenter.SetV(this.localCenter);
         copy.c0.SetV(this.c0);
         copy.c.SetV(this.c);
         copy.a0 = this.a0;
         copy.a = this.a;
         copy.t0 = this.t0;
         return copy;
      }
      b2Sweep.prototype.GetTransform = function (xf, alpha) {
         if (alpha === undefined) alpha = 0;
         xf.position.x = (1.0 - alpha) * this.c0.x + alpha * this.c.x;
         xf.position.y = (1.0 - alpha) * this.c0.y + alpha * this.c.y;
         var angle = (1.0 - alpha) * this.a0 + alpha * this.a;
         xf.R.Set(angle);
         var tMat = xf.R;
         xf.position.x -= (tMat.col1.x * this.localCenter.x + tMat.col2.x * this.localCenter.y);
         xf.position.y -= (tMat.col1.y * this.localCenter.x + tMat.col2.y * this.localCenter.y);
      }
      b2Sweep.prototype.Advance = function (t) {
         if (t === undefined) t = 0;
         if (this.t0 < t && 1.0 - this.t0 > Number.MIN_VALUE) {
            var alpha = (t - this.t0) / (1.0 - this.t0);
            this.c0.x = (1.0 - alpha) * this.c0.x + alpha * this.c.x;
            this.c0.y = (1.0 - alpha) * this.c0.y + alpha * this.c.y;
            this.a0 = (1.0 - alpha) * this.a0 + alpha * this.a;
            this.t0 = t;
         }
      }
      b2Transform.b2Transform = function () {
         this.position = new b2Vec2;
         this.R = new b2Mat22();
      };
      b2Transform.prototype.b2Transform = function (pos, r) {
         if (pos === undefined) pos = null;
         if (r === undefined) r = null;
         if (pos) {
            this.position.SetV(pos);
            this.R.SetM(r);
         }
      }
      b2Transform.prototype.Initialize = function (pos, r) {
         this.position.SetV(pos);
         this.R.SetM(r);
      }
      b2Transform.prototype.SetIdentity = function () {
         this.position.SetZero();
         this.R.SetIdentity();
      }
      b2Transform.prototype.Set = function (x) {
         this.position.SetV(x.position);
         this.R.SetM(x.R);
      }
      b2Transform.prototype.GetAngle = function () {
         return Math.atan2(this.R.col1.y, this.R.col1.x);
      }
      b2Vec2.b2Vec2 = function () {};
      b2Vec2.prototype.b2Vec2 = function (x_, y_) {
         if (x_ === undefined) x_ = 0;
         if (y_ === undefined) y_ = 0;
         this.x = x_;
         this.y = y_;
      }
      b2Vec2.prototype.SetZero = function () {
         this.x = 0.0;
         this.y = 0.0;
      }
      b2Vec2.prototype.Set = function (x_, y_) {
         if (x_ === undefined) x_ = 0;
         if (y_ === undefined) y_ = 0;
         this.x = x_;
         this.y = y_;
      }
      b2Vec2.prototype.SetV = function (v) {
         this.x = v.x;
         this.y = v.y;
      }
      b2Vec2.prototype.GetNegative = function () {
         return new b2Vec2((-this.x), (-this.y));
      }
      b2Vec2.prototype.NegativeSelf = function () {
         this.x = (-this.x);
         this.y = (-this.y);
      }
      b2Vec2.Make = function (x_, y_) {
         if (x_ === undefined) x_ = 0;
         if (y_ === undefined) y_ = 0;
         return new b2Vec2(x_, y_);
      }
      b2Vec2.prototype.Copy = function () {
         return new b2Vec2(this.x, this.y);
      }
      b2Vec2.prototype.Add = function (v) {
         this.x += v.x;
         this.y += v.y;
      }
      b2Vec2.prototype.Subtract = function (v) {
         this.x -= v.x;
         this.y -= v.y;
      }
      b2Vec2.prototype.Multiply = function (a) {
         if (a === undefined) a = 0;
         this.x *= a;
         this.y *= a;
      }
      b2Vec2.prototype.MulM = function (A) {
         var tX = this.x;
         this.x = A.col1.x * tX + A.col2.x * this.y;
         this.y = A.col1.y * tX + A.col2.y * this.y;
      }
      b2Vec2.prototype.MulTM = function (A) {
         var tX = b2Math.Dot(this, A.col1);
         this.y = b2Math.Dot(this, A.col2);
         this.x = tX;
      }
      b2Vec2.prototype.CrossVF = function (s) {
         if (s === undefined) s = 0;
         var tX = this.x;
         this.x = s * this.y;
         this.y = (-s * tX);
      }
      b2Vec2.prototype.CrossFV = function (s) {
         if (s === undefined) s = 0;
         var tX = this.x;
         this.x = (-s * this.y);
         this.y = s * tX;
      }
      b2Vec2.prototype.MinV = function (b) {
         this.x = this.x < b.x ? this.x : b.x;
         this.y = this.y < b.y ? this.y : b.y;
      }
      b2Vec2.prototype.MaxV = function (b) {
         this.x = this.x > b.x ? this.x : b.x;
         this.y = this.y > b.y ? this.y : b.y;
      }
      b2Vec2.prototype.Abs = function () {
         if (this.x < 0) this.x = (-this.x);
         if (this.y < 0) this.y = (-this.y);
      }
      b2Vec2.prototype.Length = function () {
         return Math.sqrt(this.x * this.x + this.y * this.y);
      }
      b2Vec2.prototype.LengthSquared = function () {
         return (this.x * this.x + this.y * this.y);
      }
      b2Vec2.prototype.Normalize = function () {
         var length = Math.sqrt(this.x * this.x + this.y * this.y);
         if (length < Number.MIN_VALUE) {
            return 0.0;
         }
         var invLength = 1.0 / length;
         this.x *= invLength;
         this.y *= invLength;
         return length;
      }
      b2Vec2.prototype.IsValid = function () {
         return b2Math.IsValid(this.x) && b2Math.IsValid(this.y);
      }
      b2Vec3.b2Vec3 = function () {};
      b2Vec3.prototype.b2Vec3 = function (x, y, z) {
         if (x === undefined) x = 0;
         if (y === undefined) y = 0;
         if (z === undefined) z = 0;
         this.x = x;
         this.y = y;
         this.z = z;
      }
      b2Vec3.prototype.SetZero = function () {
         this.x = this.y = this.z = 0.0;
      }
      b2Vec3.prototype.Set = function (x, y, z) {
         if (x === undefined) x = 0;
         if (y === undefined) y = 0;
         if (z === undefined) z = 0;
         this.x = x;
         this.y = y;
         this.z = z;
      }
      b2Vec3.prototype.SetV = function (v) {
         this.x = v.x;
         this.y = v.y;
         this.z = v.z;
      }
      b2Vec3.prototype.GetNegative = function () {
         return new b2Vec3((-this.x), (-this.y), (-this.z));
      }
      b2Vec3.prototype.NegativeSelf = function () {
         this.x = (-this.x);
         this.y = (-this.y);
         this.z = (-this.z);
      }
      b2Vec3.prototype.Copy = function () {
         return new b2Vec3(this.x, this.y, this.z);
      }
      b2Vec3.prototype.Add = function (v) {
         this.x += v.x;
         this.y += v.y;
         this.z += v.z;
      }
      b2Vec3.prototype.Subtract = function (v) {
         this.x -= v.x;
         this.y -= v.y;
         this.z -= v.z;
      }
      b2Vec3.prototype.Multiply = function (a) {
         if (a === undefined) a = 0;
         this.x *= a;
         this.y *= a;
         this.z *= a;
      }
   })();
   (function () {
      var b2ControllerEdge = Box2D.Dynamics.Controllers.b2ControllerEdge,
         b2Mat22 = Box2D.Common.Math.b2Mat22,
         b2Mat33 = Box2D.Common.Math.b2Mat33,
         b2Math = Box2D.Common.Math.b2Math,
         b2Sweep = Box2D.Common.Math.b2Sweep,
         b2Transform = Box2D.Common.Math.b2Transform,
         b2Vec2 = Box2D.Common.Math.b2Vec2,
         b2Vec3 = Box2D.Common.Math.b2Vec3,
         b2Color = Box2D.Common.b2Color,
         b2internal = Box2D.Common.b2internal,
         b2Settings = Box2D.Common.b2Settings,
         b2AABB = Box2D.Collision.b2AABB,
         b2Bound = Box2D.Collision.b2Bound,
         b2BoundValues = Box2D.Collision.b2BoundValues,
         b2Collision = Box2D.Collision.b2Collision,
         b2ContactID = Box2D.Collision.b2ContactID,
         b2ContactPoint = Box2D.Collision.b2ContactPoint,
         b2Distance = Box2D.Collision.b2Distance,
         b2DistanceInput = Box2D.Collision.b2DistanceInput,
         b2DistanceOutput = Box2D.Collision.b2DistanceOutput,
         b2DistanceProxy = Box2D.Collision.b2DistanceProxy,
         b2DynamicTree = Box2D.Collision.b2DynamicTree,
         b2DynamicTreeBroadPhase = Box2D.Collision.b2DynamicTreeBroadPhase,
         b2DynamicTreeNode = Box2D.Collision.b2DynamicTreeNode,
         b2DynamicTreePair = Box2D.Collision.b2DynamicTreePair,
         b2Manifold = Box2D.Collision.b2Manifold,
         b2ManifoldPoint = Box2D.Collision.b2ManifoldPoint,
         b2Point = Box2D.Collision.b2Point,
         b2RayCastInput = Box2D.Collision.b2RayCastInput,
         b2RayCastOutput = Box2D.Collision.b2RayCastOutput,
         b2Segment = Box2D.Collision.b2Segment,
         b2SeparationFunction = Box2D.Collision.b2SeparationFunction,
         b2Simplex = Box2D.Collision.b2Simplex,
         b2SimplexCache = Box2D.Collision.b2SimplexCache,
         b2SimplexVertex = Box2D.Collision.b2SimplexVertex,
         b2TimeOfImpact = Box2D.Collision.b2TimeOfImpact,
         b2TOIInput = Box2D.Collision.b2TOIInput,
         b2WorldManifold = Box2D.Collision.b2WorldManifold,
         ClipVertex = Box2D.Collision.ClipVertex,
         Features = Box2D.Collision.Features,
         IBroadPhase = Box2D.Collision.IBroadPhase,
         b2CircleShape = Box2D.Collision.Shapes.b2CircleShape,
         b2EdgeChainDef = Box2D.Collision.Shapes.b2EdgeChainDef,
         b2EdgeShape = Box2D.Collision.Shapes.b2EdgeShape,
         b2MassData = Box2D.Collision.Shapes.b2MassData,
         b2PolygonShape = Box2D.Collision.Shapes.b2PolygonShape,
         b2Shape = Box2D.Collision.Shapes.b2Shape,
         b2Body = Box2D.Dynamics.b2Body,
         b2BodyDef = Box2D.Dynamics.b2BodyDef,
         b2ContactFilter = Box2D.Dynamics.b2ContactFilter,
         b2ContactImpulse = Box2D.Dynamics.b2ContactImpulse,
         b2ContactListener = Box2D.Dynamics.b2ContactListener,
         b2ContactManager = Box2D.Dynamics.b2ContactManager,
         b2DebugDraw = Box2D.Dynamics.b2DebugDraw,
         b2DestructionListener = Box2D.Dynamics.b2DestructionListener,
         b2FilterData