Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
requirebin sketch
var Box2D = require('box2dweb-commonjs').Box2D
var vkey = require('vkey')
var raf = require('raf')
var b2BodyDef = Box2D.Dynamics.b2BodyDef
var b2Body = Box2D.Dynamics.b2Body
var b2FixtureDef = Box2D.Dynamics.b2FixtureDef
var b2World = Box2D.Dynamics.b2World
var b2CircleShape = Box2D.Collision.Shapes.b2CircleShape
var b2DebugDraw = Box2D.Dynamics.b2DebugDraw
var canvas = document.createElement('canvas')
var ctx = canvas.getContext('2d')
canvas.width = 500
canvas.height = 300
ctx.fillStyle = '#f00'
ctx.fillRect(0, 0, 500, 300)
document.body.appendChild(canvas)
var jumping = false
var debugDraw = new b2DebugDraw
var gravity = { x: 0, y: 9.8 }
var world = new b2World(gravity, true)
debugDraw.SetDrawScale(18)
debugDraw.SetSprite(ctx)
debugDraw.SetFlags(
b2DebugDraw.e_shapeBit
| b2DebugDraw.e_jointBit
| b2DebugDraw.e_centerOfMassBit
| b2DebugDraw.e_controllerBit
| b2DebugDraw.e_pairBit
)
world.SetDebugDraw(debugDraw)
/**
* Player Setup
*/
var player = require('box2d-player')(Box2D)(world, {
position: { x: 10, y: 0 }
})
/**
* Loop
*/
raf(canvas).on('data', function(dt) {
player.body.m_linearVelocity.x = moving.x
if (jumping) player.jump()
world.Step(dt / 1000, 8, 3)
world.DrawDebugData()
})
/**
* "terrain"
*/
for (var i = 0; i < 5; i += 1) {
var def = new b2BodyDef
def.position = { x: i * 5 + 5, y: 15 }
def.type = b2Body.b2_staticBody
var shape = new b2CircleShape(i === 2 ? 4 : i % 2 ? 2 : 1)
var fixturedef = new b2FixtureDef
fixturedef.shape = shape
world.CreateBody(def).CreateFixture(fixturedef)
}
/**
* Input
*/
var moving = { x: 0, y: 0 }
function keydown(key) {
switch (key) {
case 'A': case '<left>': moving.x = -5; break
case 'D': case '<right>': moving.x = +5; break
case 'W': case '<up>': jumping = true; break
}
}
function keyup(key) {
switch (key) {
case 'A': case '<left>': moving.x = 0; break
case 'D': case '<right>': moving.x = 0; break
case 'W': case '<up>': jumping = false; break
}
}
document.body.addEventListener('keydown', function(e) {
keydown(vkey[e.keyCode])
}, false)
document.body.addEventListener('keyup', function(e) {
keyup(vkey[e.keyCode])
}, false)
function keydown(t){switch(t){case"A":case"<left>":moving.x=-5;break;case"D":case"<right>":moving.x=5;break;case"W":case"<up>":jumping=!0}}function keyup(t){switch(t){case"A":case"<left>":moving.x=0;break;case"D":case"<right>":moving.x=0;break;case"W":case"<up>":jumping=!1}}require=function e(t,i,o){function n(r,a){if(!i[r]){if(!t[r]){var m="function"==typeof require&&require;if(!a&&m)return m(r,!0);if(s)return s(r,!0);throw Error("Cannot find module '"+r+"'")}var l=i[r]={exports:{}};t[r][0].call(l.exports,function(i){var e=t[r][1][i];return n(e?e:i)},l,l.exports,e,t,i,o)}return i[r].exports}for(var s="function"==typeof require&&require,r=0;o.length>r;r++)n(o[r]);return n}({mgSi3g:[function(t,i,e){var o={};(function(t,i){function e(){}!Object.defineProperty&&Object.prototype.__defineGetter__ instanceof Function&&Object.prototype.__defineSetter__ instanceof Function&&(Object.defineProperty=function(t,i,e){e.get instanceof Function&&t.__defineGetter__(i,e.get),e.set instanceof Function&&t.__defineSetter__(i,e.set)}),t.inherit=function(t,i){var o=t;e.prototype=i.prototype,t.prototype=new e,t.prototype.constructor=o},t.generateCallback=function(t,i){return function(){i.apply(t,arguments)}},t.NVector=function(t){t===i&&(t=0);for(var e=Array(t||0),o=0;t>o;++o)e[o]=0;return e},t.is=function(t,e){return null===t?!1:e instanceof Function&&t instanceof e?!0:t.constructor.__implements!=i&&t.constructor.__implements[e]?!0:!1},t.parseUInt=function(t){return Math.abs(parseInt(t))}})(o);var n=Array,s=o.NVector;o===void 0&&(o={}),o.Collision===void 0&&(o.Collision={}),o.Collision.Shapes===void 0&&(o.Collision.Shapes={}),o.Common===void 0&&(o.Common={}),o.Common.Math===void 0&&(o.Common.Math={}),o.Dynamics===void 0&&(o.Dynamics={}),o.Dynamics.Contacts===void 0&&(o.Dynamics.Contacts={}),o.Dynamics.Controllers===void 0&&(o.Dynamics.Controllers={}),o.Dynamics.Joints===void 0&&(o.Dynamics.Joints={}),function(){function t(){t.b2AABB.apply(this,arguments)}function i(){i.b2Bound.apply(this,arguments)}function e(){e.b2BoundValues.apply(this,arguments),this.constructor===e&&this.b2BoundValues.apply(this,arguments)}function n(){n.b2Collision.apply(this,arguments)}function s(){s.b2ContactID.apply(this,arguments),this.constructor===s&&this.b2ContactID.apply(this,arguments)}function r(){r.b2ContactPoint.apply(this,arguments)}function a(){a.b2Distance.apply(this,arguments)}function m(){m.b2DistanceInput.apply(this,arguments)}function l(){l.b2DistanceOutput.apply(this,arguments)}function c(){c.b2DistanceProxy.apply(this,arguments)}function h(){h.b2DynamicTree.apply(this,arguments),this.constructor===h&&this.b2DynamicTree.apply(this,arguments)}function _(){_.b2DynamicTreeBroadPhase.apply(this,arguments)}function p(){p.b2DynamicTreeNode.apply(this,arguments)}function y(){y.b2DynamicTreePair.apply(this,arguments)}function u(){u.b2Manifold.apply(this,arguments),this.constructor===u&&this.b2Manifold.apply(this,arguments)}function x(){x.b2ManifoldPoint.apply(this,arguments),this.constructor===x&&this.b2ManifoldPoint.apply(this,arguments)}function f(){f.b2Point.apply(this,arguments)}function d(){d.b2RayCastInput.apply(this,arguments),this.constructor===d&&this.b2RayCastInput.apply(this,arguments)}function b(){b.b2RayCastOutput.apply(this,arguments)}function v(){v.b2Segment.apply(this,arguments)}function C(){C.b2SeparationFunction.apply(this,arguments)}function g(){g.b2Simplex.apply(this,arguments),this.constructor===g&&this.b2Simplex.apply(this,arguments)}function w(){w.b2SimplexCache.apply(this,arguments)}function A(){A.b2SimplexVertex.apply(this,arguments)}function S(){S.b2TimeOfImpact.apply(this,arguments)}function D(){D.b2TOIInput.apply(this,arguments)}function B(){B.b2WorldManifold.apply(this,arguments),this.constructor===B&&this.b2WorldManifold.apply(this,arguments)}function M(){M.ClipVertex.apply(this,arguments)}function V(){V.Features.apply(this,arguments)}function I(){I.b2CircleShape.apply(this,arguments),this.constructor===I&&this.b2CircleShape.apply(this,arguments)}function G(){G.b2EdgeChainDef.apply(this,arguments),this.constructor===G&&this.b2EdgeChainDef.apply(this,arguments)}function L(){L.b2EdgeShape.apply(this,arguments),this.constructor===L&&this.b2EdgeShape.apply(this,arguments)}function J(){J.b2MassData.apply(this,arguments)}function F(){F.b2PolygonShape.apply(this,arguments),this.constructor===F&&this.b2PolygonShape.apply(this,arguments)}function P(){P.b2Shape.apply(this,arguments),this.constructor===P&&this.b2Shape.apply(this,arguments)}function T(){T.b2Color.apply(this,arguments),this.constructor===T&&this.b2Color.apply(this,arguments)}function R(){R.b2Settings.apply(this,arguments)}function k(){k.b2Mat22.apply(this,arguments),this.constructor===k&&this.b2Mat22.apply(this,arguments)}function E(){E.b2Mat33.apply(this,arguments),this.constructor===E&&this.b2Mat33.apply(this,arguments)}function z(){z.b2Math.apply(this,arguments)}function N(){N.b2Sweep.apply(this,arguments)}function j(){j.b2Transform.apply(this,arguments),this.constructor===j&&this.b2Transform.apply(this,arguments)}function q(){q.b2Vec2.apply(this,arguments),this.constructor===q&&this.b2Vec2.apply(this,arguments)}function O(){O.b2Vec3.apply(this,arguments),this.constructor===O&&this.b2Vec3.apply(this,arguments)}function U(){U.b2Body.apply(this,arguments),this.constructor===U&&this.b2Body.apply(this,arguments)}function W(){W.b2BodyDef.apply(this,arguments),this.constructor===W&&this.b2BodyDef.apply(this,arguments)}function K(){K.b2ContactFilter.apply(this,arguments)}function X(){X.b2ContactImpulse.apply(this,arguments)}function Z(){Z.b2ContactListener.apply(this,arguments)}function H(){H.b2ContactManager.apply(this,arguments),this.constructor===H&&this.b2ContactManager.apply(this,arguments)}function Y(){Y.b2DebugDraw.apply(this,arguments),this.constructor===Y&&this.b2DebugDraw.apply(this,arguments)}function Q(){Q.b2DestructionListener.apply(this,arguments)}function $(){$.b2FilterData.apply(this,arguments)}function ti(){ti.b2Fixture.apply(this,arguments),this.constructor===ti&&this.b2Fixture.apply(this,arguments)}function ii(){ii.b2FixtureDef.apply(this,arguments),this.constructor===ii&&this.b2FixtureDef.apply(this,arguments)}function ei(){ei.b2Island.apply(this,arguments),this.constructor===ei&&this.b2Island.apply(this,arguments)}function oi(){oi.b2TimeStep.apply(this,arguments)}function ni(){ni.b2World.apply(this,arguments),this.constructor===ni&&this.b2World.apply(this,arguments)}function si(){si.b2CircleContact.apply(this,arguments)}function ri(){ri.b2Contact.apply(this,arguments),this.constructor===ri&&this.b2Contact.apply(this,arguments)}function ai(){ai.b2ContactConstraint.apply(this,arguments),this.constructor===ai&&this.b2ContactConstraint.apply(this,arguments)}function mi(){mi.b2ContactConstraintPoint.apply(this,arguments)}function li(){li.b2ContactEdge.apply(this,arguments)}function ci(){ci.b2ContactFactory.apply(this,arguments),this.constructor===ci&&this.b2ContactFactory.apply(this,arguments)}function hi(){hi.b2ContactRegister.apply(this,arguments)}function _i(){_i.b2ContactResult.apply(this,arguments)}function pi(){pi.b2ContactSolver.apply(this,arguments),this.constructor===pi&&this.b2ContactSolver.apply(this,arguments)}function yi(){yi.b2EdgeAndCircleContact.apply(this,arguments)}function ui(){ui.b2NullContact.apply(this,arguments),this.constructor===ui&&this.b2NullContact.apply(this,arguments)}function xi(){xi.b2PolyAndCircleContact.apply(this,arguments)}function fi(){fi.b2PolyAndEdgeContact.apply(this,arguments)}function di(){di.b2PolygonContact.apply(this,arguments)}function bi(){bi.b2PositionSolverManifold.apply(this,arguments),this.constructor===bi&&this.b2PositionSolverManifold.apply(this,arguments)}function vi(){vi.b2BuoyancyController.apply(this,arguments)}function Ci(){Ci.b2ConstantAccelController.apply(this,arguments)}function gi(){gi.b2ConstantForceController.apply(this,arguments)}function wi(){wi.b2Controller.apply(this,arguments)}function Ai(){Ai.b2ControllerEdge.apply(this,arguments)}function Si(){Si.b2GravityController.apply(this,arguments)}function Di(){Di.b2TensorDampingController.apply(this,arguments)}function Bi(){Bi.b2DistanceJoint.apply(this,arguments),this.constructor===Bi&&this.b2DistanceJoint.apply(this,arguments)}function Mi(){Mi.b2DistanceJointDef.apply(this,arguments),this.constructor===Mi&&this.b2DistanceJointDef.apply(this,arguments)}function Vi(){Vi.b2FrictionJoint.apply(this,arguments),this.constructor===Vi&&this.b2FrictionJoint.apply(this,arguments)}function Ii(){Ii.b2FrictionJointDef.apply(this,arguments),this.constructor===Ii&&this.b2FrictionJointDef.apply(this,arguments)}function Gi(){Gi.b2GearJoint.apply(this,arguments),this.constructor===Gi&&this.b2GearJoint.apply(this,arguments)}function Li(){Li.b2GearJointDef.apply(this,arguments),this.constructor===Li&&this.b2GearJointDef.apply(this,arguments)}function Ji(){Ji.b2Jacobian.apply(this,arguments)}function Fi(){Fi.b2Joint.apply(this,arguments),this.constructor===Fi&&this.b2Joint.apply(this,arguments)}function Pi(){Pi.b2JointDef.apply(this,arguments),this.constructor===Pi&&this.b2JointDef.apply(this,arguments)}function Ti(){Ti.b2JointEdge.apply(this,arguments)}function Ri(){Ri.b2LineJoint.apply(this,arguments),this.constructor===Ri&&this.b2LineJoint.apply(this,arguments)}function ki(){ki.b2LineJointDef.apply(this,arguments),this.constructor===ki&&this.b2LineJointDef.apply(this,arguments)}function Ei(){Ei.b2MouseJoint.apply(this,arguments),this.constructor===Ei&&this.b2MouseJoint.apply(this,arguments)}function zi(){zi.b2MouseJointDef.apply(this,arguments),this.constructor===zi&&this.b2MouseJointDef.apply(this,arguments)}function Ni(){Ni.b2PrismaticJoint.apply(this,arguments),this.constructor===Ni&&this.b2PrismaticJoint.apply(this,arguments)}function ji(){ji.b2PrismaticJointDef.apply(this,arguments),this.constructor===ji&&this.b2PrismaticJointDef.apply(this,arguments)}function qi(){qi.b2PulleyJoint.apply(this,arguments),this.constructor===qi&&this.b2PulleyJoint.apply(this,arguments)}function Oi(){Oi.b2PulleyJointDef.apply(this,arguments),this.constructor===Oi&&this.b2PulleyJointDef.apply(this,arguments)}function Ui(){Ui.b2RevoluteJoint.apply(this,arguments),this.constructor===Ui&&this.b2RevoluteJoint.apply(this,arguments)}function Wi(){Wi.b2RevoluteJointDef.apply(this,arguments),this.constructor===Wi&&this.b2RevoluteJointDef.apply(this,arguments)}function Ki(){Ki.b2WeldJoint.apply(this,arguments),this.constructor===Ki&&this.b2WeldJoint.apply(this,arguments)}function Xi(){Xi.b2WeldJointDef.apply(this,arguments),this.constructor===Xi&&this.b2WeldJointDef.apply(this,arguments)}o.Collision.IBroadPhase="Box2D.Collision.IBroadPhase",o.Collision.b2AABB=t,o.Collision.b2Bound=i,o.Collision.b2BoundValues=e,o.Collision.b2Collision=n,o.Collision.b2ContactID=s,o.Collision.b2ContactPoint=r,o.Collision.b2Distance=a,o.Collision.b2DistanceInput=m,o.Collision.b2DistanceOutput=l,o.Collision.b2DistanceProxy=c,o.Collision.b2DynamicTree=h,o.Collision.b2DynamicTreeBroadPhase=_,o.Collision.b2DynamicTreeNode=p,o.Collision.b2DynamicTreePair=y,o.Collision.b2Manifold=u,o.Collision.b2ManifoldPoint=x,o.Collision.b2Point=f,o.Collision.b2RayCastInput=d,o.Collision.b2RayCastOutput=b,o.Collision.b2Segment=v,o.Collision.b2SeparationFunction=C,o.Collision.b2Simplex=g,o.Collision.b2SimplexCache=w,o.Collision.b2SimplexVertex=A,o.Collision.b2TimeOfImpact=S,o.Collision.b2TOIInput=D,o.Collision.b2WorldManifold=B,o.Collision.ClipVertex=M,o.Collision.Features=V,o.Collision.Shapes.b2CircleShape=I,o.Collision.Shapes.b2EdgeChainDef=G,o.Collision.Shapes.b2EdgeShape=L,o.Collision.Shapes.b2MassData=J,o.Collision.Shapes.b2PolygonShape=F,o.Collision.Shapes.b2Shape=P,o.Common.b2internal="Box2D.Common.b2internal",o.Common.b2Color=T,o.Common.b2Settings=R,o.Common.Math.b2Mat22=k,o.Common.Math.b2Mat33=E,o.Common.Math.b2Math=z,o.Common.Math.b2Sweep=N,o.Common.Math.b2Transform=j,o.Common.Math.b2Vec2=q,o.Common.Math.b2Vec3=O,o.Dynamics.b2Body=U,o.Dynamics.b2BodyDef=W,o.Dynamics.b2ContactFilter=K,o.Dynamics.b2ContactImpulse=X,o.Dynamics.b2ContactListener=Z,o.Dynamics.b2ContactManager=H,o.Dynamics.b2DebugDraw=Y,o.Dynamics.b2DestructionListener=Q,o.Dynamics.b2FilterData=$,o.Dynamics.b2Fixture=ti,o.Dynamics.b2FixtureDef=ii,o.Dynamics.b2Island=ei,o.Dynamics.b2TimeStep=oi,o.Dynamics.b2World=ni,o.Dynamics.Contacts.b2CircleContact=si,o.Dynamics.Contacts.b2Contact=ri,o.Dynamics.Contacts.b2ContactConstraint=ai,o.Dynamics.Contacts.b2ContactConstraintPoint=mi,o.Dynamics.Contacts.b2ContactEdge=li,o.Dynamics.Contacts.b2ContactFactory=ci,o.Dynamics.Contacts.b2ContactRegister=hi,o.Dynamics.Contacts.b2ContactResult=_i,o.Dynamics.Contacts.b2ContactSolver=pi,o.Dynamics.Contacts.b2EdgeAndCircleContact=yi,o.Dynamics.Contacts.b2NullContact=ui,o.Dynamics.Contacts.b2PolyAndCircleContact=xi,o.Dynamics.Contacts.b2PolyAndEdgeContact=fi,o.Dynamics.Contacts.b2PolygonContact=di,o.Dynamics.Contacts.b2PositionSolverManifold=bi,o.Dynamics.Controllers.b2BuoyancyController=vi,o.Dynamics.Controllers.b2ConstantAccelController=Ci,o.Dynamics.Controllers.b2ConstantForceController=gi,o.Dynamics.Controllers.b2Controller=wi,o.Dynamics.Controllers.b2ControllerEdge=Ai,o.Dynamics.Controllers.b2GravityController=Si,o.Dynamics.Controllers.b2TensorDampingController=Di,o.Dynamics.Joints.b2DistanceJoint=Bi,o.Dynamics.Joints.b2DistanceJointDef=Mi,o.Dynamics.Joints.b2FrictionJoint=Vi,o.Dynamics.Joints.b2FrictionJointDef=Ii,o.Dynamics.Joints.b2GearJoint=Gi,o.Dynamics.Joints.b2GearJointDef=Li,o.Dynamics.Joints.b2Jacobian=Ji,o.Dynamics.Joints.b2Joint=Fi,o.Dynamics.Joints.b2JointDef=Pi,o.Dynamics.Joints.b2JointEdge=Ti,o.Dynamics.Joints.b2LineJoint=Ri,o.Dynamics.Joints.b2LineJointDef=ki,o.Dynamics.Joints.b2MouseJoint=Ei,o.Dynamics.Joints.b2MouseJointDef=zi,o.Dynamics.Joints.b2PrismaticJoint=Ni,o.Dynamics.Joints.b2PrismaticJointDef=ji,o.Dynamics.Joints.b2PulleyJoint=qi,o.Dynamics.Joints.b2PulleyJointDef=Oi,o.Dynamics.Joints.b2RevoluteJoint=Ui,o.Dynamics.Joints.b2RevoluteJointDef=Wi,o.Dynamics.Joints.b2WeldJoint=Ki,o.Dynamics.Joints.b2WeldJointDef=Xi}(),o.postDefs=[],function(){var t=o.Collision.Shapes.b2CircleShape,i=(o.Collision.Shapes.b2EdgeChainDef,o.Collision.Shapes.b2EdgeShape,o.Collision.Shapes.b2MassData,o.Collision.Shapes.b2PolygonShape),e=o.Collision.Shapes.b2Shape,r=(o.Common.b2Color,o.Common.b2internal,o.Common.b2Settings),a=(o.Common.Math.b2Mat22,o.Common.Math.b2Mat33,o.Common.Math.b2Math),m=o.Common.Math.b2Sweep,l=o.Common.Math.b2Transform,c=o.Common.Math.b2Vec2,h=(o.Common.Math.b2Vec3,o.Collision.b2AABB),_=o.Collision.b2Bound,p=o.Collision.b2BoundValues,y=o.Collision.b2Collision,u=o.Collision.b2ContactID,x=o.Collision.b2ContactPoint,f=o.Collision.b2Distance,d=o.Collision.b2DistanceInput,b=o.Collision.b2DistanceOutput,v=o.Collision.b2DistanceProxy,C=o.Collision.b2DynamicTree,g=o.Collision.b2DynamicTreeBroadPhase,w=o.Collision.b2DynamicTreeNode,A=o.Collision.b2DynamicTreePair,S=o.Collision.b2Manifold,D=o.Collision.b2ManifoldPoint,B=o.Collision.b2Point,M=o.Collision.b2RayCastInput,V=o.Collision.b2RayCastOutput,I=o.Collision.b2Segment,G=o.Collision.b2SeparationFunction,L=o.Collision.b2Simplex,J=o.Collision.b2SimplexCache,F=o.Collision.b2SimplexVertex,P=o.Collision.b2TimeOfImpact,T=o.Collision.b2TOIInput,R=o.Collision.b2WorldManifold,k=o.Collision.ClipVertex,E=o.Collision.Features,z=o.Collision.IBroadPhase;h.b2AABB=function(){this.lowerBound=new c,this.upperBound=new c},h.prototype.IsValid=function(){var t=this.upperBound.x-this.lowerBound.x,i=this.upperBound.y-this.lowerBound.y,e=t>=0&&i>=0;return e=e&&this.lowerBound.IsValid()&&this.upperBound.IsValid()},h.prototype.GetCenter=function(){return new c((this.lowerBound.x+this.upperBound.x)/2,(this.lowerBound.y+this.upperBound.y)/2)},h.prototype.GetExtents=function(){return new c((this.upperBound.x-this.lowerBound.x)/2,(this.upperBound.y-this.lowerBound.y)/2)},h.prototype.Contains=function(t){var i=!0;return i=i&&this.lowerBound.x<=t.lowerBound.x,i=i&&this.lowerBound.y<=t.lowerBound.y,i=i&&t.upperBound.x<=this.upperBound.x,i=i&&t.upperBound.y<=this.upperBound.y},h.prototype.RayCast=function(t,i){var e=-Number.MAX_VALUE,o=Number.MAX_VALUE,n=i.p1.x,s=i.p1.y,r=i.p2.x-i.p1.x,a=i.p2.y-i.p1.y,m=Math.abs(r),l=Math.abs(a),c=t.normal,h=0,_=0,p=0,y=0,u=0;if(Number.MIN_VALUE>m){if(this.lowerBound.x>n||n>this.upperBound.x)return!1}else if(h=1/r,_=(this.lowerBound.x-n)*h,p=(this.upperBound.x-n)*h,u=-1,_>p&&(y=_,_=p,p=y,u=1),_>e&&(c.x=u,c.y=0,e=_),o=Math.min(o,p),e>o)return!1;if(Number.MIN_VALUE>l){if(this.lowerBound.y>s||s>this.upperBound.y)return!1}else if(h=1/a,_=(this.lowerBound.y-s)*h,p=(this.upperBound.y-s)*h,u=-1,_>p&&(y=_,_=p,p=y,u=1),_>e&&(c.y=u,c.x=0,e=_),o=Math.min(o,p),e>o)return!1;return t.fraction=e,!0},h.prototype.TestOverlap=function(t){var i=t.lowerBound.x-this.upperBound.x,e=t.lowerBound.y-this.upperBound.y,o=this.lowerBound.x-t.upperBound.x,n=this.lowerBound.y-t.upperBound.y;return i>0||e>0?!1:o>0||n>0?!1:!0},h.Combine=function(t,i){var e=new h;return e.Combine(t,i),e},h.prototype.Combine=function(t,i){this.lowerBound.x=Math.min(t.lowerBound.x,i.lowerBound.x),this.lowerBound.y=Math.min(t.lowerBound.y,i.lowerBound.y),this.upperBound.x=Math.max(t.upperBound.x,i.upperBound.x),this.upperBound.y=Math.max(t.upperBound.y,i.upperBound.y)},_.b2Bound=function(){},_.prototype.IsLower=function(){return 0==(1&this.value)},_.prototype.IsUpper=function(){return 1==(1&this.value)},_.prototype.Swap=function(t){var i=this.value,e=this.proxy,o=this.stabbingCount;this.value=t.value,this.proxy=t.proxy,this.stabbingCount=t.stabbingCount,t.value=i,t.proxy=e,t.stabbingCount=o},p.b2BoundValues=function(){},p.prototype.b2BoundValues=function(){this.lowerValues=new s,this.lowerValues[0]=0,this.lowerValues[1]=0,this.upperValues=new s,this.upperValues[0]=0,this.upperValues[1]=0},y.b2Collision=function(){},y.ClipSegmentToLine=function(t,i,e,o){void 0===o&&(o=0);var n,s=0;n=i[0];var r=n.v;n=i[1];var a=n.v,m=e.x*r.x+e.y*r.y-o,l=e.x*a.x+e.y*a.y-o;if(0>=m&&t[s++].Set(i[0]),0>=l&&t[s++].Set(i[1]),0>m*l){var c=m/(m-l);n=t[s];var h=n.v;h.x=r.x+c*(a.x-r.x),h.y=r.y+c*(a.y-r.y),n=t[s];var _;m>0?(_=i[0],n.id=_.id):(_=i[1],n.id=_.id),++s}return s},y.EdgeSeparation=function(t,i,e,o,n){void 0===e&&(e=0),parseInt(t.m_vertexCount);var s,r,a=t.m_vertices,m=t.m_normals,l=parseInt(o.m_vertexCount),c=o.m_vertices;s=i.R,r=m[e];var h=s.col1.x*r.x+s.col2.x*r.y,_=s.col1.y*r.x+s.col2.y*r.y;s=n.R;for(var p=s.col1.x*h+s.col1.y*_,y=s.col2.x*h+s.col2.y*_,u=0,x=Number.MAX_VALUE,f=0;l>f;++f){r=c[f];var d=r.x*p+r.y*y;x>d&&(x=d,u=f)}r=a[e],s=i.R;var b=i.position.x+(s.col1.x*r.x+s.col2.x*r.y),v=i.position.y+(s.col1.y*r.x+s.col2.y*r.y);r=c[u],s=n.R;var C=n.position.x+(s.col1.x*r.x+s.col2.x*r.y),g=n.position.y+(s.col1.y*r.x+s.col2.y*r.y);C-=b,g-=v;var w=C*h+g*_;return w},y.FindMaxSeparation=function(t,i,e,o,n){var s,r,a=parseInt(i.m_vertexCount),m=i.m_normals;r=n.R,s=o.m_centroid;var l=n.position.x+(r.col1.x*s.x+r.col2.x*s.y),c=n.position.y+(r.col1.y*s.x+r.col2.y*s.y);r=e.R,s=i.m_centroid,l-=e.position.x+(r.col1.x*s.x+r.col2.x*s.y),c-=e.position.y+(r.col1.y*s.x+r.col2.y*s.y);for(var h=l*e.R.col1.x+c*e.R.col1.y,_=l*e.R.col2.x+c*e.R.col2.y,p=0,u=-Number.MAX_VALUE,x=0;a>x;++x){s=m[x];var f=s.x*h+s.y*_;f>u&&(u=f,p=x)}var d=y.EdgeSeparation(i,e,p,o,n),b=parseInt(p-1>=0?p-1:a-1),v=y.EdgeSeparation(i,e,b,o,n),C=parseInt(a>p+1?p+1:0),g=y.EdgeSeparation(i,e,C,o,n),w=0,A=0,S=0;if(v>d&&v>g)S=-1,w=b,A=v;else{if(!(g>d))return t[0]=p,d;S=1,w=C,A=g}for(;;){if(p=-1==S?w-1>=0?w-1:a-1:a>w+1?w+1:0,d=y.EdgeSeparation(i,e,p,o,n),!(d>A))break;w=p,A=d}return t[0]=w,A},y.FindIncidentEdge=function(t,i,e,o,n,s){void 0===o&&(o=0),parseInt(i.m_vertexCount);var r,a,m=i.m_normals,l=parseInt(n.m_vertexCount),c=n.m_vertices,h=n.m_normals;r=e.R,a=m[o];var _=r.col1.x*a.x+r.col2.x*a.y,p=r.col1.y*a.x+r.col2.y*a.y;r=s.R;var y=r.col1.x*_+r.col1.y*p;p=r.col2.x*_+r.col2.y*p,_=y;for(var u=0,x=Number.MAX_VALUE,f=0;l>f;++f){a=h[f];var d=_*a.x+p*a.y;x>d&&(x=d,u=f)}var b,v=parseInt(u),C=parseInt(l>v+1?v+1:0);b=t[0],a=c[v],r=s.R,b.v.x=s.position.x+(r.col1.x*a.x+r.col2.x*a.y),b.v.y=s.position.y+(r.col1.y*a.x+r.col2.y*a.y),b.id.features.referenceEdge=o,b.id.features.incidentEdge=v,b.id.features.incidentVertex=0,b=t[1],a=c[C],r=s.R,b.v.x=s.position.x+(r.col1.x*a.x+r.col2.x*a.y),b.v.y=s.position.y+(r.col1.y*a.x+r.col2.y*a.y),b.id.features.referenceEdge=o,b.id.features.incidentEdge=C,b.id.features.incidentVertex=1},y.MakeClipPointVector=function(){var t=new n(2);return t[0]=new k,t[1]=new k,t},y.CollidePolygons=function(t,i,e,o,n){var s;t.m_pointCount=0;var a=i.m_radius+o.m_radius,m=0;y.s_edgeAO[0]=m;var l=y.FindMaxSeparation(y.s_edgeAO,i,e,o,n);if(m=y.s_edgeAO[0],!(l>a)){var c=0;y.s_edgeBO[0]=c;var h=y.FindMaxSeparation(y.s_edgeBO,o,n,i,e);if(c=y.s_edgeBO[0],!(h>a)){var _,p,u,x,f,d=0,b=0,v=.98,C=.001;h>v*l+C?(_=o,p=i,u=n,x=e,d=c,t.m_type=S.e_faceB,b=1):(_=i,p=o,u=e,x=n,d=m,t.m_type=S.e_faceA,b=0);var g=y.s_incidentEdge;y.FindIncidentEdge(g,_,u,d,p,x);var w,A=parseInt(_.m_vertexCount),D=_.m_vertices,B=D[d];w=A>d+1?D[parseInt(d+1)]:D[0];var M=y.s_localTangent;M.Set(w.x-B.x,w.y-B.y),M.Normalize();var V=y.s_localNormal;V.x=M.y,V.y=-M.x;var I=y.s_planePoint;I.Set(.5*(B.x+w.x),.5*(B.y+w.y));var G=y.s_tangent;f=u.R,G.x=f.col1.x*M.x+f.col2.x*M.y,G.y=f.col1.y*M.x+f.col2.y*M.y;var L=y.s_tangent2;L.x=-G.x,L.y=-G.y;var J=y.s_normal;J.x=G.y,J.y=-G.x;var F=y.s_v11,P=y.s_v12;F.x=u.position.x+(f.col1.x*B.x+f.col2.x*B.y),F.y=u.position.y+(f.col1.y*B.x+f.col2.y*B.y),P.x=u.position.x+(f.col1.x*w.x+f.col2.x*w.y),P.y=u.position.y+(f.col1.y*w.x+f.col2.y*w.y);var T=J.x*F.x+J.y*F.y,R=-G.x*F.x-G.y*F.y+a,k=G.x*P.x+G.y*P.y+a,E=y.s_clipPoints1,z=y.s_clipPoints2,N=0;if(N=y.ClipSegmentToLine(E,g,L,R),!(2>N||(N=y.ClipSegmentToLine(z,E,G,k),2>N))){t.m_localPlaneNormal.SetV(V),t.m_localPoint.SetV(I);for(var j=0,q=0;r.b2_maxManifoldPoints>q;++q){s=z[q];var O=J.x*s.v.x+J.y*s.v.y-T;if(a>=O){var U=t.m_points[j];f=x.R;var W=s.v.x-x.position.x,K=s.v.y-x.position.y;U.m_localPoint.x=W*f.col1.x+K*f.col1.y,U.m_localPoint.y=W*f.col2.x+K*f.col2.y,U.m_id.Set(s.id),U.m_id.features.flip=b,++j}}t.m_pointCount=j}}}},y.CollideCircles=function(t,i,e,o,n){t.m_pointCount=0;var s,r;s=e.R,r=i.m_p;var a=e.position.x+(s.col1.x*r.x+s.col2.x*r.y),m=e.position.y+(s.col1.y*r.x+s.col2.y*r.y);s=n.R,r=o.m_p;var l=n.position.x+(s.col1.x*r.x+s.col2.x*r.y),c=n.position.y+(s.col1.y*r.x+s.col2.y*r.y),h=l-a,_=c-m,p=h*h+_*_,y=i.m_radius+o.m_radius;p>y*y||(t.m_type=S.e_circles,t.m_localPoint.SetV(i.m_p),t.m_localPlaneNormal.SetZero(),t.m_pointCount=1,t.m_points[0].m_localPoint.SetV(o.m_p),t.m_points[0].m_id.key=0)},y.CollidePolygonAndCircle=function(t,i,e,o,n){t.m_pointCount=0;var s,r,a=0,m=0;r=n.R,s=o.m_p;var l=n.position.x+(r.col1.x*s.x+r.col2.x*s.y),c=n.position.y+(r.col1.y*s.x+r.col2.y*s.y);a=l-e.position.x,m=c-e.position.y,r=e.R;for(var h=a*r.col1.x+m*r.col1.y,_=a*r.col2.x+m*r.col2.y,p=0,y=-Number.MAX_VALUE,u=i.m_radius+o.m_radius,x=parseInt(i.m_vertexCount),f=i.m_vertices,d=i.m_normals,b=0;x>b;++b){s=f[b],a=h-s.x,m=_-s.y,s=d[b];var v=s.x*a+s.y*m;if(v>u)return;v>y&&(y=v,p=b)}var C=parseInt(p),g=parseInt(x>C+1?C+1:0),w=f[C],A=f[g];if(Number.MIN_VALUE>y)return t.m_pointCount=1,t.m_type=S.e_faceA,t.m_localPlaneNormal.SetV(d[p]),t.m_localPoint.x=.5*(w.x+A.x),t.m_localPoint.y=.5*(w.y+A.y),t.m_points[0].m_localPoint.SetV(o.m_p),t.m_points[0].m_id.key=0,void 0;var D=(h-w.x)*(A.x-w.x)+(_-w.y)*(A.y-w.y),B=(h-A.x)*(w.x-A.x)+(_-A.y)*(w.y-A.y);if(0>=D){if((h-w.x)*(h-w.x)+(_-w.y)*(_-w.y)>u*u)return;t.m_pointCount=1,t.m_type=S.e_faceA,t.m_localPlaneNormal.x=h-w.x,t.m_localPlaneNormal.y=_-w.y,t.m_localPlaneNormal.Normalize(),t.m_localPoint.SetV(w),t.m_points[0].m_localPoint.SetV(o.m_p),t.m_points[0].m_id.key=0}else if(0>=B){if((h-A.x)*(h-A.x)+(_-A.y)*(_-A.y)>u*u)return;t.m_pointCount=1,t.m_type=S.e_faceA,t.m_localPlaneNormal.x=h-A.x,t.m_localPlaneNormal.y=_-A.y,t.m_localPlaneNormal.Normalize(),t.m_localPoint.SetV(A),t.m_points[0].m_localPoint.SetV(o.m_p),t.m_points[0].m_id.key=0}else{var M=.5*(w.x+A.x),V=.5*(w.y+A.y);if(y=(h-M)*d[C].x+(_-V)*d[C].y,y>u)return;t.m_pointCount=1,t.m_type=S.e_faceA,t.m_localPlaneNormal.x=d[C].x,t.m_localPlaneNormal.y=d[C].y,t.m_localPlaneNormal.Normalize(),t.m_localPoint.Set(M,V),t.m_points[0].m_localPoint.SetV(o.m_p),t.m_points[0].m_id.key=0}},y.TestOverlap=function(t,i){var e=i.lowerBound,o=t.upperBound,n=e.x-o.x,s=e.y-o.y;e=t.lowerBound,o=i.upperBound;var r=e.x-o.x,a=e.y-o.y;return n>0||s>0?!1:r>0||a>0?!1:!0},o.postDefs.push(function(){o.Collision.b2Collision.s_incidentEdge=y.MakeClipPointVector(),o.Collision.b2Collision.s_clipPoints1=y.MakeClipPointVector(),o.Collision.b2Collision.s_clipPoints2=y.MakeClipPointVector(),o.Collision.b2Collision.s_edgeAO=new s(1),o.Collision.b2Collision.s_edgeBO=new s(1),o.Collision.b2Collision.s_localTangent=new c,o.Collision.b2Collision.s_localNormal=new c,o.Collision.b2Collision.s_planePoint=new c,o.Collision.b2Collision.s_normal=new c,o.Collision.b2Collision.s_tangent=new c,o.Collision.b2Collision.s_tangent2=new c,o.Collision.b2Collision.s_v11=new c,o.Collision.b2Collision.s_v12=new c,o.Collision.b2Collision.b2CollidePolyTempVec=new c,o.Collision.b2Collision.b2_nullFeature=255}),u.b2ContactID=function(){this.features=new E},u.prototype.b2ContactID=function(){this.features._m_id=this},u.prototype.Set=function(t){this.key=t._key},u.prototype.Copy=function(){var t=new u;return t.key=this.key,t},Object.defineProperty(u.prototype,"key",{enumerable:!1,configurable:!0,get:function(){return this._key}}),Object.defineProperty(u.prototype,"key",{enumerable:!1,configurable:!0,set:function(t){void 0===t&&(t=0),this._key=t,this.features._referenceEdge=255&this._key,this.features._incidentEdge=255&(65280&this._key)>>8,this.features._incidentVertex=255&(16711680&this._key)>>16,this.features._flip=255&(4278190080&this._key)>>24}}),x.b2ContactPoint=function(){this.position=new c,this.velocity=new c,this.normal=new c,this.id=new u},f.b2Distance=function(){},f.Distance=function(t,i,e){++f.b2_gjkCalls;var o=e.proxyA,n=e.proxyB,s=e.transformA,m=e.transformB,l=f.s_simplex;l.ReadCache(i,o,s,n,m);for(var h,_=l.m_vertices,p=20,y=f.s_saveA,u=f.s_saveB,x=0,d=l.GetClosestPoint(),b=d.LengthSquared(),v=b,C=0,g=0;p>g;){for(x=l.m_count,C=0;x>C;C++)y[C]=_[C].indexA,u[C]=_[C].indexB;switch(l.m_count){case 1:break;case 2:l.Solve2();break;case 3:l.Solve3();break;default:r.b2Assert(!1)}if(3==l.m_count)break;h=l.GetClosestPoint(),v=h.LengthSquared(),b=v;var w=l.GetSearchDirection();if(w.LengthSquared()<Number.MIN_VALUE*Number.MIN_VALUE)break;var A=_[l.m_count];A.indexA=o.GetSupport(a.MulTMV(s.R,w.GetNegative())),A.wA=a.MulX(s,o.GetVertex(A.indexA)),A.indexB=n.GetSupport(a.MulTMV(m.R,w)),A.wB=a.MulX(m,n.GetVertex(A.indexB)),A.w=a.SubtractVV(A.wB,A.wA),++g,++f.b2_gjkIters;var S=!1;for(C=0;x>C;C++)if(A.indexA==y[C]&&A.indexB==u[C]){S=!0;break}if(S)break;++l.m_count}if(f.b2_gjkMaxIters=a.Max(f.b2_gjkMaxIters,g),l.GetWitnessPoints(t.pointA,t.pointB),t.distance=a.SubtractVV(t.pointA,t.pointB).Length(),t.iterations=g,l.WriteCache(i),e.useRadii){var D=o.m_radius,B=n.m_radius;if(t.distance>D+B&&t.distance>Number.MIN_VALUE){t.distance-=D+B;var M=a.SubtractVV(t.pointB,t.pointA);M.Normalize(),t.pointA.x+=D*M.x,t.pointA.y+=D*M.y,t.pointB.x-=B*M.x,t.pointB.y-=B*M.y}else h=new c,h.x=.5*(t.pointA.x+t.pointB.x),h.y=.5*(t.pointA.y+t.pointB.y),t.pointA.x=t.pointB.x=h.x,t.pointA.y=t.pointB.y=h.y,t.distance=0}},o.postDefs.push(function(){o.Collision.b2Distance.s_simplex=new L,o.Collision.b2Distance.s_saveA=new s(3),o.Collision.b2Distance.s_saveB=new s(3)}),d.b2DistanceInput=function(){},b.b2DistanceOutput=function(){this.pointA=new c,this.pointB=new c},v.b2DistanceProxy=function(){},v.prototype.Set=function(o){switch(o.GetType()){case e.e_circleShape:var s=o instanceof t?o:null;this.m_vertices=new n(1,!0),this.m_vertices[0]=s.m_p,this.m_count=1,this.m_radius=s.m_radius;break;case e.e_polygonShape:var a=o instanceof i?o:null;this.m_vertices=a.m_vertices,this.m_count=a.m_vertexCount,this.m_radius=a.m_radius;break;default:r.b2Assert(!1)}},v.prototype.GetSupport=function(t){for(var i=0,e=this.m_vertices[0].x*t.x+this.m_vertices[0].y*t.y,o=1;this.m_count>o;++o){var n=this.m_vertices[o].x*t.x+this.m_vertices[o].y*t.y;n>e&&(i=o,e=n)}return i},v.prototype.GetSupportVertex=function(t){for(var i=0,e=this.m_vertices[0].x*t.x+this.m_vertices[0].y*t.y,o=1;this.m_count>o;++o){var n=this.m_vertices[o].x*t.x+this.m_vertices[o].y*t.y;n>e&&(i=o,e=n)}return this.m_vertices[i]},v.prototype.GetVertexCount=function(){return this.m_count},v.prototype.GetVertex=function(t){return void 0===t&&(t=0),r.b2Assert(t>=0&&this.m_count>t),this.m_vertices[t]},C.b2DynamicTree=function(){},C.prototype.b2DynamicTree=function(){this.m_root=null,this.m_freeList=null,this.m_path=0,this.m_insertionCount=0},C.prototype.CreateProxy=function(t,i){var e=this.AllocateNode(),o=r.b2_aabbExtension,n=r.b2_aabbExtension;return e.aabb.lowerBound.x=t.lowerBound.x-o,e.aabb.lowerBound.y=t.lowerBound.y-n,e.aabb.upperBound.x=t.upperBound.x+o,e.aabb.upperBound.y=t.upperBound.y+n,e.userData=i,this.InsertLeaf(e),e},C.prototype.DestroyProxy=function(t){this.RemoveLeaf(t),this.FreeNode(t)},C.prototype.MoveProxy=function(t,i,e){if(r.b2Assert(t.IsLeaf()),t.aabb.Contains(i))return!1;this.RemoveLeaf(t);var o=r.b2_aabbExtension+r.b2_aabbMultiplier*(e.x>0?e.x:-e.x),n=r.b2_aabbExtension+r.b2_aabbMultiplier*(e.y>0?e.y:-e.y);return t.aabb.lowerBound.x=i.lowerBound.x-o,t.aabb.lowerBound.y=i.lowerBound.y-n,t.aabb.upperBound.x=i.upperBound.x+o,t.aabb.upperBound.y=i.upperBound.y+n,this.InsertLeaf(t),!0},C.prototype.Rebalance=function(t){if(void 0===t&&(t=0),null!=this.m_root)for(var i=0;t>i;i++){for(var e=this.m_root,o=0;0==e.IsLeaf();)e=1&this.m_path>>o?e.child2:e.child1,o=31&o+1;++this.m_path,this.RemoveLeaf(e),this.InsertLeaf(e)}},C.prototype.GetFatAABB=function(t){return t.aabb},C.prototype.GetUserData=function(t){return t.userData},C.prototype.Query=function(t,i){if(null!=this.m_root){var e=new n,o=0;for(e[o++]=this.m_root;o>0;){var s=e[--o];if(s.aabb.TestOverlap(i))if(s.IsLeaf()){var r=t(s);if(!r)return}else e[o++]=s.child1,e[o++]=s.child2}}},C.prototype.RayCast=function(t,i){if(null!=this.m_root){var e=i.p1,o=i.p2,s=a.SubtractVV(e,o);s.Normalize();var r=a.CrossFV(1,s),m=a.AbsV(r),l=i.maxFraction,c=new h,_=0,p=0;_=e.x+l*(o.x-e.x),p=e.y+l*(o.y-e.y),c.lowerBound.x=Math.min(e.x,_),c.lowerBound.y=Math.min(e.y,p),c.upperBound.x=Math.max(e.x,_),c.upperBound.y=Math.max(e.y,p);var y=new n,u=0;for(y[u++]=this.m_root;u>0;){var x=y[--u];if(0!=x.aabb.TestOverlap(c)){var f=x.aabb.GetCenter(),d=x.aabb.GetExtents(),b=Math.abs(r.x*(e.x-f.x)+r.y*(e.y-f.y))-m.x*d.x-m.y*d.y;if(!(b>0))if(x.IsLeaf()){var v=new M;if(v.p1=i.p1,v.p2=i.p2,v.maxFraction=i.maxFraction,l=t(v,x),0==l)return;l>0&&(_=e.x+l*(o.x-e.x),p=e.y+l*(o.y-e.y),c.lowerBound.x=Math.min(e.x,_),c.lowerBound.y=Math.min(e.y,p),c.upperBound.x=Math.max(e.x,_),c.upperBound.y=Math.max(e.y,p))}else y[u++]=x.child1,y[u++]=x.child2}}}},C.prototype.AllocateNode=function(){if(this.m_freeList){var t=this.m_freeList;return this.m_freeList=t.parent,t.parent=null,t.child1=null,t.child2=null,t}return new w},C.prototype.FreeNode=function(t){t.parent=this.m_freeList,this.m_freeList=t},C.prototype.InsertLeaf=function(t){if(++this.m_insertionCount,null==this.m_root)return this.m_root=t,this.m_root.parent=null,void 0;var i=t.aabb.GetCenter(),e=this.m_root;if(0==e.IsLeaf())do{var o=e.child1,n=e.child2,s=Math.abs((o.aabb.lowerBound.x+o.aabb.upperBound.x)/2-i.x)+Math.abs((o.aabb.lowerBound.y+o.aabb.upperBound.y)/2-i.y),r=Math.abs((n.aabb.lowerBound.x+n.aabb.upperBound.x)/2-i.x)+Math.abs((n.aabb.lowerBound.y+n.aabb.upperBound.y)/2-i.y);e=r>s?o:n}while(0==e.IsLeaf());var a=e.parent,m=this.AllocateNode();if(m.parent=a,m.userData=null,m.aabb.Combine(t.aabb,e.aabb),a){e.parent.child1==e?a.child1=m:a.child2=m,m.child1=e,m.child2=t,e.parent=m,t.parent=m;do{if(a.aabb.Contains(m.aabb))break;a.aabb.Combine(a.child1.aabb,a.child2.aabb),m=a,a=a.parent}while(a)}else m.child1=e,m.child2=t,e.parent=m,t.parent=m,this.m_root=m},C.prototype.RemoveLeaf=function(t){if(t==this.m_root)return this.m_root=null,void 0;
var i,e=t.parent,o=e.parent;if(i=e.child1==t?e.child2:e.child1,o)for(o.child1==e?o.child1=i:o.child2=i,i.parent=o,this.FreeNode(e);o;){var n=o.aabb;if(o.aabb=h.Combine(o.child1.aabb,o.child2.aabb),n.Contains(o.aabb))break;o=o.parent}else this.m_root=i,i.parent=null,this.FreeNode(e)},g.b2DynamicTreeBroadPhase=function(){this.m_tree=new C,this.m_moveBuffer=new n,this.m_pairBuffer=new n,this.m_pairCount=0},g.prototype.CreateProxy=function(t,i){var e=this.m_tree.CreateProxy(t,i);return++this.m_proxyCount,this.BufferMove(e),e},g.prototype.DestroyProxy=function(t){this.UnBufferMove(t),--this.m_proxyCount,this.m_tree.DestroyProxy(t)},g.prototype.MoveProxy=function(t,i,e){var o=this.m_tree.MoveProxy(t,i,e);o&&this.BufferMove(t)},g.prototype.TestOverlap=function(t,i){var e=this.m_tree.GetFatAABB(t),o=this.m_tree.GetFatAABB(i);return e.TestOverlap(o)},g.prototype.GetUserData=function(t){return this.m_tree.GetUserData(t)},g.prototype.GetFatAABB=function(t){return this.m_tree.GetFatAABB(t)},g.prototype.GetProxyCount=function(){return this.m_proxyCount},g.prototype.UpdatePairs=function(t){function i(t){if(t==o)return!0;e.m_pairCount==e.m_pairBuffer.length&&(e.m_pairBuffer[e.m_pairCount]=new A);var i=e.m_pairBuffer[e.m_pairCount];return i.proxyA=o>t?t:o,i.proxyB=t>=o?t:o,++e.m_pairCount,!0}var e=this;e.m_pairCount=0;var o,n=0;for(n=0;e.m_moveBuffer.length>n;++n){o=e.m_moveBuffer[n];var s=e.m_tree.GetFatAABB(o);e.m_tree.Query(i,s)}e.m_moveBuffer.length=0;for(var n=0;e.m_pairCount>n;){var r=e.m_pairBuffer[n],a=e.m_tree.GetUserData(r.proxyA),m=e.m_tree.GetUserData(r.proxyB);for(t(a,m),++n;e.m_pairCount>n;){var l=e.m_pairBuffer[n];if(l.proxyA!=r.proxyA||l.proxyB!=r.proxyB)break;++n}}},g.prototype.Query=function(t,i){this.m_tree.Query(t,i)},g.prototype.RayCast=function(t,i){this.m_tree.RayCast(t,i)},g.prototype.Validate=function(){},g.prototype.Rebalance=function(t){void 0===t&&(t=0),this.m_tree.Rebalance(t)},g.prototype.BufferMove=function(t){this.m_moveBuffer[this.m_moveBuffer.length]=t},g.prototype.UnBufferMove=function(t){var i=parseInt(this.m_moveBuffer.indexOf(t));this.m_moveBuffer.splice(i,1)},g.prototype.ComparePairs=function(){return 0},g.__implements={},g.__implements[z]=!0,w.b2DynamicTreeNode=function(){this.aabb=new h},w.prototype.IsLeaf=function(){return null==this.child1},A.b2DynamicTreePair=function(){},S.b2Manifold=function(){this.m_pointCount=0},S.prototype.b2Manifold=function(){this.m_points=new n(r.b2_maxManifoldPoints);for(var t=0;r.b2_maxManifoldPoints>t;t++)this.m_points[t]=new D;this.m_localPlaneNormal=new c,this.m_localPoint=new c},S.prototype.Reset=function(){for(var t=0;r.b2_maxManifoldPoints>t;t++)(this.m_points[t]instanceof D?this.m_points[t]:null).Reset();this.m_localPlaneNormal.SetZero(),this.m_localPoint.SetZero(),this.m_type=0,this.m_pointCount=0},S.prototype.Set=function(t){this.m_pointCount=t.m_pointCount;for(var i=0;r.b2_maxManifoldPoints>i;i++)(this.m_points[i]instanceof D?this.m_points[i]:null).Set(t.m_points[i]);this.m_localPlaneNormal.SetV(t.m_localPlaneNormal),this.m_localPoint.SetV(t.m_localPoint),this.m_type=t.m_type},S.prototype.Copy=function(){var t=new S;return t.Set(this),t},o.postDefs.push(function(){o.Collision.b2Manifold.e_circles=1,o.Collision.b2Manifold.e_faceA=2,o.Collision.b2Manifold.e_faceB=4}),D.b2ManifoldPoint=function(){this.m_localPoint=new c,this.m_id=new u},D.prototype.b2ManifoldPoint=function(){this.Reset()},D.prototype.Reset=function(){this.m_localPoint.SetZero(),this.m_normalImpulse=0,this.m_tangentImpulse=0,this.m_id.key=0},D.prototype.Set=function(t){this.m_localPoint.SetV(t.m_localPoint),this.m_normalImpulse=t.m_normalImpulse,this.m_tangentImpulse=t.m_tangentImpulse,this.m_id.Set(t.m_id)},B.b2Point=function(){this.p=new c},B.prototype.Support=function(t,i,e){return void 0===i&&(i=0),void 0===e&&(e=0),this.p},B.prototype.GetFirstVertex=function(){return this.p},M.b2RayCastInput=function(){this.p1=new c,this.p2=new c},M.prototype.b2RayCastInput=function(t,i,e){void 0===t&&(t=null),void 0===i&&(i=null),void 0===e&&(e=1),t&&this.p1.SetV(t),i&&this.p2.SetV(i),this.maxFraction=e},V.b2RayCastOutput=function(){this.normal=new c},I.b2Segment=function(){this.p1=new c,this.p2=new c},I.prototype.TestSegment=function(t,i,e,o){void 0===o&&(o=0);var n=e.p1,s=e.p2.x-n.x,r=e.p2.y-n.y,a=this.p2.x-this.p1.x,m=this.p2.y-this.p1.y,l=m,c=-a,h=100*Number.MIN_VALUE,_=-(s*l+r*c);if(_>h){var p=n.x-this.p1.x,y=n.y-this.p1.y,u=p*l+y*c;if(u>=0&&o*_>=u){var x=-s*y+r*p;if(x>=-h*_&&_*(1+h)>=x){u/=_;var f=Math.sqrt(l*l+c*c);return l/=f,c/=f,t[0]=u,i.Set(l,c),!0}}}return!1},I.prototype.Extend=function(t){this.ExtendForward(t),this.ExtendBackward(t)},I.prototype.ExtendForward=function(t){var i=this.p2.x-this.p1.x,e=this.p2.y-this.p1.y,o=Math.min(i>0?(t.upperBound.x-this.p1.x)/i:0>i?(t.lowerBound.x-this.p1.x)/i:Number.POSITIVE_INFINITY,e>0?(t.upperBound.y-this.p1.y)/e:0>e?(t.lowerBound.y-this.p1.y)/e:Number.POSITIVE_INFINITY);this.p2.x=this.p1.x+i*o,this.p2.y=this.p1.y+e*o},I.prototype.ExtendBackward=function(t){var i=-this.p2.x+this.p1.x,e=-this.p2.y+this.p1.y,o=Math.min(i>0?(t.upperBound.x-this.p2.x)/i:0>i?(t.lowerBound.x-this.p2.x)/i:Number.POSITIVE_INFINITY,e>0?(t.upperBound.y-this.p2.y)/e:0>e?(t.lowerBound.y-this.p2.y)/e:Number.POSITIVE_INFINITY);this.p1.x=this.p2.x+i*o,this.p1.y=this.p2.y+e*o},G.b2SeparationFunction=function(){this.m_localPoint=new c,this.m_axis=new c},G.prototype.Initialize=function(t,i,e,o,n){this.m_proxyA=i,this.m_proxyB=o;var s=parseInt(t.count);r.b2Assert(s>0&&3>s);var m,l,h,_,p,y,u,x,f=0,d=0,b=0,v=0,C=0,g=0,w=0,A=0;if(1==s)this.m_type=G.e_points,m=this.m_proxyA.GetVertex(t.indexA[0]),_=this.m_proxyB.GetVertex(t.indexB[0]),x=m,u=e.R,f=e.position.x+(u.col1.x*x.x+u.col2.x*x.y),d=e.position.y+(u.col1.y*x.x+u.col2.y*x.y),x=_,u=n.R,b=n.position.x+(u.col1.x*x.x+u.col2.x*x.y),v=n.position.y+(u.col1.y*x.x+u.col2.y*x.y),this.m_axis.x=b-f,this.m_axis.y=v-d,this.m_axis.Normalize();else if(t.indexB[0]==t.indexB[1])this.m_type=G.e_faceA,l=this.m_proxyA.GetVertex(t.indexA[0]),h=this.m_proxyA.GetVertex(t.indexA[1]),_=this.m_proxyB.GetVertex(t.indexB[0]),this.m_localPoint.x=.5*(l.x+h.x),this.m_localPoint.y=.5*(l.y+h.y),this.m_axis=a.CrossVF(a.SubtractVV(h,l),1),this.m_axis.Normalize(),x=this.m_axis,u=e.R,C=u.col1.x*x.x+u.col2.x*x.y,g=u.col1.y*x.x+u.col2.y*x.y,x=this.m_localPoint,u=e.R,f=e.position.x+(u.col1.x*x.x+u.col2.x*x.y),d=e.position.y+(u.col1.y*x.x+u.col2.y*x.y),x=_,u=n.R,b=n.position.x+(u.col1.x*x.x+u.col2.x*x.y),v=n.position.y+(u.col1.y*x.x+u.col2.y*x.y),w=(b-f)*C+(v-d)*g,0>w&&this.m_axis.NegativeSelf();else if(t.indexA[0]==t.indexA[0])this.m_type=G.e_faceB,p=this.m_proxyB.GetVertex(t.indexB[0]),y=this.m_proxyB.GetVertex(t.indexB[1]),m=this.m_proxyA.GetVertex(t.indexA[0]),this.m_localPoint.x=.5*(p.x+y.x),this.m_localPoint.y=.5*(p.y+y.y),this.m_axis=a.CrossVF(a.SubtractVV(y,p),1),this.m_axis.Normalize(),x=this.m_axis,u=n.R,C=u.col1.x*x.x+u.col2.x*x.y,g=u.col1.y*x.x+u.col2.y*x.y,x=this.m_localPoint,u=n.R,b=n.position.x+(u.col1.x*x.x+u.col2.x*x.y),v=n.position.y+(u.col1.y*x.x+u.col2.y*x.y),x=m,u=e.R,f=e.position.x+(u.col1.x*x.x+u.col2.x*x.y),d=e.position.y+(u.col1.y*x.x+u.col2.y*x.y),w=(f-b)*C+(d-v)*g,0>w&&this.m_axis.NegativeSelf();else{l=this.m_proxyA.GetVertex(t.indexA[0]),h=this.m_proxyA.GetVertex(t.indexA[1]),p=this.m_proxyB.GetVertex(t.indexB[0]),y=this.m_proxyB.GetVertex(t.indexB[1]),a.MulX(e,m);var S=a.MulMV(e.R,a.SubtractVV(h,l));a.MulX(n,_);var D=a.MulMV(n.R,a.SubtractVV(y,p)),B=S.x*S.x+S.y*S.y,M=D.x*D.x+D.y*D.y,V=a.SubtractVV(D,S),I=S.x*V.x+S.y*V.y,L=D.x*V.x+D.y*V.y,J=S.x*D.x+S.y*D.y,F=B*M-J*J;w=0,0!=F&&(w=a.Clamp((J*L-I*M)/F,0,1));var P=(J*w+L)/M;0>P&&(P=0,w=a.Clamp((J-I)/B,0,1)),m=new c,m.x=l.x+w*(h.x-l.x),m.y=l.y+w*(h.y-l.y),_=new c,_.x=p.x+w*(y.x-p.x),_.y=p.y+w*(y.y-p.y),0==w||1==w?(this.m_type=G.e_faceB,this.m_axis=a.CrossVF(a.SubtractVV(y,p),1),this.m_axis.Normalize(),this.m_localPoint=_,x=this.m_axis,u=n.R,C=u.col1.x*x.x+u.col2.x*x.y,g=u.col1.y*x.x+u.col2.y*x.y,x=this.m_localPoint,u=n.R,b=n.position.x+(u.col1.x*x.x+u.col2.x*x.y),v=n.position.y+(u.col1.y*x.x+u.col2.y*x.y),x=m,u=e.R,f=e.position.x+(u.col1.x*x.x+u.col2.x*x.y),d=e.position.y+(u.col1.y*x.x+u.col2.y*x.y),A=(f-b)*C+(d-v)*g,0>w&&this.m_axis.NegativeSelf()):(this.m_type=G.e_faceA,this.m_axis=a.CrossVF(a.SubtractVV(h,l),1),this.m_localPoint=m,x=this.m_axis,u=e.R,C=u.col1.x*x.x+u.col2.x*x.y,g=u.col1.y*x.x+u.col2.y*x.y,x=this.m_localPoint,u=e.R,f=e.position.x+(u.col1.x*x.x+u.col2.x*x.y),d=e.position.y+(u.col1.y*x.x+u.col2.y*x.y),x=_,u=n.R,b=n.position.x+(u.col1.x*x.x+u.col2.x*x.y),v=n.position.y+(u.col1.y*x.x+u.col2.y*x.y),A=(b-f)*C+(v-d)*g,0>w&&this.m_axis.NegativeSelf())}},G.prototype.Evaluate=function(t,i){var e,o,n,s,m,l,c,h=0;switch(this.m_type){case G.e_points:return e=a.MulTMV(t.R,this.m_axis),o=a.MulTMV(i.R,this.m_axis.GetNegative()),n=this.m_proxyA.GetSupportVertex(e),s=this.m_proxyB.GetSupportVertex(o),m=a.MulX(t,n),l=a.MulX(i,s),h=(l.x-m.x)*this.m_axis.x+(l.y-m.y)*this.m_axis.y;case G.e_faceA:return c=a.MulMV(t.R,this.m_axis),m=a.MulX(t,this.m_localPoint),o=a.MulTMV(i.R,c.GetNegative()),s=this.m_proxyB.GetSupportVertex(o),l=a.MulX(i,s),h=(l.x-m.x)*c.x+(l.y-m.y)*c.y;case G.e_faceB:return c=a.MulMV(i.R,this.m_axis),l=a.MulX(i,this.m_localPoint),e=a.MulTMV(t.R,c.GetNegative()),n=this.m_proxyA.GetSupportVertex(e),m=a.MulX(t,n),h=(m.x-l.x)*c.x+(m.y-l.y)*c.y;default:return r.b2Assert(!1),0}},o.postDefs.push(function(){o.Collision.b2SeparationFunction.e_points=1,o.Collision.b2SeparationFunction.e_faceA=2,o.Collision.b2SeparationFunction.e_faceB=4}),L.b2Simplex=function(){this.m_v1=new F,this.m_v2=new F,this.m_v3=new F,this.m_vertices=new n(3)},L.prototype.b2Simplex=function(){this.m_vertices[0]=this.m_v1,this.m_vertices[1]=this.m_v2,this.m_vertices[2]=this.m_v3},L.prototype.ReadCache=function(t,i,e,o,n){r.b2Assert(t.count>=0&&3>=t.count);var s,m;this.m_count=t.count;for(var l=this.m_vertices,c=0;this.m_count>c;c++){var h=l[c];h.indexA=t.indexA[c],h.indexB=t.indexB[c],s=i.GetVertex(h.indexA),m=o.GetVertex(h.indexB),h.wA=a.MulX(e,s),h.wB=a.MulX(n,m),h.w=a.SubtractVV(h.wB,h.wA),h.a=0}if(this.m_count>1){var _=t.metric,p=this.GetMetric();(.5*_>p||p>2*_||Number.MIN_VALUE>p)&&(this.m_count=0)}0==this.m_count&&(h=l[0],h.indexA=0,h.indexB=0,s=i.GetVertex(0),m=o.GetVertex(0),h.wA=a.MulX(e,s),h.wB=a.MulX(n,m),h.w=a.SubtractVV(h.wB,h.wA),this.m_count=1)},L.prototype.WriteCache=function(t){t.metric=this.GetMetric(),t.count=o.parseUInt(this.m_count);for(var i=this.m_vertices,e=0;this.m_count>e;e++)t.indexA[e]=o.parseUInt(i[e].indexA),t.indexB[e]=o.parseUInt(i[e].indexB)},L.prototype.GetSearchDirection=function(){switch(this.m_count){case 1:return this.m_v1.w.GetNegative();case 2:var t=a.SubtractVV(this.m_v2.w,this.m_v1.w),i=a.CrossVV(t,this.m_v1.w.GetNegative());return i>0?a.CrossFV(1,t):a.CrossVF(t,1);default:return r.b2Assert(!1),new c}},L.prototype.GetClosestPoint=function(){switch(this.m_count){case 0:return r.b2Assert(!1),new c;case 1:return this.m_v1.w;case 2:return new c(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:return r.b2Assert(!1),new c}},L.prototype.GetWitnessPoints=function(t,i){switch(this.m_count){case 0:r.b2Assert(!1);break;case 1:t.SetV(this.m_v1.wA),i.SetV(this.m_v1.wB);break;case 2:t.x=this.m_v1.a*this.m_v1.wA.x+this.m_v2.a*this.m_v2.wA.x,t.y=this.m_v1.a*this.m_v1.wA.y+this.m_v2.a*this.m_v2.wA.y,i.x=this.m_v1.a*this.m_v1.wB.x+this.m_v2.a*this.m_v2.wB.x,i.y=this.m_v1.a*this.m_v1.wB.y+this.m_v2.a*this.m_v2.wB.y;break;case 3:i.x=t.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,i.y=t.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:r.b2Assert(!1)}},L.prototype.GetMetric=function(){switch(this.m_count){case 0:return r.b2Assert(!1),0;case 1:return 0;case 2:return a.SubtractVV(this.m_v1.w,this.m_v2.w).Length();case 3:return a.CrossVV(a.SubtractVV(this.m_v2.w,this.m_v1.w),a.SubtractVV(this.m_v3.w,this.m_v1.w));default:return r.b2Assert(!1),0}},L.prototype.Solve2=function(){var t=this.m_v1.w,i=this.m_v2.w,e=a.SubtractVV(i,t),o=-(t.x*e.x+t.y*e.y);if(0>=o)return this.m_v1.a=1,this.m_count=1,void 0;var n=i.x*e.x+i.y*e.y;if(0>=n)return this.m_v2.a=1,this.m_count=1,this.m_v1.Set(this.m_v2),void 0;var s=1/(n+o);this.m_v1.a=n*s,this.m_v2.a=o*s,this.m_count=2},L.prototype.Solve3=function(){var t=this.m_v1.w,i=this.m_v2.w,e=this.m_v3.w,o=a.SubtractVV(i,t),n=a.Dot(t,o),s=a.Dot(i,o),r=s,m=-n,l=a.SubtractVV(e,t),c=a.Dot(t,l),h=a.Dot(e,l),_=h,p=-c,y=a.SubtractVV(e,i),u=a.Dot(i,y),x=a.Dot(e,y),f=x,d=-u,b=a.CrossVV(o,l),v=b*a.CrossVV(i,e),C=b*a.CrossVV(e,t),g=b*a.CrossVV(t,i);if(0>=m&&0>=p)return this.m_v1.a=1,this.m_count=1,void 0;if(r>0&&m>0&&0>=g){var w=1/(r+m);return this.m_v1.a=r*w,this.m_v2.a=m*w,this.m_count=2,void 0}if(_>0&&p>0&&0>=C){var A=1/(_+p);return this.m_v1.a=_*A,this.m_v3.a=p*A,this.m_count=2,this.m_v2.Set(this.m_v3),void 0}if(0>=r&&0>=d)return this.m_v2.a=1,this.m_count=1,this.m_v1.Set(this.m_v2),void 0;if(0>=_&&0>=f)return this.m_v3.a=1,this.m_count=1,this.m_v1.Set(this.m_v3),void 0;if(f>0&&d>0&&0>=v){var S=1/(f+d);return this.m_v2.a=f*S,this.m_v3.a=d*S,this.m_count=2,this.m_v1.Set(this.m_v3),void 0}var D=1/(v+C+g);this.m_v1.a=v*D,this.m_v2.a=C*D,this.m_v3.a=g*D,this.m_count=3},J.b2SimplexCache=function(){this.indexA=new s(3),this.indexB=new s(3)},F.b2SimplexVertex=function(){},F.prototype.Set=function(t){this.wA.SetV(t.wA),this.wB.SetV(t.wB),this.w.SetV(t.w),this.a=t.a,this.indexA=t.indexA,this.indexB=t.indexB},P.b2TimeOfImpact=function(){},P.TimeOfImpact=function(t){++P.b2_toiCalls;var i=t.proxyA,e=t.proxyB,o=t.sweepA,n=t.sweepB;r.b2Assert(o.t0==n.t0),r.b2Assert(1-o.t0>Number.MIN_VALUE);var s=i.m_radius+e.m_radius,m=t.tolerance,l=0,c=1e3,h=0,_=0;for(P.s_cache.count=0,P.s_distanceInput.useRadii=!1;;){if(o.GetTransform(P.s_xfA,l),n.GetTransform(P.s_xfB,l),P.s_distanceInput.proxyA=i,P.s_distanceInput.proxyB=e,P.s_distanceInput.transformA=P.s_xfA,P.s_distanceInput.transformB=P.s_xfB,f.Distance(P.s_distanceOutput,P.s_cache,P.s_distanceInput),0>=P.s_distanceOutput.distance){l=1;break}P.s_fcn.Initialize(P.s_cache,i,P.s_xfA,e,P.s_xfB);var p=P.s_fcn.Evaluate(P.s_xfA,P.s_xfB);if(0>=p){l=1;break}if(0==h&&(_=p>s?a.Max(s-m,.75*s):a.Max(p-m,.02*s)),.5*m>p-_){if(0==h){l=1;break}break}var y=l,u=l,x=1,d=p;o.GetTransform(P.s_xfA,x),n.GetTransform(P.s_xfB,x);var b=P.s_fcn.Evaluate(P.s_xfA,P.s_xfB);if(b>=_){l=1;break}for(var v=0;;){var C=0;C=1&v?u+(_-d)*(x-u)/(b-d):.5*(u+x),o.GetTransform(P.s_xfA,C),n.GetTransform(P.s_xfB,C);var g=P.s_fcn.Evaluate(P.s_xfA,P.s_xfB);if(.025*m>a.Abs(g-_)){y=C;break}if(g>_?(u=C,d=g):(x=C,b=g),++v,++P.b2_toiRootIters,50==v)break}if(P.b2_toiMaxRootIters=a.Max(P.b2_toiMaxRootIters,v),(1+100*Number.MIN_VALUE)*l>y)break;if(l=y,h++,++P.b2_toiIters,h==c)break}return P.b2_toiMaxIters=a.Max(P.b2_toiMaxIters,h),l},o.postDefs.push(function(){o.Collision.b2TimeOfImpact.b2_toiCalls=0,o.Collision.b2TimeOfImpact.b2_toiIters=0,o.Collision.b2TimeOfImpact.b2_toiMaxIters=0,o.Collision.b2TimeOfImpact.b2_toiRootIters=0,o.Collision.b2TimeOfImpact.b2_toiMaxRootIters=0,o.Collision.b2TimeOfImpact.s_cache=new J,o.Collision.b2TimeOfImpact.s_distanceInput=new d,o.Collision.b2TimeOfImpact.s_xfA=new l,o.Collision.b2TimeOfImpact.s_xfB=new l,o.Collision.b2TimeOfImpact.s_fcn=new G,o.Collision.b2TimeOfImpact.s_distanceOutput=new b}),T.b2TOIInput=function(){this.proxyA=new v,this.proxyB=new v,this.sweepA=new m,this.sweepB=new m},R.b2WorldManifold=function(){this.m_normal=new c},R.prototype.b2WorldManifold=function(){this.m_points=new n(r.b2_maxManifoldPoints);for(var t=0;r.b2_maxManifoldPoints>t;t++)this.m_points[t]=new c},R.prototype.Initialize=function(t,i,e,o,n){if(void 0===e&&(e=0),void 0===n&&(n=0),0!=t.m_pointCount){var s,r,a=0,m=0,l=0,c=0,h=0,_=0,p=0;switch(t.m_type){case S.e_circles:r=i.R,s=t.m_localPoint;var y=i.position.x+r.col1.x*s.x+r.col2.x*s.y,u=i.position.y+r.col1.y*s.x+r.col2.y*s.y;r=o.R,s=t.m_points[0].m_localPoint;var x=o.position.x+r.col1.x*s.x+r.col2.x*s.y,f=o.position.y+r.col1.y*s.x+r.col2.y*s.y,d=x-y,b=f-u,v=d*d+b*b;if(v>Number.MIN_VALUE*Number.MIN_VALUE){var C=Math.sqrt(v);this.m_normal.x=d/C,this.m_normal.y=b/C}else this.m_normal.x=1,this.m_normal.y=0;var g=y+e*this.m_normal.x,w=u+e*this.m_normal.y,A=x-n*this.m_normal.x,D=f-n*this.m_normal.y;this.m_points[0].x=.5*(g+A),this.m_points[0].y=.5*(w+D);break;case S.e_faceA:for(r=i.R,s=t.m_localPlaneNormal,m=r.col1.x*s.x+r.col2.x*s.y,l=r.col1.y*s.x+r.col2.y*s.y,r=i.R,s=t.m_localPoint,c=i.position.x+r.col1.x*s.x+r.col2.x*s.y,h=i.position.y+r.col1.y*s.x+r.col2.y*s.y,this.m_normal.x=m,this.m_normal.y=l,a=0;t.m_pointCount>a;a++)r=o.R,s=t.m_points[a].m_localPoint,_=o.position.x+r.col1.x*s.x+r.col2.x*s.y,p=o.position.y+r.col1.y*s.x+r.col2.y*s.y,this.m_points[a].x=_+.5*(e-(_-c)*m-(p-h)*l-n)*m,this.m_points[a].y=p+.5*(e-(_-c)*m-(p-h)*l-n)*l;break;case S.e_faceB:for(r=o.R,s=t.m_localPlaneNormal,m=r.col1.x*s.x+r.col2.x*s.y,l=r.col1.y*s.x+r.col2.y*s.y,r=o.R,s=t.m_localPoint,c=o.position.x+r.col1.x*s.x+r.col2.x*s.y,h=o.position.y+r.col1.y*s.x+r.col2.y*s.y,this.m_normal.x=-m,this.m_normal.y=-l,a=0;t.m_pointCount>a;a++)r=i.R,s=t.m_points[a].m_localPoint,_=i.position.x+r.col1.x*s.x+r.col2.x*s.y,p=i.position.y+r.col1.y*s.x+r.col2.y*s.y,this.m_points[a].x=_+.5*(n-(_-c)*m-(p-h)*l-e)*m,this.m_points[a].y=p+.5*(n-(_-c)*m-(p-h)*l-e)*l}}},k.ClipVertex=function(){this.v=new c,this.id=new u},k.prototype.Set=function(t){this.v.SetV(t.v),this.id.Set(t.id)},E.Features=function(){},Object.defineProperty(E.prototype,"referenceEdge",{enumerable:!1,configurable:!0,get:function(){return this._referenceEdge}}),Object.defineProperty(E.prototype,"referenceEdge",{enumerable:!1,configurable:!0,set:function(t){void 0===t&&(t=0),this._referenceEdge=t,this._m_id._key=4294967040&this._m_id._key|255&this._referenceEdge}}),Object.defineProperty(E.prototype,"incidentEdge",{enumerable:!1,configurable:!0,get:function(){return this._incidentEdge}}),Object.defineProperty(E.prototype,"incidentEdge",{enumerable:!1,configurable:!0,set:function(t){void 0===t&&(t=0),this._incidentEdge=t,this._m_id._key=4294902015&this._m_id._key|65280&this._incidentEdge<<8}}),Object.defineProperty(E.prototype,"incidentVertex",{enumerable:!1,configurable:!0,get:function(){return this._incidentVertex}}),Object.defineProperty(E.prototype,"incidentVertex",{enumerable:!1,configurable:!0,set:function(t){void 0===t&&(t=0),this._incidentVertex=t,this._m_id._key=4278255615&this._m_id._key|16711680&this._incidentVertex<<16}}),Object.defineProperty(E.prototype,"flip",{enumerable:!1,configurable:!0,get:function(){return this._flip}}),Object.defineProperty(E.prototype,"flip",{enumerable:!1,configurable:!0,set:function(t){void 0===t&&(t=0),this._flip=t,this._m_id._key=16777215&this._m_id._key|4278190080&this._flip<<24}})}(),function(){var t=(o.Common.b2Color,o.Common.b2internal,o.Common.b2Settings),i=o.Collision.Shapes.b2CircleShape,e=o.Collision.Shapes.b2EdgeChainDef,r=o.Collision.Shapes.b2EdgeShape,a=o.Collision.Shapes.b2MassData,m=o.Collision.Shapes.b2PolygonShape,l=o.Collision.Shapes.b2Shape,c=o.Common.Math.b2Mat22,h=(o.Common.Math.b2Mat33,o.Common.Math.b2Math),_=(o.Common.Math.b2Sweep,o.Common.Math.b2Transform),p=o.Common.Math.b2Vec2,y=(o.Common.Math.b2Vec3,o.Dynamics.b2Body,o.Dynamics.b2BodyDef,o.Dynamics.b2ContactFilter,o.Dynamics.b2ContactImpulse,o.Dynamics.b2ContactListener,o.Dynamics.b2ContactManager,o.Dynamics.b2DebugDraw,o.Dynamics.b2DestructionListener,o.Dynamics.b2FilterData,o.Dynamics.b2Fixture,o.Dynamics.b2FixtureDef,o.Dynamics.b2Island,o.Dynamics.b2TimeStep,o.Dynamics.b2World,o.Collision.b2AABB,o.Collision.b2Bound,o.Collision.b2BoundValues,o.Collision.b2Collision,o.Collision.b2ContactID,o.Collision.b2ContactPoint,o.Collision.b2Distance),u=o.Collision.b2DistanceInput,x=o.Collision.b2DistanceOutput,f=o.Collision.b2DistanceProxy,d=(o.Collision.b2DynamicTree,o.Collision.b2DynamicTreeBroadPhase,o.Collision.b2DynamicTreeNode,o.Collision.b2DynamicTreePair,o.Collision.b2Manifold,o.Collision.b2ManifoldPoint,o.Collision.b2Point,o.Collision.b2RayCastInput,o.Collision.b2RayCastOutput,o.Collision.b2Segment,o.Collision.b2SeparationFunction,o.Collision.b2Simplex,o.Collision.b2SimplexCache);o.Collision.b2SimplexVertex,o.Collision.b2TimeOfImpact,o.Collision.b2TOIInput,o.Collision.b2WorldManifold,o.Collision.ClipVertex,o.Collision.Features,o.Collision.IBroadPhase,o.inherit(i,o.Collision.Shapes.b2Shape),i.prototype.__super=o.Collision.Shapes.b2Shape.prototype,i.b2CircleShape=function(){o.Collision.Shapes.b2Shape.b2Shape.apply(this,arguments),this.m_p=new p},i.prototype.Copy=function(){var t=new i;return t.Set(this),t},i.prototype.Set=function(t){if(this.__super.Set.call(this,t),o.is(t,i)){var e=t instanceof i?t:null;this.m_p.SetV(e.m_p)}},i.prototype.TestPoint=function(t,i){var e=t.R,o=t.position.x+(e.col1.x*this.m_p.x+e.col2.x*this.m_p.y),n=t.position.y+(e.col1.y*this.m_p.x+e.col2.y*this.m_p.y);return o=i.x-o,n=i.y-n,this.m_radius*this.m_radius>=o*o+n*n},i.prototype.RayCast=function(t,i,e){var o=e.R,n=e.position.x+(o.col1.x*this.m_p.x+o.col2.x*this.m_p.y),s=e.position.y+(o.col1.y*this.m_p.x+o.col2.y*this.m_p.y),r=i.p1.x-n,a=i.p1.y-s,m=r*r+a*a-this.m_radius*this.m_radius,l=i.p2.x-i.p1.x,c=i.p2.y-i.p1.y,h=r*l+a*c,_=l*l+c*c,p=h*h-_*m;if(0>p||Number.MIN_VALUE>_)return!1;var y=-(h+Math.sqrt(p));return y>=0&&i.maxFraction*_>=y?(y/=_,t.fraction=y,t.normal.x=r+y*l,t.normal.y=a+y*c,t.normal.Normalize(),!0):!1},i.prototype.ComputeAABB=function(t,i){var e=i.R,o=i.position.x+(e.col1.x*this.m_p.x+e.col2.x*this.m_p.y),n=i.position.y+(e.col1.y*this.m_p.x+e.col2.y*this.m_p.y);t.lowerBound.Set(o-this.m_radius,n-this.m_radius),t.upperBound.Set(o+this.m_radius,n+this.m_radius)},i.prototype.ComputeMass=function(i,e){void 0===e&&(e=0),i.mass=e*t.b2_pi*this.m_radius*this.m_radius,i.center.SetV(this.m_p),i.I=i.mass*(.5*this.m_radius*this.m_radius+(this.m_p.x*this.m_p.x+this.m_p.y*this.m_p.y))},i.prototype.ComputeSubmergedArea=function(t,i,e,o){void 0===i&&(i=0);var n=h.MulX(e,this.m_p),s=-(h.Dot(t,n)-i);if(-this.m_radius+Number.MIN_VALUE>s)return 0;if(s>this.m_radius)return o.SetV(n),Math.PI*this.m_radius*this.m_radius;var r=this.m_radius*this.m_radius,a=s*s,m=r*(Math.asin(s/this.m_radius)+Math.PI/2)+s*Math.sqrt(r-a),l=-2/3*Math.pow(r-a,1.5)/m;return o.x=n.x+t.x*l,o.y=n.y+t.y*l,m},i.prototype.GetLocalPosition=function(){return this.m_p},i.prototype.SetLocalPosition=function(t){this.m_p.SetV(t)},i.prototype.GetRadius=function(){return this.m_radius},i.prototype.SetRadius=function(t){void 0===t&&(t=0),this.m_radius=t},i.prototype.b2CircleShape=function(t){void 0===t&&(t=0),this.__super.b2Shape.call(this),this.m_type=l.e_circleShape,this.m_radius=t},e.b2EdgeChainDef=function(){},e.prototype.b2EdgeChainDef=function(){this.vertexCount=0,this.isALoop=!0,this.vertices=[]},o.inherit(r,o.Collision.Shapes.b2Shape),r.prototype.__super=o.Collision.Shapes.b2Shape.prototype,r.b2EdgeShape=function(){o.Collision.Shapes.b2Shape.b2Shape.apply(this,arguments),this.s_supportVec=new p,this.m_v1=new p,this.m_v2=new p,this.m_coreV1=new p,this.m_coreV2=new p,this.m_normal=new p,this.m_direction=new p,this.m_cornerDir1=new p,this.m_cornerDir2=new p},r.prototype.TestPoint=function(){return!1},r.prototype.RayCast=function(t,i,e){var o,n=i.p2.x-i.p1.x,s=i.p2.y-i.p1.y;o=e.R;var r=e.position.x+(o.col1.x*this.m_v1.x+o.col2.x*this.m_v1.y),a=e.position.y+(o.col1.y*this.m_v1.x+o.col2.y*this.m_v1.y),m=e.position.y+(o.col1.y*this.m_v2.x+o.col2.y*this.m_v2.y)-a,l=-(e.position.x+(o.col1.x*this.m_v2.x+o.col2.x*this.m_v2.y)-r),c=100*Number.MIN_VALUE,h=-(n*m+s*l);if(h>c){var _=i.p1.x-r,p=i.p1.y-a,y=_*m+p*l;if(y>=0&&i.maxFraction*h>=y){var u=-n*p+s*_;if(u>=-c*h&&h*(1+c)>=u){y/=h,t.fraction=y;var x=Math.sqrt(m*m+l*l);return t.normal.x=m/x,t.normal.y=l/x,!0}}}return!1},r.prototype.ComputeAABB=function(t,i){var e=i.R,o=i.position.x+(e.col1.x*this.m_v1.x+e.col2.x*this.m_v1.y),n=i.position.y+(e.col1.y*this.m_v1.x+e.col2.y*this.m_v1.y),s=i.position.x+(e.col1.x*this.m_v2.x+e.col2.x*this.m_v2.y),r=i.position.y+(e.col1.y*this.m_v2.x+e.col2.y*this.m_v2.y);s>o?(t.lowerBound.x=o,t.upperBound.x=s):(t.lowerBound.x=s,t.upperBound.x=o),r>n?(t.lowerBound.y=n,t.upperBound.y=r):(t.lowerBound.y=r,t.upperBound.y=n)},r.prototype.ComputeMass=function(t,i){void 0===i&&(i=0),t.mass=0,t.center.SetV(this.m_v1),t.I=0},r.prototype.ComputeSubmergedArea=function(t,i,e,o){void 0===i&&(i=0);var n=new p(t.x*i,t.y*i),s=h.MulX(e,this.m_v1),r=h.MulX(e,this.m_v2),a=h.Dot(t,s)-i,m=h.Dot(t,r)-i;if(a>0){if(m>0)return 0;s.x=-m/(a-m)*s.x+a/(a-m)*r.x,s.y=-m/(a-m)*s.y+a/(a-m)*r.y}else m>0&&(r.x=-m/(a-m)*s.x+a/(a-m)*r.x,r.y=-m/(a-m)*s.y+a/(a-m)*r.y);return o.x=(n.x+s.x+r.x)/3,o.y=(n.y+s.y+r.y)/3,.5*((s.x-n.x)*(r.y-n.y)-(s.y-n.y)*(r.x-n.x))},r.prototype.GetLength=function(){return this.m_length},r.prototype.GetVertex1=function(){return this.m_v1},r.prototype.GetVertex2=function(){return this.m_v2},r.prototype.GetCoreVertex1=function(){return this.m_coreV1},r.prototype.GetCoreVertex2=function(){return this.m_coreV2},r.prototype.GetNormalVector=function(){return this.m_normal},r.prototype.GetDirectionVector=function(){return this.m_direction},r.prototype.GetCorner1Vector=function(){return this.m_cornerDir1},r.prototype.GetCorner2Vector=function(){return this.m_cornerDir2},r.prototype.Corner1IsConvex=function(){return this.m_cornerConvex1},r.prototype.Corner2IsConvex=function(){return this.m_cornerConvex2},r.prototype.GetFirstVertex=function(t){var i=t.R;return new p(t.position.x+(i.col1.x*this.m_coreV1.x+i.col2.x*this.m_coreV1.y),t.position.y+(i.col1.y*this.m_coreV1.x+i.col2.y*this.m_coreV1.y))},r.prototype.GetNextEdge=function(){return this.m_nextEdge},r.prototype.GetPrevEdge=function(){return this.m_prevEdge},r.prototype.Support=function(t,i,e){void 0===i&&(i=0),void 0===e&&(e=0);var o=t.R,n=t.position.x+(o.col1.x*this.m_coreV1.x+o.col2.x*this.m_coreV1.y),s=t.position.y+(o.col1.y*this.m_coreV1.x+o.col2.y*this.m_coreV1.y),r=t.position.x+(o.col1.x*this.m_coreV2.x+o.col2.x*this.m_coreV2.y),a=t.position.y+(o.col1.y*this.m_coreV2.x+o.col2.y*this.m_coreV2.y);return n*i+s*e>r*i+a*e?(this.s_supportVec.x=n,this.s_supportVec.y=s):(this.s_supportVec.x=r,this.s_supportVec.y=a),this.s_supportVec},r.prototype.b2EdgeShape=function(i,e){this.__super.b2Shape.call(this),this.m_type=l.e_edgeShape,this.m_prevEdge=null,this.m_nextEdge=null,this.m_v1=i,this.m_v2=e,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(-t.b2_toiSlop*(this.m_normal.x-this.m_direction.x)+this.m_v1.x,-t.b2_toiSlop*(this.m_normal.y-this.m_direction.y)+this.m_v1.y),this.m_coreV2.Set(-t.b2_toiSlop*(this.m_normal.x+this.m_direction.x)+this.m_v2.x,-t.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)},r.prototype.SetPrevEdge=function(t,i,e,o){this.m_prevEdge=t,this.m_coreV1=i,this.m_cornerDir1=e,this.m_cornerConvex1=o},r.prototype.SetNextEdge=function(t,i,e,o){this.m_nextEdge=t,this.m_coreV2=i,this.m_cornerDir2=e,this.m_cornerConvex2=o},a.b2MassData=function(){this.mass=0,this.center=new p(0,0),this.I=0},o.inherit(m,o.Collision.Shapes.b2Shape),m.prototype.__super=o.Collision.Shapes.b2Shape.prototype,m.b2PolygonShape=function(){o.Collision.Shapes.b2Shape.b2Shape.apply(this,arguments)},m.prototype.Copy=function(){var t=new m;return t.Set(this),t},m.prototype.Set=function(t){if(this.__super.Set.call(this,t),o.is(t,m)){var i=t instanceof m?t:null;this.m_centroid.SetV(i.m_centroid),this.m_vertexCount=i.m_vertexCount,this.Reserve(this.m_vertexCount);for(var e=0;this.m_vertexCount>e;e++)this.m_vertices[e].SetV(i.m_vertices[e]),this.m_normals[e].SetV(i.m_normals[e])}},m.prototype.SetAsArray=function(t,i){void 0===i&&(i=0);var e,o=new n,s=0;for(s=0;t.length>s;++s)e=t[s],o.push(e);this.SetAsVector(o,i)},m.AsArray=function(t,i){void 0===i&&(i=0);var e=new m;return e.SetAsArray(t,i),e},m.prototype.SetAsVector=function(i,e){void 0===e&&(e=0),0==e&&(e=i.length),t.b2Assert(e>=2),this.m_vertexCount=e,this.Reserve(e);var o=0;for(o=0;this.m_vertexCount>o;o++)this.m_vertices[o].SetV(i[o]);for(o=0;this.m_vertexCount>o;++o){var n=parseInt(o),s=parseInt(this.m_vertexCount>o+1?o+1:0),r=h.SubtractVV(this.m_vertices[s],this.m_vertices[n]);t.b2Assert(r.LengthSquared()>Number.MIN_VALUE),this.m_normals[o].SetV(h.CrossVF(r,1)),this.m_normals[o].Normalize()}this.m_centroid=m.ComputeCentroid(this.m_vertices,this.m_vertexCount)},m.AsVector=function(t,i){void 0===i&&(i=0);var e=new m;return e.SetAsVector(t,i),e},m.prototype.SetAsBox=function(t,i){void 0===t&&(t=0),void 0===i&&(i=0),this.m_vertexCount=4,this.Reserve(4),this.m_vertices[0].Set(-t,-i),this.m_vertices[1].Set(t,-i),this.m_vertices[2].Set(t,i),this.m_vertices[3].Set(-t,i),this.m_normals[0].Set(0,-1),this.m_normals[1].Set(1,0),this.m_normals[2].Set(0,1),this.m_normals[3].Set(-1,0),this.m_centroid.SetZero()},m.AsBox=function(t,i){void 0===t&&(t=0),void 0===i&&(i=0);var e=new m;return e.SetAsBox(t,i),e},m.prototype.SetAsOrientedBox=function(t,i,e,o){void 0===t&&(t=0),void 0===i&&(i=0),void 0===e&&(e=null),void 0===o&&(o=0),this.m_vertexCount=4,this.Reserve(4),this.m_vertices[0].Set(-t,-i),this.m_vertices[1].Set(t,-i),this.m_vertices[2].Set(t,i),this.m_vertices[3].Set(-t,i),this.m_normals[0].Set(0,-1),this.m_normals[1].Set(1,0),this.m_normals[2].Set(0,1),this.m_normals[3].Set(-1,0),this.m_centroid=e;var n=new _;n.position=e,n.R.Set(o);for(var s=0;this.m_vertexCount>s;++s)this.m_vertices[s]=h.MulX(n,this.m_vertices[s]),this.m_normals[s]=h.MulMV(n.R,this.m_normals[s])},m.AsOrientedBox=function(t,i,e,o){void 0===t&&(t=0),void 0===i&&(i=0),void 0===e&&(e=null),void 0===o&&(o=0);var n=new m;return n.SetAsOrientedBox(t,i,e,o),n},m.prototype.SetAsEdge=function(t,i){this.m_vertexCount=2,this.Reserve(2),this.m_vertices[0].SetV(t),this.m_vertices[1].SetV(i),this.m_centroid.x=.5*(t.x+i.x),this.m_centroid.y=.5*(t.y+i.y),this.m_normals[0]=h.CrossVF(h.SubtractVV(i,t),1),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},m.AsEdge=function(t,i){var e=new m;return e.SetAsEdge(t,i),e},m.prototype.TestPoint=function(t,i){for(var e,o=t.R,n=i.x-t.position.x,s=i.y-t.position.y,r=n*o.col1.x+s*o.col1.y,a=n*o.col2.x+s*o.col2.y,m=0;this.m_vertexCount>m;++m){e=this.m_vertices[m],n=r-e.x,s=a-e.y,e=this.m_normals[m];var l=e.x*n+e.y*s;if(l>0)return!1}return!0},m.prototype.RayCast=function(t,i,e){var o,n,s=0,r=i.maxFraction,a=0,m=0;a=i.p1.x-e.position.x,m=i.p1.y-e.position.y,o=e.R;var l=a*o.col1.x+m*o.col1.y,c=a*o.col2.x+m*o.col2.y;a=i.p2.x-e.position.x,m=i.p2.y-e.position.y,o=e.R;for(var h=a*o.col1.x+m*o.col1.y,_=a*o.col2.x+m*o.col2.y,p=h-l,y=_-c,u=parseInt(-1),x=0;this.m_vertexCount>x;++x){n=this.m_vertices[x],a=n.x-l,m=n.y-c,n=this.m_normals[x];var f=n.x*a+n.y*m,d=n.x*p+n.y*y;if(0==d){if(0>f)return!1}else 0>d&&s*d>f?(s=f/d,u=x):d>0&&r*d>f&&(r=f/d);if(s-Number.MIN_VALUE>r)return!1}return u>=0?(t.fraction=s,o=e.R,n=this.m_normals[u],t.normal.x=o.col1.x*n.x+o.col2.x*n.y,t.normal.y=o.col1.y*n.x+o.col2.y*n.y,!0):!1},m.prototype.ComputeAABB=function(t,i){for(var e=i.R,o=this.m_vertices[0],n=i.position.x+(e.col1.x*o.x+e.col2.x*o.y),s=i.position.y+(e.col1.y*o.x+e.col2.y*o.y),r=n,a=s,m=1;this.m_vertexCount>m;++m){o=this.m_vertices[m];var l=i.position.x+(e.col1.x*o.x+e.col2.x*o.y),c=i.position.y+(e.col1.y*o.x+e.col2.y*o.y);n=l>n?n:l,s=c>s?s:c,r=r>l?r:l,a=a>c?a:c}t.lowerBound.x=n-this.m_radius,t.lowerBound.y=s-this.m_radius,t.upperBound.x=r+this.m_radius,t.upperBound.y=a+this.m_radius},m.prototype.ComputeMass=function(t,i){if(void 0===i&&(i=0),2==this.m_vertexCount)return t.center.x=.5*(this.m_vertices[0].x+this.m_vertices[1].x),t.center.y=.5*(this.m_vertices[0].y+this.m_vertices[1].y),t.mass=0,t.I=0,void 0;for(var e=0,o=0,n=0,s=0,r=0,a=0,m=1/3,l=0;this.m_vertexCount>l;++l){var c=this.m_vertices[l],h=this.m_vertexCount>l+1?this.m_vertices[parseInt(l+1)]:this.m_vertices[0],_=c.x-r,p=c.y-a,y=h.x-r,u=h.y-a,x=_*u-p*y,f=.5*x;
n+=f,e+=f*m*(r+c.x+h.x),o+=f*m*(a+c.y+h.y);var d=r,b=a,v=_,C=p,g=y,w=u,A=m*(.25*(v*v+g*v+g*g)+(d*v+d*g))+.5*d*d,S=m*(.25*(C*C+w*C+w*w)+(b*C+b*w))+.5*b*b;s+=x*(A+S)}t.mass=i*n,e*=1/n,o*=1/n,t.center.Set(e,o),t.I=i*s},m.prototype.ComputeSubmergedArea=function(t,i,e,o){void 0===i&&(i=0);var n=h.MulTMV(e.R,t),r=i-h.Dot(t,e.position),m=new s,l=0,c=parseInt(-1),_=parseInt(-1),y=!1,u=0;for(u=0;this.m_vertexCount>u;++u){m[u]=h.Dot(n,this.m_vertices[u])-r;var x=m[u]<-Number.MIN_VALUE;u>0&&(x?y||(c=u-1,l++):y&&(_=u-1,l++)),y=x}switch(l){case 0:if(y){var f=new a;return this.ComputeMass(f,1),o.SetV(h.MulX(e,f.center)),f.mass}return 0;case 1:-1==c?c=this.m_vertexCount-1:_=this.m_vertexCount-1}var d,b=parseInt((c+1)%this.m_vertexCount),v=parseInt((_+1)%this.m_vertexCount),C=(0-m[c])/(m[b]-m[c]),g=(0-m[_])/(m[v]-m[_]),w=new p(this.m_vertices[c].x*(1-C)+this.m_vertices[b].x*C,this.m_vertices[c].y*(1-C)+this.m_vertices[b].y*C),A=new p(this.m_vertices[_].x*(1-g)+this.m_vertices[v].x*g,this.m_vertices[_].y*(1-g)+this.m_vertices[v].y*g),S=0,D=new p,B=this.m_vertices[b];for(u=b;u!=v;){u=(u+1)%this.m_vertexCount,d=u==v?A:this.m_vertices[u];var M=.5*((B.x-w.x)*(d.y-w.y)-(B.y-w.y)*(d.x-w.x));S+=M,D.x+=M*(w.x+B.x+d.x)/3,D.y+=M*(w.y+B.y+d.y)/3,B=d}return D.Multiply(1/S),o.SetV(h.MulX(e,D)),S},m.prototype.GetVertexCount=function(){return this.m_vertexCount},m.prototype.GetVertices=function(){return this.m_vertices},m.prototype.GetNormals=function(){return this.m_normals},m.prototype.GetSupport=function(t){for(var i=0,e=this.m_vertices[0].x*t.x+this.m_vertices[0].y*t.y,o=1;this.m_vertexCount>o;++o){var n=this.m_vertices[o].x*t.x+this.m_vertices[o].y*t.y;n>e&&(i=o,e=n)}return i},m.prototype.GetSupportVertex=function(t){for(var i=0,e=this.m_vertices[0].x*t.x+this.m_vertices[0].y*t.y,o=1;this.m_vertexCount>o;++o){var n=this.m_vertices[o].x*t.x+this.m_vertices[o].y*t.y;n>e&&(i=o,e=n)}return this.m_vertices[i]},m.prototype.Validate=function(){return!1},m.prototype.b2PolygonShape=function(){this.__super.b2Shape.call(this),this.m_type=l.e_polygonShape,this.m_centroid=new p,this.m_vertices=new n,this.m_normals=new n},m.prototype.Reserve=function(t){void 0===t&&(t=0);for(var i=parseInt(this.m_vertices.length);t>i;i++)this.m_vertices[i]=new p,this.m_normals[i]=new p},m.ComputeCentroid=function(t,i){void 0===i&&(i=0);for(var e=new p,o=0,n=0,s=0,r=1/3,a=0;i>a;++a){var m=t[a],l=i>a+1?t[parseInt(a+1)]:t[0],c=m.x-n,h=m.y-s,_=l.x-n,y=l.y-s,u=c*y-h*_,x=.5*u;o+=x,e.x+=x*r*(n+m.x+l.x),e.y+=x*r*(s+m.y+l.y)}return e.x*=1/o,e.y*=1/o,e},m.ComputeOBB=function(t,i,e){void 0===e&&(e=0);var o=0,s=new n(e+1);for(o=0;e>o;++o)s[o]=i[o];s[e]=s[0];var r=Number.MAX_VALUE;for(o=1;e>=o;++o){var a=s[parseInt(o-1)],m=s[o].x-a.x,l=s[o].y-a.y,c=Math.sqrt(m*m+l*l);m/=c,l/=c;for(var h=-l,_=m,p=Number.MAX_VALUE,y=Number.MAX_VALUE,u=-Number.MAX_VALUE,x=-Number.MAX_VALUE,f=0;e>f;++f){var d=s[f].x-a.x,b=s[f].y-a.y,v=m*d+l*b,C=h*d+_*b;p>v&&(p=v),y>C&&(y=C),v>u&&(u=v),C>x&&(x=C)}var g=(u-p)*(x-y);if(.95*r>g){r=g,t.R.col1.x=m,t.R.col1.y=l,t.R.col2.x=h,t.R.col2.y=_;var w=.5*(p+u),A=.5*(y+x),S=t.R;t.center.x=a.x+(S.col1.x*w+S.col2.x*A),t.center.y=a.y+(S.col1.y*w+S.col2.y*A),t.extents.x=.5*(u-p),t.extents.y=.5*(x-y)}}},o.postDefs.push(function(){o.Collision.Shapes.b2PolygonShape.s_mat=new c}),l.b2Shape=function(){},l.prototype.Copy=function(){return null},l.prototype.Set=function(t){this.m_radius=t.m_radius},l.prototype.GetType=function(){return this.m_type},l.prototype.TestPoint=function(){return!1},l.prototype.RayCast=function(){return!1},l.prototype.ComputeAABB=function(){},l.prototype.ComputeMass=function(t,i){void 0===i&&(i=0)},l.prototype.ComputeSubmergedArea=function(t,i){return void 0===i&&(i=0),0},l.TestOverlap=function(t,i,e,o){var n=new u;n.proxyA=new f,n.proxyA.Set(t),n.proxyB=new f,n.proxyB.Set(e),n.transformA=i,n.transformB=o,n.useRadii=!0;var s=new d;s.count=0;var r=new x;return y.Distance(r,s,n),r.distance<10*Number.MIN_VALUE},l.prototype.b2Shape=function(){this.m_type=l.e_unknownShape,this.m_radius=t.b2_linearSlop},o.postDefs.push(function(){o.Collision.Shapes.b2Shape.e_unknownShape=parseInt(-1),o.Collision.Shapes.b2Shape.e_circleShape=0,o.Collision.Shapes.b2Shape.e_polygonShape=1,o.Collision.Shapes.b2Shape.e_edgeShape=2,o.Collision.Shapes.b2Shape.e_shapeTypeCount=3,o.Collision.Shapes.b2Shape.e_hitCollide=1,o.Collision.Shapes.b2Shape.e_missCollide=0,o.Collision.Shapes.b2Shape.e_startsInsideCollide=parseInt(-1)})}(),function(){var t=o.Common.b2Color,i=(o.Common.b2internal,o.Common.b2Settings),e=(o.Common.Math.b2Mat22,o.Common.Math.b2Mat33,o.Common.Math.b2Math);o.Common.Math.b2Sweep,o.Common.Math.b2Transform,o.Common.Math.b2Vec2,o.Common.Math.b2Vec3,t.b2Color=function(){this._r=0,this._g=0,this._b=0},t.prototype.b2Color=function(t,i,n){void 0===t&&(t=0),void 0===i&&(i=0),void 0===n&&(n=0),this._r=o.parseUInt(255*e.Clamp(t,0,1)),this._g=o.parseUInt(255*e.Clamp(i,0,1)),this._b=o.parseUInt(255*e.Clamp(n,0,1))},t.prototype.Set=function(t,i,n){void 0===t&&(t=0),void 0===i&&(i=0),void 0===n&&(n=0),this._r=o.parseUInt(255*e.Clamp(t,0,1)),this._g=o.parseUInt(255*e.Clamp(i,0,1)),this._b=o.parseUInt(255*e.Clamp(n,0,1))},Object.defineProperty(t.prototype,"r",{enumerable:!1,configurable:!0,set:function(t){void 0===t&&(t=0),this._r=o.parseUInt(255*e.Clamp(t,0,1))}}),Object.defineProperty(t.prototype,"g",{enumerable:!1,configurable:!0,set:function(t){void 0===t&&(t=0),this._g=o.parseUInt(255*e.Clamp(t,0,1))}}),Object.defineProperty(t.prototype,"b",{enumerable:!1,configurable:!0,set:function(t){void 0===t&&(t=0),this._b=o.parseUInt(255*e.Clamp(t,0,1))}}),Object.defineProperty(t.prototype,"color",{enumerable:!1,configurable:!0,get:function(){return this._r<<16|this._g<<8|this._b}}),i.b2Settings=function(){},i.b2MixFriction=function(t,i){return void 0===t&&(t=0),void 0===i&&(i=0),Math.sqrt(t*i)},i.b2MixRestitution=function(t,i){return void 0===t&&(t=0),void 0===i&&(i=0),t>i?t:i},i.b2Assert=function(t){if(!t)throw"Assertion Failed"},o.postDefs.push(function(){o.Common.b2Settings.VERSION="2.1alpha",o.Common.b2Settings.USHRT_MAX=65535,o.Common.b2Settings.b2_pi=Math.PI,o.Common.b2Settings.b2_maxManifoldPoints=2,o.Common.b2Settings.b2_aabbExtension=.1,o.Common.b2Settings.b2_aabbMultiplier=2,o.Common.b2Settings.b2_polygonRadius=2*i.b2_linearSlop,o.Common.b2Settings.b2_linearSlop=.005,o.Common.b2Settings.b2_angularSlop=2/180*i.b2_pi,o.Common.b2Settings.b2_toiSlop=8*i.b2_linearSlop,o.Common.b2Settings.b2_maxTOIContactsPerIsland=32,o.Common.b2Settings.b2_maxTOIJointsPerIsland=32,o.Common.b2Settings.b2_velocityThreshold=1,o.Common.b2Settings.b2_maxLinearCorrection=.2,o.Common.b2Settings.b2_maxAngularCorrection=8/180*i.b2_pi,o.Common.b2Settings.b2_maxTranslation=2,o.Common.b2Settings.b2_maxTranslationSquared=i.b2_maxTranslation*i.b2_maxTranslation,o.Common.b2Settings.b2_maxRotation=.5*i.b2_pi,o.Common.b2Settings.b2_maxRotationSquared=i.b2_maxRotation*i.b2_maxRotation,o.Common.b2Settings.b2_contactBaumgarte=.2,o.Common.b2Settings.b2_timeToSleep=.5,o.Common.b2Settings.b2_linearSleepTolerance=.01,o.Common.b2Settings.b2_angularSleepTolerance=2/180*i.b2_pi})}(),function(){var t=(o.Collision.b2AABB,o.Common.b2Color,o.Common.b2internal,o.Common.b2Settings,o.Common.Math.b2Mat22),i=o.Common.Math.b2Mat33,e=o.Common.Math.b2Math,n=o.Common.Math.b2Sweep,s=o.Common.Math.b2Transform,r=o.Common.Math.b2Vec2,a=o.Common.Math.b2Vec3;t.b2Mat22=function(){this.col1=new r,this.col2=new r},t.prototype.b2Mat22=function(){this.SetIdentity()},t.FromAngle=function(i){void 0===i&&(i=0);var e=new t;return e.Set(i),e},t.FromVV=function(i,e){var o=new t;return o.SetVV(i,e),o},t.prototype.Set=function(t){void 0===t&&(t=0);var i=Math.cos(t),e=Math.sin(t);this.col1.x=i,this.col2.x=-e,this.col1.y=e,this.col2.y=i},t.prototype.SetVV=function(t,i){this.col1.SetV(t),this.col2.SetV(i)},t.prototype.Copy=function(){var i=new t;return i.SetM(this),i},t.prototype.SetM=function(t){this.col1.SetV(t.col1),this.col2.SetV(t.col2)},t.prototype.AddM=function(t){this.col1.x+=t.col1.x,this.col1.y+=t.col1.y,this.col2.x+=t.col2.x,this.col2.y+=t.col2.y},t.prototype.SetIdentity=function(){this.col1.x=1,this.col2.x=0,this.col1.y=0,this.col2.y=1},t.prototype.SetZero=function(){this.col1.x=0,this.col2.x=0,this.col1.y=0,this.col2.y=0},t.prototype.GetAngle=function(){return Math.atan2(this.col1.y,this.col1.x)},t.prototype.GetInverse=function(t){var i=this.col1.x,e=this.col2.x,o=this.col1.y,n=this.col2.y,s=i*n-e*o;return 0!=s&&(s=1/s),t.col1.x=s*n,t.col2.x=-s*e,t.col1.y=-s*o,t.col2.y=s*i,t},t.prototype.Solve=function(t,i,e){void 0===i&&(i=0),void 0===e&&(e=0);var o=this.col1.x,n=this.col2.x,s=this.col1.y,r=this.col2.y,a=o*r-n*s;return 0!=a&&(a=1/a),t.x=a*(r*i-n*e),t.y=a*(o*e-s*i),t},t.prototype.Abs=function(){this.col1.Abs(),this.col2.Abs()},i.b2Mat33=function(){this.col1=new a,this.col2=new a,this.col3=new a},i.prototype.b2Mat33=function(t,i,e){void 0===t&&(t=null),void 0===i&&(i=null),void 0===e&&(e=null),t||i||e?(this.col1.SetV(t),this.col2.SetV(i),this.col3.SetV(e)):(this.col1.SetZero(),this.col2.SetZero(),this.col3.SetZero())},i.prototype.SetVVV=function(t,i,e){this.col1.SetV(t),this.col2.SetV(i),this.col3.SetV(e)},i.prototype.Copy=function(){return new i(this.col1,this.col2,this.col3)},i.prototype.SetM=function(t){this.col1.SetV(t.col1),this.col2.SetV(t.col2),this.col3.SetV(t.col3)},i.prototype.AddM=function(t){this.col1.x+=t.col1.x,this.col1.y+=t.col1.y,this.col1.z+=t.col1.z,this.col2.x+=t.col2.x,this.col2.y+=t.col2.y,this.col2.z+=t.col2.z,this.col3.x+=t.col3.x,this.col3.y+=t.col3.y,this.col3.z+=t.col3.z},i.prototype.SetIdentity=function(){this.col1.x=1,this.col2.x=0,this.col3.x=0,this.col1.y=0,this.col2.y=1,this.col3.y=0,this.col1.z=0,this.col2.z=0,this.col3.z=1},i.prototype.SetZero=function(){this.col1.x=0,this.col2.x=0,this.col3.x=0,this.col1.y=0,this.col2.y=0,this.col3.y=0,this.col1.z=0,this.col2.z=0,this.col3.z=0},i.prototype.Solve22=function(t,i,e){void 0===i&&(i=0),void 0===e&&(e=0);var o=this.col1.x,n=this.col2.x,s=this.col1.y,r=this.col2.y,a=o*r-n*s;return 0!=a&&(a=1/a),t.x=a*(r*i-n*e),t.y=a*(o*e-s*i),t},i.prototype.Solve33=function(t,i,e,o){void 0===i&&(i=0),void 0===e&&(e=0),void 0===o&&(o=0);var n=this.col1.x,s=this.col1.y,r=this.col1.z,a=this.col2.x,m=this.col2.y,l=this.col2.z,c=this.col3.x,h=this.col3.y,_=this.col3.z,p=n*(m*_-l*h)+s*(l*c-a*_)+r*(a*h-m*c);return 0!=p&&(p=1/p),t.x=p*(i*(m*_-l*h)+e*(l*c-a*_)+o*(a*h-m*c)),t.y=p*(n*(e*_-o*h)+s*(o*c-i*_)+r*(i*h-e*c)),t.z=p*(n*(m*o-l*e)+s*(l*i-a*o)+r*(a*e-m*i)),t},e.b2Math=function(){},e.IsValid=function(t){return void 0===t&&(t=0),isFinite(t)},e.Dot=function(t,i){return t.x*i.x+t.y*i.y},e.CrossVV=function(t,i){return t.x*i.y-t.y*i.x},e.CrossVF=function(t,i){void 0===i&&(i=0);var e=new r(i*t.y,-i*t.x);return e},e.CrossFV=function(t,i){void 0===t&&(t=0);var e=new r(-t*i.y,t*i.x);return e},e.MulMV=function(t,i){var e=new r(t.col1.x*i.x+t.col2.x*i.y,t.col1.y*i.x+t.col2.y*i.y);return e},e.MulTMV=function(t,i){var o=new r(e.Dot(i,t.col1),e.Dot(i,t.col2));return o},e.MulX=function(t,i){var o=e.MulMV(t.R,i);return o.x+=t.position.x,o.y+=t.position.y,o},e.MulXT=function(t,i){var o=e.SubtractVV(i,t.position),n=o.x*t.R.col1.x+o.y*t.R.col1.y;return o.y=o.x*t.R.col2.x+o.y*t.R.col2.y,o.x=n,o},e.AddVV=function(t,i){var e=new r(t.x+i.x,t.y+i.y);return e},e.SubtractVV=function(t,i){var e=new r(t.x-i.x,t.y-i.y);return e},e.Distance=function(t,i){var e=t.x-i.x,o=t.y-i.y;return Math.sqrt(e*e+o*o)},e.DistanceSquared=function(t,i){var e=t.x-i.x,o=t.y-i.y;return e*e+o*o},e.MulFV=function(t,i){void 0===t&&(t=0);var e=new r(t*i.x,t*i.y);return e},e.AddMM=function(i,o){var n=t.FromVV(e.AddVV(i.col1,o.col1),e.AddVV(i.col2,o.col2));return n},e.MulMM=function(i,o){var n=t.FromVV(e.MulMV(i,o.col1),e.MulMV(i,o.col2));return n},e.MulTMM=function(i,o){var n=new r(e.Dot(i.col1,o.col1),e.Dot(i.col2,o.col1)),s=new r(e.Dot(i.col1,o.col2),e.Dot(i.col2,o.col2)),a=t.FromVV(n,s);return a},e.Abs=function(t){return void 0===t&&(t=0),t>0?t:-t},e.AbsV=function(t){var i=new r(e.Abs(t.x),e.Abs(t.y));return i},e.AbsM=function(i){var o=t.FromVV(e.AbsV(i.col1),e.AbsV(i.col2));return o},e.Min=function(t,i){return void 0===t&&(t=0),void 0===i&&(i=0),i>t?t:i},e.MinV=function(t,i){var o=new r(e.Min(t.x,i.x),e.Min(t.y,i.y));return o},e.Max=function(t,i){return void 0===t&&(t=0),void 0===i&&(i=0),t>i?t:i},e.MaxV=function(t,i){var o=new r(e.Max(t.x,i.x),e.Max(t.y,i.y));return o},e.Clamp=function(t,i,e){return void 0===t&&(t=0),void 0===i&&(i=0),void 0===e&&(e=0),i>t?i:t>e?e:t},e.ClampV=function(t,i,o){return e.MaxV(i,e.MinV(t,o))},e.Swap=function(t,i){var e=t[0];t[0]=i[0],i[0]=e},e.Random=function(){return 2*Math.random()-1},e.RandomRange=function(t,i){void 0===t&&(t=0),void 0===i&&(i=0);var e=Math.random();return e=(i-t)*e+t},e.NextPowerOfTwo=function(t){return void 0===t&&(t=0),t|=2147483647&t>>1,t|=1073741823&t>>2,t|=268435455&t>>4,t|=16777215&t>>8,t|=65535&t>>16,t+1},e.IsPowerOfTwo=function(t){void 0===t&&(t=0);var i=t>0&&0==(t&t-1);return i},o.postDefs.push(function(){o.Common.Math.b2Math.b2Vec2_zero=new r(0,0),o.Common.Math.b2Math.b2Mat22_identity=t.FromVV(new r(1,0),new r(0,1)),o.Common.Math.b2Math.b2Transform_identity=new s(e.b2Vec2_zero,e.b2Mat22_identity)}),n.b2Sweep=function(){this.localCenter=new r,this.c0=new r,this.c=new r},n.prototype.Set=function(t){this.localCenter.SetV(t.localCenter),this.c0.SetV(t.c0),this.c.SetV(t.c),this.a0=t.a0,this.a=t.a,this.t0=t.t0},n.prototype.Copy=function(){var t=new n;return t.localCenter.SetV(this.localCenter),t.c0.SetV(this.c0),t.c.SetV(this.c),t.a0=this.a0,t.a=this.a,t.t0=this.t0,t},n.prototype.GetTransform=function(t,i){void 0===i&&(i=0),t.position.x=(1-i)*this.c0.x+i*this.c.x,t.position.y=(1-i)*this.c0.y+i*this.c.y;var e=(1-i)*this.a0+i*this.a;t.R.Set(e);var o=t.R;t.position.x-=o.col1.x*this.localCenter.x+o.col2.x*this.localCenter.y,t.position.y-=o.col1.y*this.localCenter.x+o.col2.y*this.localCenter.y},n.prototype.Advance=function(t){if(void 0===t&&(t=0),t>this.t0&&1-this.t0>Number.MIN_VALUE){var i=(t-this.t0)/(1-this.t0);this.c0.x=(1-i)*this.c0.x+i*this.c.x,this.c0.y=(1-i)*this.c0.y+i*this.c.y,this.a0=(1-i)*this.a0+i*this.a,this.t0=t}},s.b2Transform=function(){this.position=new r,this.R=new t},s.prototype.b2Transform=function(t,i){void 0===t&&(t=null),void 0===i&&(i=null),t&&(this.position.SetV(t),this.R.SetM(i))},s.prototype.Initialize=function(t,i){this.position.SetV(t),this.R.SetM(i)},s.prototype.SetIdentity=function(){this.position.SetZero(),this.R.SetIdentity()},s.prototype.Set=function(t){this.position.SetV(t.position),this.R.SetM(t.R)},s.prototype.GetAngle=function(){return Math.atan2(this.R.col1.y,this.R.col1.x)},r.b2Vec2=function(){},r.prototype.b2Vec2=function(t,i){void 0===t&&(t=0),void 0===i&&(i=0),this.x=t,this.y=i},r.prototype.SetZero=function(){this.x=0,this.y=0},r.prototype.Set=function(t,i){void 0===t&&(t=0),void 0===i&&(i=0),this.x=t,this.y=i},r.prototype.SetV=function(t){this.x=t.x,this.y=t.y},r.prototype.GetNegative=function(){return new r(-this.x,-this.y)},r.prototype.NegativeSelf=function(){this.x=-this.x,this.y=-this.y},r.Make=function(t,i){return void 0===t&&(t=0),void 0===i&&(i=0),new r(t,i)},r.prototype.Copy=function(){return new r(this.x,this.y)},r.prototype.Add=function(t){this.x+=t.x,this.y+=t.y},r.prototype.Subtract=function(t){this.x-=t.x,this.y-=t.y},r.prototype.Multiply=function(t){void 0===t&&(t=0),this.x*=t,this.y*=t},r.prototype.MulM=function(t){var i=this.x;this.x=t.col1.x*i+t.col2.x*this.y,this.y=t.col1.y*i+t.col2.y*this.y},r.prototype.MulTM=function(t){var i=e.Dot(this,t.col1);this.y=e.Dot(this,t.col2),this.x=i},r.prototype.CrossVF=function(t){void 0===t&&(t=0);var i=this.x;this.x=t*this.y,this.y=-t*i},r.prototype.CrossFV=function(t){void 0===t&&(t=0);var i=this.x;this.x=-t*this.y,this.y=t*i},r.prototype.MinV=function(t){this.x=this.x<t.x?this.x:t.x,this.y=this.y<t.y?this.y:t.y},r.prototype.MaxV=function(t){this.x=this.x>t.x?this.x:t.x,this.y=this.y>t.y?this.y:t.y},r.prototype.Abs=function(){0>this.x&&(this.x=-this.x),0>this.y&&(this.y=-this.y)},r.prototype.Length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},r.prototype.LengthSquared=function(){return this.x*this.x+this.y*this.y},r.prototype.Normalize=function(){var t=Math.sqrt(this.x*this.x+this.y*this.y);if(Number.MIN_VALUE>t)return 0;var i=1/t;return this.x*=i,this.y*=i,t},r.prototype.IsValid=function(){return e.IsValid(this.x)&&e.IsValid(this.y)},a.b2Vec3=function(){},a.prototype.b2Vec3=function(t,i,e){void 0===t&&(t=0),void 0===i&&(i=0),void 0===e&&(e=0),this.x=t,this.y=i,this.z=e},a.prototype.SetZero=function(){this.x=this.y=this.z=0},a.prototype.Set=function(t,i,e){void 0===t&&(t=0),void 0===i&&(i=0),void 0===e&&(e=0),this.x=t,this.y=i,this.z=e},a.prototype.SetV=function(t){this.x=t.x,this.y=t.y,this.z=t.z},a.prototype.GetNegative=function(){return new a(-this.x,-this.y,-this.z)},a.prototype.NegativeSelf=function(){this.x=-this.x,this.y=-this.y,this.z=-this.z},a.prototype.Copy=function(){return new a(this.x,this.y,this.z)},a.prototype.Add=function(t){this.x+=t.x,this.y+=t.y,this.z+=t.z},a.prototype.Subtract=function(t){this.x-=t.x,this.y-=t.y,this.z-=t.z},a.prototype.Multiply=function(t){void 0===t&&(t=0),this.x*=t,this.y*=t,this.z*=t}}(),function(){var t=(o.Dynamics.Controllers.b2ControllerEdge,o.Common.Math.b2Mat22,o.Common.Math.b2Mat33,o.Common.Math.b2Math),i=o.Common.Math.b2Sweep,e=o.Common.Math.b2Transform,r=o.Common.Math.b2Vec2,a=(o.Common.Math.b2Vec3,o.Common.b2Color),m=(o.Common.b2internal,o.Common.b2Settings),l=o.Collision.b2AABB,c=(o.Collision.b2Bound,o.Collision.b2BoundValues,o.Collision.b2Collision,o.Collision.b2ContactID,o.Collision.b2ContactPoint),h=(o.Collision.b2Distance,o.Collision.b2DistanceInput,o.Collision.b2DistanceOutput,o.Collision.b2DistanceProxy,o.Collision.b2DynamicTree,o.Collision.b2DynamicTreeBroadPhase),_=(o.Collision.b2DynamicTreeNode,o.Collision.b2DynamicTreePair,o.Collision.b2Manifold,o.Collision.b2ManifoldPoint,o.Collision.b2Point,o.Collision.b2RayCastInput),p=o.Collision.b2RayCastOutput,y=(o.Collision.b2Segment,o.Collision.b2SeparationFunction,o.Collision.b2Simplex,o.Collision.b2SimplexCache,o.Collision.b2SimplexVertex,o.Collision.b2TimeOfImpact,o.Collision.b2TOIInput,o.Collision.b2WorldManifold,o.Collision.ClipVertex,o.Collision.Features,o.Collision.IBroadPhase,o.Collision.Shapes.b2CircleShape),u=(o.Collision.Shapes.b2EdgeChainDef,o.Collision.Shapes.b2EdgeShape),x=o.Collision.Shapes.b2MassData,f=o.Collision.Shapes.b2PolygonShape,d=o.Collision.Shapes.b2Shape,b=o.Dynamics.b2Body,v=o.Dynamics.b2BodyDef,C=o.Dynamics.b2ContactFilter,g=o.Dynamics.b2ContactImpulse,w=o.Dynamics.b2ContactListener,A=o.Dynamics.b2ContactManager,S=o.Dynamics.b2DebugDraw,D=o.Dynamics.b2DestructionListener,B=o.Dynamics.b2FilterData,M=o.Dynamics.b2Fixture,V=o.Dynamics.b2FixtureDef,I=o.Dynamics.b2Island,G=o.Dynamics.b2TimeStep,L=o.Dynamics.b2World,J=(o.Dynamics.Contacts.b2CircleContact,o.Dynamics.Contacts.b2Contact),F=(o.Dynamics.Contacts.b2ContactConstraint,o.Dynamics.Contacts.b2ContactConstraintPoint,o.Dynamics.Contacts.b2ContactEdge,o.Dynamics.Contacts.b2ContactFactory),P=(o.Dynamics.Contacts.b2ContactRegister,o.Dynamics.Contacts.b2ContactResult,o.Dynamics.Contacts.b2ContactSolver),T=(o.Dynamics.Contacts.b2EdgeAndCircleContact,o.Dynamics.Contacts.b2NullContact,o.Dynamics.Contacts.b2PolyAndCircleContact,o.Dynamics.Contacts.b2PolyAndEdgeContact,o.Dynamics.Contacts.b2PolygonContact,o.Dynamics.Contacts.b2PositionSolverManifold,o.Dynamics.Controllers.b2Controller,o.Dynamics.Joints.b2DistanceJoint,o.Dynamics.Joints.b2DistanceJointDef,o.Dynamics.Joints.b2FrictionJoint,o.Dynamics.Joints.b2FrictionJointDef,o.Dynamics.Joints.b2GearJoint,o.Dynamics.Joints.b2GearJointDef,o.Dynamics.Joints.b2Jacobian,o.Dynamics.Joints.b2Joint),R=(o.Dynamics.Joints.b2JointDef,o.Dynamics.Joints.b2JointEdge,o.Dynamics.Joints.b2LineJoint,o.Dynamics.Joints.b2LineJointDef,o.Dynamics.Joints.b2MouseJoint,o.Dynamics.Joints.b2MouseJointDef,o.Dynamics.Joints.b2PrismaticJoint,o.Dynamics.Joints.b2PrismaticJointDef,o.Dynamics.Joints.b2PulleyJoint);o.Dynamics.Joints.b2PulleyJointDef,o.Dynamics.Joints.b2RevoluteJoint,o.Dynamics.Joints.b2RevoluteJointDef,o.Dynamics.Joints.b2WeldJoint,o.Dynamics.Joints.b2WeldJointDef,b.b2Body=function(){this.m_xf=new e,this.m_sweep=new i,this.m_linearVelocity=new r,this.m_force=new r},b.prototype.connectEdges=function(i,e,o){void 0===o&&(o=0);var n=Math.atan2(e.GetDirectionVector().y,e.GetDirectionVector().x),s=Math.tan(.5*(n-o)),r=t.MulFV(s,e.GetDirectionVector());r=t.SubtractVV(r,e.GetNormalVector()),r=t.MulFV(m.b2_toiSlop,r),r=t.AddVV(r,e.GetVertex1());var a=t.AddVV(i.GetDirectionVector(),e.GetDirectionVector());a.Normalize();var l=t.Dot(i.GetDirectionVector(),e.GetNormalVector())>0;return i.SetNextEdge(e,r,a,l),e.SetPrevEdge(i,r,a,l),n},b.prototype.CreateFixture=function(t){if(1==this.m_world.IsLocked())return null;var i=new M;if(i.Create(this,this.m_xf,t),this.m_flags&b.e_activeFlag){var e=this.m_world.m_contactManager.m_broadPhase;i.CreateProxy(e,this.m_xf)}return i.m_next=this.m_fixtureList,this.m_fixtureList=i,++this.m_fixtureCount,i.m_body=this,i.m_density>0&&this.ResetMassData(),this.m_world.m_flags|=L.e_newFixture,i},b.prototype.CreateFixture2=function(t,i){void 0===i&&(i=0);var e=new V;return e.shape=t,e.density=i,this.CreateFixture(e)},b.prototype.DestroyFixture=function(t){if(1!=this.m_world.IsLocked()){for(var i=this.m_fixtureList,e=null,o=!1;null!=i;){if(i==t){e?e.m_next=t.m_next:this.m_fixtureList=t.m_next,o=!0;break}e=i,i=i.m_next}for(var n=this.m_contactList;n;){var s=n.contact;n=n.next;var r=s.GetFixtureA(),a=s.GetFixtureB();(t==r||t==a)&&this.m_world.m_contactManager.Destroy(s)}if(this.m_flags&b.e_activeFlag){var m=this.m_world.m_contactManager.m_broadPhase;t.DestroyProxy(m)}t.Destroy(),t.m_body=null,t.m_next=null,--this.m_fixtureCount,this.ResetMassData()}},b.prototype.SetPositionAndAngle=function(t,i){void 0===i&&(i=0);var e;if(1!=this.m_world.IsLocked()){this.m_xf.R.Set(i),this.m_xf.position.SetV(t);var o=this.m_xf.R,n=this.m_sweep.localCenter;this.m_sweep.c.x=o.col1.x*n.x+o.col2.x*n.y,this.m_sweep.c.y=o.col1.y*n.x+o.col2.y*n.y,this.m_sweep.c.x+=this.m_xf.position.x,this.m_sweep.c.y+=this.m_xf.position.y,this.m_sweep.c0.SetV(this.m_sweep.c),this.m_sweep.a0=this.m_sweep.a=i;var s=this.m_world.m_contactManager.m_broadPhase;for(e=this.m_fixtureList;e;e=e.m_next)e.Synchronize(s,this.m_xf,this.m_xf);this.m_world.m_contactManager.FindNewContacts()}},b.prototype.SetTransform=function(t){this.SetPositionAndAngle(t.position,t.GetAngle())},b.prototype.GetTransform=function(){return this.m_xf},b.prototype.GetPosition=function(){return this.m_xf.position},b.prototype.SetPosition=function(t){this.SetPositionAndAngle(t,this.GetAngle())},b.prototype.GetAngle=function(){return this.m_sweep.a},b.prototype.SetAngle=function(t){void 0===t&&(t=0),this.SetPositionAndAngle(this.GetPosition(),t)},b.prototype.GetWorldCenter=function(){return this.m_sweep.c},b.prototype.GetLocalCenter=function(){return this.m_sweep.localCenter},b.prototype.SetLinearVelocity=function(t){this.m_type!=b.b2_staticBody&&this.m_linearVelocity.SetV(t)},b.prototype.GetLinearVelocity=function(){return this.m_linearVelocity},b.prototype.SetAngularVelocity=function(t){void 0===t&&(t=0),this.m_type!=b.b2_staticBody&&(this.m_angularVelocity=t)},b.prototype.GetAngularVelocity=function(){return this.m_angularVelocity},b.prototype.GetDefinition=function(){var t=new v;return t.type=this.GetType(),t.allowSleep=(this.m_flags&b.e_allowSleepFlag)==b.e_allowSleepFlag,t.angle=this.GetAngle(),t.angularDamping=this.m_angularDamping,t.angularVelocity=this.m_angularVelocity,t.fixedRotation=(this.m_flags&b.e_fixedRotationFlag)==b.e_fixedRotationFlag,t.bullet=(this.m_flags&b.e_bulletFlag)==b.e_bulletFlag,t.awake=(this.m_flags&b.e_awakeFlag)==b.e_awakeFlag,t.linearDamping=this.m_linearDamping,t.linearVelocity.SetV(this.GetLinearVelocity()),t.position=this.GetPosition(),t.userData=this.GetUserData(),t},b.prototype.ApplyForce=function(t,i){this.m_type==b.b2_dynamicBody&&(0==this.IsAwake()&&this.SetAwake(!0),this.m_force.x+=t.x,this.m_force.y+=t.y,this.m_torque+=(i.x-this.m_sweep.c.x)*t.y-(i.y-this.m_sweep.c.y)*t.x)},b.prototype.ApplyTorque=function(t){void 0===t&&(t=0),this.m_type==b.b2_dynamicBody&&(0==this.IsAwake()&&this.SetAwake(!0),this.m_torque+=t)},b.prototype.ApplyImpulse=function(t,i){this.m_type==b.b2_dynamicBody&&(0==this.IsAwake()&&this.SetAwake(!0),this.m_linearVelocity.x+=this.m_invMass*t.x,this.m_linearVelocity.y+=this.m_invMass*t.y,this.m_angularVelocity+=this.m_invI*((i.x-this.m_sweep.c.x)*t.y-(i.y-this.m_sweep.c.y)*t.x))},b.prototype.Split=function(i){for(var e,o=this.GetLinearVelocity().Copy(),n=this.GetAngularVelocity(),s=this.GetWorldCenter(),r=this,a=this.m_world.CreateBody(this.GetDefinition()),m=r.m_fixtureList;m;)if(i(m)){var l=m.m_next;e?e.m_next=l:r.m_fixtureList=l,r.m_fixtureCount--,m.m_next=a.m_fixtureList,a.m_fixtureList=m,a.m_fixtureCount++,m.m_body=a,m=l}else e=m,m=m.m_next;r.ResetMassData(),a.ResetMassData();var c=r.GetWorldCenter(),h=a.GetWorldCenter(),_=t.AddVV(o,t.CrossFV(n,t.SubtractVV(c,s))),p=t.AddVV(o,t.CrossFV(n,t.SubtractVV(h,s)));return r.SetLinearVelocity(_),a.SetLinearVelocity(p),r.SetAngularVelocity(n),a.SetAngularVelocity(n),r.SynchronizeFixtures(),a.SynchronizeFixtures(),a},b.prototype.Merge=function(t){var i;for(i=t.m_fixtureList;i;){var e=i.m_next;t.m_fixtureCount--,i.m_next=this.m_fixtureList,this.m_fixtureList=i,this.m_fixtureCount++,i.m_body=n,i=e}o.m_fixtureCount=0;var o=this,n=t;o.GetWorldCenter(),n.GetWorldCenter(),o.GetLinearVelocity().Copy(),n.GetLinearVelocity().Copy(),o.GetAngularVelocity(),n.GetAngularVelocity(),o.ResetMassData(),this.SynchronizeFixtures()},b.prototype.GetMass=function(){return this.m_mass},b.prototype.GetInertia=function(){return this.m_I},b.prototype.GetMassData=function(t){t.mass=this.m_mass,t.I=this.m_I,t.center.SetV(this.m_sweep.localCenter)},b.prototype.SetMassData=function(i){if(m.b2Assert(0==this.m_world.IsLocked()),1!=this.m_world.IsLocked()&&this.m_type==b.b2_dynamicBody){this.m_invMass=0,this.m_I=0,this.m_invI=0,this.m_mass=i.mass,0>=this.m_mass&&(this.m_mass=1),this.m_invMass=1/this.m_mass,i.I>0&&0==(this.m_flags&b.e_fixedRotationFlag)&&(this.m_I=i.I-this.m_mass*(i.center.x*i.center.x+i.center.y*i.center.y),this.m_invI=1/this.m_I);var e=this.m_sweep.c.Copy();this.m_sweep.localCenter.SetV(i.center),this.m_sweep.c0.SetV(t.MulX(this.m_xf,this.m_sweep.localCenter)),this.m_sweep.c.SetV(this.m_sweep.c0),this.m_linearVelocity.x+=this.m_angularVelocity*-(this.m_sweep.c.y-e.y),this.m_linearVelocity.y+=this.m_angularVelocity*+(this.m_sweep.c.x-e.x)}},b.prototype.ResetMassData=function(){if(this.m_mass=0,this.m_invMass=0,this.m_I=0,this.m_invI=0,this.m_sweep.localCenter.SetZero(),this.m_type!=b.b2_staticBody&&this.m_type!=b.b2_kinematicBody){for(var i=r.Make(0,0),e=this.m_fixtureList;e;e=e.m_next)if(0!=e.m_density){var o=e.GetMassData();this.m_mass+=o.mass,i.x+=o.center.x*o.mass,i.y+=o.center.y*o.mass,this.m_I+=o.I}this.m_mass>0?(this.m_invMass=1/this.m_mass,i.x*=this.m_invMass,i.y*=this.m_invMass):(this.m_mass=1,this.m_invMass=1),this.m_I>0&&0==(this.m_flags&b.e_fixedRotationFlag)?(this.m_I-=this.m_mass*(i.x*i.x+i.y*i.y),this.m_I*=this.m_inertiaScale,m.b2Assert(this.m_I>0),this.m_invI=1/this.m_I):(this.m_I=0,this.m_invI=0);var n=this.m_sweep.c.Copy();this.m_sweep.localCenter.SetV(i),this.m_sweep.c0.SetV(t.MulX(this.m_xf,this.m_sweep.localCenter)),this.m_sweep.c.SetV(this.m_sweep.c0),this.m_linearVelocity.x+=this.m_angularVelocity*-(this.m_sweep.c.y-n.y),this.m_linearVelocity.y+=this.m_angularVelocity*+(this.m_sweep.c.x-n.x)}},b.prototype.GetWorldPoint=function(t){var i=this.m_xf.R,e=new r(i.col1.x*t.x+i.col2.x*t.y,i.col1.y*t.x+i.col2.y*t.y);return e.x+=this.m_xf.position.x,e.y+=this.m_xf.position.y,e},b.prototype.GetWorldVector=function(i){return t.MulMV(this.m_xf.R,i)},b.prototype.GetLocalPoint=function(i){return t.MulXT(this.m_xf,i)},b.prototype.GetLocalVector=function(i){return t.MulTMV(this.m_xf.R,i)},b.prototype.GetLinearVelocityFromWorldPoint=function(t){return new r(this.m_linearVelocity.x-this.m_angularVelocity*(t.y-this.m_sweep.c.y),this.m_linearVelocity.y+this.m_angularVelocity*(t.x-this.m_sweep.c.x))},b.prototype.GetLinearVelocityFromLocalPoint=function(t){var i=this.m_xf.R,e=new r(i.col1.x*t.x+i.col2.x*t.y,i.col1.y*t.x+i.col2.y*t.y);return e.x+=this.m_xf.position.x,e.y+=this.m_xf.position.y,new r(this.m_linearVelocity.x-this.m_angularVelocity*(e.y-this.m_sweep.c.y),this.m_linearVelocity.y+this.m_angularVelocity*(e.x-this.m_sweep.c.x))},b.prototype.GetLinearDamping=function(){return this.m_linearDamping},b.prototype.SetLinearDamping=function(t){void 0===t&&(t=0),this.m_linearDamping=t},b.prototype.GetAngularDamping=function(){return this.m_angularDamping},b.prototype.SetAngularDamping=function(t){void 0===t&&(t=0),this.m_angularDamping=t},b.prototype.SetType=function(t){if(void 0===t&&(t=0),this.m_type!=t){this.m_type=t,this.ResetMassData(),this.m_type==b.b2_staticBody&&(this.m_linearVelocity.SetZero(),this.m_angularVelocity=0),this.SetAwake(!0),this.m_force.SetZero(),this.m_torque=0;for(var i=this.m_contactList;i;i=i.next)i.contact.FlagForFiltering()}},b.prototype.GetType=function(){return this.m_type},b.prototype.SetBullet=function(t){t?this.m_flags|=b.e_bulletFlag:this.m_flags&=~b.e_bulletFlag},b.prototype.IsBullet=function(){return(this.m_flags&b.e_bulletFlag)==b.e_bulletFlag},b.prototype.SetSleepingAllowed=function(t){t?this.m_flags|=b.e_allowSleepFlag:(this.m_flags&=~b.e_allowSleepFlag,this.SetAwake(!0))},b.prototype.SetAwake=function(t){t?(this.m_flags|=b.e_awakeFlag,this.m_sleepTime=0):(this.m_flags&=~b.e_awakeFlag,this.m_sleepTime=0,this.m_linearVelocity.SetZero(),this.m_angularVelocity=0,this.m_force.SetZero(),this.m_torque=0)},b.prototype.IsAwake=function(){return(this.m_flags&b.e_awakeFlag)==b.e_awakeFlag},b.prototype.SetFixedRotation=function(t){t?this.m_flags|=b.e_fixedRotationFlag:this.m_flags&=~b.e_fixedRotationFlag,this.ResetMassData()},b.prototype.IsFixedRotation=function(){return(this.m_flags&b.e_fixedRotationFlag)==b.e_fixedRotationFlag},b.prototype.SetActive=function(t){if(t!=this.IsActive()){var i,e;if(t)for(this.m_flags|=b.e_activeFlag,i=this.m_world.m_contactManager.m_broadPhase,e=this.m_fixtureList;e;e=e.m_next)e.CreateProxy(i,this.m_xf);else{for(this.m_flags&=~b.e_activeFlag,i=this.m_world.m_contactManager.m_broadPhase,e=this.m_fixtureList;e;e=e.m_next)e.DestroyProxy(i);for(var o=this.m_contactList;o;){var n=o;o=o.next,this.m_world.m_contactManager.Destroy(n.contact)}this.m_contactList=null}}},b.prototype.IsActive=function(){return(this.m_flags&b.e_activeFlag)==b.e_activeFlag},b.prototype.IsSleepingAllowed=function(){return(this.m_flags&b.e_allowSleepFlag)==b.e_allowSleepFlag},b.prototype.GetFixtureList=function(){return this.m_fixtureList},b.prototype.GetJointList=function(){return this.m_jointList},b.prototype.GetControllerList=function(){return this.m_controllerList},b.prototype.GetContactList=function(){return this.m_contactList},b.prototype.GetNext=function(){return this.m_next},b.prototype.GetUserData=function(){return this.m_userData},b.prototype.SetUserData=function(t){this.m_userData=t},b.prototype.GetWorld=function(){return this.m_world},b.prototype.b2Body=function(t,i){this.m_flags=0,t.bullet&&(this.m_flags|=b.e_bulletFlag),t.fixedRotation&&(this.m_flags|=b.e_fixedRotationFlag),t.allowSleep&&(this.m_flags|=b.e_allowSleepFlag),t.awake&&(this.m_flags|=b.e_awakeFlag),t.active&&(this.m_flags|=b.e_activeFlag),this.m_world=i,this.m_xf.position.SetV(t.position),this.m_xf.R.Set(t.angle),this.m_sweep.localCenter.SetZero(),this.m_sweep.t0=1,this.m_sweep.a0=this.m_sweep.a=t.angle;var e=this.m_xf.R,o=this.m_sweep.localCenter;this.m_sweep.c.x=e.col1.x*o.x+e.col2.x*o.y,this.m_sweep.c.y=e.col1.y*o.x+e.col2.y*o.y,this.m_sweep.c.x+=this.m_xf.position.x,this.m_sweep.c.y+=this.m_xf.position.y,this.m_sweep.c0.SetV(this.m_sweep.c),this.m_jointList=null,this.m_controllerList=null,this.m_contactList=null,this.m_controllerCount=0,this.m_prev=null,this.m_next=null,this.m_linearVelocity.SetV(t.linearVelocity),this.m_angularVelocity=t.angularVelocity,this.m_linearDamping=t.linearDamping,this.m_angularDamping=t.angularDamping,this.m_force.Set(0,0),this.m_torque=0,this.m_sleepTime=0,this.m_type=t.type,this.m_type==b.b2_dynamicBody?(this.m_mass=1,this.m_invMass=1):(this.m_mass=0,this.m_invMass=0),this.m_I=0,this.m_invI=0,this.m_inertiaScale=t.inertiaScale,this.m_userData=t.userData,this.m_fixtureList=null,this.m_fixtureCount=0
},b.prototype.SynchronizeFixtures=function(){var t=b.s_xf1;t.R.Set(this.m_sweep.a0);var i=t.R,e=this.m_sweep.localCenter;t.position.x=this.m_sweep.c0.x-(i.col1.x*e.x+i.col2.x*e.y),t.position.y=this.m_sweep.c0.y-(i.col1.y*e.x+i.col2.y*e.y);var o,n=this.m_world.m_contactManager.m_broadPhase;for(o=this.m_fixtureList;o;o=o.m_next)o.Synchronize(n,t,this.m_xf)},b.prototype.SynchronizeTransform=function(){this.m_xf.R.Set(this.m_sweep.a);var t=this.m_xf.R,i=this.m_sweep.localCenter;this.m_xf.position.x=this.m_sweep.c.x-(t.col1.x*i.x+t.col2.x*i.y),this.m_xf.position.y=this.m_sweep.c.y-(t.col1.y*i.x+t.col2.y*i.y)},b.prototype.ShouldCollide=function(t){if(this.m_type!=b.b2_dynamicBody&&t.m_type!=b.b2_dynamicBody)return!1;for(var i=this.m_jointList;i;i=i.next)if(i.other==t&&0==i.joint.m_collideConnected)return!1;return!0},b.prototype.Advance=function(t){void 0===t&&(t=0),this.m_sweep.Advance(t),this.m_sweep.c.SetV(this.m_sweep.c0),this.m_sweep.a=this.m_sweep.a0,this.SynchronizeTransform()},o.postDefs.push(function(){o.Dynamics.b2Body.s_xf1=new e,o.Dynamics.b2Body.e_islandFlag=1,o.Dynamics.b2Body.e_awakeFlag=2,o.Dynamics.b2Body.e_allowSleepFlag=4,o.Dynamics.b2Body.e_bulletFlag=8,o.Dynamics.b2Body.e_fixedRotationFlag=16,o.Dynamics.b2Body.e_activeFlag=32,o.Dynamics.b2Body.b2_staticBody=0,o.Dynamics.b2Body.b2_kinematicBody=1,o.Dynamics.b2Body.b2_dynamicBody=2}),v.b2BodyDef=function(){this.position=new r,this.linearVelocity=new r},v.prototype.b2BodyDef=function(){this.userData=null,this.position.Set(0,0),this.angle=0,this.linearVelocity.Set(0,0),this.angularVelocity=0,this.linearDamping=0,this.angularDamping=0,this.allowSleep=!0,this.awake=!0,this.fixedRotation=!1,this.bullet=!1,this.type=b.b2_staticBody,this.active=!0,this.inertiaScale=1},C.b2ContactFilter=function(){},C.prototype.ShouldCollide=function(t,i){var e=t.GetFilterData(),o=i.GetFilterData();if(e.groupIndex==o.groupIndex&&0!=e.groupIndex)return e.groupIndex>0;var n=0!=(e.maskBits&o.categoryBits)&&0!=(e.categoryBits&o.maskBits);return n},C.prototype.RayCollide=function(t,i){return t?this.ShouldCollide(t instanceof M?t:null,i):!0},o.postDefs.push(function(){o.Dynamics.b2ContactFilter.b2_defaultFilter=new C}),g.b2ContactImpulse=function(){this.normalImpulses=new s(m.b2_maxManifoldPoints),this.tangentImpulses=new s(m.b2_maxManifoldPoints)},w.b2ContactListener=function(){},w.prototype.BeginContact=function(){},w.prototype.EndContact=function(){},w.prototype.PreSolve=function(){},w.prototype.PostSolve=function(){},o.postDefs.push(function(){o.Dynamics.b2ContactListener.b2_defaultListener=new w}),A.b2ContactManager=function(){},A.prototype.b2ContactManager=function(){this.m_world=null,this.m_contactCount=0,this.m_contactFilter=C.b2_defaultFilter,this.m_contactListener=w.b2_defaultListener,this.m_contactFactory=new F(this.m_allocator),this.m_broadPhase=new h},A.prototype.AddPair=function(t,i){var e=t instanceof M?t:null,o=i instanceof M?i:null,n=e.GetBody(),s=o.GetBody();if(n!=s){for(var r=s.GetContactList();r;){if(r.other==n){var a=r.contact.GetFixtureA(),m=r.contact.GetFixtureB();if(a==e&&m==o)return;if(a==o&&m==e)return}r=r.next}if(0!=s.ShouldCollide(n)&&0!=this.m_contactFilter.ShouldCollide(e,o)){var l=this.m_contactFactory.Create(e,o);e=l.GetFixtureA(),o=l.GetFixtureB(),n=e.m_body,s=o.m_body,l.m_prev=null,l.m_next=this.m_world.m_contactList,null!=this.m_world.m_contactList&&(this.m_world.m_contactList.m_prev=l),this.m_world.m_contactList=l,l.m_nodeA.contact=l,l.m_nodeA.other=s,l.m_nodeA.prev=null,l.m_nodeA.next=n.m_contactList,null!=n.m_contactList&&(n.m_contactList.prev=l.m_nodeA),n.m_contactList=l.m_nodeA,l.m_nodeB.contact=l,l.m_nodeB.other=n,l.m_nodeB.prev=null,l.m_nodeB.next=s.m_contactList,null!=s.m_contactList&&(s.m_contactList.prev=l.m_nodeB),s.m_contactList=l.m_nodeB,++this.m_world.m_contactCount}}},A.prototype.FindNewContacts=function(){this.m_broadPhase.UpdatePairs(o.generateCallback(this,this.AddPair))},A.prototype.Destroy=function(t){var i=t.GetFixtureA(),e=t.GetFixtureB(),o=i.GetBody(),n=e.GetBody();t.IsTouching()&&this.m_contactListener.EndContact(t),t.m_prev&&(t.m_prev.m_next=t.m_next),t.m_next&&(t.m_next.m_prev=t.m_prev),t==this.m_world.m_contactList&&(this.m_world.m_contactList=t.m_next),t.m_nodeA.prev&&(t.m_nodeA.prev.next=t.m_nodeA.next),t.m_nodeA.next&&(t.m_nodeA.next.prev=t.m_nodeA.prev),t.m_nodeA==o.m_contactList&&(o.m_contactList=t.m_nodeA.next),t.m_nodeB.prev&&(t.m_nodeB.prev.next=t.m_nodeB.next),t.m_nodeB.next&&(t.m_nodeB.next.prev=t.m_nodeB.prev),t.m_nodeB==n.m_contactList&&(n.m_contactList=t.m_nodeB.next),this.m_contactFactory.Destroy(t),--this.m_contactCount},A.prototype.Collide=function(){for(var t=this.m_world.m_contactList;t;){var i=t.GetFixtureA(),e=t.GetFixtureB(),o=i.GetBody(),n=e.GetBody();if(0!=o.IsAwake()||0!=n.IsAwake()){if(t.m_flags&J.e_filterFlag){if(0==n.ShouldCollide(o)){var s=t;t=s.GetNext(),this.Destroy(s);continue}if(0==this.m_contactFilter.ShouldCollide(i,e)){s=t,t=s.GetNext(),this.Destroy(s);continue}t.m_flags&=~J.e_filterFlag}var r=i.m_proxy,a=e.m_proxy,m=this.m_broadPhase.TestOverlap(r,a);0!=m?(t.Update(this.m_contactListener),t=t.GetNext()):(s=t,t=s.GetNext(),this.Destroy(s))}else t=t.GetNext()}},o.postDefs.push(function(){o.Dynamics.b2ContactManager.s_evalCP=new c}),S.b2DebugDraw=function(){},S.prototype.b2DebugDraw=function(){},S.prototype.SetFlags=function(t){void 0===t&&(t=0)},S.prototype.GetFlags=function(){},S.prototype.AppendFlags=function(t){void 0===t&&(t=0)},S.prototype.ClearFlags=function(t){void 0===t&&(t=0)},S.prototype.SetSprite=function(){},S.prototype.GetSprite=function(){},S.prototype.SetDrawScale=function(t){void 0===t&&(t=0)},S.prototype.GetDrawScale=function(){},S.prototype.SetLineThickness=function(t){void 0===t&&(t=0)},S.prototype.GetLineThickness=function(){},S.prototype.SetAlpha=function(t){void 0===t&&(t=0)},S.prototype.GetAlpha=function(){},S.prototype.SetFillAlpha=function(t){void 0===t&&(t=0)},S.prototype.GetFillAlpha=function(){},S.prototype.SetXFormScale=function(t){void 0===t&&(t=0)},S.prototype.GetXFormScale=function(){},S.prototype.DrawPolygon=function(t,i){void 0===i&&(i=0)},S.prototype.DrawSolidPolygon=function(t,i){void 0===i&&(i=0)},S.prototype.DrawCircle=function(t,i){void 0===i&&(i=0)},S.prototype.DrawSolidCircle=function(t,i){void 0===i&&(i=0)},S.prototype.DrawSegment=function(){},S.prototype.DrawTransform=function(){},o.postDefs.push(function(){o.Dynamics.b2DebugDraw.e_shapeBit=1,o.Dynamics.b2DebugDraw.e_jointBit=2,o.Dynamics.b2DebugDraw.e_aabbBit=4,o.Dynamics.b2DebugDraw.e_pairBit=8,o.Dynamics.b2DebugDraw.e_centerOfMassBit=16,o.Dynamics.b2DebugDraw.e_controllerBit=32}),D.b2DestructionListener=function(){},D.prototype.SayGoodbyeJoint=function(){},D.prototype.SayGoodbyeFixture=function(){},B.b2FilterData=function(){this.categoryBits=1,this.maskBits=65535,this.groupIndex=0},B.prototype.Copy=function(){var t=new B;return t.categoryBits=this.categoryBits,t.maskBits=this.maskBits,t.groupIndex=this.groupIndex,t},M.b2Fixture=function(){this.m_filter=new B},M.prototype.GetType=function(){return this.m_shape.GetType()},M.prototype.GetShape=function(){return this.m_shape},M.prototype.SetSensor=function(t){if(this.m_isSensor!=t&&(this.m_isSensor=t,null!=this.m_body))for(var i=this.m_body.GetContactList();i;){var e=i.contact,o=e.GetFixtureA(),n=e.GetFixtureB();(o==this||n==this)&&e.SetSensor(o.IsSensor()||n.IsSensor()),i=i.next}},M.prototype.IsSensor=function(){return this.m_isSensor},M.prototype.SetFilterData=function(t){if(this.m_filter=t.Copy(),!this.m_body)for(var i=this.m_body.GetContactList();i;){var e=i.contact,o=e.GetFixtureA(),n=e.GetFixtureB();(o==this||n==this)&&e.FlagForFiltering(),i=i.next}},M.prototype.GetFilterData=function(){return this.m_filter.Copy()},M.prototype.GetBody=function(){return this.m_body},M.prototype.GetNext=function(){return this.m_next},M.prototype.GetUserData=function(){return this.m_userData},M.prototype.SetUserData=function(t){this.m_userData=t},M.prototype.TestPoint=function(t){return this.m_shape.TestPoint(this.m_body.GetTransform(),t)},M.prototype.RayCast=function(t,i){return this.m_shape.RayCast(t,i,this.m_body.GetTransform())},M.prototype.GetMassData=function(t){return void 0===t&&(t=null),null==t&&(t=new x),this.m_shape.ComputeMass(t,this.m_density),t},M.prototype.SetDensity=function(t){void 0===t&&(t=0),this.m_density=t},M.prototype.GetDensity=function(){return this.m_density},M.prototype.GetFriction=function(){return this.m_friction},M.prototype.SetFriction=function(t){void 0===t&&(t=0),this.m_friction=t},M.prototype.GetRestitution=function(){return this.m_restitution},M.prototype.SetRestitution=function(t){void 0===t&&(t=0),this.m_restitution=t},M.prototype.GetAABB=function(){return this.m_aabb},M.prototype.b2Fixture=function(){this.m_aabb=new l,this.m_userData=null,this.m_body=null,this.m_next=null,this.m_shape=null,this.m_density=0,this.m_friction=0,this.m_restitution=0},M.prototype.Create=function(t,i,e){this.m_userData=e.userData,this.m_friction=e.friction,this.m_restitution=e.restitution,this.m_body=t,this.m_next=null,this.m_filter=e.filter.Copy(),this.m_isSensor=e.isSensor,this.m_shape=e.shape.Copy(),this.m_density=e.density},M.prototype.Destroy=function(){this.m_shape=null},M.prototype.CreateProxy=function(t,i){this.m_shape.ComputeAABB(this.m_aabb,i),this.m_proxy=t.CreateProxy(this.m_aabb,this)},M.prototype.DestroyProxy=function(t){null!=this.m_proxy&&(t.DestroyProxy(this.m_proxy),this.m_proxy=null)},M.prototype.Synchronize=function(i,e,o){if(this.m_proxy){var n=new l,s=new l;this.m_shape.ComputeAABB(n,e),this.m_shape.ComputeAABB(s,o),this.m_aabb.Combine(n,s);var r=t.SubtractVV(o.position,e.position);i.MoveProxy(this.m_proxy,this.m_aabb,r)}},V.b2FixtureDef=function(){this.filter=new B},V.prototype.b2FixtureDef=function(){this.shape=null,this.userData=null,this.friction=.2,this.restitution=0,this.density=0,this.filter.categoryBits=1,this.filter.maskBits=65535,this.filter.groupIndex=0,this.isSensor=!1},I.b2Island=function(){},I.prototype.b2Island=function(){this.m_bodies=new n,this.m_contacts=new n,this.m_joints=new n},I.prototype.Initialize=function(t,i,e,o,n,s){void 0===t&&(t=0),void 0===i&&(i=0),void 0===e&&(e=0);var r=0;for(this.m_bodyCapacity=t,this.m_contactCapacity=i,this.m_jointCapacity=e,this.m_bodyCount=0,this.m_contactCount=0,this.m_jointCount=0,this.m_allocator=o,this.m_listener=n,this.m_contactSolver=s,r=this.m_bodies.length;t>r;r++)this.m_bodies[r]=null;for(r=this.m_contacts.length;i>r;r++)this.m_contacts[r]=null;for(r=this.m_joints.length;e>r;r++)this.m_joints[r]=null},I.prototype.Clear=function(){this.m_bodyCount=0,this.m_contactCount=0,this.m_jointCount=0},I.prototype.Solve=function(i,e,o){var n,s,r=0,a=0;for(r=0;this.m_bodyCount>r;++r)n=this.m_bodies[r],n.GetType()==b.b2_dynamicBody&&(n.m_linearVelocity.x+=i.dt*(e.x+n.m_invMass*n.m_force.x),n.m_linearVelocity.y+=i.dt*(e.y+n.m_invMass*n.m_force.y),n.m_angularVelocity+=i.dt*n.m_invI*n.m_torque,n.m_linearVelocity.Multiply(t.Clamp(1-i.dt*n.m_linearDamping,0,1)),n.m_angularVelocity*=t.Clamp(1-i.dt*n.m_angularDamping,0,1));this.m_contactSolver.Initialize(i,this.m_contacts,this.m_contactCount,this.m_allocator);var l=this.m_contactSolver;for(l.InitVelocityConstraints(i),r=0;this.m_jointCount>r;++r)s=this.m_joints[r],s.InitVelocityConstraints(i);for(r=0;i.velocityIterations>r;++r){for(a=0;this.m_jointCount>a;++a)s=this.m_joints[a],s.SolveVelocityConstraints(i);l.SolveVelocityConstraints()}for(r=0;this.m_jointCount>r;++r)s=this.m_joints[r],s.FinalizeVelocityConstraints();for(l.FinalizeVelocityConstraints(),r=0;this.m_bodyCount>r;++r)if(n=this.m_bodies[r],n.GetType()!=b.b2_staticBody){var c=i.dt*n.m_linearVelocity.x,h=i.dt*n.m_linearVelocity.y;c*c+h*h>m.b2_maxTranslationSquared&&(n.m_linearVelocity.Normalize(),n.m_linearVelocity.x*=m.b2_maxTranslation*i.inv_dt,n.m_linearVelocity.y*=m.b2_maxTranslation*i.inv_dt);var _=i.dt*n.m_angularVelocity;_*_>m.b2_maxRotationSquared&&(n.m_angularVelocity=0>n.m_angularVelocity?-m.b2_maxRotation*i.inv_dt:m.b2_maxRotation*i.inv_dt),n.m_sweep.c0.SetV(n.m_sweep.c),n.m_sweep.a0=n.m_sweep.a,n.m_sweep.c.x+=i.dt*n.m_linearVelocity.x,n.m_sweep.c.y+=i.dt*n.m_linearVelocity.y,n.m_sweep.a+=i.dt*n.m_angularVelocity,n.SynchronizeTransform()}for(r=0;i.positionIterations>r;++r){var p=l.SolvePositionConstraints(m.b2_contactBaumgarte),y=!0;for(a=0;this.m_jointCount>a;++a){s=this.m_joints[a];var u=s.SolvePositionConstraints(m.b2_contactBaumgarte);y=y&&u}if(p&&y)break}if(this.Report(l.m_constraints),o){var x=Number.MAX_VALUE,f=m.b2_linearSleepTolerance*m.b2_linearSleepTolerance,d=m.b2_angularSleepTolerance*m.b2_angularSleepTolerance;for(r=0;this.m_bodyCount>r;++r)n=this.m_bodies[r],n.GetType()!=b.b2_staticBody&&(0==(n.m_flags&b.e_allowSleepFlag)&&(n.m_sleepTime=0,x=0),0==(n.m_flags&b.e_allowSleepFlag)||n.m_angularVelocity*n.m_angularVelocity>d||t.Dot(n.m_linearVelocity,n.m_linearVelocity)>f?(n.m_sleepTime=0,x=0):(n.m_sleepTime+=i.dt,x=t.Min(x,n.m_sleepTime)));if(x>=m.b2_timeToSleep)for(r=0;this.m_bodyCount>r;++r)n=this.m_bodies[r],n.SetAwake(!1)}},I.prototype.SolveTOI=function(t){var i=0,e=0;this.m_contactSolver.Initialize(t,this.m_contacts,this.m_contactCount,this.m_allocator);var o=this.m_contactSolver;for(i=0;this.m_jointCount>i;++i)this.m_joints[i].InitVelocityConstraints(t);for(i=0;t.velocityIterations>i;++i)for(o.SolveVelocityConstraints(),e=0;this.m_jointCount>e;++e)this.m_joints[e].SolveVelocityConstraints(t);for(i=0;this.m_bodyCount>i;++i){var n=this.m_bodies[i];if(n.GetType()!=b.b2_staticBody){var s=t.dt*n.m_linearVelocity.x,r=t.dt*n.m_linearVelocity.y;s*s+r*r>m.b2_maxTranslationSquared&&(n.m_linearVelocity.Normalize(),n.m_linearVelocity.x*=m.b2_maxTranslation*t.inv_dt,n.m_linearVelocity.y*=m.b2_maxTranslation*t.inv_dt);var a=t.dt*n.m_angularVelocity;a*a>m.b2_maxRotationSquared&&(n.m_angularVelocity=0>n.m_angularVelocity?-m.b2_maxRotation*t.inv_dt:m.b2_maxRotation*t.inv_dt),n.m_sweep.c0.SetV(n.m_sweep.c),n.m_sweep.a0=n.m_sweep.a,n.m_sweep.c.x+=t.dt*n.m_linearVelocity.x,n.m_sweep.c.y+=t.dt*n.m_linearVelocity.y,n.m_sweep.a+=t.dt*n.m_angularVelocity,n.SynchronizeTransform()}}var l=.75;for(i=0;t.positionIterations>i;++i){var c=o.SolvePositionConstraints(l),h=!0;for(e=0;this.m_jointCount>e;++e){var _=this.m_joints[e].SolvePositionConstraints(m.b2_contactBaumgarte);h=h&&_}if(c&&h)break}this.Report(o.m_constraints)},I.prototype.Report=function(t){if(null!=this.m_listener)for(var i=0;this.m_contactCount>i;++i){for(var e=this.m_contacts[i],o=t[i],n=0;o.pointCount>n;++n)I.s_impulse.normalImpulses[n]=o.points[n].normalImpulse,I.s_impulse.tangentImpulses[n]=o.points[n].tangentImpulse;this.m_listener.PostSolve(e,I.s_impulse)}},I.prototype.AddBody=function(t){t.m_islandIndex=this.m_bodyCount,this.m_bodies[this.m_bodyCount++]=t},I.prototype.AddContact=function(t){this.m_contacts[this.m_contactCount++]=t},I.prototype.AddJoint=function(t){this.m_joints[this.m_jointCount++]=t},o.postDefs.push(function(){o.Dynamics.b2Island.s_impulse=new g}),G.b2TimeStep=function(){},G.prototype.Set=function(t){this.dt=t.dt,this.inv_dt=t.inv_dt,this.positionIterations=t.positionIterations,this.velocityIterations=t.velocityIterations,this.warmStarting=t.warmStarting},L.b2World=function(){this.s_stack=new n,this.m_contactManager=new A,this.m_contactSolver=new P,this.m_island=new I},L.prototype.b2World=function(t,i){this.m_destructionListener=null,this.m_debugDraw=null,this.m_bodyList=null,this.m_contactList=null,this.m_jointList=null,this.m_controllerList=null,this.m_bodyCount=0,this.m_contactCount=0,this.m_jointCount=0,this.m_controllerCount=0,L.m_warmStarting=!0,L.m_continuousPhysics=!0,this.m_allowSleep=i,this.m_gravity=t,this.m_inv_dt0=0,this.m_contactManager.m_world=this;var e=new v;this.m_groundBody=this.CreateBody(e)},L.prototype.SetDestructionListener=function(t){this.m_destructionListener=t},L.prototype.SetContactFilter=function(t){this.m_contactManager.m_contactFilter=t},L.prototype.SetContactListener=function(t){this.m_contactManager.m_contactListener=t},L.prototype.SetDebugDraw=function(t){this.m_debugDraw=t},L.prototype.SetBroadPhase=function(t){var i=this.m_contactManager.m_broadPhase;this.m_contactManager.m_broadPhase=t;for(var e=this.m_bodyList;e;e=e.m_next)for(var o=e.m_fixtureList;o;o=o.m_next)o.m_proxy=t.CreateProxy(i.GetFatAABB(o.m_proxy),o)},L.prototype.Validate=function(){this.m_contactManager.m_broadPhase.Validate()},L.prototype.GetProxyCount=function(){return this.m_contactManager.m_broadPhase.GetProxyCount()},L.prototype.CreateBody=function(t){if(1==this.IsLocked())return null;var i=new b(t,this);return i.m_prev=null,i.m_next=this.m_bodyList,this.m_bodyList&&(this.m_bodyList.m_prev=i),this.m_bodyList=i,++this.m_bodyCount,i},L.prototype.DestroyBody=function(t){if(1!=this.IsLocked()){for(var i=t.m_jointList;i;){var e=i;i=i.next,this.m_destructionListener&&this.m_destructionListener.SayGoodbyeJoint(e.joint),this.DestroyJoint(e.joint)}for(var o=t.m_controllerList;o;){var n=o;o=o.nextController,n.controller.RemoveBody(t)}for(var s=t.m_contactList;s;){var r=s;s=s.next,this.m_contactManager.Destroy(r.contact)}t.m_contactList=null;for(var a=t.m_fixtureList;a;){var m=a;a=a.m_next,this.m_destructionListener&&this.m_destructionListener.SayGoodbyeFixture(m),m.DestroyProxy(this.m_contactManager.m_broadPhase),m.Destroy()}t.m_fixtureList=null,t.m_fixtureCount=0,t.m_prev&&(t.m_prev.m_next=t.m_next),t.m_next&&(t.m_next.m_prev=t.m_prev),t==this.m_bodyList&&(this.m_bodyList=t.m_next),--this.m_bodyCount}},L.prototype.CreateJoint=function(t){var i=T.Create(t,null);i.m_prev=null,i.m_next=this.m_jointList,this.m_jointList&&(this.m_jointList.m_prev=i),this.m_jointList=i,++this.m_jointCount,i.m_edgeA.joint=i,i.m_edgeA.other=i.m_bodyB,i.m_edgeA.prev=null,i.m_edgeA.next=i.m_bodyA.m_jointList,i.m_bodyA.m_jointList&&(i.m_bodyA.m_jointList.prev=i.m_edgeA),i.m_bodyA.m_jointList=i.m_edgeA,i.m_edgeB.joint=i,i.m_edgeB.other=i.m_bodyA,i.m_edgeB.prev=null,i.m_edgeB.next=i.m_bodyB.m_jointList,i.m_bodyB.m_jointList&&(i.m_bodyB.m_jointList.prev=i.m_edgeB),i.m_bodyB.m_jointList=i.m_edgeB;var e=t.bodyA,o=t.bodyB;if(0==t.collideConnected)for(var n=o.GetContactList();n;)n.other==e&&n.contact.FlagForFiltering(),n=n.next;return i},L.prototype.DestroyJoint=function(t){var i=t.m_collideConnected;t.m_prev&&(t.m_prev.m_next=t.m_next),t.m_next&&(t.m_next.m_prev=t.m_prev),t==this.m_jointList&&(this.m_jointList=t.m_next);var e=t.m_bodyA,o=t.m_bodyB;if(e.SetAwake(!0),o.SetAwake(!0),t.m_edgeA.prev&&(t.m_edgeA.prev.next=t.m_edgeA.next),t.m_edgeA.next&&(t.m_edgeA.next.prev=t.m_edgeA.prev),t.m_edgeA==e.m_jointList&&(e.m_jointList=t.m_edgeA.next),t.m_edgeA.prev=null,t.m_edgeA.next=null,t.m_edgeB.prev&&(t.m_edgeB.prev.next=t.m_edgeB.next),t.m_edgeB.next&&(t.m_edgeB.next.prev=t.m_edgeB.prev),t.m_edgeB==o.m_jointList&&(o.m_jointList=t.m_edgeB.next),t.m_edgeB.prev=null,t.m_edgeB.next=null,T.Destroy(t,null),--this.m_jointCount,0==i)for(var n=o.GetContactList();n;)n.other==e&&n.contact.FlagForFiltering(),n=n.next},L.prototype.AddController=function(t){return t.m_next=this.m_controllerList,t.m_prev=null,this.m_controllerList=t,t.m_world=this,this.m_controllerCount++,t},L.prototype.RemoveController=function(t){t.m_prev&&(t.m_prev.m_next=t.m_next),t.m_next&&(t.m_next.m_prev=t.m_prev),this.m_controllerList==t&&(this.m_controllerList=t.m_next),this.m_controllerCount--},L.prototype.CreateController=function(t){if(t.m_world!=this)throw Error("Controller can only be a member of one world");return t.m_next=this.m_controllerList,t.m_prev=null,this.m_controllerList&&(this.m_controllerList.m_prev=t),this.m_controllerList=t,++this.m_controllerCount,t.m_world=this,t},L.prototype.DestroyController=function(t){t.Clear(),t.m_next&&(t.m_next.m_prev=t.m_prev),t.m_prev&&(t.m_prev.m_next=t.m_next),t==this.m_controllerList&&(this.m_controllerList=t.m_next),--this.m_controllerCount},L.prototype.SetWarmStarting=function(t){L.m_warmStarting=t},L.prototype.SetContinuousPhysics=function(t){L.m_continuousPhysics=t},L.prototype.GetBodyCount=function(){return this.m_bodyCount},L.prototype.GetJointCount=function(){return this.m_jointCount},L.prototype.GetContactCount=function(){return this.m_contactCount},L.prototype.SetGravity=function(t){this.m_gravity=t},L.prototype.GetGravity=function(){return this.m_gravity},L.prototype.GetGroundBody=function(){return this.m_groundBody},L.prototype.Step=function(t,i,e){void 0===t&&(t=0),void 0===i&&(i=0),void 0===e&&(e=0),this.m_flags&L.e_newFixture&&(this.m_contactManager.FindNewContacts(),this.m_flags&=~L.e_newFixture),this.m_flags|=L.e_locked;var o=L.s_timestep2;o.dt=t,o.velocityIterations=i,o.positionIterations=e,o.inv_dt=t>0?1/t:0,o.dtRatio=this.m_inv_dt0*t,o.warmStarting=L.m_warmStarting,this.m_contactManager.Collide(),o.dt>0&&this.Solve(o),L.m_continuousPhysics&&o.dt>0&&this.SolveTOI(o),o.dt>0&&(this.m_inv_dt0=o.inv_dt),this.m_flags&=~L.e_locked},L.prototype.ClearForces=function(){for(var t=this.m_bodyList;t;t=t.m_next)t.m_force.SetZero(),t.m_torque=0},L.prototype.DrawDebugData=function(){if(null!=this.m_debugDraw){this.m_debugDraw.m_sprite.graphics.clear();var t,i,e,o,n,s=this.m_debugDraw.GetFlags();new r,new r,new r;var m;new l,new l;var c=[new r,new r,new r,new r],h=new a(0,0,0);if(s&S.e_shapeBit)for(t=this.m_bodyList;t;t=t.m_next)for(m=t.m_xf,i=t.GetFixtureList();i;i=i.m_next)e=i.GetShape(),0==t.IsActive()?(h.Set(.5,.5,.3),this.DrawShape(e,m,h)):t.GetType()==b.b2_staticBody?(h.Set(.5,.9,.5),this.DrawShape(e,m,h)):t.GetType()==b.b2_kinematicBody?(h.Set(.5,.5,.9),this.DrawShape(e,m,h)):0==t.IsAwake()?(h.Set(.6,.6,.6),this.DrawShape(e,m,h)):(h.Set(.9,.7,.7),this.DrawShape(e,m,h));if(s&S.e_jointBit)for(o=this.m_jointList;o;o=o.m_next)this.DrawJoint(o);if(s&S.e_controllerBit)for(var _=this.m_controllerList;_;_=_.m_next)_.Draw(this.m_debugDraw);if(s&S.e_pairBit){h.Set(.3,.9,.9);for(var p=this.m_contactManager.m_contactList;p;p=p.GetNext()){var y=p.GetFixtureA(),u=p.GetFixtureB(),x=y.GetAABB().GetCenter(),f=u.GetAABB().GetCenter();this.m_debugDraw.DrawSegment(x,f,h)}}if(s&S.e_aabbBit)for(n=this.m_contactManager.m_broadPhase,c=[new r,new r,new r,new r],t=this.m_bodyList;t;t=t.GetNext())if(0!=t.IsActive())for(i=t.GetFixtureList();i;i=i.GetNext()){var d=n.GetFatAABB(i.m_proxy);c[0].Set(d.lowerBound.x,d.lowerBound.y),c[1].Set(d.upperBound.x,d.lowerBound.y),c[2].Set(d.upperBound.x,d.upperBound.y),c[3].Set(d.lowerBound.x,d.upperBound.y),this.m_debugDraw.DrawPolygon(c,4,h)}if(s&S.e_centerOfMassBit)for(t=this.m_bodyList;t;t=t.m_next)m=L.s_xf,m.R=t.m_xf.R,m.position=t.GetWorldCenter(),this.m_debugDraw.DrawTransform(m)}},L.prototype.QueryAABB=function(t,i){function e(i){return t(n.GetUserData(i))}var o=this,n=o.m_contactManager.m_broadPhase;n.Query(e,i)},L.prototype.QueryShape=function(t,i,o){function n(e){var n=r.GetUserData(e)instanceof M?r.GetUserData(e):null;return d.TestOverlap(i,o,n.GetShape(),n.GetBody().GetTransform())?t(n):!0}var s=this;void 0===o&&(o=null),null==o&&(o=new e,o.SetIdentity());var r=s.m_contactManager.m_broadPhase,a=new l;i.ComputeAABB(a,o),r.Query(n,a)},L.prototype.QueryPoint=function(t,i){function e(e){var o=n.GetUserData(e)instanceof M?n.GetUserData(e):null;return o.TestPoint(i)?t(o):!0}var o=this,n=o.m_contactManager.m_broadPhase,s=new l;s.lowerBound.Set(i.x-m.b2_linearSlop,i.y-m.b2_linearSlop),s.upperBound.Set(i.x+m.b2_linearSlop,i.y+m.b2_linearSlop),n.Query(e,s)},L.prototype.RayCast=function(t,i,e){function o(o,n){var m=s.GetUserData(n),l=m instanceof M?m:null,c=l.RayCast(a,o);if(c){var h=a.fraction,_=new r((1-h)*i.x+h*e.x,(1-h)*i.y+h*e.y);return t(l,_,a.normal,h)}return o.maxFraction}var n=this,s=n.m_contactManager.m_broadPhase,a=new p,m=new _(i,e);s.RayCast(o,m)},L.prototype.RayCastOne=function(t,i){function e(t,i,e,n){return void 0===n&&(n=0),o=t,n}var o,n=this;return n.RayCast(e,t,i),o},L.prototype.RayCastAll=function(t,i){function e(t,i,e,o){return void 0===o&&(o=0),s[s.length]=t,1}var o=this,s=new n;return o.RayCast(e,t,i),s},L.prototype.GetBodyList=function(){return this.m_bodyList},L.prototype.GetJointList=function(){return this.m_jointList},L.prototype.GetContactList=function(){return this.m_contactList},L.prototype.IsLocked=function(){return(this.m_flags&L.e_locked)>0},L.prototype.Solve=function(t){for(var i,e=this.m_controllerList;e;e=e.m_next)e.Step(t);var o=this.m_island;for(o.Initialize(this.m_bodyCount,this.m_contactCount,this.m_jointCount,null,this.m_contactManager.m_contactListener,this.m_contactSolver),i=this.m_bodyList;i;i=i.m_next)i.m_flags&=~b.e_islandFlag;for(var n=this.m_contactList;n;n=n.m_next)n.m_flags&=~J.e_islandFlag;for(var s=this.m_jointList;s;s=s.m_next)s.m_islandFlag=!1;parseInt(this.m_bodyCount);for(var r=this.s_stack,a=this.m_bodyList;a;a=a.m_next)if(!(a.m_flags&b.e_islandFlag)&&0!=a.IsAwake()&&0!=a.IsActive()&&a.GetType()!=b.b2_staticBody){o.Clear();var m=0;for(r[m++]=a,a.m_flags|=b.e_islandFlag;m>0;)if(i=r[--m],o.AddBody(i),0==i.IsAwake()&&i.SetAwake(!0),i.GetType()!=b.b2_staticBody){for(var l,c=i.m_contactList;c;c=c.next)c.contact.m_flags&J.e_islandFlag||1!=c.contact.IsSensor()&&0!=c.contact.IsEnabled()&&0!=c.contact.IsTouching()&&(o.AddContact(c.contact),c.contact.m_flags|=J.e_islandFlag,l=c.other,l.m_flags&b.e_islandFlag||(r[m++]=l,l.m_flags|=b.e_islandFlag));for(var h=i.m_jointList;h;h=h.next)1!=h.joint.m_islandFlag&&(l=h.other,0!=l.IsActive()&&(o.AddJoint(h.joint),h.joint.m_islandFlag=!0,l.m_flags&b.e_islandFlag||(r[m++]=l,l.m_flags|=b.e_islandFlag)))}o.Solve(t,this.m_gravity,this.m_allowSleep);for(var _=0;o.m_bodyCount>_;++_)i=o.m_bodies[_],i.GetType()==b.b2_staticBody&&(i.m_flags&=~b.e_islandFlag)}for(_=0;r.length>_&&r[_];++_)r[_]=null;for(i=this.m_bodyList;i;i=i.m_next)0!=i.IsAwake()&&0!=i.IsActive()&&i.GetType()!=b.b2_staticBody&&i.SynchronizeFixtures();this.m_contactManager.FindNewContacts()},L.prototype.SolveTOI=function(t){var i,e,o,n,s,r,a,l=this.m_island;l.Initialize(this.m_bodyCount,m.b2_maxTOIContactsPerIsland,m.b2_maxTOIJointsPerIsland,null,this.m_contactManager.m_contactListener,this.m_contactSolver);var c=L.s_queue;for(i=this.m_bodyList;i;i=i.m_next)i.m_flags&=~b.e_islandFlag,i.m_sweep.t0=0;var h;for(h=this.m_contactList;h;h=h.m_next)h.m_flags&=~(J.e_toiFlag|J.e_islandFlag);for(a=this.m_jointList;a;a=a.m_next)a.m_islandFlag=!1;for(;;){var _=null,p=1;for(h=this.m_contactList;h;h=h.m_next)if(1!=h.IsSensor()&&0!=h.IsEnabled()&&0!=h.IsContinuous()){var y=1;if(h.m_flags&J.e_toiFlag)y=h.m_toi;else{if(e=h.m_fixtureA,o=h.m_fixtureB,n=e.m_body,s=o.m_body,!(n.GetType()==b.b2_dynamicBody&&0!=n.IsAwake()||s.GetType()==b.b2_dynamicBody&&0!=s.IsAwake()))continue;var u=n.m_sweep.t0;n.m_sweep.t0<s.m_sweep.t0?(u=s.m_sweep.t0,n.m_sweep.Advance(u)):s.m_sweep.t0<n.m_sweep.t0&&(u=n.m_sweep.t0,s.m_sweep.Advance(u)),y=h.ComputeTOI(n.m_sweep,s.m_sweep),m.b2Assert(y>=0&&1>=y),y>0&&1>y&&(y=(1-y)*u+y,y>1&&(y=1)),h.m_toi=y,h.m_flags|=J.e_toiFlag}y>Number.MIN_VALUE&&p>y&&(_=h,p=y)}if(null==_||p>1-100*Number.MIN_VALUE)break;if(e=_.m_fixtureA,o=_.m_fixtureB,n=e.m_body,s=o.m_body,L.s_backupA.Set(n.m_sweep),L.s_backupB.Set(s.m_sweep),n.Advance(p),s.Advance(p),_.Update(this.m_contactManager.m_contactListener),_.m_flags&=~J.e_toiFlag,1!=_.IsSensor()&&0!=_.IsEnabled()){if(0!=_.IsTouching()){var x=n;x.GetType()!=b.b2_dynamicBody&&(x=s),l.Clear();var f=0,d=0;for(c[f+d++]=x,x.m_flags|=b.e_islandFlag;d>0;)if(i=c[f++],--d,l.AddBody(i),0==i.IsAwake()&&i.SetAwake(!0),i.GetType()==b.b2_dynamicBody){for(r=i.m_contactList;r&&l.m_contactCount!=l.m_contactCapacity;r=r.next)if(!(r.contact.m_flags&J.e_islandFlag)&&1!=r.contact.IsSensor()&&0!=r.contact.IsEnabled()&&0!=r.contact.IsTouching()){l.AddContact(r.contact),r.contact.m_flags|=J.e_islandFlag;var v=r.other;v.m_flags&b.e_islandFlag||(v.GetType()!=b.b2_staticBody&&(v.Advance(p),v.SetAwake(!0)),c[f+d]=v,++d,v.m_flags|=b.e_islandFlag)}for(var C=i.m_jointList;C;C=C.next)l.m_jointCount!=l.m_jointCapacity&&1!=C.joint.m_islandFlag&&(v=C.other,0!=v.IsActive()&&(l.AddJoint(C.joint),C.joint.m_islandFlag=!0,v.m_flags&b.e_islandFlag||(v.GetType()!=b.b2_staticBody&&(v.Advance(p),v.SetAwake(!0)),c[f+d]=v,++d,v.m_flags|=b.e_islandFlag)))}var g=L.s_timestep;g.warmStarting=!1,g.dt=(1-p)*t.dt,g.inv_dt=1/g.dt,g.dtRatio=0,g.velocityIterations=t.velocityIterations,g.positionIterations=t.positionIterations,l.SolveTOI(g);var w=0;for(w=0;l.m_bodyCount>w;++w)if(i=l.m_bodies[w],i.m_flags&=~b.e_islandFlag,0!=i.IsAwake()&&i.GetType()==b.b2_dynamicBody)for(i.SynchronizeFixtures(),r=i.m_contactList;r;r=r.next)r.contact.m_flags&=~J.e_toiFlag;for(w=0;l.m_contactCount>w;++w)h=l.m_contacts[w],h.m_flags&=~(J.e_toiFlag|J.e_islandFlag);for(w=0;l.m_jointCount>w;++w)a=l.m_joints[w],a.m_islandFlag=!1;this.m_contactManager.FindNewContacts()}}else n.m_sweep.Set(L.s_backupA),s.m_sweep.Set(L.s_backupB),n.SynchronizeTransform(),s.SynchronizeTransform()}},L.prototype.DrawJoint=function(t){var i=t.GetBodyA(),e=t.GetBodyB(),o=i.m_xf,n=e.m_xf,s=o.position,r=n.position,a=t.GetAnchorA(),m=t.GetAnchorB(),l=L.s_jointColor;switch(t.m_type){case T.e_distanceJoint:this.m_debugDraw.DrawSegment(a,m,l);break;case T.e_pulleyJoint:var c=t instanceof R?t:null,h=c.GetGroundAnchorA(),_=c.GetGroundAnchorB();this.m_debugDraw.DrawSegment(h,a,l),this.m_debugDraw.DrawSegment(_,m,l),this.m_debugDraw.DrawSegment(h,_,l);break;case T.e_mouseJoint:this.m_debugDraw.DrawSegment(a,m,l);break;default:i!=this.m_groundBody&&this.m_debugDraw.DrawSegment(s,a,l),this.m_debugDraw.DrawSegment(a,m,l),e!=this.m_groundBody&&this.m_debugDraw.DrawSegment(r,m,l)}},L.prototype.DrawShape=function(i,e,o){switch(i.m_type){case d.e_circleShape:var s=i instanceof y?i:null,r=t.MulX(e,s.m_p),a=s.m_radius,m=e.R.col1;this.m_debugDraw.DrawSolidCircle(r,a,m,o);break;case d.e_polygonShape:var l=0,c=i instanceof f?i:null,h=parseInt(c.GetVertexCount()),_=c.GetVertices(),p=new n(h);for(l=0;h>l;++l)p[l]=t.MulX(e,_[l]);this.m_debugDraw.DrawSolidPolygon(p,h,o);break;case d.e_edgeShape:var x=i instanceof u?i:null;this.m_debugDraw.DrawSegment(t.MulX(e,x.GetVertex1()),t.MulX(e,x.GetVertex2()),o)}},o.postDefs.push(function(){o.Dynamics.b2World.s_timestep2=new G,o.Dynamics.b2World.s_xf=new e,o.Dynamics.b2World.s_backupA=new i,o.Dynamics.b2World.s_backupB=new i,o.Dynamics.b2World.s_timestep=new G,o.Dynamics.b2World.s_queue=new n,o.Dynamics.b2World.s_jointColor=new a(.5,.8,.8),o.Dynamics.b2World.e_newFixture=1,o.Dynamics.b2World.e_locked=2})}(),function(){var t=o.Collision.Shapes.b2CircleShape,i=(o.Collision.Shapes.b2EdgeChainDef,o.Collision.Shapes.b2EdgeShape),e=(o.Collision.Shapes.b2MassData,o.Collision.Shapes.b2PolygonShape),r=o.Collision.Shapes.b2Shape,a=o.Dynamics.Contacts.b2CircleContact,m=o.Dynamics.Contacts.b2Contact,l=o.Dynamics.Contacts.b2ContactConstraint,c=o.Dynamics.Contacts.b2ContactConstraintPoint,h=o.Dynamics.Contacts.b2ContactEdge,_=o.Dynamics.Contacts.b2ContactFactory,p=o.Dynamics.Contacts.b2ContactRegister,y=o.Dynamics.Contacts.b2ContactResult,u=o.Dynamics.Contacts.b2ContactSolver,x=o.Dynamics.Contacts.b2EdgeAndCircleContact,f=o.Dynamics.Contacts.b2NullContact,d=o.Dynamics.Contacts.b2PolyAndCircleContact,b=o.Dynamics.Contacts.b2PolyAndEdgeContact,v=o.Dynamics.Contacts.b2PolygonContact,C=o.Dynamics.Contacts.b2PositionSolverManifold,g=o.Dynamics.b2Body,w=(o.Dynamics.b2BodyDef,o.Dynamics.b2ContactFilter,o.Dynamics.b2ContactImpulse,o.Dynamics.b2ContactListener,o.Dynamics.b2ContactManager,o.Dynamics.b2DebugDraw,o.Dynamics.b2DestructionListener,o.Dynamics.b2FilterData,o.Dynamics.b2Fixture,o.Dynamics.b2FixtureDef,o.Dynamics.b2Island,o.Dynamics.b2TimeStep),A=(o.Dynamics.b2World,o.Common.b2Color,o.Common.b2internal,o.Common.b2Settings),S=o.Common.Math.b2Mat22,D=(o.Common.Math.b2Mat33,o.Common.Math.b2Math),B=(o.Common.Math.b2Sweep,o.Common.Math.b2Transform,o.Common.Math.b2Vec2),M=(o.Common.Math.b2Vec3,o.Collision.b2AABB,o.Collision.b2Bound,o.Collision.b2BoundValues,o.Collision.b2Collision),V=o.Collision.b2ContactID,I=(o.Collision.b2ContactPoint,o.Collision.b2Distance,o.Collision.b2DistanceInput,o.Collision.b2DistanceOutput,o.Collision.b2DistanceProxy,o.Collision.b2DynamicTree,o.Collision.b2DynamicTreeBroadPhase,o.Collision.b2DynamicTreeNode,o.Collision.b2DynamicTreePair,o.Collision.b2Manifold),G=(o.Collision.b2ManifoldPoint,o.Collision.b2Point,o.Collision.b2RayCastInput,o.Collision.b2RayCastOutput,o.Collision.b2Segment,o.Collision.b2SeparationFunction,o.Collision.b2Simplex,o.Collision.b2SimplexCache,o.Collision.b2SimplexVertex,o.Collision.b2TimeOfImpact),L=o.Collision.b2TOIInput,J=o.Collision.b2WorldManifold;
o.Collision.ClipVertex,o.Collision.Features,o.Collision.IBroadPhase,o.inherit(a,o.Dynamics.Contacts.b2Contact),a.prototype.__super=o.Dynamics.Contacts.b2Contact.prototype,a.b2CircleContact=function(){o.Dynamics.Contacts.b2Contact.b2Contact.apply(this,arguments)},a.Create=function(){return new a},a.Destroy=function(){},a.prototype.Reset=function(t,i){this.__super.Reset.call(this,t,i)},a.prototype.Evaluate=function(){var i=this.m_fixtureA.GetBody(),e=this.m_fixtureB.GetBody();M.CollideCircles(this.m_manifold,this.m_fixtureA.GetShape()instanceof t?this.m_fixtureA.GetShape():null,i.m_xf,this.m_fixtureB.GetShape()instanceof t?this.m_fixtureB.GetShape():null,e.m_xf)},m.b2Contact=function(){this.m_nodeA=new h,this.m_nodeB=new h,this.m_manifold=new I,this.m_oldManifold=new I},m.prototype.GetManifold=function(){return this.m_manifold},m.prototype.GetWorldManifold=function(t){var i=this.m_fixtureA.GetBody(),e=this.m_fixtureB.GetBody(),o=this.m_fixtureA.GetShape(),n=this.m_fixtureB.GetShape();t.Initialize(this.m_manifold,i.GetTransform(),o.m_radius,e.GetTransform(),n.m_radius)},m.prototype.IsTouching=function(){return(this.m_flags&m.e_touchingFlag)==m.e_touchingFlag},m.prototype.IsContinuous=function(){return(this.m_flags&m.e_continuousFlag)==m.e_continuousFlag},m.prototype.SetSensor=function(t){t?this.m_flags|=m.e_sensorFlag:this.m_flags&=~m.e_sensorFlag},m.prototype.IsSensor=function(){return(this.m_flags&m.e_sensorFlag)==m.e_sensorFlag},m.prototype.SetEnabled=function(t){t?this.m_flags|=m.e_enabledFlag:this.m_flags&=~m.e_enabledFlag},m.prototype.IsEnabled=function(){return(this.m_flags&m.e_enabledFlag)==m.e_enabledFlag},m.prototype.GetNext=function(){return this.m_next},m.prototype.GetFixtureA=function(){return this.m_fixtureA},m.prototype.GetFixtureB=function(){return this.m_fixtureB},m.prototype.FlagForFiltering=function(){this.m_flags|=m.e_filterFlag},m.prototype.b2Contact=function(){},m.prototype.Reset=function(t,i){if(void 0===t&&(t=null),void 0===i&&(i=null),this.m_flags=m.e_enabledFlag,!t||!i)return this.m_fixtureA=null,this.m_fixtureB=null,void 0;(t.IsSensor()||i.IsSensor())&&(this.m_flags|=m.e_sensorFlag);var e=t.GetBody(),o=i.GetBody();(e.GetType()!=g.b2_dynamicBody||e.IsBullet()||o.GetType()!=g.b2_dynamicBody||o.IsBullet())&&(this.m_flags|=m.e_continuousFlag),this.m_fixtureA=t,this.m_fixtureB=i,this.m_manifold.m_pointCount=0,this.m_prev=null,this.m_next=null,this.m_nodeA.contact=null,this.m_nodeA.prev=null,this.m_nodeA.next=null,this.m_nodeA.other=null,this.m_nodeB.contact=null,this.m_nodeB.prev=null,this.m_nodeB.next=null,this.m_nodeB.other=null},m.prototype.Update=function(t){var i=this.m_oldManifold;this.m_oldManifold=this.m_manifold,this.m_manifold=i,this.m_flags|=m.e_enabledFlag;var e=!1,o=(this.m_flags&m.e_touchingFlag)==m.e_touchingFlag,n=this.m_fixtureA.m_body,s=this.m_fixtureB.m_body,a=this.m_fixtureA.m_aabb.TestOverlap(this.m_fixtureB.m_aabb);if(this.m_flags&m.e_sensorFlag){if(a){var l=this.m_fixtureA.GetShape(),c=this.m_fixtureB.GetShape(),h=n.GetTransform(),_=s.GetTransform();e=r.TestOverlap(l,h,c,_)}this.m_manifold.m_pointCount=0}else{if(n.GetType()!=g.b2_dynamicBody||n.IsBullet()||s.GetType()!=g.b2_dynamicBody||s.IsBullet()?this.m_flags|=m.e_continuousFlag:this.m_flags&=~m.e_continuousFlag,a){this.Evaluate(),e=this.m_manifold.m_pointCount>0;for(var p=0;this.m_manifold.m_pointCount>p;++p){var y=this.m_manifold.m_points[p];y.m_normalImpulse=0,y.m_tangentImpulse=0;for(var u=y.m_id,x=0;this.m_oldManifold.m_pointCount>x;++x){var f=this.m_oldManifold.m_points[x];if(f.m_id.key==u.key){y.m_normalImpulse=f.m_normalImpulse,y.m_tangentImpulse=f.m_tangentImpulse;break}}}}else this.m_manifold.m_pointCount=0;e!=o&&(n.SetAwake(!0),s.SetAwake(!0))}e?this.m_flags|=m.e_touchingFlag:this.m_flags&=~m.e_touchingFlag,0==o&&1==e&&t.BeginContact(this),1==o&&0==e&&t.EndContact(this),0==(this.m_flags&m.e_sensorFlag)&&t.PreSolve(this,this.m_oldManifold)},m.prototype.Evaluate=function(){},m.prototype.ComputeTOI=function(t,i){return m.s_input.proxyA.Set(this.m_fixtureA.GetShape()),m.s_input.proxyB.Set(this.m_fixtureB.GetShape()),m.s_input.sweepA=t,m.s_input.sweepB=i,m.s_input.tolerance=A.b2_linearSlop,G.TimeOfImpact(m.s_input)},o.postDefs.push(function(){o.Dynamics.Contacts.b2Contact.e_sensorFlag=1,o.Dynamics.Contacts.b2Contact.e_continuousFlag=2,o.Dynamics.Contacts.b2Contact.e_islandFlag=4,o.Dynamics.Contacts.b2Contact.e_toiFlag=8,o.Dynamics.Contacts.b2Contact.e_touchingFlag=16,o.Dynamics.Contacts.b2Contact.e_enabledFlag=32,o.Dynamics.Contacts.b2Contact.e_filterFlag=64,o.Dynamics.Contacts.b2Contact.s_input=new L}),l.b2ContactConstraint=function(){this.localPlaneNormal=new B,this.localPoint=new B,this.normal=new B,this.normalMass=new S,this.K=new S},l.prototype.b2ContactConstraint=function(){this.points=new n(A.b2_maxManifoldPoints);for(var t=0;A.b2_maxManifoldPoints>t;t++)this.points[t]=new c},c.b2ContactConstraintPoint=function(){this.localPoint=new B,this.rA=new B,this.rB=new B},h.b2ContactEdge=function(){},_.b2ContactFactory=function(){},_.prototype.b2ContactFactory=function(t){this.m_allocator=t,this.InitializeRegisters()},_.prototype.AddType=function(t,i,e,o){void 0===e&&(e=0),void 0===o&&(o=0),this.m_registers[e][o].createFcn=t,this.m_registers[e][o].destroyFcn=i,this.m_registers[e][o].primary=!0,e!=o&&(this.m_registers[o][e].createFcn=t,this.m_registers[o][e].destroyFcn=i,this.m_registers[o][e].primary=!1)},_.prototype.InitializeRegisters=function(){this.m_registers=new n(r.e_shapeTypeCount);for(var t=0;r.e_shapeTypeCount>t;t++){this.m_registers[t]=new n(r.e_shapeTypeCount);for(var i=0;r.e_shapeTypeCount>i;i++)this.m_registers[t][i]=new p}this.AddType(a.Create,a.Destroy,r.e_circleShape,r.e_circleShape),this.AddType(d.Create,d.Destroy,r.e_polygonShape,r.e_circleShape),this.AddType(v.Create,v.Destroy,r.e_polygonShape,r.e_polygonShape),this.AddType(x.Create,x.Destroy,r.e_edgeShape,r.e_circleShape),this.AddType(b.Create,b.Destroy,r.e_polygonShape,r.e_edgeShape)},_.prototype.Create=function(t,i){var e,o=parseInt(t.GetType()),n=parseInt(i.GetType()),s=this.m_registers[o][n];if(s.pool)return e=s.pool,s.pool=e.m_next,s.poolCount--,e.Reset(t,i),e;var r=s.createFcn;return null!=r?s.primary?(e=r(this.m_allocator),e.Reset(t,i),e):(e=r(this.m_allocator),e.Reset(i,t),e):null},_.prototype.Destroy=function(t){t.m_manifold.m_pointCount>0&&(t.m_fixtureA.m_body.SetAwake(!0),t.m_fixtureB.m_body.SetAwake(!0));var i=parseInt(t.m_fixtureA.GetType()),e=parseInt(t.m_fixtureB.GetType()),o=this.m_registers[i][e];o.poolCount++,t.m_next=o.pool,o.pool=t;var n=o.destroyFcn;n(t,this.m_allocator)},p.b2ContactRegister=function(){},y.b2ContactResult=function(){this.position=new B,this.normal=new B,this.id=new V},u.b2ContactSolver=function(){this.m_step=new w,this.m_constraints=new n},u.prototype.b2ContactSolver=function(){},u.prototype.Initialize=function(t,i,e,o){void 0===e&&(e=0);var n;this.m_step.Set(t),this.m_allocator=o;var s=0;for(this.m_constraintCount=e;this.m_constraints.length<this.m_constraintCount;)this.m_constraints[this.m_constraints.length]=new l;for(s=0;e>s;++s){n=i[s];var r=n.m_fixtureA,a=n.m_fixtureB,m=r.m_shape,c=a.m_shape,h=m.m_radius,_=c.m_radius,p=r.m_body,y=a.m_body,x=n.GetManifold(),f=A.b2MixFriction(r.GetFriction(),a.GetFriction()),d=A.b2MixRestitution(r.GetRestitution(),a.GetRestitution()),b=p.m_linearVelocity.x,v=p.m_linearVelocity.y,C=y.m_linearVelocity.x,g=y.m_linearVelocity.y,w=p.m_angularVelocity,S=y.m_angularVelocity;A.b2Assert(x.m_pointCount>0),u.s_worldManifold.Initialize(x,p.m_xf,h,y.m_xf,_);var D=u.s_worldManifold.m_normal.x,B=u.s_worldManifold.m_normal.y,M=this.m_constraints[s];M.bodyA=p,M.bodyB=y,M.manifold=x,M.normal.x=D,M.normal.y=B,M.pointCount=x.m_pointCount,M.friction=f,M.restitution=d,M.localPlaneNormal.x=x.m_localPlaneNormal.x,M.localPlaneNormal.y=x.m_localPlaneNormal.y,M.localPoint.x=x.m_localPoint.x,M.localPoint.y=x.m_localPoint.y,M.radius=h+_,M.type=x.m_type;for(var V=0;M.pointCount>V;++V){var I=x.m_points[V],G=M.points[V];G.normalImpulse=I.m_normalImpulse,G.tangentImpulse=I.m_tangentImpulse,G.localPoint.SetV(I.m_localPoint);var L=G.rA.x=u.s_worldManifold.m_points[V].x-p.m_sweep.c.x,J=G.rA.y=u.s_worldManifold.m_points[V].y-p.m_sweep.c.y,F=G.rB.x=u.s_worldManifold.m_points[V].x-y.m_sweep.c.x,P=G.rB.y=u.s_worldManifold.m_points[V].y-y.m_sweep.c.y,T=L*B-J*D,R=F*B-P*D;T*=T,R*=R;var k=p.m_invMass+y.m_invMass+p.m_invI*T+y.m_invI*R;G.normalMass=1/k;var E=p.m_mass*p.m_invMass+y.m_mass*y.m_invMass;E+=p.m_mass*p.m_invI*T+y.m_mass*y.m_invI*R,G.equalizedMass=1/E;var z=B,N=-D,j=L*N-J*z,q=F*N-P*z;j*=j,q*=q;var O=p.m_invMass+y.m_invMass+p.m_invI*j+y.m_invI*q;G.tangentMass=1/O,G.velocityBias=0;var U=C+-S*P-b- -w*J,W=g+S*F-v-w*L,K=M.normal.x*U+M.normal.y*W;-A.b2_velocityThreshold>K&&(G.velocityBias+=-M.restitution*K)}if(2==M.pointCount){var X=M.points[0],Z=M.points[1],H=p.m_invMass,Y=p.m_invI,Q=y.m_invMass,$=y.m_invI,ti=X.rA.x*B-X.rA.y*D,ii=X.rB.x*B-X.rB.y*D,ei=Z.rA.x*B-Z.rA.y*D,oi=Z.rB.x*B-Z.rB.y*D,ni=H+Q+Y*ti*ti+$*ii*ii,si=H+Q+Y*ei*ei+$*oi*oi,ri=H+Q+Y*ti*ei+$*ii*oi,ai=100;ai*(ni*si-ri*ri)>ni*ni?(M.K.col1.Set(ni,ri),M.K.col2.Set(ri,si),M.K.GetInverse(M.normalMass)):M.pointCount=1}}},u.prototype.InitVelocityConstraints=function(t){for(var i=0;this.m_constraintCount>i;++i){var e=this.m_constraints[i],o=e.bodyA,n=e.bodyB,s=o.m_invMass,r=o.m_invI,a=n.m_invMass,m=n.m_invI,l=e.normal.x,c=e.normal.y,h=c,_=-l,p=0,y=0;if(t.warmStarting)for(y=e.pointCount,p=0;y>p;++p){var u=e.points[p];u.normalImpulse*=t.dtRatio,u.tangentImpulse*=t.dtRatio;var x=u.normalImpulse*l+u.tangentImpulse*h,f=u.normalImpulse*c+u.tangentImpulse*_;o.m_angularVelocity-=r*(u.rA.x*f-u.rA.y*x),o.m_linearVelocity.x-=s*x,o.m_linearVelocity.y-=s*f,n.m_angularVelocity+=m*(u.rB.x*f-u.rB.y*x),n.m_linearVelocity.x+=a*x,n.m_linearVelocity.y+=a*f}else for(y=e.pointCount,p=0;y>p;++p){var d=e.points[p];d.normalImpulse=0,d.tangentImpulse=0}}},u.prototype.SolveVelocityConstraints=function(){for(var t,i,e=0,o=0,n=0,s=0,r=0,a=0,m=0,l=0,c=0,h=0,_=0,p=0,y=0,u=0,x=0,f=0,d=0;this.m_constraintCount>d;++d){var b=this.m_constraints[d],v=b.bodyA,C=b.bodyB,g=v.m_angularVelocity,w=C.m_angularVelocity,A=v.m_linearVelocity,S=C.m_linearVelocity,B=v.m_invMass,M=v.m_invI,V=C.m_invMass,I=C.m_invI,G=b.normal.x,L=b.normal.y,J=L,F=-G,P=b.friction;for(e=0;b.pointCount>e;e++)t=b.points[e],o=S.x-w*t.rB.y-A.x+g*t.rA.y,n=S.y+w*t.rB.x-A.y-g*t.rA.x,r=o*J+n*F,a=t.tangentMass*-r,m=P*t.normalImpulse,l=D.Clamp(t.tangentImpulse+a,-m,m),a=l-t.tangentImpulse,c=a*J,h=a*F,A.x-=B*c,A.y-=B*h,g-=M*(t.rA.x*h-t.rA.y*c),S.x+=V*c,S.y+=V*h,w+=I*(t.rB.x*h-t.rB.y*c),t.tangentImpulse=l;if(parseInt(b.pointCount),1==b.pointCount)t=b.points[0],o=S.x+-w*t.rB.y-A.x- -g*t.rA.y,n=S.y+w*t.rB.x-A.y-g*t.rA.x,s=o*G+n*L,a=-t.normalMass*(s-t.velocityBias),l=t.normalImpulse+a,l=l>0?l:0,a=l-t.normalImpulse,c=a*G,h=a*L,A.x-=B*c,A.y-=B*h,g-=M*(t.rA.x*h-t.rA.y*c),S.x+=V*c,S.y+=V*h,w+=I*(t.rB.x*h-t.rB.y*c),t.normalImpulse=l;else{var T=b.points[0],R=b.points[1],k=T.normalImpulse,E=R.normalImpulse,z=S.x-w*T.rB.y-A.x+g*T.rA.y,N=S.y+w*T.rB.x-A.y-g*T.rA.x,j=S.x-w*R.rB.y-A.x+g*R.rA.y,q=S.y+w*R.rB.x-A.y-g*R.rA.x,O=z*G+N*L,U=j*G+q*L,W=O-T.velocityBias,K=U-R.velocityBias;for(i=b.K,W-=i.col1.x*k+i.col2.x*E,K-=i.col1.y*k+i.col2.y*E;;){i=b.normalMass;var X=-(i.col1.x*W+i.col2.x*K),Z=-(i.col1.y*W+i.col2.y*K);if(X>=0&&Z>=0){_=X-k,p=Z-E,y=_*G,u=_*L,x=p*G,f=p*L,A.x-=B*(y+x),A.y-=B*(u+f),g-=M*(T.rA.x*u-T.rA.y*y+R.rA.x*f-R.rA.y*x),S.x+=V*(y+x),S.y+=V*(u+f),w+=I*(T.rB.x*u-T.rB.y*y+R.rB.x*f-R.rB.y*x),T.normalImpulse=X,R.normalImpulse=Z;break}if(X=-T.normalMass*W,Z=0,O=0,U=b.K.col1.y*X+K,X>=0&&U>=0){_=X-k,p=Z-E,y=_*G,u=_*L,x=p*G,f=p*L,A.x-=B*(y+x),A.y-=B*(u+f),g-=M*(T.rA.x*u-T.rA.y*y+R.rA.x*f-R.rA.y*x),S.x+=V*(y+x),S.y+=V*(u+f),w+=I*(T.rB.x*u-T.rB.y*y+R.rB.x*f-R.rB.y*x),T.normalImpulse=X,R.normalImpulse=Z;break}if(X=0,Z=-R.normalMass*K,O=b.K.col2.x*Z+W,U=0,Z>=0&&O>=0){_=X-k,p=Z-E,y=_*G,u=_*L,x=p*G,f=p*L,A.x-=B*(y+x),A.y-=B*(u+f),g-=M*(T.rA.x*u-T.rA.y*y+R.rA.x*f-R.rA.y*x),S.x+=V*(y+x),S.y+=V*(u+f),w+=I*(T.rB.x*u-T.rB.y*y+R.rB.x*f-R.rB.y*x),T.normalImpulse=X,R.normalImpulse=Z;break}if(X=0,Z=0,O=W,U=K,O>=0&&U>=0){_=X-k,p=Z-E,y=_*G,u=_*L,x=p*G,f=p*L,A.x-=B*(y+x),A.y-=B*(u+f),g-=M*(T.rA.x*u-T.rA.y*y+R.rA.x*f-R.rA.y*x),S.x+=V*(y+x),S.y+=V*(u+f),w+=I*(T.rB.x*u-T.rB.y*y+R.rB.x*f-R.rB.y*x),T.normalImpulse=X,R.normalImpulse=Z;break}break}}v.m_angularVelocity=g,C.m_angularVelocity=w}},u.prototype.FinalizeVelocityConstraints=function(){for(var t=0;this.m_constraintCount>t;++t)for(var i=this.m_constraints[t],e=i.manifold,o=0;i.pointCount>o;++o){var n=e.m_points[o],s=i.points[o];n.m_normalImpulse=s.normalImpulse,n.m_tangentImpulse=s.tangentImpulse}},u.prototype.SolvePositionConstraints=function(t){void 0===t&&(t=0);for(var i=0,e=0;this.m_constraintCount>e;e++){var o=this.m_constraints[e],n=o.bodyA,s=o.bodyB,r=n.m_mass*n.m_invMass,a=n.m_mass*n.m_invI,m=s.m_mass*s.m_invMass,l=s.m_mass*s.m_invI;u.s_psm.Initialize(o);for(var c=u.s_psm.m_normal,h=0;o.pointCount>h;h++){var _=o.points[h],p=u.s_psm.m_points[h],y=u.s_psm.m_separations[h],x=p.x-n.m_sweep.c.x,f=p.y-n.m_sweep.c.y,d=p.x-s.m_sweep.c.x,b=p.y-s.m_sweep.c.y;i=y>i?i:y;var v=D.Clamp(t*(y+A.b2_linearSlop),-A.b2_maxLinearCorrection,0),C=-_.equalizedMass*v,g=C*c.x,w=C*c.y;n.m_sweep.c.x-=r*g,n.m_sweep.c.y-=r*w,n.m_sweep.a-=a*(x*w-f*g),n.SynchronizeTransform(),s.m_sweep.c.x+=m*g,s.m_sweep.c.y+=m*w,s.m_sweep.a+=l*(d*w-b*g),s.SynchronizeTransform()}}return i>-1.5*A.b2_linearSlop},o.postDefs.push(function(){o.Dynamics.Contacts.b2ContactSolver.s_worldManifold=new J,o.Dynamics.Contacts.b2ContactSolver.s_psm=new C}),o.inherit(x,o.Dynamics.Contacts.b2Contact),x.prototype.__super=o.Dynamics.Contacts.b2Contact.prototype,x.b2EdgeAndCircleContact=function(){o.Dynamics.Contacts.b2Contact.b2Contact.apply(this,arguments)},x.Create=function(){return new x},x.Destroy=function(){},x.prototype.Reset=function(t,i){this.__super.Reset.call(this,t,i)},x.prototype.Evaluate=function(){var e=this.m_fixtureA.GetBody(),o=this.m_fixtureB.GetBody();this.b2CollideEdgeAndCircle(this.m_manifold,this.m_fixtureA.GetShape()instanceof i?this.m_fixtureA.GetShape():null,e.m_xf,this.m_fixtureB.GetShape()instanceof t?this.m_fixtureB.GetShape():null,o.m_xf)},x.prototype.b2CollideEdgeAndCircle=function(){},o.inherit(f,o.Dynamics.Contacts.b2Contact),f.prototype.__super=o.Dynamics.Contacts.b2Contact.prototype,f.b2NullContact=function(){o.Dynamics.Contacts.b2Contact.b2Contact.apply(this,arguments)},f.prototype.b2NullContact=function(){this.__super.b2Contact.call(this)},f.prototype.Evaluate=function(){},o.inherit(d,o.Dynamics.Contacts.b2Contact),d.prototype.__super=o.Dynamics.Contacts.b2Contact.prototype,d.b2PolyAndCircleContact=function(){o.Dynamics.Contacts.b2Contact.b2Contact.apply(this,arguments)},d.Create=function(){return new d},d.Destroy=function(){},d.prototype.Reset=function(t,i){this.__super.Reset.call(this,t,i),A.b2Assert(t.GetType()==r.e_polygonShape),A.b2Assert(i.GetType()==r.e_circleShape)},d.prototype.Evaluate=function(){var i=this.m_fixtureA.m_body,o=this.m_fixtureB.m_body;M.CollidePolygonAndCircle(this.m_manifold,this.m_fixtureA.GetShape()instanceof e?this.m_fixtureA.GetShape():null,i.m_xf,this.m_fixtureB.GetShape()instanceof t?this.m_fixtureB.GetShape():null,o.m_xf)},o.inherit(b,o.Dynamics.Contacts.b2Contact),b.prototype.__super=o.Dynamics.Contacts.b2Contact.prototype,b.b2PolyAndEdgeContact=function(){o.Dynamics.Contacts.b2Contact.b2Contact.apply(this,arguments)},b.Create=function(){return new b},b.Destroy=function(){},b.prototype.Reset=function(t,i){this.__super.Reset.call(this,t,i),A.b2Assert(t.GetType()==r.e_polygonShape),A.b2Assert(i.GetType()==r.e_edgeShape)},b.prototype.Evaluate=function(){var t=this.m_fixtureA.GetBody(),o=this.m_fixtureB.GetBody();this.b2CollidePolyAndEdge(this.m_manifold,this.m_fixtureA.GetShape()instanceof e?this.m_fixtureA.GetShape():null,t.m_xf,this.m_fixtureB.GetShape()instanceof i?this.m_fixtureB.GetShape():null,o.m_xf)},b.prototype.b2CollidePolyAndEdge=function(){},o.inherit(v,o.Dynamics.Contacts.b2Contact),v.prototype.__super=o.Dynamics.Contacts.b2Contact.prototype,v.b2PolygonContact=function(){o.Dynamics.Contacts.b2Contact.b2Contact.apply(this,arguments)},v.Create=function(){return new v},v.Destroy=function(){},v.prototype.Reset=function(t,i){this.__super.Reset.call(this,t,i)},v.prototype.Evaluate=function(){var t=this.m_fixtureA.GetBody(),i=this.m_fixtureB.GetBody();M.CollidePolygons(this.m_manifold,this.m_fixtureA.GetShape()instanceof e?this.m_fixtureA.GetShape():null,t.m_xf,this.m_fixtureB.GetShape()instanceof e?this.m_fixtureB.GetShape():null,i.m_xf)},C.b2PositionSolverManifold=function(){},C.prototype.b2PositionSolverManifold=function(){this.m_normal=new B,this.m_separations=new s(A.b2_maxManifoldPoints),this.m_points=new n(A.b2_maxManifoldPoints);for(var t=0;A.b2_maxManifoldPoints>t;t++)this.m_points[t]=new B},C.prototype.Initialize=function(t){A.b2Assert(t.pointCount>0);var i,e,o=0,n=0,s=0,r=0,a=0;switch(t.type){case I.e_circles:i=t.bodyA.m_xf.R,e=t.localPoint;var m=t.bodyA.m_xf.position.x+(i.col1.x*e.x+i.col2.x*e.y),l=t.bodyA.m_xf.position.y+(i.col1.y*e.x+i.col2.y*e.y);i=t.bodyB.m_xf.R,e=t.points[0].localPoint;var c=t.bodyB.m_xf.position.x+(i.col1.x*e.x+i.col2.x*e.y),h=t.bodyB.m_xf.position.y+(i.col1.y*e.x+i.col2.y*e.y),_=c-m,p=h-l,y=_*_+p*p;if(y>Number.MIN_VALUE*Number.MIN_VALUE){var u=Math.sqrt(y);this.m_normal.x=_/u,this.m_normal.y=p/u}else this.m_normal.x=1,this.m_normal.y=0;this.m_points[0].x=.5*(m+c),this.m_points[0].y=.5*(l+h),this.m_separations[0]=_*this.m_normal.x+p*this.m_normal.y-t.radius;break;case I.e_faceA:for(i=t.bodyA.m_xf.R,e=t.localPlaneNormal,this.m_normal.x=i.col1.x*e.x+i.col2.x*e.y,this.m_normal.y=i.col1.y*e.x+i.col2.y*e.y,i=t.bodyA.m_xf.R,e=t.localPoint,r=t.bodyA.m_xf.position.x+(i.col1.x*e.x+i.col2.x*e.y),a=t.bodyA.m_xf.position.y+(i.col1.y*e.x+i.col2.y*e.y),i=t.bodyB.m_xf.R,o=0;t.pointCount>o;++o)e=t.points[o].localPoint,n=t.bodyB.m_xf.position.x+(i.col1.x*e.x+i.col2.x*e.y),s=t.bodyB.m_xf.position.y+(i.col1.y*e.x+i.col2.y*e.y),this.m_separations[o]=(n-r)*this.m_normal.x+(s-a)*this.m_normal.y-t.radius,this.m_points[o].x=n,this.m_points[o].y=s;break;case I.e_faceB:for(i=t.bodyB.m_xf.R,e=t.localPlaneNormal,this.m_normal.x=i.col1.x*e.x+i.col2.x*e.y,this.m_normal.y=i.col1.y*e.x+i.col2.y*e.y,i=t.bodyB.m_xf.R,e=t.localPoint,r=t.bodyB.m_xf.position.x+(i.col1.x*e.x+i.col2.x*e.y),a=t.bodyB.m_xf.position.y+(i.col1.y*e.x+i.col2.y*e.y),i=t.bodyA.m_xf.R,o=0;t.pointCount>o;++o)e=t.points[o].localPoint,n=t.bodyA.m_xf.position.x+(i.col1.x*e.x+i.col2.x*e.y),s=t.bodyA.m_xf.position.y+(i.col1.y*e.x+i.col2.y*e.y),this.m_separations[o]=(n-r)*this.m_normal.x+(s-a)*this.m_normal.y-t.radius,this.m_points[o].Set(n,s);this.m_normal.x*=-1,this.m_normal.y*=-1}},o.postDefs.push(function(){o.Dynamics.Contacts.b2PositionSolverManifold.circlePointA=new B,o.Dynamics.Contacts.b2PositionSolverManifold.circlePointB=new B})}(),function(){var t=(o.Dynamics.b2Body,o.Dynamics.b2BodyDef,o.Dynamics.b2ContactFilter,o.Dynamics.b2ContactImpulse,o.Dynamics.b2ContactListener,o.Dynamics.b2ContactManager,o.Dynamics.b2DebugDraw,o.Dynamics.b2DestructionListener,o.Dynamics.b2FilterData,o.Dynamics.b2Fixture,o.Dynamics.b2FixtureDef,o.Dynamics.b2Island,o.Dynamics.b2TimeStep,o.Dynamics.b2World,o.Common.Math.b2Mat22),i=(o.Common.Math.b2Mat33,o.Common.Math.b2Math),e=(o.Common.Math.b2Sweep,o.Common.Math.b2Transform,o.Common.Math.b2Vec2),n=(o.Common.Math.b2Vec3,o.Common.b2Color),s=(o.Common.b2internal,o.Common.b2Settings,o.Collision.Shapes.b2CircleShape,o.Collision.Shapes.b2EdgeChainDef,o.Collision.Shapes.b2EdgeShape,o.Collision.Shapes.b2MassData,o.Collision.Shapes.b2PolygonShape,o.Collision.Shapes.b2Shape,o.Dynamics.Controllers.b2BuoyancyController),r=o.Dynamics.Controllers.b2ConstantAccelController,a=o.Dynamics.Controllers.b2ConstantForceController,m=o.Dynamics.Controllers.b2Controller,l=o.Dynamics.Controllers.b2ControllerEdge,c=o.Dynamics.Controllers.b2GravityController,h=o.Dynamics.Controllers.b2TensorDampingController;o.inherit(s,o.Dynamics.Controllers.b2Controller),s.prototype.__super=o.Dynamics.Controllers.b2Controller.prototype,s.b2BuoyancyController=function(){o.Dynamics.Controllers.b2Controller.b2Controller.apply(this,arguments),this.normal=new e(0,-1),this.offset=0,this.density=0,this.velocity=new e(0,0),this.linearDrag=2,this.angularDrag=1,this.useDensity=!1,this.useWorldGravity=!0,this.gravity=null},s.prototype.Step=function(){if(this.m_bodyList){this.useWorldGravity&&(this.gravity=this.GetWorld().GetGravity().Copy());for(var t=this.m_bodyList;t;t=t.nextBody){var i=t.body;if(0!=i.IsAwake()){for(var o=new e,n=new e,s=0,r=0,a=i.GetFixtureList();a;a=a.GetNext()){var m=new e,l=a.GetShape().ComputeSubmergedArea(this.normal,this.offset,i.GetTransform(),m);s+=l,o.x+=l*m.x,o.y+=l*m.y;var c=0;c=this.useDensity?1:1,r+=l*c,n.x+=l*m.x*c,n.y+=l*m.y*c}if(o.x/=s,o.y/=s,n.x/=r,n.y/=r,!(Number.MIN_VALUE>s)){var h=this.gravity.GetNegative();h.Multiply(this.density*s),i.ApplyForce(h,n);var _=i.GetLinearVelocityFromWorldPoint(o);_.Subtract(this.velocity),_.Multiply(-this.linearDrag*s),i.ApplyForce(_,o),i.ApplyTorque(-i.GetInertia()/i.GetMass()*s*i.GetAngularVelocity()*this.angularDrag)}}}}},s.prototype.Draw=function(t){var i=1e3,o=new e,s=new e;o.x=this.normal.x*this.offset+this.normal.y*i,o.y=this.normal.y*this.offset-this.normal.x*i,s.x=this.normal.x*this.offset-this.normal.y*i,s.y=this.normal.y*this.offset+this.normal.x*i;var r=new n(0,0,1);t.DrawSegment(o,s,r)},o.inherit(r,o.Dynamics.Controllers.b2Controller),r.prototype.__super=o.Dynamics.Controllers.b2Controller.prototype,r.b2ConstantAccelController=function(){o.Dynamics.Controllers.b2Controller.b2Controller.apply(this,arguments),this.A=new e(0,0)},r.prototype.Step=function(t){for(var i=new e(this.A.x*t.dt,this.A.y*t.dt),o=this.m_bodyList;o;o=o.nextBody){var n=o.body;n.IsAwake()&&n.SetLinearVelocity(new e(n.GetLinearVelocity().x+i.x,n.GetLinearVelocity().y+i.y))}},o.inherit(a,o.Dynamics.Controllers.b2Controller),a.prototype.__super=o.Dynamics.Controllers.b2Controller.prototype,a.b2ConstantForceController=function(){o.Dynamics.Controllers.b2Controller.b2Controller.apply(this,arguments),this.F=new e(0,0)},a.prototype.Step=function(){for(var t=this.m_bodyList;t;t=t.nextBody){var i=t.body;i.IsAwake()&&i.ApplyForce(this.F,i.GetWorldCenter())}},m.b2Controller=function(){},m.prototype.Step=function(){},m.prototype.Draw=function(){},m.prototype.AddBody=function(t){var i=new l;i.controller=this,i.body=t,i.nextBody=this.m_bodyList,i.prevBody=null,this.m_bodyList=i,i.nextBody&&(i.nextBody.prevBody=i),this.m_bodyCount++,i.nextController=t.m_controllerList,i.prevController=null,t.m_controllerList=i,i.nextController&&(i.nextController.prevController=i),t.m_controllerCount++},m.prototype.RemoveBody=function(t){for(var i=t.m_controllerList;i&&i.controller!=this;)i=i.nextController;i.prevBody&&(i.prevBody.nextBody=i.nextBody),i.nextBody&&(i.nextBody.prevBody=i.prevBody),i.nextController&&(i.nextController.prevController=i.prevController),i.prevController&&(i.prevController.nextController=i.nextController),this.m_bodyList==i&&(this.m_bodyList=i.nextBody),t.m_controllerList==i&&(t.m_controllerList=i.nextController),t.m_controllerCount--,this.m_bodyCount--},m.prototype.Clear=function(){for(;this.m_bodyList;)this.RemoveBody(this.m_bodyList.body)},m.prototype.GetNext=function(){return this.m_next},m.prototype.GetWorld=function(){return this.m_world},m.prototype.GetBodyList=function(){return this.m_bodyList},l.b2ControllerEdge=function(){},o.inherit(c,o.Dynamics.Controllers.b2Controller),c.prototype.__super=o.Dynamics.Controllers.b2Controller.prototype,c.b2GravityController=function(){o.Dynamics.Controllers.b2Controller.b2Controller.apply(this,arguments),this.G=1,this.invSqr=!0},c.prototype.Step=function(){var t=null,i=null,o=null,n=0,s=null,r=null,a=null,m=0,l=0,c=0,h=null;if(this.invSqr)for(t=this.m_bodyList;t;t=t.nextBody)for(i=t.body,o=i.GetWorldCenter(),n=i.GetMass(),s=this.m_bodyList;s!=t;s=s.nextBody)r=s.body,a=r.GetWorldCenter(),m=a.x-o.x,l=a.y-o.y,c=m*m+l*l,Number.MIN_VALUE>c||(h=new e(m,l),h.Multiply(this.G/c/Math.sqrt(c)*n*r.GetMass()),i.IsAwake()&&i.ApplyForce(h,o),h.Multiply(-1),r.IsAwake()&&r.ApplyForce(h,a));else for(t=this.m_bodyList;t;t=t.nextBody)for(i=t.body,o=i.GetWorldCenter(),n=i.GetMass(),s=this.m_bodyList;s!=t;s=s.nextBody)r=s.body,a=r.GetWorldCenter(),m=a.x-o.x,l=a.y-o.y,c=m*m+l*l,Number.MIN_VALUE>c||(h=new e(m,l),h.Multiply(this.G/c*n*r.GetMass()),i.IsAwake()&&i.ApplyForce(h,o),h.Multiply(-1),r.IsAwake()&&r.ApplyForce(h,a))},o.inherit(h,o.Dynamics.Controllers.b2Controller),h.prototype.__super=o.Dynamics.Controllers.b2Controller.prototype,h.b2TensorDampingController=function(){o.Dynamics.Controllers.b2Controller.b2Controller.apply(this,arguments),this.T=new t,this.maxTimestep=0},h.prototype.SetAxisAligned=function(t,i){void 0===t&&(t=0),void 0===i&&(i=0),this.T.col1.x=-t,this.T.col1.y=0,this.T.col2.x=0,this.T.col2.y=-i,this.maxTimestep=t>0||i>0?1/Math.max(t,i):0},h.prototype.Step=function(t){var o=t.dt;if(!(Number.MIN_VALUE>=o)){o>this.maxTimestep&&this.maxTimestep>0&&(o=this.maxTimestep);for(var n=this.m_bodyList;n;n=n.nextBody){var s=n.body;if(s.IsAwake()){var r=s.GetWorldVector(i.MulMV(this.T,s.GetLocalVector(s.GetLinearVelocity())));s.SetLinearVelocity(new e(s.GetLinearVelocity().x+r.x*o,s.GetLinearVelocity().y+r.y*o))}}}}}(),function(){var t=(o.Common.b2Color,o.Common.b2internal,o.Common.b2Settings),i=o.Common.Math.b2Mat22,e=o.Common.Math.b2Mat33,n=o.Common.Math.b2Math,s=(o.Common.Math.b2Sweep,o.Common.Math.b2Transform,o.Common.Math.b2Vec2),r=o.Common.Math.b2Vec3,a=o.Dynamics.Joints.b2DistanceJoint,m=o.Dynamics.Joints.b2DistanceJointDef,l=o.Dynamics.Joints.b2FrictionJoint,c=o.Dynamics.Joints.b2FrictionJointDef,h=o.Dynamics.Joints.b2GearJoint,_=o.Dynamics.Joints.b2GearJointDef,p=o.Dynamics.Joints.b2Jacobian,y=o.Dynamics.Joints.b2Joint,u=o.Dynamics.Joints.b2JointDef,x=o.Dynamics.Joints.b2JointEdge,f=o.Dynamics.Joints.b2LineJoint,d=o.Dynamics.Joints.b2LineJointDef,b=o.Dynamics.Joints.b2MouseJoint,v=o.Dynamics.Joints.b2MouseJointDef,C=o.Dynamics.Joints.b2PrismaticJoint,g=o.Dynamics.Joints.b2PrismaticJointDef,w=o.Dynamics.Joints.b2PulleyJoint,A=o.Dynamics.Joints.b2PulleyJointDef,S=o.Dynamics.Joints.b2RevoluteJoint,D=o.Dynamics.Joints.b2RevoluteJointDef,B=o.Dynamics.Joints.b2WeldJoint,M=o.Dynamics.Joints.b2WeldJointDef;o.Dynamics.b2Body,o.Dynamics.b2BodyDef,o.Dynamics.b2ContactFilter,o.Dynamics.b2ContactImpulse,o.Dynamics.b2ContactListener,o.Dynamics.b2ContactManager,o.Dynamics.b2DebugDraw,o.Dynamics.b2DestructionListener,o.Dynamics.b2FilterData,o.Dynamics.b2Fixture,o.Dynamics.b2FixtureDef,o.Dynamics.b2Island,o.Dynamics.b2TimeStep,o.Dynamics.b2World,o.inherit(a,o.Dynamics.Joints.b2Joint),a.prototype.__super=o.Dynamics.Joints.b2Joint.prototype,a.b2DistanceJoint=function(){o.Dynamics.Joints.b2Joint.b2Joint.apply(this,arguments),this.m_localAnchor1=new s,this.m_localAnchor2=new s,this.m_u=new s},a.prototype.GetAnchorA=function(){return this.m_bodyA.GetWorldPoint(this.m_localAnchor1)},a.prototype.GetAnchorB=function(){return this.m_bodyB.GetWorldPoint(this.m_localAnchor2)},a.prototype.GetReactionForce=function(t){return void 0===t&&(t=0),new s(t*this.m_impulse*this.m_u.x,t*this.m_impulse*this.m_u.y)},a.prototype.GetReactionTorque=function(t){return void 0===t&&(t=0),0},a.prototype.GetLength=function(){return this.m_length},a.prototype.SetLength=function(t){void 0===t&&(t=0),this.m_length=t},a.prototype.GetFrequency=function(){return this.m_frequencyHz},a.prototype.SetFrequency=function(t){void 0===t&&(t=0),this.m_frequencyHz=t},a.prototype.GetDampingRatio=function(){return this.m_dampingRatio},a.prototype.SetDampingRatio=function(t){void 0===t&&(t=0),this.m_dampingRatio=t},a.prototype.b2DistanceJoint=function(t){this.__super.b2Joint.call(this,t),this.m_localAnchor1.SetV(t.localAnchorA),this.m_localAnchor2.SetV(t.localAnchorB),this.m_length=t.length,this.m_frequencyHz=t.frequencyHz,this.m_dampingRatio=t.dampingRatio,this.m_impulse=0,this.m_gamma=0,this.m_bias=0},a.prototype.InitVelocityConstraints=function(i){var e,o=0,n=this.m_bodyA,s=this.m_bodyB;e=n.m_xf.R;var r=this.m_localAnchor1.x-n.m_sweep.localCenter.x,a=this.m_localAnchor1.y-n.m_sweep.localCenter.y;o=e.col1.x*r+e.col2.x*a,a=e.col1.y*r+e.col2.y*a,r=o,e=s.m_xf.R;var m=this.m_localAnchor2.x-s.m_sweep.localCenter.x,l=this.m_localAnchor2.y-s.m_sweep.localCenter.y;o=e.col1.x*m+e.col2.x*l,l=e.col1.y*m+e.col2.y*l,m=o,this.m_u.x=s.m_sweep.c.x+m-n.m_sweep.c.x-r,this.m_u.y=s.m_sweep.c.y+l-n.m_sweep.c.y-a;var c=Math.sqrt(this.m_u.x*this.m_u.x+this.m_u.y*this.m_u.y);c>t.b2_linearSlop?this.m_u.Multiply(1/c):this.m_u.SetZero();var h=r*this.m_u.y-a*this.m_u.x,_=m*this.m_u.y-l*this.m_u.x,p=n.m_invMass+n.m_invI*h*h+s.m_invMass+s.m_invI*_*_;if(this.m_mass=0!=p?1/p:0,this.m_frequencyHz>0){var y=c-this.m_length,u=2*Math.PI*this.m_frequencyHz,x=2*this.m_mass*this.m_dampingRatio*u,f=this.m_mass*u*u;this.m_gamma=i.dt*(x+i.dt*f),this.m_gamma=0!=this.m_gamma?1/this.m_gamma:0,this.m_bias=y*i.dt*f*this.m_gamma,this.m_mass=p+this.m_gamma,this.m_mass=0!=this.m_mass?1/this.m_mass:0}if(i.warmStarting){this.m_impulse*=i.dtRatio;var d=this.m_impulse*this.m_u.x,b=this.m_impulse*this.m_u.y;n.m_linearVelocity.x-=n.m_invMass*d,n.m_linearVelocity.y-=n.m_invMass*b,n.m_angularVelocity-=n.m_invI*(r*b-a*d),s.m_linearVelocity.x+=s.m_invMass*d,s.m_linearVelocity.y+=s.m_invMass*b,s.m_angularVelocity+=s.m_invI*(m*b-l*d)}else this.m_impulse=0},a.prototype.SolveVelocityConstraints=function(){var t,i=this.m_bodyA,e=this.m_bodyB;t=i.m_xf.R;var o=this.m_localAnchor1.x-i.m_sweep.localCenter.x,n=this.m_localAnchor1.y-i.m_sweep.localCenter.y,s=t.col1.x*o+t.col2.x*n;n=t.col1.y*o+t.col2.y*n,o=s,t=e.m_xf.R;var r=this.m_localAnchor2.x-e.m_sweep.localCenter.x,a=this.m_localAnchor2.y-e.m_sweep.localCenter.y;s=t.col1.x*r+t.col2.x*a,a=t.col1.y*r+t.col2.y*a,r=s;var m=i.m_linearVelocity.x+-i.m_angularVelocity*n,l=i.m_linearVelocity.y+i.m_angularVelocity*o,c=e.m_linearVelocity.x+-e.m_angularVelocity*a,h=e.m_linearVelocity.y+e.m_angularVelocity*r,_=this.m_u.x*(c-m)+this.m_u.y*(h-l),p=-this.m_mass*(_+this.m_bias+this.m_gamma*this.m_impulse);this.m_impulse+=p;var y=p*this.m_u.x,u=p*this.m_u.y;i.m_linearVelocity.x-=i.m_invMass*y,i.m_linearVelocity.y-=i.m_invMass*u,i.m_angularVelocity-=i.m_invI*(o*u-n*y),e.m_linearVelocity.x+=e.m_invMass*y,e.m_linearVelocity.y+=e.m_invMass*u,e.m_angularVelocity+=e.m_invI*(r*u-a*y)},a.prototype.SolvePositionConstraints=function(i){void 0===i&&(i=0);var e;if(this.m_frequencyHz>0)return!0;var o=this.m_bodyA,s=this.m_bodyB;e=o.m_xf.R;var r=this.m_localAnchor1.x-o.m_sweep.localCenter.x,a=this.m_localAnchor1.y-o.m_sweep.localCenter.y,m=e.col1.x*r+e.col2.x*a;a=e.col1.y*r+e.col2.y*a,r=m,e=s.m_xf.R;var l=this.m_localAnchor2.x-s.m_sweep.localCenter.x,c=this.m_localAnchor2.y-s.m_sweep.localCenter.y;m=e.col1.x*l+e.col2.x*c,c=e.col1.y*l+e.col2.y*c,l=m;var h=s.m_sweep.c.x+l-o.m_sweep.c.x-r,_=s.m_sweep.c.y+c-o.m_sweep.c.y-a,p=Math.sqrt(h*h+_*_);h/=p,_/=p;var y=p-this.m_length;y=n.Clamp(y,-t.b2_maxLinearCorrection,t.b2_maxLinearCorrection);var u=-this.m_mass*y;this.m_u.Set(h,_);var x=u*this.m_u.x,f=u*this.m_u.y;return o.m_sweep.c.x-=o.m_invMass*x,o.m_sweep.c.y-=o.m_invMass*f,o.m_sweep.a-=o.m_invI*(r*f-a*x),s.m_sweep.c.x+=s.m_invMass*x,s.m_sweep.c.y+=s.m_invMass*f,s.m_sweep.a+=s.m_invI*(l*f-c*x),o.SynchronizeTransform(),s.SynchronizeTransform(),n.Abs(y)<t.b2_linearSlop},o.inherit(m,o.Dynamics.Joints.b2JointDef),m.prototype.__super=o.Dynamics.Joints.b2JointDef.prototype,m.b2DistanceJointDef=function(){o.Dynamics.Joints.b2JointDef.b2JointDef.apply(this,arguments),this.localAnchorA=new s,this.localAnchorB=new s},m.prototype.b2DistanceJointDef=function(){this.__super.b2JointDef.call(this),this.type=y.e_distanceJoint,this.length=1,this.frequencyHz=0,this.dampingRatio=0},m.prototype.Initialize=function(t,i,e,o){this.bodyA=t,this.bodyB=i,this.localAnchorA.SetV(this.bodyA.GetLocalPoint(e)),this.localAnchorB.SetV(this.bodyB.GetLocalPoint(o));var n=o.x-e.x,s=o.y-e.y;this.length=Math.sqrt(n*n+s*s),this.frequencyHz=0,this.dampingRatio=0
},o.inherit(l,o.Dynamics.Joints.b2Joint),l.prototype.__super=o.Dynamics.Joints.b2Joint.prototype,l.b2FrictionJoint=function(){o.Dynamics.Joints.b2Joint.b2Joint.apply(this,arguments),this.m_localAnchorA=new s,this.m_localAnchorB=new s,this.m_linearMass=new i,this.m_linearImpulse=new s},l.prototype.GetAnchorA=function(){return this.m_bodyA.GetWorldPoint(this.m_localAnchorA)},l.prototype.GetAnchorB=function(){return this.m_bodyB.GetWorldPoint(this.m_localAnchorB)},l.prototype.GetReactionForce=function(t){return void 0===t&&(t=0),new s(t*this.m_linearImpulse.x,t*this.m_linearImpulse.y)},l.prototype.GetReactionTorque=function(t){return void 0===t&&(t=0),t*this.m_angularImpulse},l.prototype.SetMaxForce=function(t){void 0===t&&(t=0),this.m_maxForce=t},l.prototype.GetMaxForce=function(){return this.m_maxForce},l.prototype.SetMaxTorque=function(t){void 0===t&&(t=0),this.m_maxTorque=t},l.prototype.GetMaxTorque=function(){return this.m_maxTorque},l.prototype.b2FrictionJoint=function(t){this.__super.b2Joint.call(this,t),this.m_localAnchorA.SetV(t.localAnchorA),this.m_localAnchorB.SetV(t.localAnchorB),this.m_linearMass.SetZero(),this.m_angularMass=0,this.m_linearImpulse.SetZero(),this.m_angularImpulse=0,this.m_maxForce=t.maxForce,this.m_maxTorque=t.maxTorque},l.prototype.InitVelocityConstraints=function(t){var e,o=0,n=this.m_bodyA,s=this.m_bodyB;e=n.m_xf.R;var r=this.m_localAnchorA.x-n.m_sweep.localCenter.x,a=this.m_localAnchorA.y-n.m_sweep.localCenter.y;o=e.col1.x*r+e.col2.x*a,a=e.col1.y*r+e.col2.y*a,r=o,e=s.m_xf.R;var m=this.m_localAnchorB.x-s.m_sweep.localCenter.x,l=this.m_localAnchorB.y-s.m_sweep.localCenter.y;o=e.col1.x*m+e.col2.x*l,l=e.col1.y*m+e.col2.y*l,m=o;var c=n.m_invMass,h=s.m_invMass,_=n.m_invI,p=s.m_invI,y=new i;if(y.col1.x=c+h,y.col2.x=0,y.col1.y=0,y.col2.y=c+h,y.col1.x+=_*a*a,y.col2.x+=-_*r*a,y.col1.y+=-_*r*a,y.col2.y+=_*r*r,y.col1.x+=p*l*l,y.col2.x+=-p*m*l,y.col1.y+=-p*m*l,y.col2.y+=p*m*m,y.GetInverse(this.m_linearMass),this.m_angularMass=_+p,this.m_angularMass>0&&(this.m_angularMass=1/this.m_angularMass),t.warmStarting){this.m_linearImpulse.x*=t.dtRatio,this.m_linearImpulse.y*=t.dtRatio,this.m_angularImpulse*=t.dtRatio;var u=this.m_linearImpulse;n.m_linearVelocity.x-=c*u.x,n.m_linearVelocity.y-=c*u.y,n.m_angularVelocity-=_*(r*u.y-a*u.x+this.m_angularImpulse),s.m_linearVelocity.x+=h*u.x,s.m_linearVelocity.y+=h*u.y,s.m_angularVelocity+=p*(m*u.y-l*u.x+this.m_angularImpulse)}else this.m_linearImpulse.SetZero(),this.m_angularImpulse=0},l.prototype.SolveVelocityConstraints=function(t){var i,e=0,o=this.m_bodyA,r=this.m_bodyB,a=o.m_linearVelocity,m=o.m_angularVelocity,l=r.m_linearVelocity,c=r.m_angularVelocity,h=o.m_invMass,_=r.m_invMass,p=o.m_invI,y=r.m_invI;i=o.m_xf.R;var u=this.m_localAnchorA.x-o.m_sweep.localCenter.x,x=this.m_localAnchorA.y-o.m_sweep.localCenter.y;e=i.col1.x*u+i.col2.x*x,x=i.col1.y*u+i.col2.y*x,u=e,i=r.m_xf.R;var f=this.m_localAnchorB.x-r.m_sweep.localCenter.x,d=this.m_localAnchorB.y-r.m_sweep.localCenter.y;e=i.col1.x*f+i.col2.x*d,d=i.col1.y*f+i.col2.y*d,f=e;var b=0,v=c-m,C=-this.m_angularMass*v,g=this.m_angularImpulse;b=t.dt*this.m_maxTorque,this.m_angularImpulse=n.Clamp(this.m_angularImpulse+C,-b,b),C=this.m_angularImpulse-g,m-=p*C,c+=y*C;var w=l.x-c*d-a.x+m*x,A=l.y+c*f-a.y-m*u,S=n.MulMV(this.m_linearMass,new s(-w,-A)),D=this.m_linearImpulse.Copy();this.m_linearImpulse.Add(S),b=t.dt*this.m_maxForce,this.m_linearImpulse.LengthSquared()>b*b&&(this.m_linearImpulse.Normalize(),this.m_linearImpulse.Multiply(b)),S=n.SubtractVV(this.m_linearImpulse,D),a.x-=h*S.x,a.y-=h*S.y,m-=p*(u*S.y-x*S.x),l.x+=_*S.x,l.y+=_*S.y,c+=y*(f*S.y-d*S.x),o.m_angularVelocity=m,r.m_angularVelocity=c},l.prototype.SolvePositionConstraints=function(t){return void 0===t&&(t=0),!0},o.inherit(c,o.Dynamics.Joints.b2JointDef),c.prototype.__super=o.Dynamics.Joints.b2JointDef.prototype,c.b2FrictionJointDef=function(){o.Dynamics.Joints.b2JointDef.b2JointDef.apply(this,arguments),this.localAnchorA=new s,this.localAnchorB=new s},c.prototype.b2FrictionJointDef=function(){this.__super.b2JointDef.call(this),this.type=y.e_frictionJoint,this.maxForce=0,this.maxTorque=0},c.prototype.Initialize=function(t,i,e){this.bodyA=t,this.bodyB=i,this.localAnchorA.SetV(this.bodyA.GetLocalPoint(e)),this.localAnchorB.SetV(this.bodyB.GetLocalPoint(e))},o.inherit(h,o.Dynamics.Joints.b2Joint),h.prototype.__super=o.Dynamics.Joints.b2Joint.prototype,h.b2GearJoint=function(){o.Dynamics.Joints.b2Joint.b2Joint.apply(this,arguments),this.m_groundAnchor1=new s,this.m_groundAnchor2=new s,this.m_localAnchor1=new s,this.m_localAnchor2=new s,this.m_J=new p},h.prototype.GetAnchorA=function(){return this.m_bodyA.GetWorldPoint(this.m_localAnchor1)},h.prototype.GetAnchorB=function(){return this.m_bodyB.GetWorldPoint(this.m_localAnchor2)},h.prototype.GetReactionForce=function(t){return void 0===t&&(t=0),new s(t*this.m_impulse*this.m_J.linearB.x,t*this.m_impulse*this.m_J.linearB.y)},h.prototype.GetReactionTorque=function(t){void 0===t&&(t=0);var i=this.m_bodyB.m_xf.R,e=this.m_localAnchor1.x-this.m_bodyB.m_sweep.localCenter.x,o=this.m_localAnchor1.y-this.m_bodyB.m_sweep.localCenter.y,n=i.col1.x*e+i.col2.x*o;o=i.col1.y*e+i.col2.y*o,e=n;var s=this.m_impulse*this.m_J.linearB.x,r=this.m_impulse*this.m_J.linearB.y;return t*(this.m_impulse*this.m_J.angularB-e*r+o*s)},h.prototype.GetRatio=function(){return this.m_ratio},h.prototype.SetRatio=function(t){void 0===t&&(t=0),this.m_ratio=t},h.prototype.b2GearJoint=function(t){this.__super.b2Joint.call(this,t);var i=parseInt(t.joint1.m_type),e=parseInt(t.joint2.m_type);this.m_revolute1=null,this.m_prismatic1=null,this.m_revolute2=null,this.m_prismatic2=null;var o=0,n=0;this.m_ground1=t.joint1.GetBodyA(),this.m_bodyA=t.joint1.GetBodyB(),i==y.e_revoluteJoint?(this.m_revolute1=t.joint1 instanceof S?t.joint1:null,this.m_groundAnchor1.SetV(this.m_revolute1.m_localAnchor1),this.m_localAnchor1.SetV(this.m_revolute1.m_localAnchor2),o=this.m_revolute1.GetJointAngle()):(this.m_prismatic1=t.joint1 instanceof C?t.joint1:null,this.m_groundAnchor1.SetV(this.m_prismatic1.m_localAnchor1),this.m_localAnchor1.SetV(this.m_prismatic1.m_localAnchor2),o=this.m_prismatic1.GetJointTranslation()),this.m_ground2=t.joint2.GetBodyA(),this.m_bodyB=t.joint2.GetBodyB(),e==y.e_revoluteJoint?(this.m_revolute2=t.joint2 instanceof S?t.joint2:null,this.m_groundAnchor2.SetV(this.m_revolute2.m_localAnchor1),this.m_localAnchor2.SetV(this.m_revolute2.m_localAnchor2),n=this.m_revolute2.GetJointAngle()):(this.m_prismatic2=t.joint2 instanceof C?t.joint2:null,this.m_groundAnchor2.SetV(this.m_prismatic2.m_localAnchor1),this.m_localAnchor2.SetV(this.m_prismatic2.m_localAnchor2),n=this.m_prismatic2.GetJointTranslation()),this.m_ratio=t.ratio,this.m_constant=o+this.m_ratio*n,this.m_impulse=0},h.prototype.InitVelocityConstraints=function(t){var i,e,o=this.m_ground1,n=this.m_ground2,s=this.m_bodyA,r=this.m_bodyB,a=0,m=0,l=0,c=0,h=0,_=0,p=0;this.m_J.SetZero(),this.m_revolute1?(this.m_J.angularA=-1,p+=s.m_invI):(i=o.m_xf.R,e=this.m_prismatic1.m_localXAxis1,a=i.col1.x*e.x+i.col2.x*e.y,m=i.col1.y*e.x+i.col2.y*e.y,i=s.m_xf.R,l=this.m_localAnchor1.x-s.m_sweep.localCenter.x,c=this.m_localAnchor1.y-s.m_sweep.localCenter.y,_=i.col1.x*l+i.col2.x*c,c=i.col1.y*l+i.col2.y*c,l=_,h=l*m-c*a,this.m_J.linearA.Set(-a,-m),this.m_J.angularA=-h,p+=s.m_invMass+s.m_invI*h*h),this.m_revolute2?(this.m_J.angularB=-this.m_ratio,p+=this.m_ratio*this.m_ratio*r.m_invI):(i=n.m_xf.R,e=this.m_prismatic2.m_localXAxis1,a=i.col1.x*e.x+i.col2.x*e.y,m=i.col1.y*e.x+i.col2.y*e.y,i=r.m_xf.R,l=this.m_localAnchor2.x-r.m_sweep.localCenter.x,c=this.m_localAnchor2.y-r.m_sweep.localCenter.y,_=i.col1.x*l+i.col2.x*c,c=i.col1.y*l+i.col2.y*c,l=_,h=l*m-c*a,this.m_J.linearB.Set(-this.m_ratio*a,-this.m_ratio*m),this.m_J.angularB=-this.m_ratio*h,p+=this.m_ratio*this.m_ratio*(r.m_invMass+r.m_invI*h*h)),this.m_mass=p>0?1/p:0,t.warmStarting?(s.m_linearVelocity.x+=s.m_invMass*this.m_impulse*this.m_J.linearA.x,s.m_linearVelocity.y+=s.m_invMass*this.m_impulse*this.m_J.linearA.y,s.m_angularVelocity+=s.m_invI*this.m_impulse*this.m_J.angularA,r.m_linearVelocity.x+=r.m_invMass*this.m_impulse*this.m_J.linearB.x,r.m_linearVelocity.y+=r.m_invMass*this.m_impulse*this.m_J.linearB.y,r.m_angularVelocity+=r.m_invI*this.m_impulse*this.m_J.angularB):this.m_impulse=0},h.prototype.SolveVelocityConstraints=function(){var t=this.m_bodyA,i=this.m_bodyB,e=this.m_J.Compute(t.m_linearVelocity,t.m_angularVelocity,i.m_linearVelocity,i.m_angularVelocity),o=-this.m_mass*e;this.m_impulse+=o,t.m_linearVelocity.x+=t.m_invMass*o*this.m_J.linearA.x,t.m_linearVelocity.y+=t.m_invMass*o*this.m_J.linearA.y,t.m_angularVelocity+=t.m_invI*o*this.m_J.angularA,i.m_linearVelocity.x+=i.m_invMass*o*this.m_J.linearB.x,i.m_linearVelocity.y+=i.m_invMass*o*this.m_J.linearB.y,i.m_angularVelocity+=i.m_invI*o*this.m_J.angularB},h.prototype.SolvePositionConstraints=function(i){void 0===i&&(i=0);var e=0,o=this.m_bodyA,n=this.m_bodyB,s=0,r=0;s=this.m_revolute1?this.m_revolute1.GetJointAngle():this.m_prismatic1.GetJointTranslation(),r=this.m_revolute2?this.m_revolute2.GetJointAngle():this.m_prismatic2.GetJointTranslation();var a=this.m_constant-(s+this.m_ratio*r),m=-this.m_mass*a;return o.m_sweep.c.x+=o.m_invMass*m*this.m_J.linearA.x,o.m_sweep.c.y+=o.m_invMass*m*this.m_J.linearA.y,o.m_sweep.a+=o.m_invI*m*this.m_J.angularA,n.m_sweep.c.x+=n.m_invMass*m*this.m_J.linearB.x,n.m_sweep.c.y+=n.m_invMass*m*this.m_J.linearB.y,n.m_sweep.a+=n.m_invI*m*this.m_J.angularB,o.SynchronizeTransform(),n.SynchronizeTransform(),t.b2_linearSlop>e},o.inherit(_,o.Dynamics.Joints.b2JointDef),_.prototype.__super=o.Dynamics.Joints.b2JointDef.prototype,_.b2GearJointDef=function(){o.Dynamics.Joints.b2JointDef.b2JointDef.apply(this,arguments)},_.prototype.b2GearJointDef=function(){this.__super.b2JointDef.call(this),this.type=y.e_gearJoint,this.joint1=null,this.joint2=null,this.ratio=1},p.b2Jacobian=function(){this.linearA=new s,this.linearB=new s},p.prototype.SetZero=function(){this.linearA.SetZero(),this.angularA=0,this.linearB.SetZero(),this.angularB=0},p.prototype.Set=function(t,i,e,o){void 0===i&&(i=0),void 0===o&&(o=0),this.linearA.SetV(t),this.angularA=i,this.linearB.SetV(e),this.angularB=o},p.prototype.Compute=function(t,i,e,o){return void 0===i&&(i=0),void 0===o&&(o=0),this.linearA.x*t.x+this.linearA.y*t.y+this.angularA*i+(this.linearB.x*e.x+this.linearB.y*e.y)+this.angularB*o},y.b2Joint=function(){this.m_edgeA=new x,this.m_edgeB=new x,this.m_localCenterA=new s,this.m_localCenterB=new s},y.prototype.GetType=function(){return this.m_type},y.prototype.GetAnchorA=function(){return null},y.prototype.GetAnchorB=function(){return null},y.prototype.GetReactionForce=function(t){return void 0===t&&(t=0),null},y.prototype.GetReactionTorque=function(t){return void 0===t&&(t=0),0},y.prototype.GetBodyA=function(){return this.m_bodyA},y.prototype.GetBodyB=function(){return this.m_bodyB},y.prototype.GetNext=function(){return this.m_next},y.prototype.GetUserData=function(){return this.m_userData},y.prototype.SetUserData=function(t){this.m_userData=t},y.prototype.IsActive=function(){return this.m_bodyA.IsActive()&&this.m_bodyB.IsActive()},y.Create=function(t){var i=null;switch(t.type){case y.e_distanceJoint:i=new a(t instanceof m?t:null);break;case y.e_mouseJoint:i=new b(t instanceof v?t:null);break;case y.e_prismaticJoint:i=new C(t instanceof g?t:null);break;case y.e_revoluteJoint:i=new S(t instanceof D?t:null);break;case y.e_pulleyJoint:i=new w(t instanceof A?t:null);break;case y.e_gearJoint:i=new h(t instanceof _?t:null);break;case y.e_lineJoint:i=new f(t instanceof d?t:null);break;case y.e_weldJoint:i=new B(t instanceof M?t:null);break;case y.e_frictionJoint:i=new l(t instanceof c?t:null);break;default:}return i},y.Destroy=function(){},y.prototype.b2Joint=function(i){t.b2Assert(i.bodyA!=i.bodyB),this.m_type=i.type,this.m_prev=null,this.m_next=null,this.m_bodyA=i.bodyA,this.m_bodyB=i.bodyB,this.m_collideConnected=i.collideConnected,this.m_islandFlag=!1,this.m_userData=i.userData},y.prototype.InitVelocityConstraints=function(){},y.prototype.SolveVelocityConstraints=function(){},y.prototype.FinalizeVelocityConstraints=function(){},y.prototype.SolvePositionConstraints=function(t){return void 0===t&&(t=0),!1},o.postDefs.push(function(){o.Dynamics.Joints.b2Joint.e_unknownJoint=0,o.Dynamics.Joints.b2Joint.e_revoluteJoint=1,o.Dynamics.Joints.b2Joint.e_prismaticJoint=2,o.Dynamics.Joints.b2Joint.e_distanceJoint=3,o.Dynamics.Joints.b2Joint.e_pulleyJoint=4,o.Dynamics.Joints.b2Joint.e_mouseJoint=5,o.Dynamics.Joints.b2Joint.e_gearJoint=6,o.Dynamics.Joints.b2Joint.e_lineJoint=7,o.Dynamics.Joints.b2Joint.e_weldJoint=8,o.Dynamics.Joints.b2Joint.e_frictionJoint=9,o.Dynamics.Joints.b2Joint.e_inactiveLimit=0,o.Dynamics.Joints.b2Joint.e_atLowerLimit=1,o.Dynamics.Joints.b2Joint.e_atUpperLimit=2,o.Dynamics.Joints.b2Joint.e_equalLimits=3}),u.b2JointDef=function(){},u.prototype.b2JointDef=function(){this.type=y.e_unknownJoint,this.userData=null,this.bodyA=null,this.bodyB=null,this.collideConnected=!1},x.b2JointEdge=function(){},o.inherit(f,o.Dynamics.Joints.b2Joint),f.prototype.__super=o.Dynamics.Joints.b2Joint.prototype,f.b2LineJoint=function(){o.Dynamics.Joints.b2Joint.b2Joint.apply(this,arguments),this.m_localAnchor1=new s,this.m_localAnchor2=new s,this.m_localXAxis1=new s,this.m_localYAxis1=new s,this.m_axis=new s,this.m_perp=new s,this.m_K=new i,this.m_impulse=new s},f.prototype.GetAnchorA=function(){return this.m_bodyA.GetWorldPoint(this.m_localAnchor1)},f.prototype.GetAnchorB=function(){return this.m_bodyB.GetWorldPoint(this.m_localAnchor2)},f.prototype.GetReactionForce=function(t){return void 0===t&&(t=0),new s(t*(this.m_impulse.x*this.m_perp.x+(this.m_motorImpulse+this.m_impulse.y)*this.m_axis.x),t*(this.m_impulse.x*this.m_perp.y+(this.m_motorImpulse+this.m_impulse.y)*this.m_axis.y))},f.prototype.GetReactionTorque=function(t){return void 0===t&&(t=0),t*this.m_impulse.y},f.prototype.GetJointTranslation=function(){var t=this.m_bodyA,i=this.m_bodyB,e=t.GetWorldPoint(this.m_localAnchor1),o=i.GetWorldPoint(this.m_localAnchor2),n=o.x-e.x,s=o.y-e.y,r=t.GetWorldVector(this.m_localXAxis1),a=r.x*n+r.y*s;return a},f.prototype.GetJointSpeed=function(){var t,i=this.m_bodyA,e=this.m_bodyB;t=i.m_xf.R;var o=this.m_localAnchor1.x-i.m_sweep.localCenter.x,n=this.m_localAnchor1.y-i.m_sweep.localCenter.y,s=t.col1.x*o+t.col2.x*n;n=t.col1.y*o+t.col2.y*n,o=s,t=e.m_xf.R;var r=this.m_localAnchor2.x-e.m_sweep.localCenter.x,a=this.m_localAnchor2.y-e.m_sweep.localCenter.y;s=t.col1.x*r+t.col2.x*a,a=t.col1.y*r+t.col2.y*a,r=s;var m=i.m_sweep.c.x+o,l=i.m_sweep.c.y+n,c=e.m_sweep.c.x+r,h=e.m_sweep.c.y+a,_=c-m,p=h-l,y=i.GetWorldVector(this.m_localXAxis1),u=i.m_linearVelocity,x=e.m_linearVelocity,f=i.m_angularVelocity,d=e.m_angularVelocity,b=_*-f*y.y+p*f*y.x+(y.x*(x.x+-d*a-u.x- -f*n)+y.y*(x.y+d*r-u.y-f*o));return b},f.prototype.IsLimitEnabled=function(){return this.m_enableLimit},f.prototype.EnableLimit=function(t){this.m_bodyA.SetAwake(!0),this.m_bodyB.SetAwake(!0),this.m_enableLimit=t},f.prototype.GetLowerLimit=function(){return this.m_lowerTranslation},f.prototype.GetUpperLimit=function(){return this.m_upperTranslation},f.prototype.SetLimits=function(t,i){void 0===t&&(t=0),void 0===i&&(i=0),this.m_bodyA.SetAwake(!0),this.m_bodyB.SetAwake(!0),this.m_lowerTranslation=t,this.m_upperTranslation=i},f.prototype.IsMotorEnabled=function(){return this.m_enableMotor},f.prototype.EnableMotor=function(t){this.m_bodyA.SetAwake(!0),this.m_bodyB.SetAwake(!0),this.m_enableMotor=t},f.prototype.SetMotorSpeed=function(t){void 0===t&&(t=0),this.m_bodyA.SetAwake(!0),this.m_bodyB.SetAwake(!0),this.m_motorSpeed=t},f.prototype.GetMotorSpeed=function(){return this.m_motorSpeed},f.prototype.SetMaxMotorForce=function(t){void 0===t&&(t=0),this.m_bodyA.SetAwake(!0),this.m_bodyB.SetAwake(!0),this.m_maxMotorForce=t},f.prototype.GetMaxMotorForce=function(){return this.m_maxMotorForce},f.prototype.GetMotorForce=function(){return this.m_motorImpulse},f.prototype.b2LineJoint=function(t){this.__super.b2Joint.call(this,t),this.m_localAnchor1.SetV(t.localAnchorA),this.m_localAnchor2.SetV(t.localAnchorB),this.m_localXAxis1.SetV(t.localAxisA),this.m_localYAxis1.x=-this.m_localXAxis1.y,this.m_localYAxis1.y=this.m_localXAxis1.x,this.m_impulse.SetZero(),this.m_motorMass=0,this.m_motorImpulse=0,this.m_lowerTranslation=t.lowerTranslation,this.m_upperTranslation=t.upperTranslation,this.m_maxMotorForce=t.maxMotorForce,this.m_motorSpeed=t.motorSpeed,this.m_enableLimit=t.enableLimit,this.m_enableMotor=t.enableMotor,this.m_limitState=y.e_inactiveLimit,this.m_axis.SetZero(),this.m_perp.SetZero()},f.prototype.InitVelocityConstraints=function(i){var e,o=this.m_bodyA,s=this.m_bodyB,r=0;this.m_localCenterA.SetV(o.GetLocalCenter()),this.m_localCenterB.SetV(s.GetLocalCenter());var a=o.GetTransform();s.GetTransform(),e=o.m_xf.R;var m=this.m_localAnchor1.x-this.m_localCenterA.x,l=this.m_localAnchor1.y-this.m_localCenterA.y;r=e.col1.x*m+e.col2.x*l,l=e.col1.y*m+e.col2.y*l,m=r,e=s.m_xf.R;var c=this.m_localAnchor2.x-this.m_localCenterB.x,h=this.m_localAnchor2.y-this.m_localCenterB.y;r=e.col1.x*c+e.col2.x*h,h=e.col1.y*c+e.col2.y*h,c=r;var _=s.m_sweep.c.x+c-o.m_sweep.c.x-m,p=s.m_sweep.c.y+h-o.m_sweep.c.y-l;this.m_invMassA=o.m_invMass,this.m_invMassB=s.m_invMass,this.m_invIA=o.m_invI,this.m_invIB=s.m_invI,this.m_axis.SetV(n.MulMV(a.R,this.m_localXAxis1)),this.m_a1=(_+m)*this.m_axis.y-(p+l)*this.m_axis.x,this.m_a2=c*this.m_axis.y-h*this.m_axis.x,this.m_motorMass=this.m_invMassA+this.m_invMassB+this.m_invIA*this.m_a1*this.m_a1+this.m_invIB*this.m_a2*this.m_a2,this.m_motorMass=this.m_motorMass>Number.MIN_VALUE?1/this.m_motorMass:0,this.m_perp.SetV(n.MulMV(a.R,this.m_localYAxis1)),this.m_s1=(_+m)*this.m_perp.y-(p+l)*this.m_perp.x,this.m_s2=c*this.m_perp.y-h*this.m_perp.x;var u=this.m_invMassA,x=this.m_invMassB,f=this.m_invIA,d=this.m_invIB;if(this.m_K.col1.x=u+x+f*this.m_s1*this.m_s1+d*this.m_s2*this.m_s2,this.m_K.col1.y=f*this.m_s1*this.m_a1+d*this.m_s2*this.m_a2,this.m_K.col2.x=this.m_K.col1.y,this.m_K.col2.y=u+x+f*this.m_a1*this.m_a1+d*this.m_a2*this.m_a2,this.m_enableLimit){var b=this.m_axis.x*_+this.m_axis.y*p;n.Abs(this.m_upperTranslation-this.m_lowerTranslation)<2*t.b2_linearSlop?this.m_limitState=y.e_equalLimits:this.m_lowerTranslation>=b?this.m_limitState!=y.e_atLowerLimit&&(this.m_limitState=y.e_atLowerLimit,this.m_impulse.y=0):b>=this.m_upperTranslation?this.m_limitState!=y.e_atUpperLimit&&(this.m_limitState=y.e_atUpperLimit,this.m_impulse.y=0):(this.m_limitState=y.e_inactiveLimit,this.m_impulse.y=0)}else this.m_limitState=y.e_inactiveLimit;if(0==this.m_enableMotor&&(this.m_motorImpulse=0),i.warmStarting){this.m_impulse.x*=i.dtRatio,this.m_impulse.y*=i.dtRatio,this.m_motorImpulse*=i.dtRatio;var v=this.m_impulse.x*this.m_perp.x+(this.m_motorImpulse+this.m_impulse.y)*this.m_axis.x,C=this.m_impulse.x*this.m_perp.y+(this.m_motorImpulse+this.m_impulse.y)*this.m_axis.y,g=this.m_impulse.x*this.m_s1+(this.m_motorImpulse+this.m_impulse.y)*this.m_a1,w=this.m_impulse.x*this.m_s2+(this.m_motorImpulse+this.m_impulse.y)*this.m_a2;o.m_linearVelocity.x-=this.m_invMassA*v,o.m_linearVelocity.y-=this.m_invMassA*C,o.m_angularVelocity-=this.m_invIA*g,s.m_linearVelocity.x+=this.m_invMassB*v,s.m_linearVelocity.y+=this.m_invMassB*C,s.m_angularVelocity+=this.m_invIB*w}else this.m_impulse.SetZero(),this.m_motorImpulse=0},f.prototype.SolveVelocityConstraints=function(t){var i=this.m_bodyA,e=this.m_bodyB,o=i.m_linearVelocity,r=i.m_angularVelocity,a=e.m_linearVelocity,m=e.m_angularVelocity,l=0,c=0,h=0,_=0;if(this.m_enableMotor&&this.m_limitState!=y.e_equalLimits){var p=this.m_axis.x*(a.x-o.x)+this.m_axis.y*(a.y-o.y)+this.m_a2*m-this.m_a1*r,u=this.m_motorMass*(this.m_motorSpeed-p),x=this.m_motorImpulse,f=t.dt*this.m_maxMotorForce;this.m_motorImpulse=n.Clamp(this.m_motorImpulse+u,-f,f),u=this.m_motorImpulse-x,l=u*this.m_axis.x,c=u*this.m_axis.y,h=u*this.m_a1,_=u*this.m_a2,o.x-=this.m_invMassA*l,o.y-=this.m_invMassA*c,r-=this.m_invIA*h,a.x+=this.m_invMassB*l,a.y+=this.m_invMassB*c,m+=this.m_invIB*_}var d=this.m_perp.x*(a.x-o.x)+this.m_perp.y*(a.y-o.y)+this.m_s2*m-this.m_s1*r;if(this.m_enableLimit&&this.m_limitState!=y.e_inactiveLimit){var b=this.m_axis.x*(a.x-o.x)+this.m_axis.y*(a.y-o.y)+this.m_a2*m-this.m_a1*r,v=this.m_impulse.Copy(),C=this.m_K.Solve(new s,-d,-b);this.m_impulse.Add(C),this.m_limitState==y.e_atLowerLimit?this.m_impulse.y=n.Max(this.m_impulse.y,0):this.m_limitState==y.e_atUpperLimit&&(this.m_impulse.y=n.Min(this.m_impulse.y,0));var g=-d-(this.m_impulse.y-v.y)*this.m_K.col2.x,w=0;w=0!=this.m_K.col1.x?g/this.m_K.col1.x+v.x:v.x,this.m_impulse.x=w,C.x=this.m_impulse.x-v.x,C.y=this.m_impulse.y-v.y,l=C.x*this.m_perp.x+C.y*this.m_axis.x,c=C.x*this.m_perp.y+C.y*this.m_axis.y,h=C.x*this.m_s1+C.y*this.m_a1,_=C.x*this.m_s2+C.y*this.m_a2,o.x-=this.m_invMassA*l,o.y-=this.m_invMassA*c,r-=this.m_invIA*h,a.x+=this.m_invMassB*l,a.y+=this.m_invMassB*c,m+=this.m_invIB*_}else{var A=0;A=0!=this.m_K.col1.x?-d/this.m_K.col1.x:0,this.m_impulse.x+=A,l=A*this.m_perp.x,c=A*this.m_perp.y,h=A*this.m_s1,_=A*this.m_s2,o.x-=this.m_invMassA*l,o.y-=this.m_invMassA*c,r-=this.m_invIA*h,a.x+=this.m_invMassB*l,a.y+=this.m_invMassB*c,m+=this.m_invIB*_}i.m_linearVelocity.SetV(o),i.m_angularVelocity=r,e.m_linearVelocity.SetV(a),e.m_angularVelocity=m},f.prototype.SolvePositionConstraints=function(e){void 0===e&&(e=0);var o,r=this.m_bodyA,a=this.m_bodyB,m=r.m_sweep.c,l=r.m_sweep.a,c=a.m_sweep.c,h=a.m_sweep.a,_=0,p=0,y=0,u=0,x=0,f=0,d=0,b=!1,v=0,C=i.FromAngle(l),g=i.FromAngle(h);o=C;var w=this.m_localAnchor1.x-this.m_localCenterA.x,A=this.m_localAnchor1.y-this.m_localCenterA.y;_=o.col1.x*w+o.col2.x*A,A=o.col1.y*w+o.col2.y*A,w=_,o=g;var S=this.m_localAnchor2.x-this.m_localCenterB.x,D=this.m_localAnchor2.y-this.m_localCenterB.y;_=o.col1.x*S+o.col2.x*D,D=o.col1.y*S+o.col2.y*D,S=_;var B=c.x+S-m.x-w,M=c.y+D-m.y-A;if(this.m_enableLimit){this.m_axis=n.MulMV(C,this.m_localXAxis1),this.m_a1=(B+w)*this.m_axis.y-(M+A)*this.m_axis.x,this.m_a2=S*this.m_axis.y-D*this.m_axis.x;var V=this.m_axis.x*B+this.m_axis.y*M;n.Abs(this.m_upperTranslation-this.m_lowerTranslation)<2*t.b2_linearSlop?(v=n.Clamp(V,-t.b2_maxLinearCorrection,t.b2_maxLinearCorrection),f=n.Abs(V),b=!0):this.m_lowerTranslation>=V?(v=n.Clamp(V-this.m_lowerTranslation+t.b2_linearSlop,-t.b2_maxLinearCorrection,0),f=this.m_lowerTranslation-V,b=!0):V>=this.m_upperTranslation&&(v=n.Clamp(V-this.m_upperTranslation+t.b2_linearSlop,0,t.b2_maxLinearCorrection),f=V-this.m_upperTranslation,b=!0)}this.m_perp=n.MulMV(C,this.m_localYAxis1),this.m_s1=(B+w)*this.m_perp.y-(M+A)*this.m_perp.x,this.m_s2=S*this.m_perp.y-D*this.m_perp.x;var I=new s,G=this.m_perp.x*B+this.m_perp.y*M;if(f=n.Max(f,n.Abs(G)),d=0,b)p=this.m_invMassA,y=this.m_invMassB,u=this.m_invIA,x=this.m_invIB,this.m_K.col1.x=p+y+u*this.m_s1*this.m_s1+x*this.m_s2*this.m_s2,this.m_K.col1.y=u*this.m_s1*this.m_a1+x*this.m_s2*this.m_a2,this.m_K.col2.x=this.m_K.col1.y,this.m_K.col2.y=p+y+u*this.m_a1*this.m_a1+x*this.m_a2*this.m_a2,this.m_K.Solve(I,-G,-v);else{p=this.m_invMassA,y=this.m_invMassB,u=this.m_invIA,x=this.m_invIB;var L=p+y+u*this.m_s1*this.m_s1+x*this.m_s2*this.m_s2,J=0;J=0!=L?-G/L:0,I.x=J,I.y=0}var F=I.x*this.m_perp.x+I.y*this.m_axis.x,P=I.x*this.m_perp.y+I.y*this.m_axis.y,T=I.x*this.m_s1+I.y*this.m_a1,R=I.x*this.m_s2+I.y*this.m_a2;return m.x-=this.m_invMassA*F,m.y-=this.m_invMassA*P,l-=this.m_invIA*T,c.x+=this.m_invMassB*F,c.y+=this.m_invMassB*P,h+=this.m_invIB*R,r.m_sweep.a=l,a.m_sweep.a=h,r.SynchronizeTransform(),a.SynchronizeTransform(),t.b2_linearSlop>=f&&t.b2_angularSlop>=d},o.inherit(d,o.Dynamics.Joints.b2JointDef),d.prototype.__super=o.Dynamics.Joints.b2JointDef.prototype,d.b2LineJointDef=function(){o.Dynamics.Joints.b2JointDef.b2JointDef.apply(this,arguments),this.localAnchorA=new s,this.localAnchorB=new s,this.localAxisA=new s},d.prototype.b2LineJointDef=function(){this.__super.b2JointDef.call(this),this.type=y.e_lineJoint,this.localAxisA.Set(1,0),this.enableLimit=!1,this.lowerTranslation=0,this.upperTranslation=0,this.enableMotor=!1,this.maxMotorForce=0,this.motorSpeed=0},d.prototype.Initialize=function(t,i,e,o){this.bodyA=t,this.bodyB=i,this.localAnchorA=this.bodyA.GetLocalPoint(e),this.localAnchorB=this.bodyB.GetLocalPoint(e),this.localAxisA=this.bodyA.GetLocalVector(o)},o.inherit(b,o.Dynamics.Joints.b2Joint),b.prototype.__super=o.Dynamics.Joints.b2Joint.prototype,b.b2MouseJoint=function(){o.Dynamics.Joints.b2Joint.b2Joint.apply(this,arguments),this.K=new i,this.K1=new i,this.K2=new i,this.m_localAnchor=new s,this.m_target=new s,this.m_impulse=new s,this.m_mass=new i,this.m_C=new s},b.prototype.GetAnchorA=function(){return this.m_target},b.prototype.GetAnchorB=function(){return this.m_bodyB.GetWorldPoint(this.m_localAnchor)},b.prototype.GetReactionForce=function(t){return void 0===t&&(t=0),new s(t*this.m_impulse.x,t*this.m_impulse.y)},b.prototype.GetReactionTorque=function(t){return void 0===t&&(t=0),0},b.prototype.GetTarget=function(){return this.m_target},b.prototype.SetTarget=function(t){0==this.m_bodyB.IsAwake()&&this.m_bodyB.SetAwake(!0),this.m_target=t},b.prototype.GetMaxForce=function(){return this.m_maxForce},b.prototype.SetMaxForce=function(t){void 0===t&&(t=0),this.m_maxForce=t},b.prototype.GetFrequency=function(){return this.m_frequencyHz},b.prototype.SetFrequency=function(t){void 0===t&&(t=0),this.m_frequencyHz=t},b.prototype.GetDampingRatio=function(){return this.m_dampingRatio},b.prototype.SetDampingRatio=function(t){void 0===t&&(t=0),this.m_dampingRatio=t},b.prototype.b2MouseJoint=function(t){this.__super.b2Joint.call(this,t),this.m_target.SetV(t.target);var i=this.m_target.x-this.m_bodyB.m_xf.position.x,e=this.m_target.y-this.m_bodyB.m_xf.position.y,o=this.m_bodyB.m_xf.R;this.m_localAnchor.x=i*o.col1.x+e*o.col1.y,this.m_localAnchor.y=i*o.col2.x+e*o.col2.y,this.m_maxForce=t.maxForce,this.m_impulse.SetZero(),this.m_frequencyHz=t.frequencyHz,this.m_dampingRatio=t.dampingRatio,this.m_beta=0,this.m_gamma=0},b.prototype.InitVelocityConstraints=function(t){var i=this.m_bodyB,e=i.GetMass(),o=2*Math.PI*this.m_frequencyHz,n=2*e*this.m_dampingRatio*o,s=e*o*o;this.m_gamma=t.dt*(n+t.dt*s),this.m_gamma=0!=this.m_gamma?1/this.m_gamma:0,this.m_beta=t.dt*s*this.m_gamma;var r;r=i.m_xf.R;var a=this.m_localAnchor.x-i.m_sweep.localCenter.x,m=this.m_localAnchor.y-i.m_sweep.localCenter.y,l=r.col1.x*a+r.col2.x*m;m=r.col1.y*a+r.col2.y*m,a=l;var c=i.m_invMass,h=i.m_invI;this.K1.col1.x=c,this.K1.col2.x=0,this.K1.col1.y=0,this.K1.col2.y=c,this.K2.col1.x=h*m*m,this.K2.col2.x=-h*a*m,this.K2.col1.y=-h*a*m,this.K2.col2.y=h*a*a,this.K.SetM(this.K1),this.K.AddM(this.K2),this.K.col1.x+=this.m_gamma,this.K.col2.y+=this.m_gamma,this.K.GetInverse(this.m_mass),this.m_C.x=i.m_sweep.c.x+a-this.m_target.x,this.m_C.y=i.m_sweep.c.y+m-this.m_target.y,i.m_angularVelocity*=.98,this.m_impulse.x*=t.dtRatio,this.m_impulse.y*=t.dtRatio,i.m_linearVelocity.x+=c*this.m_impulse.x,i.m_linearVelocity.y+=c*this.m_impulse.y,i.m_angularVelocity+=h*(a*this.m_impulse.y-m*this.m_impulse.x)},b.prototype.SolveVelocityConstraints=function(t){var i,e=this.m_bodyB,o=0,n=0;i=e.m_xf.R;var s=this.m_localAnchor.x-e.m_sweep.localCenter.x,r=this.m_localAnchor.y-e.m_sweep.localCenter.y;o=i.col1.x*s+i.col2.x*r,r=i.col1.y*s+i.col2.y*r,s=o;var a=e.m_linearVelocity.x+-e.m_angularVelocity*r,m=e.m_linearVelocity.y+e.m_angularVelocity*s;i=this.m_mass,o=a+this.m_beta*this.m_C.x+this.m_gamma*this.m_impulse.x,n=m+this.m_beta*this.m_C.y+this.m_gamma*this.m_impulse.y;var l=-(i.col1.x*o+i.col2.x*n),c=-(i.col1.y*o+i.col2.y*n),h=this.m_impulse.x,_=this.m_impulse.y;this.m_impulse.x+=l,this.m_impulse.y+=c;var p=t.dt*this.m_maxForce;this.m_impulse.LengthSquared()>p*p&&this.m_impulse.Multiply(p/this.m_impulse.Length()),l=this.m_impulse.x-h,c=this.m_impulse.y-_,e.m_linearVelocity.x+=e.m_invMass*l,e.m_linearVelocity.y+=e.m_invMass*c,e.m_angularVelocity+=e.m_invI*(s*c-r*l)},b.prototype.SolvePositionConstraints=function(t){return void 0===t&&(t=0),!0},o.inherit(v,o.Dynamics.Joints.b2JointDef),v.prototype.__super=o.Dynamics.Joints.b2JointDef.prototype,v.b2MouseJointDef=function(){o.Dynamics.Joints.b2JointDef.b2JointDef.apply(this,arguments),this.target=new s},v.prototype.b2MouseJointDef=function(){this.__super.b2JointDef.call(this),this.type=y.e_mouseJoint,this.maxForce=0,this.frequencyHz=5,this.dampingRatio=.7},o.inherit(C,o.Dynamics.Joints.b2Joint),C.prototype.__super=o.Dynamics.Joints.b2Joint.prototype,C.b2PrismaticJoint=function(){o.Dynamics.Joints.b2Joint.b2Joint.apply(this,arguments),this.m_localAnchor1=new s,this.m_localAnchor2=new s,this.m_localXAxis1=new s,this.m_localYAxis1=new s,this.m_axis=new s,this.m_perp=new s,this.m_K=new e,this.m_impulse=new r},C.prototype.GetAnchorA=function(){return this.m_bodyA.GetWorldPoint(this.m_localAnchor1)},C.prototype.GetAnchorB=function(){return this.m_bodyB.GetWorldPoint(this.m_localAnchor2)},C.prototype.GetReactionForce=function(t){return void 0===t&&(t=0),new s(t*(this.m_impulse.x*this.m_perp.x+(this.m_motorImpulse+this.m_impulse.z)*this.m_axis.x),t*(this.m_impulse.x*this.m_perp.y+(this.m_motorImpulse+this.m_impulse.z)*this.m_axis.y))},C.prototype.GetReactionTorque=function(t){return void 0===t&&(t=0),t*this.m_impulse.y},C.prototype.GetJointTranslation=function(){var t=this.m_bodyA,i=this.m_bodyB,e=t.GetWorldPoint(this.m_localAnchor1),o=i.GetWorldPoint(this.m_localAnchor2),n=o.x-e.x,s=o.y-e.y,r=t.GetWorldVector(this.m_localXAxis1),a=r.x*n+r.y*s;return a},C.prototype.GetJointSpeed=function(){var t,i=this.m_bodyA,e=this.m_bodyB;t=i.m_xf.R;var o=this.m_localAnchor1.x-i.m_sweep.localCenter.x,n=this.m_localAnchor1.y-i.m_sweep.localCenter.y,s=t.col1.x*o+t.col2.x*n;n=t.col1.y*o+t.col2.y*n,o=s,t=e.m_xf.R;var r=this.m_localAnchor2.x-e.m_sweep.localCenter.x,a=this.m_localAnchor2.y-e.m_sweep.localCenter.y;s=t.col1.x*r+t.col2.x*a,a=t.col1.y*r+t.col2.y*a,r=s;var m=i.m_sweep.c.x+o,l=i.m_sweep.c.y+n,c=e.m_sweep.c.x+r,h=e.m_sweep.c.y+a,_=c-m,p=h-l,y=i.GetWorldVector(this.m_localXAxis1),u=i.m_linearVelocity,x=e.m_linearVelocity,f=i.m_angularVelocity,d=e.m_angularVelocity,b=_*-f*y.y+p*f*y.x+(y.x*(x.x+-d*a-u.x- -f*n)+y.y*(x.y+d*r-u.y-f*o));return b},C.prototype.IsLimitEnabled=function(){return this.m_enableLimit},C.prototype.EnableLimit=function(t){this.m_bodyA.SetAwake(!0),this.m_bodyB.SetAwake(!0),this.m_enableLimit=t},C.prototype.GetLowerLimit=function(){return this.m_lowerTranslation},C.prototype.GetUpperLimit=function(){return this.m_upperTranslation},C.prototype.SetLimits=function(t,i){void 0===t&&(t=0),void 0===i&&(i=0),this.m_bodyA.SetAwake(!0),this.m_bodyB.SetAwake(!0),this.m_lowerTranslation=t,this.m_upperTranslation=i},C.prototype.IsMotorEnabled=function(){return this.m_enableMotor},C.prototype.EnableMotor=function(t){this.m_bodyA.SetAwake(!0),this.m_bodyB.SetAwake(!0),this.m_enableMotor=t},C.prototype.SetMotorSpeed=function(t){void 0===t&&(t=0),this.m_bodyA.SetAwake(!0),this.m_bodyB.SetAwake(!0),this.m_motorSpeed=t},C.prototype.GetMotorSpeed=function(){return this.m_motorSpeed},C.prototype.SetMaxMotorForce=function(t){void 0===t&&(t=0),this.m_bodyA.SetAwake(!0),this.m_bodyB.SetAwake(!0),this.m_maxMotorForce=t},C.prototype.GetMotorForce=function(){return this.m_motorImpulse},C.prototype.b2PrismaticJoint=function(t){this.__super.b2Joint.call(this,t),this.m_localAnchor1.SetV(t.localAnchorA),this.m_localAnchor2.SetV(t.localAnchorB),this.m_localXAxis1.SetV(t.localAxisA),this.m_localYAxis1.x=-this.m_localXAxis1.y,this.m_localYAxis1.y=this.m_localXAxis1.x,this.m_refAngle=t.referenceAngle,this.m_impulse.SetZero(),this.m_motorMass=0,this.m_motorImpulse=0,this.m_lowerTranslation=t.lowerTranslation,this.m_upperTranslation=t.upperTranslation,this.m_maxMotorForce=t.maxMotorForce,this.m_motorSpeed=t.motorSpeed,this.m_enableLimit=t.enableLimit,this.m_enableMotor=t.enableMotor,this.m_limitState=y.e_inactiveLimit,this.m_axis.SetZero(),this.m_perp.SetZero()},C.prototype.InitVelocityConstraints=function(i){var e,o=this.m_bodyA,s=this.m_bodyB,r=0;this.m_localCenterA.SetV(o.GetLocalCenter()),this.m_localCenterB.SetV(s.GetLocalCenter());
var a=o.GetTransform();s.GetTransform(),e=o.m_xf.R;var m=this.m_localAnchor1.x-this.m_localCenterA.x,l=this.m_localAnchor1.y-this.m_localCenterA.y;r=e.col1.x*m+e.col2.x*l,l=e.col1.y*m+e.col2.y*l,m=r,e=s.m_xf.R;var c=this.m_localAnchor2.x-this.m_localCenterB.x,h=this.m_localAnchor2.y-this.m_localCenterB.y;r=e.col1.x*c+e.col2.x*h,h=e.col1.y*c+e.col2.y*h,c=r;var _=s.m_sweep.c.x+c-o.m_sweep.c.x-m,p=s.m_sweep.c.y+h-o.m_sweep.c.y-l;this.m_invMassA=o.m_invMass,this.m_invMassB=s.m_invMass,this.m_invIA=o.m_invI,this.m_invIB=s.m_invI,this.m_axis.SetV(n.MulMV(a.R,this.m_localXAxis1)),this.m_a1=(_+m)*this.m_axis.y-(p+l)*this.m_axis.x,this.m_a2=c*this.m_axis.y-h*this.m_axis.x,this.m_motorMass=this.m_invMassA+this.m_invMassB+this.m_invIA*this.m_a1*this.m_a1+this.m_invIB*this.m_a2*this.m_a2,this.m_motorMass>Number.MIN_VALUE&&(this.m_motorMass=1/this.m_motorMass),this.m_perp.SetV(n.MulMV(a.R,this.m_localYAxis1)),this.m_s1=(_+m)*this.m_perp.y-(p+l)*this.m_perp.x,this.m_s2=c*this.m_perp.y-h*this.m_perp.x;var u=this.m_invMassA,x=this.m_invMassB,f=this.m_invIA,d=this.m_invIB;if(this.m_K.col1.x=u+x+f*this.m_s1*this.m_s1+d*this.m_s2*this.m_s2,this.m_K.col1.y=f*this.m_s1+d*this.m_s2,this.m_K.col1.z=f*this.m_s1*this.m_a1+d*this.m_s2*this.m_a2,this.m_K.col2.x=this.m_K.col1.y,this.m_K.col2.y=f+d,this.m_K.col2.z=f*this.m_a1+d*this.m_a2,this.m_K.col3.x=this.m_K.col1.z,this.m_K.col3.y=this.m_K.col2.z,this.m_K.col3.z=u+x+f*this.m_a1*this.m_a1+d*this.m_a2*this.m_a2,this.m_enableLimit){var b=this.m_axis.x*_+this.m_axis.y*p;n.Abs(this.m_upperTranslation-this.m_lowerTranslation)<2*t.b2_linearSlop?this.m_limitState=y.e_equalLimits:this.m_lowerTranslation>=b?this.m_limitState!=y.e_atLowerLimit&&(this.m_limitState=y.e_atLowerLimit,this.m_impulse.z=0):b>=this.m_upperTranslation?this.m_limitState!=y.e_atUpperLimit&&(this.m_limitState=y.e_atUpperLimit,this.m_impulse.z=0):(this.m_limitState=y.e_inactiveLimit,this.m_impulse.z=0)}else this.m_limitState=y.e_inactiveLimit;if(0==this.m_enableMotor&&(this.m_motorImpulse=0),i.warmStarting){this.m_impulse.x*=i.dtRatio,this.m_impulse.y*=i.dtRatio,this.m_motorImpulse*=i.dtRatio;var v=this.m_impulse.x*this.m_perp.x+(this.m_motorImpulse+this.m_impulse.z)*this.m_axis.x,C=this.m_impulse.x*this.m_perp.y+(this.m_motorImpulse+this.m_impulse.z)*this.m_axis.y,g=this.m_impulse.x*this.m_s1+this.m_impulse.y+(this.m_motorImpulse+this.m_impulse.z)*this.m_a1,w=this.m_impulse.x*this.m_s2+this.m_impulse.y+(this.m_motorImpulse+this.m_impulse.z)*this.m_a2;o.m_linearVelocity.x-=this.m_invMassA*v,o.m_linearVelocity.y-=this.m_invMassA*C,o.m_angularVelocity-=this.m_invIA*g,s.m_linearVelocity.x+=this.m_invMassB*v,s.m_linearVelocity.y+=this.m_invMassB*C,s.m_angularVelocity+=this.m_invIB*w}else this.m_impulse.SetZero(),this.m_motorImpulse=0},C.prototype.SolveVelocityConstraints=function(t){var i=this.m_bodyA,e=this.m_bodyB,o=i.m_linearVelocity,a=i.m_angularVelocity,m=e.m_linearVelocity,l=e.m_angularVelocity,c=0,h=0,_=0,p=0;if(this.m_enableMotor&&this.m_limitState!=y.e_equalLimits){var u=this.m_axis.x*(m.x-o.x)+this.m_axis.y*(m.y-o.y)+this.m_a2*l-this.m_a1*a,x=this.m_motorMass*(this.m_motorSpeed-u),f=this.m_motorImpulse,d=t.dt*this.m_maxMotorForce;this.m_motorImpulse=n.Clamp(this.m_motorImpulse+x,-d,d),x=this.m_motorImpulse-f,c=x*this.m_axis.x,h=x*this.m_axis.y,_=x*this.m_a1,p=x*this.m_a2,o.x-=this.m_invMassA*c,o.y-=this.m_invMassA*h,a-=this.m_invIA*_,m.x+=this.m_invMassB*c,m.y+=this.m_invMassB*h,l+=this.m_invIB*p}var b=this.m_perp.x*(m.x-o.x)+this.m_perp.y*(m.y-o.y)+this.m_s2*l-this.m_s1*a,v=l-a;if(this.m_enableLimit&&this.m_limitState!=y.e_inactiveLimit){var C=this.m_axis.x*(m.x-o.x)+this.m_axis.y*(m.y-o.y)+this.m_a2*l-this.m_a1*a,g=this.m_impulse.Copy(),w=this.m_K.Solve33(new r,-b,-v,-C);this.m_impulse.Add(w),this.m_limitState==y.e_atLowerLimit?this.m_impulse.z=n.Max(this.m_impulse.z,0):this.m_limitState==y.e_atUpperLimit&&(this.m_impulse.z=n.Min(this.m_impulse.z,0));var A=-b-(this.m_impulse.z-g.z)*this.m_K.col3.x,S=-v-(this.m_impulse.z-g.z)*this.m_K.col3.y,D=this.m_K.Solve22(new s,A,S);D.x+=g.x,D.y+=g.y,this.m_impulse.x=D.x,this.m_impulse.y=D.y,w.x=this.m_impulse.x-g.x,w.y=this.m_impulse.y-g.y,w.z=this.m_impulse.z-g.z,c=w.x*this.m_perp.x+w.z*this.m_axis.x,h=w.x*this.m_perp.y+w.z*this.m_axis.y,_=w.x*this.m_s1+w.y+w.z*this.m_a1,p=w.x*this.m_s2+w.y+w.z*this.m_a2,o.x-=this.m_invMassA*c,o.y-=this.m_invMassA*h,a-=this.m_invIA*_,m.x+=this.m_invMassB*c,m.y+=this.m_invMassB*h,l+=this.m_invIB*p}else{var B=this.m_K.Solve22(new s,-b,-v);this.m_impulse.x+=B.x,this.m_impulse.y+=B.y,c=B.x*this.m_perp.x,h=B.x*this.m_perp.y,_=B.x*this.m_s1+B.y,p=B.x*this.m_s2+B.y,o.x-=this.m_invMassA*c,o.y-=this.m_invMassA*h,a-=this.m_invIA*_,m.x+=this.m_invMassB*c,m.y+=this.m_invMassB*h,l+=this.m_invIB*p}i.m_linearVelocity.SetV(o),i.m_angularVelocity=a,e.m_linearVelocity.SetV(m),e.m_angularVelocity=l},C.prototype.SolvePositionConstraints=function(e){void 0===e&&(e=0);var o,a=this.m_bodyA,m=this.m_bodyB,l=a.m_sweep.c,c=a.m_sweep.a,h=m.m_sweep.c,_=m.m_sweep.a,p=0,y=0,u=0,x=0,f=0,d=0,b=0,v=!1,C=0,g=i.FromAngle(c),w=i.FromAngle(_);o=g;var A=this.m_localAnchor1.x-this.m_localCenterA.x,S=this.m_localAnchor1.y-this.m_localCenterA.y;p=o.col1.x*A+o.col2.x*S,S=o.col1.y*A+o.col2.y*S,A=p,o=w;var D=this.m_localAnchor2.x-this.m_localCenterB.x,B=this.m_localAnchor2.y-this.m_localCenterB.y;p=o.col1.x*D+o.col2.x*B,B=o.col1.y*D+o.col2.y*B,D=p;var M=h.x+D-l.x-A,V=h.y+B-l.y-S;if(this.m_enableLimit){this.m_axis=n.MulMV(g,this.m_localXAxis1),this.m_a1=(M+A)*this.m_axis.y-(V+S)*this.m_axis.x,this.m_a2=D*this.m_axis.y-B*this.m_axis.x;var I=this.m_axis.x*M+this.m_axis.y*V;n.Abs(this.m_upperTranslation-this.m_lowerTranslation)<2*t.b2_linearSlop?(C=n.Clamp(I,-t.b2_maxLinearCorrection,t.b2_maxLinearCorrection),d=n.Abs(I),v=!0):this.m_lowerTranslation>=I?(C=n.Clamp(I-this.m_lowerTranslation+t.b2_linearSlop,-t.b2_maxLinearCorrection,0),d=this.m_lowerTranslation-I,v=!0):I>=this.m_upperTranslation&&(C=n.Clamp(I-this.m_upperTranslation+t.b2_linearSlop,0,t.b2_maxLinearCorrection),d=I-this.m_upperTranslation,v=!0)}this.m_perp=n.MulMV(g,this.m_localYAxis1),this.m_s1=(M+A)*this.m_perp.y-(V+S)*this.m_perp.x,this.m_s2=D*this.m_perp.y-B*this.m_perp.x;var G=new r,L=this.m_perp.x*M+this.m_perp.y*V,J=_-c-this.m_refAngle;if(d=n.Max(d,n.Abs(L)),b=n.Abs(J),v)y=this.m_invMassA,u=this.m_invMassB,x=this.m_invIA,f=this.m_invIB,this.m_K.col1.x=y+u+x*this.m_s1*this.m_s1+f*this.m_s2*this.m_s2,this.m_K.col1.y=x*this.m_s1+f*this.m_s2,this.m_K.col1.z=x*this.m_s1*this.m_a1+f*this.m_s2*this.m_a2,this.m_K.col2.x=this.m_K.col1.y,this.m_K.col2.y=x+f,this.m_K.col2.z=x*this.m_a1+f*this.m_a2,this.m_K.col3.x=this.m_K.col1.z,this.m_K.col3.y=this.m_K.col2.z,this.m_K.col3.z=y+u+x*this.m_a1*this.m_a1+f*this.m_a2*this.m_a2,this.m_K.Solve33(G,-L,-J,-C);else{y=this.m_invMassA,u=this.m_invMassB,x=this.m_invIA,f=this.m_invIB;var F=y+u+x*this.m_s1*this.m_s1+f*this.m_s2*this.m_s2,P=x*this.m_s1+f*this.m_s2,T=x+f;this.m_K.col1.Set(F,P,0),this.m_K.col2.Set(P,T,0);var R=this.m_K.Solve22(new s,-L,-J);G.x=R.x,G.y=R.y,G.z=0}var k=G.x*this.m_perp.x+G.z*this.m_axis.x,E=G.x*this.m_perp.y+G.z*this.m_axis.y,z=G.x*this.m_s1+G.y+G.z*this.m_a1,N=G.x*this.m_s2+G.y+G.z*this.m_a2;return l.x-=this.m_invMassA*k,l.y-=this.m_invMassA*E,c-=this.m_invIA*z,h.x+=this.m_invMassB*k,h.y+=this.m_invMassB*E,_+=this.m_invIB*N,a.m_sweep.a=c,m.m_sweep.a=_,a.SynchronizeTransform(),m.SynchronizeTransform(),t.b2_linearSlop>=d&&t.b2_angularSlop>=b},o.inherit(g,o.Dynamics.Joints.b2JointDef),g.prototype.__super=o.Dynamics.Joints.b2JointDef.prototype,g.b2PrismaticJointDef=function(){o.Dynamics.Joints.b2JointDef.b2JointDef.apply(this,arguments),this.localAnchorA=new s,this.localAnchorB=new s,this.localAxisA=new s},g.prototype.b2PrismaticJointDef=function(){this.__super.b2JointDef.call(this),this.type=y.e_prismaticJoint,this.localAxisA.Set(1,0),this.referenceAngle=0,this.enableLimit=!1,this.lowerTranslation=0,this.upperTranslation=0,this.enableMotor=!1,this.maxMotorForce=0,this.motorSpeed=0},g.prototype.Initialize=function(t,i,e,o){this.bodyA=t,this.bodyB=i,this.localAnchorA=this.bodyA.GetLocalPoint(e),this.localAnchorB=this.bodyB.GetLocalPoint(e),this.localAxisA=this.bodyA.GetLocalVector(o),this.referenceAngle=this.bodyB.GetAngle()-this.bodyA.GetAngle()},o.inherit(w,o.Dynamics.Joints.b2Joint),w.prototype.__super=o.Dynamics.Joints.b2Joint.prototype,w.b2PulleyJoint=function(){o.Dynamics.Joints.b2Joint.b2Joint.apply(this,arguments),this.m_groundAnchor1=new s,this.m_groundAnchor2=new s,this.m_localAnchor1=new s,this.m_localAnchor2=new s,this.m_u1=new s,this.m_u2=new s},w.prototype.GetAnchorA=function(){return this.m_bodyA.GetWorldPoint(this.m_localAnchor1)},w.prototype.GetAnchorB=function(){return this.m_bodyB.GetWorldPoint(this.m_localAnchor2)},w.prototype.GetReactionForce=function(t){return void 0===t&&(t=0),new s(t*this.m_impulse*this.m_u2.x,t*this.m_impulse*this.m_u2.y)},w.prototype.GetReactionTorque=function(t){return void 0===t&&(t=0),0},w.prototype.GetGroundAnchorA=function(){var t=this.m_ground.m_xf.position.Copy();return t.Add(this.m_groundAnchor1),t},w.prototype.GetGroundAnchorB=function(){var t=this.m_ground.m_xf.position.Copy();return t.Add(this.m_groundAnchor2),t},w.prototype.GetLength1=function(){var t=this.m_bodyA.GetWorldPoint(this.m_localAnchor1),i=this.m_ground.m_xf.position.x+this.m_groundAnchor1.x,e=this.m_ground.m_xf.position.y+this.m_groundAnchor1.y,o=t.x-i,n=t.y-e;return Math.sqrt(o*o+n*n)},w.prototype.GetLength2=function(){var t=this.m_bodyB.GetWorldPoint(this.m_localAnchor2),i=this.m_ground.m_xf.position.x+this.m_groundAnchor2.x,e=this.m_ground.m_xf.position.y+this.m_groundAnchor2.y,o=t.x-i,n=t.y-e;return Math.sqrt(o*o+n*n)},w.prototype.GetRatio=function(){return this.m_ratio},w.prototype.b2PulleyJoint=function(t){this.__super.b2Joint.call(this,t),this.m_ground=this.m_bodyA.m_world.m_groundBody,this.m_groundAnchor1.x=t.groundAnchorA.x-this.m_ground.m_xf.position.x,this.m_groundAnchor1.y=t.groundAnchorA.y-this.m_ground.m_xf.position.y,this.m_groundAnchor2.x=t.groundAnchorB.x-this.m_ground.m_xf.position.x,this.m_groundAnchor2.y=t.groundAnchorB.y-this.m_ground.m_xf.position.y,this.m_localAnchor1.SetV(t.localAnchorA),this.m_localAnchor2.SetV(t.localAnchorB),this.m_ratio=t.ratio,this.m_constant=t.lengthA+this.m_ratio*t.lengthB,this.m_maxLength1=n.Min(t.maxLengthA,this.m_constant-this.m_ratio*w.b2_minPulleyLength),this.m_maxLength2=n.Min(t.maxLengthB,(this.m_constant-w.b2_minPulleyLength)/this.m_ratio),this.m_impulse=0,this.m_limitImpulse1=0,this.m_limitImpulse2=0},w.prototype.InitVelocityConstraints=function(i){var e,o=this.m_bodyA,n=this.m_bodyB;e=o.m_xf.R;var s=this.m_localAnchor1.x-o.m_sweep.localCenter.x,r=this.m_localAnchor1.y-o.m_sweep.localCenter.y,a=e.col1.x*s+e.col2.x*r;r=e.col1.y*s+e.col2.y*r,s=a,e=n.m_xf.R;var m=this.m_localAnchor2.x-n.m_sweep.localCenter.x,l=this.m_localAnchor2.y-n.m_sweep.localCenter.y;a=e.col1.x*m+e.col2.x*l,l=e.col1.y*m+e.col2.y*l,m=a;var c=o.m_sweep.c.x+s,h=o.m_sweep.c.y+r,_=n.m_sweep.c.x+m,p=n.m_sweep.c.y+l,u=this.m_ground.m_xf.position.x+this.m_groundAnchor1.x,x=this.m_ground.m_xf.position.y+this.m_groundAnchor1.y,f=this.m_ground.m_xf.position.x+this.m_groundAnchor2.x,d=this.m_ground.m_xf.position.y+this.m_groundAnchor2.y;this.m_u1.Set(c-u,h-x),this.m_u2.Set(_-f,p-d);var b=this.m_u1.Length(),v=this.m_u2.Length();b>t.b2_linearSlop?this.m_u1.Multiply(1/b):this.m_u1.SetZero(),v>t.b2_linearSlop?this.m_u2.Multiply(1/v):this.m_u2.SetZero();var C=this.m_constant-b-this.m_ratio*v;C>0?(this.m_state=y.e_inactiveLimit,this.m_impulse=0):this.m_state=y.e_atUpperLimit,this.m_maxLength1>b?(this.m_limitState1=y.e_inactiveLimit,this.m_limitImpulse1=0):this.m_limitState1=y.e_atUpperLimit,this.m_maxLength2>v?(this.m_limitState2=y.e_inactiveLimit,this.m_limitImpulse2=0):this.m_limitState2=y.e_atUpperLimit;var g=s*this.m_u1.y-r*this.m_u1.x,w=m*this.m_u2.y-l*this.m_u2.x;if(this.m_limitMass1=o.m_invMass+o.m_invI*g*g,this.m_limitMass2=n.m_invMass+n.m_invI*w*w,this.m_pulleyMass=this.m_limitMass1+this.m_ratio*this.m_ratio*this.m_limitMass2,this.m_limitMass1=1/this.m_limitMass1,this.m_limitMass2=1/this.m_limitMass2,this.m_pulleyMass=1/this.m_pulleyMass,i.warmStarting){this.m_impulse*=i.dtRatio,this.m_limitImpulse1*=i.dtRatio,this.m_limitImpulse2*=i.dtRatio;var A=(-this.m_impulse-this.m_limitImpulse1)*this.m_u1.x,S=(-this.m_impulse-this.m_limitImpulse1)*this.m_u1.y,D=(-this.m_ratio*this.m_impulse-this.m_limitImpulse2)*this.m_u2.x,B=(-this.m_ratio*this.m_impulse-this.m_limitImpulse2)*this.m_u2.y;o.m_linearVelocity.x+=o.m_invMass*A,o.m_linearVelocity.y+=o.m_invMass*S,o.m_angularVelocity+=o.m_invI*(s*S-r*A),n.m_linearVelocity.x+=n.m_invMass*D,n.m_linearVelocity.y+=n.m_invMass*B,n.m_angularVelocity+=n.m_invI*(m*B-l*D)}else this.m_impulse=0,this.m_limitImpulse1=0,this.m_limitImpulse2=0},w.prototype.SolveVelocityConstraints=function(){var t,i=this.m_bodyA,e=this.m_bodyB;t=i.m_xf.R;var o=this.m_localAnchor1.x-i.m_sweep.localCenter.x,s=this.m_localAnchor1.y-i.m_sweep.localCenter.y,r=t.col1.x*o+t.col2.x*s;s=t.col1.y*o+t.col2.y*s,o=r,t=e.m_xf.R;var a=this.m_localAnchor2.x-e.m_sweep.localCenter.x,m=this.m_localAnchor2.y-e.m_sweep.localCenter.y;r=t.col1.x*a+t.col2.x*m,m=t.col1.y*a+t.col2.y*m,a=r;var l=0,c=0,h=0,_=0,p=0,u=0,x=0,f=0,d=0,b=0,v=0;this.m_state==y.e_atUpperLimit&&(l=i.m_linearVelocity.x+-i.m_angularVelocity*s,c=i.m_linearVelocity.y+i.m_angularVelocity*o,h=e.m_linearVelocity.x+-e.m_angularVelocity*m,_=e.m_linearVelocity.y+e.m_angularVelocity*a,d=-(this.m_u1.x*l+this.m_u1.y*c)-this.m_ratio*(this.m_u2.x*h+this.m_u2.y*_),b=this.m_pulleyMass*-d,v=this.m_impulse,this.m_impulse=n.Max(0,this.m_impulse+b),b=this.m_impulse-v,p=-b*this.m_u1.x,u=-b*this.m_u1.y,x=-this.m_ratio*b*this.m_u2.x,f=-this.m_ratio*b*this.m_u2.y,i.m_linearVelocity.x+=i.m_invMass*p,i.m_linearVelocity.y+=i.m_invMass*u,i.m_angularVelocity+=i.m_invI*(o*u-s*p),e.m_linearVelocity.x+=e.m_invMass*x,e.m_linearVelocity.y+=e.m_invMass*f,e.m_angularVelocity+=e.m_invI*(a*f-m*x)),this.m_limitState1==y.e_atUpperLimit&&(l=i.m_linearVelocity.x+-i.m_angularVelocity*s,c=i.m_linearVelocity.y+i.m_angularVelocity*o,d=-(this.m_u1.x*l+this.m_u1.y*c),b=-this.m_limitMass1*d,v=this.m_limitImpulse1,this.m_limitImpulse1=n.Max(0,this.m_limitImpulse1+b),b=this.m_limitImpulse1-v,p=-b*this.m_u1.x,u=-b*this.m_u1.y,i.m_linearVelocity.x+=i.m_invMass*p,i.m_linearVelocity.y+=i.m_invMass*u,i.m_angularVelocity+=i.m_invI*(o*u-s*p)),this.m_limitState2==y.e_atUpperLimit&&(h=e.m_linearVelocity.x+-e.m_angularVelocity*m,_=e.m_linearVelocity.y+e.m_angularVelocity*a,d=-(this.m_u2.x*h+this.m_u2.y*_),b=-this.m_limitMass2*d,v=this.m_limitImpulse2,this.m_limitImpulse2=n.Max(0,this.m_limitImpulse2+b),b=this.m_limitImpulse2-v,x=-b*this.m_u2.x,f=-b*this.m_u2.y,e.m_linearVelocity.x+=e.m_invMass*x,e.m_linearVelocity.y+=e.m_invMass*f,e.m_angularVelocity+=e.m_invI*(a*f-m*x))},w.prototype.SolvePositionConstraints=function(i){void 0===i&&(i=0);var e,o=this.m_bodyA,s=this.m_bodyB,r=this.m_ground.m_xf.position.x+this.m_groundAnchor1.x,a=this.m_ground.m_xf.position.y+this.m_groundAnchor1.y,m=this.m_ground.m_xf.position.x+this.m_groundAnchor2.x,l=this.m_ground.m_xf.position.y+this.m_groundAnchor2.y,c=0,h=0,_=0,p=0,u=0,x=0,f=0,d=0,b=0,v=0,C=0,g=0,w=0,A=0;return this.m_state==y.e_atUpperLimit&&(e=o.m_xf.R,c=this.m_localAnchor1.x-o.m_sweep.localCenter.x,h=this.m_localAnchor1.y-o.m_sweep.localCenter.y,w=e.col1.x*c+e.col2.x*h,h=e.col1.y*c+e.col2.y*h,c=w,e=s.m_xf.R,_=this.m_localAnchor2.x-s.m_sweep.localCenter.x,p=this.m_localAnchor2.y-s.m_sweep.localCenter.y,w=e.col1.x*_+e.col2.x*p,p=e.col1.y*_+e.col2.y*p,_=w,u=o.m_sweep.c.x+c,x=o.m_sweep.c.y+h,f=s.m_sweep.c.x+_,d=s.m_sweep.c.y+p,this.m_u1.Set(u-r,x-a),this.m_u2.Set(f-m,d-l),b=this.m_u1.Length(),v=this.m_u2.Length(),b>t.b2_linearSlop?this.m_u1.Multiply(1/b):this.m_u1.SetZero(),v>t.b2_linearSlop?this.m_u2.Multiply(1/v):this.m_u2.SetZero(),C=this.m_constant-b-this.m_ratio*v,A=n.Max(A,-C),C=n.Clamp(C+t.b2_linearSlop,-t.b2_maxLinearCorrection,0),g=-this.m_pulleyMass*C,u=-g*this.m_u1.x,x=-g*this.m_u1.y,f=-this.m_ratio*g*this.m_u2.x,d=-this.m_ratio*g*this.m_u2.y,o.m_sweep.c.x+=o.m_invMass*u,o.m_sweep.c.y+=o.m_invMass*x,o.m_sweep.a+=o.m_invI*(c*x-h*u),s.m_sweep.c.x+=s.m_invMass*f,s.m_sweep.c.y+=s.m_invMass*d,s.m_sweep.a+=s.m_invI*(_*d-p*f),o.SynchronizeTransform(),s.SynchronizeTransform()),this.m_limitState1==y.e_atUpperLimit&&(e=o.m_xf.R,c=this.m_localAnchor1.x-o.m_sweep.localCenter.x,h=this.m_localAnchor1.y-o.m_sweep.localCenter.y,w=e.col1.x*c+e.col2.x*h,h=e.col1.y*c+e.col2.y*h,c=w,u=o.m_sweep.c.x+c,x=o.m_sweep.c.y+h,this.m_u1.Set(u-r,x-a),b=this.m_u1.Length(),b>t.b2_linearSlop?(this.m_u1.x*=1/b,this.m_u1.y*=1/b):this.m_u1.SetZero(),C=this.m_maxLength1-b,A=n.Max(A,-C),C=n.Clamp(C+t.b2_linearSlop,-t.b2_maxLinearCorrection,0),g=-this.m_limitMass1*C,u=-g*this.m_u1.x,x=-g*this.m_u1.y,o.m_sweep.c.x+=o.m_invMass*u,o.m_sweep.c.y+=o.m_invMass*x,o.m_sweep.a+=o.m_invI*(c*x-h*u),o.SynchronizeTransform()),this.m_limitState2==y.e_atUpperLimit&&(e=s.m_xf.R,_=this.m_localAnchor2.x-s.m_sweep.localCenter.x,p=this.m_localAnchor2.y-s.m_sweep.localCenter.y,w=e.col1.x*_+e.col2.x*p,p=e.col1.y*_+e.col2.y*p,_=w,f=s.m_sweep.c.x+_,d=s.m_sweep.c.y+p,this.m_u2.Set(f-m,d-l),v=this.m_u2.Length(),v>t.b2_linearSlop?(this.m_u2.x*=1/v,this.m_u2.y*=1/v):this.m_u2.SetZero(),C=this.m_maxLength2-v,A=n.Max(A,-C),C=n.Clamp(C+t.b2_linearSlop,-t.b2_maxLinearCorrection,0),g=-this.m_limitMass2*C,f=-g*this.m_u2.x,d=-g*this.m_u2.y,s.m_sweep.c.x+=s.m_invMass*f,s.m_sweep.c.y+=s.m_invMass*d,s.m_sweep.a+=s.m_invI*(_*d-p*f),s.SynchronizeTransform()),t.b2_linearSlop>A},o.postDefs.push(function(){o.Dynamics.Joints.b2PulleyJoint.b2_minPulleyLength=2}),o.inherit(A,o.Dynamics.Joints.b2JointDef),A.prototype.__super=o.Dynamics.Joints.b2JointDef.prototype,A.b2PulleyJointDef=function(){o.Dynamics.Joints.b2JointDef.b2JointDef.apply(this,arguments),this.groundAnchorA=new s,this.groundAnchorB=new s,this.localAnchorA=new s,this.localAnchorB=new s},A.prototype.b2PulleyJointDef=function(){this.__super.b2JointDef.call(this),this.type=y.e_pulleyJoint,this.groundAnchorA.Set(-1,1),this.groundAnchorB.Set(1,1),this.localAnchorA.Set(-1,0),this.localAnchorB.Set(1,0),this.lengthA=0,this.maxLengthA=0,this.lengthB=0,this.maxLengthB=0,this.ratio=1,this.collideConnected=!0},A.prototype.Initialize=function(t,i,e,o,n,s,r){void 0===r&&(r=0),this.bodyA=t,this.bodyB=i,this.groundAnchorA.SetV(e),this.groundAnchorB.SetV(o),this.localAnchorA=this.bodyA.GetLocalPoint(n),this.localAnchorB=this.bodyB.GetLocalPoint(s);var a=n.x-e.x,m=n.y-e.y;this.lengthA=Math.sqrt(a*a+m*m);var l=s.x-o.x,c=s.y-o.y;this.lengthB=Math.sqrt(l*l+c*c),this.ratio=r;var h=this.lengthA+this.ratio*this.lengthB;this.maxLengthA=h-this.ratio*w.b2_minPulleyLength,this.maxLengthB=(h-w.b2_minPulleyLength)/this.ratio},o.inherit(S,o.Dynamics.Joints.b2Joint),S.prototype.__super=o.Dynamics.Joints.b2Joint.prototype,S.b2RevoluteJoint=function(){o.Dynamics.Joints.b2Joint.b2Joint.apply(this,arguments),this.K=new i,this.K1=new i,this.K2=new i,this.K3=new i,this.impulse3=new r,this.impulse2=new s,this.reduced=new s,this.m_localAnchor1=new s,this.m_localAnchor2=new s,this.m_impulse=new r,this.m_mass=new e},S.prototype.GetAnchorA=function(){return this.m_bodyA.GetWorldPoint(this.m_localAnchor1)},S.prototype.GetAnchorB=function(){return this.m_bodyB.GetWorldPoint(this.m_localAnchor2)},S.prototype.GetReactionForce=function(t){return void 0===t&&(t=0),new s(t*this.m_impulse.x,t*this.m_impulse.y)},S.prototype.GetReactionTorque=function(t){return void 0===t&&(t=0),t*this.m_impulse.z},S.prototype.GetJointAngle=function(){return this.m_bodyB.m_sweep.a-this.m_bodyA.m_sweep.a-this.m_referenceAngle},S.prototype.GetJointSpeed=function(){return this.m_bodyB.m_angularVelocity-this.m_bodyA.m_angularVelocity},S.prototype.IsLimitEnabled=function(){return this.m_enableLimit},S.prototype.EnableLimit=function(t){this.m_enableLimit=t},S.prototype.GetLowerLimit=function(){return this.m_lowerAngle},S.prototype.GetUpperLimit=function(){return this.m_upperAngle},S.prototype.SetLimits=function(t,i){void 0===t&&(t=0),void 0===i&&(i=0),this.m_lowerAngle=t,this.m_upperAngle=i},S.prototype.IsMotorEnabled=function(){return this.m_bodyA.SetAwake(!0),this.m_bodyB.SetAwake(!0),this.m_enableMotor},S.prototype.EnableMotor=function(t){this.m_enableMotor=t},S.prototype.SetMotorSpeed=function(t){void 0===t&&(t=0),this.m_bodyA.SetAwake(!0),this.m_bodyB.SetAwake(!0),this.m_motorSpeed=t},S.prototype.GetMotorSpeed=function(){return this.m_motorSpeed},S.prototype.SetMaxMotorTorque=function(t){void 0===t&&(t=0),this.m_maxMotorTorque=t},S.prototype.GetMotorTorque=function(){return this.m_maxMotorTorque},S.prototype.b2RevoluteJoint=function(t){this.__super.b2Joint.call(this,t),this.m_localAnchor1.SetV(t.localAnchorA),this.m_localAnchor2.SetV(t.localAnchorB),this.m_referenceAngle=t.referenceAngle,this.m_impulse.SetZero(),this.m_motorImpulse=0,this.m_lowerAngle=t.lowerAngle,this.m_upperAngle=t.upperAngle,this.m_maxMotorTorque=t.maxMotorTorque,this.m_motorSpeed=t.motorSpeed,this.m_enableLimit=t.enableLimit,this.m_enableMotor=t.enableMotor,this.m_limitState=y.e_inactiveLimit},S.prototype.InitVelocityConstraints=function(i){var e,o=this.m_bodyA,s=this.m_bodyB,r=0;this.m_enableMotor||this.m_enableLimit,e=o.m_xf.R;var a=this.m_localAnchor1.x-o.m_sweep.localCenter.x,m=this.m_localAnchor1.y-o.m_sweep.localCenter.y;r=e.col1.x*a+e.col2.x*m,m=e.col1.y*a+e.col2.y*m,a=r,e=s.m_xf.R;var l=this.m_localAnchor2.x-s.m_sweep.localCenter.x,c=this.m_localAnchor2.y-s.m_sweep.localCenter.y;r=e.col1.x*l+e.col2.x*c,c=e.col1.y*l+e.col2.y*c,l=r;var h=o.m_invMass,_=s.m_invMass,p=o.m_invI,u=s.m_invI;if(this.m_mass.col1.x=h+_+m*m*p+c*c*u,this.m_mass.col2.x=-m*a*p-c*l*u,this.m_mass.col3.x=-m*p-c*u,this.m_mass.col1.y=this.m_mass.col2.x,this.m_mass.col2.y=h+_+a*a*p+l*l*u,this.m_mass.col3.y=a*p+l*u,this.m_mass.col1.z=this.m_mass.col3.x,this.m_mass.col2.z=this.m_mass.col3.y,this.m_mass.col3.z=p+u,this.m_motorMass=1/(p+u),0==this.m_enableMotor&&(this.m_motorImpulse=0),this.m_enableLimit){var x=s.m_sweep.a-o.m_sweep.a-this.m_referenceAngle;n.Abs(this.m_upperAngle-this.m_lowerAngle)<2*t.b2_angularSlop?this.m_limitState=y.e_equalLimits:this.m_lowerAngle>=x?(this.m_limitState!=y.e_atLowerLimit&&(this.m_impulse.z=0),this.m_limitState=y.e_atLowerLimit):x>=this.m_upperAngle?(this.m_limitState!=y.e_atUpperLimit&&(this.m_impulse.z=0),this.m_limitState=y.e_atUpperLimit):(this.m_limitState=y.e_inactiveLimit,this.m_impulse.z=0)}else this.m_limitState=y.e_inactiveLimit;if(i.warmStarting){this.m_impulse.x*=i.dtRatio,this.m_impulse.y*=i.dtRatio,this.m_motorImpulse*=i.dtRatio;var f=this.m_impulse.x,d=this.m_impulse.y;o.m_linearVelocity.x-=h*f,o.m_linearVelocity.y-=h*d,o.m_angularVelocity-=p*(a*d-m*f+this.m_motorImpulse+this.m_impulse.z),s.m_linearVelocity.x+=_*f,s.m_linearVelocity.y+=_*d,s.m_angularVelocity+=u*(l*d-c*f+this.m_motorImpulse+this.m_impulse.z)}else this.m_impulse.SetZero(),this.m_motorImpulse=0},S.prototype.SolveVelocityConstraints=function(t){var i,e=this.m_bodyA,o=this.m_bodyB,s=0,r=0,a=0,m=0,l=0,c=0,h=e.m_linearVelocity,_=e.m_angularVelocity,p=o.m_linearVelocity,u=o.m_angularVelocity,x=e.m_invMass,f=o.m_invMass,d=e.m_invI,b=o.m_invI;if(this.m_enableMotor&&this.m_limitState!=y.e_equalLimits){var v=u-_-this.m_motorSpeed,C=this.m_motorMass*-v,g=this.m_motorImpulse,w=t.dt*this.m_maxMotorTorque;this.m_motorImpulse=n.Clamp(this.m_motorImpulse+C,-w,w),C=this.m_motorImpulse-g,_-=d*C,u+=b*C}if(this.m_enableLimit&&this.m_limitState!=y.e_inactiveLimit){i=e.m_xf.R,a=this.m_localAnchor1.x-e.m_sweep.localCenter.x,m=this.m_localAnchor1.y-e.m_sweep.localCenter.y,s=i.col1.x*a+i.col2.x*m,m=i.col1.y*a+i.col2.y*m,a=s,i=o.m_xf.R,l=this.m_localAnchor2.x-o.m_sweep.localCenter.x,c=this.m_localAnchor2.y-o.m_sweep.localCenter.y,s=i.col1.x*l+i.col2.x*c,c=i.col1.y*l+i.col2.y*c,l=s;var A=p.x+-u*c-h.x- -_*m,S=p.y+u*l-h.y-_*a,D=u-_;this.m_mass.Solve33(this.impulse3,-A,-S,-D),this.m_limitState==y.e_equalLimits?this.m_impulse.Add(this.impulse3):this.m_limitState==y.e_atLowerLimit?(r=this.m_impulse.z+this.impulse3.z,0>r&&(this.m_mass.Solve22(this.reduced,-A,-S),this.impulse3.x=this.reduced.x,this.impulse3.y=this.reduced.y,this.impulse3.z=-this.m_impulse.z,this.m_impulse.x+=this.reduced.x,this.m_impulse.y+=this.reduced.y,this.m_impulse.z=0)):this.m_limitState==y.e_atUpperLimit&&(r=this.m_impulse.z+this.impulse3.z,r>0&&(this.m_mass.Solve22(this.reduced,-A,-S),this.impulse3.x=this.reduced.x,this.impulse3.y=this.reduced.y,this.impulse3.z=-this.m_impulse.z,this.m_impulse.x+=this.reduced.x,this.m_impulse.y+=this.reduced.y,this.m_impulse.z=0)),h.x-=x*this.impulse3.x,h.y-=x*this.impulse3.y,_-=d*(a*this.impulse3.y-m*this.impulse3.x+this.impulse3.z),p.x+=f*this.impulse3.x,p.y+=f*this.impulse3.y,u+=b*(l*this.impulse3.y-c*this.impulse3.x+this.impulse3.z)}else{i=e.m_xf.R,a=this.m_localAnchor1.x-e.m_sweep.localCenter.x,m=this.m_localAnchor1.y-e.m_sweep.localCenter.y,s=i.col1.x*a+i.col2.x*m,m=i.col1.y*a+i.col2.y*m,a=s,i=o.m_xf.R,l=this.m_localAnchor2.x-o.m_sweep.localCenter.x,c=this.m_localAnchor2.y-o.m_sweep.localCenter.y,s=i.col1.x*l+i.col2.x*c,c=i.col1.y*l+i.col2.y*c,l=s;var B=p.x+-u*c-h.x- -_*m,M=p.y+u*l-h.y-_*a;this.m_mass.Solve22(this.impulse2,-B,-M),this.m_impulse.x+=this.impulse2.x,this.m_impulse.y+=this.impulse2.y,h.x-=x*this.impulse2.x,h.y-=x*this.impulse2.y,_-=d*(a*this.impulse2.y-m*this.impulse2.x),p.x+=f*this.impulse2.x,p.y+=f*this.impulse2.y,u+=b*(l*this.impulse2.y-c*this.impulse2.x)}e.m_linearVelocity.SetV(h),e.m_angularVelocity=_,o.m_linearVelocity.SetV(p),o.m_angularVelocity=u},S.prototype.SolvePositionConstraints=function(i){void 0===i&&(i=0);var e,o=0,s=this.m_bodyA,r=this.m_bodyB,a=0,m=0,l=0,c=0,h=0;if(this.m_enableLimit&&this.m_limitState!=y.e_inactiveLimit){var _=r.m_sweep.a-s.m_sweep.a-this.m_referenceAngle,p=0;this.m_limitState==y.e_equalLimits?(o=n.Clamp(_-this.m_lowerAngle,-t.b2_maxAngularCorrection,t.b2_maxAngularCorrection),p=-this.m_motorMass*o,a=n.Abs(o)):this.m_limitState==y.e_atLowerLimit?(o=_-this.m_lowerAngle,a=-o,o=n.Clamp(o+t.b2_angularSlop,-t.b2_maxAngularCorrection,0),p=-this.m_motorMass*o):this.m_limitState==y.e_atUpperLimit&&(o=_-this.m_upperAngle,a=o,o=n.Clamp(o-t.b2_angularSlop,0,t.b2_maxAngularCorrection),p=-this.m_motorMass*o),s.m_sweep.a-=s.m_invI*p,r.m_sweep.a+=r.m_invI*p,s.SynchronizeTransform(),r.SynchronizeTransform()}e=s.m_xf.R;var u=this.m_localAnchor1.x-s.m_sweep.localCenter.x,x=this.m_localAnchor1.y-s.m_sweep.localCenter.y;l=e.col1.x*u+e.col2.x*x,x=e.col1.y*u+e.col2.y*x,u=l,e=r.m_xf.R;var f=this.m_localAnchor2.x-r.m_sweep.localCenter.x,d=this.m_localAnchor2.y-r.m_sweep.localCenter.y;l=e.col1.x*f+e.col2.x*d,d=e.col1.y*f+e.col2.y*d,f=l;var b=r.m_sweep.c.x+f-s.m_sweep.c.x-u,v=r.m_sweep.c.y+d-s.m_sweep.c.y-x,C=b*b+v*v,g=Math.sqrt(C);m=g;var w=s.m_invMass,A=r.m_invMass,D=s.m_invI,B=r.m_invI,M=10*t.b2_linearSlop;if(C>M*M){var V=w+A,I=1/V;c=I*-b,h=I*-v;var G=.5;s.m_sweep.c.x-=G*w*c,s.m_sweep.c.y-=G*w*h,r.m_sweep.c.x+=G*A*c,r.m_sweep.c.y+=G*A*h,b=r.m_sweep.c.x+f-s.m_sweep.c.x-u,v=r.m_sweep.c.y+d-s.m_sweep.c.y-x}return this.K1.col1.x=w+A,this.K1.col2.x=0,this.K1.col1.y=0,this.K1.col2.y=w+A,this.K2.col1.x=D*x*x,this.K2.col2.x=-D*u*x,this.K2.col1.y=-D*u*x,this.K2.col2.y=D*u*u,this.K3.col1.x=B*d*d,this.K3.col2.x=-B*f*d,this.K3.col1.y=-B*f*d,this.K3.col2.y=B*f*f,this.K.SetM(this.K1),this.K.AddM(this.K2),this.K.AddM(this.K3),this.K.Solve(S.tImpulse,-b,-v),c=S.tImpulse.x,h=S.tImpulse.y,s.m_sweep.c.x-=s.m_invMass*c,s.m_sweep.c.y-=s.m_invMass*h,s.m_sweep.a-=s.m_invI*(u*h-x*c),r.m_sweep.c.x+=r.m_invMass*c,r.m_sweep.c.y+=r.m_invMass*h,r.m_sweep.a+=r.m_invI*(f*h-d*c),s.SynchronizeTransform(),r.SynchronizeTransform(),t.b2_linearSlop>=m&&t.b2_angularSlop>=a},o.postDefs.push(function(){o.Dynamics.Joints.b2RevoluteJoint.tImpulse=new s}),o.inherit(D,o.Dynamics.Joints.b2JointDef),D.prototype.__super=o.Dynamics.Joints.b2JointDef.prototype,D.b2RevoluteJointDef=function(){o.Dynamics.Joints.b2JointDef.b2JointDef.apply(this,arguments),this.localAnchorA=new s,this.localAnchorB=new s},D.prototype.b2RevoluteJointDef=function(){this.__super.b2JointDef.call(this),this.type=y.e_revoluteJoint,this.localAnchorA.Set(0,0),this.localAnchorB.Set(0,0),this.referenceAngle=0,this.lowerAngle=0,this.upperAngle=0,this.maxMotorTorque=0,this.motorSpeed=0,this.enableLimit=!1,this.enableMotor=!1},D.prototype.Initialize=function(t,i,e){this.bodyA=t,this.bodyB=i,this.localAnchorA=this.bodyA.GetLocalPoint(e),this.localAnchorB=this.bodyB.GetLocalPoint(e),this.referenceAngle=this.bodyB.GetAngle()-this.bodyA.GetAngle()},o.inherit(B,o.Dynamics.Joints.b2Joint),B.prototype.__super=o.Dynamics.Joints.b2Joint.prototype,B.b2WeldJoint=function(){o.Dynamics.Joints.b2Joint.b2Joint.apply(this,arguments),this.m_localAnchorA=new s,this.m_localAnchorB=new s,this.m_impulse=new r,this.m_mass=new e},B.prototype.GetAnchorA=function(){return this.m_bodyA.GetWorldPoint(this.m_localAnchorA)},B.prototype.GetAnchorB=function(){return this.m_bodyB.GetWorldPoint(this.m_localAnchorB)},B.prototype.GetReactionForce=function(t){return void 0===t&&(t=0),new s(t*this.m_impulse.x,t*this.m_impulse.y)},B.prototype.GetReactionTorque=function(t){return void 0===t&&(t=0),t*this.m_impulse.z},B.prototype.b2WeldJoint=function(t){this.__super.b2Joint.call(this,t),this.m_localAnchorA.SetV(t.localAnchorA),this.m_localAnchorB.SetV(t.localAnchorB),this.m_referenceAngle=t.referenceAngle,this.m_impulse.SetZero(),this.m_mass=new e},B.prototype.InitVelocityConstraints=function(t){var i,e=0,o=this.m_bodyA,n=this.m_bodyB;i=o.m_xf.R;var s=this.m_localAnchorA.x-o.m_sweep.localCenter.x,r=this.m_localAnchorA.y-o.m_sweep.localCenter.y;e=i.col1.x*s+i.col2.x*r,r=i.col1.y*s+i.col2.y*r,s=e,i=n.m_xf.R;var a=this.m_localAnchorB.x-n.m_sweep.localCenter.x,m=this.m_localAnchorB.y-n.m_sweep.localCenter.y;e=i.col1.x*a+i.col2.x*m,m=i.col1.y*a+i.col2.y*m,a=e;var l=o.m_invMass,c=n.m_invMass,h=o.m_invI,_=n.m_invI;this.m_mass.col1.x=l+c+r*r*h+m*m*_,this.m_mass.col2.x=-r*s*h-m*a*_,this.m_mass.col3.x=-r*h-m*_,this.m_mass.col1.y=this.m_mass.col2.x,this.m_mass.col2.y=l+c+s*s*h+a*a*_,this.m_mass.col3.y=s*h+a*_,this.m_mass.col1.z=this.m_mass.col3.x,this.m_mass.col2.z=this.m_mass.col3.y,this.m_mass.col3.z=h+_,t.warmStarting?(this.m_impulse.x*=t.dtRatio,this.m_impulse.y*=t.dtRatio,this.m_impulse.z*=t.dtRatio,o.m_linearVelocity.x-=l*this.m_impulse.x,o.m_linearVelocity.y-=l*this.m_impulse.y,o.m_angularVelocity-=h*(s*this.m_impulse.y-r*this.m_impulse.x+this.m_impulse.z),n.m_linearVelocity.x+=c*this.m_impulse.x,n.m_linearVelocity.y+=c*this.m_impulse.y,n.m_angularVelocity+=_*(a*this.m_impulse.y-m*this.m_impulse.x+this.m_impulse.z)):this.m_impulse.SetZero()},B.prototype.SolveVelocityConstraints=function(){var t,i=0,e=this.m_bodyA,o=this.m_bodyB,n=e.m_linearVelocity,s=e.m_angularVelocity,a=o.m_linearVelocity,m=o.m_angularVelocity,l=e.m_invMass,c=o.m_invMass,h=e.m_invI,_=o.m_invI;t=e.m_xf.R;var p=this.m_localAnchorA.x-e.m_sweep.localCenter.x,y=this.m_localAnchorA.y-e.m_sweep.localCenter.y;i=t.col1.x*p+t.col2.x*y,y=t.col1.y*p+t.col2.y*y,p=i,t=o.m_xf.R;var u=this.m_localAnchorB.x-o.m_sweep.localCenter.x,x=this.m_localAnchorB.y-o.m_sweep.localCenter.y;i=t.col1.x*u+t.col2.x*x,x=t.col1.y*u+t.col2.y*x,u=i;var f=a.x-m*x-n.x+s*y,d=a.y+m*u-n.y-s*p,b=m-s,v=new r;this.m_mass.Solve33(v,-f,-d,-b),this.m_impulse.Add(v),n.x-=l*v.x,n.y-=l*v.y,s-=h*(p*v.y-y*v.x+v.z),a.x+=c*v.x,a.y+=c*v.y,m+=_*(u*v.y-x*v.x+v.z),e.m_angularVelocity=s,o.m_angularVelocity=m},B.prototype.SolvePositionConstraints=function(i){void 0===i&&(i=0);var e,o=0,s=this.m_bodyA,a=this.m_bodyB;e=s.m_xf.R;var m=this.m_localAnchorA.x-s.m_sweep.localCenter.x,l=this.m_localAnchorA.y-s.m_sweep.localCenter.y;o=e.col1.x*m+e.col2.x*l,l=e.col1.y*m+e.col2.y*l,m=o,e=a.m_xf.R;var c=this.m_localAnchorB.x-a.m_sweep.localCenter.x,h=this.m_localAnchorB.y-a.m_sweep.localCenter.y;o=e.col1.x*c+e.col2.x*h,h=e.col1.y*c+e.col2.y*h,c=o;var _=s.m_invMass,p=a.m_invMass,y=s.m_invI,u=a.m_invI,x=a.m_sweep.c.x+c-s.m_sweep.c.x-m,f=a.m_sweep.c.y+h-s.m_sweep.c.y-l,d=a.m_sweep.a-s.m_sweep.a-this.m_referenceAngle,b=10*t.b2_linearSlop,v=Math.sqrt(x*x+f*f),C=n.Abs(d);
v>b&&(y*=1,u*=1),this.m_mass.col1.x=_+p+l*l*y+h*h*u,this.m_mass.col2.x=-l*m*y-h*c*u,this.m_mass.col3.x=-l*y-h*u,this.m_mass.col1.y=this.m_mass.col2.x,this.m_mass.col2.y=_+p+m*m*y+c*c*u,this.m_mass.col3.y=m*y+c*u,this.m_mass.col1.z=this.m_mass.col3.x,this.m_mass.col2.z=this.m_mass.col3.y,this.m_mass.col3.z=y+u;var g=new r;return this.m_mass.Solve33(g,-x,-f,-d),s.m_sweep.c.x-=_*g.x,s.m_sweep.c.y-=_*g.y,s.m_sweep.a-=y*(m*g.y-l*g.x+g.z),a.m_sweep.c.x+=p*g.x,a.m_sweep.c.y+=p*g.y,a.m_sweep.a+=u*(c*g.y-h*g.x+g.z),s.SynchronizeTransform(),a.SynchronizeTransform(),t.b2_linearSlop>=v&&t.b2_angularSlop>=C},o.inherit(M,o.Dynamics.Joints.b2JointDef),M.prototype.__super=o.Dynamics.Joints.b2JointDef.prototype,M.b2WeldJointDef=function(){o.Dynamics.Joints.b2JointDef.b2JointDef.apply(this,arguments),this.localAnchorA=new s,this.localAnchorB=new s},M.prototype.b2WeldJointDef=function(){this.__super.b2JointDef.call(this),this.type=y.e_weldJoint,this.referenceAngle=0},M.prototype.Initialize=function(t,i,e){this.bodyA=t,this.bodyB=i,this.localAnchorA.SetV(this.bodyA.GetLocalPoint(e)),this.localAnchorB.SetV(this.bodyB.GetLocalPoint(e)),this.referenceAngle=this.bodyB.GetAngle()-this.bodyA.GetAngle()}}(),function(){var t=o.Dynamics.b2DebugDraw;t.b2DebugDraw=function(){this.m_drawScale=1,this.m_lineThickness=1,this.m_alpha=1,this.m_fillAlpha=1,this.m_xformScale=1;var t=this;this.m_sprite={graphics:{clear:function(){t.m_ctx.clearRect(0,0,t.m_ctx.canvas.width,t.m_ctx.canvas.height)}}}},t.prototype._color=function(t,i){return"rgba("+((16711680&t)>>16)+","+((65280&t)>>8)+","+(255&t)+","+i+")"},t.prototype.b2DebugDraw=function(){this.m_drawFlags=0},t.prototype.SetFlags=function(t){void 0===t&&(t=0),this.m_drawFlags=t},t.prototype.GetFlags=function(){return this.m_drawFlags},t.prototype.AppendFlags=function(t){void 0===t&&(t=0),this.m_drawFlags|=t},t.prototype.ClearFlags=function(t){void 0===t&&(t=0),this.m_drawFlags&=~t},t.prototype.SetSprite=function(t){this.m_ctx=t},t.prototype.GetSprite=function(){return this.m_ctx},t.prototype.SetDrawScale=function(t){void 0===t&&(t=0),this.m_drawScale=t},t.prototype.GetDrawScale=function(){return this.m_drawScale},t.prototype.SetLineThickness=function(t){void 0===t&&(t=0),this.m_lineThickness=t,this.m_ctx.strokeWidth=t},t.prototype.GetLineThickness=function(){return this.m_lineThickness},t.prototype.SetAlpha=function(t){void 0===t&&(t=0),this.m_alpha=t},t.prototype.GetAlpha=function(){return this.m_alpha},t.prototype.SetFillAlpha=function(t){void 0===t&&(t=0),this.m_fillAlpha=t},t.prototype.GetFillAlpha=function(){return this.m_fillAlpha},t.prototype.SetXFormScale=function(t){void 0===t&&(t=0),this.m_xformScale=t},t.prototype.GetXFormScale=function(){return this.m_xformScale},t.prototype.DrawPolygon=function(t,i,e){if(i){var o=this.m_ctx,n=this.m_drawScale;o.beginPath(),o.strokeStyle=this._color(e.color,this.m_alpha),o.moveTo(t[0].x*n,t[0].y*n);for(var s=1;i>s;s++)o.lineTo(t[s].x*n,t[s].y*n);o.lineTo(t[0].x*n,t[0].y*n),o.closePath(),o.stroke()}},t.prototype.DrawSolidPolygon=function(t,i,e){if(i){var o=this.m_ctx,n=this.m_drawScale;o.beginPath(),o.strokeStyle=this._color(e.color,this.m_alpha),o.fillStyle=this._color(e.color,this.m_fillAlpha),o.moveTo(t[0].x*n,t[0].y*n);for(var s=1;i>s;s++)o.lineTo(t[s].x*n,t[s].y*n);o.lineTo(t[0].x*n,t[0].y*n),o.closePath(),o.fill(),o.stroke()}},t.prototype.DrawCircle=function(t,i,e){if(i){var o=this.m_ctx,n=this.m_drawScale;o.beginPath(),o.strokeStyle=this._color(e.color,this.m_alpha),o.arc(t.x*n,t.y*n,i*n,0,2*Math.PI,!0),o.closePath(),o.stroke()}},t.prototype.DrawSolidCircle=function(t,i,e,o){if(i){var n=this.m_ctx,s=this.m_drawScale,r=t.x*s,a=t.y*s;n.moveTo(0,0),n.beginPath(),n.strokeStyle=this._color(o.color,this.m_alpha),n.fillStyle=this._color(o.color,this.m_fillAlpha),n.arc(r,a,i*s,0,2*Math.PI,!0),n.moveTo(r,a),n.lineTo((t.x+e.x*i)*s,(t.y+e.y*i)*s),n.closePath(),n.fill(),n.stroke()}},t.prototype.DrawSegment=function(t,i,e){var o=this.m_ctx,n=this.m_drawScale;o.strokeStyle=this._color(e.color,this.m_alpha),o.beginPath(),o.moveTo(t.x*n,t.y*n),o.lineTo(i.x*n,i.y*n),o.closePath(),o.stroke()},t.prototype.DrawTransform=function(t){var i=this.m_ctx,e=this.m_drawScale;i.beginPath(),i.strokeStyle=this._color(16711680,this.m_alpha),i.moveTo(t.position.x*e,t.position.y*e),i.lineTo((t.position.x+this.m_xformScale*t.R.col1.x)*e,(t.position.y+this.m_xformScale*t.R.col1.y)*e),i.strokeStyle=this._color(65280,this.m_alpha),i.moveTo(t.position.x*e,t.position.y*e),i.lineTo((t.position.x+this.m_xformScale*t.R.col2.x)*e,(t.position.y+this.m_xformScale*t.R.col2.y)*e),i.closePath(),i.stroke()}}();var r;for(r=0;o.postDefs.length>r;++r)o.postDefs[r]();delete o.postDefs,e.Box2D=o,e.b2AABB=o.Collision.b2AABB,e.b2Body=o.Dynamics.b2Body,e.b2BodyDef=o.Dynamics.b2BodyDef,e.b2CircleShape=o.Collision.Shapes.b2CircleShape,e.b2DebugDraw=o.Dynamics.b2DebugDraw,e.b2Fixture=o.Dynamics.b2Fixture,e.b2FixtureDef=o.Dynamics.b2FixtureDef,e.b2MassData=o.Collision.Shapes.b2MassData,e.b2PolygonShape=o.Collision.Shapes.b2PolygonShape,e.b2PrismaticJointDef=o.Dynamics.Joints.b2PrismaticJointDef,e.b2RevoluteJointDef=o.Dynamics.Joints.b2RevoluteJointDef,e.b2Transform=o.Common.Math.b2Transform,e.b2Vec2=o.Common.Math.b2Vec2,e.b2World=o.Dynamics.b2World},{}],"box2dweb-commonjs":[function(t,i){i.exports=t("mgSi3g")},{}]},{},[]),require=function e(t,i,o){function n(r,a){if(!i[r]){if(!t[r]){var m="function"==typeof require&&require;if(!a&&m)return m(r,!0);if(s)return s(r,!0);throw Error("Cannot find module '"+r+"'")}var l=i[r]={exports:{}};t[r][0].call(l.exports,function(i){var e=t[r][1][i];return n(e?e:i)},l,l.exports,e,t,i,o)}return i[r].exports}for(var s="function"==typeof require&&require,r=0;o.length>r;r++)n(o[r]);return n}({El4IPh:[function(t,i){var e,o="undefined"!=typeof window?window.navigator.userAgent:"",n=/OS X/.test(o),s=/Opera/.test(o),r=!/like Gecko/.test(o)&&!s,a=i.exports={0:n?"<menu>":"<UNK>",1:"<mouse 1>",2:"<mouse 2>",3:"<break>",4:"<mouse 3>",5:"<mouse 4>",6:"<mouse 5>",8:"<backspace>",9:"<tab>",12:"<clear>",13:"<enter>",16:"<shift>",17:"<control>",18:"<alt>",19:"<pause>",20:"<caps-lock>",21:"<ime-hangul>",23:"<ime-junja>",24:"<ime-final>",25:"<ime-kanji>",27:"<escape>",28:"<ime-convert>",29:"<ime-nonconvert>",30:"<ime-accept>",31:"<ime-mode-change>",27:"<escape>",32:"<space>",33:"<page-up>",34:"<page-down>",35:"<end>",36:"<home>",37:"<left>",38:"<up>",39:"<right>",40:"<down>",41:"<select>",42:"<print>",43:"<execute>",44:"<snapshot>",45:"<insert>",46:"<delete>",47:"<help>",91:"<meta>",92:"<meta>",93:n?"<meta>":"<menu>",95:"<sleep>",106:"<num-*>",107:"<num-+>",108:"<num-enter>",109:"<num-->",110:"<num-.>",111:"<num-/>",144:"<num-lock>",145:"<scroll-lock>",160:"<shift-left>",161:"<shift-right>",162:"<control-left>",163:"<control-right>",164:"<alt-left>",165:"<alt-right>",166:"<browser-back>",167:"<browser-forward>",168:"<browser-refresh>",169:"<browser-stop>",170:"<browser-search>",171:"<browser-favorites>",172:"<browser-home>",173:n&&r?"-":"<volume-mute>",174:"<volume-down>",175:"<volume-up>",176:"<next-track>",177:"<prev-track>",178:"<stop>",179:"<play-pause>",180:"<launch-mail>",181:"<launch-media-select>",182:"<launch-app 1>",183:"<launch-app 2>",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'",223:"<meta>",224:"<meta>",226:"<alt-gr>",229:"<ime-process>",231:s?"`":"<unicode>",246:"<attention>",247:"<crsel>",248:"<exsel>",249:"<erase-eof>",250:"<play>",251:"<zoom>",252:"<no-name>",253:"<pa-1>",254:"<clear>"};for(e=58;65>e;++e)a[e]=String.fromCharCode(e);for(e=48;58>e;++e)a[e]=e-48+"";for(e=65;91>e;++e)a[e]=String.fromCharCode(e);for(e=96;106>e;++e)a[e]="<num-"+(e-96)+">";for(e=112;136>e;++e)a[e]="F"+(e-111)},{}],vkey:[function(t,i){i.exports=t("El4IPh")},{}]},{},[]),require=function e(t,i,o){function n(r,a){if(!i[r]){if(!t[r]){var m="function"==typeof require&&require;if(!a&&m)return m(r,!0);if(s)return s(r,!0);throw Error("Cannot find module '"+r+"'")}var l=i[r]={exports:{}};t[r][0].call(l.exports,function(i){var e=t[r][1][i];return n(e?e:i)},l,l.exports,e,t,i,o)}return i[r].exports}for(var s="function"==typeof require&&require,r=0;o.length>r;r++)n(o[r]);return n}({1:[function(t,i){function e(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function o(t){return"function"==typeof t}function n(t){return"number"==typeof t}function s(t){return"object"==typeof t&&null!==t}function r(t){return void 0===t}i.exports=e,e.EventEmitter=e,e.prototype._events=void 0,e.prototype._maxListeners=void 0,e.defaultMaxListeners=10,e.prototype.setMaxListeners=function(t){if(!n(t)||0>t||isNaN(t))throw TypeError("n must be a positive number");return this._maxListeners=t,this},e.prototype.emit=function(t){var i,e,n,a,m,l;if(this._events||(this._events={}),"error"===t&&(!this._events.error||s(this._events.error)&&!this._events.error.length))throw i=arguments[1],i instanceof Error?i:TypeError('Uncaught, unspecified "error" event.');if(e=this._events[t],r(e))return!1;if(o(e))switch(arguments.length){case 1:e.call(this);break;case 2:e.call(this,arguments[1]);break;case 3:e.call(this,arguments[1],arguments[2]);break;default:for(n=arguments.length,a=Array(n-1),m=1;n>m;m++)a[m-1]=arguments[m];e.apply(this,a)}else if(s(e)){for(n=arguments.length,a=Array(n-1),m=1;n>m;m++)a[m-1]=arguments[m];for(l=e.slice(),n=l.length,m=0;n>m;m++)l[m].apply(this,a)}return!0},e.prototype.addListener=function(t,i){var n;if(!o(i))throw TypeError("listener must be a function");if(this._events||(this._events={}),this._events.newListener&&this.emit("newListener",t,o(i.listener)?i.listener:i),this._events[t]?s(this._events[t])?this._events[t].push(i):this._events[t]=[this._events[t],i]:this._events[t]=i,s(this._events[t])&&!this._events[t].warned){var n;n=r(this._maxListeners)?e.defaultMaxListeners:this._maxListeners,n&&n>0&&this._events[t].length>n&&(this._events[t].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[t].length),console.trace())}return this},e.prototype.on=e.prototype.addListener,e.prototype.once=function(t,i){function e(){this.removeListener(t,e),n||(n=!0,i.apply(this,arguments))}if(!o(i))throw TypeError("listener must be a function");var n=!1;return e.listener=i,this.on(t,e),this},e.prototype.removeListener=function(t,i){var e,n,r,a;if(!o(i))throw TypeError("listener must be a function");if(!this._events||!this._events[t])return this;if(e=this._events[t],r=e.length,n=-1,e===i||o(e.listener)&&e.listener===i)delete this._events[t],this._events.removeListener&&this.emit("removeListener",t,i);else if(s(e)){for(a=r;a-->0;)if(e[a]===i||e[a].listener&&e[a].listener===i){n=a;break}if(0>n)return this;1===e.length?(e.length=0,delete this._events[t]):e.splice(n,1),this._events.removeListener&&this.emit("removeListener",t,i)}return this},e.prototype.removeAllListeners=function(t){var i,e;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[t]&&delete this._events[t],this;if(0===arguments.length){for(i in this._events)"removeListener"!==i&&this.removeAllListeners(i);return this.removeAllListeners("removeListener"),this._events={},this}if(e=this._events[t],o(e))this.removeListener(t,e);else for(;e.length;)this.removeListener(t,e[e.length-1]);return delete this._events[t],this},e.prototype.listeners=function(t){var i;return i=this._events&&this._events[t]?o(this._events[t])?[this._events[t]]:this._events[t].slice():[]},e.listenerCount=function(t,i){var e;return e=t._events&&t._events[i]?o(t._events[i])?1:t._events[i].length:0}},{}],"5kejYY":[function(t,i){function e(t){function i(){var o=e.now(),a=o-n;n=o,s.emit("data",a),s.paused||r(i,t)}var n=e.now(),s=new o;return s.pause=function(){s.paused=!0},s.resume=function(){s.paused=!1},r(i,t),s}i.exports=e;var o=t("events").EventEmitter,n="undefined"==typeof window?this:window,s=n.performance&&n.performance.now?function(){return performance.now()}:Date.now||function(){return+new Date},r=n.requestAnimationFrame||n.webkitRequestAnimationFrame||n.mozRequestAnimationFrame||n.msRequestAnimationFrame||n.oRequestAnimationFrame||(n.setImmediate?function(t){setImmediate(t)}:function(t){setTimeout(t,0)});e.polyfill=r,e.now=s},{events:1}],raf:[function(t,i){i.exports=t("5kejYY")},{}]},{},[]),require=function e(t,i,o){function n(r,a){if(!i[r]){if(!t[r]){var m="function"==typeof require&&require;if(!a&&m)return m(r,!0);if(s)return s(r,!0);throw Error("Cannot find module '"+r+"'")}var l=i[r]={exports:{}};t[r][0].call(l.exports,function(i){var e=t[r][1][i];return n(e?e:i)},l,l.exports,e,t,i,o)}return i[r].exports}for(var s="function"==typeof require&&require,r=0;o.length>r;r++)n(o[r]);return n}({1:[function(t,i){function e(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function o(t){return"function"==typeof t}function n(t){return"number"==typeof t}function s(t){return"object"==typeof t&&null!==t}function r(t){return void 0===t}i.exports=e,e.EventEmitter=e,e.prototype._events=void 0,e.prototype._maxListeners=void 0,e.defaultMaxListeners=10,e.prototype.setMaxListeners=function(t){if(!n(t)||0>t||isNaN(t))throw TypeError("n must be a positive number");return this._maxListeners=t,this},e.prototype.emit=function(t){var i,e,n,a,m,l;if(this._events||(this._events={}),"error"===t&&(!this._events.error||s(this._events.error)&&!this._events.error.length))throw i=arguments[1],i instanceof Error?i:TypeError('Uncaught, unspecified "error" event.');if(e=this._events[t],r(e))return!1;if(o(e))switch(arguments.length){case 1:e.call(this);break;case 2:e.call(this,arguments[1]);break;case 3:e.call(this,arguments[1],arguments[2]);break;default:for(n=arguments.length,a=Array(n-1),m=1;n>m;m++)a[m-1]=arguments[m];e.apply(this,a)}else if(s(e)){for(n=arguments.length,a=Array(n-1),m=1;n>m;m++)a[m-1]=arguments[m];for(l=e.slice(),n=l.length,m=0;n>m;m++)l[m].apply(this,a)}return!0},e.prototype.addListener=function(t,i){var n;if(!o(i))throw TypeError("listener must be a function");if(this._events||(this._events={}),this._events.newListener&&this.emit("newListener",t,o(i.listener)?i.listener:i),this._events[t]?s(this._events[t])?this._events[t].push(i):this._events[t]=[this._events[t],i]:this._events[t]=i,s(this._events[t])&&!this._events[t].warned){var n;n=r(this._maxListeners)?e.defaultMaxListeners:this._maxListeners,n&&n>0&&this._events[t].length>n&&(this._events[t].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[t].length),console.trace())}return this},e.prototype.on=e.prototype.addListener,e.prototype.once=function(t,i){function e(){this.removeListener(t,e),n||(n=!0,i.apply(this,arguments))}if(!o(i))throw TypeError("listener must be a function");var n=!1;return e.listener=i,this.on(t,e),this},e.prototype.removeListener=function(t,i){var e,n,r,a;if(!o(i))throw TypeError("listener must be a function");if(!this._events||!this._events[t])return this;if(e=this._events[t],r=e.length,n=-1,e===i||o(e.listener)&&e.listener===i)delete this._events[t],this._events.removeListener&&this.emit("removeListener",t,i);else if(s(e)){for(a=r;a-->0;)if(e[a]===i||e[a].listener&&e[a].listener===i){n=a;break}if(0>n)return this;1===e.length?(e.length=0,delete this._events[t]):e.splice(n,1),this._events.removeListener&&this.emit("removeListener",t,i)}return this},e.prototype.removeAllListeners=function(t){var i,e;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[t]&&delete this._events[t],this;if(0===arguments.length){for(i in this._events)"removeListener"!==i&&this.removeAllListeners(i);return this.removeAllListeners("removeListener"),this._events={},this}if(e=this._events[t],o(e))this.removeListener(t,e);else for(;e.length;)this.removeListener(t,e[e.length-1]);return delete this._events[t],this},e.prototype.listeners=function(t){var i;return i=this._events&&this._events[t]?o(this._events[t])?[this._events[t]]:this._events[t].slice():[]},e.listenerCount=function(t,i){var e;return e=t._events&&t._events[i]?o(t._events[i])?1:t._events[i].length:0}},{}],cvIDFG:[function(t,i){function e(i){function e(n,s){if(!(this instanceof e))return new e(n,s);t("box2d-events")(i,n),s=s||{};var r=this;o.call(this),this.world=n,this.data=s.data||null,this.position=s.position||new l(0,0),this.jumpHeight=s.jumpHeight||10,this.body=s.body||this.defaultBody(),this.fixture=s.fixture||this.defaultFixture(),this.canjump=0,this.sensors=s.sensors||{},this.sensors.jump=this.sensors.jump||this.createSensor([[-.5,.2],[.5,.2],[.5,.8],[-.5,.8]]),this.sensors.jump.on("begin",function(){r.canjump+=1}),this.sensors.jump.on("end",function(){r.canjump-=1})}var s=i.Collision.Shapes.b2PolygonShape,r=i.Collision.Shapes.b2CircleShape,a=i.Dynamics.b2FixtureDef,m=i.Dynamics.b2BodyDef,l=i.Common.Math.b2Vec2,c=i.Dynamics.b2Body;n(e,o),e.prototype.defaultBody=function(){var t=new m;return t.position=this.position,t.type=c.b2_dynamicBody,t.userData=this.data,t.fixedRotation=!0,this.world.CreateBody(t)},e.prototype.defaultFixture=function(){var t=new a;return t.shape=new r(.5),this.body.CreateFixture(t)};var h=new l;return e.prototype.jump=function(){var t=this.canjump&&this.body.m_linearVelocity.y>=0;return t&&(h.x=0,h.y=-this.jumpHeight,this.body.ApplyImpulse(h,this.body.GetWorldCenter())),t},e.prototype.createSensor=function(t){for(var i=new s,e=new a,o=0;t.length>o;o+=1)t[o]=new l(t[o][0],t[o][1]);return e.isSensor=!0,e.shape=i,e.shape.SetAsArray(t),this.world.__events.fixture(this.body.CreateFixture(e))},e}var o=t("events").EventEmitter,n=t("inherits");i.exports=e},{"box2d-events":4,events:1,inherits:5}],"box2d-player":[function(t,i){i.exports=t("cvIDFG")},{}],4:[function(t,i){function e(t,i){var e=t.Dynamics.b2ContactListener,n=t.Dynamics.b2Fixture,s=n.prototype.Destroy,r=new e,a=new o,m=[],l=0;return i.__events?i.__events:(n.prototype.Destroy=function(){var t=m.indexOf(this);-1!==t&&(m[t].emitter.emit("destroy"),m.splice(t,1),delete m.emitter,s.call(this))},r.BeginContact=function(t){a.emit("begin",t.m_fixtureA,t.m_fixtureB,t);for(var i=0;l>i;i+=1)t.m_fixtureA===m[i]?m[i].emitter.emit("begin",t.m_fixtureB,t.m_fixtureA,t):t.m_fixtureB===m[i]&&m[i].emitter.emit("begin",t.m_fixtureA,t.m_fixtureB,t)},r.EndContact=function(t){a.emit("end",t.m_fixtureA,t.m_fixtureB,t);for(var i=0;l>i;i+=1)t.m_fixtureA===m[i]?m[i].emitter.emit("end",t.m_fixtureB,t.m_fixtureA,t):t.m_fixtureB===m[i]&&m[i].emitter.emit("end",t.m_fixtureA,t.m_fixtureB,t)},a.fixture=function(t){var i=new o;return l+=1,t.emitter=i,m.push(t),i},i.SetContactListener(r),i.__events=a,a)}var o=t("events").EventEmitter;i.exports=e},{events:1}],5:[function(t,i){i.exports="function"==typeof Object.create?function(t,i){t.super_=i,t.prototype=Object.create(i.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}})}:function(t,i){t.super_=i;var e=function(){};e.prototype=i.prototype,t.prototype=new e,t.prototype.constructor=t}},{}]},{},[]);var Box2D=require("box2dweb-commonjs").Box2D,vkey=require("vkey"),raf=require("raf"),b2BodyDef=Box2D.Dynamics.b2BodyDef,b2Body=Box2D.Dynamics.b2Body,b2FixtureDef=Box2D.Dynamics.b2FixtureDef,b2World=Box2D.Dynamics.b2World,b2CircleShape=Box2D.Collision.Shapes.b2CircleShape,b2DebugDraw=Box2D.Dynamics.b2DebugDraw,canvas=document.createElement("canvas"),ctx=canvas.getContext("2d");canvas.width=500,canvas.height=300,ctx.fillStyle="#f00",ctx.fillRect(0,0,500,300),document.body.appendChild(canvas);var jumping=!1,debugDraw=new b2DebugDraw,gravity={x:0,y:9.8},world=new b2World(gravity,!0);debugDraw.SetDrawScale(18),debugDraw.SetSprite(ctx),debugDraw.SetFlags(b2DebugDraw.e_shapeBit|b2DebugDraw.e_jointBit|b2DebugDraw.e_centerOfMassBit|b2DebugDraw.e_controllerBit|b2DebugDraw.e_pairBit),world.SetDebugDraw(debugDraw);var player=require("box2d-player")(Box2D)(world,{position:{x:10,y:0}});raf(canvas).on("data",function(t){player.body.m_linearVelocity.x=moving.x,jumping&&player.jump(),world.Step(t/1e3,8,3),world.DrawDebugData()});for(var i=0;5>i;i+=1){var def=new b2BodyDef;def.position={x:5*i+5,y:15},def.type=b2Body.b2_staticBody;var shape=new b2CircleShape(2===i?4:i%2?2:1),fixturedef=new b2FixtureDef;fixturedef.shape=shape,world.CreateBody(def).CreateFixture(fixturedef)}var moving={x:0,y:0};document.body.addEventListener("keydown",function(t){keydown(vkey[t.keyCode])},!1),document.body.addEventListener("keyup",function(t){keyup(vkey[t.keyCode])},!1);
{
"name": "requirebin-sketch",
"version": "1.0.0",
"dependencies": {
"box2dweb-commonjs": "2.1.0",
"vkey": "0.0.3",
"raf": "0.0.3",
"box2d-player": "0.1.0"
}
}
<style type='text/css'>html, body { margin: 0; padding: 0; border: 0; }
body, html { height: 100%; width: 100%; }</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment