/*
Impulse.js
http://www.impulsejs.com
Copyright 2012-2013 by Dustin Brown (dustin.brown@dubrowgn.com)
Licensed under GPLv2 (http://www.gnu.org/licenses/gpl-2.0.html)
*/
'use strict';var Impulse={Audio:{},Entity:function(){var e=Impulse.Util.EventDelegate,b=Impulse.Util.EventedCollection,a=Impulse.Shape2D.Matrix,f=Impulse.Model2D.ModelState,d=Impulse.Shape2D.Vector,c=function(c,l,n,d,h){this.children=new b;this._collidable=n;this.flags=void 0===h?0:h;this._matrix=new a(1,0,0,1,l.x,l.y);this.modelState=new f(c);this.moved=new e;this.parent=d;this.rotated=new e};c.prototype.children=void 0;c.prototype.flags=0;c.prototype._animation=void 0;c.prototype._animationPaused=
void 0;c.prototype._animationTime=void 0;c.prototype._collidable=void 0;c.prototype.modelState=void 0;c.prototype.moved=void 0;c.prototype._matrix=void 0;c.prototype.parent=void 0;c.prototype.rotated=void 0;c.prototype._scale=1;c.prototype.face=function(a){a instanceof c&&(a=a.getPosition());a=this.getPosition().angleTo(a)-this._matrix.getRotation();this._matrix.preRotate(a);this.rotated.dispatch(this,a)};c.prototype.getCollidable=function(){return this._collidable.clone().applyTransform(this._matrix)};
c.prototype.getAnimationState=function(a){a=this.modelState.getAnimationState(a);a.matrix.combine(this.getMatrix());return a};c.prototype.getMatrix=function(){return void 0!==this.parent?this.parent.getMatrix().clone().combine(this._matrix):this._matrix};c.prototype.getPosition=function(){return new d(this._matrix.e,this._matrix.f)};c.prototype.getRotation=function(){return this._matrix.getRotation()};c.prototype.MoveForward=function(a){a={dx:this._matrix.d/this._scale*a,dy:this._matrix.b/this._scale*
a};this._matrix.e+=a.dx;this._matrix.f+=a.dy;this.moved.dispatch(this,a)};c.prototype.rotate=function(a){this._matrix.preRotate(a);this.rotated.dispatch(this,a)};c.prototype.setPosition=function(a,b){a instanceof c&&(a=a.getPosition());var f;f=a instanceof d?{dx:a.x-this._matrix.e,dy:a.y-this._matrix.f}:{dx:a-this._matrix.e,dy:b-this._matrix.f};this._matrix.e+=f.dx;this._matrix.f+=f.dy;this.moved.dispatch(this,f)};c.prototype.setRotation=function(a){a-=this._matrix.getRotation();this._matrix.preRotate(a);
this.rotated.dispatch(this,a)};c.prototype.SetScale=function(a){this._matrix.preScale(a/this._scale);this._scale=a};c.prototype.StrafeRight=function(a){a={dx:this._matrix.b/this._scale*a,dy:this._matrix.d/this._scale*a};this._matrix.e-=a.dx;this._matrix.f+=a.dy;this.moved.dispatch(this,a)};c.prototype.translate=function(a,c){a instanceof d?(this._matrix.e+=a.x,this._matrix.f+=a.y,this.moved.dispatch(this,{dx:a.x,dy:a.y})):(this._matrix.e+=a,this._matrix.f+=c,this.moved.dispatch(this,{dx:a,dy:c}))};
c.prototype.translateLocal=function(a,c){var b=this._matrix.b/this._scale,f=this._matrix.d/this._scale,b=a instanceof d?{dx:f*a.y-b*a.x,dy:b*a.y+f*a.x}:{dx:f*c-b*a,dy:b*c+f*a};this._matrix.e+=b.dx;this._matrix.f+=b.dy;this.moved.dispatch(this,b)};return c},Input:function(){var e={},b=Impulse.Util.EventDelegate,a=Impulse.Shape2D.Vector;e.MouseAdapter=function(){var f=e.MouseButtons,d=e.MouseState,c=function(a){this._buttons=new f;this._camera=a;this.click=new b;this.doubleClick=new b;this.down=new b;
this.move=new b;this.up=new b;this.wheel=new b;var c=this;this._onClick=function(a){a=c._normalizeMouseEvent(a);c._buttons.left=c._buttons.left&&!a.buttons.left;c._buttons.middle=c._buttons.middle&&!a.buttons.middle;c._buttons.right=c._buttons.right&&!a.buttons.right;c.click.dispatch(a)};this._onDoubleClick=function(a){a=c._normalizeMouseEvent(a);c._buttons.left=c._buttons.left&&!a.buttons.left;c._buttons.middle=c._buttons.middle&&!a.buttons.middle;c._buttons.right=c._buttons.right&&!a.buttons.right;
c.doubleClick.dispatch(a)};this._onDown=function(a){a.preventDefault();a=c._normalizeMouseEvent(a);c._buttons.left=c._buttons.left||a.buttons.left;c._buttons.middle=c._buttons.middle||a.buttons.middle;c._buttons.right=c._buttons.right||a.buttons.right;c.down.dispatch(a)};this._onMove=function(a){c._updateRawPosition(a);a=c._normalizeMouseEvent(a);c._position=a.position.clone();c.move.dispatch(a)};this._onUp=function(a){a=c._normalizeMouseEvent(a);c._buttons.left=c._buttons.left&&!a.buttons.left;c._buttons.middle=
c._buttons.middle&&!a.buttons.middle;c._buttons.right=c._buttons.right&&!a.buttons.right;c.up.dispatch(a)};this._onWheel=function(a){c.wheel.dispatch(c._normalizeMouseEvent(a))};this._onCameraEvent=function(){void 0!==c._rawPosition&&(c._position=c._camera.canvasToWorld(c._rawPosition))};a.moved.add(this._onCameraEvent);a.rotated.add(this._onCameraEvent);a.zoomed.add(this._onCameraEvent);a=this._camera.getCanvas();a.addEventListener("click",this._onClick,!1);a.addEventListener("contextmenu",this._onContextMenu,
!1);a.addEventListener("dblclick",this._onDoubleClick,!1);a.addEventListener("mousedown",this._onDown,!1);a.addEventListener("mousemove",this._onMove,!1);a.addEventListener("mouseup",this._onUp,!1);a.addEventListener("mousewheel",this._onWheel,!1);a.addEventListener("DOMMouseScroll",this._onWheel,!1)};c.prototype._camera=void 0;c.prototype._buttons=void 0;c.prototype.click=void 0;c.prototype.doubleClick=void 0;c.prototype.down=void 0;c.prototype.move=void 0;c.prototype._onCameraEvent=void 0;c.prototype._onClick=
void 0;c.prototype._onDoubleClick=void 0;c.prototype._onDown=void 0;c.prototype._onMove=void 0;c.prototype._onUp=void 0;c.prototype._onWheel=void 0;c.prototype._position=void 0;c.prototype._rawPosition=void 0;c.prototype.up=void 0;c.prototype.wheel=void 0;c.prototype.destroy=function(){var a=this._camera.getCanvas();a.removeEventListener("click",this._onClick,!1);a.removeEventListener("contextmenu",this._onContextMenu,!1);a.removeEventListener("dblclick",this._onDoubleClick,!1);a.removeEventListener("mousedown",
this._onDown,!1);a.removeEventListener("mousemove",this._onMove,!1);a.removeEventListener("mouseup",this._onUp,!1);a.removeEventListener("mousewheel",this._onWheel,!1);a.removeEventListener("DOMMouseScroll",this._onWheel,!1);camera.moved.remove(this._onCameraEvent);camera.rotated.remove(this._onCameraEvent);camera.zoomed.remove(this._onCameraEvent)};c.prototype.getButtons=function(){return this._buttons};c.prototype.getPosition=function(){return this._position};c.prototype._normalizeMouseEvent=function(a){return new d(this._camera.canvasToWorld(void 0!==
a.offsetX?a.offsetX:a.pageX-a.currentTarget.offsetLeft,void 0!==a.offsetY?a.offsetY:a.pageY-a.currentTarget.offsetTop),new f(1===a.which,2===a.which,3===a.which),void 0!==a.wheelDelta?a.wheelDelta/40:void 0!==a.detail?-a.detail:0)};c.prototype._onContextMenu=function(a){a.preventDefault()};c.prototype._updateRawPosition=function(c){this._rawPosition=new a(void 0!==c.offsetX?c.offsetX:c.pageX-c.currentTarget.offsetLeft,void 0!==c.offsetY?c.offsetY:c.pageY-c.currentTarget.offsetTop)};return c};e.MouseButtons=
function(){var a=function(a,c,b){this.left=void 0===a?!1:a;this.middle=void 0===c?!1:c;this.right=void 0===b?!1:b};a.prototype.left=!1;a.prototype.middle=!1;a.prototype.right=!1;return a};e.MouseState=function(){var a=e.MouseButtons,b=Impulse.Shape2D.Vector,c=function(c,l,n){this.buttons=void 0===l?new a:l;this.position=void 0===c?new b:c;this.wheel=void 0===n?0:n};c.prototype.buttons=void 0;c.prototype.position=void 0;c.prototype.wheel=0;return c};e.MouseButtons=e.MouseButtons();e.MouseState=e.MouseState();
e.MouseAdapter=e.MouseAdapter();return e},Model2D:function(){var e={},b=Impulse.Shape2D.Matrix,a=Impulse.Shape2D.Rect;e.Animation=function(){var f=function(a,c,f,l){this._firstFrameRect=a;this._numberOfFrames=c;this._frameDuration=f/c;this.matrix=(void 0===l?new b:l).preScale(1,-1)};f.prototype._firstFrameRect=void 0;f.prototype._frameDuration=void 0;f.prototype._numberOfFrames=void 0;f.prototype.matrix=void 0;f.prototype.getFrameRect=function(b){return new a(this._firstFrameRect.x+this._firstFrameRect.w*
((b/this._frameDuration|0)%this._numberOfFrames),this._firstFrameRect.y,this._firstFrameRect.w,this._firstFrameRect.h)};return f};e.AnimationState=function(){var a=function(a,c,b){this.frameRect=a;this.image=c;this.matrix=b};a.prototype.frameRect=void 0;a.prototype.image=void 0;a.prototype.matrix=void 0;return a};e.Model=function(){var a=function(a){this.animations=[];this.image=a};a.prototype.animations=void 0;a.prototype.image=void 0;return a};e.ModelState=function(){var a=e.AnimationState,b=function(a){this._model=
a};b.prototype._model=void 0;b.prototype._animation=void 0;b.prototype._animationPaused=!1;b.prototype._animationTime=0;b.prototype.getAnimationState=function(c){if(void 0!==this._animation)return this._animationTime+=this._animationPaused?0:c-this._animationTime,new a(this._animation.getFrameRect(this._animationTime),this._model.image,this._animation.matrix.clone())};b.prototype.playAnimation=function(a){this._animation=this._model.animations[a];this._animationTime=0};b.prototype.pauseAnimation=
function(){this._animationPaused=!0};b.prototype.resumeAnimation=function(){this._animationPaused=!1};b.prototype.stopAnimation=function(){this._animationPaused=!0;this._animationTime=0};b.prototype.isAnimationPaused=function(){return this._animationPaused};b.prototype.isAnimationStopped=function(){return this._animationPaused&&0==this._animationTime};b.prototype.playSound=function(){throw"not implemented";};b.prototype.pauseSound=function(){throw"not implemented";};b.prototype.pauseSounds=function(){throw"not implemented";
};b.prototype.resumeSound=function(){throw"not implemented";};b.prototype.resumeSounds=function(){throw"not implemented";};b.prototype.stopSound=function(){throw"not implemented";};b.prototype.stopSounds=function(){throw"not implemented";};b.prototype.isSoundPaused=function(){throw"not implemented";};b.prototype.isSoundStopped=function(){throw"not implemented";};b.prototype.areSoundsPaused=function(){throw"not implemented";};b.prototype.areSoundsStopped=function(){throw"not implemented";};return b};
e.Animation=e.Animation();e.AnimationState=e.AnimationState();e.Model=e.Model();e.ModelState=e.ModelState();return e},Networking:function(){var e={Types:{Array:0,Binary:1,Float32:2,Float64:3,Int8:4,Int16:5,Int32:6,String:7,Uint8:8,Uint16:9,Uint32:10}},b=function(a){this._dv="number"===typeof a?new DataView(new ArrayBuffer(a)):new DataView(a)};b.prototype._dv=void 0;b.prototype._offset=0;b.prototype.seek=function(a){this._offset=void 0===a?0:a;return this};b.prototype.position=function(){return this._offset};
b.prototype.length=function(){return this._dv.buffer.byteLength};b.prototype.buffer=function(){return this._dv.buffer};b.prototype.get=function(a){a.call(this)};b.prototype.getInt8=function(){++this._offset;return this._dv.getInt8(this._offset-1)};b.prototype.getUint8=function(){++this._offset;return this._dv.getUint8(this._offset-1)};b.prototype.getInt16=function(){this._offset+=2;return this._dv.getInt16(this._offset-2)};b.prototype.getUint16=function(){this._offset+=2;return this._dv.getUint16(this._offset-
2)};b.prototype.getInt32=function(){this._offset+=4;return this._dv.getInt32(this._offset-4)};b.prototype.getUint32=function(){this._offset+=4;return this._dv.getUint32(this._offset-4)};b.prototype.getFloat32=function(){this._offset+=4;return this._dv.getFloat32(this._offset-4)};b.prototype.getFloat64=function(){this._offset+=8;return this._dv.getFloat64(this._offset-8)};b.prototype.getString=function(){var a=this._dv.getUint32(this._offset);this._offset+=4;for(var b="",d=0;d/g,">");a=a.replace(/"/g,""");a=a.replace(/'/g,"'");return a=a.replace(/\//g,"/")}};return e},Scene2D:function(){var e={},b=Impulse.Entity,a=Impulse.Util.EventDelegate,f=Impulse.Shape2D.Intersect,
d=Impulse.Shape2D.Matrix,c=Impulse.Input.MouseAdapter,q=Impulse.Shape2D.Polygon,l=Impulse.Shape2D.Vector;e.Camera=function(){var c=function(c,b,f,q,l,n){this._cameraMatrix=new d(1,0,0,1,-b,-f);this._canvas=c;this.moved=new a;this.rotated=new a;this._targetH=l;this._targetW=q;this.viewportMargin=void 0===n?0:n;this.zoomed=new a;var e=this;this._resizeHandler=function(){e._updateCanvasValues()};window.addEventListener("resize",this._resizeHandler,!1);this._updateCanvasValues()};c.prototype._cameraMatrix=
void 0;c.prototype._canvas=void 0;c.prototype._canvasMatrix=void 0;c.prototype._h=void 0;c.prototype.moved=void 0;c.prototype._resizeHandler=void 0;c.prototype.rotated=void 0;c.prototype._targetH=0;c.prototype._targetW=0;c.prototype.viewportMargin=0;c.prototype._w=void 0;c.prototype.zoomed=void 0;c.prototype.canvasToWorld=function(a,c){a="number"===typeof a?new l(a,c):a.clone();return a.applyTransform(this.getRenderMatrix().invert())};c.prototype.destroy=function(){window.removeEventListener("resize",
this._resizeHandler,!1)};c.prototype.getCanvas=function(){return this._canvas};c.prototype.getMatrix=function(){return this._cameraMatrix};c.prototype.getPosition=function(){return new l(-this._cameraMatrix.e,-this._cameraMatrix.e)};c.prototype.getRenderMatrix=function(){return this._cameraMatrix.clone().combine(this._canvasMatrix)};c.prototype.getViewport=function(a){var c=this._h/2+(!0===a?this.viewportMargin:0);a=this._w/2+(!0===a?this.viewportMargin:0);return(new q([new l(-a,c),new l(a,c),new l(a,
-c),new l(-a,-c)])).applyTransform(this._cameraMatrix.clone().invert())};c.prototype.rotate=function(a){this._cameraMatrix.rotate(a)};c.prototype.setPosition=function(a,c){a instanceof b&&(a=a.getPosition());a instanceof l?(this._cameraMatrix.e=-a.x,this._cameraMatrix.f=-a.y):(this._cameraMatrix.e=-a,this._cameraMatrix.f=-c);this.moved.dispatch(this)};c.prototype.setRotation=function(a){this._cameraMatrix.rotate(a-this._cameraMatrix.getRotation());this.rotated.dispatch(this)};c.prototype.setZoom=
function(a){this._cameraMatrix.preScale(a/this._cameraMatrix.getScale());this.zoomed.dispatch(this)};c.prototype.translate=function(a,c){a instanceof l?this._cameraMatrix.preTranslate(-a.x,-a.y):this._cameraMatrix.preTranslate(-a,-c);this.moved.dispatch(this)};c.prototype._updateCanvasValues=function(){var a=Math.min(this._canvas.width/this._targetW,this._canvas.height/this._targetH);this._h=this._canvas.height/a;this._w=this._canvas.width/a;this._canvasMatrix=new d(a,0,0,-a,this._canvas.width/2,
this._canvas.height/2);this.zoomed.dispatch(this)};c.prototype.worldToCanvas=function(a,c){a="number"===typeof a?new l(a,c):a.clone();return a.applyTransform(this.getRenderMatrix())};c.prototype.zoom=function(a){this._cameraMatrix.preScale(a);this.zoomed(this)};return c};e.ISceneGraph=function(){var a=function(){};a.prototype.addEntity=function(){throw"Not implemented!";};a.prototype.clear=function(){throw"Not implemented!";};a.prototype.getMtv=function(){throw"Not implemented!";};a.prototype.query=
function(){throw"Not implemented!";};a.prototype.queryCenterIn=function(){throw"Not implemented!";};a.prototype.queryContainedIn=function(){throw"Not implemented!";};a.prototype.queryIntersectWith=function(){throw"Not implemented!";};a.prototype.queryOutsideOf=function(){throw"Not implemented!";};a.prototype.removeEntity=function(){throw"Not implemented!";};return a};e.LinearSG=function(){var a=Impulse.Shape2D.Vector,c=function(){this._entities=[]};c.prototype=new e.ISceneGraph;c.prototype._entities=
void 0;c.prototype.addEntity=function(a){this._entities.push(a)};c.prototype.clear=function(){this._entities=[]};c.prototype.getMtv=function(c,q,l){var d=void 0;c instanceof b&&(d=c,c=c.getCollidable());void 0===q&&(q=0);void 0===l&&(l=!0);for(var e,g=new a(0,0),r=0;r=e))return f.scale((e-d)/d),f},_circleVsEdges:function(a,f){var d,e,g,h,j,k,p,m,t,r,s=Number.MAX_VALUE;k=0;for(d=f.length-1;kj)return;p=Math.min(h,j)-Math.max(e,g);e>g&&hj?(t=Math.abs(e-g),r=Math.abs(h-j),
tg&&d.negate();pj))return p=Math.min(h,j)-Math.max(e,g),e>g&&hj?(t=Math.abs(e-g),r=Math.abs(h-j),tg&&d.negate(),pj)return!1}n=a.getCenter().distanceSq(f[0]);
h=f[0];for(k=1;kj?!1:!0},circleVsPolygonSat:function(a,b){return!d.circleVsCircle(a,b.getBoundingCircle())?void 0:d._circleVsEdges(a,b.getVertices())},circleVsRect:function(a,b){var f=b.x-a.x,d=b.y-a.y,e=f+b.w,h=d-b.h;return 0>e?0>d?e*e+
d*dd?f*f+d*dd?Math.abs(d)=a.r))return d.scale((a.r-e)/e),d},_edgesVsEdges:function(a,f){var d,e,g,h,j,k,
p,m,t,r,s=Number.MAX_VALUE;p=0;for(d=a.length-1;pj)return;k=Math.min(h,j)-Math.max(e,g);e>g&&hj?(m=Math.abs(e-g),r=Math.abs(h-j),mg&&d.negate()):(k+=r,h>j&&d.negate())):ej)return;k=Math.min(h,j)-Math.max(e,g);e>g&&hj?(m=Math.abs(e-g),r=Math.abs(h-j),mg&&d.negate()):(k+=r,h>j&&d.negate())):eb.y!=e[h].y>b.y&&b.x<(e[h].x-e[g].x)*(b.y-e[g].y)/(e[h].y-e[g].y)+e[g].x&&(f=!f);return f},polygonVsVectorSat:function(a,b){return!d.circleVsVector(a.getBoundingCircle(),b)?void 0:d._edgesVsEdges(a.getVertices(),[b])},rectVsRect:function(a,b){return a.x<=b.x+b.w&&a.x+a.w>=b.x&&a.y>=b.y-b.h&&a.y-a.h<=b.y},rectVsRectSat:function(a,
b){return!d.rectVsRect(a,b)?void 0:d._edgesVsEdges(a.getVertices(),b.getVertices())},rectVsVector:function(a,b){return b.x>=a.x&&b.x<=a.x+a.w&&b.y<=a.y&&b.y>=a.y-a.h},rectVsVectorSat:function(a,b){return!d.rectVsVector(a,b)?void 0:d._edgesVsEdges(a.getVertices(),[b])},shapeVsShape:function(b,f){return a[b.getShapeID()][f.getShapeID()](b,f)},shapeVsShapeSat:function(a,b){return f[a.getShapeID()][b.getShapeID()](a,b)},vectorVsVector:function(a,b){return a.equals(b)},vectorVsVectorSat:function(a,b){return a.equals(b)?
new e.Vector(0,0):void 0},_verticesVsVertices:function(a,b){var f,d,g,h,j,k,p=0;for(f=a.length-1;ph)return!1}return!0}};a[0]=[];a[0][0]=d.circleVsCircle;a[0][1]=d.circleVsPolygon;a[0][2]=d.circleVsRect;a[0][3]=d.circleVsVector;
a[1]=[];a[1][0]=function(a,b){return d.circleVsPolygon(b,a)};a[1][1]=d.polygonVsPolygon;a[1][2]=d.polygonVsRect;a[1][3]=d.polygonVsVector;a[2]=[];a[2][0]=function(a,b){return d.circleVsRect(b,a)};a[2][1]=function(a,b){return d.polygonVsRect(b,a)};a[2][2]=d.rectVsRect;a[2][3]=d.rectVsVector;a[3]=[];a[3][0]=function(a,b){return d.circleVsVector(b,a)};a[3][1]=function(a,b){return d.polygonVsVector(b,a)};a[3][2]=function(a,b){return d.rectVsVector(b,a)};a[3][3]=d.vectorVsVector;f[0]=[];f[0][0]=d.circleVsCircleSat;
f[0][1]=d.circleVsPolygonSat;f[0][2]=d.circleVsRectSat;f[0][3]=d.circleVsVectorSat;f[1]=[];f[1][0]=function(a,b){var f=d.circleVsPolygonSat(b,a);return void 0===f?void 0:f.negate()};f[1][1]=d.polygonVsPolygonSat;f[1][2]=d.polygonVsRectSat;f[1][3]=d.polygonVsVectorSat;f[2]=[];f[2][0]=function(a,b){var f=d.circleVsRectSat(b,a);return void 0===f?void 0:f.negate()};f[2][1]=function(a,b){var f=d.polygonVsRectSat(b,a);return void 0===f?void 0:f.negate()};f[2][2]=d.rectVsRectSat;f[2][3]=d.rectVsVectorSat;
f[3]=[];f[3][0]=function(a,b){var f=d.circleVsVectorSat(b,a);return void 0===f?void 0:f.negate()};f[3][1]=function(a,b){var f=d.polygonVsVectorSat(b,a);return void 0===f?void 0:f.negate()};f[3][2]=function(a,b){var f=d.rectVsVectorSat(b,a);return void 0===f?void 0:f.negate()};f[3][3]=d.vectorVsVectorSat;return d},IShape:function(){var b=function(){};b.prototype.applyTransform=function(){};b.prototype.clone=function(){};b.prototype.equals=function(){};b.prototype.getCenter=function(){};b.prototype.getShapeID=
function(){};b.prototype.setCenter=function(){};b.prototype.toString=function(){};return b},Matrix:function(){var b=function(a,f,d,c,e,l){if(a instanceof b)this.a=a.a,this.b=a.b,this.c=a.c,this.d=a.d,this.e=a.e,this.f=a.f;else if(6===arguments.length)this.a=a,this.b=f,this.c=d,this.d=c,this.e=e,this.f=l;else if(0a.length)throw"Cannot construct polygon with fewer than 3 vertices!";this._vertices=[];for(var f=0;fb&&(b=d);this._r=Math.sqrt(b)}return this._r};b.prototype.getShapeID=function(){return 1};b.prototype.getVertices=function(){return this._vertices.slice()};b.prototype.setCenter=function(a,b){var d=this.getCenter();a instanceof e.Vector?(d.x=a.x-d.x,d.y=a.y-d.y,this._center=a):(d.x=a-d.x,d.y=b-d.y,this._center=new e.Vector(a,
b));for(var c=0;c,";return a.replace(/,$/,"")+")"};return b},Rect:function(){var b=function(a,f,d,c){a instanceof b?(this.h=a.h,this.w=a.w,this.x=a.x,this.y=a.y):(this.h=c,this.w=d,this.x=a,this.y=f)};b.prototype=new e.IShape;b.prototype.h=1;b.prototype.w=1;b.prototype.x=-0.5;
b.prototype.y=0.5;b.prototype.applyTransform=function(a){var b=this.getCenter();b.applyTransform(a);this.setCenter(b);b=a.getScale();this.h*=b.y;this.w*=b.x;return this};b.prototype.clone=function(){return new b(this)};b.prototype.equals=function(a){return a instanceof b&&this.x==a.x&&this.y==a.y&&this.w==a.w&&this.h==a.h};b.prototype.getCenter=function(){return new e.Vector(this.x+this.w/2,this.y-this.h/2)};b.prototype.getShapeID=function(){return 2};b.prototype.getVertices=function(){return[new e.Vector(this.x,
this.y),new e.Vector(this.x+this.w,this.y),new e.Vector(this.x+this.w,this.y-this.h),new e.Vector(this.x,this.y-this.h)]};b.prototype.setCenter=function(a,b){a instanceof e.Vector?(this.x=a.x-this.w/2,this.y=a.y+this.h/2):(this.x=a-this.w/2,this.y=b+this.h/2);return this};b.prototype.toString=function(){return"Rect("+this.x+", "+this.y+", "+this.w+", "+this.h+")"};return b},Vector:function(){var b=function(a,f){if(a instanceof b)this.x=a.x,this.y=a.y;else if(2===arguments.length)this.x=a,this.y=f;
else if(0=b.x*b.x+b.y*b.y?a:b};b.shortest=function(a,b){return a.x*a.x+a.y*a.y<=b.x*b.x+b.y*b.y?a:b};b.tripleProduct=function(a,e,d){var c=a.dotProduct(d);d=e.dotProduct(d);return new b(e.x*c-a.x*d,e.y*c-a.y*d)};return b}};e.IShape=e.IShape();e.Circle=e.Circle();e.Rect=e.Rect();e.Vector=e.Vector();e.Polygon=e.Polygon();e.Matrix=e.Matrix();e.Intersect=e.Intersect();return e},Util:function(){var e={},b=function(){this._arr=Array.prototype.slice.call(arguments)};b.prototype._arr=void 0;
b.prototype.add=function(a){this._arr.push(a)};b.prototype.at=function(a){return this._arr[a]};b.prototype.clear=function(){this._arr.splice(0,this._arr.length)};b.prototype.contains=function(a){return 0<=this._arr.indexOf(a)};b.prototype.insert=function(a,b){this._arr.splice(a,0,b)};b.prototype.length=function(){return this._arr.length};b.prototype.remove=function(a){a=this._arr.indexOf(a);0<=a&&this._arr.splice(a,1)};b.prototype.removeAt=function(a){this._arr.splice(a,1)};b.prototype.toString=function(){return this._arr.toString()};
e.Collection=b;b=function(){this._handlers=[];this._removeQueue=[]};b.prototype._handlers=void 0;b.prototype._isLocked=!1;b.prototype._removeQueue=void 0;b.prototype.add=function(a){this._handlers.push(a)};b.prototype.dispatch=function(){this._isLocked=!0;for(var a=0;a