/* Phaser v2.6.2 P2.JS Build - http://phaser.io - @photonstorm - (c) 2016 Photon Storm Ltd. */ !function(a){if("object"==typeof exports)module.exports=a();else if("function"==typeof define,1){var b;"undefined"!=typeof window?b=window:"undefined"!=typeof global?b=global:"undefined"!=typeof self&&(b=self),b.p2=a()}else define(a)}(function(){return function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);throw new Error("Cannot find module '"+g+"'")}var j=c[g]={exports:{}};b[g][0].call(j.exports,function(a){var c=b[g][1][a];return e(c?c:a)},j,j.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g=0&&i<=1&&j>=0&&j<=1}},{"./Scalar":4}],2:[function(a,b,c){function d(){}b.exports=d,d.area=function(a,b,c){return(b[0]-a[0])*(c[1]-a[1])-(c[0]-a[0])*(b[1]-a[1])},d.left=function(a,b,c){return d.area(a,b,c)>0},d.leftOn=function(a,b,c){return d.area(a,b,c)>=0},d.right=function(a,b,c){return d.area(a,b,c)<0},d.rightOn=function(a,b,c){return d.area(a,b,c)<=0};var e=[],f=[];d.collinear=function(a,b,c,g){if(g){var h=e,i=f;h[0]=b[0]-a[0],h[1]=b[1]-a[1],i[0]=c[0]-b[0],i[1]=c[1]-b[1];var j=h[0]*i[0]+h[1]*i[1],k=Math.sqrt(h[0]*h[0]+h[1]*h[1]),l=Math.sqrt(i[0]*i[0]+i[1]*i[1]),m=Math.acos(j/(k*l));return ma.vertices.length)throw new Error("lol2");if(b<0)throw new Error("lol3");for(var d=b;db[a][0])&&(a=c);g.left(this.at(a-1),this.at(a),this.at(a+1))||this.reverse()},d.prototype.reverse=function(){for(var a=[],b=0,c=this.vertices.length;b!==c;b++)a.push(this.vertices.pop());this.vertices=a},d.prototype.isReflex=function(a){return g.right(this.at(a-1),this.at(a),this.at(a+1))};var i=[],j=[];d.prototype.canSee=function(a,b){var c,d,e=i,h=j;if(g.leftOn(this.at(a+1),this.at(a),this.at(b))&&g.rightOn(this.at(a-1),this.at(a),this.at(b)))return!1;d=g.sqdist(this.at(a),this.at(b));for(var k=0;k!==this.vertices.length;++k)if((k+1)%this.vertices.length!==a&&k!==a&&g.leftOn(this.at(a),this.at(b),this.at(k+1))&&g.rightOn(this.at(a),this.at(b),this.at(k))&&(e[0]=this.at(a),e[1]=this.at(b),h[0]=this.at(k),h[1]=this.at(k+1),c=f.lineInt(e,h),g.sqdist(this.at(a),c)0?this.slice(a):[this]},d.prototype.slice=function(a){if(0==a.length)return[this];if(a instanceof Array&&a.length&&a[0]instanceof Array&&2==a[0].length&&a[0][0]instanceof Array){for(var b=[this],c=0;ch)return console.warn("quickDecomp: max level ("+h+") reached."),a;for(var x=0;xq&&(q+=this.vertices.length),p=Number.MAX_VALUE,q3&&c>=0;--c)g.collinear(this.at(c-1),this.at(c),this.at(c+1),a)&&(this.vertices.splice(c%this.vertices.length,1),c--,b++);return b}},{"./Line":1,"./Point":2,"./Scalar":4}],4:[function(a,b,c){function d(){}b.exports=d,d.eq=function(a,b,c){return c=c||0,Math.abs(a-b) (http://steffe.se)",keywords:["p2.js","p2","physics","engine","2d"],main:"./src/p2.js",engines:{node:"*"},repository:{type:"git",url:"https://github.com/schteppe/p2.js.git"},bugs:{url:"https://github.com/schteppe/p2.js/issues"},licenses:[{type:"MIT"}],devDependencies:{grunt:"^0.4.5","grunt-contrib-jshint":"^0.11.2","grunt-contrib-nodeunit":"^0.4.1","grunt-contrib-uglify":"~0.4.0","grunt-contrib-watch":"~0.5.0","grunt-browserify":"~2.0.1","grunt-contrib-concat":"^0.4.0"},dependencies:{"poly-decomp":"0.1.0"}}},{}],7:[function(a,b,c){function d(a){this.lowerBound=e.create(),a&&a.lowerBound&&e.copy(this.lowerBound,a.lowerBound),this.upperBound=e.create(),a&&a.upperBound&&e.copy(this.upperBound,a.upperBound)}var e=a("../math/vec2");a("../utils/Utils");b.exports=d;var f=e.create();d.prototype.setFromPoints=function(a,b,c,d){var g=this.lowerBound,h=this.upperBound;"number"!=typeof c&&(c=0),0!==c?e.rotate(g,a[0],c):e.copy(g,a[0]),e.copy(h,g);for(var i=Math.cos(c),j=Math.sin(c),k=1;kh[o]&&(h[o]=l[o]),l[o]c&&(this.lowerBound[b]=c);var d=a.upperBound[b];this.upperBound[b]i?-1:h}},{"../math/vec2":30,"../utils/Utils":57}],8:[function(a,b,c){function d(a){this.type=a,this.result=[],this.world=null,this.boundingVolumeType=d.AABB}var e=a("../math/vec2"),f=a("../objects/Body");b.exports=d,d.AABB=1,d.BOUNDING_CIRCLE=2,d.prototype.setWorld=function(a){this.world=a},d.prototype.getCollisionPairs=function(a){};var g=e.create();d.boundingRadiusCheck=function(a,b){e.sub(g,a.position,b.position);var c=e.squaredLength(g),d=a.boundingRadius+b.boundingRadius;return c<=d*d},d.aabbCheck=function(a,b){return a.getAABB().overlaps(b.getAABB())},d.prototype.boundingVolumeCheck=function(a,b){var c;switch(this.boundingVolumeType){case d.BOUNDING_CIRCLE:c=d.boundingRadiusCheck(a,b);break;case d.AABB:c=d.aabbCheck(a,b);break;default:throw new Error("Bounding volume type not recognized: "+this.boundingVolumeType)}return c},d.canCollide=function(a,b){var c=f.KINEMATIC,d=f.STATIC;return(a.type!==d||b.type!==d)&&(!(a.type===c&&b.type===d||a.type===d&&b.type===c)&&((a.type!==c||b.type!==c)&&((a.sleepState!==f.SLEEPING||b.sleepState!==f.SLEEPING)&&!(a.sleepState===f.SLEEPING&&b.type===d||b.sleepState===f.SLEEPING&&a.type===d))))},d.NAIVE=1,d.SAP=2},{"../math/vec2":30,"../objects/Body":31}],9:[function(a,b,c){function d(){e.call(this,e.NAIVE)}var e=(a("../shapes/Circle"),a("../shapes/Plane"),a("../shapes/Shape"),a("../shapes/Particle"),a("../collision/Broadphase"));a("../math/vec2");b.exports=d,d.prototype=new e,d.prototype.constructor=d,d.prototype.getCollisionPairs=function(a){var b=a.bodies,c=this.result;c.length=0;for(var d=0,f=b.length;d!==f;d++)for(var g=b[d],h=0;hW&&V0)for(var N=0;NMath.pow(p,2))return 0;if(l)return!0;var q=this.createContactEquation(a,e,b,f);return h(q.normalA,j,c),g.normalize(q.normalA,q.normalA),g.scale(q.contactPointA,q.normalA,m),g.scale(q.contactPointB,q.normalA,-n),i(q.contactPointA,q.contactPointA,c),h(q.contactPointA,q.contactPointA,a.position),i(q.contactPointB,q.contactPointB,j),h(q.contactPointB,q.contactPointB,e.position),this.contactEquations.push(q),this.enableFriction&&this.frictionEquations.push(this.createFrictionFromContact(q)),1},d.prototype[q.PLANE|q.CONVEX]=d.prototype[q.PLANE|q.BOX]=d.prototype.planeConvex=function(a,b,c,d,e,f,k,l,m){var n=t,o=u,p=v,q=0;g.rotate(o,s,d);for(var r=0;r!==f.vertices.length;r++){var w=f.vertices[r];if(g.rotate(n,w,l),i(n,n,k),h(p,n,c),j(p,o)<=0){if(m)return!0;q++;var x=this.createContactEquation(a,e,b,f);h(p,n,c),g.copy(x.normalA,o);var y=j(p,x.normalA);g.scale(p,x.normalA,y),h(x.contactPointB,n,e.position),h(x.contactPointA,n,p),h(x.contactPointA,x.contactPointA,a.position),this.contactEquations.push(x),this.enableFrictionReduction||this.enableFriction&&this.frictionEquations.push(this.createFrictionFromContact(x))}}return this.enableFrictionReduction&&this.enableFriction&&q&&this.frictionEquations.push(this.createFrictionFromAverage(q)),q},d.prototype[q.PARTICLE|q.PLANE]=d.prototype.particlePlane=function(a,b,c,d,e,f,i,k,l){var m=t,n=u;k=k||0,h(m,c,i),g.rotate(n,s,k);var o=j(m,n);if(o>0)return 0;if(l)return!0;var p=this.createContactEquation(e,a,f,b);return g.copy(p.normalA,n),g.scale(m,p.normalA,o),h(p.contactPointA,c,m),h(p.contactPointA,p.contactPointA,e.position),h(p.contactPointB,c,a.position),this.contactEquations.push(p),this.enableFriction&&this.frictionEquations.push(this.createFrictionFromContact(p)),1},d.prototype[q.CIRCLE|q.PARTICLE]=d.prototype.circleParticle=function(a,b,c,d,e,f,j,k,l){var m=t;if(h(m,j,c),g.squaredLength(m)>Math.pow(b.radius,2))return 0;if(l)return!0;var n=this.createContactEquation(a,e,b,f);return g.copy(n.normalA,m),g.normalize(n.normalA,n.normalA),g.scale(n.contactPointA,n.normalA,b.radius),i(n.contactPointA,n.contactPointA,c),h(n.contactPointA,n.contactPointA,a.position),h(n.contactPointB,j,e.position),this.contactEquations.push(n),this.enableFriction&&this.frictionEquations.push(this.createFrictionFromContact(n)),1};var X=new o({radius:1}),Y=g.create(),Z=g.create();g.create();d.prototype[q.PLANE|q.CAPSULE]=d.prototype.planeCapsule=function(a,b,c,d,e,f,h,j,k){var l=Y,m=Z,n=X;g.set(l,-f.length/2,0),g.rotate(l,l,j),i(l,l,h),g.set(m,f.length/2,0),g.rotate(m,m,j),i(m,m,h),n.radius=f.radius;var o;this.enableFrictionReduction&&(o=this.enableFriction,this.enableFriction=!1);var p=this.circlePlane(e,n,l,0,a,b,c,d,k),q=this.circlePlane(e,n,m,0,a,b,c,d,k);if(this.enableFrictionReduction&&(this.enableFriction=o),k)return p||q;var r=p+q;return this.enableFrictionReduction&&r&&this.frictionEquations.push(this.createFrictionFromAverage(r)),r},d.prototype[q.CIRCLE|q.PLANE]=d.prototype.circlePlane=function(a,b,c,d,e,f,k,l,m){var n=a,o=b,p=c,q=e,r=k,w=l;w=w||0;var x=t,y=u,z=v;h(x,p,r),g.rotate(y,s,w);var A=j(y,x);if(A>o.radius)return 0;if(m)return!0;var B=this.createContactEquation(q,n,f,b);return g.copy(B.normalA,y),g.scale(B.contactPointB,B.normalA,-o.radius),i(B.contactPointB,B.contactPointB,p),h(B.contactPointB,B.contactPointB,n.position),g.scale(z,B.normalA,A),h(B.contactPointA,x,z),i(B.contactPointA,B.contactPointA,r),h(B.contactPointA,B.contactPointA,q.position),this.contactEquations.push(B),this.enableFriction&&this.frictionEquations.push(this.createFrictionFromContact(B)),1},d.prototype[q.CONVEX]=d.prototype[q.CONVEX|q.BOX]=d.prototype[q.BOX]=d.prototype.convexConvex=function(a,b,c,e,f,k,l,m,n,o){var p=t,q=u,r=v,s=w,y=x,C=z,D=A,E=B,F=0,o="number"==typeof o?o:0,G=d.findSeparatingAxis(b,c,e,k,l,m,p);if(!G)return 0;h(D,l,c),j(p,D)>0&&g.scale(p,p,-1);var H=d.getClosestEdge(b,e,p,!0),I=d.getClosestEdge(k,m,p);if(H===-1||I===-1)return 0;for(var J=0;J<2;J++){var K=H,L=I,M=b,N=k,O=c,P=l,Q=e,R=m,S=a,T=f;if(0===J){var U;U=K,K=L,L=U,U=M,M=N,N=U,U=O,O=P,P=U,U=Q,Q=R,R=U,U=S,S=T,T=U}for(var V=L;V=3){if(n)return!0;var aa=this.createContactEquation(S,T,M,N);F++;var Z=M.vertices[K%M.vertices.length],$=M.vertices[(K+1)%M.vertices.length];g.rotate(r,Z,Q),g.rotate(s,$,Q),i(r,r,O),i(s,s,O),h(y,s,r),g.rotate90cw(aa.normalA,y),g.normalize(aa.normalA,aa.normalA),h(D,q,r);var _=j(aa.normalA,D);g.scale(C,aa.normalA,_),h(aa.contactPointA,q,O),h(aa.contactPointA,aa.contactPointA,C),i(aa.contactPointA,aa.contactPointA,O),h(aa.contactPointA,aa.contactPointA,S.position),h(aa.contactPointB,q,P),i(aa.contactPointB,aa.contactPointB,P),h(aa.contactPointB,aa.contactPointB,T.position),this.contactEquations.push(aa),this.enableFrictionReduction||this.enableFriction&&this.frictionEquations.push(this.createFrictionFromContact(aa))}}}return this.enableFrictionReduction&&this.enableFriction&&F&&this.frictionEquations.push(this.createFrictionFromAverage(F)),F};var $=g.fromValues(0,0);d.projectConvexOntoAxis=function(a,b,c,d,e){var f,h,i=null,k=null,l=$;g.rotate(l,d,-c);for(var m=0;mi)&&(i=h),(null===k||hi){var n=k;k=i,i=n}var o=j(b,d);g.set(e,k+o,i+o)};var _=g.fromValues(0,0),aa=g.fromValues(0,0),ba=g.fromValues(0,0),ca=g.fromValues(0,0),da=g.fromValues(0,0),ea=g.fromValues(0,0);d.findSeparatingAxis=function(a,b,c,e,f,i,j){var k=null,l=!1,m=!1,n=_,o=aa,p=ba,q=ca,s=da,t=ea;if(a instanceof r&&e instanceof r)for(var u=0;2!==u;u++){var v=a,w=c;1===u&&(v=e,w=i);for(var x=0;2!==x;x++){0===x?g.set(q,0,1):1===x&&g.set(q,1,0),0!==w&&g.rotate(q,q,w),d.projectConvexOntoAxis(a,b,c,q,s),d.projectConvexOntoAxis(e,f,i,q,t);var y=s,z=t,A=!1;s[0]>t[0]&&(z=s,y=t,A=!0);var B=z[0]-y[1];l=B<=0,(null===k||B>k)&&(g.copy(j,q),k=B,m=l)}}else for(var u=0;2!==u;u++){var v=a,w=c;1===u&&(v=e,w=i);for(var x=0;x!==v.vertices.length;x++){g.rotate(o,v.vertices[x],w),g.rotate(p,v.vertices[(x+1)%v.vertices.length],w),h(n,p,o),g.rotate90cw(q,n),g.normalize(q,q),d.projectConvexOntoAxis(a,b,c,q,s),d.projectConvexOntoAxis(e,f,i,q,t);var y=s,z=t,A=!1;s[0]>t[0]&&(z=s,y=t,A=!0);var B=z[0]-y[1];l=B<=0,(null===k||B>k)&&(g.copy(j,q),k=B,m=l)}}return m};var fa=g.fromValues(0,0),ga=g.fromValues(0,0),ha=g.fromValues(0,0);d.getClosestEdge=function(a,b,c,d){var e=fa,f=ga,i=ha;g.rotate(e,c,-b),d&&g.scale(e,e,-1);for(var k=-1,l=a.vertices.length,m=-1,n=0;n!==l;n++){h(f,a.vertices[(n+1)%l],a.vertices[n%l]),g.rotate90cw(i,f),g.normalize(i,i);var o=j(i,e);(k===-1||o>m)&&(k=n%l,m=o)}return k};var ia=g.create(),ja=g.create(),ka=g.create(),la=g.create(),ma=g.create(),na=g.create(),oa=g.create();d.prototype[q.CIRCLE|q.HEIGHTFIELD]=d.prototype.circleHeightfield=function(a,b,c,d,e,f,j,k,l,m){var n=f.heights,m=m||b.radius,o=f.elementWidth,p=ja,q=ia,r=ma,s=oa,t=na,u=ka,v=la,w=Math.floor((c[0]-m-j[0])/o),x=Math.ceil((c[0]+m-j[0])/o);w<0&&(w=0),x>=n.length&&(x=n.length-1);for(var y=n[w],z=n[x],A=w;Ay&&(y=n[A]);if(c[1]-m>y)return!l&&0;for(var B=!1,A=w;A=u[0]&&q[0]0)for(var A=w;A<=x;A++)if(g.set(u,A*o,n[A]),g.add(u,u,j),g.sub(p,c,u),g.squaredLength(p)=k.length&&(r=k.length-1);for(var s=k[q],t=k[r],u=q;us&&(s=k[u]);if(a.aabb.lowerBound[1]>s)return!j&&0;for(var v=0,u=q;u=0||f.containsPoint(this.from))&&this.intersectBody(a,e)}};var g=f.create();d.prototype.intersectBody=function(a,b){var c=this.checkCollisionResponse;if(!c||b.collisionResponse)for(var d=g,e=0,h=b.shapes.length;eb.boundingRadius*b.boundingRadius||(this._currentBody=f,this._currentShape=b,b.raycast(a,this,d,c),this._currentBody=this._currentShape=null)},d.prototype.getAABB=function(a){var b=this.to,c=this.from;f.set(a.lowerBound,Math.min(b[0],c[0]),Math.min(b[1],c[1])),f.set(a.upperBound,Math.max(b[0],c[0]),Math.max(b[1],c[1]))};f.create();d.prototype.reportIntersection=function(a,b,c,e){var g=(this.from,this.to,this._currentShape),h=this._currentBody;if(!(this.skipBackfaces&&f.dot(c,this.direction)>0))switch(this.mode){case d.ALL:a.set(c,g,h,b,e),this.callback(a);break;case d.CLOSEST:(b=0&&!(a[f].aabb.lowerBound[b]<=e.aabb.lowerBound[b]);f--)a[f+1]=a[f];a[f+1]=e}return a},d.prototype.sortList=function(){var a=this.axisList,b=this.axisIndex;d.sortAxisList(a,b)},d.prototype.getCollisionPairs=function(a){var b=this.axisList,c=this.result,d=this.axisIndex;c.length=0;for(var e=b.length;e--;){var g=b[e];g.aabbNeedsUpdate&&g.updateAABB()}this.sortList();for(var h=0,i=0|b.length;h!==i;h++)for(var j=b[h],k=h+1;kthis.upperLimit&&(f.maxForce=0,f.minForce=-this.maxForce,this.distance=this.upperLimit,l=!0),this.lowerLimitEnabled&&this.positionc)h.scale(e.normalA,j,-1),h.sub(e.contactPointA,k,g.position),h.sub(e.contactPointB,l,i.position),h.scale(o,j,c),h.add(e.contactPointA,e.contactPointA,o),a.indexOf(e)===-1&&a.push(e);else{var u=a.indexOf(e);u!==-1&&a.splice(u,1)}if(this.lowerLimitEnabled&&sh)o.angle=h,e.indexOf(o)===-1&&e.push(o);else{var r=e.indexOf(o);r!==-1&&e.splice(r,1)}if(this.lowerLimitEnabled&&q>1;if(b<3)return[];for(var c=[],e=[],f=0;f3;){var h=e[(f+0)%g],i=e[(f+1)%g],j=e[(f+2)%g],k=a[2*h],l=a[2*h+1],m=a[2*i],n=a[2*i+1],o=a[2*j],p=a[2*j+1],q=!1;if(d._convex(k,l,m,n,o,p)){q=!0;for(var r=0;r3*g)break}return c.push(e[0],e[1],e[2]),c},d._PointInTriangle=function(a,b,c,d,e,f,g,h){var i=g-c,j=h-d,k=e-c,l=f-d,m=a-c,n=b-d,o=i*i+j*j,p=i*k+j*l,q=i*m+j*n,r=k*k+l*l,s=k*m+l*n,t=1/(o*r-p*p),u=(r*q-p*s)*t,v=(o*s-p*q)*t;return u>=0&&v>=0&&u+v<1},d._convex=function(a,b,c,d,e,f){return(b-d)*(e-c)+(c-a)*(f-d)>=0},b.exports=d},{}],30:[function(a,b,c){var d=b.exports={},e=a("../utils/Utils");d.crossLength=function(a,b){return a[0]*b[1]-a[1]*b[0]},d.crossVZ=function(a,b,c){return d.rotate(a,b,-Math.PI/2),d.scale(a,a,c),a},d.crossZV=function(a,b,c){return d.rotate(a,c,Math.PI/2),d.scale(a,a,b),a},d.rotate=function(a,b,c){if(0!==c){var d=Math.cos(c),e=Math.sin(c),f=b[0],g=b[1];a[0]=d*f-e*g,a[1]=e*f+d*g}else a[0]=b[0],a[1]=b[1]},d.rotate90cw=function(a,b){var c=b[0],d=b[1];a[0]=d,a[1]=-c},d.toLocalFrame=function(a,b,c,e){d.copy(a,b),d.sub(a,a,c),d.rotate(a,a,-e)},d.toGlobalFrame=function(a,b,c,e){d.copy(a,b),d.rotate(a,a,e),d.add(a,a,c)},d.vectorToLocalFrame=function(a,b,c){d.rotate(a,b,-c)},d.vectorToGlobalFrame=function(a,b,c){d.rotate(a,b,c)},d.centroid=function(a,b,c,e){return d.add(a,b,c),d.add(a,a,e),d.scale(a,a,1/3),a},d.create=function(){var a=new e.ARRAY_TYPE(2);return a[0]=0,a[1]=0,a},d.clone=function(a){var b=new e.ARRAY_TYPE(2);return b[0]=a[0],b[1]=a[1],b},d.fromValues=function(a,b){var c=new e.ARRAY_TYPE(2);return c[0]=a,c[1]=b,c},d.copy=function(a,b){return a[0]=b[0],a[1]=b[1],a},d.set=function(a,b,c){return a[0]=b,a[1]=c,a},d.add=function(a,b,c){return a[0]=b[0]+c[0],a[1]=b[1]+c[1],a},d.subtract=function(a,b,c){return a[0]=b[0]-c[0],a[1]=b[1]-c[1],a},d.sub=d.subtract,d.multiply=function(a,b,c){return a[0]=b[0]*c[0],a[1]=b[1]*c[1],a},d.mul=d.multiply,d.divide=function(a,b,c){return a[0]=b[0]/c[0],a[1]=b[1]/c[1],a},d.div=d.divide,d.scale=function(a,b,c){return a[0]=b[0]*c,a[1]=b[1]*c,a},d.distance=function(a,b){var c=b[0]-a[0],d=b[1]-a[1];return Math.sqrt(c*c+d*d)},d.dist=d.distance,d.squaredDistance=function(a,b){var c=b[0]-a[0],d=b[1]-a[1];return c*c+d*d},d.sqrDist=d.squaredDistance,d.length=function(a){var b=a[0],c=a[1];return Math.sqrt(b*b+c*c)},d.len=d.length,d.squaredLength=function(a){var b=a[0],c=a[1];return b*b+c*c},d.sqrLen=d.squaredLength,d.negate=function(a,b){return a[0]=-b[0],a[1]=-b[1],a},d.normalize=function(a,b){var c=b[0],d=b[1],e=c*c+d*d;return e>0&&(e=1/Math.sqrt(e),a[0]=b[0]*e,a[1]=b[1]*e),a},d.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]},d.str=function(a){return"vec2("+a[0]+", "+a[1]+")"},d.lerp=function(a,b,c,d){var e=b[0],f=b[1];return a[0]=e+d*(c[0]-e),a[1]=f+d*(c[1]-f),a},d.reflect=function(a,b,c){var d=b[0]*c[0]+b[1]*c[1];a[0]=b[0]-2*c[0]*d,a[1]=b[1]-2*c[1]*d},d.getLineSegmentsIntersection=function(a,b,c,e,f){var g=d.getLineSegmentsIntersectionFraction(b,c,e,f);return!(g<0)&&(a[0]=b[0]+g*(c[0]-b[0]),a[1]=b[1]+g*(c[1]-b[1]),!0)},d.getLineSegmentsIntersectionFraction=function(a,b,c,d){var e,f,g=b[0]-a[0],h=b[1]-a[1],i=d[0]-c[0],j=d[1]-c[1];return e=(-h*(a[0]-c[0])+g*(a[1]-c[1]))/(-i*h+g*j),f=(i*(a[1]-c[1])-j*(a[0]-c[0]))/(-i*h+g*j),e>=0&&e<=1&&f>=0&&f<=1?f:-1}},{"../utils/Utils":57}],31:[function(a,b,c){function d(a){a=a||{},k.call(this),this.id=a.id||++d._idCounter,this.world=null,this.shapes=[],this.mass=a.mass||0,this.invMass=0,this.inertia=0,this.invInertia=0,this.invMassSolve=0,this.invInertiaSolve=0,this.fixedRotation=!!a.fixedRotation,this.fixedX=!!a.fixedX,this.fixedY=!!a.fixedY,this.massMultiplier=e.create(),this.position=e.fromValues(0,0),a.position&&e.copy(this.position,a.position),this.interpolatedPosition=e.fromValues(0,0),this.interpolatedAngle=0,this.previousPosition=e.fromValues(0,0),this.previousAngle=0,this.velocity=e.fromValues(0,0),a.velocity&&e.copy(this.velocity,a.velocity),this.vlambda=e.fromValues(0,0),this.wlambda=0,this.angle=a.angle||0,this.angularVelocity=a.angularVelocity||0,this.force=e.create(),a.force&&e.copy(this.force,a.force),this.angularForce=a.angularForce||0,this.damping="number"==typeof a.damping?a.damping:.1,this.angularDamping="number"==typeof a.angularDamping?a.angularDamping:.1,this.type=d.STATIC,"undefined"!=typeof a.type?this.type=a.type:a.mass?this.type=d.DYNAMIC:this.type=d.STATIC,this.boundingRadius=0,this.aabb=new j,this.aabbNeedsUpdate=!0,this.allowSleep=void 0===a.allowSleep||a.allowSleep, this.wantsToSleep=!1,this.sleepState=d.AWAKE,this.sleepSpeedLimit=void 0!==a.sleepSpeedLimit?a.sleepSpeedLimit:.2,this.sleepTimeLimit=void 0!==a.sleepTimeLimit?a.sleepTimeLimit:1,this.gravityScale=void 0!==a.gravityScale?a.gravityScale:1,this.collisionResponse=void 0===a.collisionResponse||a.collisionResponse,this.idleTime=0,this.timeLastSleepy=0,this.ccdSpeedThreshold=void 0!==a.ccdSpeedThreshold?a.ccdSpeedThreshold:-1,this.ccdIterations=void 0!==a.ccdIterations?a.ccdIterations:10,this.concavePath=null,this._wakeUpAfterNarrowphase=!1,this.updateMassProperties()}var e=a("../math/vec2"),f=a("poly-decomp"),g=a("../shapes/Convex"),h=a("../collision/RaycastResult"),i=a("../collision/Ray"),j=a("../collision/AABB"),k=a("../events/EventEmitter");b.exports=d,d.prototype=new k,d.prototype.constructor=d,d._idCounter=0,d.prototype.updateSolveMassProperties=function(){this.sleepState===d.SLEEPING||this.type===d.KINEMATIC?(this.invMassSolve=0,this.invInertiaSolve=0):(this.invMassSolve=this.invMass,this.invInertiaSolve=this.invInertia)},d.prototype.setDensity=function(a){var b=this.getArea();this.mass=b*a,this.updateMassProperties()},d.prototype.getArea=function(){for(var a=0,b=0;bc&&(c=g+h)}this.boundingRadius=c},d.prototype.addShape=function(a,b,c){if(a.body)throw new Error("A shape can only be added to one body.");a.body=this,b?e.copy(a.position,b):e.set(a.position,0,0),a.angle=c||0,this.shapes.push(a),this.updateMassProperties(),this.updateBoundingRadius(),this.aabbNeedsUpdate=!0},d.prototype.removeShape=function(a){var b=this.shapes.indexOf(a);return b!==-1&&(this.shapes.splice(b,1),this.aabbNeedsUpdate=!0,a.body=null,!0)},d.prototype.updateMassProperties=function(){if(this.type===d.STATIC||this.type===d.KINEMATIC)this.mass=Number.MAX_VALUE,this.invMass=0,this.inertia=Number.MAX_VALUE,this.invInertia=0;else{var a=this.shapes,b=a.length,c=this.mass/b,f=0;if(this.fixedRotation)this.inertia=Number.MAX_VALUE,this.invInertia=0;else{for(var g=0;g0?1/f:0}this.invMass=1/this.mass,e.set(this.massMultiplier,this.fixedX?0:1,this.fixedY?0:1)}};e.create();d.prototype.applyForce=function(a,b){if(e.add(this.force,this.force,a),b){var c=e.crossLength(b,a);this.angularForce+=c}};var n=e.create(),o=e.create(),p=e.create();d.prototype.applyForceLocal=function(a,b){b=b||p;var c=n,d=o;this.vectorToWorldFrame(c,a),this.vectorToWorldFrame(d,b),this.applyForce(c,d)};var q=e.create();d.prototype.applyImpulse=function(a,b){if(this.type===d.DYNAMIC){var c=q;if(e.scale(c,a,this.invMass),e.multiply(c,this.massMultiplier,c),e.add(this.velocity,c,this.velocity),b){var f=e.crossLength(b,a);f*=this.invInertia,this.angularVelocity+=f}}};var r=e.create(),s=e.create(),t=e.create();d.prototype.applyImpulseLocal=function(a,b){b=b||t;var c=r,d=s;this.vectorToWorldFrame(c,a),this.vectorToWorldFrame(d,b),this.applyImpulse(c,d)},d.prototype.toLocalFrame=function(a,b){e.toLocalFrame(a,b,this.position,this.angle)},d.prototype.toWorldFrame=function(a,b){e.toGlobalFrame(a,b,this.position,this.angle)},d.prototype.vectorToLocalFrame=function(a,b){e.vectorToLocalFrame(a,b,this.angle)},d.prototype.vectorToWorldFrame=function(a,b){e.vectorToGlobalFrame(a,b,this.angle)},d.prototype.fromPolygon=function(a,b){b=b||{};for(var c=this.shapes.length;c>=0;--c)this.removeShape(this.shapes[c]);var d=new f.Polygon;if(d.vertices=a,d.makeCCW(),"number"==typeof b.removeCollinearPoints&&d.removeCollinearPoints(b.removeCollinearPoints),"undefined"==typeof b.skipSimpleCheck&&!d.isSimple())return!1;this.concavePath=d.vertices.slice(0);for(var c=0;c=g?(this.idleTime=0,this.sleepState=d.AWAKE):(this.idleTime+=c,this.sleepState=d.SLEEPY),this.idleTime>this.sleepTimeLimit&&(b?this.wantsToSleep=!0:this.sleep())}},d.prototype.overlaps=function(a){return this.world.overlapKeeper.bodiesAreOverlapping(this,a)};var x=e.create(),y=e.create();d.prototype.integrate=function(a){var b=this.invMass,c=this.force,d=this.position,f=this.velocity;e.copy(this.previousPosition,this.position),this.previousAngle=this.angle,this.fixedRotation||(this.angularVelocity+=this.angularForce*this.invInertia*a),e.scale(x,c,a*b),e.multiply(x,this.massMultiplier,x),e.add(f,x,f),this.integrateToTimeOfImpact(a)||(e.scale(y,f,a),e.add(d,d,y),this.fixedRotation||(this.angle+=this.angularVelocity*a)),this.aabbNeedsUpdate=!0};var z=new h,A=new i({mode:i.ALL}),B=e.create(),C=e.create(),D=e.create(),E=e.create();d.prototype.integrateToTimeOfImpact=function(a){if(this.ccdSpeedThreshold<0||e.squaredLength(this.velocity)=j&&i=0&&(f.rotate(n,l,d),f.scale(n,n,2*r-1),b.reportIntersection(a,t,n,-1),a.shouldStop(b)))return}for(var u=Math.pow(this.radius,2)+Math.pow(q,2),r=0;r<2;r++){f.set(o,q*(2*r-1),0),f.toGlobalFrame(o,o,c,d);var v=Math.pow(g[0]-e[0],2)+Math.pow(g[1]-e[1],2),w=2*((g[0]-e[0])*(e[0]-o[0])+(g[1]-e[1])*(e[1]-o[1])),x=Math.pow(e[0]-o[0],2)+Math.pow(e[1]-o[1],2)-Math.pow(this.radius,2),t=Math.pow(w,2)-4*v*x;if(!(t<0))if(0===t){if(f.lerp(m,e,g,t),f.squaredDistance(m,c)>u&&(f.sub(n,m,o),f.normalize(n,n),b.reportIntersection(a,t,n,-1),a.shouldStop(b)))return}else{var y=Math.sqrt(t),z=1/(2*v),A=(-w-y)*z,B=(-w+y)*z;if(A>=0&&A<=1&&(f.lerp(m,e,g,A),f.squaredDistance(m,c)>u&&(f.sub(n,m,o),f.normalize(n,n),b.reportIntersection(a,A,n,-1),a.shouldStop(b))))return;if(B>=0&&B<=1&&(f.lerp(m,e,g,B),f.squaredDistance(m,c)>u&&(f.sub(n,m,o),f.normalize(n,n),b.reportIntersection(a,B,n,-1),a.shouldStop(b))))return}}}},{"../math/vec2":30,"./Shape":45}],39:[function(a,b,c){function d(a){"number"==typeof arguments[0]&&(a={radius:arguments[0]},console.warn("The Circle constructor signature has changed. Please use the following format: new Circle({ radius: 1 })")),a=a||{},this.radius=a.radius||1,a.type=e.CIRCLE,e.call(this,a)}var e=a("./Shape"),f=a("../math/vec2");b.exports=d,d.prototype=new e,d.prototype.constructor=d,d.prototype.computeMomentOfInertia=function(a){var b=this.radius;return a*b*b/2},d.prototype.updateBoundingRadius=function(){this.boundingRadius=this.radius},d.prototype.updateArea=function(){this.area=Math.PI*this.radius*this.radius},d.prototype.computeAABB=function(a,b,c){var d=this.radius;f.set(a.upperBound,d,d),f.set(a.lowerBound,-d,-d),b&&(f.add(a.lowerBound,a.lowerBound,b),f.add(a.upperBound,a.upperBound,b))};var g=f.create(),h=f.create();d.prototype.raycast=function(a,b,c,d){var e=b.from,i=b.to,j=this.radius,k=Math.pow(i[0]-e[0],2)+Math.pow(i[1]-e[1],2),l=2*((i[0]-e[0])*(e[0]-c[0])+(i[1]-e[1])*(e[1]-c[1])),m=Math.pow(e[0]-c[0],2)+Math.pow(e[1]-c[1],2)-Math.pow(j,2),n=Math.pow(l,2)-4*k*m,o=g,p=h;if(!(n<0))if(0===n)f.lerp(o,e,i,n),f.sub(p,o,c),f.normalize(p,p),b.reportIntersection(a,n,p,-1);else{var q=Math.sqrt(n),r=1/(2*k),s=(-l-q)*r,t=(-l+q)*r;if(s>=0&&s<=1&&(f.lerp(o,e,i,s),f.sub(p,o,c),f.normalize(p,p),b.reportIntersection(a,s,p,-1),a.shouldStop(b)))return;t>=0&&t<=1&&(f.lerp(o,e,i,t),f.sub(p,o,c),f.normalize(p,p),b.reportIntersection(a,t,p,-1))}}},{"../math/vec2":30,"./Shape":45}],40:[function(a,b,c){function d(a){Array.isArray(arguments[0])&&(a={vertices:arguments[0],axes:arguments[1]},console.warn("The Convex constructor signature has changed. Please use the following format: new Convex({ vertices: [...], ... })")),a=a||{},this.vertices=[];for(var b=void 0!==a.vertices?a.vertices:[],c=0;ce)&&(e=d),(null===g||de){var j=g;g=e,e=j}f.set(b,g,e)},d.prototype.projectOntoWorldAxis=function(a,b,c,d){var e=i;this.projectOntoLocalAxis(a,d),0!==c?f.rotate(e,a,c):e=a;var g=f.dot(b,e);f.set(d,d[0]+g,d[1]+g)},d.prototype.updateTriangles=function(){this.triangles.length=0;for(var a=[],b=0;bb&&(b=d)}this.boundingRadius=Math.sqrt(b)},d.triangleArea=function(a,b,c){return.5*((b[0]-a[0])*(c[1]-a[1])-(c[0]-a[0])*(b[1]-a[1]))},d.prototype.updateArea=function(){this.updateTriangles(),this.area=0;for(var a=this.triangles,b=this.vertices,c=0;c!==a.length;c++){var e=a[c],f=b[e[0]],g=b[e[1]],h=b[e[2]],i=d.triangleArea(f,g,h);this.area+=i}},d.prototype.computeAABB=function(a,b,c){a.setFromPoints(this.vertices,b,c,0)};var o=f.create(),p=f.create(),q=f.create();d.prototype.raycast=function(a,b,c,d){var e=o,g=p,h=q,i=this.vertices;f.toLocalFrame(e,b.from,c,d),f.toLocalFrame(g,b.to,c,d);for(var j=i.length,k=0;k=0&&(f.sub(h,m,l),f.rotate(h,h,-Math.PI/2+d),f.normalize(h,h),b.reportIntersection(a,n,h,k))}}},{"../math/polyk":29,"../math/vec2":30,"./Shape":45,"poly-decomp":5}],41:[function(a,b,c){function d(a){if(Array.isArray(arguments[0])){if(a={heights:arguments[0]},"object"==typeof arguments[1])for(var b in arguments[1])a[b]=arguments[1][b];console.warn("The Heightfield constructor signature has changed. Please use the following format: new Heightfield({ heights: [...], ... })")}a=a||{},this.heights=a.heights?a.heights.slice(0):[],this.maxValue=a.maxValue||null,this.minValue=a.minValue||null,this.elementWidth=a.elementWidth||.1,void 0!==a.maxValue&&void 0!==a.minValue||this.updateMaxMinValues(),a.type=e.HEIGHTFIELD,e.call(this,a)}var e=a("./Shape"),f=a("../math/vec2");a("../utils/Utils");b.exports=d,d.prototype=new e,d.prototype.constructor=d,d.prototype.updateMaxMinValues=function(){for(var a=this.heights,b=a[0],c=a[0],d=0;d!==a.length;d++){var e=a[d];e>b&&(b=e),es){var t=r;r=s,s=t}for(var u=0;u=0&&(f.sub(m,o,n),f.rotate(m,m,d+Math.PI/2),f.normalize(m,m),b.reportIntersection(a,v,m,-1),a.shouldStop(b)))return}}},{"../math/vec2":30,"../utils/Utils":57,"./Shape":45}],42:[function(a,b,c){function d(a){"number"==typeof arguments[0]&&(a={length:arguments[0]},console.warn("The Line constructor signature has changed. Please use the following format: new Line({ length: 1, ... })")),a=a||{},this.length=a.length||1,a.type=e.LINE,e.call(this,a)}var e=a("./Shape"),f=a("../math/vec2");b.exports=d,d.prototype=new e,d.prototype.constructor=d,d.prototype.computeMomentOfInertia=function(a){return a*Math.pow(this.length,2)/12},d.prototype.updateBoundingRadius=function(){this.boundingRadius=this.length/2};var g=[f.create(),f.create()];d.prototype.computeAABB=function(a,b,c){var d=this.length/2;f.set(g[0],-d,0),f.set(g[1],d,0),a.setFromPoints(g,b,c,0)};var h=(f.create(),f.create()),i=f.create(),j=f.create(),k=f.fromValues(0,1);d.prototype.raycast=function(a,b,c,d){var e=b.from,g=b.to,l=i,m=j,n=this.length/2;f.set(l,-n,0),f.set(m,n,0),f.toGlobalFrame(l,l,c,d),f.toGlobalFrame(m,m,c,d);var o=f.getLineSegmentsIntersectionFraction(l,m,e,g);if(o>=0){var p=h;f.rotate(p,k,d),b.reportIntersection(a,o,p,-1)}}},{"../math/vec2":30,"./Shape":45}],43:[function(a,b,c){function d(a){a=a||{},a.type=e.PARTICLE,e.call(this,a)}var e=a("./Shape"),f=a("../math/vec2");b.exports=d,d.prototype=new e,d.prototype.constructor=d,d.prototype.computeMomentOfInertia=function(a){return 0},d.prototype.updateBoundingRadius=function(){this.boundingRadius=0},d.prototype.computeAABB=function(a,b,c){f.copy(a.lowerBound,b),f.copy(a.upperBound,b)}},{"../math/vec2":30,"./Shape":45}],44:[function(a,b,c){function d(a){a=a||{},a.type=e.PLANE,e.call(this,a)}var e=a("./Shape"),f=a("../math/vec2");a("../utils/Utils");b.exports=d,d.prototype=new e,d.prototype.constructor=d,d.prototype.computeMomentOfInertia=function(a){return 0},d.prototype.updateBoundingRadius=function(){this.boundingRadius=Number.MAX_VALUE},d.prototype.computeAABB=function(a,b,c){var d=c%(2*Math.PI),e=f.set,g=Number.MAX_VALUE,h=a.lowerBound,i=a.upperBound;0===d?(e(h,-g,-g),e(i,g,0)):d===Math.PI/2?(e(h,0,-g),e(i,g,g)):d===Math.PI?(e(h,-g,0),e(i,g,g)):d===3*Math.PI/2?(e(h,-g,-g),e(i,0,g)):(e(h,-g,-g),e(i,g,g)),f.add(h,h,b),f.add(i,i,b)},d.prototype.updateArea=function(){this.area=Number.MAX_VALUE};var g=f.create(),h=(f.create(),f.create(),f.create()),i=f.create();d.prototype.raycast=function(a,b,c,d){var e=b.from,j=b.to,k=b.direction,l=g,m=h,n=i;f.set(m,0,1),f.rotate(m,m,d),f.sub(n,e,c);var o=f.dot(n,m);f.sub(n,j,c);var p=f.dot(n,m);if(!(o*p>0||f.squaredDistance(e,j)n*h&&(p=n*h-l),f[a]+=p,b.addToWlambda(p),p}},{"../equations/FrictionEquation":23,"../math/vec2":30,"../utils/Utils":57,"./Solver":47}],47:[function(a,b,c){function d(a,b){a=a||{},e.call(this),this.type=b,this.equations=[],this.equationSortFunction=a.equationSortFunction||!1}var e=(a("../utils/Utils"),a("../events/EventEmitter"));b.exports=d,d.prototype=new e,d.prototype.constructor=d,d.prototype.solve=function(a,b){throw new Error("Solver.solve should be implemented by subclasses!")};var f={bodies:[]};d.prototype.solveIsland=function(a,b){this.removeAllEquations(),b.equations.length&&(this.addEquations(b.equations),f.bodies.length=0,b.getBodies(f.bodies),f.bodies.length&&this.solve(a,f))},d.prototype.sortEquations=function(){this.equationSortFunction&&this.equations.sort(this.equationSortFunction)},d.prototype.addEquation=function(a){a.enabled&&this.equations.push(a)},d.prototype.addEquations=function(a){for(var b=0,c=a.length;b!==c;b++){var d=a[b];d.enabled&&this.equations.push(d)}},d.prototype.removeEquation=function(a){var b=this.equations.indexOf(a);b!==-1&&this.equations.splice(b,1)},d.prototype.removeAllEquations=function(){this.equations.length=0},d.GS=1,d.ISLAND=2},{"../events/EventEmitter":26,"../utils/Utils":57}],48:[function(a,b,c){function d(){f.apply(this,arguments)}var e=a("../equations/ContactEquation"),f=a("./Pool");b.exports=d,d.prototype=new f,d.prototype.constructor=d,d.prototype.create=function(){return new e},d.prototype.destroy=function(a){return a.bodyA=a.bodyB=null,this}},{"../equations/ContactEquation":21,"./Pool":55}],49:[function(a,b,c){function d(){f.apply(this,arguments)}var e=a("../equations/FrictionEquation"),f=a("./Pool");b.exports=d,d.prototype=new f,d.prototype.constructor=d,d.prototype.create=function(){return new e},d.prototype.destroy=function(a){return a.bodyA=a.bodyB=null,this}},{"../equations/FrictionEquation":23,"./Pool":55}],50:[function(a,b,c){function d(){f.apply(this,arguments)}var e=a("../world/IslandNode"),f=a("./Pool");b.exports=d,d.prototype=new f,d.prototype.constructor=d,d.prototype.create=function(){return new e},d.prototype.destroy=function(a){return a.reset(),this}},{"../world/IslandNode":60,"./Pool":55}],51:[function(a,b,c){function d(){f.apply(this,arguments)}var e=a("../world/Island"),f=a("./Pool");b.exports=d,d.prototype=new f,d.prototype.constructor=d,d.prototype.create=function(){return new e},d.prototype.destroy=function(a){return a.reset(),this}},{"../world/Island":58,"./Pool":55}],52:[function(a,b,c){function d(){this.overlappingShapesLastState=new e,this.overlappingShapesCurrentState=new e,this.recordPool=new f({size:16}),this.tmpDict=new e,this.tmpArray1=[]}var e=a("./TupleDictionary"),f=(a("./OverlapKeeperRecord"),a("./OverlapKeeperRecordPool"));a("./Utils");b.exports=d,d.prototype.tick=function(){for(var a=this.overlappingShapesLastState,b=this.overlappingShapesCurrentState,c=a.keys.length;c--;){var d=a.keys[c],e=a.getByKey(d);b.getByKey(d);e&&this.recordPool.release(e)}a.reset(),a.copy(b),b.reset()},d.prototype.setOverlapping=function(a,b,c,d){var e=(this.overlappingShapesLastState,this.overlappingShapesCurrentState);if(!e.get(b.id,d.id)){var f=this.recordPool.get();f.set(a,b,c,d),e.set(b.id,d.id,f)}},d.prototype.getNewOverlaps=function(a){return this.getDiff(this.overlappingShapesLastState,this.overlappingShapesCurrentState,a)},d.prototype.getEndOverlaps=function(a){return this.getDiff(this.overlappingShapesCurrentState,this.overlappingShapesLastState,a)},d.prototype.bodiesAreOverlapping=function(a,b){for(var c=this.overlappingShapesCurrentState,d=c.keys.length;d--;){var e=c.keys[d],f=c.data[e];if(f.bodyA===a&&f.bodyB===b||f.bodyA===b&&f.bodyB===a)return!0}return!1},d.prototype.getDiff=function(a,b,c){var c=c||[],d=a,e=b;c.length=0;for(var f=e.keys.length;f--;){var g=e.keys[f],h=e.data[g];if(!h)throw new Error("Key "+g+" had no data!");var i=d.data[g];i||c.push(h)}return c},d.prototype.isNewOverlap=function(a,b){var c=0|a.id,d=0|b.id,e=this.overlappingShapesLastState,f=this.overlappingShapesCurrentState;return!e.get(c,d)&&!!f.get(c,d)},d.prototype.getNewBodyOverlaps=function(a){this.tmpArray1.length=0;var b=this.getNewOverlaps(this.tmpArray1);return this.getBodyDiff(b,a)},d.prototype.getEndBodyOverlaps=function(a){this.tmpArray1.length=0;var b=this.getEndOverlaps(this.tmpArray1);return this.getBodyDiff(b,a)},d.prototype.getBodyDiff=function(a,b){b=b||[];for(var c=this.tmpDict,d=a.length;d--;){var e=a[d];c.set(0|e.bodyA.id,0|e.bodyB.id,e)}for(d=c.keys.length;d--;){var e=c.getByKey(c.keys[d]);e&&b.push(e.bodyA,e.bodyB)}return c.reset(),b}},{"./OverlapKeeperRecord":53,"./OverlapKeeperRecordPool":54,"./TupleDictionary":56,"./Utils":57}],53:[function(a,b,c){function d(a,b,c,d){this.shapeA=b,this.shapeB=d,this.bodyA=a,this.bodyB=c}b.exports=d,d.prototype.set=function(a,b,c,e){d.call(this,a,b,c,e)}},{}],54:[function(a,b,c){function d(){f.apply(this,arguments)}var e=a("./OverlapKeeperRecord"),f=a("./Pool");b.exports=d,d.prototype=new f,d.prototype.constructor=d,d.prototype.create=function(){return new e},d.prototype.destroy=function(a){return a.bodyA=a.bodyB=a.shapeA=a.shapeB=null,this}},{"./OverlapKeeperRecord":53,"./Pool":55}],55:[function(a,b,c){function d(a){a=a||{},this.objects=[],void 0!==a.size&&this.resize(a.size)}b.exports=d,d.prototype.resize=function(a){for(var b=this.objects;b.length>a;)b.pop();for(;b.length(0|b)?a<<16|65535&b:b<<16|65535&a)},d.prototype.getByKey=function(a){return a=0|a,this.data[a]},d.prototype.get=function(a,b){return this.data[this.getKey(a,b)]},d.prototype.set=function(a,b,c){if(!c)throw new Error("No data!");var d=this.getKey(a,b);return this.data[d]||this.keys.push(d),this.data[d]=c,d},d.prototype.reset=function(){for(var a=this.data,b=this.keys,c=b.length;c--;)delete a[b[c]];b.length=0},d.prototype.copy=function(a){this.reset(),e.appendArray(this.keys,a.keys);for(var b=a.keys.length;b--;){var c=a.keys[b];this.data[c]=a.data[c]}}},{"./Utils":57}],57:[function(a,b,c){function d(){}b.exports=d,d.appendArray=function(a,b){if(b.length<15e4)a.push.apply(a,b);else for(var c=0,d=b.length;c!==d;++c)a.push(b[c])},d.splice=function(a,b,c){c=c||1;for(var d=b,e=a.length-c;d=a&&d=0;r-=2)for(var A=x.length-2;A>=0;A-=2)(z[r]===x[A]&&z[r+1]===x[A+1]||z[r+1]===x[A]&&z[r]===x[A+1])&&x.splice(A,2);var B=l.length;for(r=0;r!==B;r++){var C=l[r];if(!C.collideConnected)for(var A=x.length-2;A>=0;A-=2)(C.bodyA===x[A]&&C.bodyB===x[A+1]||C.bodyB===x[A]&&C.bodyA===x[A+1])&&x.splice(A,2)}this.postBroadphaseEvent.pairs=x,this.emit(this.postBroadphaseEvent),this.postBroadphaseEvent.pairs=null,k.reset(this);for(var r=0,D=x.length;r!==D;r+=2)for(var E=x[r],F=x[r+1],G=0,H=E.shapes.length;G!==H;G++)for(var I=E.shapes[G],J=I.position,K=I.angle,L=0,M=F.shapes.length;L!==M;L++){var N=F.shapes[L],O=N.position,P=N.angle,Q=this.defaultContactMaterial;if(I.material&&N.material){var R=this.getContactMaterial(I.material,N.material);R&&(Q=R)}this.runNarrowphase(k,E,I,J,K,F,N,O,P,Q,this.frictionGravity)}for(var r=0;r!==i;r++){var S=e[r];S._wakeUpAfterNarrowphase&&(S.wakeUp(),S._wakeUpAfterNarrowphase=!1)}if(this.has("endContact")){this.overlapKeeper.getEndOverlaps(y);for(var T=this.endContactEvent,L=y.length;L--;){var U=y[L];T.shapeA=U.shapeA,T.shapeB=U.shapeB,T.bodyA=U.bodyA,T.bodyB=U.bodyB,this.emit(T)}y.length=0}var V=this.preSolveEvent;V.contactEquations=k.contactEquations,V.frictionEquations=k.frictionEquations,this.emit(V),V.contactEquations=V.frictionEquations=null;var B=l.length;for(r=0;r!==B;r++)l[r].update();if(k.contactEquations.length||k.frictionEquations.length||B)if(this.islandSplit){for(p.equations.length=0,s.appendArray(p.equations,k.contactEquations),s.appendArray(p.equations,k.frictionEquations),r=0;r!==B;r++)s.appendArray(p.equations,l[r].equations);p.split(this);for(var r=0;r!==p.islands.length;r++){var W=p.islands[r];W.equations.length&&h.solveIsland(a,W)}}else{for(h.addEquations(k.contactEquations),h.addEquations(k.frictionEquations),r=0;r!==B;r++)h.addEquations(l[r].equations);this.solveConstraints&&h.solve(a,this),h.removeAllEquations()}for(var r=0;r!==i;r++){var S=e[r];S.integrate(a)}for(var r=0;r!==i;r++)e[r].setZeroForce();if(this.emitImpactEvent&&this.has("impact"))for(var X=this.impactEvent,r=0;r!==k.contactEquations.length;r++){var Y=k.contactEquations[r];Y.firstImpact&&(X.bodyA=Y.bodyA,X.bodyB=Y.bodyB,X.shapeA=Y.shapeA,X.shapeB=Y.shapeB,X.contactEquation=Y,this.emit(X))}if(this.sleepMode===d.BODY_SLEEPING)for(r=0;r!==i;r++)e[r].sleepTick(this.time,!1,a);else if(this.sleepMode===d.ISLAND_SLEEPING&&this.islandSplit){for(r=0;r!==i;r++)e[r].sleepTick(this.time,!0,a);for(var r=0;r0,a.frictionCoefficient=k.friction;var p;p=b.type===m.STATIC||b.type===m.KINEMATIC?g.mass:g.type===m.STATIC||g.type===m.KINEMATIC?b.mass:b.mass*g.mass/(b.mass+g.mass),a.slipForce=k.friction*l*p,a.restitution=k.restitution,a.surfaceVelocity=k.surfaceVelocity,a.frictionStiffness=k.frictionStiffness,a.frictionRelaxation=k.frictionRelaxation,a.stiffness=k.stiffness,a.relaxation=k.relaxation,a.contactSkinSize=k.contactSkinSize,a.enabledEquations=b.collisionResponse&&g.collisionResponse&&c.collisionResponse&&h.collisionResponse;var q=a[c.type|h.type],r=0;if(q){var s=c.sensor||h.sensor,t=a.frictionEquations.length;r=c.type=2*y&&(b._wakeUpAfterNarrowphase=!0)}if(g.allowSleep&&g.type===m.DYNAMIC&&g.sleepState===m.SLEEPING&&b.sleepState===m.AWAKE&&b.type!==m.STATIC){var z=f.squaredLength(b.velocity)+Math.pow(b.angularVelocity,2),A=Math.pow(b.sleepSpeedLimit,2);z>=2*A&&(g._wakeUpAfterNarrowphase=!0)}if(this.overlapKeeper.setOverlapping(b,c,g,h),this.has("beginContact")&&this.overlapKeeper.isNewOverlap(c,h)){var B=this.beginContactEvent;if(B.shapeA=c,B.shapeB=h,B.bodyA=b,B.bodyB=g,B.contactEquations.length=0,"number"==typeof r)for(var C=a.contactEquations.length-r;C1)for(var C=a.frictionEquations.length-u;C=0;b--)this.removeConstraint(a[b]);for(var c=this.bodies,b=c.length-1;b>=0;b--)this.removeBody(c[b]);for(var e=this.springs,b=e.length-1;b>=0;b--)this.removeSpring(e[b]);for(var f=this.contactMaterials,b=f.length-1;b>=0;b--)this.removeContactMaterial(f[b]);d.apply(this)};var z=f.create(),A=(f.fromValues(0,0),f.fromValues(0,0));d.prototype.hitTest=function(a,b,c){c=c||0;var d=new m({position:a}),e=new k,l=a,n=0,o=z,p=A;d.addShape(e);for(var q=this.narrowphase,r=[],s=0,t=b.length;s!==t;s++)for(var u=b[s],v=0,w=u.shapes.length;v!==w;v++){var x=u.shapes[v];f.rotate(o,x.position,u.angle),f.add(o,o,u.position);var y=x.angle+u.angle;(x instanceof g&&q.circleParticle(u,x,o,y,d,e,l,n,!0)||x instanceof h&&q.particleConvex(d,e,l,n,u,x,o,y,!0)||x instanceof i&&q.particlePlane(d,e,l,n,u,x,o,y,!0)||x instanceof j&&q.particleCapsule(d,e,l,n,u,x,o,y,!0)||x instanceof k&&f.squaredLength(f.sub(p,o,a))