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