From cd00353c3145a72ed927d2b9f0a47ad71e2320f8 Mon Sep 17 00:00:00 2001 From: liabru Date: Wed, 23 Dec 2015 13:08:54 +0000 Subject: [PATCH] updated edge build --- build/matter.js | 147 +++++++++++++++++++++----------------------- build/matter.min.js | 120 ++++++++++++++++++------------------ 2 files changed, 131 insertions(+), 136 deletions(-) diff --git a/build/matter.js b/build/matter.js index 1f94929..3490db5 100644 --- a/build/matter.js +++ b/build/matter.js @@ -1,5 +1,5 @@ /** -* matter-js master by @liabru 2015-12-05 +* matter-js master by @liabru 2015-12-23 * http://brm.io/matter-js/ * License MIT */ @@ -106,7 +106,9 @@ var Axes = require('../geometry/Axes'); visible: true, sprite: { xScale: 1, - yScale: 1 + yScale: 1, + xOffset: 0, + yOffset: 0 }, lineWidth: 1.5 } @@ -182,6 +184,8 @@ var Axes = require('../geometry/Axes'); defaultStrokeStyle = Common.shadeColor(defaultFillStyle, -20); body.render.fillStyle = body.render.fillStyle || defaultFillStyle; body.render.strokeStyle = body.render.strokeStyle || defaultStrokeStyle; + body.render.sprite.xOffset += -(body.bounds.min.x - body.position.x) / (body.bounds.max.x - body.bounds.min.x); + body.render.sprite.yOffset += -(body.bounds.min.y - body.position.y) / (body.bounds.max.y - body.bounds.min.y); }; /** @@ -1056,6 +1060,22 @@ var Axes = require('../geometry/Axes'); * @default 1 */ + /** + * A `Number` that defines the offset in the x-axis for the sprite (normalised by texture width). + * + * @property render.sprite.xOffset + * @type number + * @default 0 + */ + + /** + * A `Number` that defines the offset in the y-axis for the sprite (normalised by texture height). + * + * @property render.sprite.yOffset + * @type number + * @default 0 + */ + /** * A `Number` that defines the line width to use when rendering the body outline (if a sprite is not defined). * A value of `0` means no outline will be rendered. @@ -1972,60 +1992,6 @@ var Bounds = require('../geometry/Bounds'); return collisions; }; - /** - * Description - * @method bruteForce - * @param {body[]} bodies - * @param {engine} engine - * @return {array} collisions - */ - Detector.bruteForce = function(bodies, engine) { - var collisions = [], - pairsTable = engine.pairs.table; - - - for (var i = 0; i < bodies.length; i++) { - for (var j = i + 1; j < bodies.length; j++) { - var bodyA = bodies[i], - bodyB = bodies[j]; - - // NOTE: could share a function for the below, but may drop performance? - - if ((bodyA.isStatic || bodyA.isSleeping) && (bodyB.isStatic || bodyB.isSleeping)) - continue; - - if (!Detector.canCollide(bodyA.collisionFilter, bodyB.collisionFilter)) - continue; - - - // mid phase - if (Bounds.overlaps(bodyA.bounds, bodyB.bounds)) { - - // find a previous collision we could reuse - var pairId = Pair.id(bodyA, bodyB), - pair = pairsTable[pairId], - previousCollision; - - if (pair && pair.isActive) { - previousCollision = pair.collision; - } else { - previousCollision = null; - } - - // narrow phase - var collision = SAT.collides(bodyA, bodyB, previousCollision); - - - if (collision.collided) { - collisions.push(collision); - } - } - } - } - - return collisions; - }; - /** * Returns `true` if both supplied collision filters will allow a collision to occur. * See `body.collisionFilter` for more information. @@ -2758,6 +2724,7 @@ var Bounds = require('../geometry/Bounds'); (function() { Resolver._restingThresh = 4; + Resolver._restingThreshTangent = 6; Resolver._positionDampen = 0.9; Resolver._positionWarming = 0.8; Resolver._frictionNormalMultiplier = 5; @@ -3023,37 +2990,45 @@ var Bounds = require('../geometry/Bounds'); maxFriction = Infinity; if (tangentSpeed > pair.friction * pair.frictionStatic * normalForce * timeScaleSquared) { - tangentImpulse = pair.friction * tangentVelocityDirection * timeScaleSquared; maxFriction = tangentSpeed; + tangentImpulse = Common.clamp( + pair.friction * tangentVelocityDirection * timeScaleSquared, + -maxFriction, maxFriction + ); } // modify impulses accounting for mass, inertia and offset var oAcN = Vector.cross(offsetA, normal), oBcN = Vector.cross(offsetB, normal), - denom = bodyA.inverseMass + bodyB.inverseMass + bodyA.inverseInertia * oAcN * oAcN + bodyB.inverseInertia * oBcN * oBcN; + share = contactShare / (bodyA.inverseMass + bodyB.inverseMass + bodyA.inverseInertia * oAcN * oAcN + bodyB.inverseInertia * oBcN * oBcN); - normalImpulse *= contactShare / denom; - tangentImpulse *= contactShare / (1 + denom); + normalImpulse *= share; + tangentImpulse *= share; // handle high velocity and resting collisions separately if (normalVelocity < 0 && normalVelocity * normalVelocity > Resolver._restingThresh * timeScaleSquared) { - // high velocity so clear cached contact impulse + // high normal velocity so clear cached contact normal impulse contact.normalImpulse = 0; - contact.tangentImpulse = 0; } else { // solve resting collision constraints using Erin Catto's method (GDC08) - - // impulse constraint, tends to 0 + // impulse constraint tends to 0 var contactNormalImpulse = contact.normalImpulse; contact.normalImpulse = Math.min(contact.normalImpulse + normalImpulse, 0); normalImpulse = contact.normalImpulse - contactNormalImpulse; - - // tangent impulse, tends to -maxFriction or maxFriction + } + + // handle high velocity and resting collisions separately + if (tangentVelocity * tangentVelocity > Resolver._restingThreshTangent * timeScaleSquared) { + // high tangent velocity so clear cached contact tangent impulse + contact.tangentImpulse = 0; + } else { + // solve resting collision constraints using Erin Catto's method (GDC08) + // tangent impulse tends to -tangentSpeed or +tangentSpeed var contactTangentImpulse = contact.tangentImpulse; contact.tangentImpulse = Common.clamp(contact.tangentImpulse + tangentImpulse, -maxFriction, maxFriction); tangentImpulse = contact.tangentImpulse - contactTangentImpulse; } - + // total impulse from contact impulse.x = (normal.x * normalImpulse) + (tangent.x * tangentImpulse); impulse.y = (normal.y * normalImpulse) + (tangent.y * tangentImpulse); @@ -5635,12 +5610,19 @@ var Vector = require('../geometry/Vector'); var x1 = width * slope, x2 = x1 + roof, - x3 = x2 + x1; + x3 = x2 + x1, + verticesPath; + + if (slope < 0.5) { + verticesPath = 'L 0 0 L ' + x1 + ' ' + (-height) + ' L ' + x2 + ' ' + (-height) + ' L ' + x3 + ' 0'; + } else { + verticesPath = 'L 0 0 L ' + x2 + ' ' + (-height) + ' L ' + x3 + ' 0'; + } var trapezoid = { label: 'Trapezoid Body', position: { x: x, y: y }, - vertices: Vertices.fromPath('L 0 0 L ' + x1 + ' ' + (-height) + ' L ' + x2 + ' ' + (-height) + ' L ' + x3 + ' 0') + vertices: Vertices.fromPath(verticesPath) }; if (options.chamfer) { @@ -6098,7 +6080,7 @@ var Bodies = require('./Bodies'); for (var i = 0; i < number; i++) { var separation = 1.9, circle = Bodies.circle(xx + i * (size * separation), yy + length, size, - { inertia: 99999, restitution: 1, friction: 0, frictionAir: 0.0001, slop: 0.01 }), + { inertia: Infinity, restitution: 1, friction: 0, frictionAir: 0.0001, slop: 1 }), constraint = Constraint.create({ pointA: { x: xx + i * (size * separation), y: yy }, bodyB: circle }); Composite.addBody(newtonsCradle, circle); @@ -7419,6 +7401,11 @@ var Vector = require('../geometry/Vector'); var render = Common.extend(defaults, options); + if (render.canvas) { + render.canvas.width = render.options.width || render.canvas.width; + render.canvas.height = render.options.height || render.canvas.height; + } + render.canvas = render.canvas || _createCanvas(render.options.width, render.options.height); render.context = render.canvas.getContext('2d'); render.textures = {}; @@ -7429,8 +7416,8 @@ var Vector = require('../geometry/Vector'); y: 0 }, max: { - x: render.options.width, - y: render.options.height + x: render.canvas.width, + y: render.canvas.height } }; @@ -7760,6 +7747,9 @@ var Vector = require('../geometry/Vector'); for (k = body.parts.length > 1 ? 1 : 0; k < body.parts.length; k++) { part = body.parts[k]; + if (!part.render.visible) + continue; + if (part.render.sprite && part.render.sprite.texture && !options.wireframes) { // part sprite var sprite = part.render.sprite, @@ -7771,8 +7761,13 @@ var Vector = require('../geometry/Vector'); c.translate(part.position.x, part.position.y); c.rotate(part.angle); - c.drawImage(texture, texture.width * -0.5 * sprite.xScale, texture.height * -0.5 * sprite.yScale, - texture.width * sprite.xScale, texture.height * sprite.yScale); + c.drawImage( + texture, + texture.width * -sprite.xOffset * sprite.xScale, + texture.height * -sprite.yOffset * sprite.yScale, + texture.width * sprite.xScale, + texture.height * sprite.yScale + ); // revert translation, hopefully faster than save / restore c.rotate(-part.angle); @@ -8967,8 +8962,8 @@ var Common = require('../core/Common'); texture = _getTexture(render, texturePath), sprite = new PIXI.Sprite(texture); - sprite.anchor.x = 0.5; - sprite.anchor.y = 0.5; + sprite.anchor.x = body.render.sprite.xOffset; + sprite.anchor.y = body.render.sprite.yOffset; return sprite; }; diff --git a/build/matter.min.js b/build/matter.min.js index 82b6078..21424e3 100644 --- a/build/matter.min.js +++ b/build/matter.min.js @@ -1,43 +1,43 @@ /** -* matter-js master by @liabru 2015-12-05 +* matter-js master by @liabru 2015-12-23 * http://brm.io/matter-js/ * License MIT */ !function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;t="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,t.Matter=e()}}(function(){return function e(t,o,n){function i(s,a){if(!o[s]){if(!t[s]){var l="function"==typeof require&&require;if(!a&&l)return l(s,!0);if(r)return r(s,!0);var c=new Error("Cannot find module '"+s+"'");throw c.code="MODULE_NOT_FOUND",c}var d=o[s]={exports:{}};t[s][0].call(d.exports,function(e){var o=t[s][1][e];return i(o?o:e)},d,d.exports,e,t,o,n)}return o[s].exports}for(var r="function"==typeof require&&require,s=0;s0&&r.rotateAbout(s.position,o,e.position,s.position)}},n.setVelocity=function(e,t){e.positionPrev.x=e.position.x-t.x,e.positionPrev.y=e.position.y-t.y,e.velocity.x=t.x,e.velocity.y=t.y,e.speed=r.magnitude(e.velocity)},n.setAngularVelocity=function(e,t){ -e.anglePrev=e.angle-t,e.angularVelocity=t,e.angularSpeed=Math.abs(e.angularVelocity)},n.translate=function(e,t){n.setPosition(e,r.add(e.position,t))},n.rotate=function(e,t){n.setAngle(e,e.angle+t)},n.scale=function(e,t,o,r){for(var s=0;s0&&(v.position.x+=e.velocity.x,v.position.y+=e.velocity.y),0!==e.angularVelocity&&(i.rotate(v.vertices,e.angularVelocity,e.position),c.rotate(v.axes,e.angularVelocity),p>0&&r.rotateAbout(v.position,e.angularVelocity,e.position,v.position)),l.update(v.bounds,v.vertices,e.velocity)}},n.applyForce=function(e,t,o){e.force.x+=o.x,e.force.y+=o.y;var n={x:t.x-e.position.x,y:t.y-e.position.y};e.torque+=(n.x*o.y-n.y*o.x)*e.inverseInertia};var u=function(e){for(var t={mass:0,area:0,inertia:0,centre:{x:0,y:0}},o=1===e.parts.length?0:1;o1?1:0;u1?1:0;v0:0!==(e.mask&t.category)&&0!==(t.mask&e.category); -}}()},{"../geometry/Bounds":24,"./Pair":7,"./SAT":11}],6:[function(e,t,o){var n={};t.exports=n;var i=e("./Pair"),r=e("./Detector"),s=e("../core/Common");!function(){n.create=function(e){var t={controller:n,detector:r.collisions,buckets:{},pairs:{},pairsList:[],bucketWidth:48,bucketHeight:48};return s.extend(t,e)},n.update=function(o,n,i,r){var s,p,v,f,y,m=i.world,g=o.buckets,x=!1;for(s=0;sm.bounds.width||h.bounds.max.y<0||h.bounds.min.y>m.bounds.height)){var b=t(o,h);if(!h.region||b.id!==h.region.id||r){(!h.region||r)&&(h.region=b);var S=e(b,h.region);for(p=S.startCol;p<=S.endCol;p++)for(v=S.startRow;v<=S.endRow;v++){y=a(p,v),f=g[y];var w=p>=b.startCol&&p<=b.endCol&&v>=b.startRow&&v<=b.endRow,C=p>=h.region.startCol&&p<=h.region.endCol&&v>=h.region.startRow&&v<=h.region.endRow;!w&&C&&C&&f&&d(o,f,h),(h.region===b||w&&!C||r)&&(f||(f=l(g,y)),c(o,f,h))}h.region=b,x=!0}}}x&&(o.pairsList=u(o))},n.clear=function(e){ -e.buckets={},e.pairs={},e.pairsList=[]};var e=function(e,t){var n=Math.min(e.startCol,t.startCol),i=Math.max(e.endCol,t.endCol),r=Math.min(e.startRow,t.startRow),s=Math.max(e.endRow,t.endRow);return o(n,i,r,s)},t=function(e,t){var n=t.bounds,i=Math.floor(n.min.x/e.bucketWidth),r=Math.floor(n.max.x/e.bucketWidth),s=Math.floor(n.min.y/e.bucketHeight),a=Math.floor(n.max.y/e.bucketHeight);return o(i,r,s,a)},o=function(e,t,o,n){return{id:e+","+t+","+o+","+n,startCol:e,endCol:t,startRow:o,endRow:n}},a=function(e,t){return e+","+t},l=function(e,t){var o=e[t]=[];return o},c=function(e,t,o){for(var n=0;n0?n.push(o):delete e.pairs[t[i]];return n}}(); -},{"../core/Common":14,"./Detector":5,"./Pair":7}],7:[function(e,t,o){var n={};t.exports=n;var i=e("./Contact");!function(){n.create=function(e,t){var o=e.bodyA,i=e.bodyB,r=e.parentA,s=e.parentB,a={id:n.id(o,i),bodyA:o,bodyB:i,contacts:{},activeContacts:[],separation:0,isActive:!0,timeCreated:t,timeUpdated:t,inverseMass:r.inverseMass+s.inverseMass,friction:Math.min(r.friction,s.friction),frictionStatic:Math.max(r.frictionStatic,s.frictionStatic),restitution:Math.max(r.restitution,s.restitution),slop:Math.max(r.slop,s.slop)};return n.update(a,e,t),a},n.update=function(e,t,o){var r=e.contacts,s=t.supports,a=e.activeContacts,l=t.parentA,c=t.parentB;if(e.collision=t,e.inverseMass=l.inverseMass+c.inverseMass,e.friction=Math.min(l.friction,c.friction),e.frictionStatic=Math.max(l.frictionStatic,c.frictionStatic),e.restitution=Math.max(l.restitution,c.restitution),e.slop=Math.max(l.slop,c.slop),a.length=0,t.collided){for(var d=0;de&&c.push(s);for(s=0;sv.friction*v.frictionStatic*_*o&&(L=v.friction*R*o,W=T);var F=r.cross(A,g),O=r.cross(B,g),N=y.inverseMass+m.inverseMass+y.inverseInertia*F*F+m.inverseInertia*O*O;if(E*=b/N,L*=b/(1+N),0>I&&I*I>n._restingThresh*o)w.normalImpulse=0,w.tangentImpulse=0;else{var D=w.normalImpulse;w.normalImpulse=Math.min(w.normalImpulse+E,0),E=w.normalImpulse-D;var q=w.tangentImpulse;w.tangentImpulse=s.clamp(w.tangentImpulse+L,-W,W), -L=w.tangentImpulse-q}i.x=g.x*E+x.x*L,i.y=g.y*E+x.y*L,y.isStatic||y.isSleeping||(y.positionPrev.x+=i.x*y.inverseMass,y.positionPrev.y+=i.y*y.inverseMass,y.anglePrev+=r.cross(A,i)*y.inverseInertia),m.isStatic||m.isSleeping||(m.positionPrev.x-=i.x*m.inverseMass,m.positionPrev.y-=i.y*m.inverseMass,m.anglePrev-=r.cross(B,i)*m.inverseInertia)}}}}}()},{"../core/Common":14,"../geometry/Bounds":24,"../geometry/Vector":26,"../geometry/Vertices":27}],11:[function(e,t,o){var n={};t.exports=n;var i=e("../geometry/Vertices"),r=e("../geometry/Vector");!function(){n.collides=function(t,n,s){var a,l,c,d,u=s,p=!1;if(u){var v=t.parent,f=n.parent,y=v.speed*v.speed+v.angularSpeed*v.angularSpeed+f.speed*f.speed+f.angularSpeed*f.angularSpeed;p=u&&u.collided&&.2>y,d=u}else d={collided:!1,bodyA:t,bodyB:n};if(u&&p){var m=d.axisBody,g=m===t?n:t,x=[m.axes[u.axisNumber]];if(c=e(m.vertices,g.vertices,x),d.reused=!0,c.overlap<=0)return d.collided=!1,d}else{if(a=e(t.vertices,n.vertices,t.axes),a.overlap<=0)return d.collided=!1, -d;if(l=e(n.vertices,t.vertices,n.axes),l.overlap<=0)return d.collided=!1,d;a.overlap0&&(d.normal=r.neg(d.normal)),d.tangent=r.perp(d.normal),d.penetration={x:d.normal.x*d.depth,y:d.normal.y*d.depth};var h=o(t,n,d.normal),b=d.supports||[];if(b.length=0,i.contains(t.vertices,h[0])&&b.push(h[0]),i.contains(t.vertices,h[1])&&b.push(h[1]),b.length<2){var S=o(n,t,r.neg(d.normal));i.contains(n.vertices,S[0])&&b.push(S[0]),b.length<2&&i.contains(n.vertices,S[1])&&b.push(S[1])}return b.length<1&&(b=[h[0]]),d.supports=b,d};var e=function(e,o,n){for(var i,s,a=r._temp[0],l=r._temp[1],c={overlap:Number.MAX_VALUE},d=0;d=i)return c.overlap=i,c;ii?i=a:n>a&&(n=a)}e.min=n,e.max=i},o=function(e,t,o){for(var n,i,s,a,l=Number.MAX_VALUE,c=r._temp[0],d=t.vertices,u=e.position,p=0;pn&&(l=n,s=i);var v=s.index-1>=0?s.index-1:d.length-1;i=d[v],c.x=i.x-u.x,c.y=i.y-u.y,l=-r.dot(o,c),a=i;var f=(s.index+1)%d.length;return i=d[f],c.x=i.x-u.x,c.y=i.y-u.y,n=-r.dot(o,c),l>n&&(a=i),[s,a]}}()},{"../geometry/Vector":26,"../geometry/Vertices":27}],12:[function(e,t,o){var n={};t.exports=n;var i=e("../geometry/Vertices"),r=e("../geometry/Vector"),s=e("../core/Sleeping"),a=e("../geometry/Bounds"),l=e("../geometry/Axes"),c=e("../core/Common");!function(){var e=1e-6,t=.001;n.create=function(t){var o=t;o.bodyA&&!o.pointA&&(o.pointA={x:0,y:0}),o.bodyB&&!o.pointB&&(o.pointB={x:0,y:0});var n=o.bodyA?r.add(o.bodyA.position,o.pointA):o.pointA,i=o.bodyB?r.add(o.bodyB.position,o.pointB):o.pointB,s=r.magnitude(r.sub(n,i)); -o.length=o.length||s||e;var a={visible:!0,lineWidth:2,strokeStyle:"#666"};return o.render=c.extend(a,o.render),o.id=o.id||c.nextId(),o.label=o.label||"Constraint",o.type="constraint",o.stiffness=o.stiffness||1,o.angularStiffness=o.angularStiffness||0,o.angleA=o.bodyA?o.bodyA.angle:o.angleA,o.angleB=o.bodyB?o.bodyB.angle:o.angleB,o},n.solveAll=function(e,t){for(var o=0;o0&&r.rotateAbout(s.position,o,e.position,s.position); +}},n.setVelocity=function(e,t){e.positionPrev.x=e.position.x-t.x,e.positionPrev.y=e.position.y-t.y,e.velocity.x=t.x,e.velocity.y=t.y,e.speed=r.magnitude(e.velocity)},n.setAngularVelocity=function(e,t){e.anglePrev=e.angle-t,e.angularVelocity=t,e.angularSpeed=Math.abs(e.angularVelocity)},n.translate=function(e,t){n.setPosition(e,r.add(e.position,t))},n.rotate=function(e,t){n.setAngle(e,e.angle+t)},n.scale=function(e,t,o,r){for(var s=0;s0&&(f.position.x+=e.velocity.x,f.position.y+=e.velocity.y),0!==e.angularVelocity&&(i.rotate(f.vertices,e.angularVelocity,e.position),c.rotate(f.axes,e.angularVelocity),p>0&&r.rotateAbout(f.position,e.angularVelocity,e.position,f.position)),l.update(f.bounds,f.vertices,e.velocity)}},n.applyForce=function(e,t,o){e.force.x+=o.x,e.force.y+=o.y;var n={x:t.x-e.position.x,y:t.y-e.position.y};e.torque+=(n.x*o.y-n.y*o.x)*e.inverseInertia};var u=function(e){for(var t={mass:0,area:0,inertia:0,centre:{x:0,y:0}},o=1===e.parts.length?0:1;o1?1:0;u1?1:0;f0:0!==(e.mask&t.category)&&0!==(t.mask&e.category)}}()},{"../geometry/Bounds":24,"./Pair":7,"./SAT":11}],6:[function(e,t,o){var n={};t.exports=n;var i=e("./Pair"),r=e("./Detector"),s=e("../core/Common"); +!function(){n.create=function(e){var t={controller:n,detector:r.collisions,buckets:{},pairs:{},pairsList:[],bucketWidth:48,bucketHeight:48};return s.extend(t,e)},n.update=function(o,n,i,r){var s,p,f,v,y,m=i.world,g=o.buckets,x=!1;for(s=0;sm.bounds.width||h.bounds.max.y<0||h.bounds.min.y>m.bounds.height)){var b=t(o,h);if(!h.region||b.id!==h.region.id||r){(!h.region||r)&&(h.region=b);var S=e(b,h.region);for(p=S.startCol;p<=S.endCol;p++)for(f=S.startRow;f<=S.endRow;f++){y=a(p,f),v=g[y];var w=p>=b.startCol&&p<=b.endCol&&f>=b.startRow&&f<=b.endRow,C=p>=h.region.startCol&&p<=h.region.endCol&&f>=h.region.startRow&&f<=h.region.endRow;!w&&C&&C&&v&&d(o,v,h),(h.region===b||w&&!C||r)&&(v||(v=l(g,y)),c(o,v,h))}h.region=b,x=!0}}}x&&(o.pairsList=u(o))},n.clear=function(e){e.buckets={},e.pairs={},e.pairsList=[]};var e=function(e,t){var n=Math.min(e.startCol,t.startCol),i=Math.max(e.endCol,t.endCol),r=Math.min(e.startRow,t.startRow),s=Math.max(e.endRow,t.endRow); +return o(n,i,r,s)},t=function(e,t){var n=t.bounds,i=Math.floor(n.min.x/e.bucketWidth),r=Math.floor(n.max.x/e.bucketWidth),s=Math.floor(n.min.y/e.bucketHeight),a=Math.floor(n.max.y/e.bucketHeight);return o(i,r,s,a)},o=function(e,t,o,n){return{id:e+","+t+","+o+","+n,startCol:e,endCol:t,startRow:o,endRow:n}},a=function(e,t){return e+","+t},l=function(e,t){var o=e[t]=[];return o},c=function(e,t,o){for(var n=0;n0?n.push(o):delete e.pairs[t[i]];return n}}()},{"../core/Common":14,"./Detector":5,"./Pair":7}],7:[function(e,t,o){var n={};t.exports=n;var i=e("./Contact");!function(){n.create=function(e,t){var o=e.bodyA,i=e.bodyB,r=e.parentA,s=e.parentB,a={ +id:n.id(o,i),bodyA:o,bodyB:i,contacts:{},activeContacts:[],separation:0,isActive:!0,timeCreated:t,timeUpdated:t,inverseMass:r.inverseMass+s.inverseMass,friction:Math.min(r.friction,s.friction),frictionStatic:Math.max(r.frictionStatic,s.frictionStatic),restitution:Math.max(r.restitution,s.restitution),slop:Math.max(r.slop,s.slop)};return n.update(a,e,t),a},n.update=function(e,t,o){var r=e.contacts,s=t.supports,a=e.activeContacts,l=t.parentA,c=t.parentB;if(e.collision=t,e.inverseMass=l.inverseMass+c.inverseMass,e.friction=Math.min(l.friction,c.friction),e.frictionStatic=Math.max(l.frictionStatic,c.frictionStatic),e.restitution=Math.max(l.restitution,c.restitution),e.slop=Math.max(l.slop,c.slop),a.length=0,t.collided){for(var d=0;de&&c.push(s);for(s=0;sf.friction*f.frictionStatic*L*o&&(O=V,_=s.clamp(f.friction*R*o,-O,O));var W=r.cross(A,g),F=r.cross(B,g),N=b/(y.inverseMass+m.inverseMass+y.inverseInertia*W*W+m.inverseInertia*F*F);if(E*=N,_*=N,0>I&&I*I>n._restingThresh*o)w.normalImpulse=0;else{var D=w.normalImpulse;w.normalImpulse=Math.min(w.normalImpulse+E,0),E=w.normalImpulse-D}if(T*T>n._restingThreshTangent*o)w.tangentImpulse=0;else{var q=w.tangentImpulse;w.tangentImpulse=s.clamp(w.tangentImpulse+_,-O,O),_=w.tangentImpulse-q; +}i.x=g.x*E+x.x*_,i.y=g.y*E+x.y*_,y.isStatic||y.isSleeping||(y.positionPrev.x+=i.x*y.inverseMass,y.positionPrev.y+=i.y*y.inverseMass,y.anglePrev+=r.cross(A,i)*y.inverseInertia),m.isStatic||m.isSleeping||(m.positionPrev.x-=i.x*m.inverseMass,m.positionPrev.y-=i.y*m.inverseMass,m.anglePrev-=r.cross(B,i)*m.inverseInertia)}}}}}()},{"../core/Common":14,"../geometry/Bounds":24,"../geometry/Vector":26,"../geometry/Vertices":27}],11:[function(e,t,o){var n={};t.exports=n;var i=e("../geometry/Vertices"),r=e("../geometry/Vector");!function(){n.collides=function(t,n,s){var a,l,c,d,u=s,p=!1;if(u){var f=t.parent,v=n.parent,y=f.speed*f.speed+f.angularSpeed*f.angularSpeed+v.speed*v.speed+v.angularSpeed*v.angularSpeed;p=u&&u.collided&&.2>y,d=u}else d={collided:!1,bodyA:t,bodyB:n};if(u&&p){var m=d.axisBody,g=m===t?n:t,x=[m.axes[u.axisNumber]];if(c=e(m.vertices,g.vertices,x),d.reused=!0,c.overlap<=0)return d.collided=!1,d}else{if(a=e(t.vertices,n.vertices,t.axes),a.overlap<=0)return d.collided=!1,d;if(l=e(n.vertices,t.vertices,n.axes), +l.overlap<=0)return d.collided=!1,d;a.overlap0&&(d.normal=r.neg(d.normal)),d.tangent=r.perp(d.normal),d.penetration={x:d.normal.x*d.depth,y:d.normal.y*d.depth};var h=o(t,n,d.normal),b=d.supports||[];if(b.length=0,i.contains(t.vertices,h[0])&&b.push(h[0]),i.contains(t.vertices,h[1])&&b.push(h[1]),b.length<2){var S=o(n,t,r.neg(d.normal));i.contains(n.vertices,S[0])&&b.push(S[0]),b.length<2&&i.contains(n.vertices,S[1])&&b.push(S[1])}return b.length<1&&(b=[h[0]]),d.supports=b,d};var e=function(e,o,n){for(var i,s,a=r._temp[0],l=r._temp[1],c={overlap:Number.MAX_VALUE},d=0;d=i)return c.overlap=i,c;ii?i=a:n>a&&(n=a)}e.min=n,e.max=i},o=function(e,t,o){for(var n,i,s,a,l=Number.MAX_VALUE,c=r._temp[0],d=t.vertices,u=e.position,p=0;pn&&(l=n,s=i);var f=s.index-1>=0?s.index-1:d.length-1;i=d[f],c.x=i.x-u.x,c.y=i.y-u.y,l=-r.dot(o,c),a=i;var v=(s.index+1)%d.length;return i=d[v],c.x=i.x-u.x,c.y=i.y-u.y,n=-r.dot(o,c),l>n&&(a=i),[s,a]}}()},{"../geometry/Vector":26,"../geometry/Vertices":27}],12:[function(e,t,o){var n={};t.exports=n;var i=e("../geometry/Vertices"),r=e("../geometry/Vector"),s=e("../core/Sleeping"),a=e("../geometry/Bounds"),l=e("../geometry/Axes"),c=e("../core/Common");!function(){var e=1e-6,t=.001;n.create=function(t){var o=t;o.bodyA&&!o.pointA&&(o.pointA={x:0,y:0}),o.bodyB&&!o.pointB&&(o.pointB={x:0,y:0});var n=o.bodyA?r.add(o.bodyA.position,o.pointA):o.pointA,i=o.bodyB?r.add(o.bodyB.position,o.pointB):o.pointB,s=r.magnitude(r.sub(n,i)); +o.length=o.length||s||e;var a={visible:!0,lineWidth:2,strokeStyle:"#666"};return o.render=c.extend(a,o.render),o.id=o.id||c.nextId(),o.label=o.label||"Constraint",o.type="constraint",o.stiffness=o.stiffness||1,o.angularStiffness=o.angularStiffness||0,o.angleA=o.bodyA?o.bodyA.angle:o.angleA,o.angleB=o.bodyB?o.bodyB.angle:o.angleB,o},n.solveAll=function(e,t){for(var o=0;o0&&(M=0);var k,I={x:m.x*M,y:m.y*M};i&&!i.isStatic&&(k=r.cross(b,I)*i.inverseInertia*(1-o.angularStiffness),s.set(i,!1),k=c.clamp(k,-.01,.01),i.constraintImpulse.x-=g.x,i.constraintImpulse.y-=g.y,i.constraintImpulse.angle+=k,i.position.x-=g.x,i.position.y-=g.y,i.angle+=k),a&&!a.isStatic&&(k=r.cross(S,I)*a.inverseInertia*(1-o.angularStiffness),s.set(a,!1),k=c.clamp(k,-.01,.01),a.constraintImpulse.x+=g.x,a.constraintImpulse.y+=g.y,a.constraintImpulse.angle-=k, a.position.x+=g.x,a.position.y+=g.y,a.angle-=k)}}},n.postSolveAll=function(e){for(var t=0;t0&&(c.position.x+=n.x,c.position.y+=n.y),0!==n.angle&&(i.rotate(c.vertices,n.angle,o.position),l.rotate(c.axes,n.angle),s>0&&r.rotateAbout(c.position,n.angle,o.position,c.position)),a.update(c.bounds,c.vertices,o.velocity)}n.angle=0,n.x=0,n.y=0}}}}()},{"../core/Common":14,"../core/Sleeping":20,"../geometry/Axes":23,"../geometry/Bounds":24,"../geometry/Vector":26,"../geometry/Vertices":27}],13:[function(e,t,o){var n={};t.exports=n;var i=e("../geometry/Vertices"),r=e("../core/Sleeping"),s=e("../core/Mouse"),a=e("../core/Events"),l=e("../collision/Detector"),c=e("./Constraint"),d=e("../body/Composite"),u=e("../core/Common"),p=e("../geometry/Bounds");!function(){n.create=function(t,o){var i=(t?t.mouse:null)||(o?o.mouse:null);!i&&t&&t.render&&t.render.canvas?i=s.create(t.render.canvas):(i=s.create(), u.log("MouseConstraint.create: options.mouse was undefined, engine.render.canvas was undefined, may not function as expected","warn"));var r=c.create({label:"Mouse Constraint",pointA:i.position,pointB:{x:0,y:0},length:.01,stiffness:.1,angularStiffness:1,render:{strokeStyle:"#90EE90",lineWidth:3}}),l={type:"mouseConstraint",mouse:i,body:null,constraint:r,collisionFilter:{category:1,mask:4294967295,group:0}},p=u.extend(l,o);return a.on(t,"tick",function(){var o=d.allBodies(t.world);n.update(p,o),e(p)}),p},n.update=function(e,t){var o=e.mouse,n=e.constraint,s=e.body;if(0===o.button){if(n.bodyB)r.set(n.bodyB,!1),n.pointA=o.position;else for(var c=0;c1?1:0;d>16)+n,r=(o>>8&255)+n,s=(255&o)+n;return"#"+(16777216+65536*(255>i?1>i?0:i:255)+256*(255>r?1>r?0:r:255)+(255>s?1>s?0:s:255)).toString(16).slice(1)},n.shuffle=function(e){for(var t=e.length-1;t>0;t--){var o=Math.floor(n.random()*(t+1)),i=e[t];e[t]=e[o],e[o]=i}return e},n.choose=function(e){return e[Math.floor(n.random()*e.length)]},n.isElement=function(e){try{return e instanceof HTMLElement}catch(t){return"object"==typeof e&&1===e.nodeType&&"object"==typeof e.style&&"object"==typeof e.ownerDocument}},n.isArray=function(e){return"[object Array]"===Object.prototype.toString.call(e)},n.clamp=function(e,t,o){return t>e?t:e>o?o:e},n.sign=function(e){return 0>e?-1:1},n.now=function(){var e=window.performance||{};return e.now=function(){ -return e.now||e.webkitNow||e.msNow||e.oNow||e.mozNow||function(){return+new Date}}(),e.now()},n.random=function(t,o){return t="undefined"!=typeof t?t:0,o="undefined"!=typeof o?o:1,t+e()*(o-t)},n.colorToNumber=function(e){return e=e.replace("#",""),3==e.length&&(e=e.charAt(0)+e.charAt(0)+e.charAt(1)+e.charAt(1)+e.charAt(2)+e.charAt(2)),parseInt(e,16)},n.log=function(e,t){if(console&&console.log&&console.warn)switch(t){case"warn":console.warn("Matter.js:",e);break;case"error":console.log("Matter.js:",e)}},n.nextId=function(){return n._nextId++},n.indexOf=function(e,t){if(e.indexOf)return e.indexOf(t);for(var o=0;o0&&d.trigger(n,"collisionStart",{pairs:S.collisionStart}),s.preSolvePosition(S.list),c=0;c0&&d.trigger(n,"collisionActive",{pairs:S.collisionActive}),S.collisionEnd.length>0&&d.trigger(n,"collisionEnd",{pairs:S.collisionEnd}),e(x),v.isModified&&u.setModified(v,!1,!1,!0),d.trigger(n,"afterUpdate",g),n},n.merge=function(e,t){if(v.extend(e,t),t.world){e.world=t.world,n.clear(e);for(var o=u.allBodies(e.world),i=0;i0&&d.trigger(n,"collisionStart",{pairs:S.collisionStart}),s.preSolvePosition(S.list),c=0;c0&&d.trigger(n,"collisionActive",{pairs:S.collisionActive}),S.collisionEnd.length>0&&d.trigger(n,"collisionEnd",{pairs:S.collisionEnd}),e(x),f.isModified&&u.setModified(f,!1,!1,!0),d.trigger(n,"afterUpdate",g),n},n.merge=function(e,t){if(f.extend(e,t),t.world){e.world=t.world,n.clear(e);for(var o=u.allBodies(e.world),i=0;ie.deltaMax?e.deltaMax:n,a=n/e.delta,e.delta=n),0!==e.timeScalePrev&&(a*=s.timeScale/e.timeScalePrev),0===s.timeScale&&(a=0),e.timeScalePrev=s.timeScale,e.correction=a,e.frameCounter+=1,o-e.counterTimestamp>=1e3&&(e.fps=e.frameCounter*((o-e.counterTimestamp)/1e3),e.counterTimestamp=o,e.frameCounter=0),i.trigger(e,"tick",l),i.trigger(t,"tick",l),t.world.isModified&&t.render&&t.render.controller&&t.render.controller.clear&&t.render.controller.clear(t.render),i.trigger(e,"beforeUpdate",l),r.update(t,n,a),i.trigger(e,"afterUpdate",l), t.render&&t.render.controller&&(i.trigger(e,"beforeRender",l),i.trigger(t,"beforeRender",l),t.render.controller.world(t),i.trigger(e,"afterRender",l),i.trigger(t,"afterRender",l)),i.trigger(e,"afterTick",l),i.trigger(t,"afterTick",l)},n.stop=function(e){t(e.frameRequestId)},n.start=function(e,t){n.run(e,t)}}()},{"./Common":14,"./Engine":15,"./Events":16}],20:[function(e,t,o){var n={};t.exports=n;var i=e("./Events");!function(){n._motionWakeThreshold=.18,n._motionSleepThreshold=.08,n._minBias=.9,n.update=function(e,t){for(var o=t*t*t,i=0;i0&&r.motion=r.sleepThreshold&&n.set(r,!0)):r.sleepCounter>0&&(r.sleepCounter-=1)}else n.set(r,!1)}},n.afterCollisions=function(e,t){for(var o=t*t*t,i=0;in._motionWakeThreshold*o&&n.set(c,!1)}}}},n.set=function(e,t){var o=e.isSleeping;t?(e.isSleeping=!0,e.sleepCounter=e.sleepThreshold,e.positionImpulse.x=0,e.positionImpulse.y=0,e.positionPrev.x=e.position.x,e.positionPrev.y=e.position.y,e.anglePrev=e.angle,e.speed=0,e.angularSpeed=0,e.motion=0,o||i.trigger(e,"sleepStart")):(e.isSleeping=!1,e.sleepCounter=0,o&&i.trigger(e,"sleepEnd"))}}()},{"./Events":16}],21:[function(e,t,o){var n={};t.exports=n;var i=e("../geometry/Vertices"),r=e("../core/Common"),s=e("../body/Body"),a=e("../geometry/Bounds"),l=e("../geometry/Vector");!function(){n.rectangle=function(e,t,o,n,a){a=a||{};var l={label:"Rectangle Body",position:{x:e,y:t},vertices:i.fromPath("L 0 0 L "+o+" 0 L "+o+" "+n+" L 0 "+n)};if(a.chamfer){var c=a.chamfer;l.vertices=i.chamfer(l.vertices,c.radius,c.quality,c.qualityMin,c.qualityMax), -delete a.chamfer}return s.create(r.extend({},l,a))},n.trapezoid=function(e,t,o,n,a,l){l=l||{},a*=.5;var c=(1-2*a)*o,d=o*a,u=d+c,p=u+d,v={label:"Trapezoid Body",position:{x:e,y:t},vertices:i.fromPath("L 0 0 L "+d+" "+-n+" L "+u+" "+-n+" L "+p+" 0")};if(l.chamfer){var f=l.chamfer;v.vertices=i.chamfer(v.vertices,f.radius,f.quality,f.qualityMin,f.qualityMax),delete l.chamfer}return s.create(r.extend({},v,l))},n.circle=function(e,t,o,i,r){i=i||{},i.label="Circle Body",r=r||25;var s=Math.ceil(Math.max(10,Math.min(r,o)));return s%2===1&&(s+=1),i.circleRadius=o,n.polygon(e,t,s,o,i)},n.polygon=function(e,t,o,a,l){if(l=l||{},3>o)return n.circle(e,t,a,l);for(var c=2*Math.PI/o,d="",u=.5*c,p=0;o>p;p+=1){var v=u+p*c,f=Math.cos(v)*a,y=Math.sin(v)*a;d+="L "+f.toFixed(3)+" "+y.toFixed(3)+" "}var m={label:"Polygon Body",position:{x:e,y:t},vertices:i.fromPath(d)};if(l.chamfer){var g=l.chamfer;m.vertices=i.chamfer(m.vertices,g.radius,g.quality,g.qualityMin,g.qualityMax),delete l.chamfer}return s.create(r.extend({},m,l)); -},n.fromVertices=function(e,t,o,n,c,d,u){var p,v,f,y,m,g,x,h,b;for(n=n||{},v=[],c="undefined"!=typeof c?c:!1,d="undefined"!=typeof d?d:.01,u="undefined"!=typeof u?u:10,window.decomp||r.log("Bodies.fromVertices: poly-decomp.js required. Could not decompose vertices. Fallback to convex hull.","warn"),r.isArray(o[0])||(o=[o]),h=0;h0&&i.area(A)V&&B>T&&(k[x].isInternal=!0,I[b].isInternal=!0)}}}}}return v.length>1?(p=s.create(r.extend({parts:v.slice(0)},n)),s.setPosition(p,{x:e,y:t}),p):v[0]}}()},{"../body/Body":1,"../core/Common":14,"../geometry/Bounds":24,"../geometry/Vector":26,"../geometry/Vertices":27}],22:[function(e,t,o){var n={};t.exports=n;var i=e("../body/Composite"),r=e("../constraint/Constraint"),s=e("../core/Common"),a=e("../body/Body"),l=e("./Bodies");!function(){n.stack=function(e,t,o,n,r,s,l){for(var c,d=i.create({label:"Stack"}),u=e,p=t,v=0,f=0;n>f;f++){for(var y=0,m=0;o>m;m++){var g=l(u,p,m,f,c,v);if(g){var x=g.bounds.max.y-g.bounds.min.y,h=g.bounds.max.x-g.bounds.min.x;x>y&&(y=x),a.translate(g,{x:.5*h,y:.5*x}),u=g.bounds.max.x+r,i.addBody(d,g),c=g,v+=1}else u+=r}p+=y+s,u=e}return d},n.chain=function(e,t,o,n,a,l){for(var c=e.bodies,d=1;dl;l++){for(c=1;t>c;c++)d=v[c-1+l*t],u=v[c+l*t],i.addConstraint(e,r.create(s.extend({bodyA:d,bodyB:u},a)));if(l>0)for(c=0;t>c;c++)d=v[c+(l-1)*t],u=v[c+l*t],i.addConstraint(e,r.create(s.extend({bodyA:d,bodyB:u},a))),n&&c>0&&(p=v[c-1+(l-1)*t],i.addConstraint(e,r.create(s.extend({bodyA:p,bodyB:u},a)))),n&&t-1>c&&(p=v[c+1+(l-1)*t],i.addConstraint(e,r.create(s.extend({bodyA:p,bodyB:u},a))))}return e.label+=" Mesh",e},n.pyramid=function(e,t,o,i,r,s,l){return n.stack(e,t,o,i,r,s,function(t,n,s,c,d,u){var p=Math.min(i,Math.ceil(o/2)),v=d?d.bounds.max.x-d.bounds.min.x:0;if(!(c>p)){c=p-c;var f=c,y=o-1-c;if(!(f>s||s>y)){1===u&&a.translate(d,{x:(s+(o%2===1?1:-1))*v, -y:0});var m=d?s*v:0;return l(e+m+s*r,n,s,c,d,u)}}})},n.newtonsCradle=function(e,t,o,n,s){for(var a=i.create({label:"Newtons Cradle"}),c=0;o>c;c++){var d=1.9,u=l.circle(e+c*(n*d),t+s,n,{inertia:99999,restitution:1,friction:0,frictionAir:1e-4,slop:.01}),p=r.create({pointA:{x:e+c*(n*d),y:t},bodyB:u});i.addBody(a,u),i.addConstraint(a,p)}return a},n.car=function(e,t,o,n,s){var c=a.nextGroup(!0),d=-20,u=.5*-o+d,p=.5*o-d,v=0,f=i.create({label:"Car"}),y=l.trapezoid(e,t,o,n,.3,{collisionFilter:{group:c},friction:.01,chamfer:{radius:10}}),m=l.circle(e+u,t+v,s,{collisionFilter:{group:c},restitution:.5,friction:.9,frictionStatic:10,slop:.5,density:.01}),g=l.circle(e+p,t+v,s,{collisionFilter:{group:c},restitution:.5,friction:.9,frictionStatic:10,slop:.5,density:.01}),x=r.create({bodyA:y,pointA:{x:u,y:v},bodyB:m,stiffness:.5}),h=r.create({bodyA:y,pointA:{x:p,y:v},bodyB:g,stiffness:.5});return i.addBody(f,y),i.addBody(f,m),i.addBody(f,g),i.addConstraint(f,x),i.addConstraint(f,h),f},n.softBody=function(e,t,o,i,r,a,c,d,u,p){ -u=s.extend({inertia:1/0},u),p=s.extend({stiffness:.4},p);var v=n.stack(e,t,o,i,r,a,function(e,t){return l.circle(e,t,d,u)});return n.mesh(v,o,i,c,p),v.label="Soft Body",v}}()},{"../body/Body":1,"../body/Composite":2,"../constraint/Constraint":12,"../core/Common":14,"./Bodies":21}],23:[function(e,t,o){var n={};t.exports=n;var i=e("../geometry/Vector"),r=e("../core/Common");!function(){n.fromVertices=function(e){for(var t={},o=0;oe.max.x&&(e.max.x=i.x),i.xe.max.y&&(e.max.y=i.y),i.y0?e.max.x+=o.x:e.min.x+=o.x,o.y>0?e.max.y+=o.y:e.min.y+=o.y)},n.contains=function(e,t){return t.x>=e.min.x&&t.x<=e.max.x&&t.y>=e.min.y&&t.y<=e.max.y},n.overlaps=function(e,t){return e.min.x<=t.max.x&&e.max.x>=t.min.x&&e.max.y>=t.min.y&&e.min.y<=t.max.y},n.translate=function(e,t){e.min.x+=t.x,e.max.x+=t.x,e.min.y+=t.y,e.max.y+=t.y},n.shift=function(e,t){var o=e.max.x-e.min.x,n=e.max.y-e.min.y;e.min.x=t.x,e.max.x=t.x+o,e.min.y=t.y,e.max.y=t.y+n}}()},{}],25:[function(e,t,o){var n={};t.exports=n;e("../geometry/Bounds");!function(){n.pathToVertices=function(t,o){var n,i,r,s,a,l,c,d,u,p,v,f,y=[],m=0,g=0,x=0;o=o||15;var h=function(e,t,o){var n=o%2===1&&o>1;if(!u||e!=u.x||t!=u.y){u&&n?(v=u.x,f=u.y):(v=0,f=0);var i={x:v+e,y:f+t};(n||!u)&&(u=i),y.push(i),g=v+e,x=f+t}},b=function(e){var t=e.pathSegTypeAsLetter.toUpperCase(); -if("Z"!==t){switch(t){case"M":case"L":case"T":case"C":case"S":case"Q":g=e.x,x=e.y;break;case"H":g=e.x;break;case"V":x=e.y}h(g,x,e.pathSegType)}};for(e(t),r=t.getTotalLength(),l=[],n=0;nm;){if(p=t.getPathSegAtLength(m),a=l[p],a!=d){for(;c.length&&c[0]!=a;)b(c.shift());d=a}switch(a.pathSegTypeAsLetter.toUpperCase()){case"C":case"T":case"S":case"Q":case"A":s=t.getPointAtLength(m),h(s.x,s.y,0)}m+=o}for(n=0,i=c.length;i>n;++n)b(c[n]);return y};var e=function(e){for(var t,o,n,i,r,s,a=e.pathSegList,l=0,c=0,d=a.numberOfItems,u=0;d>u;++u){var p=a.getItem(u),v=p.pathSegTypeAsLetter;if(/[MLHVCSQTA]/.test(v))"x"in p&&(l=p.x),"y"in p&&(c=p.y);else switch("x1"in p&&(n=l+p.x1),"x2"in p&&(r=l+p.x2),"y1"in p&&(i=c+p.y1),"y2"in p&&(s=c+p.y2),"x"in p&&(l+=p.x),"y"in p&&(c+=p.y),v){case"m":a.replaceItem(e.createSVGPathSegMovetoAbs(l,c),u);break;case"l":a.replaceItem(e.createSVGPathSegLinetoAbs(l,c),u);break;case"h":a.replaceItem(e.createSVGPathSegLinetoHorizontalAbs(l),u); -break;case"v":a.replaceItem(e.createSVGPathSegLinetoVerticalAbs(c),u);break;case"c":a.replaceItem(e.createSVGPathSegCurvetoCubicAbs(l,c,n,i,r,s),u);break;case"s":a.replaceItem(e.createSVGPathSegCurvetoCubicSmoothAbs(l,c,r,s),u);break;case"q":a.replaceItem(e.createSVGPathSegCurvetoQuadraticAbs(l,c,n,i),u);break;case"t":a.replaceItem(e.createSVGPathSegCurvetoQuadraticSmoothAbs(l,c),u);break;case"a":a.replaceItem(e.createSVGPathSegArcAbs(l,c,p.r1,p.r2,p.angle,p.largeArcFlag,p.sweepFlag),u);break;case"z":case"Z":l=t,c=o}("M"==v||"m"==v)&&(t=l,o=c)}}}()},{"../geometry/Bounds":24}],26:[function(e,t,o){var n={};t.exports=n,function(){n.create=function(e,t){return{x:e||0,y:t||0}},n.clone=function(e){return{x:e.x,y:e.y}},n.magnitude=function(e){return Math.sqrt(e.x*e.x+e.y*e.y)},n.magnitudeSquared=function(e){return e.x*e.x+e.y*e.y},n.rotate=function(e,t){var o=Math.cos(t),n=Math.sin(t);return{x:e.x*o-e.y*n,y:e.x*n+e.y*o}},n.rotateAbout=function(e,t,o,n){var i=Math.cos(t),r=Math.sin(t);n||(n={}); -var s=o.x+((e.x-o.x)*i-(e.y-o.y)*r);return n.y=o.y+((e.x-o.x)*r+(e.y-o.y)*i),n.x=s,n},n.normalise=function(e){var t=n.magnitude(e);return 0===t?{x:0,y:0}:{x:e.x/t,y:e.y/t}},n.dot=function(e,t){return e.x*t.x+e.y*t.y},n.cross=function(e,t){return e.x*t.y-e.y*t.x},n.cross3=function(e,t,o){return(t.x-e.x)*(o.y-e.y)-(t.y-e.y)*(o.x-e.x)},n.add=function(e,t,o){return o||(o={}),o.x=e.x+t.x,o.y=e.y+t.y,o},n.sub=function(e,t,o){return o||(o={}),o.x=e.x-t.x,o.y=e.y-t.y,o},n.mult=function(e,t){return{x:e.x*t,y:e.y*t}},n.div=function(e,t){return{x:e.x/t,y:e.y/t}},n.perp=function(e,t){return t=t===!0?-1:1,{x:t*-e.y,y:t*e.x}},n.neg=function(e){return{x:-e.x,y:-e.y}},n.angle=function(e,t){return Math.atan2(t.y-e.y,t.x-e.x)},n._temp=[n.create(),n.create(),n.create(),n.create(),n.create(),n.create()]}()},{}],27:[function(e,t,o){var n={};t.exports=n;var i=e("../geometry/Vector"),r=e("../core/Common");!function(){n.create=function(e,t){for(var o=[],n=0;n0)return!1}return!0},n.scale=function(e,t,o,r){if(1===t&&1===o)return e;r=r||n.centre(e);for(var s,a,l=0;l=0?l-1:e.length-1],d=e[l],u=e[(l+1)%e.length],p=t[lw;w++)a.push(i.add(i.rotate(m,S*w),x)); +delete a.chamfer}return s.create(r.extend({},l,a))},n.trapezoid=function(e,t,o,n,a,l){l=l||{},a*=.5;var c,d=(1-2*a)*o,u=o*a,p=u+d,f=p+u;c=.5>a?"L 0 0 L "+u+" "+-n+" L "+p+" "+-n+" L "+f+" 0":"L 0 0 L "+p+" "+-n+" L "+f+" 0";var v={label:"Trapezoid Body",position:{x:e,y:t},vertices:i.fromPath(c)};if(l.chamfer){var y=l.chamfer;v.vertices=i.chamfer(v.vertices,y.radius,y.quality,y.qualityMin,y.qualityMax),delete l.chamfer}return s.create(r.extend({},v,l))},n.circle=function(e,t,o,i,r){i=i||{},i.label="Circle Body",r=r||25;var s=Math.ceil(Math.max(10,Math.min(r,o)));return s%2===1&&(s+=1),i.circleRadius=o,n.polygon(e,t,s,o,i)},n.polygon=function(e,t,o,a,l){if(l=l||{},3>o)return n.circle(e,t,a,l);for(var c=2*Math.PI/o,d="",u=.5*c,p=0;o>p;p+=1){var f=u+p*c,v=Math.cos(f)*a,y=Math.sin(f)*a;d+="L "+v.toFixed(3)+" "+y.toFixed(3)+" "}var m={label:"Polygon Body",position:{x:e,y:t},vertices:i.fromPath(d)};if(l.chamfer){var g=l.chamfer;m.vertices=i.chamfer(m.vertices,g.radius,g.quality,g.qualityMin,g.qualityMax), +delete l.chamfer}return s.create(r.extend({},m,l))},n.fromVertices=function(e,t,o,n,c,d,u){var p,f,v,y,m,g,x,h,b;for(n=n||{},f=[],c="undefined"!=typeof c?c:!1,d="undefined"!=typeof d?d:.01,u="undefined"!=typeof u?u:10,window.decomp||r.log("Bodies.fromVertices: poly-decomp.js required. Could not decompose vertices. Fallback to convex hull.","warn"),r.isArray(o[0])||(o=[o]),h=0;h0&&i.area(A)T&&B>V&&(k[x].isInternal=!0,I[b].isInternal=!0)}}}}}return f.length>1?(p=s.create(r.extend({parts:f.slice(0)},n)),s.setPosition(p,{x:e,y:t}),p):f[0]}}()},{"../body/Body":1,"../core/Common":14,"../geometry/Bounds":24,"../geometry/Vector":26,"../geometry/Vertices":27}],22:[function(e,t,o){var n={};t.exports=n;var i=e("../body/Composite"),r=e("../constraint/Constraint"),s=e("../core/Common"),a=e("../body/Body"),l=e("./Bodies");!function(){n.stack=function(e,t,o,n,r,s,l){for(var c,d=i.create({label:"Stack"}),u=e,p=t,f=0,v=0;n>v;v++){for(var y=0,m=0;o>m;m++){var g=l(u,p,m,v,c,f);if(g){var x=g.bounds.max.y-g.bounds.min.y,h=g.bounds.max.x-g.bounds.min.x;x>y&&(y=x),a.translate(g,{x:.5*h,y:.5*x}),u=g.bounds.max.x+r,i.addBody(d,g),c=g,f+=1}else u+=r}p+=y+s,u=e}return d},n.chain=function(e,t,o,n,a,l){ +for(var c=e.bodies,d=1;dl;l++){for(c=1;t>c;c++)d=f[c-1+l*t],u=f[c+l*t],i.addConstraint(e,r.create(s.extend({bodyA:d,bodyB:u},a)));if(l>0)for(c=0;t>c;c++)d=f[c+(l-1)*t],u=f[c+l*t],i.addConstraint(e,r.create(s.extend({bodyA:d,bodyB:u},a))),n&&c>0&&(p=f[c-1+(l-1)*t],i.addConstraint(e,r.create(s.extend({bodyA:p,bodyB:u},a)))),n&&t-1>c&&(p=f[c+1+(l-1)*t],i.addConstraint(e,r.create(s.extend({bodyA:p,bodyB:u},a))))}return e.label+=" Mesh",e},n.pyramid=function(e,t,o,i,r,s,l){return n.stack(e,t,o,i,r,s,function(t,n,s,c,d,u){var p=Math.min(i,Math.ceil(o/2)),f=d?d.bounds.max.x-d.bounds.min.x:0;if(!(c>p)){c=p-c;var v=c,y=o-1-c;if(!(v>s||s>y)){ +1===u&&a.translate(d,{x:(s+(o%2===1?1:-1))*f,y:0});var m=d?s*f:0;return l(e+m+s*r,n,s,c,d,u)}}})},n.newtonsCradle=function(e,t,o,n,s){for(var a=i.create({label:"Newtons Cradle"}),c=0;o>c;c++){var d=1.9,u=l.circle(e+c*(n*d),t+s,n,{inertia:1/0,restitution:1,friction:0,frictionAir:1e-4,slop:1}),p=r.create({pointA:{x:e+c*(n*d),y:t},bodyB:u});i.addBody(a,u),i.addConstraint(a,p)}return a},n.car=function(e,t,o,n,s){var c=a.nextGroup(!0),d=-20,u=.5*-o+d,p=.5*o-d,f=0,v=i.create({label:"Car"}),y=l.trapezoid(e,t,o,n,.3,{collisionFilter:{group:c},friction:.01,chamfer:{radius:10}}),m=l.circle(e+u,t+f,s,{collisionFilter:{group:c},restitution:.5,friction:.9,frictionStatic:10,slop:.5,density:.01}),g=l.circle(e+p,t+f,s,{collisionFilter:{group:c},restitution:.5,friction:.9,frictionStatic:10,slop:.5,density:.01}),x=r.create({bodyA:y,pointA:{x:u,y:f},bodyB:m,stiffness:.5}),h=r.create({bodyA:y,pointA:{x:p,y:f},bodyB:g,stiffness:.5});return i.addBody(v,y),i.addBody(v,m),i.addBody(v,g),i.addConstraint(v,x),i.addConstraint(v,h), +v},n.softBody=function(e,t,o,i,r,a,c,d,u,p){u=s.extend({inertia:1/0},u),p=s.extend({stiffness:.4},p);var f=n.stack(e,t,o,i,r,a,function(e,t){return l.circle(e,t,d,u)});return n.mesh(f,o,i,c,p),f.label="Soft Body",f}}()},{"../body/Body":1,"../body/Composite":2,"../constraint/Constraint":12,"../core/Common":14,"./Bodies":21}],23:[function(e,t,o){var n={};t.exports=n;var i=e("../geometry/Vector"),r=e("../core/Common");!function(){n.fromVertices=function(e){for(var t={},o=0;oe.max.x&&(e.max.x=i.x),i.xe.max.y&&(e.max.y=i.y),i.y0?e.max.x+=o.x:e.min.x+=o.x,o.y>0?e.max.y+=o.y:e.min.y+=o.y)},n.contains=function(e,t){return t.x>=e.min.x&&t.x<=e.max.x&&t.y>=e.min.y&&t.y<=e.max.y},n.overlaps=function(e,t){return e.min.x<=t.max.x&&e.max.x>=t.min.x&&e.max.y>=t.min.y&&e.min.y<=t.max.y},n.translate=function(e,t){e.min.x+=t.x,e.max.x+=t.x,e.min.y+=t.y,e.max.y+=t.y},n.shift=function(e,t){var o=e.max.x-e.min.x,n=e.max.y-e.min.y;e.min.x=t.x,e.max.x=t.x+o,e.min.y=t.y,e.max.y=t.y+n}}()},{}],25:[function(e,t,o){var n={};t.exports=n;e("../geometry/Bounds");!function(){n.pathToVertices=function(t,o){var n,i,r,s,a,l,c,d,u,p,f,v,y=[],m=0,g=0,x=0;o=o||15;var h=function(e,t,o){var n=o%2===1&&o>1;if(!u||e!=u.x||t!=u.y){u&&n?(f=u.x,v=u.y):(f=0,v=0);var i={x:f+e,y:v+t};(n||!u)&&(u=i),y.push(i),g=f+e,x=v+t}},b=function(e){ +var t=e.pathSegTypeAsLetter.toUpperCase();if("Z"!==t){switch(t){case"M":case"L":case"T":case"C":case"S":case"Q":g=e.x,x=e.y;break;case"H":g=e.x;break;case"V":x=e.y}h(g,x,e.pathSegType)}};for(e(t),r=t.getTotalLength(),l=[],n=0;nm;){if(p=t.getPathSegAtLength(m),a=l[p],a!=d){for(;c.length&&c[0]!=a;)b(c.shift());d=a}switch(a.pathSegTypeAsLetter.toUpperCase()){case"C":case"T":case"S":case"Q":case"A":s=t.getPointAtLength(m),h(s.x,s.y,0)}m+=o}for(n=0,i=c.length;i>n;++n)b(c[n]);return y};var e=function(e){for(var t,o,n,i,r,s,a=e.pathSegList,l=0,c=0,d=a.numberOfItems,u=0;d>u;++u){var p=a.getItem(u),f=p.pathSegTypeAsLetter;if(/[MLHVCSQTA]/.test(f))"x"in p&&(l=p.x),"y"in p&&(c=p.y);else switch("x1"in p&&(n=l+p.x1),"x2"in p&&(r=l+p.x2),"y1"in p&&(i=c+p.y1),"y2"in p&&(s=c+p.y2),"x"in p&&(l+=p.x),"y"in p&&(c+=p.y),f){case"m":a.replaceItem(e.createSVGPathSegMovetoAbs(l,c),u);break;case"l":a.replaceItem(e.createSVGPathSegLinetoAbs(l,c),u); +break;case"h":a.replaceItem(e.createSVGPathSegLinetoHorizontalAbs(l),u);break;case"v":a.replaceItem(e.createSVGPathSegLinetoVerticalAbs(c),u);break;case"c":a.replaceItem(e.createSVGPathSegCurvetoCubicAbs(l,c,n,i,r,s),u);break;case"s":a.replaceItem(e.createSVGPathSegCurvetoCubicSmoothAbs(l,c,r,s),u);break;case"q":a.replaceItem(e.createSVGPathSegCurvetoQuadraticAbs(l,c,n,i),u);break;case"t":a.replaceItem(e.createSVGPathSegCurvetoQuadraticSmoothAbs(l,c),u);break;case"a":a.replaceItem(e.createSVGPathSegArcAbs(l,c,p.r1,p.r2,p.angle,p.largeArcFlag,p.sweepFlag),u);break;case"z":case"Z":l=t,c=o}("M"==f||"m"==f)&&(t=l,o=c)}}}()},{"../geometry/Bounds":24}],26:[function(e,t,o){var n={};t.exports=n,function(){n.create=function(e,t){return{x:e||0,y:t||0}},n.clone=function(e){return{x:e.x,y:e.y}},n.magnitude=function(e){return Math.sqrt(e.x*e.x+e.y*e.y)},n.magnitudeSquared=function(e){return e.x*e.x+e.y*e.y},n.rotate=function(e,t){var o=Math.cos(t),n=Math.sin(t);return{x:e.x*o-e.y*n,y:e.x*n+e.y*o}},n.rotateAbout=function(e,t,o,n){ +var i=Math.cos(t),r=Math.sin(t);n||(n={});var s=o.x+((e.x-o.x)*i-(e.y-o.y)*r);return n.y=o.y+((e.x-o.x)*r+(e.y-o.y)*i),n.x=s,n},n.normalise=function(e){var t=n.magnitude(e);return 0===t?{x:0,y:0}:{x:e.x/t,y:e.y/t}},n.dot=function(e,t){return e.x*t.x+e.y*t.y},n.cross=function(e,t){return e.x*t.y-e.y*t.x},n.cross3=function(e,t,o){return(t.x-e.x)*(o.y-e.y)-(t.y-e.y)*(o.x-e.x)},n.add=function(e,t,o){return o||(o={}),o.x=e.x+t.x,o.y=e.y+t.y,o},n.sub=function(e,t,o){return o||(o={}),o.x=e.x-t.x,o.y=e.y-t.y,o},n.mult=function(e,t){return{x:e.x*t,y:e.y*t}},n.div=function(e,t){return{x:e.x/t,y:e.y/t}},n.perp=function(e,t){return t=t===!0?-1:1,{x:t*-e.y,y:t*e.x}},n.neg=function(e){return{x:-e.x,y:-e.y}},n.angle=function(e,t){return Math.atan2(t.y-e.y,t.x-e.x)},n._temp=[n.create(),n.create(),n.create(),n.create(),n.create(),n.create()]}()},{}],27:[function(e,t,o){var n={};t.exports=n;var i=e("../geometry/Vector"),r=e("../core/Common");!function(){n.create=function(e,t){for(var o=[],n=0;n0)return!1}return!0},n.scale=function(e,t,o,r){if(1===t&&1===o)return e;r=r||n.centre(e);for(var s,a,l=0;l=0?l-1:e.length-1],d=e[l],u=e[(l+1)%e.length],p=t[lw;w++)a.push(i.add(i.rotate(m,S*w),x)); }else a.push(d)}return a},n.clockwiseSort=function(e){var t=n.mean(e);return e.sort(function(e,o){return i.angle(t,e)-i.angle(t,o)}),e},n.isConvex=function(e){var t,o,n,i,r=0,s=e.length;if(3>s)return null;for(t=0;s>t;t++)if(o=(t+1)%s,n=(t+2)%s,i=(e[o].x-e[t].x)*(e[n].y-e[o].y),i-=(e[o].y-e[t].y)*(e[n].x-e[o].x),0>i?r|=1:i>0&&(r|=2),3===r)return!1;return 0!==r?!0:null},n.hull=function(e){var t,o,n=[],r=[];for(e=e.slice(0),e.sort(function(e,t){var o=e.x-t.x;return 0!==o?o:e.y-t.y}),o=0;o=2&&i.cross3(r[r.length-2],r[r.length-1],t)<=0;)r.pop();r.push(t)}for(o=e.length-1;o>=0;o--){for(t=e[o];n.length>=2&&i.cross3(n[n.length-2],n[n.length-1],t)<=0;)n.pop();n.push(t)}return n.pop(),r.pop(),n.concat(r)}}()},{"../core/Common":14,"../geometry/Vector":26}],28:[function(e,t,o){var n=t.exports={};n.version="master",n.Body=e("../body/Body"),n.Composite=e("../body/Composite"),n.World=e("../body/World"),n.Contact=e("../collision/Contact"),n.Detector=e("../collision/Detector"), n.Grid=e("../collision/Grid"),n.Pairs=e("../collision/Pairs"),n.Pair=e("../collision/Pair"),n.Query=e("../collision/Query"),n.Resolver=e("../collision/Resolver"),n.SAT=e("../collision/SAT"),n.Constraint=e("../constraint/Constraint"),n.MouseConstraint=e("../constraint/MouseConstraint"),n.Common=e("../core/Common"),n.Engine=e("../core/Engine"),n.Events=e("../core/Events"),n.Mouse=e("../core/Mouse"),n.Runner=e("../core/Runner"),n.Sleeping=e("../core/Sleeping"),n.Bodies=e("../factory/Bodies"),n.Composites=e("../factory/Composites"),n.Axes=e("../geometry/Axes"),n.Bounds=e("../geometry/Bounds"),n.Svg=e("../geometry/Svg"),n.Vector=e("../geometry/Vector"),n.Vertices=e("../geometry/Vertices"),n.Render=e("../render/Render"),n.RenderPixi=e("../render/RenderPixi"),n.World.add=n.Composite.add,n.World.remove=n.Composite.remove,n.World.addComposite=n.Composite.addComposite,n.World.addBody=n.Composite.addBody,n.World.addConstraint=n.Composite.addConstraint,n.World.clear=n.Composite.clear,n.Engine.run=n.Runner.run; },{"../body/Body":1,"../body/Composite":2,"../body/World":3,"../collision/Contact":4,"../collision/Detector":5,"../collision/Grid":6,"../collision/Pair":7,"../collision/Pairs":8,"../collision/Query":9,"../collision/Resolver":10,"../collision/SAT":11,"../constraint/Constraint":12,"../constraint/MouseConstraint":13,"../core/Common":14,"../core/Engine":15,"../core/Events":16,"../core/Metrics":17,"../core/Mouse":18,"../core/Runner":19,"../core/Sleeping":20,"../factory/Bodies":21,"../factory/Composites":22,"../geometry/Axes":23,"../geometry/Bounds":24,"../geometry/Svg":25,"../geometry/Vector":26,"../geometry/Vertices":27,"../render/Render":29,"../render/RenderPixi":30}],29:[function(e,t,o){var n={};t.exports=n;var i=e("../core/Common"),r=e("../body/Composite"),s=e("../geometry/Bounds"),a=e("../core/Events"),l=e("../collision/Grid"),c=e("../geometry/Vector");!function(){n.create=function(t){var o={controller:n,element:null,canvas:null,mouse:null,options:{width:800,height:600,pixelRatio:1,background:"#fafafa", -wireframeBackground:"#222",hasBounds:!1,enabled:!0,wireframes:!0,showSleeping:!0,showDebug:!1,showBroadphase:!1,showBounds:!1,showVelocity:!1,showCollisions:!1,showSeparations:!1,showAxes:!1,showPositions:!1,showAngleIndicator:!1,showIds:!1,showShadows:!1,showVertexNumbers:!1,showConvexHulls:!1,showInternalEdges:!1,showMousePosition:!1}},r=i.extend(o,t);return r.canvas=r.canvas||e(r.options.width,r.options.height),r.context=r.canvas.getContext("2d"),r.textures={},r.bounds=r.bounds||{min:{x:0,y:0},max:{x:r.options.width,y:r.options.height}},1!==r.options.pixelRatio&&n.setPixelRatio(r,r.options.pixelRatio),i.isElement(r.element)?r.element.appendChild(r.canvas):i.log("Render.create: options.element was undefined, render.canvas was created but not appended","warn"),r},n.setPixelRatio=function(e,o){var n=e.options,i=e.canvas;"auto"===o&&(o=t(i)),n.pixelRatio=o,i.setAttribute("data-pixel-ratio",o),i.width=n.width*o,i.height=n.height*o,i.style.width=n.width+"px",i.style.height=n.height+"px",e.context.scale(o,o); -},n.world=function(e){var t,o=e.render,i=e.world,u=o.canvas,p=o.context,v=o.options,f=r.allBodies(i),y=r.allConstraints(i),m=v.wireframes?v.wireframeBackground:v.background,g=[],x=[],h={timestamp:e.timing.timestamp};if(a.trigger(o,"beforeRender",h),o.currentBackground!==m&&d(o,m),p.globalCompositeOperation="source-in",p.fillStyle="transparent",p.fillRect(0,0,u.width,u.height),p.globalCompositeOperation="source-over",v.hasBounds){var b=o.bounds.max.x-o.bounds.min.x,S=o.bounds.max.y-o.bounds.min.y,w=b/v.width,C=S/v.height;for(t=0;t=500){var c="";s.timing&&(c+="fps: "+Math.round(s.timing.fps)+l),i.debugString=c,i.debugTimestamp=e.timing.timestamp}if(i.debugString){o.font="12px Arial",a.wireframes?o.fillStyle="rgba(255,255,255,0.5)":o.fillStyle="rgba(0,0,0,0.5)";for(var d=i.debugString.split("\n"),u=0;u1?1:0;l1?1:0;a1?1:0;r1?1:0;c1?1:0;r1?1:0;r1?1:0;i0)){var u=n.activeContacts[0].vertex.x,p=n.activeContacts[0].vertex.y;2===n.activeContacts.length&&(u=(n.activeContacts[0].vertex.x+n.activeContacts[1].vertex.x)/2,p=(n.activeContacts[0].vertex.y+n.activeContacts[1].vertex.y)/2),i.bodyB===i.supports[0].body||i.bodyA.isStatic===!0?a.moveTo(u-8*i.normal.x,p-8*i.normal.y):a.moveTo(u+8*i.normal.x,p+8*i.normal.y),a.lineTo(u,p)}l.wireframes?a.strokeStyle="rgba(255,165,0,0.7)":a.strokeStyle="orange",a.lineWidth=1,a.stroke()},n.separations=function(e,t,o){var n,i,r,s,a,l=o,c=e.render.options;for(l.beginPath(),a=0;a1?1:0;p=500){var c="";s.timing&&(c+="fps: "+Math.round(s.timing.fps)+l),i.debugString=c,i.debugTimestamp=e.timing.timestamp}if(i.debugString){ +o.font="12px Arial",a.wireframes?o.fillStyle="rgba(255,255,255,0.5)":o.fillStyle="rgba(0,0,0,0.5)";for(var d=i.debugString.split("\n"),u=0;u1?1:0;l1?1:0;a1?1:0;r1?1:0;c1?1:0;r1?1:0;r1?1:0;i0)){var u=n.activeContacts[0].vertex.x,p=n.activeContacts[0].vertex.y;2===n.activeContacts.length&&(u=(n.activeContacts[0].vertex.x+n.activeContacts[1].vertex.x)/2,p=(n.activeContacts[0].vertex.y+n.activeContacts[1].vertex.y)/2),i.bodyB===i.supports[0].body||i.bodyA.isStatic===!0?a.moveTo(u-8*i.normal.x,p-8*i.normal.y):a.moveTo(u+8*i.normal.x,p+8*i.normal.y),a.lineTo(u,p)}l.wireframes?a.strokeStyle="rgba(255,165,0,0.7)":a.strokeStyle="orange",a.lineWidth=1,a.stroke()},n.separations=function(e,t,o){var n,i,r,s,a,l=o,c=e.render.options;for(l.beginPath(),a=0;a1?1:0;p