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