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