text: /* Phaser v2.8.8 P2.JS Build - http://phaser.io - @photonstorm - (c) 2016 Photon Storm Ltd. */
  
  !function(t){if("object"==typeof exports)module.exports=t();else{var e;"undefined"!=typeof window?e=window:"undefined"!=typeof global?e=global:"undefined"!=typeof self&&(e=self),e.p2=t()}}(function(){return function t(e,o,i){function n(a,r){if(!o[a]){if(!e[a]){var c="function"==typeof require&&require;if(!r&&c)return c(a,!0);if(s)return s(a,!0);throw new Error("Cannot find module '"+a+"'")}var h=o[a]={exports:{}};e[a][0].call(h.exports,function(t){var o=e[a][1][t];return n(o||t)},h,h.exports,t,e,o,i)}return o[a].exports}for(var s="function"==typeof require&&require,a=0;a<i.length;a++)n(i[a]);return n}({1:[function(t,e,o){function i(){}var n=t("./Scalar");e.exports=i,i.lineInt=function(t,e,o){o=o||0;var i,s,a,r,c,h,l,p=[0,0];return i=t[1][1]-t[0][1],s=t[0][0]-t[1][0],a=i*t[0][0]+s*t[0][1],r=e[1][1]-e[0][1],c=e[0][0]-e[1][0],h=r*e[0][0]+c*e[0][1],l=i*c-r*s,n.eq(l,0,o)||(p[0]=(c*a-s*h)/l,p[1]=(i*h-r*a)/l),p},i.segmentsIntersect=function(t,e,o,i){var n=e[0]-t[0],s=e[1]-t[1],a=i[0]-o[0],r=i[1]-o[1];if(a*s-r*n==0)return!1;var c=(n*(o[1]-t[1])+s*(t[0]-o[0]))/(a*s-r*n),h=(a*(t[1]-o[1])+r*(o[0]-t[0]))/(r*n-a*s);return c>=0&&c<=1&&h>=0&&h<=1}},{"./Scalar":4}],2:[function(t,e,o){function i(){}e.exports=i,i.area=function(t,e,o){return(e[0]-t[0])*(o[1]-t[1])-(o[0]-t[0])*(e[1]-t[1])},i.left=function(t,e,o){return i.area(t,e,o)>0},i.leftOn=function(t,e,o){return i.area(t,e,o)>=0},i.right=function(t,e,o){return i.area(t,e,o)<0},i.rightOn=function(t,e,o){return i.area(t,e,o)<=0};var n=[],s=[];i.collinear=function(t,e,o,a){if(a){var r=n,c=s;r[0]=e[0]-t[0],r[1]=e[1]-t[1],c[0]=o[0]-e[0],c[1]=o[1]-e[1];var h=r[0]*c[0]+r[1]*c[1],l=Math.sqrt(r[0]*r[0]+r[1]*r[1]),p=Math.sqrt(c[0]*c[0]+c[1]*c[1]);return Math.acos(h/(l*p))<a}return 0==i.area(t,e,o)},i.sqdist=function(t,e){var o=e[0]-t[0],i=e[1]-t[1];return o*o+i*i}},{}],3:[function(t,e,o){function i(){this.vertices=[]}function n(t,e,o,i,n){n=n||0;var s=e[1]-t[1],a=t[0]-e[0],c=s*t[0]+a*t[1],h=i[1]-o[1],l=o[0]-i[0],p=h*o[0]+l*o[1],u=s*l-h*a;return r.eq(u,0,n)?[0,0]:[(l*c-a*p)/u,(s*p-h*c)/u]}var s=t("./Line"),a=t("./Point"),r=t("./Scalar");e.exports=i,i.prototype.at=function(t){var e=this.vertices,o=e.length;return e[t<0?t%o+o:t%o]},i.prototype.first=function(){return this.vertices[0]},i.prototype.last=function(){return this.vertices[this.vertices.length-1]},i.prototype.clear=function(){this.vertices.length=0},i.prototype.append=function(t,e,o){if(void 0===e)throw new Error("From is not given!");if(void 0===o)throw new Error("To is not given!");if(o-1<e)throw new Error("lol1");if(o>t.vertices.length)throw new Error("lol2");if(e<0)throw new Error("lol3");for(var i=e;i<o;i++)this.vertices.push(t.vertices[i])},i.prototype.makeCCW=function(){for(var t=0,e=this.vertices,o=1;o<this.vertices.length;++o)(e[o][1]<e[t][1]||e[o][1]==e[t][1]&&e[o][0]>e[t][0])&&(t=o);a.left(this.at(t-1),this.at(t),this.at(t+1))||this.reverse()},i.prototype.reverse=function(){for(var t=[],e=0,o=this.vertices.length;e!==o;e++)t.push(this.vertices.pop());this.vertices=t},i.prototype.isReflex=function(t){return a.right(this.at(t-1),this.at(t),this.at(t+1))};var c=[],h=[];i.prototype.canSee=function(t,e){var o,i,n=c,r=h;if(a.leftOn(this.at(t+1),this.at(t),this.at(e))&&a.rightOn(this.at(t-1),this.at(t),this.at(e)))return!1;i=a.sqdist(this.at(t),this.at(e));for(var l=0;l!==this.vertices.length;++l)if((l+1)%this.vertices.length!==t&&l!==t&&a.leftOn(this.at(t),this.at(e),this.at(l+1))&&a.rightOn(this.at(t),this.at(e),this.at(l))&&(n[0]=this.at(t),n[1]=this.at(e),r[0]=this.at(l),r[1]=this.at(l+1),o=s.lineInt(n,r),a.sqdist(this.at(t),o)<i))return!1;return!0},i.prototype.copy=function(t,e,o){var n=o||new i;if(n.clear(),t<e)for(s=t;s<=e;s++)n.vertices.push(this.vertices[s]);else{for(s=0;s<=e;s++)n.vertices.push(this.vertices[s]);for(var s=t;s<this.vertices.length;s++)n.vertices.push(this.vertices[s])}return n},i.prototype.getCutEdges=function(){for(var t=[],e=[],o=[],n=new i,s=Number.MAX_VALUE,a=0;a<this.vertices.length;++a)if(this.isReflex(a))for(var r=0;r<this.vertices.length;++r)if(this.canSee(a,r)){e=this.copy(a,r,n).getCutEdges(),o=this.copy(r,a,n).getCutEdges();for(var c=0;c<o.length;c++)e.push(o[c]);e.length<s&&(t=e,s=e.length,t.push([this.at(a),this.at(r)]))}return t},i.prototype.decomp=function(){var t=this.getCutEdges();return t.length>0?this.slice(t):[this]},i.prototype.slice=function(t){if(0==t.length)return[this];if(t instanceof Array&&t.length&&t[0]instanceof Array&&2==t[0].length&&t[0][0]instanceof Array){for(var e=[this],o=0;o<t.length;o++)for(var i=t[o],n=0;n<e.length;n++){var s=e[n].slice(i);if(s){e.splice(n,1),e.push(s[0],s[1]);break}}return e}var i=t,o=this.vertices.indexOf(i[0]),n=this.vertices.indexOf(i[1]);return-1!=o&&-1!=n&&[this.copy(o,n),this.copy(n,o)]},i.prototype.isSimple=function(){for(var t=this.vertices,e=0;e<t.length-1;e++)for(var o=0;o<e-1;o++)if(s.segmentsIntersect(t[e],t[e+1],t[o],t[o+1]))return!1;for(e=1;e<t.length-2;e++)if(s.segmentsIntersect(t[0],t[t.length-1],t[e],t[e+1]))return!1;return!0},i.prototype.quickDecomp=function(t,e,o,s,r,c){r=r||100,c=c||0,s=s||25,t=void 0!==t?t:[],e=e||[],o=o||[];var h=[0,0],l=[0,0],p=[0,0],u=0,d=0,f=0,v=0,y=0,m=0,g=0,A=new i,b=new i,E=this,B=this.vertices;if(B.length<3)return t;if(++c>r)return console.warn("quickDecomp: max level ("+r+") reached."),t;for(var q=0;q<this.vertices.length;++q)if(E.isReflex(q)){e.push(E.vertices[q]),u=d=Number.MAX_VALUE;for(P=0;P<this.vertices.length;++P)a.left(E.at(q-1),E.at(q),E.at(P))&&a.rightOn(E.at(q-1),E.at(q),E.at(P-1))&&(p=n(E.at(q-1),E.at(q),E.at(P),E.at(P-1)),a.right(E.at(q+1),E.at(q),p)&&(f=a.sqdist(E.vertices[q],p))<d&&(d=f,l=p,m=P)),a.left(E.at(q+1),E.at(q),E.at(P+1))&&a.rightOn(E.at(q+1),E.at(q),E.at(P))&&(p=n(E.at(q+1),E.at(q),E.at(P),E.at(P+1)),a.left(E.at(q-1),E.at(q),p)&&(f=a.sqdist(E.vertices[q],p))<u&&(u=f,h=p,y=P));if(m==(y+1)%this.vertices.length)p[0]=(l[0]+h[0])/2,p[1]=(l[1]+h[1])/2,o.push(p),q<y?(A.append(E,q,y+1),A.vertices.push(p),b.vertices.push(p),0!=m&&b.append(E,m,E.vertices.length),b.append(E,0,q+1)):(0!=q&&A.append(E,q,E.vertices.length),A.append(E,0,y+1),A.vertices.push(p),b.vertices.push(p),b.append(E,m,q+1));else{if(m>y&&(y+=this.vertices.length),v=Number.MAX_VALUE,y<m)return t;for(var P=m;P<=y;++P)a.leftOn(E.at(q-1),E.at(q),E.at(P))&&a.rightOn(E.at(q+1),E.at(q),E.at(P))&&(f=a.sqdist(E.at(q),E.at(P)))<v&&(v=f,g=P%this.vertices.length);q<g?(A.append(E,q,g+1),0!=g&&b.append(E,g,B.length),b.append(E,0,q+1)):(0!=q&&A.append(E,q,B.length),A.append(E,0,g+1),b.append(E,g,q+1))}return A.vertices.length<b.vertices.length?(A.quickDecomp(t,e,o,s,r,c),b.quickDecomp(t,e,o,s,r,c)):(b.quickDecomp(t,e,o,s,r,c),A.quickDecomp(t,e,o,s,r,c)),t}return t.push(this),t},i.prototype.removeCollinearPoints=function(t){for(var e=0,o=this.vertices.length-1;this.vertices.length>3&&o>=0;--o)a.collinear(this.at(o-1),this.at(o),this.at(o+1),t)&&(this.vertices.splice(o%this.vertices.length,1),o--,e++);return e}},{"./Line":1,"./Point":2,"./Scalar":4}],4:[function(t,e,o){function i(){}e.exports=i,i.eq=function(t,e,o){return o=o||0,Math.abs(t-e)<o}},{}],5:[function(t,e,o){e.exports={Polygon:t("./Polygon"),Point:t("./Point")}},{"./Point":2,"./Polygon":3}],6:[function(t,e,o){e.exports={name:"p2",version:"0.7.1",description:"A JavaScript 2D physics engine.",author:"Stefan Hedman <schteppe@gmail.com> (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.1"}}},{}],7:[function(t,e,o){function i(t){this.lowerBound=n.create(),t&&t.lowerBound&&n.copy(this.lowerBound,t.lowerBound),this.upperBound=n.create(),t&&t.upperBound&&n.copy(this.upperBound,t.upperBound)}var n=t("../math/vec2");t("../utils/Utils");e.exports=i;var s=n.create();i.prototype.setFromPoints=function(t,e,o,i){var a=this.lowerBound,r=this.upperBound;"number"!=typeof o&&(o=0),0!==o?n.rotate(a,t[0],o):n.copy(a,t[0]),n.copy(r,a);for(var c=Math.cos(o),h=Math.sin(o),l=1;l<t.length;l++){var p=t[l];if(0!==o){var u=p[0],d=p[1];s[0]=c*u-h*d,s[1]=h*u+c*d,p=s}for(var f=0;f<2;f++)p[f]>r[f]&&(r[f]=p[f]),p[f]<a[f]&&(a[f]=p[f])}e&&(n.add(this.lowerBound,this.lowerBound,e),n.add(this.upperBound,this.upperBound,e)),i&&(this.lowerBound[0]-=i,this.lowerBound[1]-=i,this.upperBound[0]+=i,this.upperBound[1]+=i)},i.prototype.copy=function(t){n.copy(this.lowerBound,t.lowerBound),n.copy(this.upperBound,t.upperBound)},i.prototype.extend=function(t){for(var e=2;e--;){var o=t.lowerBound[e];this.lowerBound[e]>o&&(this.lowerBound[e]=o);var i=t.upperBound[e];this.upperBound[e]<i&&(this.upperBound[e]=i)}},i.prototype.overlaps=function(t){var e=this.lowerBound,o=this.upperBound,i=t.lowerBound,n=t.upperBound;return(i[0]<=o[0]&&o[0]<=n[0]||e[0]<=n[0]&&n[0]<=o[0])&&(i[1]<=o[1]&&o[1]<=n[1]||e[1]<=n[1]&&n[1]<=o[1])},i.prototype.containsPoint=function(t){var e=this.lowerBound,o=this.upperBound;return e[0]<=t[0]&&t[0]<=o[0]&&e[1]<=t[1]&&t[1]<=o[1]},i.prototype.overlapsRay=function(t){var e=1/t.direction[0],o=1/t.direction[1],i=(this.lowerBound[0]-t.from[0])*e,n=(this.upperBound[0]-t.from[0])*e,s=(this.lowerBound[1]-t.from[1])*o,a=(this.upperBound[1]-t.from[1])*o,r=Math.max(Math.max(Math.min(i,n),Math.min(s,a))),c=Math.min(Math.min(Math.max(i,n),Math.max(s,a)));return c<0?-1:r>c?-1:r}},{"../math/vec2":30,"../utils/Utils":57}],8:[function(t,e,o){function i(t){this.type=t,this.result=[],this.world=null,this.boundingVolumeType=i.AABB}var n=t("../math/vec2"),s=t("../objects/Body");e.exports=i,i.AABB=1,i.BOUNDING_CIRCLE=2,i.prototype.setWorld=function(t){this.world=t},i.prototype.getCollisionPairs=function(t){};var a=n.create();i.boundingRadiusCheck=function(t,e){n.sub(a,t.position,e.position);var o=n.squaredLength(a),i=t.boundingRadius+e.boundingRadius;return o<=i*i},i.aabbCheck=function(t,e){return t.getAABB().overlaps(e.getAABB())},i.prototype.boundingVolumeCheck=function(t,e){var o;switch(this.boundingVolumeType){case i.BOUNDING_CIRCLE:o=i.boundingRadiusCheck(t,e);break;case i.AABB:o=i.aabbCheck(t,e);break;default:throw new Error("Bounding volume type not recognized: "+this.boundingVolumeType)}return o},i.canCollide=function(t,e){var o=s.KINEMATIC,i=s.STATIC;return(t.type!==i||e.type!==i)&&(!(t.type===o&&e.type===i||t.type===i&&e.type===o)&&((t.type!==o||e.type!==o)&&((t.sleepState!==s.SLEEPING||e.sleepState!==s.SLEEPING)&&!(t.sleepState===s.SLEEPING&&e.type===i||e.sleepState===s.SLEEPING&&t.type===i))))},i.NAIVE=1,i.SAP=2},{"../math/vec2":30,"../objects/Body":31}],9:[function(t,e,o){function i(){n.call(this,n.NAIVE)}t("../shapes/Circle"),t("../shapes/Plane"),t("../shapes/Shape"),t("../shapes/Particle");var n=t("../collision/Broadphase");t("../math/vec2");e.exports=i,(i.prototype=new n).constructor=i,i.prototype.getCollisionPairs=function(t){var e=t.bodies,o=this.result;o.length=0;for(var i=0,s=e.length;i!==s;i++)for(var a=e[i],r=0;r<i;r++){var c=e[r];n.canCollide(a,c)&&this.boundingVolumeCheck(a,c)&&o.push(a,c)}return o},i.prototype.aabbQuery=function(t,e,o){o=o||[];for(var i=t.bodies,n=0;n<i.length;n++){var s=i[n];s.aabbNeedsUpdate&&s.updateAABB(),s.aabb.overlaps(e)&&o.push(s)}return o}},{"../collision/Broadphase":8,"../math/vec2":30,"../shapes/Circle":39,"../shapes/Particle":43,"../shapes/Plane":44,"../shapes/Shape":45}],10:[function(t,e,o){function i(){this.contactEquations=[],this.frictionEquations=[],this.enableFriction=!0,this.enabledEquations=!0,this.slipForce=10,this.frictionCoefficient=.3,this.surfaceVelocity=0,this.contactEquationPool=new l({size:32}),this.frictionEquationPool=new p({size:64}),this.restitution=0,this.stiffness=d.DEFAULT_STIFFNESS,this.relaxation=d.DEFAULT_RELAXATION,this.frictionStiffness=d.DEFAULT_STIFFNESS,this.frictionRelaxation=d.DEFAULT_RELAXATION,this.enableFrictionReduction=!0,this.collidingBodiesLastStep=new u,this.contactSkinSize=.01}function n(t,e){a.set(t.vertices[0],.5*-e.length,-e.radius),a.set(t.vertices[1],.5*e.length,-e.radius),a.set(t.vertices[2],.5*e.length,e.radius),a.set(t.vertices[3],.5*-e.length,e.radius)}function s(t,e,o,i){for(var n=X,s=z,h=Y,l=K,p=t,u=e.vertices,d=null,f=0;f!==u.length+1;f++){var v=u[f%u.length],y=u[(f+1)%u.length];a.rotate(n,v,i),a.rotate(s,y,i),c(n,n,o),c(s,s,o),r(h,n,p),r(l,s,p);var m=a.crossLength(h,l);if(null===d&&(d=m),m*d<=0)return!1;d=m}return!0}var a=t("../math/vec2"),r=a.sub,c=a.add,h=a.dot,l=(t("../utils/Utils"),t("../utils/ContactEquationPool")),p=t("../utils/FrictionEquationPool"),u=t("../utils/TupleDictionary"),d=t("../equations/Equation"),f=(t("../equations/ContactEquation"),t("../equations/FrictionEquation"),t("../shapes/Circle")),v=t("../shapes/Convex"),y=t("../shapes/Shape"),m=(t("../objects/Body"),t("../shapes/Box"));e.exports=i;var g=a.fromValues(0,1),A=a.fromValues(0,0),b=a.fromValues(0,0),E=a.fromValues(0,0),B=a.fromValues(0,0),q=a.fromValues(0,0),P=a.fromValues(0,0),w=a.fromValues(0,0),S=a.fromValues(0,0),C=a.fromValues(0,0),L=a.fromValues(0,0),x=a.fromValues(0,0),F=a.fromValues(0,0),M=a.fromValues(0,0),I=a.fromValues(0,0),R=a.fromValues(0,0),V=a.fromValues(0,0),T=a.fromValues(0,0),N=a.fromValues(0,0),G=[],O=a.create(),U=a.create();i.prototype.bodiesOverlap=function(t,e){for(var o=O,i=U,n=0,s=t.shapes.length;n!==s;n++){var a=t.shapes[n];t.toWorldFrame(o,a.position);for(var r=0,c=e.shapes.length;r!==c;r++){var h=e.shapes[r];if(e.toWorldFrame(i,h.position),this[a.type|h.type](t,a,o,a.angle+t.angle,e,h,i,h.angle+e.angle,!0))return!0}}return!1},i.prototype.collidedLastStep=function(t,e){var o=0|t.id,i=0|e.id;return!!this.collidingBodiesLastStep.get(o,i)},i.prototype.reset=function(){this.collidingBodiesLastStep.reset();for(var t=this.contactEquations,e=t.length;e--;){var o=t[e],i=o.bodyA.id,n=o.bodyB.id;this.collidingBodiesLastStep.set(i,n,!0)}for(var s=this.contactEquations,a=this.frictionEquations,r=0;r<s.length;r++)this.contactEquationPool.release(s[r]);for(r=0;r<a.length;r++)this.frictionEquationPool.release(a[r]);this.contactEquations.length=this.frictionEquations.length=0},i.prototype.createContactEquation=function(t,e,o,i){var n=this.contactEquationPool.get();return n.bodyA=t,n.bodyB=e,n.shapeA=o,n.shapeB=i,n.restitution=this.restitution,n.firstImpact=!this.collidedLastStep(t,e),n.stiffness=this.stiffness,n.relaxation=this.relaxation,n.needsUpdate=!0,n.enabled=this.enabledEquations,n.offset=this.contactSkinSize,n},i.prototype.createFrictionEquation=function(t,e,o,i){var n=this.frictionEquationPool.get();return n.bodyA=t,n.bodyB=e,n.shapeA=o,n.shapeB=i,n.setSlipForce(this.slipForce),n.frictionCoefficient=this.frictionCoefficient,n.relativeVelocity=this.surfaceVelocity,n.enabled=this.enabledEquations,n.needsUpdate=!0,n.stiffness=this.frictionStiffness,n.relaxation=this.frictionRelaxation,n.contactEquations.length=0,n},i.prototype.createFrictionFromContact=function(t){var e=this.createFrictionEquation(t.bodyA,t.bodyB,t.shapeA,t.shapeB);return a.copy(e.contactPointA,t.contactPointA),a.copy(e.contactPointB,t.contactPointB),a.rotate90cw(e.t,t.normalA),e.contactEquations.push(t),e},i.prototype.createFrictionFromAverage=function(t){var e=this.contactEquations[this.contactEquations.length-1],o=this.createFrictionEquation(e.bodyA,e.bodyB,e.shapeA,e.shapeB),i=e.bodyA;e.bodyB;a.set(o.contactPointA,0,0),a.set(o.contactPointB,0,0),a.set(o.t,0,0);for(var n=0;n!==t;n++)(e=this.contactEquations[this.contactEquations.length-1-n]).bodyA===i?(a.add(o.t,o.t,e.normalA),a.add(o.contactPointA,o.contactPointA,e.contactPointA),a.add(o.contactPointB,o.contactPointB,e.contactPointB)):(a.sub(o.t,o.t,e.normalA),a.add(o.contactPointA,o.contactPointA,e.contactPointB),a.add(o.contactPointB,o.contactPointB,e.contactPointA)),o.contactEquations.push(e);var s=1/t;return a.scale(o.contactPointA,o.contactPointA,s),a.scale(o.contactPointB,o.contactPointB,s),a.normalize(o.t,o.t),a.rotate90cw(o.t,o.t),o},i.prototype[y.LINE|y.CONVEX]=i.prototype.convexLine=function(t,e,o,i,n,s,a,r,c){return!c&&0},i.prototype[y.LINE|y.BOX]=i.prototype.lineBox=function(t,e,o,i,n,s,a,r,c){return!c&&0};var k=new m({width:1,height:1}),_=a.create();i.prototype[y.CAPSULE|y.CONVEX]=i.prototype[y.CAPSULE|y.BOX]=i.prototype.convexCapsule=function(t,e,o,i,s,r,c,h,l){var p=_;a.set(p,r.length/2,0),a.rotate(p,p,h),a.add(p,p,c);var u=this.circleConvex(s,r,p,h,t,e,o,i,l,r.radius);a.set(p,-r.length/2,0),a.rotate(p,p,h),a.add(p,p,c);var d=this.circleConvex(s,r,p,h,t,e,o,i,l,r.radius);if(l&&(u||d))return!0;var f=k;return n(f,r),this.convexConvex(t,e,o,i,s,f,c,h,l)+u+d},i.prototype[y.CAPSULE|y.LINE]=i.prototype.lineCapsule=function(t,e,o,i,n,s,a,r,c){return!c&&0};var D=a.create(),W=a.create(),j=new m({width:1,height:1});i.prototype[y.CAPSULE|y.CAPSULE]=i.prototype.capsuleCapsule=function(t,e,o,i,s,r,c,h,l){for(var p=D,u=W,d=0,f=0;f<2;f++){a.set(p,(0===f?-1:1)*e.length/2,0),a.rotate(p,p,i),a.add(p,p,o);for(var v=0;v<2;v++){a.set(u,(0===v?-1:1)*r.length/2,0),a.rotate(u,u,h),a.add(u,u,c),this.enableFrictionReduction&&(A=this.enableFriction,this.enableFriction=!1);var y=this.circleCircle(t,e,p,i,s,r,u,h,l,e.radius,r.radius);if(this.enableFrictionReduction&&(this.enableFriction=A),l&&y)return!0;d+=y}}this.enableFrictionReduction&&(A=this.enableFriction,this.enableFriction=!1);var m=j;n(m,e);var g=this.convexCapsule(t,m,o,i,s,r,c,h,l);if(this.enableFrictionReduction&&(this.enableFriction=A),l&&g)return!0;if(d+=g,this.enableFrictionReduction){var A=this.enableFriction;this.enableFriction=!1}n(m,r);var b=this.convexCapsule(s,m,c,h,t,e,o,i,l);return this.enableFrictionReduction&&(this.enableFriction=A),!(!l||!b)||(d+=b,this.enableFrictionReduction&&d&&this.enableFriction&&this.frictionEquations.push(this.createFrictionFromAverage(d)),d)},i.prototype[y.LINE|y.LINE]=i.prototype.lineLine=function(t,e,o,i,n,s,a,r,c){return!c&&0},i.prototype[y.PLANE|y.LINE]=i.prototype.planeLine=function(t,e,o,i,n,s,l,p,u){var d=A,f=b,v=E,y=B,m=q,L=P,x=w,F=S,M=C,I=G,R=0;a.set(d,-s.length/2,0),a.set(f,s.length/2,0),a.rotate(v,d,p),a.rotate(y,f,p),c(v,v,l),c(y,y,l),a.copy(d,v),a.copy(f,y),r(m,f,d),a.normalize(L,m),a.rotate90cw(M,L),a.rotate(F,g,i),I[0]=d,I[1]=f;for(var V=0;V<I.length;V++){var T=I[V];r(x,T,o);var N=h(x,F);if(N<0){if(u)return!0;var O=this.createContactEquation(t,n,e,s);R++,a.copy(O.normalA,F),a.normalize(O.normalA,O.normalA),a.scale(x,F,N),r(O.contactPointA,T,x),r(O.contactPointA,O.contactPointA,t.position),r(O.contactPointB,T,l),c(O.contactPointB,O.contactPointB,l),r(O.contactPointB,O.contactPointB,n.position),this.contactEquations.push(O),this.enableFrictionReduction||this.enableFriction&&this.frictionEquations.push(this.createFrictionFromContact(O))}}return!u&&(this.enableFrictionReduction||R&&this.enableFriction&&this.frictionEquations.push(this.createFrictionFromAverage(R)),R)},i.prototype[y.PARTICLE|y.CAPSULE]=i.prototype.particleCapsule=function(t,e,o,i,n,s,a,r,c){return this.circleLine(t,e,o,i,n,s,a,r,c,s.radius,0)},i.prototype[y.CIRCLE|y.LINE]=i.prototype.circleLine=function(t,e,o,i,n,s,l,p,u,d,f){var d=d||0,f=void 0!==f?f:e.radius,v=A,y=b,m=E,g=B,R=q,V=P,T=w,N=S,O=C,U=L,k=x,_=F,D=M,W=I,j=G;a.set(N,-s.length/2,0),a.set(O,s.length/2,0),a.rotate(U,N,p),a.rotate(k,O,p),c(U,U,l),c(k,k,l),a.copy(N,U),a.copy(O,k),r(V,O,N),a.normalize(T,V),a.rotate90cw(R,T),r(_,o,N);var X=h(_,R);r(g,N,l),r(D,o,l);var z=f+d;if(Math.abs(X)<z){a.scale(v,R,X),r(m,o,v),a.scale(y,R,h(R,D)),a.normalize(y,y),a.scale(y,y,d),c(m,m,y);var Y=h(T,m),K=h(T,N),H=h(T,O);if(Y>K&&Y<H){if(u)return!0;Q=this.createContactEquation(t,n,e,s);return a.scale(Q.normalA,v,-1),a.normalize(Q.normalA,Q.normalA),a.scale(Q.contactPointA,Q.normalA,f),c(Q.contactPointA,Q.contactPointA,o),r(Q.contactPointA,Q.contactPointA,t.position),r(Q.contactPointB,m,l),c(Q.contactPointB,Q.contactPointB,l),r(Q.contactPointB,Q.contactPointB,n.position),this.contactEquations.push(Q),this.enableFriction&&this.frictionEquations.push(this.createFrictionFromContact(Q)),1}}j[0]=N,j[1]=O;for(var Z=0;Z<j.length;Z++){var J=j[Z];if(r(_,J,o),a.squaredLength(_)<Math.pow(z,2)){if(u)return!0;var Q=this.createContactEquation(t,n,e,s);return a.copy(Q.normalA,_),a.normalize(Q.normalA,Q.normalA),a.scale(Q.contactPointA,Q.normalA,f),c(Q.contactPointA,Q.contactPointA,o),r(Q.contactPointA,Q.contactPointA,t.position),r(Q.contactPointB,J,l),a.scale(W,Q.normalA,-d),c(Q.contactPointB,Q.contactPointB,W),c(Q.contactPointB,Q.contactPointB,l),r(Q.contactPointB,Q.contactPointB,n.position),this.contactEquations.push(Q),this.enableFriction&&this.frictionEquations.push(this.createFrictionFromContact(Q)),1}}return 0},i.prototype[y.CIRCLE|y.CAPSULE]=i.prototype.circleCapsule=function(t,e,o,i,n,s,a,r,c){return this.circleLine(t,e,o,i,n,s,a,r,c,s.radius)},i.prototype[y.CIRCLE|y.CONVEX]=i.prototype[y.CIRCLE|y.BOX]=i.prototype.circleConvex=function(t,e,o,i,n,h,l,p,u,d){for(var d="number"==typeof d?d:e.radius,f=A,v=b,y=E,m=B,g=q,P=L,w=x,S=M,C=I,F=R,T=V,N=!1,G=Number.MAX_VALUE,O=h.vertices,U=0;U!==O.length+1;U++){var k=O[U%O.length],_=O[(U+1)%O.length];if(a.rotate(f,k,p),a.rotate(v,_,p),c(f,f,l),c(v,v,l),r(y,v,f),a.normalize(m,y),a.rotate90cw(g,m),a.scale(C,g,-e.radius),c(C,C,o),s(C,h,l,p)){a.sub(F,f,C);var D=Math.abs(a.dot(F,g));D<G&&(a.copy(T,C),G=D,a.scale(S,g,D),a.add(S,S,C),N=!0)}}if(N){if(u)return!0;j=this.createContactEquation(t,n,e,h);return a.sub(j.normalA,T,o),a.normalize(j.normalA,j.normalA),a.scale(j.contactPointA,j.normalA,d),c(j.contactPointA,j.contactPointA,o),r(j.contactPointA,j.contactPointA,t.position),r(j.contactPointB,S,l),c(j.contactPointB,j.contactPointB,l),r(j.contactPointB,j.contactPointB,n.position),this.contactEquations.push(j),this.enableFriction&&this.frictionEquations.push(this.createFrictionFromContact(j)),1}if(d>0)for(U=0;U<O.length;U++){var W=O[U];if(a.rotate(w,W,p),c(w,w,l),r(P,w,o),a.squaredLength(P)<Math.pow(d,2)){if(u)return!0;var j=this.createContactEquation(t,n,e,h);return a.copy(j.normalA,P),a.normalize(j.normalA,j.normalA),a.scale(j.contactPointA,j.normalA,d),c(j.contactPointA,j.contactPointA,o),r(j.contactPointA,j.contactPointA,t.position),r(j.contactPointB,w,l),c(j.contactPointB,j.contactPointB,l),r(j.contactPointB,j.contactPointB,n.position),this.contactEquations.push(j),this.enableFriction&&this.frictionEquations.push(this.createFrictionFromContact(j)),1}}return 0};var X=a.create(),z=a.create(),Y=a.create(),K=a.create();i.prototype[y.PARTICLE|y.CONVEX]=i.prototype[y.PARTICLE|y.BOX]=i.prototype.particleConvex=function(t,e,o,i,n,l,p,u,d){var f=A,v=b,y=E,m=B,g=q,S=P,C=w,x=L,F=M,I=T,R=N,V=Number.MAX_VALUE,G=!1,O=l.vertices;if(!s(o,l,p,u))return 0;if(d)return!0;for(var U=0;U!==O.length+1;U++){var k=O[U%O.length],_=O[(U+1)%O.length];a.rotate(f,k,u),a.rotate(v,_,u),c(f,f,p),c(v,v,p),r(y,v,f),a.normalize(m,y),a.rotate90cw(g,m),r(x,o,f);h(x,g);r(S,f,p),r(C,o,p),a.sub(I,f,o);var D=Math.abs(a.dot(I,g));D<V&&(V=D,a.scale(F,g,D),a.add(F,F,o),a.copy(R,g),G=!0)}if(G){var W=this.createContactEquation(t,n,e,l);return a.scale(W.normalA,R,-1),a.normalize(W.normalA,W.normalA),a.set(W.contactPointA,0,0),c(W.contactPointA,W.contactPointA,o),r(W.contactPointA,W.contactPointA,t.position),r(W.contactPointB,F,p),c(W.contactPointB,W.contactPointB,p),r(W.contactPointB,W.contactPointB,n.position),this.contactEquations.push(W),this.enableFriction&&this.frictionEquations.push(this.createFrictionFromContact(W)),1}return 0},i.prototype[y.CIRCLE]=i.prototype.circleCircle=function(t,e,o,i,n,s,h,l,p,u,d){var f=A,u=u||e.radius,d=d||s.radius;r(f,o,h);var v=u+d;if(a.squaredLength(f)>Math.pow(v,2))return 0;if(p)return!0;var y=this.createContactEquation(t,n,e,s);return r(y.normalA,h,o),a.normalize(y.normalA,y.normalA),a.scale(y.contactPointA,y.normalA,u),a.scale(y.contactPointB,y.normalA,-d),c(y.contactPointA,y.contactPointA,o),r(y.contactPointA,y.contactPointA,t.position),c(y.contactPointB,y.contactPointB,h),r(y.contactPointB,y.contactPointB,n.position),this.contactEquations.push(y),this.enableFriction&&this.frictionEquations.push(this.createFrictionFromContact(y)),1},i.prototype[y.PLANE|y.CONVEX]=i.prototype[y.PLANE|y.BOX]=i.prototype.planeConvex=function(t,e,o,i,n,s,l,p,u){var d=A,f=b,v=E,y=0;a.rotate(f,g,i);for(var m=0;m!==s.vertices.length;m++){var B=s.vertices[m];if(a.rotate(d,B,p),c(d,d,l),r(v,d,o),h(v,f)<=0){if(u)return!0;y++;var q=this.createContactEquation(t,n,e,s);r(v,d,o),a.copy(q.normalA,f);var P=h(v,q.normalA);a.scale(v,q.normalA,P),r(q.contactPointB,d,n.position),r(q.contactPointA,d,v),r(q.contactPointA,q.contactPointA,t.position),this.contactEquations.push(q),this.enableFrictionReduction||this.enableFriction&&this.frictionEquations.push(this.createFrictionFromContact(q))}}return this.enableFrictionReduction&&this.enableFriction&&y&&this.frictionEquations.push(this.createFrictionFromAverage(y)),y},i.prototype[y.PARTICLE|y.PLANE]=i.prototype.particlePlane=function(t,e,o,i,n,s,c,l,p){var u=A,d=b;l=l||0,r(u,o,c),a.rotate(d,g,l);var f=h(u,d);if(f>0)return 0;if(p)return!0;var v=this.createContactEquation(n,t,s,e);return a.copy(v.normalA,d),a.scale(u,v.normalA,f),r(v.contactPointA,o,u),r(v.contactPointA,v.contactPointA,n.position),r(v.contactPointB,o,t.position),this.contactEquations.push(v),this.enableFriction&&this.frictionEquations.push(this.createFrictionFromContact(v)),1},i.prototype[y.CIRCLE|y.PARTICLE]=i.prototype.circleParticle=function(t,e,o,i,n,s,h,l,p){var u=A;if(r(u,h,o),a.squaredLength(u)>Math.pow(e.radius,2))return 0;if(p)return!0;var d=this.createContactEquation(t,n,e,s);return a.copy(d.normalA,u),a.normalize(d.normalA,d.normalA),a.scale(d.contactPointA,d.normalA,e.radius),c(d.contactPointA,d.contactPointA,o),r(d.contactPointA,d.contactPointA,t.position),r(d.contactPointB,h,n.position),this.contactEquations.push(d),this.enableFriction&&this.frictionEquations.push(this.createFrictionFromContact(d)),1};var H=new f({radius:1}),Z=a.create(),J=a.create();a.create();i.prototype[y.PLANE|y.CAPSULE]=i.prototype.planeCapsule=function(t,e,o,i,n,s,r,h,l){var p=Z,u=J,d=H;a.set(p,-s.length/2,0),a.rotate(p,p,h),c(p,p,r),a.set(u,s.length/2,0),a.rotate(u,u,h),c(u,u,r),d.radius=s.radius;var f;this.enableFrictionReduction&&(f=this.enableFriction,this.enableFriction=!1);var v=this.circlePlane(n,d,p,0,t,e,o,i,l),y=this.circlePlane(n,d,u,0,t,e,o,i,l);if(this.enableFrictionReduction&&(this.enableFriction=f),l)return v||y;var m=v+y;return this.enableFrictionReduction&&m&&this.frictionEquations.push(this.createFrictionFromAverage(m)),m},i.prototype[y.CIRCLE|y.PLANE]=i.prototype.circlePlane=function(t,e,o,i,n,s,l,p,u){var d=t,f=e,v=o,y=n,m=l,B=p;B=B||0;var q=A,P=b,w=E;r(q,v,m),a.rotate(P,g,B);var S=h(P,q);if(S>f.radius)return 0;if(u)return!0;var C=this.createContactEquation(y,d,s,e);return a.copy(C.normalA,P),a.scale(C.contactPointB,C.normalA,-f.radius),c(C.contactPointB,C.contactPointB,v),r(C.contactPointB,C.contactPointB,d.position),a.scale(w,C.normalA,S),r(C.contactPointA,q,w),c(C.contactPointA,C.contactPointA,m),r(C.contactPointA,C.contactPointA,y.position),this.contactEquations.push(C),this.enableFriction&&this.frictionEquations.push(this.createFrictionFromContact(C)),1},i.prototype[y.CONVEX]=i.prototype[y.CONVEX|y.BOX]=i.prototype[y.BOX]=i.prototype.convexConvex=function(t,e,o,n,s,l,p,u,d,f){var v=A,y=b,m=E,g=B,P=q,L=w,x=S,F=C,M=0,f="number"==typeof f?f:0;if(!i.findSeparatingAxis(e,o,n,l,p,u,v))return 0;r(x,p,o),h(v,x)>0&&a.scale(v,v,-1);var I=i.getClosestEdge(e,n,v,!0),R=i.getClosestEdge(l,u,v);if(-1===I||-1===R)return 0;for(var V=0;V<2;V++){var T=I,N=R,G=e,O=l,U=o,k=p,_=n,D=u,W=t,j=s;if(0===V){var X;X=T,T=N,N=X,X=G,G=O,O=X,X=U,U=k,k=X,X=_,_=D,D=X,X=W,W=j,j=X}for(var z=N;z<N+2;z++){var Y=O.vertices[(z+O.vertices.length)%O.vertices.length];a.rotate(y,Y,D),c(y,y,k);for(var K=0,H=T-1;H<T+2;H++){var Z=G.vertices[(H+G.vertices.length)%G.vertices.length],J=G.vertices[(H+1+G.vertices.length)%G.vertices.length];a.rotate(m,Z,_),a.rotate(g,J,_),c(m,m,U),c(g,g,U),r(P,g,m),a.rotate90cw(F,P),a.normalize(F,F),r(x,y,m);$=h(F,x);(H===T&&$<=f||H!==T&&$<=0)&&K++}if(K>=3){if(d)return!0;var Q=this.createContactEquation(W,j,G,O);M++;var Z=G.vertices[T%G.vertices.length],J=G.vertices[(T+1)%G.vertices.length];a.rotate(m,Z,_),a.rotate(g,J,_),c(m,m,U),c(g,g,U),r(P,g,m),a.rotate90cw(Q.normalA,P),a.normalize(Q.normalA,Q.normalA),r(x,y,m);var $=h(Q.normalA,x);a.scale(L,Q.normalA,$),r(Q.contactPointA,y,U),r(Q.contactPointA,Q.contactPointA,L),c(Q.contactPointA,Q.contactPointA,U),r(Q.contactPointA,Q.contactPointA,W.position),r(Q.contactPointB,y,k),c(Q.contactPointB,Q.contactPointB,k),r(Q.contactPointB,Q.contactPointB,j.position),this.contactEquations.push(Q),this.enableFrictionReduction||this.enableFriction&&this.frictionEquations.push(this.createFrictionFromContact(Q))}}}return this.enableFrictionReduction&&this.enableFriction&&M&&this.frictionEquations.push(this.createFrictionFromAverage(M)),M};var Q=a.fromValues(0,0);i.projectConvexOntoAxis=function(t,e,o,i,n){var s,r,c=null,l=null,p=Q;a.rotate(p,i,-o);for(var u=0;u<t.vertices.length;u++)s=t.vertices[u],r=h(s,p),(null===c||r>c)&&(c=r),(null===l||r<l)&&(l=r);if(l>c){var d=l;l=c,c=d}var f=h(e,i);a.set(n,l+f,c+f)};var $=a.fromValues(0,0),tt=a.fromValues(0,0),et=a.fromValues(0,0),ot=a.fromValues(0,0),it=a.fromValues(0,0),nt=a.fromValues(0,0);i.findSeparatingAxis=function(t,e,o,n,s,c,h){var l=null,p=!1,u=!1,d=$,f=tt,v=et,y=ot,g=it,A=nt;if(t instanceof m&&n instanceof m)for(P=0;2!==P;P++){var b=t,E=o;1===P&&(b=n,E=c);for(w=0;2!==w;w++){0===w?a.set(y,0,1):1===w&&a.set(y,1,0),0!==E&&a.rotate(y,y,E),i.projectConvexOntoAxis(t,e,o,y,g),i.projectConvexOntoAxis(n,s,c,y,A);var B=g,q=A;g[0]>A[0]&&(q=g,B=A,!0),p=(S=q[0]-B[1])<=0,(null===l||S>l)&&(a.copy(h,y),l=S,u=p)}}else for(var P=0;2!==P;P++){var b=t,E=o;1===P&&(b=n,E=c);for(var w=0;w!==b.vertices.length;w++){a.rotate(f,b.vertices[w],E),a.rotate(v,b.vertices[(w+1)%b.vertices.length],E),r(d,v,f),a.rotate90cw(y,d),a.normalize(y,y),i.projectConvexOntoAxis(t,e,o,y,g),i.projectConvexOntoAxis(n,s,c,y,A);var B=g,q=A;g[0]>A[0]&&(q=g,B=A,!0);var S=q[0]-B[1];p=S<=0,(null===l||S>l)&&(a.copy(h,y),l=S,u=p)}}return u};var st=a.fromValues(0,0),at=a.fromValues(0,0),rt=a.fromValues(0,0);i.getClosestEdge=function(t,e,o,i){var n=st,s=at,c=rt;a.rotate(n,o,-e),i&&a.scale(n,n,-1);for(var l=-1,p=t.vertices.length,u=-1,d=0;d!==p;d++){r(s,t.vertices[(d+1)%p],t.vertices[d%p]),a.rotate90cw(c,s),a.normalize(c,c);var f=h(c,n);(-1===l||f>u)&&(l=d%p,u=f)}return l};var ct=a.create(),ht=a.create(),lt=a.create(),pt=a.create(),ut=a.create(),dt=a.create(),ft=a.create();i.prototype[y.CIRCLE|y.HEIGHTFIELD]=i.prototype.circleHeightfield=function(t,e,o,i,n,s,h,l,p,u){var d=s.heights,u=u||e.radius,f=s.elementWidth,v=ht,y=ct,m=ut,g=ft,A=dt,b=lt,E=pt,B=Math.floor((o[0]-u-h[0])/f),q=Math.ceil((o[0]+u-h[0])/f);B<0&&(B=0),q>=d.length&&(q=d.length-1);for(var P=d[B],w=d[q],S=B;S<q;S++)d[S]<w&&(w=d[S]),d[S]>P&&(P=d[S]);if(o[1]-u>P)return!p&&0;for(var C=!1,S=B;S<q;S++){a.set(b,S*f,d[S]),a.set(E,(S+1)*f,d[S+1]),a.add(b,b,h),a.add(E,E,h),a.sub(A,E,b),a.rotate(A,A,Math.PI/2),a.normalize(A,A),a.scale(y,A,-u),a.add(y,y,o),a.sub(v,y,b);var L=a.dot(v,A);if(y[0]>=b[0]&&y[0]<E[0]&&L<=0){if(p)return!0;C=!0,a.scale(v,A,-L),a.add(m,y,v),a.copy(g,A);x=this.createContactEquation(n,t,s,e);a.copy(x.normalA,g),a.scale(x.contactPointB,x.normalA,-u),c(x.contactPointB,x.contactPointB,o),r(x.contactPointB,x.contactPointB,t.position),a.copy(x.contactPointA,m),a.sub(x.contactPointA,x.contactPointA,n.position),this.contactEquations.push(x),this.enableFriction&&this.frictionEquations.push(this.createFrictionFromContact(x))}}if(C=!1,u>0)for(S=B;S<=q;S++)if(a.set(b,S*f,d[S]),a.add(b,b,h),a.sub(v,o,b),a.squaredLength(v)<Math.pow(u,2)){if(p)return!0;C=!0;var x=this.createContactEquation(n,t,s,e);a.copy(x.normalA,v),a.normalize(x.normalA,x.normalA),a.scale(x.contactPointB,x.normalA,-u),c(x.contactPointB,x.contactPointB,o),r(x.contactPointB,x.contactPointB,t.position),r(x.contactPointA,b,h),c(x.contactPointA,x.contactPointA,h),r(x.contactPointA,x.contactPointA,n.position),this.contactEquations.push(x),this.enableFriction&&this.frictionEquations.push(this.createFrictionFromContact(x))}return C?1:0};var vt=a.create(),yt=a.create(),mt=a.create(),gt=new v({vertices:[a.create(),a.create(),a.create(),a.create()]});i.prototype[y.BOX|y.HEIGHTFIELD]=i.prototype[y.CONVEX|y.HEIGHTFIELD]=i.prototype.convexHeightfield=function(t,e,o,i,n,s,r,c,h){var l=s.heights,p=s.elementWidth,u=vt,d=yt,f=mt,v=gt,y=Math.floor((t.aabb.lowerBound[0]-r[0])/p),m=Math.ceil((t.aabb.upperBound[0]-r[0])/p);y<0&&(y=0),m>=l.length&&(m=l.length-1);for(var g=l[y],A=l[m],b=y;b<m;b++)l[b]<A&&(A=l[b]),l[b]>g&&(g=l[b]);if(t.aabb.lowerBound[1]>g)return!h&&0;for(var E=0,b=y;b<m;b++){a.set(u,b*p,l[b]),a.set(d,(b+1)*p,l[b+1]),a.add(u,u,r),a.add(d,d,r);a.set(f,.5*(d[0]+u[0]),.5*(d[1]+u[1]-100)),a.sub(v.vertices[0],d,f),a.sub(v.vertices[1],u,f),a.copy(v.vertices[2],v.vertices[1]),a.copy(v.vertices[3],v.vertices[0]),v.vertices[2][1]-=100,v.vertices[3][1]-=100,E+=this.convexConvex(t,e,o,i,n,v,f,0,h)}return E}},{"../equations/ContactEquation":21,"../equations/Equation":22,"../equations/FrictionEquation":23,"../math/vec2":30,"../objects/Body":31,"../shapes/Box":37,"../shapes/Circle":39,"../shapes/Convex":40,"../shapes/Shape":45,"../utils/ContactEquationPool":48,"../utils/FrictionEquationPool":49,"../utils/TupleDictionary":56,"../utils/Utils":57}],11:[function(t,e,o){function i(t){t=t||{},this.from=t.from?s.fromValues(t.from[0],t.from[1]):s.create(),this.to=t.to?s.fromValues(t.to[0],t.to[1]):s.create(),this.checkCollisionResponse=void 0===t.checkCollisionResponse||t.checkCollisionResponse,this.skipBackfaces=!!t.skipBackfaces,this.collisionMask=void 0!==t.collisionMask?t.collisionMask:-1,this.collisionGroup=void 0!==t.collisionGroup?t.collisionGroup:-1,this.mode=void 0!==t.mode?t.mode:i.ANY,this.callback=t.callback||function(t){},this.direction=s.create(),this.length=1,this.update()}function n(t,e,o){s.sub(r,o,t);var i=s.dot(r,e);return s.scale(c,e,i),s.add(c,c,t),s.squaredDistance(o,c)}e.exports=i;var s=t("../math/vec2");t("../collision/RaycastResult"),t("../shapes/Shape"),t("../collision/AABB");i.prototype.constructor=i,i.CLOSEST=1,i.ANY=2,i.ALL=4,i.prototype.update=function(){var t=this.direction;s.sub(t,this.to,this.from),this.length=s.length(t),s.normalize(t,t)},i.prototype.intersectBodies=function(t,e){for(var o=0,i=e.length;!t.shouldStop(this)&&o<i;o++){var n=e[o],s=n.getAABB();(s.overlapsRay(this)>=0||s.containsPoint(this.from))&&this.intersectBody(t,n)}};var a=s.create();i.prototype.intersectBody=function(t,e){var o=this.checkCollisionResponse;if(!o||e.collisionResponse)for(var i=a,n=0,r=e.shapes.length;n<r;n++){var c=e.shapes[n];if((!o||c.collisionResponse)&&(0!=(this.collisionGroup&c.collisionMask)&&0!=(c.collisionGroup&this.collisionMask))){s.rotate(i,c.position,e.angle),s.add(i,i,e.position);var h=c.angle+e.angle;if(this.intersectShape(t,c,h,i,e),t.shouldStop(this))break}}},i.prototype.intersectShape=function(t,e,o,i,s){n(this.from,this.direction,i)>e.boundingRadius*e.boundingRadius||(this._currentBody=s,this._currentShape=e,e.raycast(t,this,i,o),this._currentBody=this._currentShape=null)},i.prototype.getAABB=function(t){var e=this.to,o=this.from;s.set(t.lowerBound,Math.min(e[0],o[0]),Math.min(e[1],o[1])),s.set(t.upperBound,Math.max(e[0],o[0]),Math.max(e[1],o[1]))};s.create();i.prototype.reportIntersection=function(t,e,o,n){this.from,this.to;var a=this._currentShape,r=this._currentBody;if(!(this.skipBackfaces&&s.dot(o,this.direction)>0))switch(this.mode){case i.ALL:t.set(o,a,r,e,n),this.callback(t);break;case i.CLOSEST:(e<t.fraction||!t.hasHit())&&t.set(o,a,r,e,n);break;case i.ANY:t.set(o,a,r,e,n)}};var r=s.create(),c=s.create()},{"../collision/AABB":7,"../collision/RaycastResult":12,"../math/vec2":30,"../shapes/Shape":45}],12:[function(t,e,o){function i(){this.normal=n.create(),this.shape=null,this.body=null,this.faceIndex=-1,this.fraction=-1,this.isStopped=!1}var n=t("../math/vec2"),s=t("../collision/Ray");e.exports=i,i.prototype.reset=function(){n.set(this.normal,0,0),this.shape=null,this.body=null,this.faceIndex=-1,this.fraction=-1,this.isStopped=!1},i.prototype.getHitDistance=function(t){return n.distance(t.from,t.to)*this.fraction},i.prototype.hasHit=function(){return-1!==this.fraction},i.prototype.getHitPoint=function(t,e){n.lerp(t,e.from,e.to,this.fraction)},i.prototype.stop=function(){this.isStopped=!0},i.prototype.shouldStop=function(t){return this.isStopped||-1!==this.fraction&&t.mode===s.ANY},i.prototype.set=function(t,e,o,i,s){n.copy(this.normal,t),this.shape=e,this.body=o,this.fraction=i,this.faceIndex=s}},{"../collision/Ray":11,"../math/vec2":30}],13:[function(t,e,o){function i(){s.call(this,s.SAP),this.axisList=[],this.axisIndex=0;var t=this;this._addBodyHandler=function(e){t.axisList.push(e.body)},this._removeBodyHandler=function(e){var o=t.axisList.indexOf(e.body);-1!==o&&t.axisList.splice(o,1)}}var n=t("../utils/Utils"),s=t("../collision/Broadphase");e.exports=i,(i.prototype=new s).constructor=i,i.prototype.setWorld=function(t){this.axisList.length=0,n.appendArray(this.axisList,t.bodies),t.off("addBody",this._addBodyHandler).off("removeBody",this._removeBodyHandler),t.on("addBody",this._addBodyHandler).on("removeBody",this._removeBodyHandler),this.world=t},i.sortAxisList=function(t,e){e|=0;for(var o=1,i=t.length;o<i;o++){for(var n=t[o],s=o-1;s>=0&&!(t[s].aabb.lowerBound[e]<=n.aabb.lowerBound[e]);s--)t[s+1]=t[s];t[s+1]=n}return t},i.prototype.sortList=function(){var t=this.axisList,e=this.axisIndex;i.sortAxisList(t,e)},i.prototype.getCollisionPairs=function(t){var e=this.axisList,o=this.result,i=this.axisIndex;o.length=0;for(var n=e.length;n--;){var a=e[n];a.aabbNeedsUpdate&&a.updateAABB()}this.sortList();for(var r=0,c=0|e.length;r!==c;r++)for(var h=e[r],l=r+1;l<c;l++){var p=e[l];if(!(p.aabb.lowerBound[i]<=h.aabb.upperBound[i]))break;s.canCollide(h,p)&&this.boundingVolumeCheck(h,p)&&o.push(h,p)}return o},i.prototype.aabbQuery=function(t,e,o){o=o||[],this.sortList();var i=this.axisIndex,n="x";1===i&&(n="y"),2===i&&(n="z");for(var s=this.axisList,a=(e.lowerBound[n],e.upperBound[n],0);a<s.length;a++){var r=s[a];r.aabbNeedsUpdate&&r.updateAABB(),r.aabb.overlaps(e)&&o.push(r)}return o}},{"../collision/Broadphase":8,"../utils/Utils":57}],14:[function(t,e,o){function i(t,e,o,i){this.type=o,i=n.defaults(i,{collideConnected:!0,wakeUpBodies:!0}),this.equations=[],this.bodyA=t,this.bodyB=e,this.collideConnected=i.collideConnected,i.wakeUpBodies&&(t&&t.wakeUp(),e&&e.wakeUp())}e.exports=i;var n=t("../utils/Utils");i.prototype.update=function(){throw new Error("method update() not implmemented in this Constraint subclass!")},i.DISTANCE=1,i.GEAR=2,i.LOCK=3,i.PRISMATIC=4,i.REVOLUTE=5,i.prototype.setStiffness=function(t){for(var e=this.equations,o=0;o!==e.length;o++){var i=e[o];i.stiffness=t,i.needsUpdate=!0}},i.prototype.setRelaxation=function(t){for(var e=this.equations,o=0;o!==e.length;o++){var i=e[o];i.relaxation=t,i.needsUpdate=!0}}},{"../utils/Utils":57}],15:[function(t,e,o){function i(t,e,o){o=r.defaults(o,{localAnchorA:[0,0],localAnchorB:[0,0]}),n.call(this,t,e,n.DISTANCE,o),this.localAnchorA=a.fromValues(o.localAnchorA[0],o.localAnchorA[1]),this.localAnchorB=a.fromValues(o.localAnchorB[0],o.localAnchorB[1]);var i=this.localAnchorA,c=this.localAnchorB;if(this.distance=0,"number"==typeof o.distance)this.distance=o.distance;else{var h=a.create(),l=a.create(),p=a.create();a.rotate(h,i,t.angle),a.rotate(l,c,e.angle),a.add(p,e.position,l),a.sub(p,p,h),a.sub(p,p,t.position),this.distance=a.length(p)}var u;u=void 0===o.maxForce?Number.MAX_VALUE:o.maxForce;var d=new s(t,e,-u,u);this.equations=[d],this.maxForce=u;var p=a.create(),f=a.create(),v=a.create(),y=this;d.computeGq=function(){var t=this.bodyA,e=this.bodyB,o=t.position,n=e.position;return a.rotate(f,i,t.angle),a.rotate(v,c,e.angle),a.add(p,n,v),a.sub(p,p,f),a.sub(p,p,o),a.length(p)-y.distance},this.setMaxForce(u),this.upperLimitEnabled=!1,this.upperLimit=1,this.lowerLimitEnabled=!1,this.lowerLimit=0,this.position=0}var n=t("./Constraint"),s=t("../equations/Equation"),a=t("../math/vec2"),r=t("../utils/Utils");e.exports=i,(i.prototype=new n).constructor=i;var c=a.create(),h=a.create(),l=a.create();i.prototype.update=function(){var t=this.equations[0],e=this.bodyA,o=this.bodyB,i=(this.distance,e.position),n=o.position,s=this.equations[0],r=t.G;a.rotate(h,this.localAnchorA,e.angle),a.rotate(l,this.localAnchorB,o.angle),a.add(c,n,l),a.sub(c,c,h),a.sub(c,c,i),this.position=a.length(c);var p=!1;if(this.upperLimitEnabled&&this.position>this.upperLimit&&(s.maxForce=0,s.minForce=-this.maxForce,this.distance=this.upperLimit,p=!0),this.lowerLimitEnabled&&this.position<this.lowerLimit&&(s.maxForce=this.maxForce,s.minForce=0,this.distance=this.lowerLimit,p=!0),!this.lowerLimitEnabled&&!this.upperLimitEnabled||p){s.enabled=!0,a.normalize(c,c);var u=a.crossLength(h,c),d=a.crossLength(l,c);r[0]=-c[0],r[1]=-c[1],r[2]=-u,r[3]=c[0],r[4]=c[1],r[5]=d}else s.enabled=!1},i.prototype.setMaxForce=function(t){var e=this.equations[0];e.minForce=-t,e.maxForce=t},i.prototype.getMaxForce=function(){return this.equations[0].maxForce}},{"../equations/Equation":22,"../math/vec2":30,"../utils/Utils":57,"./Constraint":14}],16:[function(t,e,o){function i(t,e,o){o=o||{},n.call(this,t,e,n.GEAR,o),this.ratio=void 0!==o.ratio?o.ratio:1,this.angle=void 0!==o.angle?o.angle:e.angle-this.ratio*t.angle,o.angle=this.angle,o.ratio=this.ratio,this.equations=[new s(t,e,o)],void 0!==o.maxTorque&&this.setMaxTorque(o.maxTorque)}var n=t("./Constraint"),s=(t("../equations/Equation"),t("../equations/AngleLockEquation"));t("../math/vec2");e.exports=i,(i.prototype=new n).constructor=i,i.prototype.update=function(){var t=this.equations[0];t.ratio!==this.ratio&&t.setRatio(this.ratio),t.angle=this.angle},i.prototype.setMaxTorque=function(t){this.equations[0].setMaxTorque(t)},i.prototype.getMaxTorque=function(t){return this.equations[0].maxForce}},{"../equations/AngleLockEquation":20,"../equations/Equation":22,"../math/vec2":30,"./Constraint":14}],17:[function(t,e,o){function i(t,e,o){o=o||{},n.call(this,t,e,n.LOCK,o);var i=void 0===o.maxForce?Number.MAX_VALUE:o.maxForce,r=(o.localAngleB,new a(t,e,-i,i)),c=new a(t,e,-i,i),h=new a(t,e,-i,i),l=s.create(),p=s.create(),u=this;r.computeGq=function(){return s.rotate(l,u.localOffsetB,t.angle),s.sub(p,e.position,t.position),s.sub(p,p,l),p[0]},c.computeGq=function(){return s.rotate(l,u.localOffsetB,t.angle),s.sub(p,e.position,t.position),s.sub(p,p,l),p[1]};var d=s.create(),f=s.create();h.computeGq=function(){return s.rotate(d,u.localOffsetB,e.angle-u.localAngleB),s.scale(d,d,-1),s.sub(p,t.position,e.position),s.add(p,p,d),s.rotate(f,d,-Math.PI/2),s.normalize(f,f),s.dot(p,f)},this.localOffsetB=s.create(),o.localOffsetB?s.copy(this.localOffsetB,o.localOffsetB):(s.sub(this.localOffsetB,e.position,t.position),s.rotate(this.localOffsetB,this.localOffsetB,-t.angle)),this.localAngleB=0,"number"==typeof o.localAngleB?this.localAngleB=o.localAngleB:this.localAngleB=e.angle-t.angle,this.equations.push(r,c,h),this.setMaxForce(i)}var n=t("./Constraint"),s=t("../math/vec2"),a=t("../equations/Equation");e.exports=i,(i.prototype=new n).constructor=i,i.prototype.setMaxForce=function(t){for(var e=this.equations,o=0;o<this.equations.length;o++)e[o].maxForce=t,e[o].minForce=-t},i.prototype.getMaxForce=function(){return this.equations[0].maxForce};var r=s.create(),c=s.create(),h=s.create(),l=s.fromValues(1,0),p=s.fromValues(0,1);i.prototype.update=function(){var t=this.equations[0],e=this.equations[1],o=this.equations[2],i=this.bodyA,n=this.bodyB;s.rotate(r,this.localOffsetB,i.angle),s.rotate(c,this.localOffsetB,n.angle-this.localAngleB),s.scale(c,c,-1),s.rotate(h,c,Math.PI/2),s.normalize(h,h),t.G[0]=-1,t.G[1]=0,t.G[2]=-s.crossLength(r,l),t.G[3]=1,e.G[0]=0,e.G[1]=-1,e.G[2]=-s.crossLength(r,p),e.G[4]=1,o.G[0]=-h[0],o.G[1]=-h[1],o.G[3]=h[0],o.G[4]=h[1],o.G[5]=s.crossLength(c,h)}},{"../equations/Equation":22,"../math/vec2":30,"./Constraint":14}],18:[function(t,e,o){function i(t,e,o){o=o||{},n.call(this,t,e,n.PRISMATIC,o);var i=r.fromValues(0,0),h=r.fromValues(1,0),l=r.fromValues(0,0);o.localAnchorA&&r.copy(i,o.localAnchorA),o.localAxisA&&r.copy(h,o.localAxisA),o.localAnchorB&&r.copy(l,o.localAnchorB),this.localAnchorA=i,this.localAnchorB=l,this.localAxisA=h;var p=this.maxForce=void 0!==o.maxForce?o.maxForce:Number.MAX_VALUE,u=new a(t,e,-p,p),d=new r.create,f=new r.create,v=new r.create,y=new r.create;if(u.computeGq=function(){return r.dot(v,y)},u.updateJacobian=function(){var o=this.G,n=t.position,s=e.position;r.rotate(d,i,t.angle),r.rotate(f,l,e.angle),r.add(v,s,f),r.sub(v,v,n),r.sub(v,v,d),r.rotate(y,h,t.angle+Math.PI/2),o[0]=-y[0],o[1]=-y[1],o[2]=-r.crossLength(d,y)+r.crossLength(y,v),o[3]=y[0],o[4]=y[1],o[5]=r.crossLength(f,y)},this.equations.push(u),!o.disableRotationalLock){var m=new c(t,e,-p,p);this.equations.push(m)}this.position=0,this.velocity=0,this.lowerLimitEnabled=void 0!==o.lowerLimit,this.upperLimitEnabled=void 0!==o.upperLimit,this.lowerLimit=void 0!==o.lowerLimit?o.lowerLimit:0,this.upperLimit=void 0!==o.upperLimit?o.upperLimit:1,this.upperLimitEquation=new s(t,e),this.lowerLimitEquation=new s(t,e),this.upperLimitEquation.minForce=this.lowerLimitEquation.minForce=0,this.upperLimitEquation.maxForce=this.lowerLimitEquation.maxForce=p,this.motorEquation=new a(t,e),this.motorEnabled=!1,this.motorSpeed=0;var g=this,A=this.motorEquation;A.computeGW;A.computeGq=function(){return 0},A.computeGW=function(){var t=this.G,e=this.bodyA,o=this.bodyB,i=e.velocity,n=o.velocity,s=e.angularVelocity,a=o.angularVelocity;return this.gmult(t,i,s,n,a)+g.motorSpeed}}var n=t("./Constraint"),s=t("../equations/ContactEquation"),a=t("../equations/Equation"),r=t("../math/vec2"),c=t("../equations/RotationalLockEquation");e.exports=i,(i.prototype=new n).constructor=i;var h=r.create(),l=r.create(),p=r.create(),u=r.create(),d=r.create(),f=r.create();i.prototype.update=function(){var t=this.equations,e=t[0],o=this.upperLimit,i=this.lowerLimit,n=this.upperLimitEquation,s=this.lowerLimitEquation,a=this.bodyA,c=this.bodyB,v=this.localAxisA,y=this.localAnchorA,m=this.localAnchorB;e.updateJacobian(),r.rotate(h,v,a.angle),r.rotate(u,y,a.angle),r.add(l,u,a.position),r.rotate(d,m,c.angle),r.add(p,d,c.position);var g=this.position=r.dot(p,h)-r.dot(l,h);if(this.motorEnabled){var A=this.motorEquation.G;A[0]=h[0],A[1]=h[1],A[2]=r.crossLength(h,d),A[3]=-h[0],A[4]=-h[1],A[5]=-r.crossLength(h,u)}if(this.upperLimitEnabled&&g>o?(r.scale(n.normalA,h,-1),r.sub(n.contactPointA,l,a.position),r.sub(n.contactPointB,p,c.position),r.scale(f,h,o),r.add(n.contactPointA,n.contactPointA,f),-1===t.indexOf(n)&&t.push(n)):-1!==(b=t.indexOf(n))&&t.splice(b,1),this.lowerLimitEnabled&&g<i)r.scale(s.normalA,h,1),r.sub(s.contactPointA,l,a.position),r.sub(s.contactPointB,p,c.position),r.scale(f,h,i),r.sub(s.contactPointB,s.contactPointB,f),-1===t.indexOf(s)&&t.push(s);else{var b=t.indexOf(s);-1!==b&&t.splice(b,1)}},i.prototype.enableMotor=function(){this.motorEnabled||(this.equations.push(this.motorEquation),this.motorEnabled=!0)},i.prototype.disableMotor=function(){if(this.motorEnabled){var t=this.equations.indexOf(this.motorEquation);this.equations.splice(t,1),this.motorEnabled=!1}},i.prototype.setLimits=function(t,e){"number"==typeof t?(this.lowerLimit=t,this.lowerLimitEnabled=!0):(this.lowerLimit=t,this.lowerLimitEnabled=!1),"number"==typeof e?(this.upperLimit=e,this.upperLimitEnabled=!0):(this.upperLimit=e,this.upperLimitEnabled=!1)}},{"../equations/ContactEquation":21,"../equations/Equation":22,"../equations/RotationalLockEquation":24,"../math/vec2":30,"./Constraint":14}],19:[function(t,e,o){function i(t,e,o){o=o||{},n.call(this,t,e,n.REVOLUTE,o);var i=this.maxForce=void 0!==o.maxForce?o.maxForce:Number.MAX_VALUE;this.pivotA=c.create(),this.pivotB=c.create(),o.worldPivot?(c.sub(this.pivotA,o.worldPivot,t.position),c.sub(this.pivotB,o.worldPivot,e.position),c.rotate(this.pivotA,this.pivotA,-t.angle),c.rotate(this.pivotB,this.pivotB,-e.angle)):(c.copy(this.pivotA,o.localPivotA),c.copy(this.pivotB,o.localPivotB));var f=this.equations=[new s(t,e,-i,i),new s(t,e,-i,i)],v=f[0],y=f[1],m=this;v.computeGq=function(){return c.rotate(h,m.pivotA,t.angle),c.rotate(l,m.pivotB,e.angle),c.add(d,e.position,l),c.sub(d,d,t.position),c.sub(d,d,h),c.dot(d,p)},y.computeGq=function(){return c.rotate(h,m.pivotA,t.angle),c.rotate(l,m.pivotB,e.angle),c.add(d,e.position,l),c.sub(d,d,t.position),c.sub(d,d,h),c.dot(d,u)},y.minForce=v.minForce=-i,y.maxForce=v.maxForce=i,this.motorEquation=new a(t,e),this.motorEnabled=!1,this.angle=0,this.lowerLimitEnabled=!1,this.upperLimitEnabled=!1,this.lowerLimit=0,this.upperLimit=0,this.upperLimitEquation=new r(t,e),this.lowerLimitEquation=new r(t,e),this.upperLimitEquation.minForce=0,this.lowerLimitEquation.maxForce=0}var n=t("./Constraint"),s=t("../equations/Equation"),a=t("../equations/RotationalVelocityEquation"),r=t("../equations/RotationalLockEquation"),c=t("../math/vec2");e.exports=i;var h=c.create(),l=c.create(),p=c.fromValues(1,0),u=c.fromValues(0,1),d=c.create();(i.prototype=new n).constructor=i,i.prototype.setLimits=function(t,e){"number"==typeof t?(this.lowerLimit=t,this.lowerLimitEnabled=!0):(this.lowerLimit=t,this.lowerLimitEnabled=!1),"number"==typeof e?(this.upperLimit=e,this.upperLimitEnabled=!0):(this.upperLimit=e,this.upperLimitEnabled=!1)},i.prototype.update=function(){var t=this.bodyA,e=this.bodyB,o=this.pivotA,i=this.pivotB,n=this.equations,s=(n[0],n[1],n[0]),a=n[1],r=this.upperLimit,d=this.lowerLimit,f=this.upperLimitEquation,v=this.lowerLimitEquation,y=this.angle=e.angle-t.angle;if(this.upperLimitEnabled&&y>r?(f.angle=r,-1===n.indexOf(f)&&n.push(f)):-1!==(m=n.indexOf(f))&&n.splice(m,1),this.lowerLimitEnabled&&y<d)v.angle=d,-1===n.indexOf(v)&&n.push(v);else{var m=n.indexOf(v);-1!==m&&n.splice(m,1)}c.rotate(h,o,t.angle),c.rotate(l,i,e.angle),s.G[0]=-1,s.G[1]=0,s.G[2]=-c.crossLength(h,p),s.G[3]=1,s.G[4]=0,s.G[5]=c.crossLength(l,p),a.G[0]=0,a.G[1]=-1,a.G[2]=-c.crossLength(h,u),a.G[3]=0,a.G[4]=1,a.G[5]=c.crossLength(l,u)},i.prototype.enableMotor=function(){this.motorEnabled||(this.equations.push(this.motorEquation),this.motorEnabled=!0)},i.prototype.disableMotor=function(){if(this.motorEnabled){var t=this.equations.indexOf(this.motorEquation);this.equations.splice(t,1),this.motorEnabled=!1}},i.prototype.motorIsEnabled=function(){return!!this.motorEnabled},i.prototype.setMotorSpeed=function(t){if(this.motorEnabled){var e=this.equations.indexOf(this.motorEquation);this.equations[e].relativeVelocity=t}},i.prototype.getMotorSpeed=function(){return!!this.motorEnabled&&this.motorEquation.relativeVelocity}},{"../equations/Equation":22,"../equations/RotationalLockEquation":24,"../equations/RotationalVelocityEquation":25,"../math/vec2":30,"./Constraint":14}],20:[function(t,e,o){function i(t,e,o){o=o||{},n.call(this,t,e,-Number.MAX_VALUE,Number.MAX_VALUE),this.angle=o.angle||0,this.ratio="number"==typeof o.ratio?o.ratio:1,this.setRatio(this.ratio)}var n=t("./Equation");t("../math/vec2");e.exports=i,(i.prototype=new n).constructor=i,i.prototype.computeGq=function(){return this.ratio*this.bodyA.angle-this.bodyB.angle+this.angle},i.prototype.setRatio=function(t){var e=this.G;e[2]=t,e[5]=-1,this.ratio=t},i.prototype.setMaxTorque=function(t){this.maxForce=t,this.minForce=-t}},{"../math/vec2":30,"./Equation":22}],21:[function(t,e,o){function i(t,e){n.call(this,t,e,0,Number.MAX_VALUE),this.contactPointA=s.create(),this.penetrationVec=s.create(),this.contactPointB=s.create(),this.normalA=s.create(),this.restitution=0,this.firstImpact=!1,this.shapeA=null,this.shapeB=null}var n=t("./Equation"),s=t("../math/vec2");e.exports=i,(i.prototype=new n).constructor=i,i.prototype.computeB=function(t,e,o){var i=this.bodyA,n=this.bodyB,a=this.contactPointA,r=this.contactPointB,c=i.position,h=n.position,l=this.penetrationVec,p=this.normalA,u=this.G,d=s.crossLength(a,p),f=s.crossLength(r,p);u[0]=-p[0],u[1]=-p[1],u[2]=-d,u[3]=p[0],u[4]=p[1],u[5]=f,s.add(l,h,r),s.sub(l,l,c),s.sub(l,l,a);var v,y;return this.firstImpact&&0!==this.restitution?(y=0,v=1/e*(1+this.restitution)*this.computeGW()):(y=s.dot(p,l)+this.offset,v=this.computeGW()),-y*t-v*e-o*this.computeGiMf()};var a=s.create(),r=s.create(),c=s.create();i.prototype.getVelocityAlongNormal=function(){return this.bodyA.getVelocityAtPoint(a,this.contactPointA),this.bodyB.getVelocityAtPoint(r,this.contactPointB),s.subtract(c,a,r),s.dot(this.normalA,c)}},{"../math/vec2":30,"./Equation":22}],22:[function(t,e,o){function i(t,e,o,n){this.minForce=void 0===o?-Number.MAX_VALUE:o,this.maxForce=void 0===n?Number.MAX_VALUE:n,this.bodyA=t,this.bodyB=e,this.stiffness=i.DEFAULT_STIFFNESS,this.relaxation=i.DEFAULT_RELAXATION,this.G=new s.ARRAY_TYPE(6);for(var a=0;a<6;a++)this.G[a]=0;this.offset=0,this.a=0,this.b=0,this.epsilon=0,this.timeStep=1/60,this.needsUpdate=!0,this.multiplier=0,this.relativeVelocity=0,this.enabled=!0}e.exports=i;var n=t("../math/vec2"),s=t("../utils/Utils");t("../objects/Body");i.prototype.constructor=i,i.DEFAULT_STIFFNESS=1e6,i.DEFAULT_RELAXATION=4,i.prototype.update=function(){var t=this.stiffness,e=this.relaxation,o=this.timeStep;this.a=4/(o*(1+4*e)),this.b=4*e/(1+4*e),this.epsilon=4/(o*o*t*(1+4*e)),this.needsUpdate=!1},i.prototype.gmult=function(t,e,o,i,n){return t[0]*e[0]+t[1]*e[1]+t[2]*o+t[3]*i[0]+t[4]*i[1]+t[5]*n},i.prototype.computeB=function(t,e,o){var i=this.computeGW();return-this.computeGq()*t-i*e-this.computeGiMf()*o};var a=n.create(),r=n.create();i.prototype.computeGq=function(){var t=this.G,e=this.bodyA,o=this.bodyB,i=(e.position,o.position,e.angle),n=o.angle;return this.gmult(t,a,i,r,n)+this.offset},i.prototype.computeGW=function(){var t=this.G,e=this.bodyA,o=this.bodyB,i=e.velocity,n=o.velocity,s=e.angularVelocity,a=o.angularVelocity;return this.gmult(t,i,s,n,a)+this.relativeVelocity},i.prototype.computeGWlambda=function(){var t=this.G,e=this.bodyA,o=this.bodyB,i=e.vlambda,n=o.vlambda,s=e.wlambda,a=o.wlambda;return this.gmult(t,i,s,n,a)};var c=n.create(),h=n.create();i.prototype.computeGiMf=function(){var t=this.bodyA,e=this.bodyB,o=t.force,i=t.angularForce,s=e.force,a=e.angularForce,r=t.invMassSolve,l=e.invMassSolve,p=t.invInertiaSolve,u=e.invInertiaSolve,d=this.G;return n.scale(c,o,r),n.multiply(c,t.massMultiplier,c),n.scale(h,s,l),n.multiply(h,e.massMultiplier,h),this.gmult(d,c,i*p,h,a*u)},i.prototype.computeGiMGt=function(){var t=this.bodyA,e=this.bodyB,o=t.invMassSolve,i=e.invMassSolve,n=t.invInertiaSolve,s=e.invInertiaSolve,a=this.G;return a[0]*a[0]*o*t.massMultiplier[0]+a[1]*a[1]*o*t.massMultiplier[1]+a[2]*a[2]*n+a[3]*a[3]*i*e.massMultiplier[0]+a[4]*a[4]*i*e.massMultiplier[1]+a[5]*a[5]*s};var l=n.create(),p=n.create(),u=n.create();n.create(),n.create(),n.create();i.prototype.addToWlambda=function(t){var e=this.bodyA,o=this.bodyB,i=l,s=p,a=u,r=e.invMassSolve,c=o.invMassSolve,h=e.invInertiaSolve,d=o.invInertiaSolve,f=this.G;s[0]=f[0],s[1]=f[1],a[0]=f[3],a[1]=f[4],n.scale(i,s,r*t),n.multiply(i,i,e.massMultiplier),n.add(e.vlambda,e.vlambda,i),e.wlambda+=h*f[2]*t,n.scale(i,a,c*t),n.multiply(i,i,o.massMultiplier),n.add(o.vlambda,o.vlambda,i),o.wlambda+=d*f[5]*t},i.prototype.computeInvC=function(t){return 1/(this.computeGiMGt()+t)}},{"../math/vec2":30,"../objects/Body":31,"../utils/Utils":57}],23:[function(t,e,o){function i(t,e,o){s.call(this,t,e,-o,o),this.contactPointA=n.create(),this.contactPointB=n.create(),this.t=n.create(),this.contactEquations=[],this.shapeA=null,this.shapeB=null,this.frictionCoefficient=.3}var n=t("../math/vec2"),s=t("./Equation");t("../utils/Utils");e.exports=i,(i.prototype=new s).constructor=i,i.prototype.setSlipForce=function(t){this.maxForce=t,this.minForce=-t},i.prototype.getSlipForce=function(){return this.maxForce},i.prototype.computeB=function(t,e,o){this.bodyA,this.bodyB;var i=this.contactPointA,s=this.contactPointB,a=this.t,r=this.G;return r[0]=-a[0],r[1]=-a[1],r[2]=-n.crossLength(i,a),r[3]=a[0],r[4]=a[1],r[5]=n.crossLength(s,a),-this.computeGW()*e-o*this.computeGiMf()}},{"../math/vec2":30,"../utils/Utils":57,"./Equation":22}],24:[function(t,e,o){function i(t,e,o){o=o||{},n.call(this,t,e,-Number.MAX_VALUE,Number.MAX_VALUE),this.angle=o.angle||0;var i=this.G;i[2]=1,i[5]=-1}var n=t("./Equation"),s=t("../math/vec2");e.exports=i,(i.prototype=new n).constructor=i;var a=s.create(),r=s.create(),c=s.fromValues(1,0),h=s.fromValues(0,1);i.prototype.computeGq=function(){return s.rotate(a,c,this.bodyA.angle+this.angle),s.rotate(r,h,this.bodyB.angle),s.dot(a,r)}},{"../math/vec2":30,"./Equation":22}],25:[function(t,e,o){function i(t,e){n.call(this,t,e,-Number.MAX_VALUE,Number.MAX_VALUE),this.relativeVelocity=1,this.ratio=1}var n=t("./Equation");t("../math/vec2");e.exports=i,(i.prototype=new n).constructor=i,i.prototype.computeB=function(t,e,o){var i=this.G;i[2]=-1,i[5]=this.ratio;var n=this.computeGiMf();return-this.computeGW()*e-o*n}},{"../math/vec2":30,"./Equation":22}],26:[function(t,e,o){var i=function(){};e.exports=i,i.prototype={constructor:i,on:function(t,e,o){e.context=o||this,void 0===this._listeners&&(this._listeners={});var i=this._listeners;return void 0===i[t]&&(i[t]=[]),-1===i[t].indexOf(e)&&i[t].push(e),this},has:function(t,e){if(void 0===this._listeners)return!1;var o=this._listeners;if(e){if(void 0!==o[t]&&-1!==o[t].indexOf(e))return!0}else if(void 0!==o[t])return!0;return!1},off:function(t,e){if(void 0===this._listeners)return this;var o=this._listeners,i=o[t].indexOf(e);return-1!==i&&o[t].splice(i,1),this},emit:function(t){if(void 0===this._listeners)return this;var e=this._listeners[t.type];if(void 0!==e){t.target=this;for(var o=0,i=e.length;o<i;o++){var n=e[o];n.call(n.context,t)}}return this}}},{}],27:[function(t,e,o){function i(t,e,o){if(o=o||{},!(t instanceof n&&e instanceof n))throw new Error("First two arguments must be Material instances.");this.id=i.idCounter++,this.materialA=t,this.materialB=e,this.friction=void 0!==o.friction?Number(o.friction):.3,this.restitution=void 0!==o.restitution?Number(o.restitution):0,this.stiffness=void 0!==o.stiffness?Number(o.stiffness):s.DEFAULT_STIFFNESS,this.relaxation=void 0!==o.relaxation?Number(o.relaxation):s.DEFAULT_RELAXATION,this.frictionStiffness=void 0!==o.frictionStiffness?Number(o.frictionStiffness):s.DEFAULT_STIFFNESS,this.frictionRelaxation=void 0!==o.frictionRelaxation?Number(o.frictionRelaxation):s.DEFAULT_RELAXATION,this.surfaceVelocity=void 0!==o.surfaceVelocity?Number(o.surfaceVelocity):0,this.contactSkinSize=.005}var n=t("./Material"),s=t("../equations/Equation");e.exports=i,i.idCounter=0},{"../equations/Equation":22,"./Material":28}],28:[function(t,e,o){function i(t){this.id=t||i.idCounter++}e.exports=i,i.idCounter=0},{}],29:[function(t,e,o){var i={};i.GetArea=function(t){if(t.length<6)return 0;for(var e=t.length-2,o=0,i=0;i<e;i+=2)o+=(t[i+2]-t[i])*(t[i+1]+t[i+3]);return.5*-(o+=(t[0]-t[e])*(t[e+1]+t[1]))},i.Triangulate=function(t){var e=t.length>>1;if(e<3)return[];for(var o=[],n=[],s=0;s<e;s++)n.push(s);for(var s=0,a=e;a>3;){var r=n[(s+0)%a],c=n[(s+1)%a],h=n[(s+2)%a],l=t[2*r],p=t[2*r+1],u=t[2*c],d=t[2*c+1],f=t[2*h],v=t[2*h+1],y=!1;if(i._convex(l,p,u,d,f,v)){y=!0;for(var m=0;m<a;m++){var g=n[m];if(g!=r&&g!=c&&g!=h&&i._PointInTriangle(t[2*g],t[2*g+1],l,p,u,d,f,v)){y=!1;break}}}if(y)o.push(r,c,h),n.splice((s+1)%a,1),a--,s=0;else if(s++>3*a)break}return o.push(n[0],n[1],n[2]),o},i._PointInTriangle=function(t,e,o,i,n,s,a,r){var c=a-o,h=r-i,l=n-o,p=s-i,u=t-o,d=e-i,f=c*c+h*h,v=c*l+h*p,y=c*u+h*d,m=l*l+p*p,g=l*u+p*d,A=1/(f*m-v*v),b=(m*y-v*g)*A,E=(f*g-v*y)*A;return b>=0&&E>=0&&b+E<1},i._convex=function(t,e,o,i,n,s){return(e-i)*(n-o)+(o-t)*(s-i)>=0},e.exports=i},{}],30:[function(t,e,o){var i=e.exports={},n=t("../utils/Utils");i.crossLength=function(t,e){return t[0]*e[1]-t[1]*e[0]},i.crossVZ=function(t,e,o){return i.rotate(t,e,-Math.PI/2),i.scale(t,t,o),t},i.crossZV=function(t,e,o){return i.rotate(t,o,Math.PI/2),i.scale(t,t,e),t},i.rotate=function(t,e,o){if(0!==o){var i=Math.cos(o),n=Math.sin(o),s=e[0],a=e[1];t[0]=i*s-n*a,t[1]=n*s+i*a}else t[0]=e[0],t[1]=e[1]},i.rotate90cw=function(t,e){var o=e[0],i=e[1];t[0]=i,t[1]=-o},i.toLocalFrame=function(t,e,o,n){i.copy(t,e),i.sub(t,t,o),i.rotate(t,t,-n)},i.toGlobalFrame=function(t,e,o,n){i.copy(t,e),i.rotate(t,t,n),i.add(t,t,o)},i.vectorToLocalFrame=function(t,e,o){i.rotate(t,e,-o)},i.vectorToGlobalFrame=function(t,e,o){i.rotate(t,e,o)},i.centroid=function(t,e,o,n){return i.add(t,e,o),i.add(t,t,n),i.scale(t,t,1/3),t},i.create=function(){var t=new n.ARRAY_TYPE(2);return t[0]=0,t[1]=0,t},i.clone=function(t){var e=new n.ARRAY_TYPE(2);return e[0]=t[0],e[1]=t[1],e},i.fromValues=function(t,e){var o=new n.ARRAY_TYPE(2);return o[0]=t,o[1]=e,o},i.copy=function(t,e){return t[0]=e[0],t[1]=e[1],t},i.set=function(t,e,o){return t[0]=e,t[1]=o,t},i.add=function(t,e,o){return t[0]=e[0]+o[0],t[1]=e[1]+o[1],t},i.subtract=function(t,e,o){return t[0]=e[0]-o[0],t[1]=e[1]-o[1],t},i.sub=i.subtract,i.multiply=function(t,e,o){return t[0]=e[0]*o[0],t[1]=e[1]*o[1],t},i.mul=i.multiply,i.divide=function(t,e,o){return t[0]=e[0]/o[0],t[1]=e[1]/o[1],t},i.div=i.divide,i.scale=function(t,e,o){return t[0]=e[0]*o,t[1]=e[1]*o,t},i.distance=function(t,e){var o=e[0]-t[0],i=e[1]-t[1];return Math.sqrt(o*o+i*i)},i.dist=i.distance,i.squaredDistance=function(t,e){var o=e[0]-t[0],i=e[1]-t[1];return o*o+i*i},i.sqrDist=i.squaredDistance,i.length=function(t){var e=t[0],o=t[1];return Math.sqrt(e*e+o*o)},i.len=i.length,i.squaredLength=function(t){var e=t[0],o=t[1];return e*e+o*o},i.sqrLen=i.squaredLength,i.negate=function(t,e){return t[0]=-e[0],t[1]=-e[1],t},i.normalize=function(t,e){var o=e[0],i=e[1],n=o*o+i*i;return n>0&&(n=1/Math.sqrt(n),t[0]=e[0]*n,t[1]=e[1]*n),t},i.dot=function(t,e){return t[0]*e[0]+t[1]*e[1]},i.str=function(t){return"vec2("+t[0]+", "+t[1]+")"},i.lerp=function(t,e,o,i){var n=e[0],s=e[1];return t[0]=n+i*(o[0]-n),t[1]=s+i*(o[1]-s),t},i.reflect=function(t,e,o){var i=e[0]*o[0]+e[1]*o[1];t[0]=e[0]-2*o[0]*i,t[1]=e[1]-2*o[1]*i},i.getLineSegmentsIntersection=function(t,e,o,n,s){var a=i.getLineSegmentsIntersectionFraction(e,o,n,s);return!(a<0)&&(t[0]=e[0]+a*(o[0]-e[0]),t[1]=e[1]+a*(o[1]-e[1]),!0)},i.getLineSegmentsIntersectionFraction=function(t,e,o,i){var n,s,a=e[0]-t[0],r=e[1]-t[1],c=i[0]-o[0],h=i[1]-o[1];return n=(-r*(t[0]-o[0])+a*(t[1]-o[1]))/(-c*r+a*h),s=(c*(t[1]-o[1])-h*(t[0]-o[0]))/(-c*r+a*h),n>=0&&n<=1&&s>=0&&s<=1?s:-1}},{"../utils/Utils":57}],31:[function(t,e,o){function i(t){t=t||{},l.call(this),this.id=t.id||++i._idCounter,this.world=null,this.shapes=[],this.mass=t.mass||0,this.invMass=0,this.inertia=0,this.invInertia=0,this.invMassSolve=0,this.invInertiaSolve=0,this.fixedRotation=!!t.fixedRotation,this.fixedX=!!t.fixedX,this.fixedY=!!t.fixedY,this.massMultiplier=n.create(),this.position=n.fromValues(0,0),t.position&&n.copy(this.position,t.position),this.interpolatedPosition=n.fromValues(0,0),this.interpolatedAngle=0,this.previousPosition=n.fromValues(0,0),this.previousAngle=0,this.velocity=n.fromValues(0,0),t.velocity&&n.copy(this.velocity,t.velocity),this.vlambda=n.fromValues(0,0),this.wlambda=0,this.angle=t.angle||0,this.angularVelocity=t.angularVelocity||0,this.force=n.create(),t.force&&n.copy(this.force,t.force),this.angularForce=t.angularForce||0,this.damping="number"==typeof t.damping?t.damping:.1,this.angularDamping="number"==typeof t.angularDamping?t.angularDamping:.1,this.type=i.STATIC,void 0!==t.type?this.type=t.type:t.mass?this.type=i.DYNAMIC:this.type=i.STATIC,this.boundingRadius=0,this.aabb=new h,this.aabbNeedsUpdate=!0,this.allowSleep=void 0===t.allowSleep||t.allowSleep,this.wantsToSleep=!1,this.sleepState=i.AWAKE,this.sleepSpeedLimit=void 0!==t.sleepSpeedLimit?t.sleepSpeedLimit:.2,this.sleepTimeLimit=void 0!==t.sleepTimeLimit?t.sleepTimeLimit:1,this.gravityScale=void 0!==t.gravityScale?t.gravityScale:1,this.collisionResponse=void 0===t.collisionResponse||t.collisionResponse,this.idleTime=0,this.timeLastSleepy=0,this.ccdSpeedThreshold=void 0!==t.ccdSpeedThreshold?t.ccdSpeedThreshold:-1,this.ccdIterations=void 0!==t.ccdIterations?t.ccdIterations:10,this.concavePath=null,this._wakeUpAfterNarrowphase=!1,this.updateMassProperties()}var n=t("../math/vec2"),s=t("poly-decomp"),a=t("../shapes/Convex"),r=t("../collision/RaycastResult"),c=t("../collision/Ray"),h=t("../collision/AABB"),l=t("../events/EventEmitter");e.exports=i,i.prototype=new l,i.prototype.constructor=i,i._idCounter=0,i.prototype.updateSolveMassProperties=function(){this.sleepState===i.SLEEPING||this.type===i.KINEMATIC?(this.invMassSolve=0,this.invInertiaSolve=0):(this.invMassSolve=this.invMass,this.invInertiaSolve=this.invInertia)},i.prototype.setDensity=function(t){var e=this.getArea();this.mass=e*t,this.updateMassProperties()},i.prototype.getArea=function(){for(var t=0,e=0;e<this.shapes.length;e++)t+=this.shapes[e].area;return t},i.prototype.getAABB=function(){return this.aabbNeedsUpdate&&this.updateAABB(),this.aabb};var p=new h,u=n.create();i.prototype.updateAABB=function(){for(var t=this.shapes,e=t.length,o=u,i=this.angle,s=0;s!==e;s++){var a=t[s],r=a.angle+i;n.rotate(o,a.position,i),n.add(o,o,this.position),a.computeAABB(p,o,r),0===s?this.aabb.copy(p):this.aabb.extend(p)}this.aabbNeedsUpdate=!1},i.prototype.updateBoundingRadius=function(){for(var t=this.shapes,e=t.length,o=0,i=0;i!==e;i++){var s=t[i],a=n.length(s.position),r=s.boundingRadius;a+r>o&&(o=a+r)}this.boundingRadius=o},i.prototype.addShape=function(t,e,o){if(t.body)throw new Error("A shape can only be added to one body.");t.body=this,e?n.copy(t.position,e):n.set(t.position,0,0),t.angle=o||0,this.shapes.push(t),this.updateMassProperties(),this.updateBoundingRadius(),this.aabbNeedsUpdate=!0},i.prototype.removeShape=function(t){var e=this.shapes.indexOf(t);return-1!==e&&(this.shapes.splice(e,1),this.aabbNeedsUpdate=!0,t.body=null,!0)},i.prototype.updateMassProperties=function(){if(this.type===i.STATIC||this.type===i.KINEMATIC)this.mass=Number.MAX_VALUE,this.invMass=0,this.inertia=Number.MAX_VALUE,this.invInertia=0;else{var t=this.shapes,e=t.length,o=this.mass/e,s=0;if(this.fixedRotation)this.inertia=Number.MAX_VALUE,this.invInertia=0;else{for(var a=0;a<e;a++){var r=t[a],c=n.squaredLength(r.position);s+=r.computeMomentOfInertia(o)+o*c}this.inertia=s,this.invInertia=s>0?1/s:0}this.invMass=1/this.mass,n.set(this.massMultiplier,this.fixedX?0:1,this.fixedY?0:1)}};n.create();i.prototype.applyForce=function(t,e){if(n.add(this.force,this.force,t),e){var o=n.crossLength(e,t);this.angularForce+=o}};var d=n.create(),f=n.create(),v=n.create();i.prototype.applyForceLocal=function(t,e){e=e||v;var o=d,i=f;this.vectorToWorldFrame(o,t),this.vectorToWorldFrame(i,e),this.applyForce(o,i)};var y=n.create();i.prototype.applyImpulse=function(t,e){if(this.type===i.DYNAMIC){var o=y;if(n.scale(o,t,this.invMass),n.multiply(o,this.massMultiplier,o),n.add(this.velocity,o,this.velocity),e){var s=n.crossLength(e,t);s*=this.invInertia,this.angularVelocity+=s}}};var m=n.create(),g=n.create(),A=n.create();i.prototype.applyImpulseLocal=function(t,e){e=e||A;var o=m,i=g;this.vectorToWorldFrame(o,t),this.vectorToWorldFrame(i,e),this.applyImpulse(o,i)},i.prototype.toLocalFrame=function(t,e){n.toLocalFrame(t,e,this.position,this.angle)},i.prototype.toWorldFrame=function(t,e){n.toGlobalFrame(t,e,this.position,this.angle)},i.prototype.vectorToLocalFrame=function(t,e){n.vectorToLocalFrame(t,e,this.angle)},i.prototype.vectorToWorldFrame=function(t,e){n.vectorToGlobalFrame(t,e,this.angle)},i.prototype.fromPolygon=function(t,e){e=e||{};for(c=this.shapes.length;c>=0;--c)this.removeShape(this.shapes[c]);var o=new s.Polygon;if(o.vertices=t,o.makeCCW(),"number"==typeof e.removeCollinearPoints&&o.removeCollinearPoints(e.removeCollinearPoints),void 0===e.skipSimpleCheck&&!o.isSimple())return!1;this.concavePath=o.vertices.slice(0);for(c=0;c<this.concavePath.length;c++){p=[0,0];n.copy(p,this.concavePath[c]),this.concavePath[c]=p}var i;i=e.optimalDecomp?o.decomp():o.quickDecomp();for(var r=n.create(),c=0;c!==i.length;c++){for(var h=new a({vertices:i[c].vertices}),l=0;l!==h.vertices.length;l++){var p=h.vertices[l];n.sub(p,p,h.centerOfMass)}n.scale(r,h.centerOfMass,1),h.updateTriangles(),h.updateCenterOfMass(),h.updateBoundingRadius(),this.addShape(h,r)}return this.adjustCenterOfMass(),this.aabbNeedsUpdate=!0,!0};n.fromValues(0,0);var b=n.fromValues(0,0),E=n.fromValues(0,0),B=n.fromValues(0,0);i.prototype.adjustCenterOfMass=function(){var t=b,e=E,o=B,i=0;n.set(e,0,0);for(a=0;a!==this.shapes.length;a++){s=this.shapes[a];n.scale(t,s.position,s.area),n.add(e,e,t),i+=s.area}n.scale(o,e,1/i);for(a=0;a!==this.shapes.length;a++){var s=this.shapes[a];n.sub(s.position,s.position,o)}n.add(this.position,this.position,o);for(var a=0;this.concavePath&&a<this.concavePath.length;a++)n.sub(this.concavePath[a],this.concavePath[a],o);this.updateMassProperties(),this.updateBoundingRadius()},i.prototype.setZeroForce=function(){n.set(this.force,0,0),this.angularForce=0},i.prototype.resetConstraintVelocity=function(){var t=this,e=t.vlambda;n.set(e,0,0),t.wlambda=0},i.prototype.addConstraintVelocity=function(){var t=this,e=t.velocity;n.add(e,e,t.vlambda),t.angularVelocity+=t.wlambda},i.prototype.applyDamping=function(t){if(this.type===i.DYNAMIC){var e=this.velocity;n.scale(e,e,Math.pow(1-this.damping,t)),this.angularVelocity*=Math.pow(1-this.angularDamping,t)}},i.prototype.wakeUp=function(){var t=this.sleepState;this.sleepState=i.AWAKE,this.idleTime=0,t!==i.AWAKE&&this.emit(i.wakeUpEvent)},i.prototype.sleep=function(){this.sleepState=i.SLEEPING,this.angularVelocity=0,this.angularForce=0,n.set(this.velocity,0,0),n.set(this.force,0,0),this.emit(i.sleepEvent)},i.prototype.sleepTick=function(t,e,o){if(this.allowSleep&&this.type!==i.SLEEPING){this.wantsToSleep=!1;this.sleepState;n.squaredLength(this.velocity)+Math.pow(this.angularVelocity,2)>=Math.pow(this.sleepSpeedLimit,2)?(this.idleTime=0,this.sleepState=i.AWAKE):(this.idleTime+=o,this.sleepState=i.SLEEPY),this.idleTime>this.sleepTimeLimit&&(e?this.wantsToSleep=!0:this.sleep())}},i.prototype.overlaps=function(t){return this.world.overlapKeeper.bodiesAreOverlapping(this,t)};var q=n.create(),P=n.create();i.prototype.integrate=function(t){var e=this.invMass,o=this.force,i=this.position,s=this.velocity;n.copy(this.previousPosition,this.position),this.previousAngle=this.angle,this.fixedRotation||(this.angularVelocity+=this.angularForce*this.invInertia*t),n.scale(q,o,t*e),n.multiply(q,this.massMultiplier,q),n.add(s,q,s),this.integrateToTimeOfImpact(t)||(n.scale(P,s,t),n.add(i,i,P),this.fixedRotation||(this.angle+=this.angularVelocity*t)),this.aabbNeedsUpdate=!0};var w=new r,S=new c({mode:c.ALL}),C=n.create(),L=n.create(),x=n.create(),F=n.create();i.prototype.integrateToTimeOfImpact=function(t){if(this.ccdSpeedThreshold<0||n.squaredLength(this.velocity)<Math.pow(this.ccdSpeedThreshold,2))return!1;n.normalize(C,this.velocity),n.scale(L,this.velocity,t),n.add(L,L,this.position),n.sub(x,L,this.position);var e,o=this.angularVelocity*t,i=n.length(x),s=1,a=this;if(w.reset(),S.callback=function(t){t.body!==a&&(e=t.body,t.getHitPoint(L,S),n.sub(x,L,a.position),s=n.length(x)/i,t.stop())},n.copy(S.from,this.position),n.copy(S.to,L),S.update(),this.world.raycast(w,S),!e)return!1;var r=this.angle;n.copy(F,this.position);for(var c=0,h=0,l=0,p=s;p>=h&&c<this.ccdIterations;)c++,l=(p-h)/2,n.scale(P,x,s),n.add(this.position,F,P),this.angle=r+o*s,this.updateAABB(),this.aabb.overlaps(e.aabb)&&this.world.narrowphase.bodiesOverlap(this,e)?h=l:p=l;return s=l,n.copy(this.position,F),this.angle=r,n.scale(P,x,s),n.add(this.position,this.position,P),this.fixedRotation||(this.angle+=o*s),!0},i.prototype.getVelocityAtPoint=function(t,e){return n.crossVZ(t,e,this.angularVelocity),n.subtract(t,this.velocity,t),t},i.sleepyEvent={type:"sleepy"},i.sleepEvent={type:"sleep"},i.wakeUpEvent={type:"wakeup"},i.DYNAMIC=1,i.STATIC=2,i.KINEMATIC=4,i.AWAKE=0,i.SLEEPY=1,i.SLEEPING=2},{"../collision/AABB":7,"../collision/Ray":11,"../collision/RaycastResult":12,"../events/EventEmitter":26,"../math/vec2":30,"../shapes/Convex":40,"poly-decomp":5}],32:[function(t,e,o){function i(t,e,o){o=o||{},s.call(this,t,e,o),this.localAnchorA=n.fromValues(0,0),this.localAnchorB=n.fromValues(0,0),o.localAnchorA&&n.copy(this.localAnchorA,o.localAnchorA),o.localAnchorB&&n.copy(this.localAnchorB,o.localAnchorB),o.worldAnchorA&&this.setWorldAnchorA(o.worldAnchorA),o.worldAnchorB&&this.setWorldAnchorB(o.worldAnchorB);var i=n.create(),a=n.create();this.getWorldAnchorA(i),this.getWorldAnchorB(a);var r=n.distance(i,a);this.restLength="number"==typeof o.restLength?o.restLength:r}var n=t("../math/vec2"),s=t("./Spring");t("../utils/Utils");e.exports=i,(i.prototype=new s).constructor=i,i.prototype.setWorldAnchorA=function(t){this.bodyA.toLocalFrame(this.localAnchorA,t)},i.prototype.setWorldAnchorB=function(t){this.bodyB.toLocalFrame(this.localAnchorB,t)},i.prototype.getWorldAnchorA=function(t){this.bodyA.toWorldFrame(t,this.localAnchorA)},i.prototype.getWorldAnchorB=function(t){this.bodyB.toWorldFrame(t,this.localAnchorB)};var a=n.create(),r=n.create(),c=n.create(),h=n.create(),l=n.create(),p=n.create(),u=n.create(),d=n.create(),f=n.create();i.prototype.applyForce=function(){var t=this.stiffness,e=this.damping,o=this.restLength,i=this.bodyA,s=this.bodyB,v=a,y=r,m=c,g=h,A=f,b=l,E=p,B=u,q=d;this.getWorldAnchorA(b),this.getWorldAnchorB(E),n.sub(B,b,i.position),n.sub(q,E,s.position),n.sub(v,E,b);var P=n.len(v);n.normalize(y,v),n.sub(m,s.velocity,i.velocity),n.crossZV(A,s.angularVelocity,q),n.add(m,m,A),n.crossZV(A,i.angularVelocity,B),n.sub(m,m,A),n.scale(g,y,-t*(P-o)-e*n.dot(m,y)),n.sub(i.force,i.force,g),n.add(s.force,s.force,g);var w=n.crossLength(B,g),S=n.crossLength(q,g);i.angularForce-=w,s.angularForce+=S}},{"../math/vec2":30,"../utils/Utils":57,"./Spring":34}],33:[function(t,e,o){function i(t,e,o){o=o||{},n.call(this,t,e,o),this.restAngle="number"==typeof o.restAngle?o.restAngle:e.angle-t.angle}t("../math/vec2");var n=t("./Spring");e.exports=i,(i.prototype=new n).constructor=i,i.prototype.applyForce=function(){var t=this.stiffness,e=this.damping,o=this.restAngle,i=this.bodyA,n=this.bodyB,s=-t*(n.angle-i.angle-o)-e*(n.angularVelocity-i.angularVelocity)*0;i.angularForce-=s,n.angularForce+=s}},{"../math/vec2":30,"./Spring":34}],34:[function(t,e,o){function i(t,e,o){o=n.defaults(o,{stiffness:100,damping:1}),this.stiffness=o.stiffness,this.damping=o.damping,this.bodyA=t,this.bodyB=e}t("../math/vec2");var n=t("../utils/Utils");e.exports=i,i.prototype.applyForce=function(){}},{"../math/vec2":30,"../utils/Utils":57}],35:[function(t,e,o){function i(t,e){e=e||{},this.chassisBody=t,this.wheels=[],this.groundBody=new c({mass:0}),this.world=null;var o=this;this.preStepCallback=function(){o.update()}}function n(t,e){e=e||{},this.vehicle=t,this.forwardEquation=new r(t.chassisBody,t.groundBody),this.sideEquation=new r(t.chassisBody,t.groundBody),this.steerValue=0,this.engineForce=0,this.setSideFriction(void 0!==e.sideFriction?e.sideFriction:5),this.localForwardVector=s.fromValues(0,1),e.localForwardVector&&s.copy(this.localForwardVector,e.localForwardVector),this.localPosition=s.fromValues(0,0),e.localPosition&&s.copy(this.localPosition,e.localPosition),a.apply(this,t.chassisBody,t.groundBody),this.equations.push(this.forwardEquation,this.sideEquation),this.setBrakeForce(0)}var s=t("../math/vec2"),a=(t("../utils/Utils"),t("../constraints/Constraint")),r=t("../equations/FrictionEquation"),c=t("../objects/Body");e.exports=i,i.prototype.addToWorld=function(t){this.world=t,t.addBody(this.groundBody),t.on("preStep",this.preStepCallback);for(var e=0;e<this.wheels.length;e++){var o=this.wheels[e];t.addConstraint(o)}},i.prototype.removeFromWorld=function(){var t=this.world;t.removeBody(this.groundBody),t.off("preStep",this.preStepCallback);for(var e=0;e<this.wheels.length;e++){var o=this.wheels[e];t.removeConstraint(o)}this.world=null},i.prototype.addWheel=function(t){var e=new n(this,t);return this.wheels.push(e),e},i.prototype.update=function(){for(var t=0;t<this.wheels.length;t++)this.wheels[t].update()},(n.prototype=new a).setBrakeForce=function(t){this.forwardEquation.setSlipForce(t)},n.prototype.setSideFriction=function(t){this.sideEquation.setSlipForce(t)};var h=s.create(),l=s.create();n.prototype.getSpeed=function(){return this.vehicle.chassisBody.vectorToWorldFrame(l,this.localForwardVector),this.vehicle.chassisBody.getVelocityAtPoint(h,l),s.dot(h,l)};var p=s.create();n.prototype.update=function(){this.vehicle.chassisBody.vectorToWorldFrame(this.forwardEquation.t,this.localForwardVector),s.rotate(this.sideEquation.t,this.localForwardVector,Math.PI/2),this.vehicle.chassisBody.vectorToWorldFrame(this.sideEquation.t,this.sideEquation.t),s.rotate(this.forwardEquation.t,this.forwardEquation.t,this.steerValue),s.rotate(this.sideEquation.t,this.sideEquation.t,this.steerValue),this.vehicle.chassisBody.toWorldFrame(this.forwardEquation.contactPointB,this.localPosition),s.copy(this.sideEquation.contactPointB,this.forwardEquation.contactPointB),this.vehicle.chassisBody.vectorToWorldFrame(this.forwardEquation.contactPointA,this.localPosition),s.copy(this.sideEquation.contactPointA,this.forwardEquation.contactPointA),s.normalize(p,this.forwardEquation.t),s.scale(p,p,this.engineForce),this.vehicle.chassisBody.applyForce(p,this.forwardEquation.contactPointA)}},{"../constraints/Constraint":14,"../equations/FrictionEquation":23,"../math/vec2":30,"../objects/Body":31,"../utils/Utils":57}],36:[function(t,e,o){var i=e.exports={AABB:t("./collision/AABB"),AngleLockEquation:t("./equations/AngleLockEquation"),Body:t("./objects/Body"),Broadphase:t("./collision/Broadphase"),Capsule:t("./shapes/Capsule"),Circle:t("./shapes/Circle"),Constraint:t("./constraints/Constraint"),ContactEquation:t("./equations/ContactEquation"),ContactEquationPool:t("./utils/ContactEquationPool"),ContactMaterial:t("./material/ContactMaterial"),Convex:t("./shapes/Convex"),DistanceConstraint:t("./constraints/DistanceConstraint"),Equation:t("./equations/Equation"),EventEmitter:t("./events/EventEmitter"),FrictionEquation:t("./equations/FrictionEquation"),FrictionEquationPool:t("./utils/FrictionEquationPool"),GearConstraint:t("./constraints/GearConstraint"),GSSolver:t("./solver/GSSolver"),Heightfield:t("./shapes/Heightfield"),Line:t("./shapes/Line"),LockConstraint:t("./constraints/LockConstraint"),Material:t("./material/Material"),Narrowphase:t("./collision/Narrowphase"),NaiveBroadphase:t("./collision/NaiveBroadphase"),Particle:t("./shapes/Particle"),Plane:t("./shapes/Plane"),Pool:t("./utils/Pool"),RevoluteConstraint:t("./constraints/RevoluteConstraint"),PrismaticConstraint:t("./constraints/PrismaticConstraint"),Ray:t("./collision/Ray"),RaycastResult:t("./collision/RaycastResult"),Box:t("./shapes/Box"),RotationalVelocityEquation:t("./equations/RotationalVelocityEquation"),SAPBroadphase:t("./collision/SAPBroadphase"),Shape:t("./shapes/Shape"),Solver:t("./solver/Solver"),Spring:t("./objects/Spring"),TopDownVehicle:t("./objects/TopDownVehicle"),LinearSpring:t("./objects/LinearSpring"),RotationalSpring:t("./objects/RotationalSpring"),Utils:t("./utils/Utils"),World:t("./world/World"),vec2:t("./math/vec2"),version:t("../package.json").version};Object.defineProperty(i,"Rectangle",{get:function(){return console.warn("The Rectangle class has been renamed to Box."),this.Box}})},{"../package.json":6,"./collision/AABB":7,"./collision/Broadphase":8,"./collision/NaiveBroadphase":9,"./collision/Narrowphase":10,"./collision/Ray":11,"./collision/RaycastResult":12,"./collision/SAPBroadphase":13,"./constraints/Constraint":14,"./constraints/DistanceConstraint":15,"./constraints/GearConstraint":16,"./constraints/LockConstraint":17,"./constraints/PrismaticConstraint":18,"./constraints/RevoluteConstraint":19,"./equations/AngleLockEquation":20,"./equations/ContactEquation":21,"./equations/Equation":22,"./equations/FrictionEquation":23,"./equations/RotationalVelocityEquation":25,"./events/EventEmitter":26,"./material/ContactMaterial":27,"./material/Material":28,"./math/vec2":30,"./objects/Body":31,"./objects/LinearSpring":32,"./objects/RotationalSpring":33,"./objects/Spring":34,"./objects/TopDownVehicle":35,"./shapes/Box":37,"./shapes/Capsule":38,"./shapes/Circle":39,"./shapes/Convex":40,"./shapes/Heightfield":41,"./shapes/Line":42,"./shapes/Particle":43,"./shapes/Plane":44,"./shapes/Shape":45,"./solver/GSSolver":46,"./solver/Solver":47,"./utils/ContactEquationPool":48,"./utils/FrictionEquationPool":49,"./utils/Pool":55,"./utils/Utils":57,"./world/World":61}],37:[function(t,e,o){function i(t){"number"==typeof arguments[0]&&"number"==typeof arguments[1]&&(t={width:arguments[0],height:arguments[1]},console.warn("The Rectangle has been renamed to Box and its constructor signature has changed. Please use the following format: new Box({ width: 1, height: 1, ... })")),t=t||{};var e=this.width=t.width||1,o=this.height=t.height||1,i=[n.fromValues(-e/2,-o/2),n.fromValues(e/2,-o/2),n.fromValues(e/2,o/2),n.fromValues(-e/2,o/2)],r=[n.fromValues(1,0),n.fromValues(0,1)];t.vertices=i,t.axes=r,t.type=s.BOX,a.call(this,t)}var n=t("../math/vec2"),s=t("./Shape"),a=t("./Convex");e.exports=i,(i.prototype=new a).constructor=i,i.prototype.computeMomentOfInertia=function(t){var e=this.width,o=this.height;return t*(o*o+e*e)/12},i.prototype.updateBoundingRadius=function(){var t=this.width,e=this.height;this.boundingRadius=Math.sqrt(t*t+e*e)/2};n.create(),n.create(),n.create(),n.create();i.prototype.computeAABB=function(t,e,o){t.setFromPoints(this.vertices,e,o,0)},i.prototype.updateArea=function(){this.area=this.width*this.height}},{"../math/vec2":30,"./Convex":40,"./Shape":45}],38:[function(t,e,o){function i(t){"number"==typeof arguments[0]&&"number"==typeof arguments[1]&&(t={length:arguments[0],radius:arguments[1]},console.warn("The Capsule constructor signature has changed. Please use the following format: new Capsule({ radius: 1, length: 1 })")),t=t||{},this.length=t.length||1,this.radius=t.radius||1,t.type=n.CAPSULE,n.call(this,t)}var n=t("./Shape"),s=t("../math/vec2");e.exports=i,(i.prototype=new n).constructor=i,i.prototype.computeMomentOfInertia=function(t){var e=this.radius,o=this.length+e,i=2*e;return t*(i*i+o*o)/12},i.prototype.updateBoundingRadius=function(){this.boundingRadius=this.radius+this.length/2},i.prototype.updateArea=function(){this.area=Math.PI*this.radius*this.radius+2*this.radius*this.length};var a=s.create();i.prototype.computeAABB=function(t,e,o){var i=this.radius;s.set(a,this.length/2,0),0!==o&&s.rotate(a,a,o),s.set(t.upperBound,Math.max(a[0]+i,-a[0]+i),Math.max(a[1]+i,-a[1]+i)),s.set(t.lowerBound,Math.min(a[0]-i,-a[0]-i),Math.min(a[1]-i,-a[1]-i)),s.add(t.lowerBound,t.lowerBound,e),s.add(t.upperBound,t.upperBound,e)};var r=s.create(),c=s.create(),h=s.create(),l=s.create(),p=s.fromValues(0,1);i.prototype.raycast=function(t,e,o,i){for(var n=e.from,a=e.to,u=(e.direction,r),d=c,f=h,v=l,y=this.length/2,m=0;m<2;m++){var g=this.radius*(2*m-1);if(s.set(f,-y,g),s.set(v,y,g),s.toGlobalFrame(f,f,o,i),s.toGlobalFrame(v,v,o,i),(q=s.getLineSegmentsIntersectionFraction(n,a,f,v))>=0&&(s.rotate(d,p,i),s.scale(d,d,2*m-1),e.reportIntersection(t,q,d,-1),t.shouldStop(e)))return}for(var A=Math.pow(this.radius,2)+Math.pow(y,2),m=0;m<2;m++){s.set(f,y*(2*m-1),0),s.toGlobalFrame(f,f,o,i);var b=Math.pow(a[0]-n[0],2)+Math.pow(a[1]-n[1],2),E=2*((a[0]-n[0])*(n[0]-f[0])+(a[1]-n[1])*(n[1]-f[1])),B=Math.pow(n[0]-f[0],2)+Math.pow(n[1]-f[1],2)-Math.pow(this.radius,2),q=Math.pow(E,2)-4*b*B;if(!(q<0))if(0===q){if(s.lerp(u,n,a,q),s.squaredDistance(u,o)>A&&(s.sub(d,u,f),s.normalize(d,d),e.reportIntersection(t,q,d,-1),t.shouldStop(e)))return}else{var P=Math.sqrt(q),w=1/(2*b),S=(-E-P)*w,C=(-E+P)*w;if(S>=0&&S<=1&&(s.lerp(u,n,a,S),s.squaredDistance(u,o)>A&&(s.sub(d,u,f),s.normalize(d,d),e.reportIntersection(t,S,d,-1),t.shouldStop(e))))return;if(C>=0&&C<=1&&(s.lerp(u,n,a,C),s.squaredDistance(u,o)>A&&(s.sub(d,u,f),s.normalize(d,d),e.reportIntersection(t,C,d,-1),t.shouldStop(e))))return}}}},{"../math/vec2":30,"./Shape":45}],39:[function(t,e,o){function i(t){"number"==typeof arguments[0]&&(t={radius:arguments[0]},console.warn("The Circle constructor signature has changed. Please use the following format: new Circle({ radius: 1 })")),t=t||{},this.radius=t.radius||1,t.type=n.CIRCLE,n.call(this,t)}var n=t("./Shape"),s=t("../math/vec2");e.exports=i,(i.prototype=new n).constructor=i,i.prototype.computeMomentOfInertia=function(t){var e=this.radius;return t*e*e/2},i.prototype.updateBoundingRadius=function(){this.boundingRadius=this.radius},i.prototype.updateArea=function(){this.area=Math.PI*this.radius*this.radius},i.prototype.computeAABB=function(t,e,o){var i=this.radius;s.set(t.upperBound,i,i),s.set(t.lowerBound,-i,-i),e&&(s.add(t.lowerBound,t.lowerBound,e),s.add(t.upperBound,t.upperBound,e))};var a=s.create(),r=s.create();i.prototype.raycast=function(t,e,o,i){var n=e.from,c=e.to,h=this.radius,l=Math.pow(c[0]-n[0],2)+Math.pow(c[1]-n[1],2),p=2*((c[0]-n[0])*(n[0]-o[0])+(c[1]-n[1])*(n[1]-o[1])),u=Math.pow(n[0]-o[0],2)+Math.pow(n[1]-o[1],2)-Math.pow(h,2),d=Math.pow(p,2)-4*l*u,f=a,v=r;if(!(d<0))if(0===d)s.lerp(f,n,c,d),s.sub(v,f,o),s.normalize(v,v),e.reportIntersection(t,d,v,-1);else{var y=Math.sqrt(d),m=1/(2*l),g=(-p-y)*m,A=(-p+y)*m;if(g>=0&&g<=1&&(s.lerp(f,n,c,g),s.sub(v,f,o),s.normalize(v,v),e.reportIntersection(t,g,v,-1),t.shouldStop(e)))return;A>=0&&A<=1&&(s.lerp(f,n,c,A),s.sub(v,f,o),s.normalize(v,v),e.reportIntersection(t,A,v,-1))}}},{"../math/vec2":30,"./Shape":45}],40:[function(t,e,o){function i(t){Array.isArray(arguments[0])&&(t={vertices:arguments[0],axes:arguments[1]},console.warn("The Convex constructor signature has changed. Please use the following format: new Convex({ vertices: [...], ... })")),t=t||{},this.vertices=[];for(var e=void 0!==t.vertices?t.vertices:[],o=0;o<e.length;o++){var i=s.create();s.copy(i,e[o]),this.vertices.push(i)}if(this.axes=[],t.axes)for(o=0;o<t.axes.length;o++){var a=s.create();s.copy(a,t.axes[o]),this.axes.push(a)}else for(o=0;o<this.vertices.length;o++){var r=this.vertices[o],c=this.vertices[(o+1)%this.vertices.length],h=s.create();s.sub(h,c,r),s.rotate90cw(h,h),s.normalize(h,h),this.axes.push(h)}if(this.centerOfMass=s.fromValues(0,0),this.triangles=[],this.vertices.length&&(this.updateTriangles(),this.updateCenterOfMass()),this.boundingRadius=0,t.type=n.CONVEX,n.call(this,t),this.updateBoundingRadius(),this.updateArea(),this.area<0)throw new Error("Convex vertices must be given in conter-clockwise winding.")}var n=t("./Shape"),s=t("../math/vec2"),a=t("../math/polyk");t("poly-decomp");e.exports=i,(i.prototype=new n).constructor=i;var r=s.create(),c=s.create();i.prototype.projectOntoLocalAxis=function(t,e){for(var o,i,n=null,a=null,t=r,c=0;c<this.vertices.length;c++)o=this.vertices[c],i=s.dot(o,t),(null===n||i>n)&&(n=i),(null===a||i<a)&&(a=i);if(a>n){var h=a;a=n,n=h}s.set(e,a,n)},i.prototype.projectOntoWorldAxis=function(t,e,o,i){var n=c;this.projectOntoLocalAxis(t,i),0!==o?s.rotate(n,t,o):n=t;var a=s.dot(e,n);s.set(i,i[0]+a,i[1]+a)},i.prototype.updateTriangles=function(){this.triangles.length=0;for(var t=[],e=0;e<this.vertices.length;e++){var o=this.vertices[e];t.push(o[0],o[1])}for(var i=a.Triangulate(t),e=0;e<i.length;e+=3){var n=i[e],s=i[e+1],r=i[e+2];this.triangles.push([n,s,r])}};var h=s.create(),l=s.create(),p=s.create(),u=s.create(),d=s.create();s.create(),s.create(),s.create(),s.create();i.prototype.updateCenterOfMass=function(){var t=this.triangles,e=this.vertices,o=this.centerOfMass,n=h,a=p,r=u,c=d,f=l;s.set(o,0,0);for(var v=0,y=0;y!==t.length;y++){var m=t[y],a=e[m[0]],r=e[m[1]],c=e[m[2]];s.centroid(n,a,r,c);var g=i.triangleArea(a,r,c);v+=g,s.scale(f,n,g),s.add(o,o,f)}s.scale(o,o,1/v)},i.prototype.computeMomentOfInertia=function(t){for(var e=0,o=0,i=this.vertices.length,n=i-1,a=0;a<i;n=a,a++){var r=this.vertices[n],c=this.vertices[a],h=Math.abs(s.crossLength(r,c));e+=h*(s.dot(c,c)+s.dot(c,r)+s.dot(r,r)),o+=h}return t/6*(e/o)},i.prototype.updateBoundingRadius=function(){for(var t=this.vertices,e=0,o=0;o!==t.length;o++){var i=s.squaredLength(t[o]);i>e&&(e=i)}this.boundingRadius=Math.sqrt(e)},i.triangleArea=function(t,e,o){return.5*((e[0]-t[0])*(o[1]-t[1])-(o[0]-t[0])*(e[1]-t[1]))},i.prototype.updateArea=function(){this.updateTriangles(),this.area=0;for(var t=this.triangles,e=this.vertices,o=0;o!==t.length;o++){var n=t[o],s=e[n[0]],a=e[n[1]],r=e[n[2]],c=i.triangleArea(s,a,r);this.area+=c}},i.prototype.computeAABB=function(t,e,o){t.setFromPoints(this.vertices,e,o,0)};var f=s.create(),v=s.create(),y=s.create();i.prototype.raycast=function(t,e,o,i){var n=f,a=v,r=y,c=this.vertices;s.toLocalFrame(n,e.from,o,i),s.toLocalFrame(a,e.to,o,i);for(var h=c.length,l=0;l<h&&!t.shouldStop(e);l++){var p=c[l],u=c[(l+1)%h],d=s.getLineSegmentsIntersectionFraction(n,a,p,u);d>=0&&(s.sub(r,u,p),s.rotate(r,r,-Math.PI/2+i),s.normalize(r,r),e.reportIntersection(t,d,r,l))}}},{"../math/polyk":29,"../math/vec2":30,"./Shape":45,"poly-decomp":5}],41:[function(t,e,o){function i(t){if(Array.isArray(arguments[0])){if(t={heights:arguments[0]},"object"==typeof arguments[1])for(var e in arguments[1])t[e]=arguments[1][e];console.warn("The Heightfield constructor signature has changed. Please use the following format: new Heightfield({ heights: [...], ... })")}t=t||{},this.heights=t.heights?t.heights.slice(0):[],this.maxValue=t.maxValue||null,this.minValue=t.minValue||null,this.elementWidth=t.elementWidth||.1,void 0!==t.maxValue&&void 0!==t.minValue||this.updateMaxMinValues(),t.type=n.HEIGHTFIELD,n.call(this,t)}var n=t("./Shape"),s=t("../math/vec2");t("../utils/Utils");e.exports=i,(i.prototype=new n).constructor=i,i.prototype.updateMaxMinValues=function(){for(var t=this.heights,e=t[0],o=t[0],i=0;i!==t.length;i++){var n=t[i];n>e&&(e=n),n<o&&(o=n)}this.maxValue=e,this.minValue=o},i.prototype.computeMomentOfInertia=function(t){return Number.MAX_VALUE},i.prototype.updateBoundingRadius=function(){this.boundingRadius=Number.MAX_VALUE},i.prototype.updateArea=function(){for(var t=this.heights,e=0,o=0;o<t.length-1;o++)e+=(t[o]+t[o+1])/2*this.elementWidth;this.area=e};var a=[s.create(),s.create(),s.create(),s.create()];i.prototype.computeAABB=function(t,e,o){s.set(a[0],0,this.maxValue),s.set(a[1],this.elementWidth*this.heights.length,this.maxValue),s.set(a[2],this.elementWidth*this.heights.length,this.minValue),s.set(a[3],0,this.minValue),t.setFromPoints(a,e,o)},i.prototype.getLineSegment=function(t,e,o){var i=this.heights,n=this.elementWidth;s.set(t,o*n,i[o]),s.set(e,(o+1)*n,i[o+1])},i.prototype.getSegmentIndex=function(t){return Math.floor(t[0]/this.elementWidth)},i.prototype.getClampedSegmentIndex=function(t){var e=this.getSegmentIndex(t);return e=Math.min(this.heights.length,Math.max(e,0))};s.create();var r=s.create(),c=s.create(),h=s.create(),l=s.create(),p=s.create();s.fromValues(0,1);i.prototype.raycast=function(t,e,o,i){var n=e.from,a=e.to,u=(e.direction,r),d=c,f=h,v=l,y=p;s.toLocalFrame(v,n,o,i),s.toLocalFrame(y,a,o,i);var m=this.getClampedSegmentIndex(v),g=this.getClampedSegmentIndex(y);if(m>g){var A=m;m=g,g=A}for(var b=0;b<this.heights.length-1;b++){this.getLineSegment(d,f,b);var E=s.getLineSegmentsIntersectionFraction(v,y,d,f);if(E>=0&&(s.sub(u,f,d),s.rotate(u,u,i+Math.PI/2),s.normalize(u,u),e.reportIntersection(t,E,u,-1),t.shouldStop(e)))return}}},{"../math/vec2":30,"../utils/Utils":57,"./Shape":45}],42:[function(t,e,o){function i(t){"number"==typeof arguments[0]&&(t={length:arguments[0]},console.warn("The Line constructor signature has changed. Please use the following format: new Line({ length: 1, ... })")),t=t||{},this.length=t.length||1,t.type=n.LINE,n.call(this,t)}var n=t("./Shape"),s=t("../math/vec2");e.exports=i,(i.prototype=new n).constructor=i,i.prototype.computeMomentOfInertia=function(t){return t*Math.pow(this.length,2)/12},i.prototype.updateBoundingRadius=function(){this.boundingRadius=this.length/2};var a=[s.create(),s.create()];i.prototype.computeAABB=function(t,e,o){var i=this.length/2;s.set(a[0],-i,0),s.set(a[1],i,0),t.setFromPoints(a,e,o,0)};s.create();var r=s.create(),c=s.create(),h=s.create(),l=s.fromValues(0,1);i.prototype.raycast=function(t,e,o,i){var n=e.from,a=e.to,p=c,u=h,d=this.length/2;s.set(p,-d,0),s.set(u,d,0),s.toGlobalFrame(p,p,o,i),s.toGlobalFrame(u,u,o,i);var f=s.getLineSegmentsIntersectionFraction(p,u,n,a);if(f>=0){var v=r;s.rotate(v,l,i),e.reportIntersection(t,f,v,-1)}}},{"../math/vec2":30,"./Shape":45}],43:[function(t,e,o){function i(t){(t=t||{}).type=n.PARTICLE,n.call(this,t)}var n=t("./Shape"),s=t("../math/vec2");e.exports=i,(i.prototype=new n).constructor=i,i.prototype.computeMomentOfInertia=function(t){return 0},i.prototype.updateBoundingRadius=function(){this.boundingRadius=0},i.prototype.computeAABB=function(t,e,o){s.copy(t.lowerBound,e),s.copy(t.upperBound,e)}},{"../math/vec2":30,"./Shape":45}],44:[function(t,e,o){function i(t){(t=t||{}).type=n.PLANE,n.call(this,t)}var n=t("./Shape"),s=t("../math/vec2");t("../utils/Utils");e.exports=i,(i.prototype=new n).constructor=i,i.prototype.computeMomentOfInertia=function(t){return 0},i.prototype.updateBoundingRadius=function(){this.boundingRadius=Number.MAX_VALUE},i.prototype.computeAABB=function(t,e,o){var i=o%(2*Math.PI),n=s.set,a=t.lowerBound,r=t.upperBound;n(a,-1e7,-1e7),n(r,1e7,1e7),0===i?r[1]=0:i===Math.PI/2?a[0]=0:i===Math.PI?a[1]=0:i===3*Math.PI/2&&(r[0]=0)},i.prototype.updateArea=function(){this.area=Number.MAX_VALUE};var a=s.create(),r=(s.create(),s.create(),s.create()),c=s.create();i.prototype.raycast=function(t,e,o,i){var n=e.from,h=e.to,l=e.direction,p=a,u=r,d=c;s.set(u,0,1),s.rotate(u,u,i),s.sub(d,n,o);var f=s.dot(d,u);if(s.sub(d,h,o),!(f*s.dot(d,u)>0||s.squaredDistance(n,h)<f*f)){var v=s.dot(u,l);s.sub(p,n,o);var y=-s.dot(u,p)/v/e.length;e.reportIntersection(t,y,u,-1)}}},{"../math/vec2":30,"../utils/Utils":57,"./Shape":45}],45:[function(t,e,o){function i(t){t=t||{},this.body=null,this.position=n.fromValues(0,0),t.position&&n.copy(this.position,t.position),this.angle=t.angle||0,this.type=t.type||0,this.id=i.idCounter++,this.boundingRadius=0,this.collisionGroup=void 0!==t.collisionGroup?t.collisionGroup:1,this.collisionResponse=void 0===t.collisionResponse||t.collisionResponse,this.collisionMask=void 0!==t.collisionMask?t.collisionMask:1,this.material=t.material||null,this.area=0,this.sensor=void 0!==t.sensor&&t.sensor,this.type&&this.updateBoundingRadius(),this.updateArea()}e.exports=i;var n=t("../math/vec2");i.idCounter=0,i.CIRCLE=1,i.PARTICLE=2,i.PLANE=4,i.CONVEX=8,i.LINE=16,i.BOX=32,Object.defineProperty(i,"RECTANGLE",{get:function(){return console.warn("Shape.RECTANGLE is deprecated, use Shape.BOX instead."),i.BOX}}),i.CAPSULE=64,i.HEIGHTFIELD=128,i.prototype.computeMomentOfInertia=function(t){},i.prototype.updateBoundingRadius=function(){},i.prototype.updateArea=function(){},i.prototype.computeAABB=function(t,e,o){},i.prototype.raycast=function(t,e,o,i){}},{"../math/vec2":30}],46:[function(t,e,o){function i(t){a.call(this,t,a.GS),t=t||{},this.iterations=t.iterations||10,this.tolerance=t.tolerance||1e-7,this.arrayStep=30,this.lambda=new r.ARRAY_TYPE(this.arrayStep),this.Bs=new r.ARRAY_TYPE(this.arrayStep),this.invCs=new r.ARRAY_TYPE(this.arrayStep),this.useZeroRHS=!1,this.frictionIterations=void 0!==t.frictionIterations?0:t.frictionIterations,this.usedIterations=0}function n(t){for(var e=t.length;e--;)t[e]=0}var s=t("../math/vec2"),a=t("./Solver"),r=t("../utils/Utils"),c=t("../equations/FrictionEquation");e.exports=i,(i.prototype=new a).constructor=i,i.prototype.solve=function(t,e){this.sortEquations();var o=0,a=this.iterations,h=this.frictionIterations,l=this.equations,p=l.length,u=Math.pow(this.tolerance*p,2),d=e.bodies,f=e.bodies.length,v=(s.add,s.set,this.useZeroRHS),y=this.lambda;if(this.usedIterations=0,p)for(A=0;A!==f;A++)(q=d[A]).updateSolveMassProperties();y.length<p&&(y=this.lambda=new r.ARRAY_TYPE(p+this.arrayStep),this.Bs=new r.ARRAY_TYPE(p+this.arrayStep),this.invCs=new r.ARRAY_TYPE(p+this.arrayStep)),n(y);for(var m=this.invCs,g=this.Bs,y=this.lambda,A=0;A!==l.length;A++)((b=l[A]).timeStep!==t||b.needsUpdate)&&(b.timeStep=t,b.update()),g[A]=b.computeB(b.a,b.b,t),m[A]=b.computeInvC(b.epsilon);var b,E,B;if(0!==p){for(A=0;A!==f;A++){var q=d[A];q.resetConstraintVelocity()}if(h){for(o=0;o!==h;o++){for(E=0,B=0;B!==p;B++){b=l[B];C=i.iterateEquation(B,b,b.epsilon,g,m,y,v,t,o);E+=Math.abs(C)}if(this.usedIterations++,E*E<=u)break}for(i.updateMultipliers(l,y,1/t),B=0;B!==p;B++){var P=l[B];if(P instanceof c){for(var w=0,S=0;S!==P.contactEquations.length;S++)w+=P.contactEquations[S].multiplier;w*=P.frictionCoefficient/P.contactEquations.length,P.maxForce=w,P.minForce=-w}}}for(o=0;o!==a;o++){for(E=0,B=0;B!==p;B++){b=l[B];var C=i.iterateEquation(B,b,b.epsilon,g,m,y,v,t,o);E+=Math.abs(C)}if(this.usedIterations++,E*E<=u)break}for(A=0;A!==f;A++)d[A].addConstraintVelocity();i.updateMultipliers(l,y,1/t)}},i.updateMultipliers=function(t,e,o){for(var i=t.length;i--;)t[i].multiplier=e[i]*o},i.iterateEquation=function(t,e,o,i,n,s,a,r,c){var h=i[t],l=n[t],p=s[t],u=e.computeGWlambda(),d=e.maxForce,f=e.minForce;a&&(h=0);var v=l*(h-u-o*p),y=p+v;return y<f*r?v=f*r-p:y>d*r&&(v=d*r-p),s[t]+=v,e.addToWlambda(v),v}},{"../equations/FrictionEquation":23,"../math/vec2":30,"../utils/Utils":57,"./Solver":47}],47:[function(t,e,o){function i(t,e){t=t||{},n.call(this),this.type=e,this.equations=[],this.equationSortFunction=t.equationSortFunction||!1}t("../utils/Utils");var n=t("../events/EventEmitter");e.exports=i,(i.prototype=new n).constructor=i,i.prototype.solve=function(t,e){throw new Error("Solver.solve should be implemented by subclasses!")};var s={bodies:[]};i.prototype.solveIsland=function(t,e){this.removeAllEquations(),e.equations.length&&(this.addEquations(e.equations),s.bodies.length=0,e.getBodies(s.bodies),s.bodies.length&&this.solve(t,s))},i.prototype.sortEquations=function(){this.equationSortFunction&&this.equations.sort(this.equationSortFunction)},i.prototype.addEquation=function(t){t.enabled&&this.equations.push(t)},i.prototype.addEquations=function(t){for(var e=0,o=t.length;e!==o;e++){var i=t[e];i.enabled&&this.equations.push(i)}},i.prototype.removeEquation=function(t){var e=this.equations.indexOf(t);-1!==e&&this.equations.splice(e,1)},i.prototype.removeAllEquations=function(){this.equations.length=0},i.GS=1,i.ISLAND=2},{"../events/EventEmitter":26,"../utils/Utils":57}],48:[function(t,e,o){function i(){s.apply(this,arguments)}var n=t("../equations/ContactEquation"),s=t("./Pool");e.exports=i,(i.prototype=new s).constructor=i,i.prototype.create=function(){return new n},i.prototype.destroy=function(t){return t.bodyA=t.bodyB=null,this}},{"../equations/ContactEquation":21,"./Pool":55}],49:[function(t,e,o){function i(){s.apply(this,arguments)}var n=t("../equations/FrictionEquation"),s=t("./Pool");e.exports=i,(i.prototype=new s).constructor=i,i.prototype.create=function(){return new n},i.prototype.destroy=function(t){return t.bodyA=t.bodyB=null,this}},{"../equations/FrictionEquation":23,"./Pool":55}],50:[function(t,e,o){function i(){s.apply(this,arguments)}var n=t("../world/IslandNode"),s=t("./Pool");e.exports=i,(i.prototype=new s).constructor=i,i.prototype.create=function(){return new n},i.prototype.destroy=function(t){return t.reset(),this}},{"../world/IslandNode":60,"./Pool":55}],51:[function(t,e,o){function i(){s.apply(this,arguments)}var n=t("../world/Island"),s=t("./Pool");e.exports=i,(i.prototype=new s).constructor=i,i.prototype.create=function(){return new n},i.prototype.destroy=function(t){return t.reset(),this}},{"../world/Island":58,"./Pool":55}],52:[function(t,e,o){function i(){this.overlappingShapesLastState=new n,this.overlappingShapesCurrentState=new n,this.recordPool=new s({size:16}),this.tmpDict=new n,this.tmpArray1=[]}var n=t("./TupleDictionary"),s=(t("./OverlapKeeperRecord"),t("./OverlapKeeperRecordPool"));t("./Utils");e.exports=i,i.prototype.tick=function(){for(var t=this.overlappingShapesLastState,e=this.overlappingShapesCurrentState,o=t.keys.length;o--;){var i=t.keys[o],n=t.getByKey(i);e.getByKey(i);n&&this.recordPool.release(n)}t.reset(),t.copy(e),e.reset()},i.prototype.setOverlapping=function(t,e,o,i){this.overlappingShapesLastState;var n=this.overlappingShapesCurrentState;if(!n.get(e.id,i.id)){var s=this.recordPool.get();s.set(t,e,o,i),n.set(e.id,i.id,s)}},i.prototype.getNewOverlaps=function(t){return this.getDiff(this.overlappingShapesLastState,this.overlappingShapesCurrentState,t)},i.prototype.getEndOverlaps=function(t){return this.getDiff(this.overlappingShapesCurrentState,this.overlappingShapesLastState,t)},i.prototype.bodiesAreOverlapping=function(t,e){for(var o=this.overlappingShapesCurrentState,i=o.keys.length;i--;){var n=o.keys[i],s=o.data[n];if(s.bodyA===t&&s.bodyB===e||s.bodyA===e&&s.bodyB===t)return!0}return!1},i.prototype.getDiff=function(t,e,o){var i=t,n=e;(o=o||[]).length=0;for(var s=n.keys.length;s--;){var a=n.keys[s],r=n.data[a];if(!r)throw new Error("Key "+a+" had no data!");i.data[a]||o.push(r)}return o},i.prototype.isNewOverlap=function(t,e){var o=0|t.id,i=0|e.id,n=this.overlappingShapesLastState,s=this.overlappingShapesCurrentState;return!n.get(o,i)&&!!s.get(o,i)},i.prototype.getNewBodyOverlaps=function(t){this.tmpArray1.length=0;var e=this.getNewOverlaps(this.tmpArray1);return this.getBodyDiff(e,t)},i.prototype.getEndBodyOverlaps=function(t){this.tmpArray1.length=0;var e=this.getEndOverlaps(this.tmpArray1);return this.getBodyDiff(e,t)},i.prototype.getBodyDiff=function(t,e){e=e||[];for(var o=this.tmpDict,i=t.length;i--;){var n=t[i];o.set(0|n.bodyA.id,0|n.bodyB.id,n)}for(i=o.keys.length;i--;)(n=o.getByKey(o.keys[i]))&&e.push(n.bodyA,n.bodyB);return o.reset(),e}},{"./OverlapKeeperRecord":53,"./OverlapKeeperRecordPool":54,"./TupleDictionary":56,"./Utils":57}],53:[function(t,e,o){function i(t,e,o,i){this.shapeA=e,this.shapeB=i,this.bodyA=t,this.bodyB=o}e.exports=i,i.prototype.set=function(t,e,o,n){i.call(this,t,e,o,n)}},{}],54:[function(t,e,o){function i(){s.apply(this,arguments)}var n=t("./OverlapKeeperRecord"),s=t("./Pool");e.exports=i,(i.prototype=new s).constructor=i,i.prototype.create=function(){return new n},i.prototype.destroy=function(t){return t.bodyA=t.bodyB=t.shapeA=t.shapeB=null,this}},{"./OverlapKeeperRecord":53,"./Pool":55}],55:[function(t,e,o){function i(t){t=t||{},this.objects=[],void 0!==t.size&&this.resize(t.size)}e.exports=i,i.prototype.resize=function(t){for(var e=this.objects;e.length>t;)e.pop();for(;e.length<t;)e.push(this.create());return this},i.prototype.get=function(){var t=this.objects;return t.length?t.pop():this.create()},i.prototype.release=function(t){return this.destroy(t),this.objects.push(t),this}},{}],56:[function(t,e,o){function i(){this.data={},this.keys=[]}var n=t("./Utils");e.exports=i,i.prototype.getKey=function(t,e){return t|=0,e|=0,(0|t)==(0|e)?-1:0|((0|t)>(0|e)?t<<16|65535&e:e<<16|65535&t)},i.prototype.getByKey=function(t){return t|=0,this.data[t]},i.prototype.get=function(t,e){return this.data[this.getKey(t,e)]},i.prototype.set=function(t,e,o){if(!o)throw new Error("No data!");var i=this.getKey(t,e);return this.data[i]||this.keys.push(i),this.data[i]=o,i},i.prototype.reset=function(){for(var t=this.data,e=this.keys,o=e.length;o--;)delete t[e[o]];e.length=0},i.prototype.copy=function(t){this.reset(),n.appendArray(this.keys,t.keys);for(var e=t.keys.length;e--;){var o=t.keys[e];this.data[o]=t.data[o]}}},{"./Utils":57}],57:[function(t,e,o){function i(){}e.exports=i,i.appendArray=function(t,e){if(e.length<15e4)t.push.apply(t,e);else for(var o=0,i=e.length;o!==i;++o)t.push(e[o])},i.splice=function(t,e,o){o=o||1;for(var i=e,n=t.length-o;i<n;i++)t[i]=t[i+o];t.length=n},i.ARRAY_TYPE="undefined"!=typeof P2_ARRAY_TYPE?P2_ARRAY_TYPE:"undefined"!=typeof Float32Array?Float32Array:Array,i.extend=function(t,e){for(var o in e)t[o]=e[o]},i.defaults=function(t,e){t=t||{};for(var o in e)o in t||(t[o]=e[o]);return t}},{}],58:[function(t,e,o){function i(){this.equations=[],this.bodies=[]}var n=t("../objects/Body");e.exports=i,i.prototype.reset=function(){this.equations.length=this.bodies.length=0};var s=[];i.prototype.getBodies=function(t){var e=t||[],o=this.equations;s.length=0;for(var i=0;i!==o.length;i++){var n=o[i];-1===s.indexOf(n.bodyA.id)&&(e.push(n.bodyA),s.push(n.bodyA.id)),-1===s.indexOf(n.bodyB.id)&&(e.push(n.bodyB),s.push(n.bodyB.id))}return e},i.prototype.wantsToSleep=function(){for(var t=0;t<this.bodies.length;t++){var e=this.bodies[t];if(e.type===n.DYNAMIC&&!e.wantsToSleep)return!1}return!0},i.prototype.sleep=function(){for(var t=0;t<this.bodies.length;t++)this.bodies[t].sleep();return!0}},{"../objects/Body":31}],59:[function(t,e,o){function i(t){this.nodePool=new n({size:16}),this.islandPool=new s({size:8}),this.equations=[],this.islands=[],this.nodes=[],this.queue=[]}t("../math/vec2"),t("./Island"),t("./IslandNode");var n=t("./../utils/IslandNodePool"),s=t("./../utils/IslandPool"),a=t("../objects/Body");e.exports=i,i.getUnvisitedNode=function(t){for(var e=t.length,o=0;o!==e;o++){var i=t[o];if(!i.visited&&i.body.type===a.DYNAMIC)return i}return!1},i.prototype.visit=function(t,e,o){e.push(t.body);for(var i=t.equations.length,n=0;n!==i;n++){var s=t.equations[n];-1===o.indexOf(s)&&o.push(s)}},i.prototype.bfs=function(t,e,o){var n=this.queue;for(n.length=0,n.push(t),t.visited=!0,this.visit(t,e,o);n.length;)for(var s,r=n.pop();s=i.getUnvisitedNode(r.neighbors);)s.visited=!0,this.visit(s,e,o),s.body.type===a.DYNAMIC&&n.push(s)},i.prototype.split=function(t){for(var e=t.bodies,o=this.nodes,n=this.equations;o.length;)this.nodePool.release(o.pop());for(c=0;c!==e.length;c++){var s=this.nodePool.get();s.body=e[c],o.push(s)}for(var a=0;a!==n.length;a++){var r=n[a],c=e.indexOf(r.bodyA),h=e.indexOf(r.bodyB),l=o[c],p=o[h];l.neighbors.push(p),p.neighbors.push(l),l.equations.push(r),p.equations.push(r)}for(var u=this.islands,c=0;c<u.length;c++)this.islandPool.release(u[c]);u.length=0;for(var d;d=i.getUnvisitedNode(o);){var f=this.islandPool.get();this.bfs(d,f.bodies,f.equations),u.push(f)}return u}},{"../math/vec2":30,"../objects/Body":31,"./../utils/IslandNodePool":50,"./../utils/IslandPool":51,"./Island":58,"./IslandNode":60}],60:[function(t,e,o){function i(t){this.body=t,this.neighbors=[],this.equations=[],this.visited=!1}e.exports=i,i.prototype.reset=function(){this.equations.length=0,this.neighbors.length=0,this.visited=!1,this.body=null}},{}],61:[function(t,e,o){function i(t){p.apply(this),t=t||{},this.springs=[],this.bodies=[],this.disabledBodyCollisionPairs=[],this.solver=t.solver||new n,this.narrowphase=new m(this),this.islandManager=new b,this.gravity=s.fromValues(0,-9.78),t.gravity&&s.copy(this.gravity,t.gravity),this.frictionGravity=s.length(this.gravity)||10,this.useWorldGravityAsFrictionGravity=!0,this.useFrictionGravityOnZeroGravity=!0,this.broadphase=t.broadphase||new y,this.broadphase.setWorld(this),this.constraints=[],this.defaultMaterial=new d,this.defaultContactMaterial=new f(this.defaultMaterial,this.defaultMaterial),this.lastTimeStep=1/60,this.applySpringForces=!0,this.applyDamping=!0,this.applyGravity=!0,this.solveConstraints=!0,this.contactMaterials=[],this.time=0,this.accumulator=0,this.stepping=!1,this.bodiesToBeRemoved=[],this.islandSplit=void 0===t.islandSplit||!!t.islandSplit,this.emitImpactEvent=!0,this._constraintIdCounter=0,this._bodyIdCounter=0,this.postStepEvent={type:"postStep"},this.addBodyEvent={type:"addBody",body:null},this.removeBodyEvent={type:"removeBody",body:null},this.addSpringEvent={type:"addSpring",spring:null},this.impactEvent={type:"impact",bodyA:null,bodyB:null,shapeA:null,shapeB:null,contactEquation:null},this.postBroadphaseEvent={type:"postBroadphase",pairs:null},this.sleepMode=i.NO_SLEEPING,this.beginContactEvent={type:"beginContact",shapeA:null,shapeB:null,bodyA:null,bodyB:null,contactEquations:[]},this.endContactEvent={type:"endContact",shapeA:null,shapeB:null,bodyA:null,bodyB:null},this.preSolveEvent={type:"preSolve",contactEquations:null,frictionEquations:null},this.overlappingShapesLastState={keys:[]},this.overlappingShapesCurrentState={keys:[]},this.overlapKeeper=new A}var n=t("../solver/GSSolver"),s=(t("../solver/Solver"),t("../collision/Ray"),t("../math/vec2")),a=t("../shapes/Circle"),r=t("../shapes/Convex"),c=(t("../shapes/Line"),t("../shapes/Plane")),h=t("../shapes/Capsule"),l=t("../shapes/Particle"),p=t("../events/EventEmitter"),u=t("../objects/Body"),d=(t("../shapes/Shape"),t("../objects/LinearSpring"),t("../material/Material")),f=t("../material/ContactMaterial"),v=(t("../constraints/DistanceConstraint"),t("../constraints/Constraint"),t("../constraints/LockConstraint"),t("../constraints/RevoluteConstraint"),t("../constraints/PrismaticConstraint"),t("../constraints/GearConstraint"),t("../../package.json"),t("../collision/Broadphase"),t("../collision/AABB")),y=t("../collision/SAPBroadphase"),m=t("../collision/Narrowphase"),g=t("../utils/Utils"),A=t("../utils/OverlapKeeper"),b=t("./IslandManager");t("../objects/RotationalSpring");e.exports=i,i.prototype=new Object(p.prototype),i.prototype.constructor=i,i.NO_SLEEPING=1,i.BODY_SLEEPING=2,i.ISLAND_SLEEPING=4,i.prototype.addConstraint=function(t){this.constraints.push(t)},i.prototype.addContactMaterial=function(t){this.contactMaterials.push(t)},i.prototype.removeContactMaterial=function(t){var e=this.contactMaterials.indexOf(t);-1!==e&&g.splice(this.contactMaterials,e,1)},i.prototype.getContactMaterial=function(t,e){for(var o=this.contactMaterials,i=0,n=o.length;i!==n;i++){var s=o[i];if(s.materialA.id===t.id&&s.materialB.id===e.id||s.materialA.id===e.id&&s.materialB.id===t.id)return s}return!1},i.prototype.removeConstraint=function(t){var e=this.constraints.indexOf(t);-1!==e&&g.splice(this.constraints,e,1)};s.create(),s.create(),s.create(),s.create(),s.create(),s.create();var E=s.create(),B=s.fromValues(0,0),q=s.fromValues(0,0);s.fromValues(0,0),s.fromValues(0,0);i.prototype.step=function(t,e,o){if(o=o||10,0===(e=e||0))this.internalStep(t),this.time+=t;else{this.accumulator+=e;for(var i=0;this.accumulator>=t&&i<o;)this.internalStep(t),this.time+=t,this.accumulator-=t,i++;for(var n=this.accumulator%t/t,a=0;a!==this.bodies.length;a++){var r=this.bodies[a];s.lerp(r.interpolatedPosition,r.previousPosition,r.position,n),r.interpolatedAngle=r.previousAngle+n*(r.angle-r.previousAngle)}}};var P=[];i.prototype.internalStep=function(t){this.stepping=!0;var e=this.springs.length,o=this.springs,n=this.bodies,a=this.gravity,r=this.solver,c=this.bodies.length,h=this.broadphase,l=this.narrowphase,p=this.constraints,d=E,f=(s.scale,s.add),v=(s.rotate,this.islandManager);if(this.overlapKeeper.tick(),this.lastTimeStep=t,this.useWorldGravityAsFrictionGravity){var y=s.length(this.gravity);0===y&&this.useFrictionGravityOnZeroGravity||(this.frictionGravity=y)}if(this.applyGravity)for(q=0;q!==c;q++){var m=(A=n[q]).force;A.type===u.DYNAMIC&&A.sleepState!==u.SLEEPING&&(s.scale(d,a,A.mass*A.gravityScale),f(m,m,d))}if(this.applySpringForces)for(q=0;q!==e;q++)o[q].applyForce();if(this.applyDamping)for(q=0;q!==c;q++){var A=n[q];A.type===u.DYNAMIC&&A.applyDamping(t)}for(var b=h.getCollisionPairs(this),B=this.disabledBodyCollisionPairs,q=B.length-2;q>=0;q-=2)for(S=b.length-2;S>=0;S-=2)(B[q]===b[S]&&B[q+1]===b[S+1]||B[q+1]===b[S]&&B[q]===b[S+1])&&b.splice(S,2);X=p.length;for(q=0;q!==X;q++){var w=p[q];if(!w.collideConnected)for(var S=b.length-2;S>=0;S-=2)(w.bodyA===b[S]&&w.bodyB===b[S+1]||w.bodyB===b[S]&&w.bodyA===b[S+1])&&b.splice(S,2)}this.postBroadphaseEvent.pairs=b,this.emit(this.postBroadphaseEvent),this.postBroadphaseEvent.pairs=null,l.reset(this);for(var q=0,C=b.length;q!==C;q+=2)for(var L=b[q],x=b[q+1],F=0,M=L.shapes.length;F!==M;F++)for(var I=L.shapes[F],R=I.position,V=I.angle,T=0,N=x.shapes.length;T!==N;T++){var G=x.shapes[T],O=G.position,U=G.angle,k=this.defaultContactMaterial;if(I.material&&G.material){var _=this.getContactMaterial(I.material,G.material);_&&(k=_)}this.runNarrowphase(l,L,I,R,V,x,G,O,U,k,this.frictionGravity)}for(q=0;q!==c;q++)(z=n[q])._wakeUpAfterNarrowphase&&(z.wakeUp(),z._wakeUpAfterNarrowphase=!1);if(this.has("endContact")){this.overlapKeeper.getEndOverlaps(P);for(var D=this.endContactEvent,T=P.length;T--;){var W=P[T];D.shapeA=W.shapeA,D.shapeB=W.shapeB,D.bodyA=W.bodyA,D.bodyB=W.bodyB,this.emit(D)}P.length=0}var j=this.preSolveEvent;j.contactEquations=l.contactEquations,j.frictionEquations=l.frictionEquations,this.emit(j),j.contactEquations=j.frictionEquations=null;var X=p.length;for(q=0;q!==X;q++)p[q].update();if(l.contactEquations.length||l.frictionEquations.length||X)if(this.islandSplit){for(v.equations.length=0,g.appendArray(v.equations,l.contactEquations),g.appendArray(v.equations,l.frictionEquations),q=0;q!==X;q++)g.appendArray(v.equations,p[q].equations);v.split(this);for(q=0;q!==v.islands.length;q++)(H=v.islands[q]).equations.length&&r.solveIsland(t,H)}else{for(r.addEquations(l.contactEquations),r.addEquations(l.frictionEquations),q=0;q!==X;q++)r.addEquations(p[q].equations);this.solveConstraints&&r.solve(t,this),r.removeAllEquations()}for(q=0;q!==c;q++){var z=n[q];z.integrate(t)}for(q=0;q!==c;q++)n[q].setZeroForce();if(this.emitImpactEvent&&this.has("impact"))for(var Y=this.impactEvent,q=0;q!==l.contactEquations.length;q++){var K=l.contactEquations[q];K.firstImpact&&(Y.bodyA=K.bodyA,Y.bodyB=K.bodyB,Y.shapeA=K.shapeA,Y.shapeB=K.shapeB,Y.contactEquation=K,this.emit(Y))}if(this.sleepMode===i.BODY_SLEEPING)for(q=0;q!==c;q++)n[q].sleepTick(this.time,!1,t);else if(this.sleepMode===i.ISLAND_SLEEPING&&this.islandSplit){for(q=0;q!==c;q++)n[q].sleepTick(this.time,!0,t);for(q=0;q<this.islandManager.islands.length;q++){var H=this.islandManager.islands[q];H.wantsToSleep()&&H.sleep()}}this.stepping=!1;for(var Z=this.bodiesToBeRemoved,q=0;q!==Z.length;q++)this.removeBody(Z[q]);Z.length=0,this.emit(this.postStepEvent)},i.prototype.runNarrowphase=function(t,e,o,i,n,a,r,c,h,l,p){if(0!=(o.collisionGroup&r.collisionMask)&&0!=(r.collisionGroup&o.collisionMask)){s.rotate(B,i,e.angle),s.rotate(q,c,a.angle),s.add(B,B,e.position),s.add(q,q,a.position);var d=n+e.angle,f=h+a.angle;t.enableFriction=l.friction>0,t.frictionCoefficient=l.friction;var v;v=e.type===u.STATIC||e.type===u.KINEMATIC?a.mass:a.type===u.STATIC||a.type===u.KINEMATIC?e.mass:e.mass*a.mass/(e.mass+a.mass),t.slipForce=l.friction*p*v,t.restitution=l.restitution,t.surfaceVelocity=l.surfaceVelocity,t.frictionStiffness=l.frictionStiffness,t.frictionRelaxation=l.frictionRelaxation,t.stiffness=l.stiffness,t.relaxation=l.relaxation,t.contactSkinSize=l.contactSkinSize,t.enabledEquations=e.collisionResponse&&a.collisionResponse&&o.collisionResponse&&r.collisionResponse;var y=t[o.type|r.type],m=0;if(y){var g=o.sensor||r.sensor,A=t.frictionEquations.length;m=o.type<r.type?y.call(t,e,o,B,d,a,r,q,f,g):y.call(t,a,r,q,f,e,o,B,d,g);var b=t.frictionEquations.length-A;if(m){if(e.allowSleep&&e.type===u.DYNAMIC&&e.sleepState===u.SLEEPING&&a.sleepState===u.AWAKE&&a.type!==u.STATIC&&s.squaredLength(a.velocity)+Math.pow(a.angularVelocity,2)>=2*Math.pow(a.sleepSpeedLimit,2)&&(e._wakeUpAfterNarrowphase=!0),a.allowSleep&&a.type===u.DYNAMIC&&a.sleepState===u.SLEEPING&&e.sleepState===u.AWAKE&&e.type!==u.STATIC&&s.squaredLength(e.velocity)+Math.pow(e.angularVelocity,2)>=2*Math.pow(e.sleepSpeedLimit,2)&&(a._wakeUpAfterNarrowphase=!0),this.overlapKeeper.setOverlapping(e,o,a,r),this.has("beginContact")&&this.overlapKeeper.isNewOverlap(o,r)){var E=this.beginContactEvent;if(E.shapeA=o,E.shapeB=r,E.bodyA=e,E.bodyB=a,E.contactEquations.length=0,"number"==typeof m)for(P=t.contactEquations.length-m;P<t.contactEquations.length;P++)E.contactEquations.push(t.contactEquations[P]);this.emit(E)}if("number"==typeof m&&b>1)for(var P=t.frictionEquations.length-b;P<t.frictionEquations.length;P++){var w=t.frictionEquations[P];w.setSlipForce(w.getSlipForce()/b)}}}}},i.prototype.addSpring=function(t){this.springs.push(t);var e=this.addSpringEvent;e.spring=t,this.emit(e),e.spring=null},i.prototype.removeSpring=function(t){var e=this.springs.indexOf(t);-1!==e&&g.splice(this.springs,e,1)},i.prototype.addBody=function(t){if(-1===this.bodies.indexOf(t)){this.bodies.push(t),t.world=this;var e=this.addBodyEvent;e.body=t,this.emit(e),e.body=null}},i.prototype.removeBody=function(t){if(this.stepping)this.bodiesToBeRemoved.push(t);else{t.world=null;var e=this.bodies.indexOf(t);-1!==e&&(g.splice(this.bodies,e,1),this.removeBodyEvent.body=t,t.resetConstraintVelocity(),this.emit(this.removeBodyEvent),this.removeBodyEvent.body=null)}},i.prototype.getBodyById=function(t){for(var e=this.bodies,o=0;o<e.length;o++){var i=e[o];if(i.id===t)return i}return!1},i.prototype.disableBodyCollision=function(t,e){this.disabledBodyCollisionPairs.push(t,e)},i.prototype.enableBodyCollision=function(t,e){for(var o=this.disabledBodyCollisionPairs,i=0;i<o.length;i+=2)if(o[i]===t&&o[i+1]===e||o[i+1]===t&&o[i]===e)return void o.splice(i,2)},i.prototype.clear=function(){this.time=0,this.solver&&this.solver.equations.length&&this.solver.removeAllEquations();for(var t=this.constraints,e=t.length-1;e>=0;e--)this.removeConstraint(t[e]);for(var o=this.bodies,e=o.length-1;e>=0;e--)this.removeBody(o[e]);for(var n=this.springs,e=n.length-1;e>=0;e--)this.removeSpring(n[e]);for(var s=this.contactMaterials,e=s.length-1;e>=0;e--)this.removeContactMaterial(s[e]);i.apply(this)};var w=s.create(),S=(s.fromValues(0,0),s.fromValues(0,0));i.prototype.hitTest=function(t,e,o){o=o||0;var i=new u({position:t}),n=new l,p=t,d=w,f=S;i.addShape(n);for(var v=this.narrowphase,y=[],m=0,g=e.length;m!==g;m++)for(var A=e[m],b=0,E=A.shapes.length;b!==E;b++){var B=A.shapes[b];s.rotate(d,B.position,A.angle),s.add(d,d,A.position);var q=B.angle+A.angle;(B instanceof a&&v.circleParticle(A,B,d,q,i,n,p,0,!0)||B instanceof r&&v.particleConvex(i,n,p,0,A,B,d,q,!0)||B instanceof c&&v.particlePlane(i,n,p,0,A,B,d,q,!0)||B instanceof h&&v.particleCapsule(i,n,p,0,A,B,d,q,!0)||B instanceof l&&s.squaredLength(s.sub(f,d,t))<o*o)&&y.push(A)}return y},i.prototype.setGlobalStiffness=function(t){for(var e=this.constraints,o=0;o!==e.length;o++)for(var i=e[o],n=0;n!==i.equations.length;n++){var s=i.equations[n];s.stiffness=t,s.needsUpdate=!0}for(var a=this.contactMaterials,o=0;o!==a.length;o++)(i=a[o]).stiffness=i.frictionStiffness=t;(i=this.defaultContactMaterial).stiffness=i.frictionStiffness=t},i.prototype.setGlobalRelaxation=function(t){for(n=0;n!==this.constraints.length;n++)for(var e=this.constraints[n],o=0;o!==e.equations.length;o++){var i=e.equations[o];i.relaxation=t,i.needsUpdate=!0}for(var n=0;n!==this.contactMaterials.length;n++)(e=this.contactMaterials[n]).relaxation=e.frictionRelaxation=t;(e=this.defaultContactMaterial).relaxation=e.frictionRelaxation=t};var C=new v,L=[];i.prototype.raycast=function(t,e){return e.getAABB(C),this.broadphase.aabbQuery(this,C,L),e.intersectBodies(t,L),L.length=0,t.hasHit()}},{"../../package.json":6,"../collision/AABB":7,"../collision/Broadphase":8,"../collision/Narrowphase":10,"../collision/Ray":11,"../collision/SAPBroadphase":13,"../constraints/Constraint":14,"../constraints/DistanceConstraint":15,"../constraints/GearConstraint":16,"../constraints/LockConstraint":17,"../constraints/PrismaticConstraint":18,"../constraints/RevoluteConstraint":19,"../events/EventEmitter":26,"../material/ContactMaterial":27,"../material/Material":28,"../math/vec2":30,"../objects/Body":31,"../objects/LinearSpring":32,"../objects/RotationalSpring":33,"../shapes/Capsule":38,"../shapes/Circle":39,"../shapes/Convex":40,"../shapes/Line":42,"../shapes/Particle":43,"../shapes/Plane":44,"../shapes/Shape":45,"../solver/GSSolver":46,"../solver/Solver":47,"../utils/OverlapKeeper":52,"../utils/Utils":57,"./IslandManager":59}]},{},[36])(36)});
  //# sourceMappingURL=p2.map