var Box2D={};
(function(m,r){function q(){}if(!(Object.prototype.defineProperty instanceof Function)&&Object.prototype.__defineGetter__ instanceof Function&&Object.prototype.__defineSetter__ instanceof Function)Object.defineProperty=function(e,h,l){l.get instanceof Function&&e.__defineGetter__(h,l.get);l.set instanceof Function&&e.__defineSetter__(h,l.set)};m.inherit=function(e,h){q.prototype=h.prototype;e.prototype=new q;e.prototype.constructor=e};m.generateCallback=function(e,h){return function(){h.apply(e,arguments)}};
m.NVector=function(e){e===r&&(e=0);for(var h=Array(e||0),l=0;l<e;++l)h[l]=0;return h};m.is=function(e,h){return e===null?!1:h instanceof Function&&e instanceof h?!0:e.constructor.__implements!=r&&e.constructor.__implements[h]?!0:!1};m.parseUInt=function(e){return Math.abs(parseInt(e))}})(Box2D);var Vector=Array,Vector_a2j_Number=Box2D.NVector;typeof Box2D==="undefined"&&(Box2D={});if(typeof Box2D.Collision==="undefined")Box2D.Collision={};
if(typeof Box2D.Collision.Shapes==="undefined")Box2D.Collision.Shapes={};if(typeof Box2D.Common==="undefined")Box2D.Common={};if(typeof Box2D.Common.Math==="undefined")Box2D.Common.Math={};if(typeof Box2D.Dynamics==="undefined")Box2D.Dynamics={};if(typeof Box2D.Dynamics.Contacts==="undefined")Box2D.Dynamics.Contacts={};if(typeof Box2D.Dynamics.Controllers==="undefined")Box2D.Dynamics.Controllers={};if(typeof Box2D.Dynamics.Joints==="undefined")Box2D.Dynamics.Joints={};
(function(){function m(){m.b2AABB.apply(this,arguments)}function r(){r.b2Bound.apply(this,arguments)}function q(){q.b2BoundValues.apply(this,arguments);this.constructor===q&&this.b2BoundValues.apply(this,arguments)}function e(){e.b2Collision.apply(this,arguments)}function h(){h.b2ContactID.apply(this,arguments);this.constructor===h&&this.b2ContactID.apply(this,arguments)}function l(){l.b2ContactPoint.apply(this,arguments)}function w(){w.b2Distance.apply(this,arguments)}function c(){c.b2DistanceInput.apply(this,
arguments)}function p(){p.b2DistanceOutput.apply(this,arguments)}function H(){H.b2DistanceProxy.apply(this,arguments)}function C(){C.b2DynamicTree.apply(this,arguments);this.constructor===C&&this.b2DynamicTree.apply(this,arguments)}function v(){v.b2DynamicTreeBroadPhase.apply(this,arguments)}function y(){y.b2DynamicTreeNode.apply(this,arguments)}function s(){s.b2DynamicTreePair.apply(this,arguments)}function J(){J.b2Manifold.apply(this,arguments);this.constructor===J&&this.b2Manifold.apply(this,arguments)}
function K(){K.b2ManifoldPoint.apply(this,arguments);this.constructor===K&&this.b2ManifoldPoint.apply(this,arguments)}function d(){d.b2Point.apply(this,arguments)}function x(){x.b2RayCastInput.apply(this,arguments);this.constructor===x&&this.b2RayCastInput.apply(this,arguments)}function j(){j.b2RayCastOutput.apply(this,arguments)}function B(){B.b2Segment.apply(this,arguments)}function E(){E.b2SeparationFunction.apply(this,arguments)}function G(){G.b2Simplex.apply(this,arguments);this.constructor===
G&&this.b2Simplex.apply(this,arguments)}function A(){A.b2SimplexCache.apply(this,arguments)}function L(){L.b2SimplexVertex.apply(this,arguments)}function D(){D.b2TimeOfImpact.apply(this,arguments)}function F(){F.b2TOIInput.apply(this,arguments)}function M(){M.b2WorldManifold.apply(this,arguments);this.constructor===M&&this.b2WorldManifold.apply(this,arguments)}function I(){I.ClipVertex.apply(this,arguments)}function a(){a.Features.apply(this,arguments)}function g(){g.b2CircleShape.apply(this,arguments);
this.constructor===g&&this.b2CircleShape.apply(this,arguments)}function o(){o.b2EdgeChainDef.apply(this,arguments);this.constructor===o&&this.b2EdgeChainDef.apply(this,arguments)}function n(){n.b2EdgeShape.apply(this,arguments);this.constructor===n&&this.b2EdgeShape.apply(this,arguments)}function t(){t.b2MassData.apply(this,arguments)}function z(){z.b2PolygonShape.apply(this,arguments);this.constructor===z&&this.b2PolygonShape.apply(this,arguments)}function f(){f.b2Shape.apply(this,arguments);this.constructor===
f&&this.b2Shape.apply(this,arguments)}function b(){b.b2Color.apply(this,arguments);this.constructor===b&&this.b2Color.apply(this,arguments)}function k(){k.b2Settings.apply(this,arguments)}function u(){u.b2Mat22.apply(this,arguments);this.constructor===u&&this.b2Mat22.apply(this,arguments)}function N(){N.b2Mat33.apply(this,arguments);this.constructor===N&&this.b2Mat33.apply(this,arguments)}function ya(){ya.b2Math.apply(this,arguments)}function za(){za.b2Sweep.apply(this,arguments)}function O(){O.b2Transform.apply(this,
arguments);this.constructor===O&&this.b2Transform.apply(this,arguments)}function P(){P.b2Vec2.apply(this,arguments);this.constructor===P&&this.b2Vec2.apply(this,arguments)}function Q(){Q.b2Vec3.apply(this,arguments);this.constructor===Q&&this.b2Vec3.apply(this,arguments)}function R(){R.b2Body.apply(this,arguments);this.constructor===R&&this.b2Body.apply(this,arguments)}function S(){S.b2BodyDef.apply(this,arguments);this.constructor===S&&this.b2BodyDef.apply(this,arguments)}function Aa(){Aa.b2ContactFilter.apply(this,
arguments)}function Ba(){Ba.b2ContactImpulse.apply(this,arguments)}function Ca(){Ca.b2ContactListener.apply(this,arguments)}function T(){T.b2ContactManager.apply(this,arguments);this.constructor===T&&this.b2ContactManager.apply(this,arguments)}function U(){U.b2DebugDraw.apply(this,arguments);this.constructor===U&&this.b2DebugDraw.apply(this,arguments)}function Da(){Da.b2DestructionListener.apply(this,arguments)}function Ea(){Ea.b2FilterData.apply(this,arguments)}function V(){V.b2Fixture.apply(this,
arguments);this.constructor===V&&this.b2Fixture.apply(this,arguments)}function W(){W.b2FixtureDef.apply(this,arguments);this.constructor===W&&this.b2FixtureDef.apply(this,arguments)}function X(){X.b2Island.apply(this,arguments);this.constructor===X&&this.b2Island.apply(this,arguments)}function Fa(){Fa.b2TimeStep.apply(this,arguments)}function Y(){Y.b2World.apply(this,arguments);this.constructor===Y&&this.b2World.apply(this,arguments)}function Ga(){Ga.b2CircleContact.apply(this,arguments)}function Z(){Z.b2Contact.apply(this,
arguments);this.constructor===Z&&this.b2Contact.apply(this,arguments)}function $(){$.b2ContactConstraint.apply(this,arguments);this.constructor===$&&this.b2ContactConstraint.apply(this,arguments)}function Ha(){Ha.b2ContactConstraintPoint.apply(this,arguments)}function Ia(){Ia.b2ContactEdge.apply(this,arguments)}function aa(){aa.b2ContactFactory.apply(this,arguments);this.constructor===aa&&this.b2ContactFactory.apply(this,arguments)}function Ja(){Ja.b2ContactRegister.apply(this,arguments)}function Ka(){Ka.b2ContactResult.apply(this,
arguments)}function ba(){ba.b2ContactSolver.apply(this,arguments);this.constructor===ba&&this.b2ContactSolver.apply(this,arguments)}function La(){La.b2EdgeAndCircleContact.apply(this,arguments)}function ca(){ca.b2NullContact.apply(this,arguments);this.constructor===ca&&this.b2NullContact.apply(this,arguments)}function Ma(){Ma.b2PolyAndCircleContact.apply(this,arguments)}function Na(){Na.b2PolyAndEdgeContact.apply(this,arguments)}function Oa(){Oa.b2PolygonContact.apply(this,arguments)}function da(){da.b2PositionSolverManifold.apply(this,
arguments);this.constructor===da&&this.b2PositionSolverManifold.apply(this,arguments)}function Pa(){Pa.b2BuoyancyController.apply(this,arguments)}function Qa(){Qa.b2ConstantAccelController.apply(this,arguments)}function Ra(){Ra.b2ConstantForceController.apply(this,arguments)}function Sa(){Sa.b2Controller.apply(this,arguments)}function Ta(){Ta.b2ControllerEdge.apply(this,arguments)}function Ua(){Ua.b2GravityController.apply(this,arguments)}function Va(){Va.b2TensorDampingController.apply(this,arguments)}
function ea(){ea.b2DistanceJoint.apply(this,arguments);this.constructor===ea&&this.b2DistanceJoint.apply(this,arguments)}function fa(){fa.b2DistanceJointDef.apply(this,arguments);this.constructor===fa&&this.b2DistanceJointDef.apply(this,arguments)}function ga(){ga.b2FrictionJoint.apply(this,arguments);this.constructor===ga&&this.b2FrictionJoint.apply(this,arguments)}function ha(){ha.b2FrictionJointDef.apply(this,arguments);this.constructor===ha&&this.b2FrictionJointDef.apply(this,arguments)}function ia(){ia.b2GearJoint.apply(this,
arguments);this.constructor===ia&&this.b2GearJoint.apply(this,arguments)}function ja(){ja.b2GearJointDef.apply(this,arguments);this.constructor===ja&&this.b2GearJointDef.apply(this,arguments)}function Wa(){Wa.b2Jacobian.apply(this,arguments)}function ka(){ka.b2Joint.apply(this,arguments);this.constructor===ka&&this.b2Joint.apply(this,arguments)}function la(){la.b2JointDef.apply(this,arguments);this.constructor===la&&this.b2JointDef.apply(this,arguments)}function Xa(){Xa.b2JointEdge.apply(this,arguments)}
function ma(){ma.b2LineJoint.apply(this,arguments);this.constructor===ma&&this.b2LineJoint.apply(this,arguments)}function na(){na.b2LineJointDef.apply(this,arguments);this.constructor===na&&this.b2LineJointDef.apply(this,arguments)}function oa(){oa.b2MouseJoint.apply(this,arguments);this.constructor===oa&&this.b2MouseJoint.apply(this,arguments)}function pa(){pa.b2MouseJointDef.apply(this,arguments);this.constructor===pa&&this.b2MouseJointDef.apply(this,arguments)}function qa(){qa.b2PrismaticJoint.apply(this,
arguments);this.constructor===qa&&this.b2PrismaticJoint.apply(this,arguments)}function ra(){ra.b2PrismaticJointDef.apply(this,arguments);this.constructor===ra&&this.b2PrismaticJointDef.apply(this,arguments)}function sa(){sa.b2PulleyJoint.apply(this,arguments);this.constructor===sa&&this.b2PulleyJoint.apply(this,arguments)}function ta(){ta.b2PulleyJointDef.apply(this,arguments);this.constructor===ta&&this.b2PulleyJointDef.apply(this,arguments)}function ua(){ua.b2RevoluteJoint.apply(this,arguments);
this.constructor===ua&&this.b2RevoluteJoint.apply(this,arguments)}function va(){va.b2RevoluteJointDef.apply(this,arguments);this.constructor===va&&this.b2RevoluteJointDef.apply(this,arguments)}function wa(){wa.b2WeldJoint.apply(this,arguments);this.constructor===wa&&this.b2WeldJoint.apply(this,arguments)}function xa(){xa.b2WeldJointDef.apply(this,arguments);this.constructor===xa&&this.b2WeldJointDef.apply(this,arguments)}Box2D.Collision.IBroadPhase="Box2D.Collision.IBroadPhase";Box2D.Collision.b2AABB=
m;Box2D.Collision.b2Bound=r;Box2D.Collision.b2BoundValues=q;Box2D.Collision.b2Collision=e;Box2D.Collision.b2ContactID=h;Box2D.Collision.b2ContactPoint=l;Box2D.Collision.b2Distance=w;Box2D.Collision.b2DistanceInput=c;Box2D.Collision.b2DistanceOutput=p;Box2D.Collision.b2DistanceProxy=H;Box2D.Collision.b2DynamicTree=C;Box2D.Collision.b2DynamicTreeBroadPhase=v;Box2D.Collision.b2DynamicTreeNode=y;Box2D.Collision.b2DynamicTreePair=s;Box2D.Collision.b2Manifold=J;Box2D.Collision.b2ManifoldPoint=K;Box2D.Collision.b2Point=
d;Box2D.Collision.b2RayCastInput=x;Box2D.Collision.b2RayCastOutput=j;Box2D.Collision.b2Segment=B;Box2D.Collision.b2SeparationFunction=E;Box2D.Collision.b2Simplex=G;Box2D.Collision.b2SimplexCache=A;Box2D.Collision.b2SimplexVertex=L;Box2D.Collision.b2TimeOfImpact=D;Box2D.Collision.b2TOIInput=F;Box2D.Collision.b2WorldManifold=M;Box2D.Collision.ClipVertex=I;Box2D.Collision.Features=a;Box2D.Collision.Shapes.b2CircleShape=g;Box2D.Collision.Shapes.b2EdgeChainDef=o;Box2D.Collision.Shapes.b2EdgeShape=n;Box2D.Collision.Shapes.b2MassData=
t;Box2D.Collision.Shapes.b2PolygonShape=z;Box2D.Collision.Shapes.b2Shape=f;Box2D.Common.b2internal="Box2D.Common.b2internal";Box2D.Common.b2Color=b;Box2D.Common.b2Settings=k;Box2D.Common.Math.b2Mat22=u;Box2D.Common.Math.b2Mat33=N;Box2D.Common.Math.b2Math=ya;Box2D.Common.Math.b2Sweep=za;Box2D.Common.Math.b2Transform=O;Box2D.Common.Math.b2Vec2=P;Box2D.Common.Math.b2Vec3=Q;Box2D.Dynamics.b2Body=R;Box2D.Dynamics.b2BodyDef=S;Box2D.Dynamics.b2ContactFilter=Aa;Box2D.Dynamics.b2ContactImpulse=Ba;Box2D.Dynamics.b2ContactListener=
Ca;Box2D.Dynamics.b2ContactManager=T;Box2D.Dynamics.b2DebugDraw=U;Box2D.Dynamics.b2DestructionListener=Da;Box2D.Dynamics.b2FilterData=Ea;Box2D.Dynamics.b2Fixture=V;Box2D.Dynamics.b2FixtureDef=W;Box2D.Dynamics.b2Island=X;Box2D.Dynamics.b2TimeStep=Fa;Box2D.Dynamics.b2World=Y;Box2D.Dynamics.Contacts.b2CircleContact=Ga;Box2D.Dynamics.Contacts.b2Contact=Z;Box2D.Dynamics.Contacts.b2ContactConstraint=$;Box2D.Dynamics.Contacts.b2ContactConstraintPoint=Ha;Box2D.Dynamics.Contacts.b2ContactEdge=Ia;Box2D.Dynamics.Contacts.b2ContactFactory=
aa;Box2D.Dynamics.Contacts.b2ContactRegister=Ja;Box2D.Dynamics.Contacts.b2ContactResult=Ka;Box2D.Dynamics.Contacts.b2ContactSolver=ba;Box2D.Dynamics.Contacts.b2EdgeAndCircleContact=La;Box2D.Dynamics.Contacts.b2NullContact=ca;Box2D.Dynamics.Contacts.b2PolyAndCircleContact=Ma;Box2D.Dynamics.Contacts.b2PolyAndEdgeContact=Na;Box2D.Dynamics.Contacts.b2PolygonContact=Oa;Box2D.Dynamics.Contacts.b2PositionSolverManifold=da;Box2D.Dynamics.Controllers.b2BuoyancyController=Pa;Box2D.Dynamics.Controllers.b2ConstantAccelController=
Qa;Box2D.Dynamics.Controllers.b2ConstantForceController=Ra;Box2D.Dynamics.Controllers.b2Controller=Sa;Box2D.Dynamics.Controllers.b2ControllerEdge=Ta;Box2D.Dynamics.Controllers.b2GravityController=Ua;Box2D.Dynamics.Controllers.b2TensorDampingController=Va;Box2D.Dynamics.Joints.b2DistanceJoint=ea;Box2D.Dynamics.Joints.b2DistanceJointDef=fa;Box2D.Dynamics.Joints.b2FrictionJoint=ga;Box2D.Dynamics.Joints.b2FrictionJointDef=ha;Box2D.Dynamics.Joints.b2GearJoint=ia;Box2D.Dynamics.Joints.b2GearJointDef=ja;
Box2D.Dynamics.Joints.b2Jacobian=Wa;Box2D.Dynamics.Joints.b2Joint=ka;Box2D.Dynamics.Joints.b2JointDef=la;Box2D.Dynamics.Joints.b2JointEdge=Xa;Box2D.Dynamics.Joints.b2LineJoint=ma;Box2D.Dynamics.Joints.b2LineJointDef=na;Box2D.Dynamics.Joints.b2MouseJoint=oa;Box2D.Dynamics.Joints.b2MouseJointDef=pa;Box2D.Dynamics.Joints.b2PrismaticJoint=qa;Box2D.Dynamics.Joints.b2PrismaticJointDef=ra;Box2D.Dynamics.Joints.b2PulleyJoint=sa;Box2D.Dynamics.Joints.b2PulleyJointDef=ta;Box2D.Dynamics.Joints.b2RevoluteJoint=
ua;Box2D.Dynamics.Joints.b2RevoluteJointDef=va;Box2D.Dynamics.Joints.b2WeldJoint=wa;Box2D.Dynamics.Joints.b2WeldJointDef=xa})();Box2D.postDefs=[];
(function(){var m=Box2D.Collision.Shapes.b2CircleShape,r=Box2D.Collision.Shapes.b2PolygonShape,q=Box2D.Collision.Shapes.b2Shape,e=Box2D.Common.b2Settings,h=Box2D.Common.Math.b2Math,l=Box2D.Common.Math.b2Sweep,w=Box2D.Common.Math.b2Transform,c=Box2D.Common.Math.b2Vec2,p=Box2D.Collision.b2AABB,H=Box2D.Collision.b2Bound,C=Box2D.Collision.b2BoundValues,v=Box2D.Collision.b2Collision,y=Box2D.Collision.b2ContactID,s=Box2D.Collision.b2ContactPoint,J=Box2D.Collision.b2Distance,K=Box2D.Collision.b2DistanceInput,
d=Box2D.Collision.b2DistanceOutput,x=Box2D.Collision.b2DistanceProxy,j=Box2D.Collision.b2DynamicTree,B=Box2D.Collision.b2DynamicTreeBroadPhase,E=Box2D.Collision.b2DynamicTreeNode,G=Box2D.Collision.b2DynamicTreePair,A=Box2D.Collision.b2Manifold,L=Box2D.Collision.b2ManifoldPoint,D=Box2D.Collision.b2Point,F=Box2D.Collision.b2RayCastInput,M=Box2D.Collision.b2RayCastOutput,I=Box2D.Collision.b2Segment,a=Box2D.Collision.b2SeparationFunction,g=Box2D.Collision.b2Simplex,o=Box2D.Collision.b2SimplexCache,n=
Box2D.Collision.b2SimplexVertex,t=Box2D.Collision.b2TimeOfImpact,z=Box2D.Collision.b2TOIInput,f=Box2D.Collision.b2WorldManifold,b=Box2D.Collision.ClipVertex,k=Box2D.Collision.Features,u=Box2D.Collision.IBroadPhase;p.b2AABB=function(){this.lowerBound=new c;this.upperBound=new c};p.prototype.IsValid=function(){var b=this.upperBound.y-this.lowerBound.y;return b=(b=this.upperBound.x-this.lowerBound.x>=0&&b>=0)&&this.lowerBound.IsValid()&&this.upperBound.IsValid()};p.prototype.GetCenter=function(){return new c((this.lowerBound.x+
this.upperBound.x)/2,(this.lowerBound.y+this.upperBound.y)/2)};p.prototype.GetExtents=function(){return new c((this.upperBound.x-this.lowerBound.x)/2,(this.upperBound.y-this.lowerBound.y)/2)};p.prototype.Contains=function(b){var k;return k=(k=(k=(k=this.lowerBound.x<=b.lowerBound.x)&&this.lowerBound.y<=b.lowerBound.y)&&b.upperBound.x<=this.upperBound.x)&&b.upperBound.y<=this.upperBound.y};p.prototype.RayCast=function(b,k){var a=-Number.MAX_VALUE,u=Number.MAX_VALUE,g=k.p1.x,n=k.p1.y,d=k.p2.x-k.p1.x,
o=k.p2.y-k.p1.y,f=Math.abs(d),t=Math.abs(o),c=b.normal,z=0,j=0,e=z=0,e=0;if(f<Number.MIN_VALUE){if(g<this.lowerBound.x||this.upperBound.x<g)return!1}else{z=1/d;j=(this.lowerBound.x-g)*z;z*=this.upperBound.x-g;e=-1;j>z&&(e=j,j=z,z=e,e=1);if(j>a)c.x=e,c.y=0,a=j;u=Math.min(u,z);if(a>u)return!1}if(t<Number.MIN_VALUE){if(n<this.lowerBound.y||this.upperBound.y<n)return!1}else{z=1/o;j=(this.lowerBound.y-n)*z;z*=this.upperBound.y-n;e=-1;j>z&&(e=j,j=z,z=e,e=1);if(j>a)c.y=e,c.x=0,a=j;u=Math.min(u,z);if(a>u)return!1}b.fraction=
a;return!0};p.prototype.TestOverlap=function(b){var k=b.lowerBound.y-this.upperBound.y,a=this.lowerBound.y-b.upperBound.y;return b.lowerBound.x-this.upperBound.x>0||k>0?!1:this.lowerBound.x-b.upperBound.x>0||a>0?!1:!0};p.Combine=function(b,k){var a=new p;a.Combine(b,k);return a};p.prototype.Combine=function(b,k){this.lowerBound.x=Math.min(b.lowerBound.x,k.lowerBound.x);this.lowerBound.y=Math.min(b.lowerBound.y,k.lowerBound.y);this.upperBound.x=Math.max(b.upperBound.x,k.upperBound.x);this.upperBound.y=
Math.max(b.upperBound.y,k.upperBound.y)};H.b2Bound=function(){};H.prototype.IsLower=function(){return(this.value&1)==0};H.prototype.IsUpper=function(){return(this.value&1)==1};H.prototype.Swap=function(b){var k=this.value,a=this.proxy,u=this.stabbingCount;this.value=b.value;this.proxy=b.proxy;this.stabbingCount=b.stabbingCount;b.value=k;b.proxy=a;b.stabbingCount=u};C.b2BoundValues=function(){};C.prototype.b2BoundValues=function(){this.lowerValues=new Vector_a2j_Number;this.lowerValues[0]=0;this.lowerValues[1]=
0;this.upperValues=new Vector_a2j_Number;this.upperValues[0]=0;this.upperValues[1]=0};v.b2Collision=function(){};v.ClipSegmentToLine=function(b,k,a,u){u===void 0&&(u=0);var g,n=0;g=k[0];var d=g.v;g=k[1];var o=g.v,f=a.x*d.x+a.y*d.y-u;g=a.x*o.x+a.y*o.y-u;f<=0&&b[n++].Set(k[0]);g<=0&&b[n++].Set(k[1]);if(f*g<0)a=f/(f-g),g=b[n],g=g.v,g.x=d.x+a*(o.x-d.x),g.y=d.y+a*(o.y-d.y),g=b[n],g.id=(f>0?k[0]:k[1]).id,++n;return n};v.EdgeSeparation=function(b,k,a,g,u){a===void 0&&(a=0);parseInt(b.m_vertexCount);var n=
b.m_vertices,b=b.m_normals,d=parseInt(g.m_vertexCount),o=g.m_vertices,f,t;f=k.R;t=b[a];b=f.col1.x*t.x+f.col2.x*t.y;g=f.col1.y*t.x+f.col2.y*t.y;f=u.R;var c=f.col1.x*b+f.col1.y*g;f=f.col2.x*b+f.col2.y*g;for(var z=0,j=Number.MAX_VALUE,e=0;e<d;++e)t=o[e],t=t.x*c+t.y*f,t<j&&(j=t,z=e);t=n[a];f=k.R;a=k.position.x+(f.col1.x*t.x+f.col2.x*t.y);k=k.position.y+(f.col1.y*t.x+f.col2.y*t.y);t=o[z];f=u.R;n=u.position.x+(f.col1.x*t.x+f.col2.x*t.y);u=u.position.y+(f.col1.y*t.x+f.col2.y*t.y);n-=a;u-=k;return n*b+u*
g};v.FindMaxSeparation=function(b,k,a,g,u){var n=parseInt(k.m_vertexCount),d=k.m_normals,f,o;o=u.R;f=g.m_centroid;var t=u.position.x+(o.col1.x*f.x+o.col2.x*f.y),c=u.position.y+(o.col1.y*f.x+o.col2.y*f.y);o=a.R;f=k.m_centroid;t-=a.position.x+(o.col1.x*f.x+o.col2.x*f.y);c-=a.position.y+(o.col1.y*f.x+o.col2.y*f.y);o=t*a.R.col1.x+c*a.R.col1.y;for(var c=t*a.R.col2.x+c*a.R.col2.y,t=0,z=-Number.MAX_VALUE,j=0;j<n;++j)f=d[j],f=f.x*o+f.y*c,f>z&&(z=f,t=j);d=v.EdgeSeparation(k,a,t,g,u);f=parseInt(t-1>=0?t-1:
n-1);o=v.EdgeSeparation(k,a,f,g,u);var c=parseInt(t+1<n?t+1:0),z=v.EdgeSeparation(k,a,c,g,u),e=j=0,h=0;if(o>d&&o>z)h=-1,j=f,e=o;else if(z>d)h=1,j=c,e=z;else return b[0]=t,d;for(;;)if(t=h==-1?j-1>=0?j-1:n-1:j+1<n?j+1:0,d=v.EdgeSeparation(k,a,t,g,u),d>e)j=t,e=d;else break;b[0]=j;return e};v.FindIncidentEdge=function(b,k,a,u,g,n){u===void 0&&(u=0);parseInt(k.m_vertexCount);var f=k.m_normals,o=parseInt(g.m_vertexCount),k=g.m_vertices,g=g.m_normals,d;d=a.R;var a=f[u],f=d.col1.x*a.x+d.col2.x*a.y,t=d.col1.y*
a.x+d.col2.y*a.y;d=n.R;a=d.col1.x*f+d.col1.y*t;t=d.col2.x*f+d.col2.y*t;f=a;d=0;for(var c=Number.MAX_VALUE,z=0;z<o;++z)a=g[z],a=f*a.x+t*a.y,a<c&&(c=a,d=z);g=parseInt(d);f=parseInt(g+1<o?g+1:0);o=b[0];a=k[g];d=n.R;o.v.x=n.position.x+(d.col1.x*a.x+d.col2.x*a.y);o.v.y=n.position.y+(d.col1.y*a.x+d.col2.y*a.y);o.id.features.referenceEdge=u;o.id.features.incidentEdge=g;o.id.features.incidentVertex=0;o=b[1];a=k[f];d=n.R;o.v.x=n.position.x+(d.col1.x*a.x+d.col2.x*a.y);o.v.y=n.position.y+(d.col1.y*a.x+d.col2.y*
a.y);o.id.features.referenceEdge=u;o.id.features.incidentEdge=f;o.id.features.incidentVertex=1};v.MakeClipPointVector=function(){var N=new Vector(2);N[0]=new b;N[1]=new b;return N};v.CollidePolygons=function(b,k,a,g,u){var n;b.m_pointCount=0;var d=k.m_radius+g.m_radius;v.s_edgeAO[0]=0;var f=v.FindMaxSeparation(v.s_edgeAO,k,a,g,u);n=v.s_edgeAO[0];if(!(f>d)){var o;v.s_edgeBO[0]=0;var t=v.FindMaxSeparation(v.s_edgeBO,g,u,k,a);o=v.s_edgeBO[0];if(!(t>d)){var c=0,z=0;t>0.98*f+0.001?(f=g,g=k,k=u,c=o,b.m_type=
A.e_faceB,z=1):(f=k,k=a,a=u,c=n,b.m_type=A.e_faceA,z=0);n=v.s_incidentEdge;v.FindIncidentEdge(n,f,k,c,g,a);o=parseInt(f.m_vertexCount);var u=f.m_vertices,f=u[c],j;j=c+1<o?u[parseInt(c+1)]:u[0];c=v.s_localTangent;c.Set(j.x-f.x,j.y-f.y);c.Normalize();u=v.s_localNormal;u.x=c.y;u.y=-c.x;g=v.s_planePoint;g.Set(0.5*(f.x+j.x),0.5*(f.y+j.y));t=v.s_tangent;o=k.R;t.x=o.col1.x*c.x+o.col2.x*c.y;t.y=o.col1.y*c.x+o.col2.y*c.y;var h=v.s_tangent2;h.x=-t.x;h.y=-t.y;c=v.s_normal;c.x=t.y;c.y=-t.x;var x=v.s_v11,p=v.s_v12;
x.x=k.position.x+(o.col1.x*f.x+o.col2.x*f.y);x.y=k.position.y+(o.col1.y*f.x+o.col2.y*f.y);p.x=k.position.x+(o.col1.x*j.x+o.col2.x*j.y);p.y=k.position.y+(o.col1.y*j.x+o.col2.y*j.y);k=c.x*x.x+c.y*x.y;o=t.x*p.x+t.y*p.y+d;j=v.s_clipPoints1;f=v.s_clipPoints2;p=0;p=v.ClipSegmentToLine(j,n,h,-t.x*x.x-t.y*x.y+d);if(!(p<2)&&(p=v.ClipSegmentToLine(f,j,t,o),!(p<2))){b.m_localPlaneNormal.SetV(u);b.m_localPoint.SetV(g);for(g=u=0;g<e.b2_maxManifoldPoints;++g)if(n=f[g],c.x*n.v.x+c.y*n.v.y-k<=d)t=b.m_points[u],o=
a.R,h=n.v.x-a.position.x,x=n.v.y-a.position.y,t.m_localPoint.x=h*o.col1.x+x*o.col1.y,t.m_localPoint.y=h*o.col2.x+x*o.col2.y,t.m_id.Set(n.id),t.m_id.features.flip=z,++u;b.m_pointCount=u}}}};v.CollideCircles=function(b,k,a,g,u){b.m_pointCount=0;var n,o;n=a.R;o=k.m_p;var f=a.position.x+(n.col1.x*o.x+n.col2.x*o.y),a=a.position.y+(n.col1.y*o.x+n.col2.y*o.y);n=u.R;o=g.m_p;f=u.position.x+(n.col1.x*o.x+n.col2.x*o.y)-f;u=u.position.y+(n.col1.y*o.x+n.col2.y*o.y)-a;n=k.m_radius+g.m_radius;if(!(f*f+u*u>n*n))b.m_type=
A.e_circles,b.m_localPoint.SetV(k.m_p),b.m_localPlaneNormal.SetZero(),b.m_pointCount=1,b.m_points[0].m_localPoint.SetV(g.m_p),b.m_points[0].m_id.key=0};v.CollidePolygonAndCircle=function(b,k,a,u,g){var n=b.m_pointCount=0,o=0,f,d;d=g.R;f=u.m_p;var t=g.position.y+(d.col1.y*f.x+d.col2.y*f.y),n=g.position.x+(d.col1.x*f.x+d.col2.x*f.y)-a.position.x,o=t-a.position.y;d=a.R;a=n*d.col1.x+o*d.col1.y;d=n*d.col2.x+o*d.col2.y;for(var c=0,t=-Number.MAX_VALUE,g=k.m_radius+u.m_radius,z=parseInt(k.m_vertexCount),
j=k.m_vertices,k=k.m_normals,e=0;e<z;++e){f=j[e];n=a-f.x;o=d-f.y;f=k[e];n=f.x*n+f.y*o;if(n>g)return;n>t&&(t=n,c=e)}n=parseInt(c);o=parseInt(n+1<z?n+1:0);f=j[n];j=j[o];if(t<Number.MIN_VALUE)b.m_pointCount=1,b.m_type=A.e_faceA,b.m_localPlaneNormal.SetV(k[c]),b.m_localPoint.x=0.5*(f.x+j.x),b.m_localPoint.y=0.5*(f.y+j.y);else if(t=(a-j.x)*(f.x-j.x)+(d-j.y)*(f.y-j.y),(a-f.x)*(j.x-f.x)+(d-f.y)*(j.y-f.y)<=0){if((a-f.x)*(a-f.x)+(d-f.y)*(d-f.y)>g*g)return;b.m_pointCount=1;b.m_type=A.e_faceA;b.m_localPlaneNormal.x=
a-f.x;b.m_localPlaneNormal.y=d-f.y;b.m_localPlaneNormal.Normalize();b.m_localPoint.SetV(f)}else if(t<=0){if((a-j.x)*(a-j.x)+(d-j.y)*(d-j.y)>g*g)return;b.m_pointCount=1;b.m_type=A.e_faceA;b.m_localPlaneNormal.x=a-j.x;b.m_localPlaneNormal.y=d-j.y;b.m_localPlaneNormal.Normalize();b.m_localPoint.SetV(j)}else{c=0.5*(f.x+j.x);f=0.5*(f.y+j.y);t=(a-c)*k[n].x+(d-f)*k[n].y;if(t>g)return;b.m_pointCount=1;b.m_type=A.e_faceA;b.m_localPlaneNormal.x=k[n].x;b.m_localPlaneNormal.y=k[n].y;b.m_localPlaneNormal.Normalize();
b.m_localPoint.Set(c,f)}b.m_points[0].m_localPoint.SetV(u.m_p);b.m_points[0].m_id.key=0};v.TestOverlap=function(b,k){var a=k.lowerBound,g=b.upperBound,n=a.x-g.x,u=a.y-g.y,a=b.lowerBound,g=k.upperBound,f=a.y-g.y;return n>0||u>0?!1:a.x-g.x>0||f>0?!1:!0};Box2D.postDefs.push(function(){Box2D.Collision.b2Collision.s_incidentEdge=v.MakeClipPointVector();Box2D.Collision.b2Collision.s_clipPoints1=v.MakeClipPointVector();Box2D.Collision.b2Collision.s_clipPoints2=v.MakeClipPointVector();Box2D.Collision.b2Collision.s_edgeAO=
new Vector_a2j_Number(1);Box2D.Collision.b2Collision.s_edgeBO=new Vector_a2j_Number(1);Box2D.Collision.b2Collision.s_localTangent=new c;Box2D.Collision.b2Collision.s_localNormal=new c;Box2D.Collision.b2Collision.s_planePoint=new c;Box2D.Collision.b2Collision.s_normal=new c;Box2D.Collision.b2Collision.s_tangent=new c;Box2D.Collision.b2Collision.s_tangent2=new c;Box2D.Collision.b2Collision.s_v11=new c;Box2D.Collision.b2Collision.s_v12=new c;Box2D.Collision.b2Collision.b2CollidePolyTempVec=new c;Box2D.Collision.b2Collision.b2_nullFeature=
255});y.b2ContactID=function(){this.features=new k};y.prototype.b2ContactID=function(){this.features._m_id=this};y.prototype.Set=function(b){this.key=b._key};y.prototype.Copy=function(){var b=new y;b.key=this.key;return b};Object.defineProperty(y.prototype,"key",{enumerable:!1,configurable:!0,get:function(){return this._key}});Object.defineProperty(y.prototype,"key",{enumerable:!1,configurable:!0,set:function(b){b===void 0&&(b=0);this._key=b;this.features._referenceEdge=this._key&255;this.features._incidentEdge=
(this._key&65280)>>8&255;this.features._incidentVertex=(this._key&16711680)>>16&255;this.features._flip=(this._key&4278190080)>>24&255}});s.b2ContactPoint=function(){this.position=new c;this.velocity=new c;this.normal=new c;this.id=new y};J.b2Distance=function(){};J.Distance=function(b,k,a){++J.b2_gjkCalls;var g=a.proxyA,n=a.proxyB,u=a.transformA,f=a.transformB,o=J.s_simplex;o.ReadCache(k,g,u,n,f);var d=o.m_vertices,t=J.s_saveA,z=J.s_saveB,j=0;o.GetClosestPoint().LengthSquared();for(var x=0,p,l=0;l<
20;){j=o.m_count;for(x=0;x<j;x++)t[x]=d[x].indexA,z[x]=d[x].indexB;switch(o.m_count){case 1:break;case 2:o.Solve2();break;case 3:o.Solve3();break;default:e.b2Assert(!1)}if(o.m_count==3)break;p=o.GetClosestPoint();p.LengthSquared();x=o.GetSearchDirection();if(x.LengthSquared()<Number.MIN_VALUE*Number.MIN_VALUE)break;p=d[o.m_count];p.indexA=g.GetSupport(h.MulTMV(u.R,x.GetNegative()));p.wA=h.MulX(u,g.GetVertex(p.indexA));p.indexB=n.GetSupport(h.MulTMV(f.R,x));p.wB=h.MulX(f,n.GetVertex(p.indexB));p.w=
h.SubtractVV(p.wB,p.wA);++l;++J.b2_gjkIters;for(var B=!1,x=0;x<j;x++)if(p.indexA==t[x]&&p.indexB==z[x]){B=!0;break}if(B)break;++o.m_count}J.b2_gjkMaxIters=h.Max(J.b2_gjkMaxIters,l);o.GetWitnessPoints(b.pointA,b.pointB);b.distance=h.SubtractVV(b.pointA,b.pointB).Length();b.iterations=l;o.WriteCache(k);if(a.useRadii)k=g.m_radius,n=n.m_radius,b.distance>k+n&&b.distance>Number.MIN_VALUE?(b.distance-=k+n,a=h.SubtractVV(b.pointB,b.pointA),a.Normalize(),b.pointA.x+=k*a.x,b.pointA.y+=k*a.y,b.pointB.x-=n*
a.x,b.pointB.y-=n*a.y):(p=new c,p.x=0.5*(b.pointA.x+b.pointB.x),p.y=0.5*(b.pointA.y+b.pointB.y),b.pointA.x=b.pointB.x=p.x,b.pointA.y=b.pointB.y=p.y,b.distance=0)};Box2D.postDefs.push(function(){Box2D.Collision.b2Distance.s_simplex=new g;Box2D.Collision.b2Distance.s_saveA=new Vector_a2j_Number(3);Box2D.Collision.b2Distance.s_saveB=new Vector_a2j_Number(3)});K.b2DistanceInput=function(){};d.b2DistanceOutput=function(){this.pointA=new c;this.pointB=new c};x.b2DistanceProxy=function(){};x.prototype.Set=
function(b){switch(b.GetType()){case q.e_circleShape:b=b instanceof m?b:null;this.m_vertices=new Vector(1,!0);this.m_vertices[0]=b.m_p;this.m_count=1;this.m_radius=b.m_radius;break;case q.e_polygonShape:b=b instanceof r?b:null;this.m_vertices=b.m_vertices;this.m_count=b.m_vertexCount;this.m_radius=b.m_radius;break;default:e.b2Assert(!1)}};x.prototype.GetSupport=function(b){for(var a=0,k=this.m_vertices[0].x*b.x+this.m_vertices[0].y*b.y,g=1;g<this.m_count;++g){var n=this.m_vertices[g].x*b.x+this.m_vertices[g].y*
b.y;n>k&&(a=g,k=n)}return a};x.prototype.GetSupportVertex=function(b){for(var a=0,k=this.m_vertices[0].x*b.x+this.m_vertices[0].y*b.y,g=1;g<this.m_count;++g){var n=this.m_vertices[g].x*b.x+this.m_vertices[g].y*b.y;n>k&&(a=g,k=n)}return this.m_vertices[a]};x.prototype.GetVertexCount=function(){return this.m_count};x.prototype.GetVertex=function(b){b===void 0&&(b=0);e.b2Assert(0<=b&&b<this.m_count);return this.m_vertices[b]};j.b2DynamicTree=function(){};j.prototype.b2DynamicTree=function(){this.m_freeList=
this.m_root=null;this.m_insertionCount=this.m_path=0};j.prototype.CreateProxy=function(b,a){var k=this.AllocateNode(),g=e.b2_aabbExtension,n=e.b2_aabbExtension;k.aabb.lowerBound.x=b.lowerBound.x-g;k.aabb.lowerBound.y=b.lowerBound.y-n;k.aabb.upperBound.x=b.upperBound.x+g;k.aabb.upperBound.y=b.upperBound.y+n;k.userData=a;this.InsertLeaf(k);return k};j.prototype.DestroyProxy=function(b){this.RemoveLeaf(b);this.FreeNode(b)};j.prototype.MoveProxy=function(b,k,a){e.b2Assert(b.IsLeaf());if(b.aabb.Contains(k))return!1;
this.RemoveLeaf(b);var g=e.b2_aabbExtension+e.b2_aabbMultiplier*(a.x>0?a.x:-a.x),a=e.b2_aabbExtension+e.b2_aabbMultiplier*(a.y>0?a.y:-a.y);b.aabb.lowerBound.x=k.lowerBound.x-g;b.aabb.lowerBound.y=k.lowerBound.y-a;b.aabb.upperBound.x=k.upperBound.x+g;b.aabb.upperBound.y=k.upperBound.y+a;this.InsertLeaf(b);return!0};j.prototype.Rebalance=function(b){b===void 0&&(b=0);if(this.m_root!=null)for(var a=0;a<b;a++){for(var k=this.m_root,g=0;k.IsLeaf()==!1;)k=this.m_path>>g&1?k.child2:k.child1,g=g+1&31;++this.m_path;
this.RemoveLeaf(k);this.InsertLeaf(k)}};j.prototype.GetFatAABB=function(b){return b.aabb};j.prototype.GetUserData=function(b){return b.userData};j.prototype.Query=function(b,k){if(this.m_root!=null){var a=new Vector,g=0;for(a[g++]=this.m_root;g>0;){var n=a[--g];if(n.aabb.TestOverlap(k))if(n.IsLeaf()){if(!b(n))break}else a[g++]=n.child1,a[g++]=n.child2}}};j.prototype.RayCast=function(b,a){if(this.m_root!=null){var k=a.p1,g=a.p2,n=h.SubtractVV(k,g);n.Normalize();var n=h.CrossFV(1,n),u=h.AbsV(n),f=a.maxFraction,
o=new p,d=0,t=0,d=k.x+f*(g.x-k.x),t=k.y+f*(g.y-k.y);o.lowerBound.x=Math.min(k.x,d);o.lowerBound.y=Math.min(k.y,t);o.upperBound.x=Math.max(k.x,d);o.upperBound.y=Math.max(k.y,t);var c=new Vector,z=0;for(c[z++]=this.m_root;z>0;)if(f=c[--z],f.aabb.TestOverlap(o)!=!1&&(d=f.aabb.GetCenter(),t=f.aabb.GetExtents(),!(Math.abs(n.x*(k.x-d.x)+n.y*(k.y-d.y))-u.x*t.x-u.y*t.y>0)))if(f.IsLeaf()){d=new F;d.p1=a.p1;d.p2=a.p2;d.maxFraction=a.maxFraction;f=b(d,f);if(f==0)break;if(f>0)d=k.x+f*(g.x-k.x),t=k.y+f*(g.y-k.y),
o.lowerBound.x=Math.min(k.x,d),o.lowerBound.y=Math.min(k.y,t),o.upperBound.x=Math.max(k.x,d),o.upperBound.y=Math.max(k.y,t)}else c[z++]=f.child1,c[z++]=f.child2}};j.prototype.AllocateNode=function(){if(this.m_freeList){var b=this.m_freeList;this.m_freeList=b.parent;b.parent=null;b.child1=null;b.child2=null;return b}return new E};j.prototype.FreeNode=function(b){b.parent=this.m_freeList;this.m_freeList=b};j.prototype.InsertLeaf=function(b){++this.m_insertionCount;if(this.m_root==null)this.m_root=b,
this.m_root.parent=null;else{var k=b.aabb.GetCenter(),a=this.m_root;if(a.IsLeaf()==!1){do var g=a.child1,a=a.child2,n=Math.abs((g.aabb.lowerBound.x+g.aabb.upperBound.x)/2-k.x)+Math.abs((g.aabb.lowerBound.y+g.aabb.upperBound.y)/2-k.y),u=Math.abs((a.aabb.lowerBound.x+a.aabb.upperBound.x)/2-k.x)+Math.abs((a.aabb.lowerBound.y+a.aabb.upperBound.y)/2-k.y),a=n<u?g:a;while(a.IsLeaf()==!1)}k=a.parent;g=this.AllocateNode();g.parent=k;g.userData=null;g.aabb.Combine(b.aabb,a.aabb);if(k){a.parent.child1==a?k.child1=
g:k.child2=g;g.child1=a;g.child2=b;a.parent=g;b.parent=g;do{if(k.aabb.Contains(g.aabb))break;k.aabb.Combine(k.child1.aabb,k.child2.aabb);g=k;k=k.parent}while(k)}else g.child1=a,g.child2=b,a.parent=g,this.m_root=b.parent=g}};j.prototype.RemoveLeaf=function(b){if(b==this.m_root)this.m_root=null;else{var k=b.parent,a=k.parent,b=k.child1==b?k.child2:k.child1;if(a){a.child1==k?a.child1=b:a.child2=b;b.parent=a;for(this.FreeNode(k);a;){k=a.aabb;a.aabb=p.Combine(a.child1.aabb,a.child2.aabb);if(k.Contains(a.aabb))break;
a=a.parent}}else this.m_root=b,b.parent=null,this.FreeNode(k)}};B.b2DynamicTreeBroadPhase=function(){this.m_tree=new j;this.m_moveBuffer=new Vector;this.m_pairBuffer=new Vector;this.m_pairCount=0};B.prototype.CreateProxy=function(b,k){var a=this.m_tree.CreateProxy(b,k);++this.m_proxyCount;this.BufferMove(a);return a};B.prototype.DestroyProxy=function(b){this.UnBufferMove(b);--this.m_proxyCount;this.m_tree.DestroyProxy(b)};B.prototype.MoveProxy=function(b,k,a){this.m_tree.MoveProxy(b,k,a)&&this.BufferMove(b)};
B.prototype.TestOverlap=function(b,k){var a=this.m_tree.GetFatAABB(b),g=this.m_tree.GetFatAABB(k);return a.TestOverlap(g)};B.prototype.GetUserData=function(b){return this.m_tree.GetUserData(b)};B.prototype.GetFatAABB=function(b){return this.m_tree.GetFatAABB(b)};B.prototype.GetProxyCount=function(){return this.m_proxyCount};B.prototype.UpdatePairs=function(b){for(var k=this,a=k.m_pairCount=0,g,a=0;a<k.m_moveBuffer.length;++a){g=k.m_moveBuffer[a];var n=k.m_tree.GetFatAABB(g);k.m_tree.Query(function(b){if(b==
g)return!0;k.m_pairCount==k.m_pairBuffer.length&&(k.m_pairBuffer[k.m_pairCount]=new G);var a=k.m_pairBuffer[k.m_pairCount];a.proxyA=b<g?b:g;a.proxyB=b>=g?b:g;++k.m_pairCount;return!0},n)}for(a=k.m_moveBuffer.length=0;a<k.m_pairCount;){var n=k.m_pairBuffer[a],u=k.m_tree.GetUserData(n.proxyA),f=k.m_tree.GetUserData(n.proxyB);b(u,f);for(++a;a<k.m_pairCount;){u=k.m_pairBuffer[a];if(u.proxyA!=n.proxyA||u.proxyB!=n.proxyB)break;++a}}};B.prototype.Query=function(b,k){this.m_tree.Query(b,k)};B.prototype.RayCast=
function(b,k){this.m_tree.RayCast(b,k)};B.prototype.Validate=function(){};B.prototype.Rebalance=function(b){b===void 0&&(b=0);this.m_tree.Rebalance(b)};B.prototype.BufferMove=function(b){this.m_moveBuffer[this.m_moveBuffer.length]=b};B.prototype.UnBufferMove=function(b){this.m_moveBuffer.splice(parseInt(this.m_moveBuffer.indexOf(b)),1)};B.prototype.ComparePairs=function(){return 0};B.__implements={};B.__implements[u]=!0;E.b2DynamicTreeNode=function(){this.aabb=new p};E.prototype.IsLeaf=function(){return this.child1==
null};G.b2DynamicTreePair=function(){};A.b2Manifold=function(){this.m_pointCount=0};A.prototype.b2Manifold=function(){this.m_points=new Vector(e.b2_maxManifoldPoints);for(var b=0;b<e.b2_maxManifoldPoints;b++)this.m_points[b]=new L;this.m_localPlaneNormal=new c;this.m_localPoint=new c};A.prototype.Reset=function(){for(var b=0;b<e.b2_maxManifoldPoints;b++)(this.m_points[b]instanceof L?this.m_points[b]:null).Reset();this.m_localPlaneNormal.SetZero();this.m_localPoint.SetZero();this.m_pointCount=this.m_type=
0};A.prototype.Set=function(b){this.m_pointCount=b.m_pointCount;for(var k=0;k<e.b2_maxManifoldPoints;k++)(this.m_points[k]instanceof L?this.m_points[k]:null).Set(b.m_points[k]);this.m_localPlaneNormal.SetV(b.m_localPlaneNormal);this.m_localPoint.SetV(b.m_localPoint);this.m_type=b.m_type};A.prototype.Copy=function(){var b=new A;b.Set(this);return b};Box2D.postDefs.push(function(){Box2D.Collision.b2Manifold.e_circles=1;Box2D.Collision.b2Manifold.e_faceA=2;Box2D.Collision.b2Manifold.e_faceB=4});L.b2ManifoldPoint=
function(){this.m_localPoint=new c;this.m_id=new y};L.prototype.b2ManifoldPoint=function(){this.Reset()};L.prototype.Reset=function(){this.m_localPoint.SetZero();this.m_tangentImpulse=this.m_normalImpulse=0;this.m_id.key=0};L.prototype.Set=function(b){this.m_localPoint.SetV(b.m_localPoint);this.m_normalImpulse=b.m_normalImpulse;this.m_tangentImpulse=b.m_tangentImpulse;this.m_id.Set(b.m_id)};D.b2Point=function(){this.p=new c};D.prototype.Support=function(){return this.p};D.prototype.GetFirstVertex=
function(){return this.p};F.b2RayCastInput=function(){this.p1=new c;this.p2=new c};F.prototype.b2RayCastInput=function(b,k,a){b===void 0&&(b=null);k===void 0&&(k=null);a===void 0&&(a=1);b&&this.p1.SetV(b);k&&this.p2.SetV(k);this.maxFraction=a};M.b2RayCastOutput=function(){this.normal=new c};I.b2Segment=function(){this.p1=new c;this.p2=new c};I.prototype.TestSegment=function(b,k,a,g){g===void 0&&(g=0);var n=a.p1,u=a.p2.x-n.x,f=a.p2.y-n.y,a=this.p2.y-this.p1.y,o=-(this.p2.x-this.p1.x),d=100*Number.MIN_VALUE,
t=-(u*a+f*o);if(t>d){var c=n.x-this.p1.x,z=n.y-this.p1.y,n=c*a+z*o;if(0<=n&&n<=g*t&&(g=-u*z+f*c,-d*t<=g&&g<=t*(1+d)))return n/=t,g=Math.sqrt(a*a+o*o),a/=g,o/=g,b[0]=n,k.Set(a,o),!0}return!1};I.prototype.Extend=function(b){this.ExtendForward(b);this.ExtendBackward(b)};I.prototype.ExtendForward=function(b){var k=this.p2.x-this.p1.x,a=this.p2.y-this.p1.y,b=Math.min(k>0?(b.upperBound.x-this.p1.x)/k:k<0?(b.lowerBound.x-this.p1.x)/k:Number.POSITIVE_INFINITY,a>0?(b.upperBound.y-this.p1.y)/a:a<0?(b.lowerBound.y-
this.p1.y)/a:Number.POSITIVE_INFINITY);this.p2.x=this.p1.x+k*b;this.p2.y=this.p1.y+a*b};I.prototype.ExtendBackward=function(b){var k=-this.p2.x+this.p1.x,a=-this.p2.y+this.p1.y,b=Math.min(k>0?(b.upperBound.x-this.p2.x)/k:k<0?(b.lowerBound.x-this.p2.x)/k:Number.POSITIVE_INFINITY,a>0?(b.upperBound.y-this.p2.y)/a:a<0?(b.lowerBound.y-this.p2.y)/a:Number.POSITIVE_INFINITY);this.p1.x=this.p2.x+k*b;this.p1.y=this.p2.y+a*b};a.b2SeparationFunction=function(){this.m_localPoint=new c;this.m_axis=new c};a.prototype.Initialize=
function(b,k,g,n,u){this.m_proxyA=k;this.m_proxyB=n;var f=parseInt(b.count);e.b2Assert(0<f&&f<3);var o,d,t,z,j=z=t=n=k=0,x=0,j=0;f==1?(this.m_type=a.e_points,o=this.m_proxyA.GetVertex(b.indexA[0]),d=this.m_proxyB.GetVertex(b.indexB[0]),f=o,b=g.R,k=g.position.x+(b.col1.x*f.x+b.col2.x*f.y),n=g.position.y+(b.col1.y*f.x+b.col2.y*f.y),f=d,b=u.R,t=u.position.x+(b.col1.x*f.x+b.col2.x*f.y),z=u.position.y+(b.col1.y*f.x+b.col2.y*f.y),this.m_axis.x=t-k,this.m_axis.y=z-n,this.m_axis.Normalize()):(b.indexB[0]==
b.indexB[1]?(this.m_type=a.e_faceA,k=this.m_proxyA.GetVertex(b.indexA[0]),n=this.m_proxyA.GetVertex(b.indexA[1]),d=this.m_proxyB.GetVertex(b.indexB[0]),this.m_localPoint.x=0.5*(k.x+n.x),this.m_localPoint.y=0.5*(k.y+n.y),this.m_axis=h.CrossVF(h.SubtractVV(n,k),1),this.m_axis.Normalize(),f=this.m_axis,b=g.R,j=b.col1.x*f.x+b.col2.x*f.y,x=b.col1.y*f.x+b.col2.y*f.y,f=this.m_localPoint,b=g.R,k=g.position.x+(b.col1.x*f.x+b.col2.x*f.y),n=g.position.y+(b.col1.y*f.x+b.col2.y*f.y),f=d,b=u.R,t=u.position.x+(b.col1.x*
f.x+b.col2.x*f.y),z=u.position.y+(b.col1.y*f.x+b.col2.y*f.y),j=(t-k)*j+(z-n)*x):b.indexA[0]==b.indexA[0]?(this.m_type=a.e_faceB,t=this.m_proxyB.GetVertex(b.indexB[0]),z=this.m_proxyB.GetVertex(b.indexB[1]),o=this.m_proxyA.GetVertex(b.indexA[0]),this.m_localPoint.x=0.5*(t.x+z.x),this.m_localPoint.y=0.5*(t.y+z.y),this.m_axis=h.CrossVF(h.SubtractVV(z,t),1),this.m_axis.Normalize(),f=this.m_axis,b=u.R,j=b.col1.x*f.x+b.col2.x*f.y,x=b.col1.y*f.x+b.col2.y*f.y,f=this.m_localPoint,b=u.R,t=u.position.x+(b.col1.x*
f.x+b.col2.x*f.y),z=u.position.y+(b.col1.y*f.x+b.col2.y*f.y),f=o,b=g.R,k=g.position.x+(b.col1.x*f.x+b.col2.x*f.y),n=g.position.y+(b.col1.y*f.x+b.col2.y*f.y),j=(k-t)*j+(n-z)*x):(k=this.m_proxyA.GetVertex(b.indexA[0]),n=this.m_proxyA.GetVertex(b.indexA[1]),t=this.m_proxyB.GetVertex(b.indexB[0]),z=this.m_proxyB.GetVertex(b.indexB[1]),h.MulX(g,o),o=h.MulMV(g.R,h.SubtractVV(n,k)),h.MulX(u,d),j=h.MulMV(u.R,h.SubtractVV(z,t)),u=o.x*o.x+o.y*o.y,d=j.x*j.x+j.y*j.y,b=h.SubtractVV(j,o),g=o.x*b.x+o.y*b.y,b=j.x*
b.x+j.y*b.y,o=o.x*j.x+o.y*j.y,x=u*d-o*o,j=0,x!=0&&(j=h.Clamp((o*b-g*d)/x,0,1)),(o*j+b)/d<0&&(j=h.Clamp((o-g)/u,0,1)),o=new c,o.x=k.x+j*(n.x-k.x),o.y=k.y+j*(n.y-k.y),d=new c,d.x=t.x+j*(z.x-t.x),d.y=t.y+j*(z.y-t.y),j==0||j==1?(this.m_type=a.e_faceB,this.m_axis=h.CrossVF(h.SubtractVV(z,t),1),this.m_axis.Normalize(),this.m_localPoint=d):(this.m_type=a.e_faceA,this.m_axis=h.CrossVF(h.SubtractVV(n,k),1),this.m_localPoint=o)),j<0&&this.m_axis.NegativeSelf())};a.prototype.Evaluate=function(b,k){var g,n,u=
0;switch(this.m_type){case a.e_points:return g=h.MulTMV(b.R,this.m_axis),n=h.MulTMV(k.R,this.m_axis.GetNegative()),g=this.m_proxyA.GetSupportVertex(g),n=this.m_proxyB.GetSupportVertex(n),g=h.MulX(b,g),n=h.MulX(k,n),u=(n.x-g.x)*this.m_axis.x+(n.y-g.y)*this.m_axis.y;case a.e_faceA:return u=h.MulMV(b.R,this.m_axis),g=h.MulX(b,this.m_localPoint),n=h.MulTMV(k.R,u.GetNegative()),n=this.m_proxyB.GetSupportVertex(n),n=h.MulX(k,n),u=(n.x-g.x)*u.x+(n.y-g.y)*u.y;case a.e_faceB:return u=h.MulMV(k.R,this.m_axis),
n=h.MulX(k,this.m_localPoint),g=h.MulTMV(b.R,u.GetNegative()),g=this.m_proxyA.GetSupportVertex(g),g=h.MulX(b,g),u=(g.x-n.x)*u.x+(g.y-n.y)*u.y;default:return e.b2Assert(!1),0}};Box2D.postDefs.push(function(){Box2D.Collision.b2SeparationFunction.e_points=1;Box2D.Collision.b2SeparationFunction.e_faceA=2;Box2D.Collision.b2SeparationFunction.e_faceB=4});g.b2Simplex=function(){this.m_v1=new n;this.m_v2=new n;this.m_v3=new n;this.m_vertices=new Vector(3)};g.prototype.b2Simplex=function(){this.m_vertices[0]=
this.m_v1;this.m_vertices[1]=this.m_v2;this.m_vertices[2]=this.m_v3};g.prototype.ReadCache=function(b,k,a,g,n){e.b2Assert(0<=b.count&&b.count<=3);var u,f;this.m_count=b.count;for(var o=this.m_vertices,d=0;d<this.m_count;d++){var t=o[d];t.indexA=b.indexA[d];t.indexB=b.indexB[d];u=k.GetVertex(t.indexA);f=g.GetVertex(t.indexB);t.wA=h.MulX(a,u);t.wB=h.MulX(n,f);t.w=h.SubtractVV(t.wB,t.wA);t.a=0}if(this.m_count>1&&(b=b.metric,u=this.GetMetric(),u<0.5*b||2*b<u||u<Number.MIN_VALUE))this.m_count=0;if(this.m_count==
0)t=o[0],t.indexA=0,t.indexB=0,u=k.GetVertex(0),f=g.GetVertex(0),t.wA=h.MulX(a,u),t.wB=h.MulX(n,f),t.w=h.SubtractVV(t.wB,t.wA),this.m_count=1};g.prototype.WriteCache=function(b){b.metric=this.GetMetric();b.count=Box2D.parseUInt(this.m_count);for(var k=this.m_vertices,a=0;a<this.m_count;a++)b.indexA[a]=Box2D.parseUInt(k[a].indexA),b.indexB[a]=Box2D.parseUInt(k[a].indexB)};g.prototype.GetSearchDirection=function(){switch(this.m_count){case 1:return this.m_v1.w.GetNegative();case 2:var b=h.SubtractVV(this.m_v2.w,
this.m_v1.w);return h.CrossVV(b,this.m_v1.w.GetNegative())>0?h.CrossFV(1,b):h.CrossVF(b,1);default:return e.b2Assert(!1),new c}};g.prototype.GetClosestPoint=function(){switch(this.m_count){case 0:return e.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 e.b2Assert(!1),new c}};g.prototype.GetWitnessPoints=function(b,k){switch(this.m_count){case 0:e.b2Assert(!1);break;
case 1:b.SetV(this.m_v1.wA);k.SetV(this.m_v1.wB);break;case 2:b.x=this.m_v1.a*this.m_v1.wA.x+this.m_v2.a*this.m_v2.wA.x;b.y=this.m_v1.a*this.m_v1.wA.y+this.m_v2.a*this.m_v2.wA.y;k.x=this.m_v1.a*this.m_v1.wB.x+this.m_v2.a*this.m_v2.wB.x;k.y=this.m_v1.a*this.m_v1.wB.y+this.m_v2.a*this.m_v2.wB.y;break;case 3:k.x=b.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;k.y=b.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:e.b2Assert(!1)}};
g.prototype.GetMetric=function(){switch(this.m_count){case 0:return e.b2Assert(!1),0;case 1:return 0;case 2:return h.SubtractVV(this.m_v1.w,this.m_v2.w).Length();case 3:return h.CrossVV(h.SubtractVV(this.m_v2.w,this.m_v1.w),h.SubtractVV(this.m_v3.w,this.m_v1.w));default:return e.b2Assert(!1),0}};g.prototype.Solve2=function(){var b=this.m_v1.w,k=this.m_v2.w,a=h.SubtractVV(k,b),b=-(b.x*a.x+b.y*a.y);b<=0?this.m_count=this.m_v1.a=1:(k=k.x*a.x+k.y*a.y,k<=0?(this.m_count=this.m_v2.a=1,this.m_v1.Set(this.m_v2)):
(a=1/(k+b),this.m_v1.a=k*a,this.m_v2.a=b*a,this.m_count=2))};g.prototype.Solve3=function(){var b=this.m_v1.w,k=this.m_v2.w,a=this.m_v3.w,g=h.SubtractVV(k,b),n=h.Dot(b,g),u=h.Dot(k,g),n=-n,f=h.SubtractVV(a,b),o=h.Dot(b,f),d=h.Dot(a,f),o=-o,t=h.SubtractVV(a,k),c=h.Dot(k,t),t=h.Dot(a,t),c=-c,f=h.CrossVV(g,f),g=f*h.CrossVV(k,a),a=f*h.CrossVV(a,b),b=f*h.CrossVV(b,k);n<=0&&o<=0?this.m_count=this.m_v1.a=1:u>0&&n>0&&b<=0?(d=1/(u+n),this.m_v1.a=u*d,this.m_v2.a=n*d,this.m_count=2):d>0&&o>0&&a<=0?(u=1/(d+o),
this.m_v1.a=d*u,this.m_v3.a=o*u,this.m_count=2,this.m_v2.Set(this.m_v3)):u<=0&&c<=0?(this.m_count=this.m_v2.a=1,this.m_v1.Set(this.m_v2)):d<=0&&t<=0?(this.m_count=this.m_v3.a=1,this.m_v1.Set(this.m_v3)):t>0&&c>0&&g<=0?(u=1/(t+c),this.m_v2.a=t*u,this.m_v3.a=c*u,this.m_count=2,this.m_v1.Set(this.m_v3)):(u=1/(g+a+b),this.m_v1.a=g*u,this.m_v2.a=a*u,this.m_v3.a=b*u,this.m_count=3)};o.b2SimplexCache=function(){this.indexA=new Vector_a2j_Number(3);this.indexB=new Vector_a2j_Number(3)};n.b2SimplexVertex=
function(){};n.prototype.Set=function(b){this.wA.SetV(b.wA);this.wB.SetV(b.wB);this.w.SetV(b.w);this.a=b.a;this.indexA=b.indexA;this.indexB=b.indexB};t.b2TimeOfImpact=function(){};t.TimeOfImpact=function(b){++t.b2_toiCalls;var k=b.proxyA,a=b.proxyB,g=b.sweepA,n=b.sweepB;e.b2Assert(g.t0==n.t0);e.b2Assert(1-g.t0>Number.MIN_VALUE);var u=k.m_radius+a.m_radius,b=b.tolerance,f=0,o=0,d=0;t.s_cache.count=0;for(t.s_distanceInput.useRadii=!1;;){g.GetTransform(t.s_xfA,f);n.GetTransform(t.s_xfB,f);t.s_distanceInput.proxyA=
k;t.s_distanceInput.proxyB=a;t.s_distanceInput.transformA=t.s_xfA;t.s_distanceInput.transformB=t.s_xfB;J.Distance(t.s_distanceOutput,t.s_cache,t.s_distanceInput);if(t.s_distanceOutput.distance<=0){f=1;break}t.s_fcn.Initialize(t.s_cache,k,t.s_xfA,a,t.s_xfB);var c=t.s_fcn.Evaluate(t.s_xfA,t.s_xfB);if(c<=0){f=1;break}o==0&&(d=c>u?h.Max(u-b,0.75*u):h.Max(c-b,0.02*u));if(c-d<0.5*b){if(o==0){f=1;break}break}var z=f,j=f,x=1;g.GetTransform(t.s_xfA,x);n.GetTransform(t.s_xfB,x);var p=t.s_fcn.Evaluate(t.s_xfA,
t.s_xfB);if(p>=d){f=1;break}for(var l=0;;){var B=0,B=l&1?j+(d-c)*(x-j)/(p-c):0.5*(j+x);g.GetTransform(t.s_xfA,B);n.GetTransform(t.s_xfB,B);var A=t.s_fcn.Evaluate(t.s_xfA,t.s_xfB);if(h.Abs(A-d)<0.025*b){z=B;break}A>d?(j=B,c=A):(x=B,p=A);++l;++t.b2_toiRootIters;if(l==50)break}t.b2_toiMaxRootIters=h.Max(t.b2_toiMaxRootIters,l);if(z<(1+100*Number.MIN_VALUE)*f)break;f=z;o++;++t.b2_toiIters;if(o==1E3)break}t.b2_toiMaxIters=h.Max(t.b2_toiMaxIters,o);return f};Box2D.postDefs.push(function(){Box2D.Collision.b2TimeOfImpact.b2_toiCalls=
0;Box2D.Collision.b2TimeOfImpact.b2_toiIters=0;Box2D.Collision.b2TimeOfImpact.b2_toiMaxIters=0;Box2D.Collision.b2TimeOfImpact.b2_toiRootIters=0;Box2D.Collision.b2TimeOfImpact.b2_toiMaxRootIters=0;Box2D.Collision.b2TimeOfImpact.s_cache=new o;Box2D.Collision.b2TimeOfImpact.s_distanceInput=new K;Box2D.Collision.b2TimeOfImpact.s_xfA=new w;Box2D.Collision.b2TimeOfImpact.s_xfB=new w;Box2D.Collision.b2TimeOfImpact.s_fcn=new a;Box2D.Collision.b2TimeOfImpact.s_distanceOutput=new d});z.b2TOIInput=function(){this.proxyA=
new x;this.proxyB=new x;this.sweepA=new l;this.sweepB=new l};f.b2WorldManifold=function(){this.m_normal=new c};f.prototype.b2WorldManifold=function(){this.m_points=new Vector(e.b2_maxManifoldPoints);for(var b=0;b<e.b2_maxManifoldPoints;b++)this.m_points[b]=new c};f.prototype.Initialize=function(b,k,a,g,n){a===void 0&&(a=0);n===void 0&&(n=0);if(b.m_pointCount!=0){var u=0,f,o,d=0,t=0,c=0,z=0,j=0;f=0;switch(b.m_type){case A.e_circles:o=k.R;f=b.m_localPoint;u=k.position.x+o.col1.x*f.x+o.col2.x*f.y;k=
k.position.y+o.col1.y*f.x+o.col2.y*f.y;o=g.R;f=b.m_points[0].m_localPoint;b=g.position.x+o.col1.x*f.x+o.col2.x*f.y;g=g.position.y+o.col1.y*f.x+o.col2.y*f.y;f=b-u;o=g-k;d=f*f+o*o;d>Number.MIN_VALUE*Number.MIN_VALUE?(d=Math.sqrt(d),this.m_normal.x=f/d,this.m_normal.y=o/d):(this.m_normal.x=1,this.m_normal.y=0);f=k+a*this.m_normal.y;g-=n*this.m_normal.y;this.m_points[0].x=0.5*(u+a*this.m_normal.x+(b-n*this.m_normal.x));this.m_points[0].y=0.5*(f+g);break;case A.e_faceA:o=k.R;f=b.m_localPlaneNormal;d=o.col1.x*
f.x+o.col2.x*f.y;t=o.col1.y*f.x+o.col2.y*f.y;o=k.R;f=b.m_localPoint;c=k.position.x+o.col1.x*f.x+o.col2.x*f.y;z=k.position.y+o.col1.y*f.x+o.col2.y*f.y;this.m_normal.x=d;this.m_normal.y=t;for(u=0;u<b.m_pointCount;u++)o=g.R,f=b.m_points[u].m_localPoint,j=g.position.x+o.col1.x*f.x+o.col2.x*f.y,f=g.position.y+o.col1.y*f.x+o.col2.y*f.y,this.m_points[u].x=j+0.5*(a-(j-c)*d-(f-z)*t-n)*d,this.m_points[u].y=f+0.5*(a-(j-c)*d-(f-z)*t-n)*t;break;case A.e_faceB:o=g.R;f=b.m_localPlaneNormal;d=o.col1.x*f.x+o.col2.x*
f.y;t=o.col1.y*f.x+o.col2.y*f.y;o=g.R;f=b.m_localPoint;c=g.position.x+o.col1.x*f.x+o.col2.x*f.y;z=g.position.y+o.col1.y*f.x+o.col2.y*f.y;this.m_normal.x=-d;this.m_normal.y=-t;for(u=0;u<b.m_pointCount;u++)o=k.R,f=b.m_points[u].m_localPoint,j=k.position.x+o.col1.x*f.x+o.col2.x*f.y,f=k.position.y+o.col1.y*f.x+o.col2.y*f.y,this.m_points[u].x=j+0.5*(n-(j-c)*d-(f-z)*t-a)*d,this.m_points[u].y=f+0.5*(n-(j-c)*d-(f-z)*t-a)*t}}};b.ClipVertex=function(){this.v=new c;this.id=new y};b.prototype.Set=function(b){this.v.SetV(b.v);
this.id.Set(b.id)};k.Features=function(){};Object.defineProperty(k.prototype,"referenceEdge",{enumerable:!1,configurable:!0,get:function(){return this._referenceEdge}});Object.defineProperty(k.prototype,"referenceEdge",{enumerable:!1,configurable:!0,set:function(b){b===void 0&&(b=0);this._referenceEdge=b;this._m_id._key=this._m_id._key&4294967040|this._referenceEdge&255}});Object.defineProperty(k.prototype,"incidentEdge",{enumerable:!1,configurable:!0,get:function(){return this._incidentEdge}});Object.defineProperty(k.prototype,
"incidentEdge",{enumerable:!1,configurable:!0,set:function(b){b===void 0&&(b=0);this._incidentEdge=b;this._m_id._key=this._m_id._key&4294902015|this._incidentEdge<<8&65280}});Object.defineProperty(k.prototype,"incidentVertex",{enumerable:!1,configurable:!0,get:function(){return this._incidentVertex}});Object.defineProperty(k.prototype,"incidentVertex",{enumerable:!1,configurable:!0,set:function(b){b===void 0&&(b=0);this._incidentVertex=b;this._m_id._key=this._m_id._key&4278255615|this._incidentVertex<<
16&16711680}});Object.defineProperty(k.prototype,"flip",{enumerable:!1,configurable:!0,get:function(){return this._flip}});Object.defineProperty(k.prototype,"flip",{enumerable:!1,configurable:!0,set:function(b){b===void 0&&(b=0);this._flip=b;this._m_id._key=this._m_id._key&16777215|this._flip<<24&4278190080}})})();
(function(){var m=Box2D.Common.b2Settings,r=Box2D.Collision.Shapes.b2CircleShape,q=Box2D.Collision.Shapes.b2EdgeChainDef,e=Box2D.Collision.Shapes.b2EdgeShape,h=Box2D.Collision.Shapes.b2MassData,l=Box2D.Collision.Shapes.b2PolygonShape,w=Box2D.Collision.Shapes.b2Shape,c=Box2D.Common.Math.b2Mat22,p=Box2D.Common.Math.b2Math,H=Box2D.Common.Math.b2Transform,C=Box2D.Common.Math.b2Vec2,v=Box2D.Collision.b2Distance,y=Box2D.Collision.b2DistanceInput,s=Box2D.Collision.b2DistanceOutput,J=Box2D.Collision.b2DistanceProxy,
K=Box2D.Collision.b2SimplexCache;Box2D.inherit(r,Box2D.Collision.Shapes.b2Shape);r.prototype.__super=Box2D.Collision.Shapes.b2Shape.prototype;r.b2CircleShape=function(){Box2D.Collision.Shapes.b2Shape.b2Shape.apply(this,arguments);this.m_p=new C};r.prototype.Copy=function(){var d=new r;d.Set(this);return d};r.prototype.Set=function(d){this.__super.Set.call(this,d);Box2D.is(d,r)&&this.m_p.SetV((d instanceof r?d:null).m_p)};r.prototype.TestPoint=function(d,c){var j=d.R,e=d.position.x+(j.col1.x*this.m_p.x+
j.col2.x*this.m_p.y),j=d.position.y+(j.col1.y*this.m_p.x+j.col2.y*this.m_p.y),e=c.x-e,j=c.y-j;return e*e+j*j<=this.m_radius*this.m_radius};r.prototype.RayCast=function(d,c,j){var e=j.R,p=c.p1.x-(j.position.x+(e.col1.x*this.m_p.x+e.col2.x*this.m_p.y)),j=c.p1.y-(j.position.y+(e.col1.y*this.m_p.x+e.col2.y*this.m_p.y)),e=c.p2.x-c.p1.x,h=c.p2.y-c.p1.y,l=p*e+j*h,m=e*e+h*h,r=l*l-m*(p*p+j*j-this.m_radius*this.m_radius);if(r<0||m<Number.MIN_VALUE)return!1;l=-(l+Math.sqrt(r));return 0<=l&&l<=c.maxFraction*
m?(l/=m,d.fraction=l,d.normal.x=p+l*e,d.normal.y=j+l*h,d.normal.Normalize(),!0):!1};r.prototype.ComputeAABB=function(d,c){var j=c.R,e=c.position.x+(j.col1.x*this.m_p.x+j.col2.x*this.m_p.y),j=c.position.y+(j.col1.y*this.m_p.x+j.col2.y*this.m_p.y);d.lowerBound.Set(e-this.m_radius,j-this.m_radius);d.upperBound.Set(e+this.m_radius,j+this.m_radius)};r.prototype.ComputeMass=function(d,c){c===void 0&&(c=0);d.mass=c*m.b2_pi*this.m_radius*this.m_radius;d.center.SetV(this.m_p);d.I=d.mass*(0.5*this.m_radius*
this.m_radius+(this.m_p.x*this.m_p.x+this.m_p.y*this.m_p.y))};r.prototype.ComputeSubmergedArea=function(d,c,j,e){c===void 0&&(c=0);var j=p.MulX(j,this.m_p),h=-(p.Dot(d,j)-c);if(h<-this.m_radius+Number.MIN_VALUE)return 0;if(h>this.m_radius)return e.SetV(j),Math.PI*this.m_radius*this.m_radius;var c=this.m_radius*this.m_radius,l=h*h,h=c*(Math.asin(h/this.m_radius)+Math.PI/2)+h*Math.sqrt(c-l),c=-2/3*Math.pow(c-l,1.5)/h;e.x=j.x+d.x*c;e.y=j.y+d.y*c;return h};r.prototype.GetLocalPosition=function(){return this.m_p};
r.prototype.SetLocalPosition=function(d){this.m_p.SetV(d)};r.prototype.GetRadius=function(){return this.m_radius};r.prototype.SetRadius=function(d){d===void 0&&(d=0);this.m_radius=d};r.prototype.b2CircleShape=function(d){d===void 0&&(d=0);this.__super.b2Shape.call(this);this.m_type=w.e_circleShape;this.m_radius=d};q.b2EdgeChainDef=function(){};q.prototype.b2EdgeChainDef=function(){this.vertexCount=0;this.isALoop=!0;this.vertices=[]};Box2D.inherit(e,Box2D.Collision.Shapes.b2Shape);e.prototype.__super=
Box2D.Collision.Shapes.b2Shape.prototype;e.b2EdgeShape=function(){Box2D.Collision.Shapes.b2Shape.b2Shape.apply(this,arguments);this.s_supportVec=new C;this.m_v1=new C;this.m_v2=new C;this.m_coreV1=new C;this.m_coreV2=new C;this.m_normal=new C;this.m_direction=new C;this.m_cornerDir1=new C;this.m_cornerDir2=new C};e.prototype.TestPoint=function(){return!1};e.prototype.RayCast=function(d,c,j){var e,h=c.p2.x-c.p1.x,p=c.p2.y-c.p1.y;e=j.R;var l=j.position.x+(e.col1.x*this.m_v1.x+e.col2.x*this.m_v1.y),
m=j.position.y+(e.col1.y*this.m_v1.x+e.col2.y*this.m_v1.y),r=j.position.y+(e.col1.y*this.m_v2.x+e.col2.y*this.m_v2.y)-m,j=-(j.position.x+(e.col1.x*this.m_v2.x+e.col2.x*this.m_v2.y)-l);e=100*Number.MIN_VALUE;var s=-(h*r+p*j);if(s>e){var l=c.p1.x-l,y=c.p1.y-m,m=l*r+y*j;if(0<=m&&m<=c.maxFraction*s&&(c=-h*y+p*l,-e*s<=c&&c<=s*(1+e)))return m/=s,d.fraction=m,c=Math.sqrt(r*r+j*j),d.normal.x=r/c,d.normal.y=j/c,!0}return!1};e.prototype.ComputeAABB=function(d,c){var j=c.R,e=c.position.x+(j.col1.x*this.m_v1.x+
j.col2.x*this.m_v1.y),h=c.position.y+(j.col1.y*this.m_v1.x+j.col2.y*this.m_v1.y),p=c.position.x+(j.col1.x*this.m_v2.x+j.col2.x*this.m_v2.y),j=c.position.y+(j.col1.y*this.m_v2.x+j.col2.y*this.m_v2.y);e<p?(d.lowerBound.x=e,d.upperBound.x=p):(d.lowerBound.x=p,d.upperBound.x=e);h<j?(d.lowerBound.y=h,d.upperBound.y=j):(d.lowerBound.y=j,d.upperBound.y=h)};e.prototype.ComputeMass=function(d){d.mass=0;d.center.SetV(this.m_v1);d.I=0};e.prototype.ComputeSubmergedArea=function(d,c,j,e){c===void 0&&(c=0);var h=
new C(d.x*c,d.y*c),l=p.MulX(j,this.m_v1),j=p.MulX(j,this.m_v2),m=p.Dot(d,l)-c,d=p.Dot(d,j)-c;if(m>0)if(d>0)return 0;else l.x=-d/(m-d)*l.x+m/(m-d)*j.x,l.y=-d/(m-d)*l.y+m/(m-d)*j.y;else if(d>0)j.x=-d/(m-d)*l.x+m/(m-d)*j.x,j.y=-d/(m-d)*l.y+m/(m-d)*j.y;e.x=(h.x+l.x+j.x)/3;e.y=(h.y+l.y+j.y)/3;return 0.5*((l.x-h.x)*(j.y-h.y)-(l.y-h.y)*(j.x-h.x))};e.prototype.GetLength=function(){return this.m_length};e.prototype.GetVertex1=function(){return this.m_v1};e.prototype.GetVertex2=function(){return this.m_v2};
e.prototype.GetCoreVertex1=function(){return this.m_coreV1};e.prototype.GetCoreVertex2=function(){return this.m_coreV2};e.prototype.GetNormalVector=function(){return this.m_normal};e.prototype.GetDirectionVector=function(){return this.m_direction};e.prototype.GetCorner1Vector=function(){return this.m_cornerDir1};e.prototype.GetCorner2Vector=function(){return this.m_cornerDir2};e.prototype.Corner1IsConvex=function(){return this.m_cornerConvex1};e.prototype.Corner2IsConvex=function(){return this.m_cornerConvex2};
e.prototype.GetFirstVertex=function(d){var c=d.R;return new C(d.position.x+(c.col1.x*this.m_coreV1.x+c.col2.x*this.m_coreV1.y),d.position.y+(c.col1.y*this.m_coreV1.x+c.col2.y*this.m_coreV1.y))};e.prototype.GetNextEdge=function(){return this.m_nextEdge};e.prototype.GetPrevEdge=function(){return this.m_prevEdge};e.prototype.Support=function(d,c,j){c===void 0&&(c=0);j===void 0&&(j=0);var e=d.R,h=d.position.x+(e.col1.x*this.m_coreV1.x+e.col2.x*this.m_coreV1.y),p=d.position.y+(e.col1.y*this.m_coreV1.x+
e.col2.y*this.m_coreV1.y),l=d.position.x+(e.col1.x*this.m_coreV2.x+e.col2.x*this.m_coreV2.y),d=d.position.y+(e.col1.y*this.m_coreV2.x+e.col2.y*this.m_coreV2.y);h*c+p*j>l*c+d*j?(this.s_supportVec.x=h,this.s_supportVec.y=p):(this.s_supportVec.x=l,this.s_supportVec.y=d);return this.s_supportVec};e.prototype.b2EdgeShape=function(d,c){this.__super.b2Shape.call(this);this.m_type=w.e_edgeShape;this.m_nextEdge=this.m_prevEdge=null;this.m_v1=d;this.m_v2=c;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(-m.b2_toiSlop*(this.m_normal.x-this.m_direction.x)+this.m_v1.x,-m.b2_toiSlop*(this.m_normal.y-this.m_direction.y)+this.m_v1.y);this.m_coreV2.Set(-m.b2_toiSlop*(this.m_normal.x+this.m_direction.x)+this.m_v2.x,-m.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)};e.prototype.SetPrevEdge=
function(d,c,j,e){this.m_prevEdge=d;this.m_coreV1=c;this.m_cornerDir1=j;this.m_cornerConvex1=e};e.prototype.SetNextEdge=function(d,c,j,e){this.m_nextEdge=d;this.m_coreV2=c;this.m_cornerDir2=j;this.m_cornerConvex2=e};h.b2MassData=function(){this.mass=0;this.center=new C(0,0);this.I=0};Box2D.inherit(l,Box2D.Collision.Shapes.b2Shape);l.prototype.__super=Box2D.Collision.Shapes.b2Shape.prototype;l.b2PolygonShape=function(){Box2D.Collision.Shapes.b2Shape.b2Shape.apply(this,arguments)};l.prototype.Copy=
function(){var d=new l;d.Set(this);return d};l.prototype.Set=function(d){this.__super.Set.call(this,d);if(Box2D.is(d,l)){d=d instanceof l?d:null;this.m_centroid.SetV(d.m_centroid);this.m_vertexCount=d.m_vertexCount;this.Reserve(this.m_vertexCount);for(var c=0;c<this.m_vertexCount;c++)this.m_vertices[c].SetV(d.m_vertices[c]),this.m_normals[c].SetV(d.m_normals[c])}};l.prototype.SetAsArray=function(d,c){c===void 0&&(c=0);for(var j=new Vector,e=0,h,e=0;e<d.length;++e)h=d[e],j.push(h);this.SetAsVector(j,
c)};l.AsArray=function(d,c){c===void 0&&(c=0);var j=new l;j.SetAsArray(d,c);return j};l.prototype.SetAsVector=function(d,c){c===void 0&&(c=0);if(c==0)c=d.length;m.b2Assert(2<=c);this.m_vertexCount=c;this.Reserve(c);for(var j=0,j=0;j<this.m_vertexCount;j++)this.m_vertices[j].SetV(d[j]);for(j=0;j<this.m_vertexCount;++j){var e=parseInt(j),h=parseInt(j+1<this.m_vertexCount?j+1:0),e=p.SubtractVV(this.m_vertices[h],this.m_vertices[e]);m.b2Assert(e.LengthSquared()>Number.MIN_VALUE);this.m_normals[j].SetV(p.CrossVF(e,
1));this.m_normals[j].Normalize()}this.m_centroid=l.ComputeCentroid(this.m_vertices,this.m_vertexCount)};l.AsVector=function(d,c){c===void 0&&(c=0);var j=new l;j.SetAsVector(d,c);return j};l.prototype.SetAsBox=function(d,c){d===void 0&&(d=0);c===void 0&&(c=0);this.m_vertexCount=4;this.Reserve(4);this.m_vertices[0].Set(-d,-c);this.m_vertices[1].Set(d,-c);this.m_vertices[2].Set(d,c);this.m_vertices[3].Set(-d,c);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()};l.AsBox=function(d,c){d===void 0&&(d=0);c===void 0&&(c=0);var j=new l;j.SetAsBox(d,c);return j};l.prototype.SetAsOrientedBox=function(d,c,j,e){d===void 0&&(d=0);c===void 0&&(c=0);j===void 0&&(j=null);e===void 0&&(e=0);this.m_vertexCount=4;this.Reserve(4);this.m_vertices[0].Set(-d,-c);this.m_vertices[1].Set(d,-c);this.m_vertices[2].Set(d,c);this.m_vertices[3].Set(-d,c);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=j;d=new H;d.position=j;d.R.Set(e);for(j=0;j<this.m_vertexCount;++j)this.m_vertices[j]=p.MulX(d,this.m_vertices[j]),this.m_normals[j]=p.MulMV(d.R,this.m_normals[j])};l.AsOrientedBox=function(d,c,j,e){d===void 0&&(d=0);c===void 0&&(c=0);j===void 0&&(j=null);e===void 0&&(e=0);var h=new l;h.SetAsOrientedBox(d,c,j,e);return h};l.prototype.SetAsEdge=function(d,c){this.m_vertexCount=2;this.Reserve(2);this.m_vertices[0].SetV(d);this.m_vertices[1].SetV(c);this.m_centroid.x=0.5*(d.x+c.x);
this.m_centroid.y=0.5*(d.y+c.y);this.m_normals[0]=p.CrossVF(p.SubtractVV(c,d),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};l.AsEdge=function(d,c){var j=new l;j.SetAsEdge(d,c);return j};l.prototype.TestPoint=function(d,c){var j;j=d.R;for(var e=c.x-d.position.x,h=c.y-d.position.y,p=e*j.col1.x+h*j.col1.y,l=e*j.col2.x+h*j.col2.y,m=0;m<this.m_vertexCount;++m)if(j=this.m_vertices[m],e=p-j.x,h=l-j.y,j=this.m_normals[m],j.x*e+j.y*h>0)return!1;
return!0};l.prototype.RayCast=function(d,c,j){var e=0,h=c.maxFraction,p=0,l=0,m,r,p=c.p1.x-j.position.x,l=c.p1.y-j.position.y;m=j.R;var s=p*m.col1.x+l*m.col1.y,y=p*m.col2.x+l*m.col2.y,p=c.p2.x-j.position.x,l=c.p2.y-j.position.y;m=j.R;c=p*m.col1.x+l*m.col1.y-s;m=p*m.col2.x+l*m.col2.y-y;for(var q=-1,a=0;a<this.m_vertexCount;++a){r=this.m_vertices[a];p=r.x-s;l=r.y-y;r=this.m_normals[a];p=r.x*p+r.y*l;l=r.x*c+r.y*m;if(l==0){if(p<0)return!1}else l<0&&p<e*l?(e=p/l,q=a):l>0&&p<h*l&&(h=p/l);if(h<e-Number.MIN_VALUE)return!1}return q>=
0?(d.fraction=e,m=j.R,r=this.m_normals[q],d.normal.x=m.col1.x*r.x+m.col2.x*r.y,d.normal.y=m.col1.y*r.x+m.col2.y*r.y,!0):!1};l.prototype.ComputeAABB=function(d,c){for(var j=c.R,e=this.m_vertices[0],h=c.position.x+(j.col1.x*e.x+j.col2.x*e.y),p=c.position.y+(j.col1.y*e.x+j.col2.y*e.y),l=h,m=p,r=1;r<this.m_vertexCount;++r)var e=this.m_vertices[r],s=c.position.x+(j.col1.x*e.x+j.col2.x*e.y),e=c.position.y+(j.col1.y*e.x+j.col2.y*e.y),h=h<s?h:s,p=p<e?p:e,l=l>s?l:s,m=m>e?m:e;d.lowerBound.x=h-this.m_radius;
d.lowerBound.y=p-this.m_radius;d.upperBound.x=l+this.m_radius;d.upperBound.y=m+this.m_radius};l.prototype.ComputeMass=function(c,e){e===void 0&&(e=0);if(this.m_vertexCount==2)c.center.x=0.5*(this.m_vertices[0].x+this.m_vertices[1].x),c.center.y=0.5*(this.m_vertices[0].y+this.m_vertices[1].y),c.mass=0,c.I=0;else{for(var j=0,h=0,p=0,l=0,m=1/3,r=0;r<this.m_vertexCount;++r){var s=this.m_vertices[r],y=r+1<this.m_vertexCount?this.m_vertices[parseInt(r+1)]:this.m_vertices[0],q=s.x-0,v=s.y-0,a=y.x-0,g=y.y-
0,o=q*g-v*a,n=0.5*o;p+=n;j+=n*m*(0+s.x+y.x);h+=n*m*(0+s.y+y.y);s=q;l+=o*(m*(0.25*(s*s+a*s+a*a)+(0*s+0*a))+0+(m*(0.25*(v*v+g*v+g*g)+(0*v+0*g))+0))}c.mass=e*p;j*=1/p;h*=1/p;c.center.Set(j,h);c.I=e*l}};l.prototype.ComputeSubmergedArea=function(c,e,j,l){e===void 0&&(e=0);for(var m=p.MulTMV(j.R,c),r=e-p.Dot(c,j.position),s=new Vector_a2j_Number,y=0,q=-1,e=-1,v=!1,c=c=0;c<this.m_vertexCount;++c){s[c]=p.Dot(m,this.m_vertices[c])-r;var H=s[c]<-Number.MIN_VALUE;c>0&&(H?v||(q=c-1,y++):v&&(e=c-1,y++));v=H}switch(y){case 0:return v?
(c=new h,this.ComputeMass(c,1),l.SetV(p.MulX(j,c.center)),c.mass):0;case 1:q==-1?q=this.m_vertexCount-1:e=this.m_vertexCount-1}c=parseInt((q+1)%this.m_vertexCount);m=parseInt((e+1)%this.m_vertexCount);r=(0-s[q])/(s[c]-s[q]);s=(0-s[e])/(s[m]-s[e]);q=new C(this.m_vertices[q].x*(1-r)+this.m_vertices[c].x*r,this.m_vertices[q].y*(1-r)+this.m_vertices[c].y*r);e=new C(this.m_vertices[e].x*(1-s)+this.m_vertices[m].x*s,this.m_vertices[e].y*(1-s)+this.m_vertices[m].y*s);s=0;r=new C;for(y=this.m_vertices[c];c!=
m;)c=(c+1)%this.m_vertexCount,v=c==m?e:this.m_vertices[c],H=0.5*((y.x-q.x)*(v.y-q.y)-(y.y-q.y)*(v.x-q.x)),s+=H,r.x+=H*(q.x+y.x+v.x)/3,r.y+=H*(q.y+y.y+v.y)/3,y=v;r.Multiply(1/s);l.SetV(p.MulX(j,r));return s};l.prototype.GetVertexCount=function(){return this.m_vertexCount};l.prototype.GetVertices=function(){return this.m_vertices};l.prototype.GetNormals=function(){return this.m_normals};l.prototype.GetSupport=function(c){for(var e=0,j=this.m_vertices[0].x*c.x+this.m_vertices[0].y*c.y,h=1;h<this.m_vertexCount;++h){var p=
this.m_vertices[h].x*c.x+this.m_vertices[h].y*c.y;p>j&&(e=h,j=p)}return e};l.prototype.GetSupportVertex=function(c){for(var e=0,j=this.m_vertices[0].x*c.x+this.m_vertices[0].y*c.y,h=1;h<this.m_vertexCount;++h){var p=this.m_vertices[h].x*c.x+this.m_vertices[h].y*c.y;p>j&&(e=h,j=p)}return this.m_vertices[e]};l.prototype.Validate=function(){return!1};l.prototype.b2PolygonShape=function(){this.__super.b2Shape.call(this);this.m_type=w.e_polygonShape;this.m_centroid=new C;this.m_vertices=new Vector;this.m_normals=
new Vector};l.prototype.Reserve=function(c){c===void 0&&(c=0);for(var e=parseInt(this.m_vertices.length);e<c;e++)this.m_vertices[e]=new C,this.m_normals[e]=new C};l.ComputeCentroid=function(c,e){e===void 0&&(e=0);for(var j=new C,h=0,p=1/3,l=0;l<e;++l){var m=c[l],r=l+1<e?c[parseInt(l+1)]:c[0],s=0.5*((m.x-0)*(r.y-0)-(m.y-0)*(r.x-0));h+=s;j.x+=s*p*(0+m.x+r.x);j.y+=s*p*(0+m.y+r.y)}j.x*=1/h;j.y*=1/h;return j};l.ComputeOBB=function(c,e,j){j===void 0&&(j=0);for(var h=0,p=new Vector(j+1),h=0;h<j;++h)p[h]=
e[h];p[j]=p[0];e=Number.MAX_VALUE;for(h=1;h<=j;++h){var l=p[parseInt(h-1)],m=p[h].x-l.x,r=p[h].y-l.y,s=Math.sqrt(m*m+r*r);m/=s;r/=s;for(var q=-r,y=m,v=s=Number.MAX_VALUE,a=-Number.MAX_VALUE,g=-Number.MAX_VALUE,o=0;o<j;++o){var n=p[o].x-l.x,t=p[o].y-l.y,z=m*n+r*t,n=q*n+y*t;z<s&&(s=z);n<v&&(v=n);z>a&&(a=z);n>g&&(g=n)}o=(a-s)*(g-v);if(o<0.95*e)e=o,c.R.col1.x=m,c.R.col1.y=r,c.R.col2.x=q,c.R.col2.y=y,m=0.5*(s+a),r=0.5*(v+g),q=c.R,c.center.x=l.x+(q.col1.x*m+q.col2.x*r),c.center.y=l.y+(q.col1.y*m+q.col2.y*
r),c.extents.x=0.5*(a-s),c.extents.y=0.5*(g-v)}};Box2D.postDefs.push(function(){Box2D.Collision.Shapes.b2PolygonShape.s_mat=new c});w.b2Shape=function(){};w.prototype.Copy=function(){return null};w.prototype.Set=function(c){this.m_radius=c.m_radius};w.prototype.GetType=function(){return this.m_type};w.prototype.TestPoint=function(){return!1};w.prototype.RayCast=function(){return!1};w.prototype.ComputeAABB=function(){};w.prototype.ComputeMass=function(){};w.prototype.ComputeSubmergedArea=function(){return 0};
w.TestOverlap=function(c,e,j,h){var p=new y;p.proxyA=new J;p.proxyA.Set(c);p.proxyB=new J;p.proxyB.Set(j);p.transformA=e;p.transformB=h;p.useRadii=!0;c=new K;c.count=0;e=new s;v.Distance(e,c,p);return e.distance<10*Number.MIN_VALUE};w.prototype.b2Shape=function(){this.m_type=w.e_unknownShape;this.m_radius=m.b2_linearSlop};Box2D.postDefs.push(function(){Box2D.Collision.Shapes.b2Shape.e_unknownShape=-1;Box2D.Collision.Shapes.b2Shape.e_circleShape=0;Box2D.Collision.Shapes.b2Shape.e_polygonShape=1;Box2D.Collision.Shapes.b2Shape.e_edgeShape=
2;Box2D.Collision.Shapes.b2Shape.e_shapeTypeCount=3;Box2D.Collision.Shapes.b2Shape.e_hitCollide=1;Box2D.Collision.Shapes.b2Shape.e_missCollide=0;Box2D.Collision.Shapes.b2Shape.e_startsInsideCollide=-1})})();
(function(){var m=Box2D.Common.b2Color,r=Box2D.Common.b2Settings,q=Box2D.Common.Math.b2Math;m.b2Color=function(){this._b=this._g=this._r=0};m.prototype.b2Color=function(e,h,l){e===void 0&&(e=0);h===void 0&&(h=0);l===void 0&&(l=0);this._r=Box2D.parseUInt(255*q.Clamp(e,0,1));this._g=Box2D.parseUInt(255*q.Clamp(h,0,1));this._b=Box2D.parseUInt(255*q.Clamp(l,0,1))};m.prototype.Set=function(e,h,l){e===void 0&&(e=0);h===void 0&&(h=0);l===void 0&&(l=0);this._r=Box2D.parseUInt(255*q.Clamp(e,0,1));this._g=
Box2D.parseUInt(255*q.Clamp(h,0,1));this._b=Box2D.parseUInt(255*q.Clamp(l,0,1))};Object.defineProperty(m.prototype,"r",{enumerable:!1,configurable:!0,set:function(e){e===void 0&&(e=0);this._r=Box2D.parseUInt(255*q.Clamp(e,0,1))}});Object.defineProperty(m.prototype,"g",{enumerable:!1,configurable:!0,set:function(e){e===void 0&&(e=0);this._g=Box2D.parseUInt(255*q.Clamp(e,0,1))}});Object.defineProperty(m.prototype,"b",{enumerable:!1,configurable:!0,set:function(e){e===void 0&&(e=0);this._b=Box2D.parseUInt(255*
q.Clamp(e,0,1))}});Object.defineProperty(m.prototype,"color",{enumerable:!1,configurable:!0,get:function(){return this._r<<16|this._g<<8|this._b}});r.b2Settings=function(){};r.b2MixFriction=function(e,h){e===void 0&&(e=0);h===void 0&&(h=0);return Math.sqrt(e*h)};r.b2MixRestitution=function(e,h){e===void 0&&(e=0);h===void 0&&(h=0);return e>h?e:h};r.b2Assert=function(e){if(!e)throw"Assertion Failed";};Box2D.postDefs.push(function(){Box2D.Common.b2Settings.VERSION="2.1alpha";Box2D.Common.b2Settings.USHRT_MAX=
65535;Box2D.Common.b2Settings.b2_pi=Math.PI;Box2D.Common.b2Settings.b2_maxManifoldPoints=2;Box2D.Common.b2Settings.b2_aabbExtension=0.1;Box2D.Common.b2Settings.b2_aabbMultiplier=2;Box2D.Common.b2Settings.b2_polygonRadius=2*r.b2_linearSlop;Box2D.Common.b2Settings.b2_linearSlop=0.005;Box2D.Common.b2Settings.b2_angularSlop=2/180*r.b2_pi;Box2D.Common.b2Settings.b2_toiSlop=8*r.b2_linearSlop;Box2D.Common.b2Settings.b2_maxTOIContactsPerIsland=32;Box2D.Common.b2Settings.b2_maxTOIJointsPerIsland=32;Box2D.Common.b2Settings.b2_velocityThreshold=
1;Box2D.Common.b2Settings.b2_maxLinearCorrection=0.2;Box2D.Common.b2Settings.b2_maxAngularCorrection=8/180*r.b2_pi;Box2D.Common.b2Settings.b2_maxTranslation=2;Box2D.Common.b2Settings.b2_maxTranslationSquared=r.b2_maxTranslation*r.b2_maxTranslation;Box2D.Common.b2Settings.b2_maxRotation=0.5*r.b2_pi;Box2D.Common.b2Settings.b2_maxRotationSquared=r.b2_maxRotation*r.b2_maxRotation;Box2D.Common.b2Settings.b2_contactBaumgarte=0.2;Box2D.Common.b2Settings.b2_timeToSleep=0.5;Box2D.Common.b2Settings.b2_linearSleepTolerance=
0.01;Box2D.Common.b2Settings.b2_angularSleepTolerance=2/180*r.b2_pi})})();
(function(){var m=Box2D.Common.Math.b2Mat22,r=Box2D.Common.Math.b2Mat33,q=Box2D.Common.Math.b2Math,e=Box2D.Common.Math.b2Sweep,h=Box2D.Common.Math.b2Transform,l=Box2D.Common.Math.b2Vec2,w=Box2D.Common.Math.b2Vec3;m.b2Mat22=function(){this.col1=new l;this.col2=new l};m.prototype.b2Mat22=function(){this.SetIdentity()};m.FromAngle=function(c){c===void 0&&(c=0);var e=new m;e.Set(c);return e};m.FromVV=function(c,e){var h=new m;h.SetVV(c,e);return h};m.prototype.Set=function(c){c===void 0&&(c=0);var e=
Math.cos(c),c=Math.sin(c);this.col1.x=e;this.col2.x=-c;this.col1.y=c;this.col2.y=e};m.prototype.SetVV=function(c,e){this.col1.SetV(c);this.col2.SetV(e)};m.prototype.Copy=function(){var c=new m;c.SetM(this);return c};m.prototype.SetM=function(c){this.col1.SetV(c.col1);this.col2.SetV(c.col2)};m.prototype.AddM=function(c){this.col1.x+=c.col1.x;this.col1.y+=c.col1.y;this.col2.x+=c.col2.x;this.col2.y+=c.col2.y};m.prototype.SetIdentity=function(){this.col1.x=1;this.col2.x=0;this.col1.y=0;this.col2.y=1};
m.prototype.SetZero=function(){this.col1.x=0;this.col2.x=0;this.col1.y=0;this.col2.y=0};m.prototype.GetAngle=function(){return Math.atan2(this.col1.y,this.col1.x)};m.prototype.GetInverse=function(c){var e=this.col1.x,h=this.col2.x,l=this.col1.y,m=this.col2.y,r=e*m-h*l;r!=0&&(r=1/r);c.col1.x=r*m;c.col2.x=-r*h;c.col1.y=-r*l;c.col2.y=r*e;return c};m.prototype.Solve=function(c,e,h){e===void 0&&(e=0);h===void 0&&(h=0);var l=this.col1.x,m=this.col2.x,r=this.col1.y,s=this.col2.y,q=l*s-m*r;q!=0&&(q=1/q);
c.x=q*(s*e-m*h);c.y=q*(l*h-r*e);return c};m.prototype.Abs=function(){this.col1.Abs();this.col2.Abs()};r.b2Mat33=function(){this.col1=new w;this.col2=new w;this.col3=new w};r.prototype.b2Mat33=function(c,e,h){c===void 0&&(c=null);e===void 0&&(e=null);h===void 0&&(h=null);!c&&!e&&!h?(this.col1.SetZero(),this.col2.SetZero(),this.col3.SetZero()):(this.col1.SetV(c),this.col2.SetV(e),this.col3.SetV(h))};r.prototype.SetVVV=function(c,e,h){this.col1.SetV(c);this.col2.SetV(e);this.col3.SetV(h)};r.prototype.Copy=
function(){return new r(this.col1,this.col2,this.col3)};r.prototype.SetM=function(c){this.col1.SetV(c.col1);this.col2.SetV(c.col2);this.col3.SetV(c.col3)};r.prototype.AddM=function(c){this.col1.x+=c.col1.x;this.col1.y+=c.col1.y;this.col1.z+=c.col1.z;this.col2.x+=c.col2.x;this.col2.y+=c.col2.y;this.col2.z+=c.col2.z;this.col3.x+=c.col3.x;this.col3.y+=c.col3.y;this.col3.z+=c.col3.z};r.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};r.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};r.prototype.Solve22=function(c,e,h){e===void 0&&(e=0);h===void 0&&(h=0);var l=this.col1.x,m=this.col2.x,r=this.col1.y,s=this.col2.y,q=l*s-m*r;q!=0&&(q=1/q);c.x=q*(s*e-m*h);c.y=q*(l*h-r*e);return c};r.prototype.Solve33=function(c,e,h,l){e===void 0&&(e=0);h===void 0&&(h=0);l===void 0&&(l=0);var m=this.col1.x,
r=this.col1.y,s=this.col1.z,q=this.col2.x,w=this.col2.y,d=this.col2.z,x=this.col3.x,j=this.col3.y,B=this.col3.z,E=m*(w*B-d*j)+r*(d*x-q*B)+s*(q*j-w*x);E!=0&&(E=1/E);c.x=E*(e*(w*B-d*j)+h*(d*x-q*B)+l*(q*j-w*x));c.y=E*(m*(h*B-l*j)+r*(l*x-e*B)+s*(e*j-h*x));c.z=E*(m*(w*l-d*h)+r*(d*e-q*l)+s*(q*h-w*e));return c};q.b2Math=function(){};q.IsValid=function(c){c===void 0&&(c=0);return isFinite(c)};q.Dot=function(c,e){return c.x*e.x+c.y*e.y};q.CrossVV=function(c,e){return c.x*e.y-c.y*e.x};q.CrossVF=function(c,
e){e===void 0&&(e=0);return new l(e*c.y,-e*c.x)};q.CrossFV=function(c,e){c===void 0&&(c=0);return new l(-c*e.y,c*e.x)};q.MulMV=function(c,e){return new l(c.col1.x*e.x+c.col2.x*e.y,c.col1.y*e.x+c.col2.y*e.y)};q.MulTMV=function(c,e){return new l(q.Dot(e,c.col1),q.Dot(e,c.col2))};q.MulX=function(c,e){var h=q.MulMV(c.R,e);h.x+=c.position.x;h.y+=c.position.y;return h};q.MulXT=function(c,e){var h=q.SubtractVV(e,c.position),l=h.x*c.R.col1.x+h.y*c.R.col1.y;h.y=h.x*c.R.col2.x+h.y*c.R.col2.y;h.x=l;return h};
q.AddVV=function(c,e){return new l(c.x+e.x,c.y+e.y)};q.SubtractVV=function(c,e){return new l(c.x-e.x,c.y-e.y)};q.Distance=function(c,e){var h=c.x-e.x,l=c.y-e.y;return Math.sqrt(h*h+l*l)};q.DistanceSquared=function(c,e){var h=c.x-e.x,l=c.y-e.y;return h*h+l*l};q.MulFV=function(c,e){c===void 0&&(c=0);return new l(c*e.x,c*e.y)};q.AddMM=function(c,e){return m.FromVV(q.AddVV(c.col1,e.col1),q.AddVV(c.col2,e.col2))};q.MulMM=function(c,e){return m.FromVV(q.MulMV(c,e.col1),q.MulMV(c,e.col2))};q.MulTMM=function(c,
e){var h=new l(q.Dot(c.col1,e.col1),q.Dot(c.col2,e.col1)),r=new l(q.Dot(c.col1,e.col2),q.Dot(c.col2,e.col2));return m.FromVV(h,r)};q.Abs=function(c){c===void 0&&(c=0);return c>0?c:-c};q.AbsV=function(c){return new l(q.Abs(c.x),q.Abs(c.y))};q.AbsM=function(c){return m.FromVV(q.AbsV(c.col1),q.AbsV(c.col2))};q.Min=function(c,e){c===void 0&&(c=0);e===void 0&&(e=0);return c<e?c:e};q.MinV=function(c,e){return new l(q.Min(c.x,e.x),q.Min(c.y,e.y))};q.Max=function(c,e){c===void 0&&(c=0);e===void 0&&(e=0);
return c>e?c:e};q.MaxV=function(c,e){return new l(q.Max(c.x,e.x),q.Max(c.y,e.y))};q.Clamp=function(c,e,h){c===void 0&&(c=0);e===void 0&&(e=0);h===void 0&&(h=0);return c<e?e:c>h?h:c};q.ClampV=function(c,e,h){return q.MaxV(e,q.MinV(c,h))};q.Swap=function(c,e){var h=c[0];c[0]=e[0];e[0]=h};q.Random=function(){return Math.random()*2-1};q.RandomRange=function(c,e){c===void 0&&(c=0);e===void 0&&(e=0);var h=Math.random();return(e-c)*h+c};q.NextPowerOfTwo=function(c){c===void 0&&(c=0);c|=c>>1&2147483647;c|=
c>>2&1073741823;c|=c>>4&268435455;c|=c>>8&16777215;c|=c>>16&65535;return c+1};q.IsPowerOfTwo=function(c){c===void 0&&(c=0);return c>0&&(c&c-1)==0};Box2D.postDefs.push(function(){Box2D.Common.Math.b2Math.b2Vec2_zero=new l(0,0);Box2D.Common.Math.b2Math.b2Mat22_identity=m.FromVV(new l(1,0),new l(0,1));Box2D.Common.Math.b2Math.b2Transform_identity=new h(q.b2Vec2_zero,q.b2Mat22_identity)});e.b2Sweep=function(){this.localCenter=new l;this.c0=new l;this.c=new l};e.prototype.Set=function(c){this.localCenter.SetV(c.localCenter);
this.c0.SetV(c.c0);this.c.SetV(c.c);this.a0=c.a0;this.a=c.a;this.t0=c.t0};e.prototype.Copy=function(){var c=new e;c.localCenter.SetV(this.localCenter);c.c0.SetV(this.c0);c.c.SetV(this.c);c.a0=this.a0;c.a=this.a;c.t0=this.t0;return c};e.prototype.GetTransform=function(c,e){e===void 0&&(e=0);c.position.x=(1-e)*this.c0.x+e*this.c.x;c.position.y=(1-e)*this.c0.y+e*this.c.y;c.R.Set((1-e)*this.a0+e*this.a);var h=c.R;c.position.x-=h.col1.x*this.localCenter.x+h.col2.x*this.localCenter.y;c.position.y-=h.col1.y*
this.localCenter.x+h.col2.y*this.localCenter.y};e.prototype.Advance=function(c){c===void 0&&(c=0);if(this.t0<c&&1-this.t0>Number.MIN_VALUE){var e=(c-this.t0)/(1-this.t0);this.c0.x=(1-e)*this.c0.x+e*this.c.x;this.c0.y=(1-e)*this.c0.y+e*this.c.y;this.a0=(1-e)*this.a0+e*this.a;this.t0=c}};h.b2Transform=function(){this.position=new l;this.R=new m};h.prototype.b2Transform=function(c,e){c===void 0&&(c=null);e===void 0&&(e=null);c&&(this.position.SetV(c),this.R.SetM(e))};h.prototype.Initialize=function(c,
e){this.position.SetV(c);this.R.SetM(e)};h.prototype.SetIdentity=function(){this.position.SetZero();this.R.SetIdentity()};h.prototype.Set=function(c){this.position.SetV(c.position);this.R.SetM(c.R)};h.prototype.GetAngle=function(){return Math.atan2(this.R.col1.y,this.R.col1.x)};l.b2Vec2=function(){};l.prototype.b2Vec2=function(c,e){c===void 0&&(c=0);e===void 0&&(e=0);this.x=c;this.y=e};l.prototype.SetZero=function(){this.y=this.x=0};l.prototype.Set=function(c,e){c===void 0&&(c=0);e===void 0&&(e=0);
this.x=c;this.y=e};l.prototype.SetV=function(c){this.x=c.x;this.y=c.y};l.prototype.GetNegative=function(){return new l(-this.x,-this.y)};l.prototype.NegativeSelf=function(){this.x=-this.x;this.y=-this.y};l.Make=function(c,e){c===void 0&&(c=0);e===void 0&&(e=0);return new l(c,e)};l.prototype.Copy=function(){return new l(this.x,this.y)};l.prototype.Add=function(c){this.x+=c.x;this.y+=c.y};l.prototype.Subtract=function(c){this.x-=c.x;this.y-=c.y};l.prototype.Multiply=function(c){c===void 0&&(c=0);this.x*=
c;this.y*=c};l.prototype.MulM=function(c){var e=this.x;this.x=c.col1.x*e+c.col2.x*this.y;this.y=c.col1.y*e+c.col2.y*this.y};l.prototype.MulTM=function(c){var e=q.Dot(this,c.col1);this.y=q.Dot(this,c.col2);this.x=e};l.prototype.CrossVF=function(c){c===void 0&&(c=0);var e=this.x;this.x=c*this.y;this.y=-c*e};l.prototype.CrossFV=function(c){c===void 0&&(c=0);var e=this.x;this.x=-c*this.y;this.y=c*e};l.prototype.MinV=function(c){this.x=this.x<c.x?this.x:c.x;this.y=this.y<c.y?this.y:c.y};l.prototype.MaxV=
function(c){this.x=this.x>c.x?this.x:c.x;this.y=this.y>c.y?this.y:c.y};l.prototype.Abs=function(){if(this.x<0)this.x=-this.x;if(this.y<0)this.y=-this.y};l.prototype.Length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)};l.prototype.LengthSquared=function(){return this.x*this.x+this.y*this.y};l.prototype.Normalize=function(){var c=Math.sqrt(this.x*this.x+this.y*this.y);if(c<Number.MIN_VALUE)return 0;var e=1/c;this.x*=e;this.y*=e;return c};l.prototype.IsValid=function(){return q.IsValid(this.x)&&
q.IsValid(this.y)};w.b2Vec3=function(){};w.prototype.b2Vec3=function(c,e,h){c===void 0&&(c=0);e===void 0&&(e=0);h===void 0&&(h=0);this.x=c;this.y=e;this.z=h};w.prototype.SetZero=function(){this.x=this.y=this.z=0};w.prototype.Set=function(c,e,h){c===void 0&&(c=0);e===void 0&&(e=0);h===void 0&&(h=0);this.x=c;this.y=e;this.z=h};w.prototype.SetV=function(c){this.x=c.x;this.y=c.y;this.z=c.z};w.prototype.GetNegative=function(){return new w(-this.x,-this.y,-this.z)};w.prototype.NegativeSelf=function(){this.x=
-this.x;this.y=-this.y;this.z=-this.z};w.prototype.Copy=function(){return new w(this.x,this.y,this.z)};w.prototype.Add=function(c){this.x+=c.x;this.y+=c.y;this.z+=c.z};w.prototype.Subtract=function(c){this.x-=c.x;this.y-=c.y;this.z-=c.z};w.prototype.Multiply=function(c){c===void 0&&(c=0);this.x*=c;this.y*=c;this.z*=c}})();
(function(){var m=Box2D.Common.Math.b2Math,r=Box2D.Common.Math.b2Sweep,q=Box2D.Common.Math.b2Transform,e=Box2D.Common.Math.b2Vec2,h=Box2D.Common.b2Color,l=Box2D.Common.b2Settings,w=Box2D.Collision.b2AABB,c=Box2D.Collision.b2ContactPoint,p=Box2D.Collision.b2DynamicTreeBroadPhase,H=Box2D.Collision.b2RayCastInput,C=Box2D.Collision.b2RayCastOutput,v=Box2D.Collision.Shapes.b2CircleShape,y=Box2D.Collision.Shapes.b2EdgeShape,s=Box2D.Collision.Shapes.b2MassData,J=Box2D.Collision.Shapes.b2PolygonShape,K=Box2D.Collision.Shapes.b2Shape,
d=Box2D.Dynamics.b2Body,x=Box2D.Dynamics.b2BodyDef,j=Box2D.Dynamics.b2ContactFilter,B=Box2D.Dynamics.b2ContactImpulse,E=Box2D.Dynamics.b2ContactListener,G=Box2D.Dynamics.b2ContactManager,A=Box2D.Dynamics.b2DebugDraw,L=Box2D.Dynamics.b2DestructionListener,D=Box2D.Dynamics.b2FilterData,F=Box2D.Dynamics.b2Fixture,M=Box2D.Dynamics.b2FixtureDef,I=Box2D.Dynamics.b2Island,a=Box2D.Dynamics.b2TimeStep,g=Box2D.Dynamics.b2World,o=Box2D.Dynamics.Contacts.b2Contact,n=Box2D.Dynamics.Contacts.b2ContactFactory,t=
Box2D.Dynamics.Contacts.b2ContactSolver,z=Box2D.Dynamics.Joints.b2Joint,f=Box2D.Dynamics.Joints.b2PulleyJoint;d.b2Body=function(){this.m_xf=new q;this.m_sweep=new r;this.m_linearVelocity=new e;this.m_force=new e};d.prototype.connectEdges=function(b,k,a){a===void 0&&(a=0);var g=Math.atan2(k.GetDirectionVector().y,k.GetDirectionVector().x),a=Math.tan((g-a)*0.5),a=m.MulFV(a,k.GetDirectionVector()),a=m.SubtractVV(a,k.GetNormalVector()),a=m.MulFV(l.b2_toiSlop,a),a=m.AddVV(a,k.GetVertex1()),n=m.AddVV(b.GetDirectionVector(),
k.GetDirectionVector());n.Normalize();var f=m.Dot(b.GetDirectionVector(),k.GetNormalVector())>0;b.SetNextEdge(k,a,n,f);k.SetPrevEdge(b,a,n,f);return g};d.prototype.CreateFixture=function(b){if(this.m_world.IsLocked()==!0)return null;var k=new F;k.Create(this,this.m_xf,b);this.m_flags&d.e_activeFlag&&k.CreateProxy(this.m_world.m_contactManager.m_broadPhase,this.m_xf);k.m_next=this.m_fixtureList;this.m_fixtureList=k;++this.m_fixtureCount;k.m_body=this;k.m_density>0&&this.ResetMassData();this.m_world.m_flags|=
g.e_newFixture;return k};d.prototype.CreateFixture2=function(b,k){k===void 0&&(k=0);var a=new M;a.shape=b;a.density=k;return this.CreateFixture(a)};d.prototype.DestroyFixture=function(b){if(this.m_world.IsLocked()!=!0){for(var k=this.m_fixtureList,a=null;k!=null;){if(k==b){a?a.m_next=b.m_next:this.m_fixtureList=b.m_next;break}a=k;k=k.m_next}for(k=this.m_contactList;k;){var a=k.contact,k=k.next,g=a.GetFixtureA(),n=a.GetFixtureB();(b==g||b==n)&&this.m_world.m_contactManager.Destroy(a)}this.m_flags&
d.e_activeFlag&&b.DestroyProxy(this.m_world.m_contactManager.m_broadPhase);b.Destroy();b.m_body=null;b.m_next=null;--this.m_fixtureCount;this.ResetMassData()}};d.prototype.SetPositionAndAngle=function(b,k){k===void 0&&(k=0);var a;if(this.m_world.IsLocked()!=!0){this.m_xf.R.Set(k);this.m_xf.position.SetV(b);a=this.m_xf.R;var g=this.m_sweep.localCenter;this.m_sweep.c.x=a.col1.x*g.x+a.col2.x*g.y;this.m_sweep.c.y=a.col1.y*g.x+a.col2.y*g.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=k;g=this.m_world.m_contactManager.m_broadPhase;for(a=this.m_fixtureList;a;a=a.m_next)a.Synchronize(g,this.m_xf,this.m_xf);this.m_world.m_contactManager.FindNewContacts()}};d.prototype.SetTransform=function(b){this.SetPositionAndAngle(b.position,b.GetAngle())};d.prototype.GetTransform=function(){return this.m_xf};d.prototype.GetPosition=function(){return this.m_xf.position};d.prototype.SetPosition=function(b){this.SetPositionAndAngle(b,
this.GetAngle())};d.prototype.GetAngle=function(){return this.m_sweep.a};d.prototype.SetAngle=function(b){b===void 0&&(b=0);this.SetPositionAndAngle(this.GetPosition(),b)};d.prototype.GetWorldCenter=function(){return this.m_sweep.c};d.prototype.GetLocalCenter=function(){return this.m_sweep.localCenter};d.prototype.SetLinearVelocity=function(b){this.m_type!=d.b2_staticBody&&this.m_linearVelocity.SetV(b)};d.prototype.GetLinearVelocity=function(){return this.m_linearVelocity};d.prototype.SetAngularVelocity=
function(b){b===void 0&&(b=0);if(this.m_type!=d.b2_staticBody)this.m_angularVelocity=b};d.prototype.GetAngularVelocity=function(){return this.m_angularVelocity};d.prototype.GetDefinition=function(){var b=new x;b.type=this.GetType();b.allowSleep=(this.m_flags&d.e_allowSleepFlag)==d.e_allowSleepFlag;b.angle=this.GetAngle();b.angularDamping=this.m_angularDamping;b.angularVelocity=this.m_angularVelocity;b.fixedRotation=(this.m_flags&d.e_fixedRotationFlag)==d.e_fixedRotationFlag;b.bullet=(this.m_flags&
d.e_bulletFlag)==d.e_bulletFlag;b.awake=(this.m_flags&d.e_awakeFlag)==d.e_awakeFlag;b.linearDamping=this.m_linearDamping;b.linearVelocity.SetV(this.GetLinearVelocity());b.position=this.GetPosition();b.userData=this.GetUserData();return b};d.prototype.ApplyForce=function(b,k){this.m_type==d.b2_dynamicBody&&(this.IsAwake()==!1&&this.SetAwake(!0),this.m_force.x+=b.x,this.m_force.y+=b.y,this.m_torque+=(k.x-this.m_sweep.c.x)*b.y-(k.y-this.m_sweep.c.y)*b.x)};d.prototype.ApplyTorque=function(b){b===void 0&&
(b=0);this.m_type==d.b2_dynamicBody&&(this.IsAwake()==!1&&this.SetAwake(!0),this.m_torque+=b)};d.prototype.ApplyImpulse=function(b,k){this.m_type==d.b2_dynamicBody&&(this.IsAwake()==!1&&this.SetAwake(!0),this.m_linearVelocity.x+=this.m_invMass*b.x,this.m_linearVelocity.y+=this.m_invMass*b.y,this.m_angularVelocity+=this.m_invI*((k.x-this.m_sweep.c.x)*b.y-(k.y-this.m_sweep.c.y)*b.x))};d.prototype.Split=function(b){for(var k=this.GetLinearVelocity().Copy(),a=this.GetAngularVelocity(),g=this.GetWorldCenter(),
n=this.m_world.CreateBody(this.GetDefinition()),f,c=this.m_fixtureList;c;)if(b(c)){var o=c.m_next;f?f.m_next=o:this.m_fixtureList=o;this.m_fixtureCount--;c.m_next=n.m_fixtureList;n.m_fixtureList=c;n.m_fixtureCount++;c.m_body=n;c=o}else f=c,c=c.m_next;this.ResetMassData();n.ResetMassData();f=this.GetWorldCenter();b=n.GetWorldCenter();f=m.AddVV(k,m.CrossFV(a,m.SubtractVV(f,g)));k=m.AddVV(k,m.CrossFV(a,m.SubtractVV(b,g)));this.SetLinearVelocity(f);n.SetLinearVelocity(k);this.SetAngularVelocity(a);n.SetAngularVelocity(a);
this.SynchronizeFixtures();n.SynchronizeFixtures();return n};d.prototype.Merge=function(b){var a;for(a=b.m_fixtureList;a;){var g=a.m_next;b.m_fixtureCount--;a.m_next=this.m_fixtureList;this.m_fixtureList=a;this.m_fixtureCount++;a.m_body=f;a=g}n.m_fixtureCount=0;var n=this,f=b;n.GetWorldCenter();f.GetWorldCenter();n.GetLinearVelocity().Copy();f.GetLinearVelocity().Copy();n.GetAngularVelocity();f.GetAngularVelocity();n.ResetMassData();this.SynchronizeFixtures()};d.prototype.GetMass=function(){return this.m_mass};
d.prototype.GetInertia=function(){return this.m_I};d.prototype.GetMassData=function(b){b.mass=this.m_mass;b.I=this.m_I;b.center.SetV(this.m_sweep.localCenter)};d.prototype.SetMassData=function(b){l.b2Assert(this.m_world.IsLocked()==!1);if(this.m_world.IsLocked()!=!0&&this.m_type==d.b2_dynamicBody){this.m_invI=this.m_I=this.m_invMass=0;this.m_mass=b.mass;if(this.m_mass<=0)this.m_mass=1;this.m_invMass=1/this.m_mass;if(b.I>0&&(this.m_flags&d.e_fixedRotationFlag)==0)this.m_I=b.I-this.m_mass*(b.center.x*
b.center.x+b.center.y*b.center.y),this.m_invI=1/this.m_I;var a=this.m_sweep.c.Copy();this.m_sweep.localCenter.SetV(b.center);this.m_sweep.c0.SetV(m.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-a.y);this.m_linearVelocity.y+=this.m_angularVelocity*+(this.m_sweep.c.x-a.x)}};d.prototype.ResetMassData=function(){this.m_invI=this.m_I=this.m_invMass=this.m_mass=0;this.m_sweep.localCenter.SetZero();if(!(this.m_type==
d.b2_staticBody||this.m_type==d.b2_kinematicBody)){for(var b=e.Make(0,0),a=this.m_fixtureList;a;a=a.m_next)if(a.m_density!=0){var g=a.GetMassData();this.m_mass+=g.mass;b.x+=g.center.x*g.mass;b.y+=g.center.y*g.mass;this.m_I+=g.I}this.m_mass>0?(this.m_invMass=1/this.m_mass,b.x*=this.m_invMass,b.y*=this.m_invMass):this.m_invMass=this.m_mass=1;this.m_I>0&&(this.m_flags&d.e_fixedRotationFlag)==0?(this.m_I-=this.m_mass*(b.x*b.x+b.y*b.y),this.m_I*=this.m_inertiaScale,l.b2Assert(this.m_I>0),this.m_invI=1/
this.m_I):this.m_invI=this.m_I=0;a=this.m_sweep.c.Copy();this.m_sweep.localCenter.SetV(b);this.m_sweep.c0.SetV(m.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-a.y);this.m_linearVelocity.y+=this.m_angularVelocity*+(this.m_sweep.c.x-a.x)}};d.prototype.GetWorldPoint=function(b){var a=this.m_xf.R,b=new e(a.col1.x*b.x+a.col2.x*b.y,a.col1.y*b.x+a.col2.y*b.y);b.x+=this.m_xf.position.x;b.y+=this.m_xf.position.y;
return b};d.prototype.GetWorldVector=function(b){return m.MulMV(this.m_xf.R,b)};d.prototype.GetLocalPoint=function(b){return m.MulXT(this.m_xf,b)};d.prototype.GetLocalVector=function(b){return m.MulTMV(this.m_xf.R,b)};d.prototype.GetLinearVelocityFromWorldPoint=function(b){return new e(this.m_linearVelocity.x-this.m_angularVelocity*(b.y-this.m_sweep.c.y),this.m_linearVelocity.y+this.m_angularVelocity*(b.x-this.m_sweep.c.x))};d.prototype.GetLinearVelocityFromLocalPoint=function(b){var a=this.m_xf.R,
b=new e(a.col1.x*b.x+a.col2.x*b.y,a.col1.y*b.x+a.col2.y*b.y);b.x+=this.m_xf.position.x;b.y+=this.m_xf.position.y;return new e(this.m_linearVelocity.x-this.m_angularVelocity*(b.y-this.m_sweep.c.y),this.m_linearVelocity.y+this.m_angularVelocity*(b.x-this.m_sweep.c.x))};d.prototype.GetLinearDamping=function(){return this.m_linearDamping};d.prototype.SetLinearDamping=function(b){b===void 0&&(b=0);this.m_linearDamping=b};d.prototype.GetAngularDamping=function(){return this.m_angularDamping};d.prototype.SetAngularDamping=
function(b){b===void 0&&(b=0);this.m_angularDamping=b};d.prototype.SetType=function(b){b===void 0&&(b=0);if(this.m_type!=b){this.m_type=b;this.ResetMassData();if(this.m_type==d.b2_staticBody)this.m_linearVelocity.SetZero(),this.m_angularVelocity=0;this.SetAwake(!0);this.m_force.SetZero();this.m_torque=0;for(b=this.m_contactList;b;b=b.next)b.contact.FlagForFiltering()}};d.prototype.GetType=function(){return this.m_type};d.prototype.SetBullet=function(b){b?this.m_flags|=d.e_bulletFlag:this.m_flags&=
~d.e_bulletFlag};d.prototype.IsBullet=function(){return(this.m_flags&d.e_bulletFlag)==d.e_bulletFlag};d.prototype.SetSleepingAllowed=function(b){b?this.m_flags|=d.e_allowSleepFlag:(this.m_flags&=~d.e_allowSleepFlag,this.SetAwake(!0))};d.prototype.SetAwake=function(b){b?(this.m_flags|=d.e_awakeFlag,this.m_sleepTime=0):(this.m_flags&=~d.e_awakeFlag,this.m_sleepTime=0,this.m_linearVelocity.SetZero(),this.m_angularVelocity=0,this.m_force.SetZero(),this.m_torque=0)};d.prototype.IsAwake=function(){return(this.m_flags&
d.e_awakeFlag)==d.e_awakeFlag};d.prototype.SetFixedRotation=function(b){b?this.m_flags|=d.e_fixedRotationFlag:this.m_flags&=~d.e_fixedRotationFlag;this.ResetMassData()};d.prototype.IsFixedRotation=function(){return(this.m_flags&d.e_fixedRotationFlag)==d.e_fixedRotationFlag};d.prototype.SetActive=function(b){if(b!=this.IsActive()){var a;if(b){this.m_flags|=d.e_activeFlag;b=this.m_world.m_contactManager.m_broadPhase;for(a=this.m_fixtureList;a;a=a.m_next)a.CreateProxy(b,this.m_xf)}else{this.m_flags&=
~d.e_activeFlag;b=this.m_world.m_contactManager.m_broadPhase;for(a=this.m_fixtureList;a;a=a.m_next)a.DestroyProxy(b);for(b=this.m_contactList;b;)a=b,b=b.next,this.m_world.m_contactManager.Destroy(a.contact);this.m_contactList=null}}};d.prototype.IsActive=function(){return(this.m_flags&d.e_activeFlag)==d.e_activeFlag};d.prototype.IsSleepingAllowed=function(){return(this.m_flags&d.e_allowSleepFlag)==d.e_allowSleepFlag};d.prototype.GetFixtureList=function(){return this.m_fixtureList};d.prototype.GetJointList=
function(){return this.m_jointList};d.prototype.GetControllerList=function(){return this.m_controllerList};d.prototype.GetContactList=function(){return this.m_contactList};d.prototype.GetNext=function(){return this.m_next};d.prototype.GetUserData=function(){return this.m_userData};d.prototype.SetUserData=function(b){this.m_userData=b};d.prototype.GetWorld=function(){return this.m_world};d.prototype.b2Body=function(b,a){this.m_flags=0;b.bullet&&(this.m_flags|=d.e_bulletFlag);b.fixedRotation&&(this.m_flags|=
d.e_fixedRotationFlag);b.allowSleep&&(this.m_flags|=d.e_allowSleepFlag);b.awake&&(this.m_flags|=d.e_awakeFlag);b.active&&(this.m_flags|=d.e_activeFlag);this.m_world=a;this.m_xf.position.SetV(b.position);this.m_xf.R.Set(b.angle);this.m_sweep.localCenter.SetZero();this.m_sweep.t0=1;this.m_sweep.a0=this.m_sweep.a=b.angle;var g=this.m_xf.R,n=this.m_sweep.localCenter;this.m_sweep.c.x=g.col1.x*n.x+g.col2.x*n.y;this.m_sweep.c.y=g.col1.y*n.x+g.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_contactList=this.m_controllerList=this.m_jointList=null;this.m_controllerCount=0;this.m_next=this.m_prev=null;this.m_linearVelocity.SetV(b.linearVelocity);this.m_angularVelocity=b.angularVelocity;this.m_linearDamping=b.linearDamping;this.m_angularDamping=b.angularDamping;this.m_force.Set(0,0);this.m_sleepTime=this.m_torque=0;this.m_type=b.type;this.m_invMass=this.m_type==d.b2_dynamicBody?this.m_mass=1:this.m_mass=0;this.m_invI=this.m_I=
0;this.m_inertiaScale=b.inertiaScale;this.m_userData=b.userData;this.m_fixtureList=null;this.m_fixtureCount=0};d.prototype.SynchronizeFixtures=function(){var b=d.s_xf1;b.R.Set(this.m_sweep.a0);var a=b.R,g=this.m_sweep.localCenter;b.position.x=this.m_sweep.c0.x-(a.col1.x*g.x+a.col2.x*g.y);b.position.y=this.m_sweep.c0.y-(a.col1.y*g.x+a.col2.y*g.y);g=this.m_world.m_contactManager.m_broadPhase;for(a=this.m_fixtureList;a;a=a.m_next)a.Synchronize(g,b,this.m_xf)};d.prototype.SynchronizeTransform=function(){this.m_xf.R.Set(this.m_sweep.a);
var b=this.m_xf.R,a=this.m_sweep.localCenter;this.m_xf.position.x=this.m_sweep.c.x-(b.col1.x*a.x+b.col2.x*a.y);this.m_xf.position.y=this.m_sweep.c.y-(b.col1.y*a.x+b.col2.y*a.y)};d.prototype.ShouldCollide=function(b){if(this.m_type!=d.b2_dynamicBody&&b.m_type!=d.b2_dynamicBody)return!1;for(var a=this.m_jointList;a;a=a.next)if(a.other==b&&a.joint.m_collideConnected==!1)return!1;return!0};d.prototype.Advance=function(b){b===void 0&&(b=0);this.m_sweep.Advance(b);this.m_sweep.c.SetV(this.m_sweep.c0);this.m_sweep.a=
this.m_sweep.a0;this.SynchronizeTransform()};Box2D.postDefs.push(function(){Box2D.Dynamics.b2Body.s_xf1=new q;Box2D.Dynamics.b2Body.e_islandFlag=1;Box2D.Dynamics.b2Body.e_awakeFlag=2;Box2D.Dynamics.b2Body.e_allowSleepFlag=4;Box2D.Dynamics.b2Body.e_bulletFlag=8;Box2D.Dynamics.b2Body.e_fixedRotationFlag=16;Box2D.Dynamics.b2Body.e_activeFlag=32;Box2D.Dynamics.b2Body.b2_staticBody=0;Box2D.Dynamics.b2Body.b2_kinematicBody=1;Box2D.Dynamics.b2Body.b2_dynamicBody=2});x.b2BodyDef=function(){this.position=
new e;this.linearVelocity=new e};x.prototype.b2BodyDef=function(){this.userData=null;this.position.Set(0,0);this.angle=0;this.linearVelocity.Set(0,0);this.angularDamping=this.linearDamping=this.angularVelocity=0;this.awake=this.allowSleep=!0;this.bullet=this.fixedRotation=!1;this.type=d.b2_staticBody;this.active=!0;this.inertiaScale=1};j.b2ContactFilter=function(){};j.prototype.ShouldCollide=function(b,a){var g=b.GetFilterData(),n=a.GetFilterData();return g.groupIndex==n.groupIndex&&g.groupIndex!=
0?g.groupIndex>0:(g.maskBits&n.categoryBits)!=0&&(g.categoryBits&n.maskBits)!=0};j.prototype.RayCollide=function(b,a){return!b?!0:this.ShouldCollide(b instanceof F?b:null,a)};Box2D.postDefs.push(function(){Box2D.Dynamics.b2ContactFilter.b2_defaultFilter=new j});B.b2ContactImpulse=function(){this.normalImpulses=new Vector_a2j_Number(l.b2_maxManifoldPoints);this.tangentImpulses=new Vector_a2j_Number(l.b2_maxManifoldPoints)};E.b2ContactListener=function(){};E.prototype.BeginContact=function(){};E.prototype.EndContact=
function(){};E.prototype.PreSolve=function(){};E.prototype.PostSolve=function(){};Box2D.postDefs.push(function(){Box2D.Dynamics.b2ContactListener.b2_defaultListener=new E});G.b2ContactManager=function(){};G.prototype.b2ContactManager=function(){this.m_world=null;this.m_contactCount=0;this.m_contactFilter=j.b2_defaultFilter;this.m_contactListener=E.b2_defaultListener;this.m_contactFactory=new n(this.m_allocator);this.m_broadPhase=new p};G.prototype.AddPair=function(b,a){var g=b instanceof F?b:null,
n=a instanceof F?a:null,f=g.GetBody(),c=n.GetBody();if(f!=c){for(var o=c.GetContactList();o;){if(o.other==f){var e=o.contact.GetFixtureA(),t=o.contact.GetFixtureB();if(e==g&&t==n)return;if(e==n&&t==g)return}o=o.next}if(c.ShouldCollide(f)!=!1&&this.m_contactFilter.ShouldCollide(g,n)!=!1){o=this.m_contactFactory.Create(g,n);g=o.GetFixtureA();n=o.GetFixtureB();f=g.m_body;c=n.m_body;o.m_prev=null;o.m_next=this.m_world.m_contactList;if(this.m_world.m_contactList!=null)this.m_world.m_contactList.m_prev=
o;this.m_world.m_contactList=o;o.m_nodeA.contact=o;o.m_nodeA.other=c;o.m_nodeA.prev=null;o.m_nodeA.next=f.m_contactList;if(f.m_contactList!=null)f.m_contactList.prev=o.m_nodeA;f.m_contactList=o.m_nodeA;o.m_nodeB.contact=o;o.m_nodeB.other=f;o.m_nodeB.prev=null;o.m_nodeB.next=c.m_contactList;if(c.m_contactList!=null)c.m_contactList.prev=o.m_nodeB;c.m_contactList=o.m_nodeB;++this.m_world.m_contactCount}}};G.prototype.FindNewContacts=function(){this.m_broadPhase.UpdatePairs(Box2D.generateCallback(this,
this.AddPair))};G.prototype.Destroy=function(b){var a=b.GetFixtureA(),g=b.GetFixtureB(),a=a.GetBody(),g=g.GetBody();b.IsTouching()&&this.m_contactListener.EndContact(b);if(b.m_prev)b.m_prev.m_next=b.m_next;if(b.m_next)b.m_next.m_prev=b.m_prev;if(b==this.m_world.m_contactList)this.m_world.m_contactList=b.m_next;if(b.m_nodeA.prev)b.m_nodeA.prev.next=b.m_nodeA.next;if(b.m_nodeA.next)b.m_nodeA.next.prev=b.m_nodeA.prev;if(b.m_nodeA==a.m_contactList)a.m_contactList=b.m_nodeA.next;if(b.m_nodeB.prev)b.m_nodeB.prev.next=
b.m_nodeB.next;if(b.m_nodeB.next)b.m_nodeB.next.prev=b.m_nodeB.prev;if(b.m_nodeB==g.m_contactList)g.m_contactList=b.m_nodeB.next;this.m_contactFactory.Destroy(b);--this.m_contactCount};G.prototype.Collide=function(){for(var b=this.m_world.m_contactList;b;){var a=b.GetFixtureA(),g=b.GetFixtureB(),n=a.GetBody(),f=g.GetBody();if(n.IsAwake()==!1&&f.IsAwake()==!1)b=b.GetNext();else{if(b.m_flags&o.e_filterFlag){if(f.ShouldCollide(n)==!1){a=b;b=a.GetNext();this.Destroy(a);continue}if(this.m_contactFilter.ShouldCollide(a,
g)==!1){a=b;b=a.GetNext();this.Destroy(a);continue}b.m_flags&=~o.e_filterFlag}this.m_broadPhase.TestOverlap(a.m_proxy,g.m_proxy)==!1?(a=b,b=a.GetNext(),this.Destroy(a)):(b.Update(this.m_contactListener),b=b.GetNext())}}};Box2D.postDefs.push(function(){Box2D.Dynamics.b2ContactManager.s_evalCP=new c});A.b2DebugDraw=function(){};A.prototype.b2DebugDraw=function(){};A.prototype.SetFlags=function(){};A.prototype.GetFlags=function(){};A.prototype.AppendFlags=function(){};A.prototype.ClearFlags=function(){};
A.prototype.SetSprite=function(){};A.prototype.GetSprite=function(){};A.prototype.SetDrawScale=function(){};A.prototype.GetDrawScale=function(){};A.prototype.SetLineThickness=function(){};A.prototype.GetLineThickness=function(){};A.prototype.SetAlpha=function(){};A.prototype.GetAlpha=function(){};A.prototype.SetFillAlpha=function(){};A.prototype.GetFillAlpha=function(){};A.prototype.SetXFormScale=function(){};A.prototype.GetXFormScale=function(){};A.prototype.DrawPolygon=function(){};A.prototype.DrawSolidPolygon=
function(){};A.prototype.DrawCircle=function(){};A.prototype.DrawSolidCircle=function(){};A.prototype.DrawSegment=function(){};A.prototype.DrawTransform=function(){};Box2D.postDefs.push(function(){Box2D.Dynamics.b2DebugDraw.e_shapeBit=1;Box2D.Dynamics.b2DebugDraw.e_jointBit=2;Box2D.Dynamics.b2DebugDraw.e_aabbBit=4;Box2D.Dynamics.b2DebugDraw.e_pairBit=8;Box2D.Dynamics.b2DebugDraw.e_centerOfMassBit=16;Box2D.Dynamics.b2DebugDraw.e_controllerBit=32});L.b2DestructionListener=function(){};L.prototype.SayGoodbyeJoint=
function(){};L.prototype.SayGoodbyeFixture=function(){};D.b2FilterData=function(){this.categoryBits=1;this.maskBits=65535;this.groupIndex=0};D.prototype.Copy=function(){var b=new D;b.categoryBits=this.categoryBits;b.maskBits=this.maskBits;b.groupIndex=this.groupIndex;return b};F.b2Fixture=function(){this.m_filter=new D};F.prototype.GetType=function(){return this.m_shape.GetType()};F.prototype.GetShape=function(){return this.m_shape};F.prototype.SetSensor=function(b){if(this.m_isSensor!=b&&(this.m_isSensor=
b,this.m_body!=null))for(b=this.m_body.GetContactList();b;){var a=b.contact,g=a.GetFixtureA(),n=a.GetFixtureB();if(g==this||n==this)a.SetSensor(g.IsSensor()||n.IsSensor());b=b.next}};F.prototype.IsSensor=function(){return this.m_isSensor};F.prototype.SetFilterData=function(b){this.m_filter=b.Copy();if(!this.m_body)for(b=this.m_body.GetContactList();b;){var a=b.contact,g=a.GetFixtureA(),n=a.GetFixtureB();(g==this||n==this)&&a.FlagForFiltering();b=b.next}};F.prototype.GetFilterData=function(){return this.m_filter.Copy()};
F.prototype.GetBody=function(){return this.m_body};F.prototype.GetNext=function(){return this.m_next};F.prototype.GetUserData=function(){return this.m_userData};F.prototype.SetUserData=function(b){this.m_userData=b};F.prototype.TestPoint=function(b){return this.m_shape.TestPoint(this.m_body.GetTransform(),b)};F.prototype.RayCast=function(b,a){return this.m_shape.RayCast(b,a,this.m_body.GetTransform())};F.prototype.GetMassData=function(b){b===void 0&&(b=null);b==null&&(b=new s);this.m_shape.ComputeMass(b,
this.m_density);return b};F.prototype.SetDensity=function(b){b===void 0&&(b=0);this.m_density=b};F.prototype.GetDensity=function(){return this.m_density};F.prototype.GetFriction=function(){return this.m_friction};F.prototype.SetFriction=function(b){b===void 0&&(b=0);this.m_friction=b};F.prototype.GetRestitution=function(){return this.m_restitution};F.prototype.SetRestitution=function(b){b===void 0&&(b=0);this.m_restitution=b};F.prototype.GetAABB=function(){return this.m_aabb};F.prototype.b2Fixture=
function(){this.m_aabb=new w;this.m_shape=this.m_next=this.m_body=this.m_userData=null;this.m_restitution=this.m_friction=this.m_density=0};F.prototype.Create=function(b,a,g){this.m_userData=g.userData;this.m_friction=g.friction;this.m_restitution=g.restitution;this.m_body=b;this.m_next=null;this.m_filter=g.filter.Copy();this.m_isSensor=g.isSensor;this.m_shape=g.shape.Copy();this.m_density=g.density};F.prototype.Destroy=function(){this.m_shape=null};F.prototype.CreateProxy=function(b,a){this.m_shape.ComputeAABB(this.m_aabb,
a);this.m_proxy=b.CreateProxy(this.m_aabb,this)};F.prototype.DestroyProxy=function(b){if(this.m_proxy!=null)b.DestroyProxy(this.m_proxy),this.m_proxy=null};F.prototype.Synchronize=function(b,a,g){if(this.m_proxy){var n=new w,f=new w;this.m_shape.ComputeAABB(n,a);this.m_shape.ComputeAABB(f,g);this.m_aabb.Combine(n,f);a=m.SubtractVV(g.position,a.position);b.MoveProxy(this.m_proxy,this.m_aabb,a)}};M.b2FixtureDef=function(){this.filter=new D};M.prototype.b2FixtureDef=function(){this.userData=this.shape=
null;this.friction=0.2;this.density=this.restitution=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 Vector;this.m_contacts=new Vector;this.m_joints=new Vector};I.prototype.Initialize=function(b,a,g,n,f,c){b===void 0&&(b=0);a===void 0&&(a=0);g===void 0&&(g=0);var o=0;this.m_bodyCapacity=b;this.m_contactCapacity=a;this.m_jointCapacity=g;this.m_jointCount=this.m_contactCount=
this.m_bodyCount=0;this.m_allocator=n;this.m_listener=f;this.m_contactSolver=c;for(o=this.m_bodies.length;o<b;o++)this.m_bodies[o]=null;for(o=this.m_contacts.length;o<a;o++)this.m_contacts[o]=null;for(o=this.m_joints.length;o<g;o++)this.m_joints[o]=null};I.prototype.Clear=function(){this.m_jointCount=this.m_contactCount=this.m_bodyCount=0};I.prototype.Solve=function(b,a,g){for(var n=0,f=0,c,n=0;n<this.m_bodyCount;++n)f=this.m_bodies[n],f.GetType()==d.b2_dynamicBody&&(f.m_linearVelocity.x+=b.dt*(a.x+
f.m_invMass*f.m_force.x),f.m_linearVelocity.y+=b.dt*(a.y+f.m_invMass*f.m_force.y),f.m_angularVelocity+=b.dt*f.m_invI*f.m_torque,f.m_linearVelocity.Multiply(m.Clamp(1-b.dt*f.m_linearDamping,0,1)),f.m_angularVelocity*=m.Clamp(1-b.dt*f.m_angularDamping,0,1));this.m_contactSolver.Initialize(b,this.m_contacts,this.m_contactCount,this.m_allocator);a=this.m_contactSolver;a.InitVelocityConstraints(b);for(n=0;n<this.m_jointCount;++n)c=this.m_joints[n],c.InitVelocityConstraints(b);for(n=0;n<b.velocityIterations;++n){for(f=
0;f<this.m_jointCount;++f)c=this.m_joints[f],c.SolveVelocityConstraints(b);a.SolveVelocityConstraints()}for(n=0;n<this.m_jointCount;++n)c=this.m_joints[n],c.FinalizeVelocityConstraints();a.FinalizeVelocityConstraints();for(n=0;n<this.m_bodyCount;++n)if(f=this.m_bodies[n],f.GetType()!=d.b2_staticBody){var o=b.dt*f.m_linearVelocity.x,e=b.dt*f.m_linearVelocity.y;o*o+e*e>l.b2_maxTranslationSquared&&(f.m_linearVelocity.Normalize(),f.m_linearVelocity.x*=l.b2_maxTranslation*b.inv_dt,f.m_linearVelocity.y*=
l.b2_maxTranslation*b.inv_dt);o=b.dt*f.m_angularVelocity;if(o*o>l.b2_maxRotationSquared)f.m_angularVelocity=f.m_angularVelocity<0?-l.b2_maxRotation*b.inv_dt:l.b2_maxRotation*b.inv_dt;f.m_sweep.c0.SetV(f.m_sweep.c);f.m_sweep.a0=f.m_sweep.a;f.m_sweep.c.x+=b.dt*f.m_linearVelocity.x;f.m_sweep.c.y+=b.dt*f.m_linearVelocity.y;f.m_sweep.a+=b.dt*f.m_angularVelocity;f.SynchronizeTransform()}for(n=0;n<b.positionIterations;++n){o=a.SolvePositionConstraints(l.b2_contactBaumgarte);e=!0;for(f=0;f<this.m_jointCount;++f)c=
this.m_joints[f],c=c.SolvePositionConstraints(l.b2_contactBaumgarte),e=e&&c;if(o&&e)break}this.Report(a.m_constraints);if(g){g=Number.MAX_VALUE;a=l.b2_linearSleepTolerance*l.b2_linearSleepTolerance;o=l.b2_angularSleepTolerance*l.b2_angularSleepTolerance;for(n=0;n<this.m_bodyCount;++n)if(f=this.m_bodies[n],f.GetType()!=d.b2_staticBody){if((f.m_flags&d.e_allowSleepFlag)==0)g=f.m_sleepTime=0;(f.m_flags&d.e_allowSleepFlag)==0||f.m_angularVelocity*f.m_angularVelocity>o||m.Dot(f.m_linearVelocity,f.m_linearVelocity)>
a?g=f.m_sleepTime=0:(f.m_sleepTime+=b.dt,g=m.Min(g,f.m_sleepTime))}if(g>=l.b2_timeToSleep)for(n=0;n<this.m_bodyCount;++n)f=this.m_bodies[n],f.SetAwake(!1)}};I.prototype.SolveTOI=function(b){var a=0,g=0;this.m_contactSolver.Initialize(b,this.m_contacts,this.m_contactCount,this.m_allocator);for(var f=this.m_contactSolver,a=0;a<this.m_jointCount;++a)this.m_joints[a].InitVelocityConstraints(b);for(a=0;a<b.velocityIterations;++a){f.SolveVelocityConstraints();for(g=0;g<this.m_jointCount;++g)this.m_joints[g].SolveVelocityConstraints(b)}for(a=
0;a<this.m_bodyCount;++a)if(g=this.m_bodies[a],g.GetType()!=d.b2_staticBody){var n=b.dt*g.m_linearVelocity.x,c=b.dt*g.m_linearVelocity.y;n*n+c*c>l.b2_maxTranslationSquared&&(g.m_linearVelocity.Normalize(),g.m_linearVelocity.x*=l.b2_maxTranslation*b.inv_dt,g.m_linearVelocity.y*=l.b2_maxTranslation*b.inv_dt);n=b.dt*g.m_angularVelocity;if(n*n>l.b2_maxRotationSquared)g.m_angularVelocity=g.m_angularVelocity<0?-l.b2_maxRotation*b.inv_dt:l.b2_maxRotation*b.inv_dt;g.m_sweep.c0.SetV(g.m_sweep.c);g.m_sweep.a0=
g.m_sweep.a;g.m_sweep.c.x+=b.dt*g.m_linearVelocity.x;g.m_sweep.c.y+=b.dt*g.m_linearVelocity.y;g.m_sweep.a+=b.dt*g.m_angularVelocity;g.SynchronizeTransform()}for(a=0;a<b.positionIterations;++a){n=f.SolvePositionConstraints(0.75);c=!0;for(g=0;g<this.m_jointCount;++g)var o=this.m_joints[g].SolvePositionConstraints(l.b2_contactBaumgarte),c=c&&o;if(n&&c)break}this.Report(f.m_constraints)};I.prototype.Report=function(b){if(this.m_listener!=null)for(var a=0;a<this.m_contactCount;++a){for(var g=this.m_contacts[a],
f=b[a],n=0;n<f.pointCount;++n)I.s_impulse.normalImpulses[n]=f.points[n].normalImpulse,I.s_impulse.tangentImpulses[n]=f.points[n].tangentImpulse;this.m_listener.PostSolve(g,I.s_impulse)}};I.prototype.AddBody=function(b){b.m_islandIndex=this.m_bodyCount;this.m_bodies[this.m_bodyCount++]=b};I.prototype.AddContact=function(b){this.m_contacts[this.m_contactCount++]=b};I.prototype.AddJoint=function(b){this.m_joints[this.m_jointCount++]=b};Box2D.postDefs.push(function(){Box2D.Dynamics.b2Island.s_impulse=
new B});a.b2TimeStep=function(){};a.prototype.Set=function(b){this.dt=b.dt;this.inv_dt=b.inv_dt;this.positionIterations=b.positionIterations;this.velocityIterations=b.velocityIterations;this.warmStarting=b.warmStarting};g.b2World=function(){this.s_stack=new Vector;this.m_contactManager=new G;this.m_contactSolver=new t;this.m_island=new I};g.prototype.b2World=function(b,a){this.m_controllerList=this.m_jointList=this.m_contactList=this.m_bodyList=this.m_debugDraw=this.m_destructionListener=null;this.m_controllerCount=
this.m_jointCount=this.m_contactCount=this.m_bodyCount=0;g.m_warmStarting=!0;g.m_continuousPhysics=!0;this.m_allowSleep=a;this.m_gravity=b;this.m_inv_dt0=0;this.m_contactManager.m_world=this;this.m_groundBody=this.CreateBody(new x)};g.prototype.SetDestructionListener=function(b){this.m_destructionListener=b};g.prototype.SetContactFilter=function(b){this.m_contactManager.m_contactFilter=b};g.prototype.SetContactListener=function(b){this.m_contactManager.m_contactListener=b};g.prototype.SetDebugDraw=
function(b){this.m_debugDraw=b};g.prototype.SetBroadPhase=function(b){var a=this.m_contactManager.m_broadPhase;this.m_contactManager.m_broadPhase=b;for(var g=this.m_bodyList;g;g=g.m_next)for(var f=g.m_fixtureList;f;f=f.m_next)f.m_proxy=b.CreateProxy(a.GetFatAABB(f.m_proxy),f)};g.prototype.Validate=function(){this.m_contactManager.m_broadPhase.Validate()};g.prototype.GetProxyCount=function(){return this.m_contactManager.m_broadPhase.GetProxyCount()};g.prototype.CreateBody=function(b){if(this.IsLocked()==
!0)return null;b=new d(b,this);b.m_prev=null;if(b.m_next=this.m_bodyList)this.m_bodyList.m_prev=b;this.m_bodyList=b;++this.m_bodyCount;return b};g.prototype.DestroyBody=function(b){if(this.IsLocked()!=!0){for(var a=b.m_jointList;a;){var g=a,a=a.next;this.m_destructionListener&&this.m_destructionListener.SayGoodbyeJoint(g.joint);this.DestroyJoint(g.joint)}for(a=b.m_controllerList;a;)g=a,a=a.nextController,g.controller.RemoveBody(b);for(a=b.m_contactList;a;)g=a,a=a.next,this.m_contactManager.Destroy(g.contact);
b.m_contactList=null;for(a=b.m_fixtureList;a;)g=a,a=a.m_next,this.m_destructionListener&&this.m_destructionListener.SayGoodbyeFixture(g),g.DestroyProxy(this.m_contactManager.m_broadPhase),g.Destroy();b.m_fixtureList=null;b.m_fixtureCount=0;if(b.m_prev)b.m_prev.m_next=b.m_next;if(b.m_next)b.m_next.m_prev=b.m_prev;if(b==this.m_bodyList)this.m_bodyList=b.m_next;--this.m_bodyCount}};g.prototype.CreateJoint=function(b){var a=z.Create(b,null);a.m_prev=null;if(a.m_next=this.m_jointList)this.m_jointList.m_prev=
a;this.m_jointList=a;++this.m_jointCount;a.m_edgeA.joint=a;a.m_edgeA.other=a.m_bodyB;a.m_edgeA.prev=null;if(a.m_edgeA.next=a.m_bodyA.m_jointList)a.m_bodyA.m_jointList.prev=a.m_edgeA;a.m_bodyA.m_jointList=a.m_edgeA;a.m_edgeB.joint=a;a.m_edgeB.other=a.m_bodyA;a.m_edgeB.prev=null;if(a.m_edgeB.next=a.m_bodyB.m_jointList)a.m_bodyB.m_jointList.prev=a.m_edgeB;a.m_bodyB.m_jointList=a.m_edgeB;var g=b.bodyA,f=b.bodyB;if(b.collideConnected==!1)for(b=f.GetContactList();b;)b.other==g&&b.contact.FlagForFiltering(),
b=b.next;return a};g.prototype.DestroyJoint=function(b){var a=b.m_collideConnected;if(b.m_prev)b.m_prev.m_next=b.m_next;if(b.m_next)b.m_next.m_prev=b.m_prev;if(b==this.m_jointList)this.m_jointList=b.m_next;var g=b.m_bodyA,f=b.m_bodyB;g.SetAwake(!0);f.SetAwake(!0);if(b.m_edgeA.prev)b.m_edgeA.prev.next=b.m_edgeA.next;if(b.m_edgeA.next)b.m_edgeA.next.prev=b.m_edgeA.prev;if(b.m_edgeA==g.m_jointList)g.m_jointList=b.m_edgeA.next;b.m_edgeA.prev=null;b.m_edgeA.next=null;if(b.m_edgeB.prev)b.m_edgeB.prev.next=
b.m_edgeB.next;if(b.m_edgeB.next)b.m_edgeB.next.prev=b.m_edgeB.prev;if(b.m_edgeB==f.m_jointList)f.m_jointList=b.m_edgeB.next;b.m_edgeB.prev=null;b.m_edgeB.next=null;z.Destroy(b,null);--this.m_jointCount;if(a==!1)for(b=f.GetContactList();b;)b.other==g&&b.contact.FlagForFiltering(),b=b.next};g.prototype.AddController=function(b){b.m_next=this.m_controllerList;b.m_prev=null;this.m_controllerList=b;b.m_world=this;this.m_controllerCount++;return b};g.prototype.RemoveController=function(b){if(b.m_prev)b.m_prev.m_next=
b.m_next;if(b.m_next)b.m_next.m_prev=b.m_prev;if(this.m_controllerList==b)this.m_controllerList=b.m_next;this.m_controllerCount--};g.prototype.CreateController=function(b){if(b.m_world!=this)throw Error("Controller can only be a member of one world");b.m_next=this.m_controllerList;b.m_prev=null;if(this.m_controllerList)this.m_controllerList.m_prev=b;this.m_controllerList=b;++this.m_controllerCount;b.m_world=this;return b};g.prototype.DestroyController=function(b){b.Clear();if(b.m_next)b.m_next.m_prev=
b.m_prev;if(b.m_prev)b.m_prev.m_next=b.m_next;if(b==this.m_controllerList)this.m_controllerList=b.m_next;--this.m_controllerCount};g.prototype.SetWarmStarting=function(b){g.m_warmStarting=b};g.prototype.SetContinuousPhysics=function(b){g.m_continuousPhysics=b};g.prototype.GetBodyCount=function(){return this.m_bodyCount};g.prototype.GetJointCount=function(){return this.m_jointCount};g.prototype.GetContactCount=function(){return this.m_contactCount};g.prototype.SetGravity=function(b){this.m_gravity=
b};g.prototype.GetGravity=function(){return this.m_gravity};g.prototype.GetGroundBody=function(){return this.m_groundBody};g.prototype.Step=function(b,a,f){b===void 0&&(b=0);a===void 0&&(a=0);f===void 0&&(f=0);this.m_flags&g.e_newFixture&&(this.m_contactManager.FindNewContacts(),this.m_flags&=~g.e_newFixture);this.m_flags|=g.e_locked;var n=g.s_timestep2;n.dt=b;n.velocityIterations=a;n.positionIterations=f;n.inv_dt=b>0?1/b:0;n.dtRatio=this.m_inv_dt0*b;n.warmStarting=g.m_warmStarting;this.m_contactManager.Collide();
n.dt>0&&this.Solve(n);g.m_continuousPhysics&&n.dt>0&&this.SolveTOI(n);if(n.dt>0)this.m_inv_dt0=n.inv_dt;this.m_flags&=~g.e_locked};g.prototype.ClearForces=function(){for(var b=this.m_bodyList;b;b=b.m_next)b.m_force.SetZero(),b.m_torque=0};g.prototype.DrawDebugData=function(){if(this.m_debugDraw!=null){this.m_debugDraw.m_sprite.graphics.clear();var b=this.m_debugDraw.GetFlags(),a,f,n;new e;new e;new e;var c;new w;new w;c=[new e,new e,new e,new e];var o=new h(0,0,0);if(b&A.e_shapeBit)for(a=this.m_bodyList;a;a=
a.m_next){c=a.m_xf;for(f=a.GetFixtureList();f;f=f.m_next)n=f.GetShape(),a.IsActive()==!1?o.Set(0,0,0):a.GetType()==d.b2_staticBody?o.Set(0,0,0):a.GetType()==d.b2_kinematicBody?o.Set(0,0,0):(a.IsAwake(),o.Set(0,0.45,0.53)),n.m_radius==0.4&&o.Set(1,0,0),this.DrawShape(n,c,o)}if(b&A.e_jointBit)for(a=this.m_jointList;a;a=a.m_next)this.DrawJoint(a);if(b&A.e_controllerBit)for(a=this.m_controllerList;a;a=a.m_next)a.Draw(this.m_debugDraw);if(b&A.e_pairBit){o.Set(0,0,0);for(a=this.m_contactManager.m_contactList;a;a=
a.GetNext())n=a.GetFixtureA(),f=a.GetFixtureB(),n=n.GetAABB().GetCenter(),f=f.GetAABB().GetCenter(),this.m_debugDraw.DrawSegment(n,f,o)}if(b&A.e_aabbBit){n=this.m_contactManager.m_broadPhase;c=[new e,new e,new e,new e];for(a=this.m_bodyList;a;a=a.GetNext())if(a.IsActive()!=!1)for(f=a.GetFixtureList();f;f=f.GetNext()){var t=n.GetFatAABB(f.m_proxy);c[0].Set(t.lowerBound.x,t.lowerBound.y);c[1].Set(t.upperBound.x,t.lowerBound.y);c[2].Set(t.upperBound.x,t.upperBound.y);c[3].Set(t.lowerBound.x,t.upperBound.y);
this.m_debugDraw.DrawPolygon(c,4,o)}}if(b&A.e_centerOfMassBit)for(a=this.m_bodyList;a;a=a.m_next)c=g.s_xf,c.R=a.m_xf.R,c.position=a.GetWorldCenter(),this.m_debugDraw.DrawTransform(c)}};g.prototype.QueryAABB=function(b,a){var g=this.m_contactManager.m_broadPhase;g.Query(function(a){return b(g.GetUserData(a))},a)};g.prototype.QueryShape=function(b,a,g){g===void 0&&(g=null);g==null&&(g=new q,g.SetIdentity());var f=this.m_contactManager.m_broadPhase,n=new w;a.ComputeAABB(n,g);f.Query(function(n){n=f.GetUserData(n)instanceof
F?f.GetUserData(n):null;return K.TestOverlap(a,g,n.GetShape(),n.GetBody().GetTransform())?b(n):!0},n)};g.prototype.QueryPoint=function(b,a){var g=this.m_contactManager.m_broadPhase,f=new w;f.lowerBound.Set(a.x-l.b2_linearSlop,a.y-l.b2_linearSlop);f.upperBound.Set(a.x+l.b2_linearSlop,a.y+l.b2_linearSlop);g.Query(function(f){f=g.GetUserData(f)instanceof F?g.GetUserData(f):null;return f.TestPoint(a)?b(f):!0},f)};g.prototype.RayCast=function(b,a,g){var f=this.m_contactManager.m_broadPhase,n=new C,c=new H(a,
g);f.RayCast(function(c,o){var t=f.GetUserData(o),t=t instanceof F?t:null;if(t.RayCast(n,c)){var d=n.fraction,z=new e((1-d)*a.x+d*g.x,(1-d)*a.y+d*g.y);return b(t,z,n.normal,d)}return c.maxFraction},c)};g.prototype.RayCastOne=function(b,a){var g;this.RayCast(function(b,a,f,n){n===void 0&&(n=0);g=b;return n},b,a);return g};g.prototype.RayCastAll=function(b,a){var g=new Vector;this.RayCast(function(b){g[g.length]=b;return 1},b,a);return g};g.prototype.GetBodyList=function(){return this.m_bodyList};g.prototype.GetJointList=
function(){return this.m_jointList};g.prototype.GetContactList=function(){return this.m_contactList};g.prototype.IsLocked=function(){return(this.m_flags&g.e_locked)>0};g.prototype.Solve=function(b){for(var a,g=this.m_controllerList;g;g=g.m_next)g.Step(b);g=this.m_island;g.Initialize(this.m_bodyCount,this.m_contactCount,this.m_jointCount,null,this.m_contactManager.m_contactListener,this.m_contactSolver);for(a=this.m_bodyList;a;a=a.m_next)a.m_flags&=~d.e_islandFlag;for(var f=this.m_contactList;f;f=
f.m_next)f.m_flags&=~o.e_islandFlag;for(f=this.m_jointList;f;f=f.m_next)f.m_islandFlag=!1;parseInt(this.m_bodyCount);for(var f=this.s_stack,n=this.m_bodyList;n;n=n.m_next)if(!(n.m_flags&d.e_islandFlag)&&!(n.IsAwake()==!1||n.IsActive()==!1)&&n.GetType()!=d.b2_staticBody){g.Clear();var c=0;f[c++]=n;for(n.m_flags|=d.e_islandFlag;c>0;)if(a=f[--c],g.AddBody(a),a.IsAwake()==!1&&a.SetAwake(!0),a.GetType()!=d.b2_staticBody){for(var e,t=a.m_contactList;t;t=t.next)if(!(t.contact.m_flags&o.e_islandFlag)&&!(t.contact.IsSensor()==
!0||t.contact.IsEnabled()==!1||t.contact.IsTouching()==!1))g.AddContact(t.contact),t.contact.m_flags|=o.e_islandFlag,e=t.other,e.m_flags&d.e_islandFlag||(f[c++]=e,e.m_flags|=d.e_islandFlag);for(a=a.m_jointList;a;a=a.next)if(a.joint.m_islandFlag!=!0&&(e=a.other,e.IsActive()!=!1))g.AddJoint(a.joint),a.joint.m_islandFlag=!0,e.m_flags&d.e_islandFlag||(f[c++]=e,e.m_flags|=d.e_islandFlag)}g.Solve(b,this.m_gravity,this.m_allowSleep);for(c=0;c<g.m_bodyCount;++c)a=g.m_bodies[c],a.GetType()==d.b2_staticBody&&
(a.m_flags&=~d.e_islandFlag)}for(c=0;c<f.length;++c){if(!f[c])break;f[c]=null}for(a=this.m_bodyList;a;a=a.m_next)a.IsAwake()==!1||a.IsActive()==!1||a.GetType()!=d.b2_staticBody&&a.SynchronizeFixtures();this.m_contactManager.FindNewContacts()};g.prototype.SolveTOI=function(b){var a,f,n,c=this.m_island;c.Initialize(this.m_bodyCount,l.b2_maxTOIContactsPerIsland,l.b2_maxTOIJointsPerIsland,null,this.m_contactManager.m_contactListener,this.m_contactSolver);var e=g.s_queue;for(a=this.m_bodyList;a;a=a.m_next)a.m_flags&=
~d.e_islandFlag,a.m_sweep.t0=0;for(n=this.m_contactList;n;n=n.m_next)n.m_flags&=~(o.e_toiFlag|o.e_islandFlag);for(n=this.m_jointList;n;n=n.m_next)n.m_islandFlag=!1;for(;;){var t=null,z=1;for(n=this.m_contactList;n;n=n.m_next)if(!(n.IsSensor()==!0||n.IsEnabled()==!1||n.IsContinuous()==!1)){a=1;if(n.m_flags&o.e_toiFlag)a=n.m_toi;else{a=n.m_fixtureA;f=n.m_fixtureB;a=a.m_body;f=f.m_body;if((a.GetType()!=d.b2_dynamicBody||a.IsAwake()==!1)&&(f.GetType()!=d.b2_dynamicBody||f.IsAwake()==!1))continue;var h=
a.m_sweep.t0;if(a.m_sweep.t0<f.m_sweep.t0)h=f.m_sweep.t0,a.m_sweep.Advance(h);else if(f.m_sweep.t0<a.m_sweep.t0)h=a.m_sweep.t0,f.m_sweep.Advance(h);a=n.ComputeTOI(a.m_sweep,f.m_sweep);l.b2Assert(0<=a&&a<=1);a>0&&a<1&&(a=(1-a)*h+a,a>1&&(a=1));n.m_toi=a;n.m_flags|=o.e_toiFlag}Number.MIN_VALUE<a&&a<z&&(t=n,z=a)}if(t==null||1-100*Number.MIN_VALUE<z)break;a=t.m_fixtureA;f=t.m_fixtureB;a=a.m_body;f=f.m_body;g.s_backupA.Set(a.m_sweep);g.s_backupB.Set(f.m_sweep);a.Advance(z);f.Advance(z);t.Update(this.m_contactManager.m_contactListener);
t.m_flags&=~o.e_toiFlag;if(t.IsSensor()==!0||t.IsEnabled()==!1)a.m_sweep.Set(g.s_backupA),f.m_sweep.Set(g.s_backupB),a.SynchronizeTransform(),f.SynchronizeTransform();else if(t.IsTouching()!=!1){a.GetType()!=d.b2_dynamicBody&&(a=f);c.Clear();t=n=0;e[n+t++]=a;for(a.m_flags|=d.e_islandFlag;t>0;)if(a=e[n++],--t,c.AddBody(a),a.IsAwake()==!1&&a.SetAwake(!0),a.GetType()==d.b2_dynamicBody){for(f=a.m_contactList;f;f=f.next){if(c.m_contactCount==c.m_contactCapacity)break;if(!(f.contact.m_flags&o.e_islandFlag)&&
!(f.contact.IsSensor()==!0||f.contact.IsEnabled()==!1||f.contact.IsTouching()==!1))c.AddContact(f.contact),f.contact.m_flags|=o.e_islandFlag,h=f.other,h.m_flags&d.e_islandFlag||(h.GetType()!=d.b2_staticBody&&(h.Advance(z),h.SetAwake(!0)),e[n+t]=h,++t,h.m_flags|=d.e_islandFlag)}for(a=a.m_jointList;a;a=a.next)if(c.m_jointCount!=c.m_jointCapacity&&a.joint.m_islandFlag!=!0&&(h=a.other,h.IsActive()!=!1))c.AddJoint(a.joint),a.joint.m_islandFlag=!0,h.m_flags&d.e_islandFlag||(h.GetType()!=d.b2_staticBody&&
(h.Advance(z),h.SetAwake(!0)),e[n+t]=h,++t,h.m_flags|=d.e_islandFlag)}n=g.s_timestep;n.warmStarting=!1;n.dt=(1-z)*b.dt;n.inv_dt=1/n.dt;n.dtRatio=0;n.velocityIterations=b.velocityIterations;n.positionIterations=b.positionIterations;c.SolveTOI(n);for(z=z=0;z<c.m_bodyCount;++z)if(a=c.m_bodies[z],a.m_flags&=~d.e_islandFlag,a.IsAwake()!=!1&&a.GetType()==d.b2_dynamicBody){a.SynchronizeFixtures();for(f=a.m_contactList;f;f=f.next)f.contact.m_flags&=~o.e_toiFlag}for(z=0;z<c.m_contactCount;++z)n=c.m_contacts[z],
n.m_flags&=~(o.e_toiFlag|o.e_islandFlag);for(z=0;z<c.m_jointCount;++z)n=c.m_joints[z],n.m_islandFlag=!1;this.m_contactManager.FindNewContacts()}}};g.prototype.DrawJoint=function(b){var a=b.GetBodyA(),n=b.GetBodyB(),c=a.m_xf.position,o=n.m_xf.position,e=b.GetAnchorA(),t=b.GetAnchorB(),d=g.s_jointColor;switch(b.m_type){case z.e_distanceJoint:this.m_debugDraw.DrawSegment(e,t,d);break;case z.e_pulleyJoint:a=b instanceof f?b:null;b=a.GetGroundAnchorA();a=a.GetGroundAnchorB();this.m_debugDraw.DrawSegment(b,
e,d);this.m_debugDraw.DrawSegment(a,t,d);this.m_debugDraw.DrawSegment(b,a,d);break;case z.e_mouseJoint:break;default:a!=this.m_groundBody&&this.m_debugDraw.DrawSegment(c,e,d),this.m_debugDraw.DrawSegment(e,t,d),n!=this.m_groundBody&&this.m_debugDraw.DrawSegment(o,t,d)}};g.prototype.DrawShape=function(b,a,g){switch(b.m_type){case K.e_circleShape:var f=b instanceof v?b:null;this.m_debugDraw.DrawSolidCircle(m.MulX(a,f.m_p),f.m_radius,a.R.col1,g);break;case K.e_polygonShape:for(var f=0,f=b instanceof
J?b:null,b=parseInt(f.GetVertexCount()),n=f.GetVertices(),c=new Vector(b),f=0;f<b;++f)c[f]=m.MulX(a,n[f]);this.m_debugDraw.DrawSolidPolygon(c,b,g);break;case K.e_edgeShape:f=b instanceof y?b:null,this.m_debugDraw.DrawSegment(m.MulX(a,f.GetVertex1()),m.MulX(a,f.GetVertex2()),g)}};Box2D.postDefs.push(function(){Box2D.Dynamics.b2World.s_timestep2=new a;Box2D.Dynamics.b2World.s_xf=new q;Box2D.Dynamics.b2World.s_backupA=new r;Box2D.Dynamics.b2World.s_backupB=new r;Box2D.Dynamics.b2World.s_timestep=new a;
Box2D.Dynamics.b2World.s_queue=new Vector;Box2D.Dynamics.b2World.s_jointColor=new h(0,0,0);Box2D.Dynamics.b2World.e_newFixture=1;Box2D.Dynamics.b2World.e_locked=2})})();
(function(){var m=Box2D.Collision.Shapes.b2CircleShape,r=Box2D.Collision.Shapes.b2EdgeShape,q=Box2D.Collision.Shapes.b2PolygonShape,e=Box2D.Collision.Shapes.b2Shape,h=Box2D.Dynamics.Contacts.b2CircleContact,l=Box2D.Dynamics.Contacts.b2Contact,w=Box2D.Dynamics.Contacts.b2ContactConstraint,c=Box2D.Dynamics.Contacts.b2ContactConstraintPoint,p=Box2D.Dynamics.Contacts.b2ContactEdge,H=Box2D.Dynamics.Contacts.b2ContactFactory,C=Box2D.Dynamics.Contacts.b2ContactRegister,v=Box2D.Dynamics.Contacts.b2ContactResult,
y=Box2D.Dynamics.Contacts.b2ContactSolver,s=Box2D.Dynamics.Contacts.b2EdgeAndCircleContact,J=Box2D.Dynamics.Contacts.b2NullContact,K=Box2D.Dynamics.Contacts.b2PolyAndCircleContact,d=Box2D.Dynamics.Contacts.b2PolyAndEdgeContact,x=Box2D.Dynamics.Contacts.b2PolygonContact,j=Box2D.Dynamics.Contacts.b2PositionSolverManifold,B=Box2D.Dynamics.b2Body,E=Box2D.Dynamics.b2TimeStep,G=Box2D.Common.b2Settings,A=Box2D.Common.Math.b2Mat22,L=Box2D.Common.Math.b2Math,D=Box2D.Common.Math.b2Vec2,F=Box2D.Collision.b2Collision,
M=Box2D.Collision.b2ContactID,I=Box2D.Collision.b2Manifold,a=Box2D.Collision.b2TimeOfImpact,g=Box2D.Collision.b2TOIInput,o=Box2D.Collision.b2WorldManifold;Box2D.inherit(h,Box2D.Dynamics.Contacts.b2Contact);h.prototype.__super=Box2D.Dynamics.Contacts.b2Contact.prototype;h.b2CircleContact=function(){Box2D.Dynamics.Contacts.b2Contact.b2Contact.apply(this,arguments)};h.Create=function(){return new h};h.Destroy=function(){};h.prototype.Reset=function(a,g){this.__super.Reset.call(this,a,g)};h.prototype.Evaluate=
function(){var a=this.m_fixtureA.GetBody(),g=this.m_fixtureB.GetBody();F.CollideCircles(this.m_manifold,this.m_fixtureA.GetShape()instanceof m?this.m_fixtureA.GetShape():null,a.m_xf,this.m_fixtureB.GetShape()instanceof m?this.m_fixtureB.GetShape():null,g.m_xf)};l.b2Contact=function(){this.m_nodeA=new p;this.m_nodeB=new p;this.m_manifold=new I;this.m_oldManifold=new I};l.prototype.GetManifold=function(){return this.m_manifold};l.prototype.GetWorldManifold=function(a){var g=this.m_fixtureA.GetBody(),
c=this.m_fixtureB.GetBody(),f=this.m_fixtureA.GetShape(),b=this.m_fixtureB.GetShape();a.Initialize(this.m_manifold,g.GetTransform(),f.m_radius,c.GetTransform(),b.m_radius)};l.prototype.IsTouching=function(){return(this.m_flags&l.e_touchingFlag)==l.e_touchingFlag};l.prototype.IsContinuous=function(){return(this.m_flags&l.e_continuousFlag)==l.e_continuousFlag};l.prototype.SetSensor=function(a){a?this.m_flags|=l.e_sensorFlag:this.m_flags&=~l.e_sensorFlag};l.prototype.IsSensor=function(){return(this.m_flags&
l.e_sensorFlag)==l.e_sensorFlag};l.prototype.SetEnabled=function(a){a?this.m_flags|=l.e_enabledFlag:this.m_flags&=~l.e_enabledFlag};l.prototype.IsEnabled=function(){return(this.m_flags&l.e_enabledFlag)==l.e_enabledFlag};l.prototype.GetNext=function(){return this.m_next};l.prototype.GetFixtureA=function(){return this.m_fixtureA};l.prototype.GetFixtureB=function(){return this.m_fixtureB};l.prototype.FlagForFiltering=function(){this.m_flags|=l.e_filterFlag};l.prototype.b2Contact=function(){};l.prototype.Reset=
function(a,g){a===void 0&&(a=null);g===void 0&&(g=null);this.m_flags=l.e_enabledFlag;if(!a||!g)this.m_fixtureB=this.m_fixtureA=null;else{if(a.IsSensor()||g.IsSensor())this.m_flags|=l.e_sensorFlag;var c=a.GetBody(),f=g.GetBody();if(c.GetType()!=B.b2_dynamicBody||c.IsBullet()||f.GetType()!=B.b2_dynamicBody||f.IsBullet())this.m_flags|=l.e_continuousFlag;this.m_fixtureA=a;this.m_fixtureB=g;this.m_manifold.m_pointCount=0;this.m_next=this.m_prev=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}};l.prototype.Update=function(a){var g=this.m_oldManifold;this.m_oldManifold=this.m_manifold;this.m_manifold=g;this.m_flags|=l.e_enabledFlag;var c=!1,g=(this.m_flags&l.e_touchingFlag)==l.e_touchingFlag,f=this.m_fixtureA.m_body,b=this.m_fixtureB.m_body,o=this.m_fixtureA.m_aabb.TestOverlap(this.m_fixtureB.m_aabb);if(this.m_flags&l.e_sensorFlag)o&&(c=this.m_fixtureA.GetShape(),
o=this.m_fixtureB.GetShape(),f=f.GetTransform(),b=b.GetTransform(),c=e.TestOverlap(c,f,o,b)),this.m_manifold.m_pointCount=0;else{f.GetType()!=B.b2_dynamicBody||f.IsBullet()||b.GetType()!=B.b2_dynamicBody||b.IsBullet()?this.m_flags|=l.e_continuousFlag:this.m_flags&=~l.e_continuousFlag;if(o){this.Evaluate();c=this.m_manifold.m_pointCount>0;for(o=0;o<this.m_manifold.m_pointCount;++o){var d=this.m_manifold.m_points[o];d.m_normalImpulse=0;d.m_tangentImpulse=0;for(var h=d.m_id,j=0;j<this.m_oldManifold.m_pointCount;++j){var m=
this.m_oldManifold.m_points[j];if(m.m_id.key==h.key){d.m_normalImpulse=m.m_normalImpulse;d.m_tangentImpulse=m.m_tangentImpulse;break}}}}else this.m_manifold.m_pointCount=0;c!=g&&(f.SetAwake(!0),b.SetAwake(!0))}c?this.m_flags|=l.e_touchingFlag:this.m_flags&=~l.e_touchingFlag;g==!1&&c==!0&&a.BeginContact(this);g==!0&&c==!1&&a.EndContact(this);(this.m_flags&l.e_sensorFlag)==0&&a.PreSolve(this,this.m_oldManifold)};l.prototype.Evaluate=function(){};l.prototype.ComputeTOI=function(g,c){l.s_input.proxyA.Set(this.m_fixtureA.GetShape());
l.s_input.proxyB.Set(this.m_fixtureB.GetShape());l.s_input.sweepA=g;l.s_input.sweepB=c;l.s_input.tolerance=G.b2_linearSlop;return a.TimeOfImpact(l.s_input)};Box2D.postDefs.push(function(){Box2D.Dynamics.Contacts.b2Contact.e_sensorFlag=1;Box2D.Dynamics.Contacts.b2Contact.e_continuousFlag=2;Box2D.Dynamics.Contacts.b2Contact.e_islandFlag=4;Box2D.Dynamics.Contacts.b2Contact.e_toiFlag=8;Box2D.Dynamics.Contacts.b2Contact.e_touchingFlag=16;Box2D.Dynamics.Contacts.b2Contact.e_enabledFlag=32;Box2D.Dynamics.Contacts.b2Contact.e_filterFlag=
64;Box2D.Dynamics.Contacts.b2Contact.s_input=new g});w.b2ContactConstraint=function(){this.localPlaneNormal=new D;this.localPoint=new D;this.normal=new D;this.normalMass=new A;this.K=new A};w.prototype.b2ContactConstraint=function(){this.points=new Vector(G.b2_maxManifoldPoints);for(var a=0;a<G.b2_maxManifoldPoints;a++)this.points[a]=new c};c.b2ContactConstraintPoint=function(){this.localPoint=new D;this.rA=new D;this.rB=new D};p.b2ContactEdge=function(){};H.b2ContactFactory=function(){};H.prototype.b2ContactFactory=
function(a){this.m_allocator=a;this.InitializeRegisters()};H.prototype.AddType=function(a,g,c,f){c===void 0&&(c=0);f===void 0&&(f=0);this.m_registers[c][f].createFcn=a;this.m_registers[c][f].destroyFcn=g;this.m_registers[c][f].primary=!0;if(c!=f)this.m_registers[f][c].createFcn=a,this.m_registers[f][c].destroyFcn=g,this.m_registers[f][c].primary=!1};H.prototype.InitializeRegisters=function(){this.m_registers=new Vector(e.e_shapeTypeCount);for(var a=0;a<e.e_shapeTypeCount;a++){this.m_registers[a]=
new Vector(e.e_shapeTypeCount);for(var g=0;g<e.e_shapeTypeCount;g++)this.m_registers[a][g]=new C}this.AddType(h.Create,h.Destroy,e.e_circleShape,e.e_circleShape);this.AddType(K.Create,K.Destroy,e.e_polygonShape,e.e_circleShape);this.AddType(x.Create,x.Destroy,e.e_polygonShape,e.e_polygonShape);this.AddType(s.Create,s.Destroy,e.e_edgeShape,e.e_circleShape);this.AddType(d.Create,d.Destroy,e.e_polygonShape,e.e_edgeShape)};H.prototype.Create=function(a,g){var c=parseInt(a.GetType()),f=parseInt(g.GetType()),
c=this.m_registers[c][f];if(c.pool)return f=c.pool,c.pool=f.m_next,c.poolCount--,f.Reset(a,g),f;f=c.createFcn;return f!=null?(c.primary?(f=f(this.m_allocator),f.Reset(a,g)):(f=f(this.m_allocator),f.Reset(g,a)),f):null};H.prototype.Destroy=function(a){a.m_manifold.m_pointCount>0&&(a.m_fixtureA.m_body.SetAwake(!0),a.m_fixtureB.m_body.SetAwake(!0));var g=parseInt(a.m_fixtureA.GetType()),c=parseInt(a.m_fixtureB.GetType()),g=this.m_registers[g][c];g.poolCount++;a.m_next=g.pool;g.pool=a;g=g.destroyFcn;
g(a,this.m_allocator)};C.b2ContactRegister=function(){};v.b2ContactResult=function(){this.position=new D;this.normal=new D;this.id=new M};y.b2ContactSolver=function(){this.m_step=new E;this.m_constraints=new Vector};y.prototype.b2ContactSolver=function(){};y.prototype.Initialize=function(a,g,c,f){c===void 0&&(c=0);var b;this.m_step.Set(a);this.m_allocator=f;a=0;for(this.m_constraintCount=c;this.m_constraints.length<this.m_constraintCount;)this.m_constraints[this.m_constraints.length]=new w;for(a=
0;a<c;++a){b=g[a];var f=b.m_fixtureA,o=b.m_fixtureB,e=f.m_shape.m_radius,d=o.m_shape.m_radius,h=f.m_body,j=o.m_body,l=b.GetManifold(),m=G.b2MixFriction(f.GetFriction(),o.GetFriction()),r=G.b2MixRestitution(f.GetRestitution(),o.GetRestitution()),s=h.m_linearVelocity.x,q=h.m_linearVelocity.y,p=j.m_linearVelocity.x,v=j.m_linearVelocity.y,x=h.m_angularVelocity,A=j.m_angularVelocity;G.b2Assert(l.m_pointCount>0);y.s_worldManifold.Initialize(l,h.m_xf,e,j.m_xf,d);o=y.s_worldManifold.m_normal.x;b=y.s_worldManifold.m_normal.y;
f=this.m_constraints[a];f.bodyA=h;f.bodyB=j;f.manifold=l;f.normal.x=o;f.normal.y=b;f.pointCount=l.m_pointCount;f.friction=m;f.restitution=r;f.localPlaneNormal.x=l.m_localPlaneNormal.x;f.localPlaneNormal.y=l.m_localPlaneNormal.y;f.localPoint.x=l.m_localPoint.x;f.localPoint.y=l.m_localPoint.y;f.radius=e+d;f.type=l.m_type;for(e=0;e<f.pointCount;++e){m=l.m_points[e];d=f.points[e];d.normalImpulse=m.m_normalImpulse;d.tangentImpulse=m.m_tangentImpulse;d.localPoint.SetV(m.m_localPoint);var m=d.rA.x=y.s_worldManifold.m_points[e].x-
h.m_sweep.c.x,r=d.rA.y=y.s_worldManifold.m_points[e].y-h.m_sweep.c.y,B=d.rB.x=y.s_worldManifold.m_points[e].x-j.m_sweep.c.x,E=d.rB.y=y.s_worldManifold.m_points[e].y-j.m_sweep.c.y,D=m*b-r*o,C=B*b-E*o;D*=D;C*=C;d.normalMass=1/(h.m_invMass+j.m_invMass+h.m_invI*D+j.m_invI*C);var F=h.m_mass*h.m_invMass+j.m_mass*j.m_invMass;F+=h.m_mass*h.m_invI*D+j.m_mass*j.m_invI*C;d.equalizedMass=1/F;C=b;F=-o;D=m*F-r*C;C=B*F-E*C;D*=D;C*=C;d.tangentMass=1/(h.m_invMass+j.m_invMass+h.m_invI*D+j.m_invI*C);d.velocityBias=
0;m=f.normal.x*(p+-A*E-s- -x*r)+f.normal.y*(v+A*B-q-x*m);m<-G.b2_velocityThreshold&&(d.velocityBias+=-f.restitution*m)}if(f.pointCount==2)v=f.points[0],p=f.points[1],l=h.m_invMass,h=h.m_invI,s=j.m_invMass,j=j.m_invI,q=v.rA.x*b-v.rA.y*o,v=v.rB.x*b-v.rB.y*o,x=p.rA.x*b-p.rA.y*o,p=p.rB.x*b-p.rB.y*o,o=l+s+h*q*q+j*v*v,b=l+s+h*x*x+j*p*p,j=l+s+h*q*x+j*v*p,o*o<100*(o*b-j*j)?(f.K.col1.Set(o,j),f.K.col2.Set(j,b),f.K.GetInverse(f.normalMass)):f.pointCount=1}};y.prototype.InitVelocityConstraints=function(a){for(var g=
0;g<this.m_constraintCount;++g){var c=this.m_constraints[g],f=c.bodyA,b=c.bodyB,o=f.m_invMass,e=f.m_invI,d=b.m_invMass,h=b.m_invI,j=c.normal.x,l=c.normal.y,m=l,r=-j,s=0,q=0;if(a.warmStarting){q=c.pointCount;for(s=0;s<q;++s){var p=c.points[s];p.normalImpulse*=a.dtRatio;p.tangentImpulse*=a.dtRatio;var y=p.normalImpulse*j+p.tangentImpulse*m,v=p.normalImpulse*l+p.tangentImpulse*r;f.m_angularVelocity-=e*(p.rA.x*v-p.rA.y*y);f.m_linearVelocity.x-=o*y;f.m_linearVelocity.y-=o*v;b.m_angularVelocity+=h*(p.rB.x*
v-p.rB.y*y);b.m_linearVelocity.x+=d*y;b.m_linearVelocity.y+=d*v}}else{q=c.pointCount;for(s=0;s<q;++s)f=c.points[s],f.normalImpulse=0,f.tangentImpulse=0}}};y.prototype.SolveVelocityConstraints=function(){for(var a=0,g,c=0,f=0,b=0,o=f=f=c=c=0,e=c=c=0,d=c=b=0,h=0,j,l=0;l<this.m_constraintCount;++l){var b=this.m_constraints[l],m=b.bodyA,r=b.bodyB,s=m.m_angularVelocity,q=r.m_angularVelocity,p=m.m_linearVelocity,y=r.m_linearVelocity,v=m.m_invMass,x=m.m_invI,w=r.m_invMass,A=r.m_invI,d=b.normal.x,B=h=b.normal.y;
j=-d;e=b.friction;for(a=0;a<b.pointCount;a++)g=b.points[a],c=y.x-q*g.rB.y-p.x+s*g.rA.y,f=y.y+q*g.rB.x-p.y-s*g.rA.x,c=c*B+f*j,c=g.tangentMass*-c,f=e*g.normalImpulse,f=L.Clamp(g.tangentImpulse+c,-f,f),c=f-g.tangentImpulse,o=c*B,c*=j,p.x-=v*o,p.y-=v*c,s-=x*(g.rA.x*c-g.rA.y*o),y.x+=w*o,y.y+=w*c,q+=A*(g.rB.x*c-g.rB.y*o),g.tangentImpulse=f;parseInt(b.pointCount);if(b.pointCount==1)g=b.points[0],c=y.x+-q*g.rB.y-p.x- -s*g.rA.y,f=y.y+q*g.rB.x-p.y-s*g.rA.x,b=c*d+f*h,c=-g.normalMass*(b-g.velocityBias),f=g.normalImpulse+
c,f=f>0?f:0,c=f-g.normalImpulse,o=c*d,c*=h,p.x-=v*o,p.y-=v*c,s-=x*(g.rA.x*c-g.rA.y*o),y.x+=w*o,y.y+=w*c,q+=A*(g.rB.x*c-g.rB.y*o),g.normalImpulse=f;else{g=b.points[0];var a=b.points[1],c=g.normalImpulse,e=a.normalImpulse,E=(y.x-q*g.rB.y-p.x+s*g.rA.y)*d+(y.y+q*g.rB.x-p.y-s*g.rA.x)*h,C=(y.x-q*a.rB.y-p.x+s*a.rA.y)*d+(y.y+q*a.rB.x-p.y-s*a.rA.x)*h,f=E-g.velocityBias,o=C-a.velocityBias;j=b.K;f-=j.col1.x*c+j.col2.x*e;for(o-=j.col1.y*c+j.col2.y*e;;){j=b.normalMass;B=-(j.col1.x*f+j.col2.x*o);j=-(j.col1.y*f+
j.col2.y*o);if(B>=0&&j>=0){c=B-c;e=j-e;b=c*d;c*=h;d*=e;h*=e;p.x-=v*(b+d);p.y-=v*(c+h);s-=x*(g.rA.x*c-g.rA.y*b+a.rA.x*h-a.rA.y*d);y.x+=w*(b+d);y.y+=w*(c+h);q+=A*(g.rB.x*c-g.rB.y*b+a.rB.x*h-a.rB.y*d);g.normalImpulse=B;a.normalImpulse=j;break}B=-g.normalMass*f;j=0;C=b.K.col1.y*B+o;if(B>=0&&C>=0){c=B-c;e=j-e;b=c*d;c*=h;d*=e;h*=e;p.x-=v*(b+d);p.y-=v*(c+h);s-=x*(g.rA.x*c-g.rA.y*b+a.rA.x*h-a.rA.y*d);y.x+=w*(b+d);y.y+=w*(c+h);q+=A*(g.rB.x*c-g.rB.y*b+a.rB.x*h-a.rB.y*d);g.normalImpulse=B;a.normalImpulse=j;
break}B=0;j=-a.normalMass*o;E=b.K.col2.x*j+f;if(j>=0&&E>=0){c=B-c;e=j-e;b=c*d;c*=h;d*=e;h*=e;p.x-=v*(b+d);p.y-=v*(c+h);s-=x*(g.rA.x*c-g.rA.y*b+a.rA.x*h-a.rA.y*d);y.x+=w*(b+d);y.y+=w*(c+h);q+=A*(g.rB.x*c-g.rB.y*b+a.rB.x*h-a.rB.y*d);g.normalImpulse=B;a.normalImpulse=j;break}j=B=0;E=f;C=o;if(E>=0&&C>=0){c=B-c;e=j-e;b=c*d;c*=h;d*=e;h*=e;p.x-=v*(b+d);p.y-=v*(c+h);s-=x*(g.rA.x*c-g.rA.y*b+a.rA.x*h-a.rA.y*d);y.x+=w*(b+d);y.y+=w*(c+h);q+=A*(g.rB.x*c-g.rB.y*b+a.rB.x*h-a.rB.y*d);g.normalImpulse=B;a.normalImpulse=
j;break}break}}m.m_angularVelocity=s;r.m_angularVelocity=q}};y.prototype.FinalizeVelocityConstraints=function(){for(var a=0;a<this.m_constraintCount;++a)for(var g=this.m_constraints[a],c=g.manifold,f=0;f<g.pointCount;++f){var b=c.m_points[f],o=g.points[f];b.m_normalImpulse=o.normalImpulse;b.m_tangentImpulse=o.tangentImpulse}};y.prototype.SolvePositionConstraints=function(a){a===void 0&&(a=0);for(var g=0,c=0;c<this.m_constraintCount;c++){var f=this.m_constraints[c],b=f.bodyA,o=f.bodyB,e=b.m_mass*b.m_invMass,
d=b.m_mass*b.m_invI,h=o.m_mass*o.m_invMass,j=o.m_mass*o.m_invI;y.s_psm.Initialize(f);for(var l=y.s_psm.m_normal,m=0;m<f.pointCount;m++){var r=f.points[m],s=y.s_psm.m_points[m],q=y.s_psm.m_separations[m],p=s.x-b.m_sweep.c.x,v=s.y-b.m_sweep.c.y,x=s.x-o.m_sweep.c.x,s=s.y-o.m_sweep.c.y,g=g<q?g:q,q=L.Clamp(a*(q+G.b2_linearSlop),-G.b2_maxLinearCorrection,0);q*=-r.equalizedMass;r=q*l.x;q*=l.y;b.m_sweep.c.x-=e*r;b.m_sweep.c.y-=e*q;b.m_sweep.a-=d*(p*q-v*r);b.SynchronizeTransform();o.m_sweep.c.x+=h*r;o.m_sweep.c.y+=
h*q;o.m_sweep.a+=j*(x*q-s*r);o.SynchronizeTransform()}}return g>-1.5*G.b2_linearSlop};Box2D.postDefs.push(function(){Box2D.Dynamics.Contacts.b2ContactSolver.s_worldManifold=new o;Box2D.Dynamics.Contacts.b2ContactSolver.s_psm=new j});Box2D.inherit(s,Box2D.Dynamics.Contacts.b2Contact);s.prototype.__super=Box2D.Dynamics.Contacts.b2Contact.prototype;s.b2EdgeAndCircleContact=function(){Box2D.Dynamics.Contacts.b2Contact.b2Contact.apply(this,arguments)};s.Create=function(){return new s};s.Destroy=function(){};
s.prototype.Reset=function(a,g){this.__super.Reset.call(this,a,g)};s.prototype.Evaluate=function(){var a=this.m_fixtureA.GetBody(),g=this.m_fixtureB.GetBody();this.b2CollideEdgeAndCircle(this.m_manifold,this.m_fixtureA.GetShape()instanceof r?this.m_fixtureA.GetShape():null,a.m_xf,this.m_fixtureB.GetShape()instanceof m?this.m_fixtureB.GetShape():null,g.m_xf)};s.prototype.b2CollideEdgeAndCircle=function(){};Box2D.inherit(J,Box2D.Dynamics.Contacts.b2Contact);J.prototype.__super=Box2D.Dynamics.Contacts.b2Contact.prototype;
J.b2NullContact=function(){Box2D.Dynamics.Contacts.b2Contact.b2Contact.apply(this,arguments)};J.prototype.b2NullContact=function(){this.__super.b2Contact.call(this)};J.prototype.Evaluate=function(){};Box2D.inherit(K,Box2D.Dynamics.Contacts.b2Contact);K.prototype.__super=Box2D.Dynamics.Contacts.b2Contact.prototype;K.b2PolyAndCircleContact=function(){Box2D.Dynamics.Contacts.b2Contact.b2Contact.apply(this,arguments)};K.Create=function(){return new K};K.Destroy=function(){};K.prototype.Reset=function(a,
g){this.__super.Reset.call(this,a,g);G.b2Assert(a.GetType()==e.e_polygonShape);G.b2Assert(g.GetType()==e.e_circleShape)};K.prototype.Evaluate=function(){var a=this.m_fixtureA.m_body,g=this.m_fixtureB.m_body;F.CollidePolygonAndCircle(this.m_manifold,this.m_fixtureA.GetShape()instanceof q?this.m_fixtureA.GetShape():null,a.m_xf,this.m_fixtureB.GetShape()instanceof m?this.m_fixtureB.GetShape():null,g.m_xf)};Box2D.inherit(d,Box2D.Dynamics.Contacts.b2Contact);d.prototype.__super=Box2D.Dynamics.Contacts.b2Contact.prototype;
d.b2PolyAndEdgeContact=function(){Box2D.Dynamics.Contacts.b2Contact.b2Contact.apply(this,arguments)};d.Create=function(){return new d};d.Destroy=function(){};d.prototype.Reset=function(a,g){this.__super.Reset.call(this,a,g);G.b2Assert(a.GetType()==e.e_polygonShape);G.b2Assert(g.GetType()==e.e_edgeShape)};d.prototype.Evaluate=function(){var a=this.m_fixtureA.GetBody(),g=this.m_fixtureB.GetBody();this.b2CollidePolyAndEdge(this.m_manifold,this.m_fixtureA.GetShape()instanceof q?this.m_fixtureA.GetShape():
null,a.m_xf,this.m_fixtureB.GetShape()instanceof r?this.m_fixtureB.GetShape():null,g.m_xf)};d.prototype.b2CollidePolyAndEdge=function(){};Box2D.inherit(x,Box2D.Dynamics.Contacts.b2Contact);x.prototype.__super=Box2D.Dynamics.Contacts.b2Contact.prototype;x.b2PolygonContact=function(){Box2D.Dynamics.Contacts.b2Contact.b2Contact.apply(this,arguments)};x.Create=function(){return new x};x.Destroy=function(){};x.prototype.Reset=function(a,g){this.__super.Reset.call(this,a,g)};x.prototype.Evaluate=function(){var a=
this.m_fixtureA.GetBody(),g=this.m_fixtureB.GetBody();F.CollidePolygons(this.m_manifold,this.m_fixtureA.GetShape()instanceof q?this.m_fixtureA.GetShape():null,a.m_xf,this.m_fixtureB.GetShape()instanceof q?this.m_fixtureB.GetShape():null,g.m_xf)};j.b2PositionSolverManifold=function(){};j.prototype.b2PositionSolverManifold=function(){this.m_normal=new D;this.m_separations=new Vector_a2j_Number(G.b2_maxManifoldPoints);this.m_points=new Vector(G.b2_maxManifoldPoints);for(var a=0;a<G.b2_maxManifoldPoints;a++)this.m_points[a]=
new D};j.prototype.Initialize=function(a){G.b2Assert(a.pointCount>0);var g=0,c=0,f=0,b,o=0,e=0;switch(a.type){case I.e_circles:b=a.bodyA.m_xf.R;f=a.localPoint;g=a.bodyA.m_xf.position.x+(b.col1.x*f.x+b.col2.x*f.y);c=a.bodyA.m_xf.position.y+(b.col1.y*f.x+b.col2.y*f.y);b=a.bodyB.m_xf.R;f=a.points[0].localPoint;o=a.bodyB.m_xf.position.x+(b.col1.x*f.x+b.col2.x*f.y);b=a.bodyB.m_xf.position.y+(b.col1.y*f.x+b.col2.y*f.y);var f=o-g,e=b-c,d=f*f+e*e;d>Number.MIN_VALUE*Number.MIN_VALUE?(d=Math.sqrt(d),this.m_normal.x=
f/d,this.m_normal.y=e/d):(this.m_normal.x=1,this.m_normal.y=0);this.m_points[0].x=0.5*(g+o);this.m_points[0].y=0.5*(c+b);this.m_separations[0]=f*this.m_normal.x+e*this.m_normal.y-a.radius;break;case I.e_faceA:b=a.bodyA.m_xf.R;f=a.localPlaneNormal;this.m_normal.x=b.col1.x*f.x+b.col2.x*f.y;this.m_normal.y=b.col1.y*f.x+b.col2.y*f.y;b=a.bodyA.m_xf.R;f=a.localPoint;o=a.bodyA.m_xf.position.x+(b.col1.x*f.x+b.col2.x*f.y);e=a.bodyA.m_xf.position.y+(b.col1.y*f.x+b.col2.y*f.y);b=a.bodyB.m_xf.R;for(g=0;g<a.pointCount;++g)f=
a.points[g].localPoint,c=a.bodyB.m_xf.position.x+(b.col1.x*f.x+b.col2.x*f.y),f=a.bodyB.m_xf.position.y+(b.col1.y*f.x+b.col2.y*f.y),this.m_separations[g]=(c-o)*this.m_normal.x+(f-e)*this.m_normal.y-a.radius,this.m_points[g].x=c,this.m_points[g].y=f;break;case I.e_faceB:b=a.bodyB.m_xf.R;f=a.localPlaneNormal;this.m_normal.x=b.col1.x*f.x+b.col2.x*f.y;this.m_normal.y=b.col1.y*f.x+b.col2.y*f.y;b=a.bodyB.m_xf.R;f=a.localPoint;o=a.bodyB.m_xf.position.x+(b.col1.x*f.x+b.col2.x*f.y);e=a.bodyB.m_xf.position.y+
(b.col1.y*f.x+b.col2.y*f.y);b=a.bodyA.m_xf.R;for(g=0;g<a.pointCount;++g)f=a.points[g].localPoint,c=a.bodyA.m_xf.position.x+(b.col1.x*f.x+b.col2.x*f.y),f=a.bodyA.m_xf.position.y+(b.col1.y*f.x+b.col2.y*f.y),this.m_separations[g]=(c-o)*this.m_normal.x+(f-e)*this.m_normal.y-a.radius,this.m_points[g].Set(c,f);this.m_normal.x*=-1;this.m_normal.y*=-1}};Box2D.postDefs.push(function(){Box2D.Dynamics.Contacts.b2PositionSolverManifold.circlePointA=new D;Box2D.Dynamics.Contacts.b2PositionSolverManifold.circlePointB=
new D})})();
(function(){var m=Box2D.Common.Math.b2Mat22,r=Box2D.Common.Math.b2Math,q=Box2D.Common.Math.b2Vec2,e=Box2D.Common.b2Color,h=Box2D.Dynamics.Controllers.b2BuoyancyController,l=Box2D.Dynamics.Controllers.b2ConstantAccelController,w=Box2D.Dynamics.Controllers.b2ConstantForceController,c=Box2D.Dynamics.Controllers.b2Controller,p=Box2D.Dynamics.Controllers.b2ControllerEdge,H=Box2D.Dynamics.Controllers.b2GravityController,C=Box2D.Dynamics.Controllers.b2TensorDampingController;Box2D.inherit(h,Box2D.Dynamics.Controllers.b2Controller);
h.prototype.__super=Box2D.Dynamics.Controllers.b2Controller.prototype;h.b2BuoyancyController=function(){Box2D.Dynamics.Controllers.b2Controller.b2Controller.apply(this,arguments);this.normal=new q(0,-1);this.density=this.offset=0;this.velocity=new q(0,0);this.linearDrag=2;this.angularDrag=1;this.useDensity=!1;this.useWorldGravity=!0;this.gravity=null};h.prototype.Step=function(){if(this.m_bodyList){if(this.useWorldGravity)this.gravity=this.GetWorld().GetGravity().Copy();for(var c=this.m_bodyList;c;c=
c.nextBody){var e=c.body;if(e.IsAwake()!=!1){for(var h=new q,l=new q,m=0,d=0,r=e.GetFixtureList();r;r=r.GetNext()){var j=new q,p=r.GetShape().ComputeSubmergedArea(this.normal,this.offset,e.GetTransform(),j);m+=p;h.x+=p*j.x;h.y+=p*j.y;var w=0,w=1;d+=p*w;l.x+=p*j.x*w;l.y+=p*j.y*w}h.x/=m;h.y/=m;l.x/=d;l.y/=d;m<Number.MIN_VALUE||(d=this.gravity.GetNegative(),d.Multiply(this.density*m),e.ApplyForce(d,l),l=e.GetLinearVelocityFromWorldPoint(h),l.Subtract(this.velocity),l.Multiply(-this.linearDrag*m),e.ApplyForce(l,
h),e.ApplyTorque(-e.GetInertia()/e.GetMass()*m*e.GetAngularVelocity()*this.angularDrag))}}}};h.prototype.Draw=function(c){var h=new q,l=new q;h.x=this.normal.x*this.offset+this.normal.y*1E3;h.y=this.normal.y*this.offset-this.normal.x*1E3;l.x=this.normal.x*this.offset-this.normal.y*1E3;l.y=this.normal.y*this.offset+this.normal.x*1E3;var m=new e(0,0,1);c.DrawSegment(h,l,m)};Box2D.inherit(l,Box2D.Dynamics.Controllers.b2Controller);l.prototype.__super=Box2D.Dynamics.Controllers.b2Controller.prototype;
l.b2ConstantAccelController=function(){Box2D.Dynamics.Controllers.b2Controller.b2Controller.apply(this,arguments);this.A=new q(0,0)};l.prototype.Step=function(c){for(var c=new q(this.A.x*c.dt,this.A.y*c.dt),e=this.m_bodyList;e;e=e.nextBody){var h=e.body;h.IsAwake()&&h.SetLinearVelocity(new q(h.GetLinearVelocity().x+c.x,h.GetLinearVelocity().y+c.y))}};Box2D.inherit(w,Box2D.Dynamics.Controllers.b2Controller);w.prototype.__super=Box2D.Dynamics.Controllers.b2Controller.prototype;w.b2ConstantForceController=
function(){Box2D.Dynamics.Controllers.b2Controller.b2Controller.apply(this,arguments);this.F=new q(0,0)};w.prototype.Step=function(){for(var c=this.m_bodyList;c;c=c.nextBody){var e=c.body;e.IsAwake()&&e.ApplyForce(this.F,e.GetWorldCenter())}};c.b2Controller=function(){};c.prototype.Step=function(){};c.prototype.Draw=function(){};c.prototype.AddBody=function(c){var e=new p;e.controller=this;e.body=c;e.nextBody=this.m_bodyList;e.prevBody=null;this.m_bodyList=e;if(e.nextBody)e.nextBody.prevBody=e;this.m_bodyCount++;
e.nextController=c.m_controllerList;e.prevController=null;c.m_controllerList=e;if(e.nextController)e.nextController.prevController=e;c.m_controllerCount++};c.prototype.RemoveBody=function(c){for(var e=c.m_controllerList;e&&e.controller!=this;)e=e.nextController;if(e.prevBody)e.prevBody.nextBody=e.nextBody;if(e.nextBody)e.nextBody.prevBody=e.prevBody;if(e.nextController)e.nextController.prevController=e.prevController;if(e.prevController)e.prevController.nextController=e.nextController;if(this.m_bodyList==
e)this.m_bodyList=e.nextBody;if(c.m_controllerList==e)c.m_controllerList=e.nextController;c.m_controllerCount--;this.m_bodyCount--};c.prototype.Clear=function(){for(;this.m_bodyList;)this.RemoveBody(this.m_bodyList.body)};c.prototype.GetNext=function(){return this.m_next};c.prototype.GetWorld=function(){return this.m_world};c.prototype.GetBodyList=function(){return this.m_bodyList};p.b2ControllerEdge=function(){};Box2D.inherit(H,Box2D.Dynamics.Controllers.b2Controller);H.prototype.__super=Box2D.Dynamics.Controllers.b2Controller.prototype;
H.b2GravityController=function(){Box2D.Dynamics.Controllers.b2Controller.b2Controller.apply(this,arguments);this.G=1;this.invSqr=!0};H.prototype.Step=function(){var c=null,e=null,h=null,l=0,m=null,d=null,r=null,j=0,p=0,w=0,j=null;if(this.invSqr)for(c=this.m_bodyList;c;c=c.nextBody){e=c.body;h=e.GetWorldCenter();l=e.GetMass();for(m=this.m_bodyList;m!=c;m=m.nextBody)d=m.body,r=d.GetWorldCenter(),j=r.x-h.x,p=r.y-h.y,w=j*j+p*p,w<Number.MIN_VALUE||(j=new q(j,p),j.Multiply(this.G/w/Math.sqrt(w)*l*d.GetMass()),
e.IsAwake()&&e.ApplyForce(j,h),j.Multiply(-1),d.IsAwake()&&d.ApplyForce(j,r))}else for(c=this.m_bodyList;c;c=c.nextBody){e=c.body;h=e.GetWorldCenter();l=e.GetMass();for(m=this.m_bodyList;m!=c;m=m.nextBody)d=m.body,r=d.GetWorldCenter(),j=r.x-h.x,p=r.y-h.y,w=j*j+p*p,w<Number.MIN_VALUE||(j=new q(j,p),j.Multiply(this.G/w*l*d.GetMass()),e.IsAwake()&&e.ApplyForce(j,h),j.Multiply(-1),d.IsAwake()&&d.ApplyForce(j,r))}};Box2D.inherit(C,Box2D.Dynamics.Controllers.b2Controller);C.prototype.__super=Box2D.Dynamics.Controllers.b2Controller.prototype;
C.b2TensorDampingController=function(){Box2D.Dynamics.Controllers.b2Controller.b2Controller.apply(this,arguments);this.T=new m;this.maxTimestep=0};C.prototype.SetAxisAligned=function(c,e){c===void 0&&(c=0);e===void 0&&(e=0);this.T.col1.x=-c;this.T.col1.y=0;this.T.col2.x=0;this.T.col2.y=-e;this.maxTimestep=c>0||e>0?1/Math.max(c,e):0};C.prototype.Step=function(c){c=c.dt;if(!(c<=Number.MIN_VALUE)){if(c>this.maxTimestep&&this.maxTimestep>0)c=this.maxTimestep;for(var e=this.m_bodyList;e;e=e.nextBody){var h=
e.body;if(h.IsAwake()){var l=h.GetWorldVector(r.MulMV(this.T,h.GetLocalVector(h.GetLinearVelocity())));h.SetLinearVelocity(new q(h.GetLinearVelocity().x+l.x*c,h.GetLinearVelocity().y+l.y*c))}}}}})();
(function(){var m=Box2D.Common.b2Settings,r=Box2D.Common.Math.b2Mat22,q=Box2D.Common.Math.b2Mat33,e=Box2D.Common.Math.b2Math,h=Box2D.Common.Math.b2Vec2,l=Box2D.Common.Math.b2Vec3,w=Box2D.Dynamics.Joints.b2DistanceJoint,c=Box2D.Dynamics.Joints.b2DistanceJointDef,p=Box2D.Dynamics.Joints.b2FrictionJoint,H=Box2D.Dynamics.Joints.b2FrictionJointDef,C=Box2D.Dynamics.Joints.b2GearJoint,v=Box2D.Dynamics.Joints.b2GearJointDef,y=Box2D.Dynamics.Joints.b2Jacobian,s=Box2D.Dynamics.Joints.b2Joint,J=Box2D.Dynamics.Joints.b2JointDef,
K=Box2D.Dynamics.Joints.b2JointEdge,d=Box2D.Dynamics.Joints.b2LineJoint,x=Box2D.Dynamics.Joints.b2LineJointDef,j=Box2D.Dynamics.Joints.b2MouseJoint,B=Box2D.Dynamics.Joints.b2MouseJointDef,E=Box2D.Dynamics.Joints.b2PrismaticJoint,G=Box2D.Dynamics.Joints.b2PrismaticJointDef,A=Box2D.Dynamics.Joints.b2PulleyJoint,L=Box2D.Dynamics.Joints.b2PulleyJointDef,D=Box2D.Dynamics.Joints.b2RevoluteJoint,F=Box2D.Dynamics.Joints.b2RevoluteJointDef,M=Box2D.Dynamics.Joints.b2WeldJoint,I=Box2D.Dynamics.Joints.b2WeldJointDef;
Box2D.inherit(w,Box2D.Dynamics.Joints.b2Joint);w.prototype.__super=Box2D.Dynamics.Joints.b2Joint.prototype;w.b2DistanceJoint=function(){Box2D.Dynamics.Joints.b2Joint.b2Joint.apply(this,arguments);this.m_localAnchor1=new h;this.m_localAnchor2=new h;this.m_u=new h};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(a){a===void 0&&(a=0);
return new h(a*this.m_impulse*this.m_u.x,a*this.m_impulse*this.m_u.y)};w.prototype.GetReactionTorque=function(){return 0};w.prototype.GetLength=function(){return this.m_length};w.prototype.SetLength=function(a){a===void 0&&(a=0);this.m_length=a};w.prototype.GetFrequency=function(){return this.m_frequencyHz};w.prototype.SetFrequency=function(a){a===void 0&&(a=0);this.m_frequencyHz=a};w.prototype.GetDampingRatio=function(){return this.m_dampingRatio};w.prototype.SetDampingRatio=function(a){a===void 0&&
(a=0);this.m_dampingRatio=a};w.prototype.b2DistanceJoint=function(a){this.__super.b2Joint.call(this,a);this.m_localAnchor1.SetV(a.localAnchorA);this.m_localAnchor2.SetV(a.localAnchorB);this.m_length=a.length;this.m_frequencyHz=a.frequencyHz;this.m_dampingRatio=a.dampingRatio;this.m_bias=this.m_gamma=this.m_impulse=0};w.prototype.InitVelocityConstraints=function(a){var g,c=0,e=this.m_bodyA,d=this.m_bodyB;g=e.m_xf.R;var h=this.m_localAnchor1.x-e.m_sweep.localCenter.x,f=this.m_localAnchor1.y-e.m_sweep.localCenter.y,
c=g.col1.x*h+g.col2.x*f,f=g.col1.y*h+g.col2.y*f,h=c;g=d.m_xf.R;var b=this.m_localAnchor2.x-d.m_sweep.localCenter.x,k=this.m_localAnchor2.y-d.m_sweep.localCenter.y,c=g.col1.x*b+g.col2.x*k,k=g.col1.y*b+g.col2.y*k,b=c;this.m_u.x=d.m_sweep.c.x+b-e.m_sweep.c.x-h;this.m_u.y=d.m_sweep.c.y+k-e.m_sweep.c.y-f;c=Math.sqrt(this.m_u.x*this.m_u.x+this.m_u.y*this.m_u.y);c>m.b2_linearSlop?this.m_u.Multiply(1/c):this.m_u.SetZero();g=h*this.m_u.y-f*this.m_u.x;var j=b*this.m_u.y-k*this.m_u.x;g=e.m_invMass+e.m_invI*
g*g+d.m_invMass+d.m_invI*j*j;this.m_mass=g!=0?1/g:0;if(this.m_frequencyHz>0){c-=this.m_length;var j=2*Math.PI*this.m_frequencyHz,l=this.m_mass*j*j;this.m_gamma=a.dt*(2*this.m_mass*this.m_dampingRatio*j+a.dt*l);this.m_gamma=this.m_gamma!=0?1/this.m_gamma:0;this.m_bias=c*a.dt*l*this.m_gamma;this.m_mass=g+this.m_gamma;this.m_mass=this.m_mass!=0?1/this.m_mass:0}a.warmStarting?(this.m_impulse*=a.dtRatio,a=this.m_impulse*this.m_u.x,g=this.m_impulse*this.m_u.y,e.m_linearVelocity.x-=e.m_invMass*a,e.m_linearVelocity.y-=
e.m_invMass*g,e.m_angularVelocity-=e.m_invI*(h*g-f*a),d.m_linearVelocity.x+=d.m_invMass*a,d.m_linearVelocity.y+=d.m_invMass*g,d.m_angularVelocity+=d.m_invI*(b*g-k*a)):this.m_impulse=0};w.prototype.SolveVelocityConstraints=function(){var a,g=this.m_bodyA,c=this.m_bodyB;a=g.m_xf.R;var e=this.m_localAnchor1.x-g.m_sweep.localCenter.x,d=this.m_localAnchor1.y-g.m_sweep.localCenter.y,h=a.col1.x*e+a.col2.x*d,d=a.col1.y*e+a.col2.y*d,e=h;a=c.m_xf.R;var f=this.m_localAnchor2.x-c.m_sweep.localCenter.x,b=this.m_localAnchor2.y-
c.m_sweep.localCenter.y,h=a.col1.x*f+a.col2.x*b,b=a.col1.y*f+a.col2.y*b,f=h,h=-this.m_mass*(this.m_u.x*(c.m_linearVelocity.x+-c.m_angularVelocity*b-(g.m_linearVelocity.x+-g.m_angularVelocity*d))+this.m_u.y*(c.m_linearVelocity.y+c.m_angularVelocity*f-(g.m_linearVelocity.y+g.m_angularVelocity*e))+this.m_bias+this.m_gamma*this.m_impulse);this.m_impulse+=h;a=h*this.m_u.x;h*=this.m_u.y;g.m_linearVelocity.x-=g.m_invMass*a;g.m_linearVelocity.y-=g.m_invMass*h;g.m_angularVelocity-=g.m_invI*(e*h-d*a);c.m_linearVelocity.x+=
c.m_invMass*a;c.m_linearVelocity.y+=c.m_invMass*h;c.m_angularVelocity+=c.m_invI*(f*h-b*a)};w.prototype.SolvePositionConstraints=function(){var a;if(this.m_frequencyHz>0)return!0;var g=this.m_bodyA,c=this.m_bodyB;a=g.m_xf.R;var n=this.m_localAnchor1.x-g.m_sweep.localCenter.x,d=this.m_localAnchor1.y-g.m_sweep.localCenter.y,h=a.col1.x*n+a.col2.x*d,d=a.col1.y*n+a.col2.y*d,n=h;a=c.m_xf.R;var f=this.m_localAnchor2.x-c.m_sweep.localCenter.x,b=this.m_localAnchor2.y-c.m_sweep.localCenter.y,h=a.col1.x*f+a.col2.x*
b,b=a.col1.y*f+a.col2.y*b,f=h,h=c.m_sweep.c.x+f-g.m_sweep.c.x-n,k=c.m_sweep.c.y+b-g.m_sweep.c.y-d;a=Math.sqrt(h*h+k*k);h/=a;k/=a;a-=this.m_length;a=e.Clamp(a,-m.b2_maxLinearCorrection,m.b2_maxLinearCorrection);var j=-this.m_mass*a;this.m_u.Set(h,k);h=j*this.m_u.x;k=j*this.m_u.y;g.m_sweep.c.x-=g.m_invMass*h;g.m_sweep.c.y-=g.m_invMass*k;g.m_sweep.a-=g.m_invI*(n*k-d*h);c.m_sweep.c.x+=c.m_invMass*h;c.m_sweep.c.y+=c.m_invMass*k;c.m_sweep.a+=c.m_invI*(f*k-b*h);g.SynchronizeTransform();c.SynchronizeTransform();
return e.Abs(a)<m.b2_linearSlop};Box2D.inherit(c,Box2D.Dynamics.Joints.b2JointDef);c.prototype.__super=Box2D.Dynamics.Joints.b2JointDef.prototype;c.b2DistanceJointDef=function(){Box2D.Dynamics.Joints.b2JointDef.b2JointDef.apply(this,arguments);this.localAnchorA=new h;this.localAnchorB=new h};c.prototype.b2DistanceJointDef=function(){this.__super.b2JointDef.call(this);this.type=s.e_distanceJoint;this.length=1;this.dampingRatio=this.frequencyHz=0};c.prototype.Initialize=function(a,g,c,e){this.bodyA=
a;this.bodyB=g;this.localAnchorA.SetV(this.bodyA.GetLocalPoint(c));this.localAnchorB.SetV(this.bodyB.GetLocalPoint(e));a=e.x-c.x;c=e.y-c.y;this.length=Math.sqrt(a*a+c*c);this.dampingRatio=this.frequencyHz=0};Box2D.inherit(p,Box2D.Dynamics.Joints.b2Joint);p.prototype.__super=Box2D.Dynamics.Joints.b2Joint.prototype;p.b2FrictionJoint=function(){Box2D.Dynamics.Joints.b2Joint.b2Joint.apply(this,arguments);this.m_localAnchorA=new h;this.m_localAnchorB=new h;this.m_linearMass=new r;this.m_linearImpulse=
new h};p.prototype.GetAnchorA=function(){return this.m_bodyA.GetWorldPoint(this.m_localAnchorA)};p.prototype.GetAnchorB=function(){return this.m_bodyB.GetWorldPoint(this.m_localAnchorB)};p.prototype.GetReactionForce=function(a){a===void 0&&(a=0);return new h(a*this.m_linearImpulse.x,a*this.m_linearImpulse.y)};p.prototype.GetReactionTorque=function(a){a===void 0&&(a=0);return a*this.m_angularImpulse};p.prototype.SetMaxForce=function(a){a===void 0&&(a=0);this.m_maxForce=a};p.prototype.GetMaxForce=function(){return this.m_maxForce};
p.prototype.SetMaxTorque=function(a){a===void 0&&(a=0);this.m_maxTorque=a};p.prototype.GetMaxTorque=function(){return this.m_maxTorque};p.prototype.b2FrictionJoint=function(a){this.__super.b2Joint.call(this,a);this.m_localAnchorA.SetV(a.localAnchorA);this.m_localAnchorB.SetV(a.localAnchorB);this.m_linearMass.SetZero();this.m_angularMass=0;this.m_linearImpulse.SetZero();this.m_angularImpulse=0;this.m_maxForce=a.maxForce;this.m_maxTorque=a.maxTorque};p.prototype.InitVelocityConstraints=function(a){var g,
c=0,e=this.m_bodyA,d=this.m_bodyB;g=e.m_xf.R;var h=this.m_localAnchorA.x-e.m_sweep.localCenter.x,f=this.m_localAnchorA.y-e.m_sweep.localCenter.y,c=g.col1.x*h+g.col2.x*f,f=g.col1.y*h+g.col2.y*f,h=c;g=d.m_xf.R;var b=this.m_localAnchorB.x-d.m_sweep.localCenter.x,k=this.m_localAnchorB.y-d.m_sweep.localCenter.y,c=g.col1.x*b+g.col2.x*k,k=g.col1.y*b+g.col2.y*k,b=c;g=e.m_invMass;var c=d.m_invMass,j=e.m_invI,l=d.m_invI,m=new r;m.col1.x=g+c;m.col2.x=0;m.col1.y=0;m.col2.y=g+c;m.col1.x+=j*f*f;m.col2.x+=-j*h*
f;m.col1.y+=-j*h*f;m.col2.y+=j*h*h;m.col1.x+=l*k*k;m.col2.x+=-l*b*k;m.col1.y+=-l*b*k;m.col2.y+=l*b*b;m.GetInverse(this.m_linearMass);this.m_angularMass=j+l;if(this.m_angularMass>0)this.m_angularMass=1/this.m_angularMass;a.warmStarting?(this.m_linearImpulse.x*=a.dtRatio,this.m_linearImpulse.y*=a.dtRatio,this.m_angularImpulse*=a.dtRatio,a=this.m_linearImpulse,e.m_linearVelocity.x-=g*a.x,e.m_linearVelocity.y-=g*a.y,e.m_angularVelocity-=j*(h*a.y-f*a.x+this.m_angularImpulse),d.m_linearVelocity.x+=c*a.x,
d.m_linearVelocity.y+=c*a.y,d.m_angularVelocity+=l*(b*a.y-k*a.x+this.m_angularImpulse)):(this.m_linearImpulse.SetZero(),this.m_angularImpulse=0)};p.prototype.SolveVelocityConstraints=function(a){var g,c=0,n=this.m_bodyA,d=this.m_bodyB,j=n.m_linearVelocity,f=n.m_angularVelocity,b=d.m_linearVelocity,k=d.m_angularVelocity,l=n.m_invMass,m=d.m_invMass,r=n.m_invI,q=d.m_invI;g=n.m_xf.R;var p=this.m_localAnchorA.x-n.m_sweep.localCenter.x,s=this.m_localAnchorA.y-n.m_sweep.localCenter.y,c=g.col1.x*p+g.col2.x*
s,s=g.col1.y*p+g.col2.y*s,p=c;g=d.m_xf.R;var w=this.m_localAnchorB.x-d.m_sweep.localCenter.x,v=this.m_localAnchorB.y-d.m_sweep.localCenter.y,c=g.col1.x*w+g.col2.x*v,v=g.col1.y*w+g.col2.y*v,w=c;g=0;var c=-this.m_angularMass*(k-f),x=this.m_angularImpulse;g=a.dt*this.m_maxTorque;this.m_angularImpulse=e.Clamp(this.m_angularImpulse+c,-g,g);c=this.m_angularImpulse-x;f-=r*c;k+=q*c;g=e.MulMV(this.m_linearMass,new h(-(b.x-k*v-j.x+f*s),-(b.y+k*w-j.y-f*p)));c=this.m_linearImpulse.Copy();this.m_linearImpulse.Add(g);
g=a.dt*this.m_maxForce;this.m_linearImpulse.LengthSquared()>g*g&&(this.m_linearImpulse.Normalize(),this.m_linearImpulse.Multiply(g));g=e.SubtractVV(this.m_linearImpulse,c);j.x-=l*g.x;j.y-=l*g.y;f-=r*(p*g.y-s*g.x);b.x+=m*g.x;b.y+=m*g.y;k+=q*(w*g.y-v*g.x);n.m_angularVelocity=f;d.m_angularVelocity=k};p.prototype.SolvePositionConstraints=function(){return!0};Box2D.inherit(H,Box2D.Dynamics.Joints.b2JointDef);H.prototype.__super=Box2D.Dynamics.Joints.b2JointDef.prototype;H.b2FrictionJointDef=function(){Box2D.Dynamics.Joints.b2JointDef.b2JointDef.apply(this,
arguments);this.localAnchorA=new h;this.localAnchorB=new h};H.prototype.b2FrictionJointDef=function(){this.__super.b2JointDef.call(this);this.type=s.e_frictionJoint;this.maxTorque=this.maxForce=0};H.prototype.Initialize=function(a,g,c){this.bodyA=a;this.bodyB=g;this.localAnchorA.SetV(this.bodyA.GetLocalPoint(c));this.localAnchorB.SetV(this.bodyB.GetLocalPoint(c))};Box2D.inherit(C,Box2D.Dynamics.Joints.b2Joint);C.prototype.__super=Box2D.Dynamics.Joints.b2Joint.prototype;C.b2GearJoint=function(){Box2D.Dynamics.Joints.b2Joint.b2Joint.apply(this,
arguments);this.m_groundAnchor1=new h;this.m_groundAnchor2=new h;this.m_localAnchor1=new h;this.m_localAnchor2=new h;this.m_J=new y};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(a){a===void 0&&(a=0);return new h(a*this.m_impulse*this.m_J.linearB.x,a*this.m_impulse*this.m_J.linearB.y)};C.prototype.GetReactionTorque=function(a){a===
void 0&&(a=0);var g=this.m_bodyB.m_xf.R,c=this.m_localAnchor1.x-this.m_bodyB.m_sweep.localCenter.x,e=this.m_localAnchor1.y-this.m_bodyB.m_sweep.localCenter.y,d=g.col1.x*c+g.col2.x*e,e=g.col1.y*c+g.col2.y*e;return a*(this.m_impulse*this.m_J.angularB-d*this.m_impulse*this.m_J.linearB.y+e*this.m_impulse*this.m_J.linearB.x)};C.prototype.GetRatio=function(){return this.m_ratio};C.prototype.SetRatio=function(a){a===void 0&&(a=0);this.m_ratio=a};C.prototype.b2GearJoint=function(a){this.__super.b2Joint.call(this,
a);var g=parseInt(a.joint1.m_type),c=parseInt(a.joint2.m_type);this.m_prismatic2=this.m_revolute2=this.m_prismatic1=this.m_revolute1=null;var e=0,d=0;this.m_ground1=a.joint1.GetBodyA();this.m_bodyA=a.joint1.GetBodyB();g==s.e_revoluteJoint?(this.m_revolute1=a.joint1 instanceof D?a.joint1:null,this.m_groundAnchor1.SetV(this.m_revolute1.m_localAnchor1),this.m_localAnchor1.SetV(this.m_revolute1.m_localAnchor2),e=this.m_revolute1.GetJointAngle()):(this.m_prismatic1=a.joint1 instanceof E?a.joint1:null,
this.m_groundAnchor1.SetV(this.m_prismatic1.m_localAnchor1),this.m_localAnchor1.SetV(this.m_prismatic1.m_localAnchor2),e=this.m_prismatic1.GetJointTranslation());this.m_ground2=a.joint2.GetBodyA();this.m_bodyB=a.joint2.GetBodyB();c==s.e_revoluteJoint?(this.m_revolute2=a.joint2 instanceof D?a.joint2:null,this.m_groundAnchor2.SetV(this.m_revolute2.m_localAnchor1),this.m_localAnchor2.SetV(this.m_revolute2.m_localAnchor2),d=this.m_revolute2.GetJointAngle()):(this.m_prismatic2=a.joint2 instanceof E?a.joint2:
null,this.m_groundAnchor2.SetV(this.m_prismatic2.m_localAnchor1),this.m_localAnchor2.SetV(this.m_prismatic2.m_localAnchor2),d=this.m_prismatic2.GetJointTranslation());this.m_ratio=a.ratio;this.m_constant=e+this.m_ratio*d;this.m_impulse=0};C.prototype.InitVelocityConstraints=function(a){var g=this.m_ground1,c=this.m_ground2,e=this.m_bodyA,d=this.m_bodyB,h=0,f=0,b=0,k=0,j=b=0,l=0;this.m_J.SetZero();this.m_revolute1?(this.m_J.angularA=-1,l+=e.m_invI):(g=g.m_xf.R,f=this.m_prismatic1.m_localXAxis1,h=g.col1.x*
f.x+g.col2.x*f.y,f=g.col1.y*f.x+g.col2.y*f.y,g=e.m_xf.R,b=this.m_localAnchor1.x-e.m_sweep.localCenter.x,k=this.m_localAnchor1.y-e.m_sweep.localCenter.y,j=g.col1.x*b+g.col2.x*k,k=g.col1.y*b+g.col2.y*k,b=j*f-k*h,this.m_J.linearA.Set(-h,-f),this.m_J.angularA=-b,l+=e.m_invMass+e.m_invI*b*b);this.m_revolute2?(this.m_J.angularB=-this.m_ratio,l+=this.m_ratio*this.m_ratio*d.m_invI):(g=c.m_xf.R,f=this.m_prismatic2.m_localXAxis1,h=g.col1.x*f.x+g.col2.x*f.y,f=g.col1.y*f.x+g.col2.y*f.y,g=d.m_xf.R,b=this.m_localAnchor2.x-
d.m_sweep.localCenter.x,k=this.m_localAnchor2.y-d.m_sweep.localCenter.y,j=g.col1.x*b+g.col2.x*k,k=g.col1.y*b+g.col2.y*k,b=j*f-k*h,this.m_J.linearB.Set(-this.m_ratio*h,-this.m_ratio*f),this.m_J.angularB=-this.m_ratio*b,l+=this.m_ratio*this.m_ratio*(d.m_invMass+d.m_invI*b*b));this.m_mass=l>0?1/l:0;a.warmStarting?(e.m_linearVelocity.x+=e.m_invMass*this.m_impulse*this.m_J.linearA.x,e.m_linearVelocity.y+=e.m_invMass*this.m_impulse*this.m_J.linearA.y,e.m_angularVelocity+=e.m_invI*this.m_impulse*this.m_J.angularA,
d.m_linearVelocity.x+=d.m_invMass*this.m_impulse*this.m_J.linearB.x,d.m_linearVelocity.y+=d.m_invMass*this.m_impulse*this.m_J.linearB.y,d.m_angularVelocity+=d.m_invI*this.m_impulse*this.m_J.angularB):this.m_impulse=0};C.prototype.SolveVelocityConstraints=function(){var a=this.m_bodyA,g=this.m_bodyB,c=-this.m_mass*this.m_J.Compute(a.m_linearVelocity,a.m_angularVelocity,g.m_linearVelocity,g.m_angularVelocity);this.m_impulse+=c;a.m_linearVelocity.x+=a.m_invMass*c*this.m_J.linearA.x;a.m_linearVelocity.y+=
a.m_invMass*c*this.m_J.linearA.y;a.m_angularVelocity+=a.m_invI*c*this.m_J.angularA;g.m_linearVelocity.x+=g.m_invMass*c*this.m_J.linearB.x;g.m_linearVelocity.y+=g.m_invMass*c*this.m_J.linearB.y;g.m_angularVelocity+=g.m_invI*c*this.m_J.angularB};C.prototype.SolvePositionConstraints=function(){var a=this.m_bodyA,g=this.m_bodyB,c=0,e=0,c=this.m_revolute1?this.m_revolute1.GetJointAngle():this.m_prismatic1.GetJointTranslation(),e=this.m_revolute2?this.m_revolute2.GetJointAngle():this.m_prismatic2.GetJointTranslation(),
c=-this.m_mass*(this.m_constant-(c+this.m_ratio*e));a.m_sweep.c.x+=a.m_invMass*c*this.m_J.linearA.x;a.m_sweep.c.y+=a.m_invMass*c*this.m_J.linearA.y;a.m_sweep.a+=a.m_invI*c*this.m_J.angularA;g.m_sweep.c.x+=g.m_invMass*c*this.m_J.linearB.x;g.m_sweep.c.y+=g.m_invMass*c*this.m_J.linearB.y;g.m_sweep.a+=g.m_invI*c*this.m_J.angularB;a.SynchronizeTransform();g.SynchronizeTransform();return 0<m.b2_linearSlop};Box2D.inherit(v,Box2D.Dynamics.Joints.b2JointDef);v.prototype.__super=Box2D.Dynamics.Joints.b2JointDef.prototype;
v.b2GearJointDef=function(){Box2D.Dynamics.Joints.b2JointDef.b2JointDef.apply(this,arguments)};v.prototype.b2GearJointDef=function(){this.__super.b2JointDef.call(this);this.type=s.e_gearJoint;this.joint2=this.joint1=null;this.ratio=1};y.b2Jacobian=function(){this.linearA=new h;this.linearB=new h};y.prototype.SetZero=function(){this.linearA.SetZero();this.angularA=0;this.linearB.SetZero();this.angularB=0};y.prototype.Set=function(a,g,c,e){g===void 0&&(g=0);e===void 0&&(e=0);this.linearA.SetV(a);this.angularA=
g;this.linearB.SetV(c);this.angularB=e};y.prototype.Compute=function(a,g,c,e){g===void 0&&(g=0);e===void 0&&(e=0);return this.linearA.x*a.x+this.linearA.y*a.y+this.angularA*g+(this.linearB.x*c.x+this.linearB.y*c.y)+this.angularB*e};s.b2Joint=function(){this.m_edgeA=new K;this.m_edgeB=new K;this.m_localCenterA=new h;this.m_localCenterB=new h};s.prototype.GetType=function(){return this.m_type};s.prototype.GetAnchorA=function(){return null};s.prototype.GetAnchorB=function(){return null};s.prototype.GetReactionForce=
function(){return null};s.prototype.GetReactionTorque=function(){return 0};s.prototype.GetBodyA=function(){return this.m_bodyA};s.prototype.GetBodyB=function(){return this.m_bodyB};s.prototype.GetNext=function(){return this.m_next};s.prototype.GetUserData=function(){return this.m_userData};s.prototype.SetUserData=function(a){this.m_userData=a};s.prototype.IsActive=function(){return this.m_bodyA.IsActive()&&this.m_bodyB.IsActive()};s.Create=function(a){var g=null;switch(a.type){case s.e_distanceJoint:g=
new w(a instanceof c?a:null);break;case s.e_mouseJoint:g=new j(a instanceof B?a:null);break;case s.e_prismaticJoint:g=new E(a instanceof G?a:null);break;case s.e_revoluteJoint:g=new D(a instanceof F?a:null);break;case s.e_pulleyJoint:g=new A(a instanceof L?a:null);break;case s.e_gearJoint:g=new C(a instanceof v?a:null);break;case s.e_lineJoint:g=new d(a instanceof x?a:null);break;case s.e_weldJoint:g=new M(a instanceof I?a:null);break;case s.e_frictionJoint:g=new p(a instanceof H?a:null)}return g};
s.Destroy=function(){};s.prototype.b2Joint=function(a){m.b2Assert(a.bodyA!=a.bodyB);this.m_type=a.type;this.m_next=this.m_prev=null;this.m_bodyA=a.bodyA;this.m_bodyB=a.bodyB;this.m_collideConnected=a.collideConnected;this.m_islandFlag=!1;this.m_userData=a.userData};s.prototype.InitVelocityConstraints=function(){};s.prototype.SolveVelocityConstraints=function(){};s.prototype.FinalizeVelocityConstraints=function(){};s.prototype.SolvePositionConstraints=function(){return!1};Box2D.postDefs.push(function(){Box2D.Dynamics.Joints.b2Joint.e_unknownJoint=
0;Box2D.Dynamics.Joints.b2Joint.e_revoluteJoint=1;Box2D.Dynamics.Joints.b2Joint.e_prismaticJoint=2;Box2D.Dynamics.Joints.b2Joint.e_distanceJoint=3;Box2D.Dynamics.Joints.b2Joint.e_pulleyJoint=4;Box2D.Dynamics.Joints.b2Joint.e_mouseJoint=5;Box2D.Dynamics.Joints.b2Joint.e_gearJoint=6;Box2D.Dynamics.Joints.b2Joint.e_lineJoint=7;Box2D.Dynamics.Joints.b2Joint.e_weldJoint=8;Box2D.Dynamics.Joints.b2Joint.e_frictionJoint=9;Box2D.Dynamics.Joints.b2Joint.e_inactiveLimit=0;Box2D.Dynamics.Joints.b2Joint.e_atLowerLimit=
1;Box2D.Dynamics.Joints.b2Joint.e_atUpperLimit=2;Box2D.Dynamics.Joints.b2Joint.e_equalLimits=3});J.b2JointDef=function(){};J.prototype.b2JointDef=function(){this.type=s.e_unknownJoint;this.bodyB=this.bodyA=this.userData=null;this.collideConnected=!1};K.b2JointEdge=function(){};Box2D.inherit(d,Box2D.Dynamics.Joints.b2Joint);d.prototype.__super=Box2D.Dynamics.Joints.b2Joint.prototype;d.b2LineJoint=function(){Box2D.Dynamics.Joints.b2Joint.b2Joint.apply(this,arguments);this.m_localAnchor1=new h;this.m_localAnchor2=
new h;this.m_localXAxis1=new h;this.m_localYAxis1=new h;this.m_axis=new h;this.m_perp=new h;this.m_K=new r;this.m_impulse=new h};d.prototype.GetAnchorA=function(){return this.m_bodyA.GetWorldPoint(this.m_localAnchor1)};d.prototype.GetAnchorB=function(){return this.m_bodyB.GetWorldPoint(this.m_localAnchor2)};d.prototype.GetReactionForce=function(a){a===void 0&&(a=0);return new h(a*(this.m_impulse.x*this.m_perp.x+(this.m_motorImpulse+this.m_impulse.y)*this.m_axis.x),a*(this.m_impulse.x*this.m_perp.y+
(this.m_motorImpulse+this.m_impulse.y)*this.m_axis.y))};d.prototype.GetReactionTorque=function(a){a===void 0&&(a=0);return a*this.m_impulse.y};d.prototype.GetJointTranslation=function(){var a=this.m_bodyA,g=this.m_bodyB,c=a.GetWorldPoint(this.m_localAnchor1),e=g.GetWorldPoint(this.m_localAnchor2),g=e.x-c.x,c=e.y-c.y,a=a.GetWorldVector(this.m_localXAxis1);return a.x*g+a.y*c};d.prototype.GetJointSpeed=function(){var a=this.m_bodyA,g=this.m_bodyB,c;c=a.m_xf.R;var e=this.m_localAnchor1.x-a.m_sweep.localCenter.x,
d=this.m_localAnchor1.y-a.m_sweep.localCenter.y,h=c.col1.x*e+c.col2.x*d,d=c.col1.y*e+c.col2.y*d,e=h;c=g.m_xf.R;var f=this.m_localAnchor2.x-g.m_sweep.localCenter.x,b=this.m_localAnchor2.y-g.m_sweep.localCenter.y,h=c.col1.x*f+c.col2.x*b,b=c.col1.y*f+c.col2.y*b,f=h;c=g.m_sweep.c.x+f-(a.m_sweep.c.x+e);var h=g.m_sweep.c.y+b-(a.m_sweep.c.y+d),k=a.GetWorldVector(this.m_localXAxis1),j=a.m_linearVelocity,l=g.m_linearVelocity,a=a.m_angularVelocity,g=g.m_angularVelocity;return c*-a*k.y+h*a*k.x+(k.x*(l.x+-g*
b-j.x- -a*d)+k.y*(l.y+g*f-j.y-a*e))};d.prototype.IsLimitEnabled=function(){return this.m_enableLimit};d.prototype.EnableLimit=function(a){this.m_bodyA.SetAwake(!0);this.m_bodyB.SetAwake(!0);this.m_enableLimit=a};d.prototype.GetLowerLimit=function(){return this.m_lowerTranslation};d.prototype.GetUpperLimit=function(){return this.m_upperTranslation};d.prototype.SetLimits=function(a,g){a===void 0&&(a=0);g===void 0&&(g=0);this.m_bodyA.SetAwake(!0);this.m_bodyB.SetAwake(!0);this.m_lowerTranslation=a;this.m_upperTranslation=
g};d.prototype.IsMotorEnabled=function(){return this.m_enableMotor};d.prototype.EnableMotor=function(a){this.m_bodyA.SetAwake(!0);this.m_bodyB.SetAwake(!0);this.m_enableMotor=a};d.prototype.SetMotorSpeed=function(a){a===void 0&&(a=0);this.m_bodyA.SetAwake(!0);this.m_bodyB.SetAwake(!0);this.m_motorSpeed=a};d.prototype.GetMotorSpeed=function(){return this.m_motorSpeed};d.prototype.SetMaxMotorForce=function(a){a===void 0&&(a=0);this.m_bodyA.SetAwake(!0);this.m_bodyB.SetAwake(!0);this.m_maxMotorForce=
a};d.prototype.GetMaxMotorForce=function(){return this.m_maxMotorForce};d.prototype.GetMotorForce=function(){return this.m_motorImpulse};d.prototype.b2LineJoint=function(a){this.__super.b2Joint.call(this,a);this.m_localAnchor1.SetV(a.localAnchorA);this.m_localAnchor2.SetV(a.localAnchorB);this.m_localXAxis1.SetV(a.localAxisA);this.m_localYAxis1.x=-this.m_localXAxis1.y;this.m_localYAxis1.y=this.m_localXAxis1.x;this.m_impulse.SetZero();this.m_motorImpulse=this.m_motorMass=0;this.m_lowerTranslation=a.lowerTranslation;
this.m_upperTranslation=a.upperTranslation;this.m_maxMotorForce=a.maxMotorForce;this.m_motorSpeed=a.motorSpeed;this.m_enableLimit=a.enableLimit;this.m_enableMotor=a.enableMotor;this.m_limitState=s.e_inactiveLimit;this.m_axis.SetZero();this.m_perp.SetZero()};d.prototype.InitVelocityConstraints=function(a){var g=this.m_bodyA,c=this.m_bodyB,d,h=0;this.m_localCenterA.SetV(g.GetLocalCenter());this.m_localCenterB.SetV(c.GetLocalCenter());var j=g.GetTransform();c.GetTransform();d=g.m_xf.R;var f=this.m_localAnchor1.x-
this.m_localCenterA.x,b=this.m_localAnchor1.y-this.m_localCenterA.y,h=d.col1.x*f+d.col2.x*b,b=d.col1.y*f+d.col2.y*b,f=h;d=c.m_xf.R;var k=this.m_localAnchor2.x-this.m_localCenterB.x,l=this.m_localAnchor2.y-this.m_localCenterB.y,h=d.col1.x*k+d.col2.x*l,l=d.col1.y*k+d.col2.y*l,k=h;d=c.m_sweep.c.x+k-g.m_sweep.c.x-f;h=c.m_sweep.c.y+l-g.m_sweep.c.y-b;this.m_invMassA=g.m_invMass;this.m_invMassB=c.m_invMass;this.m_invIA=g.m_invI;this.m_invIB=c.m_invI;this.m_axis.SetV(e.MulMV(j.R,this.m_localXAxis1));this.m_a1=
(d+f)*this.m_axis.y-(h+b)*this.m_axis.x;this.m_a2=k*this.m_axis.y-l*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(e.MulMV(j.R,this.m_localYAxis1));this.m_s1=(d+f)*this.m_perp.y-(h+b)*this.m_perp.x;this.m_s2=k*this.m_perp.y-l*this.m_perp.x;j=this.m_invMassA;f=this.m_invMassB;b=this.m_invIA;k=this.m_invIB;this.m_K.col1.x=j+f+b*this.m_s1*
this.m_s1+k*this.m_s2*this.m_s2;this.m_K.col1.y=b*this.m_s1*this.m_a1+k*this.m_s2*this.m_a2;this.m_K.col2.x=this.m_K.col1.y;this.m_K.col2.y=j+f+b*this.m_a1*this.m_a1+k*this.m_a2*this.m_a2;if(this.m_enableLimit)if(d=this.m_axis.x*d+this.m_axis.y*h,e.Abs(this.m_upperTranslation-this.m_lowerTranslation)<2*m.b2_linearSlop)this.m_limitState=s.e_equalLimits;else if(d<=this.m_lowerTranslation){if(this.m_limitState!=s.e_atLowerLimit)this.m_limitState=s.e_atLowerLimit,this.m_impulse.y=0}else if(d>=this.m_upperTranslation){if(this.m_limitState!=
s.e_atUpperLimit)this.m_limitState=s.e_atUpperLimit,this.m_impulse.y=0}else this.m_limitState=s.e_inactiveLimit,this.m_impulse.y=0;else this.m_limitState=s.e_inactiveLimit;if(this.m_enableMotor==!1)this.m_motorImpulse=0;a.warmStarting?(this.m_impulse.x*=a.dtRatio,this.m_impulse.y*=a.dtRatio,this.m_motorImpulse*=a.dtRatio,a=this.m_impulse.x*this.m_perp.x+(this.m_motorImpulse+this.m_impulse.y)*this.m_axis.x,d=this.m_impulse.x*this.m_perp.y+(this.m_motorImpulse+this.m_impulse.y)*this.m_axis.y,h=this.m_impulse.x*
this.m_s1+(this.m_motorImpulse+this.m_impulse.y)*this.m_a1,j=this.m_impulse.x*this.m_s2+(this.m_motorImpulse+this.m_impulse.y)*this.m_a2,g.m_linearVelocity.x-=this.m_invMassA*a,g.m_linearVelocity.y-=this.m_invMassA*d,g.m_angularVelocity-=this.m_invIA*h,c.m_linearVelocity.x+=this.m_invMassB*a,c.m_linearVelocity.y+=this.m_invMassB*d,c.m_angularVelocity+=this.m_invIB*j):(this.m_impulse.SetZero(),this.m_motorImpulse=0)};d.prototype.SolveVelocityConstraints=function(a){var c=this.m_bodyA,d=this.m_bodyB,
n=c.m_linearVelocity,j=c.m_angularVelocity,l=d.m_linearVelocity,f=d.m_angularVelocity,b=0,k=0,m=0,r=0;if(this.m_enableMotor&&this.m_limitState!=s.e_equalLimits)r=this.m_motorMass*(this.m_motorSpeed-(this.m_axis.x*(l.x-n.x)+this.m_axis.y*(l.y-n.y)+this.m_a2*f-this.m_a1*j)),b=this.m_motorImpulse,k=a.dt*this.m_maxMotorForce,this.m_motorImpulse=e.Clamp(this.m_motorImpulse+r,-k,k),r=this.m_motorImpulse-b,b=r*this.m_axis.x,k=r*this.m_axis.y,m=r*this.m_a1,r*=this.m_a2,n.x-=this.m_invMassA*b,n.y-=this.m_invMassA*
k,j-=this.m_invIA*m,l.x+=this.m_invMassB*b,l.y+=this.m_invMassB*k,f+=this.m_invIB*r;k=this.m_perp.x*(l.x-n.x)+this.m_perp.y*(l.y-n.y)+this.m_s2*f-this.m_s1*j;if(this.m_enableLimit&&this.m_limitState!=s.e_inactiveLimit){m=this.m_axis.x*(l.x-n.x)+this.m_axis.y*(l.y-n.y)+this.m_a2*f-this.m_a1*j;b=this.m_impulse.Copy();a=this.m_K.Solve(new h,-k,-m);this.m_impulse.Add(a);if(this.m_limitState==s.e_atLowerLimit)this.m_impulse.y=e.Max(this.m_impulse.y,0);else if(this.m_limitState==s.e_atUpperLimit)this.m_impulse.y=
e.Min(this.m_impulse.y,0);k=-k-(this.m_impulse.y-b.y)*this.m_K.col2.x;m=0;m=this.m_K.col1.x!=0?k/this.m_K.col1.x+b.x:b.x;this.m_impulse.x=m;a.x=this.m_impulse.x-b.x;a.y=this.m_impulse.y-b.y;b=a.x*this.m_perp.x+a.y*this.m_axis.x;k=a.x*this.m_perp.y+a.y*this.m_axis.y;m=a.x*this.m_s1+a.y*this.m_a1;r=a.x*this.m_s2+a.y*this.m_a2}else a=0,a=this.m_K.col1.x!=0?-k/this.m_K.col1.x:0,this.m_impulse.x+=a,b=a*this.m_perp.x,k=a*this.m_perp.y,m=a*this.m_s1,r=a*this.m_s2;n.x-=this.m_invMassA*b;n.y-=this.m_invMassA*
k;j-=this.m_invIA*m;l.x+=this.m_invMassB*b;l.y+=this.m_invMassB*k;f+=this.m_invIB*r;c.m_linearVelocity.SetV(n);c.m_angularVelocity=j;d.m_linearVelocity.SetV(l);d.m_angularVelocity=f};d.prototype.SolvePositionConstraints=function(){var a=this.m_bodyA,c=this.m_bodyB,d=a.m_sweep.c,n=a.m_sweep.a,j=c.m_sweep.c,l=c.m_sweep.a,f,b=0,k=0,u=0,q=0,p=f=0,s=0,k=!1,w=0,v=r.FromAngle(n),u=r.FromAngle(l);f=v;var s=this.m_localAnchor1.x-this.m_localCenterA.x,x=this.m_localAnchor1.y-this.m_localCenterA.y,b=f.col1.x*
s+f.col2.x*x,x=f.col1.y*s+f.col2.y*x,s=b;f=u;u=this.m_localAnchor2.x-this.m_localCenterB.x;q=this.m_localAnchor2.y-this.m_localCenterB.y;b=f.col1.x*u+f.col2.x*q;q=f.col1.y*u+f.col2.y*q;u=b;f=j.x+u-d.x-s;b=j.y+q-d.y-x;if(this.m_enableLimit){this.m_axis=e.MulMV(v,this.m_localXAxis1);this.m_a1=(f+s)*this.m_axis.y-(b+x)*this.m_axis.x;this.m_a2=u*this.m_axis.y-q*this.m_axis.x;var y=this.m_axis.x*f+this.m_axis.y*b;e.Abs(this.m_upperTranslation-this.m_lowerTranslation)<2*m.b2_linearSlop?(w=e.Clamp(y,-m.b2_maxLinearCorrection,
m.b2_maxLinearCorrection),p=e.Abs(y),k=!0):y<=this.m_lowerTranslation?(w=e.Clamp(y-this.m_lowerTranslation+m.b2_linearSlop,-m.b2_maxLinearCorrection,0),p=this.m_lowerTranslation-y,k=!0):y>=this.m_upperTranslation&&(w=e.Clamp(y-this.m_upperTranslation+m.b2_linearSlop,0,m.b2_maxLinearCorrection),p=y-this.m_upperTranslation,k=!0)}this.m_perp=e.MulMV(v,this.m_localYAxis1);this.m_s1=(f+s)*this.m_perp.y-(b+x)*this.m_perp.x;this.m_s2=u*this.m_perp.y-q*this.m_perp.x;v=new h;x=this.m_perp.x*f+this.m_perp.y*
b;p=e.Max(p,e.Abs(x));s=0;k?(k=this.m_invMassA,u=this.m_invMassB,q=this.m_invIA,f=this.m_invIB,this.m_K.col1.x=k+u+q*this.m_s1*this.m_s1+f*this.m_s2*this.m_s2,this.m_K.col1.y=q*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=k+u+q*this.m_a1*this.m_a1+f*this.m_a2*this.m_a2,this.m_K.Solve(v,-x,-w)):(k=this.m_invMassA,u=this.m_invMassB,q=this.m_invIA,f=this.m_invIB,w=k+u+q*this.m_s1*this.m_s1+f*this.m_s2*this.m_s2,k=0,v.x=w!=0?-x/w:0,v.y=0);w=v.x*this.m_perp.x+
v.y*this.m_axis.x;k=v.x*this.m_perp.y+v.y*this.m_axis.y;x=v.x*this.m_s1+v.y*this.m_a1;v=v.x*this.m_s2+v.y*this.m_a2;d.x-=this.m_invMassA*w;d.y-=this.m_invMassA*k;n-=this.m_invIA*x;j.x+=this.m_invMassB*w;j.y+=this.m_invMassB*k;l+=this.m_invIB*v;a.m_sweep.a=n;c.m_sweep.a=l;a.SynchronizeTransform();c.SynchronizeTransform();return p<=m.b2_linearSlop&&s<=m.b2_angularSlop};Box2D.inherit(x,Box2D.Dynamics.Joints.b2JointDef);x.prototype.__super=Box2D.Dynamics.Joints.b2JointDef.prototype;x.b2LineJointDef=function(){Box2D.Dynamics.Joints.b2JointDef.b2JointDef.apply(this,
arguments);this.localAnchorA=new h;this.localAnchorB=new h;this.localAxisA=new h};x.prototype.b2LineJointDef=function(){this.__super.b2JointDef.call(this);this.type=s.e_lineJoint;this.localAxisA.Set(1,0);this.enableLimit=!1;this.upperTranslation=this.lowerTranslation=0;this.enableMotor=!1;this.motorSpeed=this.maxMotorForce=0};x.prototype.Initialize=function(a,c,e,d){this.bodyA=a;this.bodyB=c;this.localAnchorA=this.bodyA.GetLocalPoint(e);this.localAnchorB=this.bodyB.GetLocalPoint(e);this.localAxisA=
this.bodyA.GetLocalVector(d)};Box2D.inherit(j,Box2D.Dynamics.Joints.b2Joint);j.prototype.__super=Box2D.Dynamics.Joints.b2Joint.prototype;j.b2MouseJoint=function(){Box2D.Dynamics.Joints.b2Joint.b2Joint.apply(this,arguments);this.K=new r;this.K1=new r;this.K2=new r;this.m_localAnchor=new h;this.m_target=new h;this.m_impulse=new h;this.m_mass=new r;this.m_C=new h};j.prototype.GetAnchorA=function(){return this.m_target};j.prototype.GetAnchorB=function(){return this.m_bodyB.GetWorldPoint(this.m_localAnchor)};
j.prototype.GetReactionForce=function(a){a===void 0&&(a=0);return new h(a*this.m_impulse.x,a*this.m_impulse.y)};j.prototype.GetReactionTorque=function(){return 0};j.prototype.GetTarget=function(){return this.m_target};j.prototype.SetTarget=function(a){this.m_bodyB.IsAwake()==!1&&this.m_bodyB.SetAwake(!0);this.m_target=a};j.prototype.GetMaxForce=function(){return this.m_maxForce};j.prototype.SetMaxForce=function(a){a===void 0&&(a=0);this.m_maxForce=a};j.prototype.GetFrequency=function(){return this.m_frequencyHz};
j.prototype.SetFrequency=function(a){a===void 0&&(a=0);this.m_frequencyHz=a};j.prototype.GetDampingRatio=function(){return this.m_dampingRatio};j.prototype.SetDampingRatio=function(a){a===void 0&&(a=0);this.m_dampingRatio=a};j.prototype.b2MouseJoint=function(a){this.__super.b2Joint.call(this,a);this.m_target.SetV(a.target);var c=this.m_target.x-this.m_bodyB.m_xf.position.x,e=this.m_target.y-this.m_bodyB.m_xf.position.y,d=this.m_bodyB.m_xf.R;this.m_localAnchor.x=c*d.col1.x+e*d.col1.y;this.m_localAnchor.y=
c*d.col2.x+e*d.col2.y;this.m_maxForce=a.maxForce;this.m_impulse.SetZero();this.m_frequencyHz=a.frequencyHz;this.m_dampingRatio=a.dampingRatio;this.m_gamma=this.m_beta=0};j.prototype.InitVelocityConstraints=function(a){var c=this.m_bodyB,e=c.GetMass(),d=2*Math.PI*this.m_frequencyHz,h=e*d*d;this.m_gamma=a.dt*(2*e*this.m_dampingRatio*d+a.dt*h);this.m_gamma=this.m_gamma!=0?1/this.m_gamma:0;this.m_beta=a.dt*h*this.m_gamma;var h=c.m_xf.R,e=this.m_localAnchor.x-c.m_sweep.localCenter.x,d=this.m_localAnchor.y-
c.m_sweep.localCenter.y,j=h.col1.x*e+h.col2.x*d,d=h.col1.y*e+h.col2.y*d,e=j,h=c.m_invMass,j=c.m_invI;this.K1.col1.x=h;this.K1.col2.x=0;this.K1.col1.y=0;this.K1.col2.y=h;this.K2.col1.x=j*d*d;this.K2.col2.x=-j*e*d;this.K2.col1.y=-j*e*d;this.K2.col2.y=j*e*e;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=c.m_sweep.c.x+e-this.m_target.x;this.m_C.y=c.m_sweep.c.y+d-this.m_target.y;c.m_angularVelocity*=0.98;this.m_impulse.x*=
a.dtRatio;this.m_impulse.y*=a.dtRatio;c.m_linearVelocity.x+=h*this.m_impulse.x;c.m_linearVelocity.y+=h*this.m_impulse.y;c.m_angularVelocity+=j*(e*this.m_impulse.y-d*this.m_impulse.x)};j.prototype.SolveVelocityConstraints=function(a){var c=this.m_bodyB,e,d=0,h=0;e=c.m_xf.R;var j=this.m_localAnchor.x-c.m_sweep.localCenter.x,f=this.m_localAnchor.y-c.m_sweep.localCenter.y,d=e.col1.x*j+e.col2.x*f,f=e.col1.y*j+e.col2.y*f,j=d,d=c.m_linearVelocity.x+-c.m_angularVelocity*f,b=c.m_linearVelocity.y+c.m_angularVelocity*
j;e=this.m_mass;d=d+this.m_beta*this.m_C.x+this.m_gamma*this.m_impulse.x;h=b+this.m_beta*this.m_C.y+this.m_gamma*this.m_impulse.y;b=-(e.col1.x*d+e.col2.x*h);h=-(e.col1.y*d+e.col2.y*h);e=this.m_impulse.x;d=this.m_impulse.y;this.m_impulse.x+=b;this.m_impulse.y+=h;a=a.dt*this.m_maxForce;this.m_impulse.LengthSquared()>a*a&&this.m_impulse.Multiply(a/this.m_impulse.Length());b=this.m_impulse.x-e;h=this.m_impulse.y-d;c.m_linearVelocity.x+=c.m_invMass*b;c.m_linearVelocity.y+=c.m_invMass*h;c.m_angularVelocity+=
c.m_invI*(j*h-f*b)};j.prototype.SolvePositionConstraints=function(){return!0};Box2D.inherit(B,Box2D.Dynamics.Joints.b2JointDef);B.prototype.__super=Box2D.Dynamics.Joints.b2JointDef.prototype;B.b2MouseJointDef=function(){Box2D.Dynamics.Joints.b2JointDef.b2JointDef.apply(this,arguments);this.target=new h};B.prototype.b2MouseJointDef=function(){this.__super.b2JointDef.call(this);this.type=s.e_mouseJoint;this.maxForce=0;this.frequencyHz=5;this.dampingRatio=0.7};Box2D.inherit(E,Box2D.Dynamics.Joints.b2Joint);
E.prototype.__super=Box2D.Dynamics.Joints.b2Joint.prototype;E.b2PrismaticJoint=function(){Box2D.Dynamics.Joints.b2Joint.b2Joint.apply(this,arguments);this.m_localAnchor1=new h;this.m_localAnchor2=new h;this.m_localXAxis1=new h;this.m_localYAxis1=new h;this.m_axis=new h;this.m_perp=new h;this.m_K=new q;this.m_impulse=new l};E.prototype.GetAnchorA=function(){return this.m_bodyA.GetWorldPoint(this.m_localAnchor1)};E.prototype.GetAnchorB=function(){return this.m_bodyB.GetWorldPoint(this.m_localAnchor2)};
E.prototype.GetReactionForce=function(a){a===void 0&&(a=0);return new h(a*(this.m_impulse.x*this.m_perp.x+(this.m_motorImpulse+this.m_impulse.z)*this.m_axis.x),a*(this.m_impulse.x*this.m_perp.y+(this.m_motorImpulse+this.m_impulse.z)*this.m_axis.y))};E.prototype.GetReactionTorque=function(a){a===void 0&&(a=0);return a*this.m_impulse.y};E.prototype.GetJointTranslation=function(){var a=this.m_bodyA,c=this.m_bodyB,e=a.GetWorldPoint(this.m_localAnchor1),d=c.GetWorldPoint(this.m_localAnchor2),c=d.x-e.x,
e=d.y-e.y,a=a.GetWorldVector(this.m_localXAxis1);return a.x*c+a.y*e};E.prototype.GetJointSpeed=function(){var a=this.m_bodyA,c=this.m_bodyB,e;e=a.m_xf.R;var d=this.m_localAnchor1.x-a.m_sweep.localCenter.x,h=this.m_localAnchor1.y-a.m_sweep.localCenter.y,j=e.col1.x*d+e.col2.x*h,h=e.col1.y*d+e.col2.y*h,d=j;e=c.m_xf.R;var f=this.m_localAnchor2.x-c.m_sweep.localCenter.x,b=this.m_localAnchor2.y-c.m_sweep.localCenter.y,j=e.col1.x*f+e.col2.x*b,b=e.col1.y*f+e.col2.y*b,f=j;e=c.m_sweep.c.x+f-(a.m_sweep.c.x+
d);var j=c.m_sweep.c.y+b-(a.m_sweep.c.y+h),k=a.GetWorldVector(this.m_localXAxis1),l=a.m_linearVelocity,m=c.m_linearVelocity,a=a.m_angularVelocity,c=c.m_angularVelocity;return e*-a*k.y+j*a*k.x+(k.x*(m.x+-c*b-l.x- -a*h)+k.y*(m.y+c*f-l.y-a*d))};E.prototype.IsLimitEnabled=function(){return this.m_enableLimit};E.prototype.EnableLimit=function(a){this.m_bodyA.SetAwake(!0);this.m_bodyB.SetAwake(!0);this.m_enableLimit=a};E.prototype.GetLowerLimit=function(){return this.m_lowerTranslation};E.prototype.GetUpperLimit=
function(){return this.m_upperTranslation};E.prototype.SetLimits=function(a,c){a===void 0&&(a=0);c===void 0&&(c=0);this.m_bodyA.SetAwake(!0);this.m_bodyB.SetAwake(!0);this.m_lowerTranslation=a;this.m_upperTranslation=c};E.prototype.IsMotorEnabled=function(){return this.m_enableMotor};E.prototype.EnableMotor=function(a){this.m_bodyA.SetAwake(!0);this.m_bodyB.SetAwake(!0);this.m_enableMotor=a};E.prototype.SetMotorSpeed=function(a){a===void 0&&(a=0);this.m_bodyA.SetAwake(!0);this.m_bodyB.SetAwake(!0);
this.m_motorSpeed=a};E.prototype.GetMotorSpeed=function(){return this.m_motorSpeed};E.prototype.SetMaxMotorForce=function(a){a===void 0&&(a=0);this.m_bodyA.SetAwake(!0);this.m_bodyB.SetAwake(!0);this.m_maxMotorForce=a};E.prototype.GetMotorForce=function(){return this.m_motorImpulse};E.prototype.b2PrismaticJoint=function(a){this.__super.b2Joint.call(this,a);this.m_localAnchor1.SetV(a.localAnchorA);this.m_localAnchor2.SetV(a.localAnchorB);this.m_localXAxis1.SetV(a.localAxisA);this.m_localYAxis1.x=-this.m_localXAxis1.y;
this.m_localYAxis1.y=this.m_localXAxis1.x;this.m_refAngle=a.referenceAngle;this.m_impulse.SetZero();this.m_motorImpulse=this.m_motorMass=0;this.m_lowerTranslation=a.lowerTranslation;this.m_upperTranslation=a.upperTranslation;this.m_maxMotorForce=a.maxMotorForce;this.m_motorSpeed=a.motorSpeed;this.m_enableLimit=a.enableLimit;this.m_enableMotor=a.enableMotor;this.m_limitState=s.e_inactiveLimit;this.m_axis.SetZero();this.m_perp.SetZero()};E.prototype.InitVelocityConstraints=function(a){var c=this.m_bodyA,
d=this.m_bodyB,h,j=0;this.m_localCenterA.SetV(c.GetLocalCenter());this.m_localCenterB.SetV(d.GetLocalCenter());var l=c.GetTransform();d.GetTransform();h=c.m_xf.R;var f=this.m_localAnchor1.x-this.m_localCenterA.x,b=this.m_localAnchor1.y-this.m_localCenterA.y,j=h.col1.x*f+h.col2.x*b,b=h.col1.y*f+h.col2.y*b,f=j;h=d.m_xf.R;var k=this.m_localAnchor2.x-this.m_localCenterB.x,u=this.m_localAnchor2.y-this.m_localCenterB.y,j=h.col1.x*k+h.col2.x*u,u=h.col1.y*k+h.col2.y*u,k=j;h=d.m_sweep.c.x+k-c.m_sweep.c.x-
f;j=d.m_sweep.c.y+u-c.m_sweep.c.y-b;this.m_invMassA=c.m_invMass;this.m_invMassB=d.m_invMass;this.m_invIA=c.m_invI;this.m_invIB=d.m_invI;this.m_axis.SetV(e.MulMV(l.R,this.m_localXAxis1));this.m_a1=(h+f)*this.m_axis.y-(j+b)*this.m_axis.x;this.m_a2=k*this.m_axis.y-u*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;if(this.m_motorMass>Number.MIN_VALUE)this.m_motorMass=1/this.m_motorMass;this.m_perp.SetV(e.MulMV(l.R,this.m_localYAxis1));
this.m_s1=(h+f)*this.m_perp.y-(j+b)*this.m_perp.x;this.m_s2=k*this.m_perp.y-u*this.m_perp.x;l=this.m_invMassA;f=this.m_invMassB;b=this.m_invIA;k=this.m_invIB;this.m_K.col1.x=l+f+b*this.m_s1*this.m_s1+k*this.m_s2*this.m_s2;this.m_K.col1.y=b*this.m_s1+k*this.m_s2;this.m_K.col1.z=b*this.m_s1*this.m_a1+k*this.m_s2*this.m_a2;this.m_K.col2.x=this.m_K.col1.y;this.m_K.col2.y=b+k;this.m_K.col2.z=b*this.m_a1+k*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=l+f+b*this.m_a1*
this.m_a1+k*this.m_a2*this.m_a2;if(this.m_enableLimit)if(h=this.m_axis.x*h+this.m_axis.y*j,e.Abs(this.m_upperTranslation-this.m_lowerTranslation)<2*m.b2_linearSlop)this.m_limitState=s.e_equalLimits;else if(h<=this.m_lowerTranslation){if(this.m_limitState!=s.e_atLowerLimit)this.m_limitState=s.e_atLowerLimit,this.m_impulse.z=0}else if(h>=this.m_upperTranslation){if(this.m_limitState!=s.e_atUpperLimit)this.m_limitState=s.e_atUpperLimit,this.m_impulse.z=0}else this.m_limitState=s.e_inactiveLimit,this.m_impulse.z=
0;else this.m_limitState=s.e_inactiveLimit;if(this.m_enableMotor==!1)this.m_motorImpulse=0;a.warmStarting?(this.m_impulse.x*=a.dtRatio,this.m_impulse.y*=a.dtRatio,this.m_motorImpulse*=a.dtRatio,a=this.m_impulse.x*this.m_perp.x+(this.m_motorImpulse+this.m_impulse.z)*this.m_axis.x,h=this.m_impulse.x*this.m_perp.y+(this.m_motorImpulse+this.m_impulse.z)*this.m_axis.y,j=this.m_impulse.x*this.m_s1+this.m_impulse.y+(this.m_motorImpulse+this.m_impulse.z)*this.m_a1,l=this.m_impulse.x*this.m_s2+this.m_impulse.y+
(this.m_motorImpulse+this.m_impulse.z)*this.m_a2,c.m_linearVelocity.x-=this.m_invMassA*a,c.m_linearVelocity.y-=this.m_invMassA*h,c.m_angularVelocity-=this.m_invIA*j,d.m_linearVelocity.x+=this.m_invMassB*a,d.m_linearVelocity.y+=this.m_invMassB*h,d.m_angularVelocity+=this.m_invIB*l):(this.m_impulse.SetZero(),this.m_motorImpulse=0)};E.prototype.SolveVelocityConstraints=function(a){var c=this.m_bodyA,d=this.m_bodyB,n=c.m_linearVelocity,j=c.m_angularVelocity,m=d.m_linearVelocity,f=d.m_angularVelocity,
b=0,k=0,u=0,r=0;if(this.m_enableMotor&&this.m_limitState!=s.e_equalLimits)r=this.m_motorMass*(this.m_motorSpeed-(this.m_axis.x*(m.x-n.x)+this.m_axis.y*(m.y-n.y)+this.m_a2*f-this.m_a1*j)),b=this.m_motorImpulse,a=a.dt*this.m_maxMotorForce,this.m_motorImpulse=e.Clamp(this.m_motorImpulse+r,-a,a),r=this.m_motorImpulse-b,b=r*this.m_axis.x,k=r*this.m_axis.y,u=r*this.m_a1,r*=this.m_a2,n.x-=this.m_invMassA*b,n.y-=this.m_invMassA*k,j-=this.m_invIA*u,m.x+=this.m_invMassB*b,m.y+=this.m_invMassB*k,f+=this.m_invIB*
r;u=this.m_perp.x*(m.x-n.x)+this.m_perp.y*(m.y-n.y)+this.m_s2*f-this.m_s1*j;k=f-j;if(this.m_enableLimit&&this.m_limitState!=s.e_inactiveLimit){a=this.m_axis.x*(m.x-n.x)+this.m_axis.y*(m.y-n.y)+this.m_a2*f-this.m_a1*j;b=this.m_impulse.Copy();a=this.m_K.Solve33(new l,-u,-k,-a);this.m_impulse.Add(a);if(this.m_limitState==s.e_atLowerLimit)this.m_impulse.z=e.Max(this.m_impulse.z,0);else if(this.m_limitState==s.e_atUpperLimit)this.m_impulse.z=e.Min(this.m_impulse.z,0);u=-u-(this.m_impulse.z-b.z)*this.m_K.col3.x;
k=-k-(this.m_impulse.z-b.z)*this.m_K.col3.y;k=this.m_K.Solve22(new h,u,k);k.x+=b.x;k.y+=b.y;this.m_impulse.x=k.x;this.m_impulse.y=k.y;a.x=this.m_impulse.x-b.x;a.y=this.m_impulse.y-b.y;a.z=this.m_impulse.z-b.z;b=a.x*this.m_perp.x+a.z*this.m_axis.x;k=a.x*this.m_perp.y+a.z*this.m_axis.y;u=a.x*this.m_s1+a.y+a.z*this.m_a1;r=a.x*this.m_s2+a.y+a.z*this.m_a2}else a=this.m_K.Solve22(new h,-u,-k),this.m_impulse.x+=a.x,this.m_impulse.y+=a.y,b=a.x*this.m_perp.x,k=a.x*this.m_perp.y,u=a.x*this.m_s1+a.y,r=a.x*this.m_s2+
a.y;n.x-=this.m_invMassA*b;n.y-=this.m_invMassA*k;j-=this.m_invIA*u;m.x+=this.m_invMassB*b;m.y+=this.m_invMassB*k;f+=this.m_invIB*r;c.m_linearVelocity.SetV(n);c.m_angularVelocity=j;d.m_linearVelocity.SetV(m);d.m_angularVelocity=f};E.prototype.SolvePositionConstraints=function(){var a=this.m_bodyA,c=this.m_bodyB,d=a.m_sweep.c,n=a.m_sweep.a,j=c.m_sweep.c,q=c.m_sweep.a,f,b=0,k=0,u=0,p=b=f=0,s=0,k=!1,v=0,w=r.FromAngle(n),x=r.FromAngle(q);f=w;var s=this.m_localAnchor1.x-this.m_localCenterA.x,y=this.m_localAnchor1.y-
this.m_localCenterA.y,b=f.col1.x*s+f.col2.x*y,y=f.col1.y*s+f.col2.y*y,s=b;f=x;x=this.m_localAnchor2.x-this.m_localCenterB.x;u=this.m_localAnchor2.y-this.m_localCenterB.y;b=f.col1.x*x+f.col2.x*u;u=f.col1.y*x+f.col2.y*u;x=b;f=j.x+x-d.x-s;b=j.y+u-d.y-y;if(this.m_enableLimit){this.m_axis=e.MulMV(w,this.m_localXAxis1);this.m_a1=(f+s)*this.m_axis.y-(b+y)*this.m_axis.x;this.m_a2=x*this.m_axis.y-u*this.m_axis.x;var A=this.m_axis.x*f+this.m_axis.y*b;e.Abs(this.m_upperTranslation-this.m_lowerTranslation)<2*
m.b2_linearSlop?(v=e.Clamp(A,-m.b2_maxLinearCorrection,m.b2_maxLinearCorrection),p=e.Abs(A),k=!0):A<=this.m_lowerTranslation?(v=e.Clamp(A-this.m_lowerTranslation+m.b2_linearSlop,-m.b2_maxLinearCorrection,0),p=this.m_lowerTranslation-A,k=!0):A>=this.m_upperTranslation&&(v=e.Clamp(A-this.m_upperTranslation+m.b2_linearSlop,0,m.b2_maxLinearCorrection),p=A-this.m_upperTranslation,k=!0)}this.m_perp=e.MulMV(w,this.m_localYAxis1);this.m_s1=(f+s)*this.m_perp.y-(b+y)*this.m_perp.x;this.m_s2=x*this.m_perp.y-
u*this.m_perp.x;w=new l;y=this.m_perp.x*f+this.m_perp.y*b;x=q-n-this.m_refAngle;p=e.Max(p,e.Abs(y));s=e.Abs(x);k?(k=this.m_invMassA,u=this.m_invMassB,f=this.m_invIA,b=this.m_invIB,this.m_K.col1.x=k+u+f*this.m_s1*this.m_s1+b*this.m_s2*this.m_s2,this.m_K.col1.y=f*this.m_s1+b*this.m_s2,this.m_K.col1.z=f*this.m_s1*this.m_a1+b*this.m_s2*this.m_a2,this.m_K.col2.x=this.m_K.col1.y,this.m_K.col2.y=f+b,this.m_K.col2.z=f*this.m_a1+b*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=
k+u+f*this.m_a1*this.m_a1+b*this.m_a2*this.m_a2,this.m_K.Solve33(w,-y,-x,-v)):(k=this.m_invMassA,u=this.m_invMassB,f=this.m_invIA,b=this.m_invIB,v=f*this.m_s1+b*this.m_s2,A=f+b,this.m_K.col1.Set(k+u+f*this.m_s1*this.m_s1+b*this.m_s2*this.m_s2,v,0),this.m_K.col2.Set(v,A,0),v=this.m_K.Solve22(new h,-y,-x),w.x=v.x,w.y=v.y,w.z=0);v=w.x*this.m_perp.x+w.z*this.m_axis.x;k=w.x*this.m_perp.y+w.z*this.m_axis.y;y=w.x*this.m_s1+w.y+w.z*this.m_a1;w=w.x*this.m_s2+w.y+w.z*this.m_a2;d.x-=this.m_invMassA*v;d.y-=this.m_invMassA*
k;n-=this.m_invIA*y;j.x+=this.m_invMassB*v;j.y+=this.m_invMassB*k;q+=this.m_invIB*w;a.m_sweep.a=n;c.m_sweep.a=q;a.SynchronizeTransform();c.SynchronizeTransform();return p<=m.b2_linearSlop&&s<=m.b2_angularSlop};Box2D.inherit(G,Box2D.Dynamics.Joints.b2JointDef);G.prototype.__super=Box2D.Dynamics.Joints.b2JointDef.prototype;G.b2PrismaticJointDef=function(){Box2D.Dynamics.Joints.b2JointDef.b2JointDef.apply(this,arguments);this.localAnchorA=new h;this.localAnchorB=new h;this.localAxisA=new h};G.prototype.b2PrismaticJointDef=
function(){this.__super.b2JointDef.call(this);this.type=s.e_prismaticJoint;this.localAxisA.Set(1,0);this.referenceAngle=0;this.enableLimit=!1;this.upperTranslation=this.lowerTranslation=0;this.enableMotor=!1;this.motorSpeed=this.maxMotorForce=0};G.prototype.Initialize=function(a,c,e,d){this.bodyA=a;this.bodyB=c;this.localAnchorA=this.bodyA.GetLocalPoint(e);this.localAnchorB=this.bodyB.GetLocalPoint(e);this.localAxisA=this.bodyA.GetLocalVector(d);this.referenceAngle=this.bodyB.GetAngle()-this.bodyA.GetAngle()};
Box2D.inherit(A,Box2D.Dynamics.Joints.b2Joint);A.prototype.__super=Box2D.Dynamics.Joints.b2Joint.prototype;A.b2PulleyJoint=function(){Box2D.Dynamics.Joints.b2Joint.b2Joint.apply(this,arguments);this.m_groundAnchor1=new h;this.m_groundAnchor2=new h;this.m_localAnchor1=new h;this.m_localAnchor2=new h;this.m_u1=new h;this.m_u2=new h};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(a){a===void 0&&(a=0);return new h(a*this.m_impulse*this.m_u2.x,a*this.m_impulse*this.m_u2.y)};A.prototype.GetReactionTorque=function(){return 0};A.prototype.GetGroundAnchorA=function(){var a=this.m_ground.m_xf.position.Copy();a.Add(this.m_groundAnchor1);return a};A.prototype.GetGroundAnchorB=function(){var a=this.m_ground.m_xf.position.Copy();a.Add(this.m_groundAnchor2);return a};A.prototype.GetLength1=function(){var a=this.m_bodyA.GetWorldPoint(this.m_localAnchor1),
c=a.x-(this.m_ground.m_xf.position.x+this.m_groundAnchor1.x),a=a.y-(this.m_ground.m_xf.position.y+this.m_groundAnchor1.y);return Math.sqrt(c*c+a*a)};A.prototype.GetLength2=function(){var a=this.m_bodyB.GetWorldPoint(this.m_localAnchor2),c=a.x-(this.m_ground.m_xf.position.x+this.m_groundAnchor2.x),a=a.y-(this.m_ground.m_xf.position.y+this.m_groundAnchor2.y);return Math.sqrt(c*c+a*a)};A.prototype.GetRatio=function(){return this.m_ratio};A.prototype.b2PulleyJoint=function(a){this.__super.b2Joint.call(this,
a);this.m_ground=this.m_bodyA.m_world.m_groundBody;this.m_groundAnchor1.x=a.groundAnchorA.x-this.m_ground.m_xf.position.x;this.m_groundAnchor1.y=a.groundAnchorA.y-this.m_ground.m_xf.position.y;this.m_groundAnchor2.x=a.groundAnchorB.x-this.m_ground.m_xf.position.x;this.m_groundAnchor2.y=a.groundAnchorB.y-this.m_ground.m_xf.position.y;this.m_localAnchor1.SetV(a.localAnchorA);this.m_localAnchor2.SetV(a.localAnchorB);this.m_ratio=a.ratio;this.m_constant=a.lengthA+this.m_ratio*a.lengthB;this.m_maxLength1=
e.Min(a.maxLengthA,this.m_constant-this.m_ratio*A.b2_minPulleyLength);this.m_maxLength2=e.Min(a.maxLengthB,(this.m_constant-A.b2_minPulleyLength)/this.m_ratio);this.m_limitImpulse2=this.m_limitImpulse1=this.m_impulse=0};A.prototype.InitVelocityConstraints=function(a){var c=this.m_bodyA,e=this.m_bodyB,d;d=c.m_xf.R;var h=this.m_localAnchor1.x-c.m_sweep.localCenter.x,j=this.m_localAnchor1.y-c.m_sweep.localCenter.y,f=d.col1.x*h+d.col2.x*j,j=d.col1.y*h+d.col2.y*j,h=f;d=e.m_xf.R;var b=this.m_localAnchor2.x-
e.m_sweep.localCenter.x,k=this.m_localAnchor2.y-e.m_sweep.localCenter.y,f=d.col1.x*b+d.col2.x*k,k=d.col1.y*b+d.col2.y*k,b=f;d=e.m_sweep.c.x+b;var f=e.m_sweep.c.y+k,l=this.m_ground.m_xf.position.x+this.m_groundAnchor2.x,r=this.m_ground.m_xf.position.y+this.m_groundAnchor2.y;this.m_u1.Set(c.m_sweep.c.x+h-(this.m_ground.m_xf.position.x+this.m_groundAnchor1.x),c.m_sweep.c.y+j-(this.m_ground.m_xf.position.y+this.m_groundAnchor1.y));this.m_u2.Set(d-l,f-r);d=this.m_u1.Length();f=this.m_u2.Length();d>m.b2_linearSlop?
this.m_u1.Multiply(1/d):this.m_u1.SetZero();f>m.b2_linearSlop?this.m_u2.Multiply(1/f):this.m_u2.SetZero();this.m_constant-d-this.m_ratio*f>0?(this.m_state=s.e_inactiveLimit,this.m_impulse=0):this.m_state=s.e_atUpperLimit;d<this.m_maxLength1?(this.m_limitState1=s.e_inactiveLimit,this.m_limitImpulse1=0):this.m_limitState1=s.e_atUpperLimit;f<this.m_maxLength2?(this.m_limitState2=s.e_inactiveLimit,this.m_limitImpulse2=0):this.m_limitState2=s.e_atUpperLimit;d=h*this.m_u1.y-j*this.m_u1.x;f=b*this.m_u2.y-
k*this.m_u2.x;this.m_limitMass1=c.m_invMass+c.m_invI*d*d;this.m_limitMass2=e.m_invMass+e.m_invI*f*f;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;a.warmStarting?(this.m_impulse*=a.dtRatio,this.m_limitImpulse1*=a.dtRatio,this.m_limitImpulse2*=a.dtRatio,a=(-this.m_impulse-this.m_limitImpulse1)*this.m_u1.x,d=(-this.m_impulse-this.m_limitImpulse1)*this.m_u1.y,
f=(-this.m_ratio*this.m_impulse-this.m_limitImpulse2)*this.m_u2.x,l=(-this.m_ratio*this.m_impulse-this.m_limitImpulse2)*this.m_u2.y,c.m_linearVelocity.x+=c.m_invMass*a,c.m_linearVelocity.y+=c.m_invMass*d,c.m_angularVelocity+=c.m_invI*(h*d-j*a),e.m_linearVelocity.x+=e.m_invMass*f,e.m_linearVelocity.y+=e.m_invMass*l,e.m_angularVelocity+=e.m_invI*(b*l-k*f)):this.m_limitImpulse2=this.m_limitImpulse1=this.m_impulse=0};A.prototype.SolveVelocityConstraints=function(){var a=this.m_bodyA,c=this.m_bodyB,d;
d=a.m_xf.R;var h=this.m_localAnchor1.x-a.m_sweep.localCenter.x,j=this.m_localAnchor1.y-a.m_sweep.localCenter.y,l=d.col1.x*h+d.col2.x*j,j=d.col1.y*h+d.col2.y*j,h=l;d=c.m_xf.R;var f=this.m_localAnchor2.x-c.m_sweep.localCenter.x,b=this.m_localAnchor2.y-c.m_sweep.localCenter.y,l=d.col1.x*f+d.col2.x*b,b=d.col1.y*f+d.col2.y*b,f=l,k=l=d=0,m=0;d=m=d=m=k=l=d=0;if(this.m_state==s.e_atUpperLimit)d=a.m_linearVelocity.x+-a.m_angularVelocity*j,l=a.m_linearVelocity.y+a.m_angularVelocity*h,k=c.m_linearVelocity.x+
-c.m_angularVelocity*b,m=c.m_linearVelocity.y+c.m_angularVelocity*f,d=-(this.m_u1.x*d+this.m_u1.y*l)-this.m_ratio*(this.m_u2.x*k+this.m_u2.y*m),m=this.m_pulleyMass*-d,d=this.m_impulse,this.m_impulse=e.Max(0,this.m_impulse+m),m=this.m_impulse-d,d=-m*this.m_u1.x,l=-m*this.m_u1.y,k=-this.m_ratio*m*this.m_u2.x,m=-this.m_ratio*m*this.m_u2.y,a.m_linearVelocity.x+=a.m_invMass*d,a.m_linearVelocity.y+=a.m_invMass*l,a.m_angularVelocity+=a.m_invI*(h*l-j*d),c.m_linearVelocity.x+=c.m_invMass*k,c.m_linearVelocity.y+=
c.m_invMass*m,c.m_angularVelocity+=c.m_invI*(f*m-b*k);if(this.m_limitState1==s.e_atUpperLimit)d=a.m_linearVelocity.x+-a.m_angularVelocity*j,l=a.m_linearVelocity.y+a.m_angularVelocity*h,d=-(this.m_u1.x*d+this.m_u1.y*l),m=-this.m_limitMass1*d,d=this.m_limitImpulse1,this.m_limitImpulse1=e.Max(0,this.m_limitImpulse1+m),m=this.m_limitImpulse1-d,d=-m*this.m_u1.x,l=-m*this.m_u1.y,a.m_linearVelocity.x+=a.m_invMass*d,a.m_linearVelocity.y+=a.m_invMass*l,a.m_angularVelocity+=a.m_invI*(h*l-j*d);if(this.m_limitState2==
s.e_atUpperLimit)k=c.m_linearVelocity.x+-c.m_angularVelocity*b,m=c.m_linearVelocity.y+c.m_angularVelocity*f,d=-(this.m_u2.x*k+this.m_u2.y*m),m=-this.m_limitMass2*d,d=this.m_limitImpulse2,this.m_limitImpulse2=e.Max(0,this.m_limitImpulse2+m),m=this.m_limitImpulse2-d,k=-m*this.m_u2.x,m=-m*this.m_u2.y,c.m_linearVelocity.x+=c.m_invMass*k,c.m_linearVelocity.y+=c.m_invMass*m,c.m_angularVelocity+=c.m_invI*(f*m-b*k)};A.prototype.SolvePositionConstraints=function(){var a=this.m_bodyA,c=this.m_bodyB,d,h=this.m_ground.m_xf.position.x+
this.m_groundAnchor1.x,j=this.m_ground.m_xf.position.y+this.m_groundAnchor1.y,l=this.m_ground.m_xf.position.x+this.m_groundAnchor2.x,f=this.m_ground.m_xf.position.y+this.m_groundAnchor2.y,b=0,k=0,r=0,q=0,p=d=0,w=0,v=0,x=p=v=d=p=d=0;if(this.m_state==s.e_atUpperLimit)d=a.m_xf.R,b=this.m_localAnchor1.x-a.m_sweep.localCenter.x,k=this.m_localAnchor1.y-a.m_sweep.localCenter.y,p=d.col1.x*b+d.col2.x*k,k=d.col1.y*b+d.col2.y*k,b=p,d=c.m_xf.R,r=this.m_localAnchor2.x-c.m_sweep.localCenter.x,q=this.m_localAnchor2.y-
c.m_sweep.localCenter.y,p=d.col1.x*r+d.col2.x*q,q=d.col1.y*r+d.col2.y*q,r=p,d=a.m_sweep.c.x+b,p=a.m_sweep.c.y+k,w=c.m_sweep.c.x+r,v=c.m_sweep.c.y+q,this.m_u1.Set(d-h,p-j),this.m_u2.Set(w-l,v-f),d=this.m_u1.Length(),p=this.m_u2.Length(),d>m.b2_linearSlop?this.m_u1.Multiply(1/d):this.m_u1.SetZero(),p>m.b2_linearSlop?this.m_u2.Multiply(1/p):this.m_u2.SetZero(),d=this.m_constant-d-this.m_ratio*p,x=e.Max(x,-d),d=e.Clamp(d+m.b2_linearSlop,-m.b2_maxLinearCorrection,0),v=-this.m_pulleyMass*d,d=-v*this.m_u1.x,
p=-v*this.m_u1.y,w=-this.m_ratio*v*this.m_u2.x,v=-this.m_ratio*v*this.m_u2.y,a.m_sweep.c.x+=a.m_invMass*d,a.m_sweep.c.y+=a.m_invMass*p,a.m_sweep.a+=a.m_invI*(b*p-k*d),c.m_sweep.c.x+=c.m_invMass*w,c.m_sweep.c.y+=c.m_invMass*v,c.m_sweep.a+=c.m_invI*(r*v-q*w),a.SynchronizeTransform(),c.SynchronizeTransform();if(this.m_limitState1==s.e_atUpperLimit)d=a.m_xf.R,b=this.m_localAnchor1.x-a.m_sweep.localCenter.x,k=this.m_localAnchor1.y-a.m_sweep.localCenter.y,p=d.col1.x*b+d.col2.x*k,k=d.col1.y*b+d.col2.y*k,
b=p,d=a.m_sweep.c.x+b,p=a.m_sweep.c.y+k,this.m_u1.Set(d-h,p-j),d=this.m_u1.Length(),d>m.b2_linearSlop?(this.m_u1.x*=1/d,this.m_u1.y*=1/d):this.m_u1.SetZero(),d=this.m_maxLength1-d,x=e.Max(x,-d),d=e.Clamp(d+m.b2_linearSlop,-m.b2_maxLinearCorrection,0),v=-this.m_limitMass1*d,d=-v*this.m_u1.x,p=-v*this.m_u1.y,a.m_sweep.c.x+=a.m_invMass*d,a.m_sweep.c.y+=a.m_invMass*p,a.m_sweep.a+=a.m_invI*(b*p-k*d),a.SynchronizeTransform();if(this.m_limitState2==s.e_atUpperLimit)d=c.m_xf.R,r=this.m_localAnchor2.x-c.m_sweep.localCenter.x,
q=this.m_localAnchor2.y-c.m_sweep.localCenter.y,p=d.col1.x*r+d.col2.x*q,q=d.col1.y*r+d.col2.y*q,r=p,w=c.m_sweep.c.x+r,v=c.m_sweep.c.y+q,this.m_u2.Set(w-l,v-f),p=this.m_u2.Length(),p>m.b2_linearSlop?(this.m_u2.x*=1/p,this.m_u2.y*=1/p):this.m_u2.SetZero(),d=this.m_maxLength2-p,x=e.Max(x,-d),d=e.Clamp(d+m.b2_linearSlop,-m.b2_maxLinearCorrection,0),v=-this.m_limitMass2*d,w=-v*this.m_u2.x,v=-v*this.m_u2.y,c.m_sweep.c.x+=c.m_invMass*w,c.m_sweep.c.y+=c.m_invMass*v,c.m_sweep.a+=c.m_invI*(r*v-q*w),c.SynchronizeTransform();
return x<m.b2_linearSlop};Box2D.postDefs.push(function(){Box2D.Dynamics.Joints.b2PulleyJoint.b2_minPulleyLength=2});Box2D.inherit(L,Box2D.Dynamics.Joints.b2JointDef);L.prototype.__super=Box2D.Dynamics.Joints.b2JointDef.prototype;L.b2PulleyJointDef=function(){Box2D.Dynamics.Joints.b2JointDef.b2JointDef.apply(this,arguments);this.groundAnchorA=new h;this.groundAnchorB=new h;this.localAnchorA=new h;this.localAnchorB=new h};L.prototype.b2PulleyJointDef=function(){this.__super.b2JointDef.call(this);this.type=
s.e_pulleyJoint;this.groundAnchorA.Set(-1,1);this.groundAnchorB.Set(1,1);this.localAnchorA.Set(-1,0);this.localAnchorB.Set(1,0);this.maxLengthB=this.lengthB=this.maxLengthA=this.lengthA=0;this.ratio=1;this.collideConnected=!0};L.prototype.Initialize=function(a,c,e,d,h,j,f){f===void 0&&(f=0);this.bodyA=a;this.bodyB=c;this.groundAnchorA.SetV(e);this.groundAnchorB.SetV(d);this.localAnchorA=this.bodyA.GetLocalPoint(h);this.localAnchorB=this.bodyB.GetLocalPoint(j);a=h.x-e.x;e=h.y-e.y;this.lengthA=Math.sqrt(a*
a+e*e);e=j.x-d.x;d=j.y-d.y;this.lengthB=Math.sqrt(e*e+d*d);this.ratio=f;f=this.lengthA+this.ratio*this.lengthB;this.maxLengthA=f-this.ratio*A.b2_minPulleyLength;this.maxLengthB=(f-A.b2_minPulleyLength)/this.ratio};Box2D.inherit(D,Box2D.Dynamics.Joints.b2Joint);D.prototype.__super=Box2D.Dynamics.Joints.b2Joint.prototype;D.b2RevoluteJoint=function(){Box2D.Dynamics.Joints.b2Joint.b2Joint.apply(this,arguments);this.K=new r;this.K1=new r;this.K2=new r;this.K3=new r;this.impulse3=new l;this.impulse2=new h;
this.reduced=new h;this.m_localAnchor1=new h;this.m_localAnchor2=new h;this.m_impulse=new l;this.m_mass=new q};D.prototype.GetAnchorA=function(){return this.m_bodyA.GetWorldPoint(this.m_localAnchor1)};D.prototype.GetAnchorB=function(){return this.m_bodyB.GetWorldPoint(this.m_localAnchor2)};D.prototype.GetReactionForce=function(a){a===void 0&&(a=0);return new h(a*this.m_impulse.x,a*this.m_impulse.y)};D.prototype.GetReactionTorque=function(a){a===void 0&&(a=0);return a*this.m_impulse.z};D.prototype.GetJointAngle=
function(){return this.m_bodyB.m_sweep.a-this.m_bodyA.m_sweep.a-this.m_referenceAngle};D.prototype.GetJointSpeed=function(){return this.m_bodyB.m_angularVelocity-this.m_bodyA.m_angularVelocity};D.prototype.IsLimitEnabled=function(){return this.m_enableLimit};D.prototype.EnableLimit=function(a){this.m_enableLimit=a};D.prototype.GetLowerLimit=function(){return this.m_lowerAngle};D.prototype.GetUpperLimit=function(){return this.m_upperAngle};D.prototype.SetLimits=function(a,c){a===void 0&&(a=0);c===
void 0&&(c=0);this.m_lowerAngle=a;this.m_upperAngle=c};D.prototype.IsMotorEnabled=function(){this.m_bodyA.SetAwake(!0);this.m_bodyB.SetAwake(!0);return this.m_enableMotor};D.prototype.EnableMotor=function(a){this.m_enableMotor=a};D.prototype.SetMotorSpeed=function(a){a===void 0&&(a=0);this.m_bodyA.SetAwake(!0);this.m_bodyB.SetAwake(!0);this.m_motorSpeed=a};D.prototype.GetMotorSpeed=function(){return this.m_motorSpeed};D.prototype.SetMaxMotorTorque=function(a){a===void 0&&(a=0);this.m_maxMotorTorque=
a};D.prototype.GetMotorTorque=function(){return this.m_maxMotorTorque};D.prototype.b2RevoluteJoint=function(a){this.__super.b2Joint.call(this,a);this.m_localAnchor1.SetV(a.localAnchorA);this.m_localAnchor2.SetV(a.localAnchorB);this.m_referenceAngle=a.referenceAngle;this.m_impulse.SetZero();this.m_motorImpulse=0;this.m_lowerAngle=a.lowerAngle;this.m_upperAngle=a.upperAngle;this.m_maxMotorTorque=a.maxMotorTorque;this.m_motorSpeed=a.motorSpeed;this.m_enableLimit=a.enableLimit;this.m_enableMotor=a.enableMotor;
this.m_limitState=s.e_inactiveLimit};D.prototype.InitVelocityConstraints=function(a){var c=this.m_bodyA,d=this.m_bodyB,h,j=0;h=c.m_xf.R;var l=this.m_localAnchor1.x-c.m_sweep.localCenter.x,f=this.m_localAnchor1.y-c.m_sweep.localCenter.y,j=h.col1.x*l+h.col2.x*f,f=h.col1.y*l+h.col2.y*f,l=j;h=d.m_xf.R;var b=this.m_localAnchor2.x-d.m_sweep.localCenter.x,k=this.m_localAnchor2.y-d.m_sweep.localCenter.y,j=h.col1.x*b+h.col2.x*k,k=h.col1.y*b+h.col2.y*k,b=j;h=c.m_invMass;var j=d.m_invMass,r=c.m_invI,p=d.m_invI;
this.m_mass.col1.x=h+j+f*f*r+k*k*p;this.m_mass.col2.x=-f*l*r-k*b*p;this.m_mass.col3.x=-f*r-k*p;this.m_mass.col1.y=this.m_mass.col2.x;this.m_mass.col2.y=h+j+l*l*r+b*b*p;this.m_mass.col3.y=l*r+b*p;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=r+p;this.m_motorMass=1/(r+p);if(this.m_enableMotor==!1)this.m_motorImpulse=0;if(this.m_enableLimit){var q=d.m_sweep.a-c.m_sweep.a-this.m_referenceAngle;if(e.Abs(this.m_upperAngle-this.m_lowerAngle)<2*m.b2_angularSlop)this.m_limitState=
s.e_equalLimits;else if(q<=this.m_lowerAngle){if(this.m_limitState!=s.e_atLowerLimit)this.m_impulse.z=0;this.m_limitState=s.e_atLowerLimit}else if(q>=this.m_upperAngle){if(this.m_limitState!=s.e_atUpperLimit)this.m_impulse.z=0;this.m_limitState=s.e_atUpperLimit}else this.m_limitState=s.e_inactiveLimit,this.m_impulse.z=0}else this.m_limitState=s.e_inactiveLimit;a.warmStarting?(this.m_impulse.x*=a.dtRatio,this.m_impulse.y*=a.dtRatio,this.m_motorImpulse*=a.dtRatio,a=this.m_impulse.x,q=this.m_impulse.y,
c.m_linearVelocity.x-=h*a,c.m_linearVelocity.y-=h*q,c.m_angularVelocity-=r*(l*q-f*a+this.m_motorImpulse+this.m_impulse.z),d.m_linearVelocity.x+=j*a,d.m_linearVelocity.y+=j*q,d.m_angularVelocity+=p*(b*q-k*a+this.m_motorImpulse+this.m_impulse.z)):(this.m_impulse.SetZero(),this.m_motorImpulse=0)};D.prototype.SolveVelocityConstraints=function(a){var c=this.m_bodyA,d=this.m_bodyB,h=0,j=h=0,l=0,f=0,b=0,k=c.m_linearVelocity,m=c.m_angularVelocity,r=d.m_linearVelocity,p=d.m_angularVelocity,q=c.m_invMass,v=
d.m_invMass,w=c.m_invI,x=d.m_invI;if(this.m_enableMotor&&this.m_limitState!=s.e_equalLimits)j=this.m_motorMass*-(p-m-this.m_motorSpeed),l=this.m_motorImpulse,f=a.dt*this.m_maxMotorTorque,this.m_motorImpulse=e.Clamp(this.m_motorImpulse+j,-f,f),j=this.m_motorImpulse-l,m-=w*j,p+=x*j;if(this.m_enableLimit&&this.m_limitState!=s.e_inactiveLimit){var a=c.m_xf.R,j=this.m_localAnchor1.x-c.m_sweep.localCenter.x,l=this.m_localAnchor1.y-c.m_sweep.localCenter.y,h=a.col1.x*j+a.col2.x*l,l=a.col1.y*j+a.col2.y*l,
j=h,a=d.m_xf.R,f=this.m_localAnchor2.x-d.m_sweep.localCenter.x,b=this.m_localAnchor2.y-d.m_sweep.localCenter.y,h=a.col1.x*f+a.col2.x*b,b=a.col1.y*f+a.col2.y*b,f=h,a=r.x+-p*b-k.x- -m*l,y=r.y+p*f-k.y-m*j;this.m_mass.Solve33(this.impulse3,-a,-y,-(p-m));if(this.m_limitState==s.e_equalLimits)this.m_impulse.Add(this.impulse3);else if(this.m_limitState==s.e_atLowerLimit){if(h=this.m_impulse.z+this.impulse3.z,h<0)this.m_mass.Solve22(this.reduced,-a,-y),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}else if(this.m_limitState==s.e_atUpperLimit&&(h=this.m_impulse.z+this.impulse3.z,h>0))this.m_mass.Solve22(this.reduced,-a,-y),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;k.x-=q*this.impulse3.x;k.y-=q*this.impulse3.y;m-=w*(j*this.impulse3.y-l*this.impulse3.x+
this.impulse3.z);r.x+=v*this.impulse3.x;r.y+=v*this.impulse3.y;p+=x*(f*this.impulse3.y-b*this.impulse3.x+this.impulse3.z)}else a=c.m_xf.R,j=this.m_localAnchor1.x-c.m_sweep.localCenter.x,l=this.m_localAnchor1.y-c.m_sweep.localCenter.y,h=a.col1.x*j+a.col2.x*l,l=a.col1.y*j+a.col2.y*l,j=h,a=d.m_xf.R,f=this.m_localAnchor2.x-d.m_sweep.localCenter.x,b=this.m_localAnchor2.y-d.m_sweep.localCenter.y,h=a.col1.x*f+a.col2.x*b,b=a.col1.y*f+a.col2.y*b,f=h,this.m_mass.Solve22(this.impulse2,-(r.x+-p*b-k.x- -m*l),
-(r.y+p*f-k.y-m*j)),this.m_impulse.x+=this.impulse2.x,this.m_impulse.y+=this.impulse2.y,k.x-=q*this.impulse2.x,k.y-=q*this.impulse2.y,m-=w*(j*this.impulse2.y-l*this.impulse2.x),r.x+=v*this.impulse2.x,r.y+=v*this.impulse2.y,p+=x*(f*this.impulse2.y-b*this.impulse2.x);c.m_linearVelocity.SetV(k);c.m_angularVelocity=m;d.m_linearVelocity.SetV(r);d.m_angularVelocity=p};D.prototype.SolvePositionConstraints=function(){var a=0,c,d=this.m_bodyA,h=this.m_bodyB,j=0,l=c=0,f=0,b=0;if(this.m_enableLimit&&this.m_limitState!=
s.e_inactiveLimit){var a=h.m_sweep.a-d.m_sweep.a-this.m_referenceAngle,k=0;this.m_limitState==s.e_equalLimits?(a=e.Clamp(a-this.m_lowerAngle,-m.b2_maxAngularCorrection,m.b2_maxAngularCorrection),k=-this.m_motorMass*a,j=e.Abs(a)):this.m_limitState==s.e_atLowerLimit?(a-=this.m_lowerAngle,j=-a,a=e.Clamp(a+m.b2_angularSlop,-m.b2_maxAngularCorrection,0),k=-this.m_motorMass*a):this.m_limitState==s.e_atUpperLimit&&(a-=this.m_upperAngle,j=a,a=e.Clamp(a-m.b2_angularSlop,0,m.b2_maxAngularCorrection),k=-this.m_motorMass*
a);d.m_sweep.a-=d.m_invI*k;h.m_sweep.a+=h.m_invI*k;d.SynchronizeTransform();h.SynchronizeTransform()}c=d.m_xf.R;k=this.m_localAnchor1.x-d.m_sweep.localCenter.x;a=this.m_localAnchor1.y-d.m_sweep.localCenter.y;l=c.col1.x*k+c.col2.x*a;a=c.col1.y*k+c.col2.y*a;k=l;c=h.m_xf.R;var r=this.m_localAnchor2.x-h.m_sweep.localCenter.x,p=this.m_localAnchor2.y-h.m_sweep.localCenter.y,l=c.col1.x*r+c.col2.x*p,p=c.col1.y*r+c.col2.y*p,r=l,f=h.m_sweep.c.x+r-d.m_sweep.c.x-k,b=h.m_sweep.c.y+p-d.m_sweep.c.y-a,q=f*f+b*b;
c=Math.sqrt(q);var l=d.m_invMass,v=h.m_invMass,w=d.m_invI,x=h.m_invI,y=10*m.b2_linearSlop;q>y*y&&(q=1/(l+v),f=q*-f,b=q*-b,d.m_sweep.c.x-=0.5*l*f,d.m_sweep.c.y-=0.5*l*b,h.m_sweep.c.x+=0.5*v*f,h.m_sweep.c.y+=0.5*v*b,f=h.m_sweep.c.x+r-d.m_sweep.c.x-k,b=h.m_sweep.c.y+p-d.m_sweep.c.y-a);this.K1.col1.x=l+v;this.K1.col2.x=0;this.K1.col1.y=0;this.K1.col2.y=l+v;this.K2.col1.x=w*a*a;this.K2.col2.x=-w*k*a;this.K2.col1.y=-w*k*a;this.K2.col2.y=w*k*k;this.K3.col1.x=x*p*p;this.K3.col2.x=-x*r*p;this.K3.col1.y=-x*
r*p;this.K3.col2.y=x*r*r;this.K.SetM(this.K1);this.K.AddM(this.K2);this.K.AddM(this.K3);this.K.Solve(D.tImpulse,-f,-b);f=D.tImpulse.x;b=D.tImpulse.y;d.m_sweep.c.x-=d.m_invMass*f;d.m_sweep.c.y-=d.m_invMass*b;d.m_sweep.a-=d.m_invI*(k*b-a*f);h.m_sweep.c.x+=h.m_invMass*f;h.m_sweep.c.y+=h.m_invMass*b;h.m_sweep.a+=h.m_invI*(r*b-p*f);d.SynchronizeTransform();h.SynchronizeTransform();return c<=m.b2_linearSlop&&j<=m.b2_angularSlop};Box2D.postDefs.push(function(){Box2D.Dynamics.Joints.b2RevoluteJoint.tImpulse=
new h});Box2D.inherit(F,Box2D.Dynamics.Joints.b2JointDef);F.prototype.__super=Box2D.Dynamics.Joints.b2JointDef.prototype;F.b2RevoluteJointDef=function(){Box2D.Dynamics.Joints.b2JointDef.b2JointDef.apply(this,arguments);this.localAnchorA=new h;this.localAnchorB=new h};F.prototype.b2RevoluteJointDef=function(){this.__super.b2JointDef.call(this);this.type=s.e_revoluteJoint;this.localAnchorA.Set(0,0);this.localAnchorB.Set(0,0);this.motorSpeed=this.maxMotorTorque=this.upperAngle=this.lowerAngle=this.referenceAngle=
0;this.enableMotor=this.enableLimit=!1};F.prototype.Initialize=function(a,c,d){this.bodyA=a;this.bodyB=c;this.localAnchorA=this.bodyA.GetLocalPoint(d);this.localAnchorB=this.bodyB.GetLocalPoint(d);this.referenceAngle=this.bodyB.GetAngle()-this.bodyA.GetAngle()};Box2D.inherit(M,Box2D.Dynamics.Joints.b2Joint);M.prototype.__super=Box2D.Dynamics.Joints.b2Joint.prototype;M.b2WeldJoint=function(){Box2D.Dynamics.Joints.b2Joint.b2Joint.apply(this,arguments);this.m_localAnchorA=new h;this.m_localAnchorB=new h;
this.m_impulse=new l;this.m_mass=new q};M.prototype.GetAnchorA=function(){return this.m_bodyA.GetWorldPoint(this.m_localAnchorA)};M.prototype.GetAnchorB=function(){return this.m_bodyB.GetWorldPoint(this.m_localAnchorB)};M.prototype.GetReactionForce=function(a){a===void 0&&(a=0);return new h(a*this.m_impulse.x,a*this.m_impulse.y)};M.prototype.GetReactionTorque=function(a){a===void 0&&(a=0);return a*this.m_impulse.z};M.prototype.b2WeldJoint=function(a){this.__super.b2Joint.call(this,a);this.m_localAnchorA.SetV(a.localAnchorA);
this.m_localAnchorB.SetV(a.localAnchorB);this.m_referenceAngle=a.referenceAngle;this.m_impulse.SetZero();this.m_mass=new q};M.prototype.InitVelocityConstraints=function(a){var c,d=0,e=this.m_bodyA,h=this.m_bodyB;c=e.m_xf.R;var j=this.m_localAnchorA.x-e.m_sweep.localCenter.x,f=this.m_localAnchorA.y-e.m_sweep.localCenter.y,d=c.col1.x*j+c.col2.x*f,f=c.col1.y*j+c.col2.y*f,j=d;c=h.m_xf.R;var b=this.m_localAnchorB.x-h.m_sweep.localCenter.x,k=this.m_localAnchorB.y-h.m_sweep.localCenter.y,d=c.col1.x*b+c.col2.x*
k,k=c.col1.y*b+c.col2.y*k,b=d;c=e.m_invMass;var d=h.m_invMass,l=e.m_invI,m=h.m_invI;this.m_mass.col1.x=c+d+f*f*l+k*k*m;this.m_mass.col2.x=-f*j*l-k*b*m;this.m_mass.col3.x=-f*l-k*m;this.m_mass.col1.y=this.m_mass.col2.x;this.m_mass.col2.y=c+d+j*j*l+b*b*m;this.m_mass.col3.y=j*l+b*m;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=l+m;a.warmStarting?(this.m_impulse.x*=a.dtRatio,this.m_impulse.y*=a.dtRatio,this.m_impulse.z*=a.dtRatio,e.m_linearVelocity.x-=c*
this.m_impulse.x,e.m_linearVelocity.y-=c*this.m_impulse.y,e.m_angularVelocity-=l*(j*this.m_impulse.y-f*this.m_impulse.x+this.m_impulse.z),h.m_linearVelocity.x+=d*this.m_impulse.x,h.m_linearVelocity.y+=d*this.m_impulse.y,h.m_angularVelocity+=m*(b*this.m_impulse.y-k*this.m_impulse.x+this.m_impulse.z)):this.m_impulse.SetZero()};M.prototype.SolveVelocityConstraints=function(){var a,c=0,d=this.m_bodyA,e=this.m_bodyB,h=d.m_linearVelocity,j=d.m_angularVelocity,f=e.m_linearVelocity,b=e.m_angularVelocity,
k=d.m_invMass,m=e.m_invMass,r=d.m_invI,p=e.m_invI;a=d.m_xf.R;var q=this.m_localAnchorA.x-d.m_sweep.localCenter.x,s=this.m_localAnchorA.y-d.m_sweep.localCenter.y,c=a.col1.x*q+a.col2.x*s,s=a.col1.y*q+a.col2.y*s,q=c;a=e.m_xf.R;var v=this.m_localAnchorB.x-e.m_sweep.localCenter.x,w=this.m_localAnchorB.y-e.m_sweep.localCenter.y,c=a.col1.x*v+a.col2.x*w,w=a.col1.y*v+a.col2.y*w,v=c;a=f.x-b*w-h.x+j*s;var c=f.y+b*v-h.y-j*q,x=b-j,y=new l;this.m_mass.Solve33(y,-a,-c,-x);this.m_impulse.Add(y);h.x-=k*y.x;h.y-=k*
y.y;j-=r*(q*y.y-s*y.x+y.z);f.x+=m*y.x;f.y+=m*y.y;b+=p*(v*y.y-w*y.x+y.z);d.m_angularVelocity=j;e.m_angularVelocity=b};M.prototype.SolvePositionConstraints=function(){var a,c=0,d=this.m_bodyA,h=this.m_bodyB;a=d.m_xf.R;var j=this.m_localAnchorA.x-d.m_sweep.localCenter.x,r=this.m_localAnchorA.y-d.m_sweep.localCenter.y,c=a.col1.x*j+a.col2.x*r,r=a.col1.y*j+a.col2.y*r,j=c;a=h.m_xf.R;var f=this.m_localAnchorB.x-h.m_sweep.localCenter.x,b=this.m_localAnchorB.y-h.m_sweep.localCenter.y,c=a.col1.x*f+a.col2.x*
b,b=a.col1.y*f+a.col2.y*b,f=c;a=d.m_invMass;var c=h.m_invMass,k=d.m_invI,p=h.m_invI,q=h.m_sweep.c.x+f-d.m_sweep.c.x-j,s=h.m_sweep.c.y+b-d.m_sweep.c.y-r,v=h.m_sweep.a-d.m_sweep.a-this.m_referenceAngle,w=10*m.b2_linearSlop,x=Math.sqrt(q*q+s*s),y=e.Abs(v);x>w&&(k*=1,p*=1);this.m_mass.col1.x=a+c+r*r*k+b*b*p;this.m_mass.col2.x=-r*j*k-b*f*p;this.m_mass.col3.x=-r*k-b*p;this.m_mass.col1.y=this.m_mass.col2.x;this.m_mass.col2.y=a+c+j*j*k+f*f*p;this.m_mass.col3.y=j*k+f*p;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=k+p;w=new l;this.m_mass.Solve33(w,-q,-s,-v);d.m_sweep.c.x-=a*w.x;d.m_sweep.c.y-=a*w.y;d.m_sweep.a-=k*(j*w.y-r*w.x+w.z);h.m_sweep.c.x+=c*w.x;h.m_sweep.c.y+=c*w.y;h.m_sweep.a+=p*(f*w.y-b*w.x+w.z);d.SynchronizeTransform();h.SynchronizeTransform();return x<=m.b2_linearSlop&&y<=m.b2_angularSlop};Box2D.inherit(I,Box2D.Dynamics.Joints.b2JointDef);I.prototype.__super=Box2D.Dynamics.Joints.b2JointDef.prototype;I.b2WeldJointDef=function(){Box2D.Dynamics.Joints.b2JointDef.b2JointDef.apply(this,
arguments);this.localAnchorA=new h;this.localAnchorB=new h};I.prototype.b2WeldJointDef=function(){this.__super.b2JointDef.call(this);this.type=s.e_weldJoint;this.referenceAngle=0};I.prototype.Initialize=function(a,c,d){this.bodyA=a;this.bodyB=c;this.localAnchorA.SetV(this.bodyA.GetLocalPoint(d));this.localAnchorB.SetV(this.bodyB.GetLocalPoint(d));this.referenceAngle=this.bodyB.GetAngle()-this.bodyA.GetAngle()}})();
(function(){var m=Box2D.Dynamics.b2DebugDraw;m.b2DebugDraw=function(){this.m_xformScale=this.m_fillAlpha=this.m_alpha=this.m_lineThickness=this.m_drawScale=1;var m=this;this.m_sprite={graphics:{clear:function(){m.m_ctx.clearRect(0,0,m.m_ctx.canvas.width,m.m_ctx.canvas.height)}}}};m.prototype._color=function(m,q){return"rgba("+((m&16711680)>>16)+","+((m&65280)>>8)+","+(m&255)+","+q+")"};m.prototype.b2DebugDraw=function(){this.m_drawFlags=0};m.prototype.SetFlags=function(m){m===void 0&&(m=0);this.m_drawFlags=
m};m.prototype.GetFlags=function(){return this.m_drawFlags};m.prototype.AppendFlags=function(m){m===void 0&&(m=0);this.m_drawFlags|=m};m.prototype.ClearFlags=function(m){m===void 0&&(m=0);this.m_drawFlags&=~m};m.prototype.SetSprite=function(m){this.m_ctx=m};m.prototype.GetSprite=function(){return this.m_ctx};m.prototype.SetDrawScale=function(m){m===void 0&&(m=0);this.m_drawScale=m};m.prototype.GetDrawScale=function(){return this.m_drawScale};m.prototype.SetLineThickness=function(m){m===void 0&&(m=
0);this.m_lineThickness=m;this.m_ctx.strokeWidth=m};m.prototype.GetLineThickness=function(){return this.m_lineThickness};m.prototype.SetAlpha=function(m){m===void 0&&(m=0);this.m_alpha=m};m.prototype.GetAlpha=function(){return this.m_alpha};m.prototype.SetFillAlpha=function(m){m===void 0&&(m=0);this.m_fillAlpha=m};m.prototype.GetFillAlpha=function(){return this.m_fillAlpha};m.prototype.SetXFormScale=function(m){m===void 0&&(m=0);this.m_xformScale=m};m.prototype.GetXFormScale=function(){return this.m_xformScale};
m.prototype.DrawPolygon=function(m,q,e){if(q){var h=this.m_ctx,l=this.m_drawScale;h.beginPath();h.strokeStyle=this._color(e.color,this.m_alpha);h.moveTo(m[0].x*l,m[0].y*l);for(e=1;e<q;e++)h.lineTo(m[e].x*l,m[e].y*l);h.lineTo(m[0].x*l,m[0].y*l);h.closePath();h.stroke()}};m.prototype.DrawSolidPolygon=function(m,q){if(q){var e=this.m_ctx,h=this.m_drawScale;e.beginPath();e.fillStyle="rgba(255,255,0,0.5)";e.moveTo(m[0].x*h,m[0].y*h);for(var l=1;l<q;l++)e.lineTo(m[l].x*h,m[l].y*h);e.lineTo(m[0].x*h,m[0].y*
h);e.closePath();e.fill()}};m.prototype.DrawCircle=function(m,q,e){if(q){var h=this.m_ctx,l=this.m_drawScale;h.beginPath();h.strokeStyle=this._color(e.color,this.m_alpha);h.arc(m.x*l,m.y*l,q*l,0,Math.PI*2,!0);h.closePath();h.stroke()}};m.prototype.DrawSolidCircle=function(m,q){if(q){var e=this.m_ctx,h=this.m_drawScale,l=m.x*h,w=m.y*h;e.moveTo(0,0);e.beginPath();e.fillStyle="rgba(255,255,255,0.7)";e.arc(l,w,q*h,0,Math.PI,!0);e.closePath();e.fill();e.beginPath();e.fillStyle="rgba(255,0,0,0.7)";e.arc(l,
w,q*h,Math.PI,Math.PI*2,!0);e.closePath();e.fill()}};m.prototype.DrawSegment=function(m,q,e){var h=this.m_ctx,l=this.m_drawScale;h.strokeStyle=this._color(e.color,this.m_alpha);h.beginPath();h.moveTo(m.x*l,m.y*l);h.lineTo(q.x*l,q.y*l);h.closePath();h.stroke()};m.prototype.DrawTransform=function(m){var q=this.m_ctx,e=this.m_drawScale;q.beginPath();q.strokeStyle=this._color(16711680,this.m_alpha);q.moveTo(m.position.x*e,m.position.y*e);q.lineTo((m.position.x+this.m_xformScale*m.R.col1.x)*e,(m.position.y+
this.m_xformScale*m.R.col1.y)*e);q.strokeStyle=this._color(65280,this.m_alpha);q.moveTo(m.position.x*e,m.position.y*e);q.lineTo((m.position.x+this.m_xformScale*m.R.col2.x)*e,(m.position.y+this.m_xformScale*m.R.col2.y)*e);q.closePath();q.stroke()}})();var i;for(i=0;i<Box2D.postDefs.length;++i)Box2D.postDefs[i]();delete Box2D.postDefs;
