Browse files

rest of VerletPhysics2D ported, constraints not tested. Build files s…

…eparated.
  • Loading branch information...
1 parent 40df292 commit cf973a12b60baa6736ff50365dbb001cfdfd5418 @hapticdata hapticdata committed May 14, 2011
View
28 build/toxi-color.js
@@ -0,0 +1,28 @@
+// toxi-color.js r33 - http://github.com/hapticdata/toxiclibsjs
+toxi.color=toxi.color===undefined?{}:toxi.color;toxi.color.TColor=function(a){this.rgb=Array(3);this.hsv=Array(3);this.cmyk=Array(4);this._alpha=1;if(a!==undefined){this.cmyk=a.toCMYKAArray().splice(0,4);this.hsv=a.toHSVAArray().splice(0,3);this.rgb=a.toRGBAArray().splice(0,3);this._alpha=a._alpha}};
+toxi.color.TColor.prototype={add:function(a){return this.copy().addSelf(a)},addSelf:function(a){this.rgb[0]=toxi.MathUtils.min(this.rgb[0]+a.rgb[0],1);this.rgb[1]=toxi.MathUtils.min(this.rgb[1]+a.rgb[1],1);this.rgb[2]=toxi.MathUtils.min(this.rgb[2]+a.rgb[2],1);return this.setRGB(rgb)},adjustConstrast:function(a){return this.hsv[2]<0.5?this.darken(a):this.lighten(a)},adjustHSV:function(a,b,d){return this.setHSV([this.hsv[0]+a,this.hsv[1]+b,this.hsv[2]+d])},adjustRGB:function(a,b,d){return this.setRGB([this.rgb[0]+
+a,this.rgb[1]+b,this.rgb[2]+d])},alpha:function(){return this._alpha},analog:function(a,b){this.rotateRYB(toxi.MathUtils.degrees(a)*toxi.MathUtils.normalizedRandom());this.hsv[1]+=b*toxi.MathUtils.normalizedRandom();this.hsv[2]+=b*toxi.MathUtils.normalizedRandom();return this.setHSV(this.hsv)},black:function(){return this.cmyk[3]},blend:function(a,b){if(b===undefined)b=0.5;var d=a.toRGBAArray();this.rgb[0]+=(d[0]-this.rgb[0])*b;this.rgb[1]+=(d[1]-this.rgb[1])*b;this.rgb[2]+=(d[2]-this.rgb[2])*b;this._alpha+=
+(a.alpha-this._alpha)*b;return this.setRGB(this.rgb)},blue:function(){return this.rgb[2]},brightness:function(){return this.hsv[2]},complement:function(){return this.rotateRYB(180)},copy:function(){return new toxi.color.TColor(this)},cyan:function(){return this.cmyk[0]},darken:function(a){this.hsv[2]=toxi.MathUtils.clip(this.hsv[2]-a,0,1);return this.setHSV(this.hsv)},desaturate:function(a){this.hsv[1]=toxi.MathUtils.clip(this.hsv[1]-a,0,1);return this.setHSV(this.hsv)},differenceTo:function(a){return toxi.color.TColor.newRGB(Math.abs(this.rgb[0]-
+a.rgb[0]),Math.abs(this.rgb[1]-a.rgb[1]),Math.abs(this.rgb[2]-a.rgb[2]))},distanceToCMYK:function(a){var b=a.toCMYKAArray();a=this.cmyk[0]-b[0];var d=this.cmyk[1]-b[1],c=this.cmyk[2]-b[2];b=this.cmyk[3]-b[3];return Math.sqrt(a*a+d*d+c*c+b*b)},distanceToHSV:function(a){var b=this.hsv[0]*toxi.MathUtils.TWO_PI,d=a.hue()*toxi.MathUtils.TWO_PI;b=new toxi.Vec3D(Math.cos(b)*this.hsv[1],Math.sin(b)*this.hsv[1],this.hsv[2]);a=new toxi.Vec3D(Math.cos(d)*a.saturation(),Math.sin(d)*a.saturation(),a.brightness());
+return b.distanceTo(a)},distanceToRGB:function(a){var b=a.toRGBAArray();a=this.rgb[0]-b[0];var d=this.rgb[1]-b[1];b=this.rgb[2]-b[2];return Math.sqrt(a*a+d*d+b*b)},equals:function(a){if(a!==undefined&&a instanceof toxi.color.TColor){var b=a.rgb[0]-rgb[0],d=a.rgb[1]-rgb[1],c=a.rgb[2]-rgb[2];a=a.alpha-alpha;return Math.sqrt(b*b+d*d+c*c+a*a)<toxi.color.TColor.EPS}return false},getAnalog:function(a,b){return(new toxi.color.TColor(this)).analog(a,b)},getBlended:function(a,b){return(new toxi.color.TColor(this)).blend(a,
+b)},getComplement:function(){return(new toxi.color.TColor(this)).complement()},getComponentValue:function(a){return a.getComponentValueFor(this)},getDarkened:function(a){return(new toxi.color.TColor(this)).darken(a)},getDesaturated:function(a){return(new toxi.color.TColor(this)).desaturate(a)},getDifferenceTo:function(a){return this.copy().differenceTo(a)},getInverted:function(){return(new toxi.color.TColor(this)).invert()},getLightened:function(a){return(new toxi.color.TColor(this)).lighten(a)},
+getRotatedRYB:function(a){return(new toxi.color.TColor(this)).rotateRYB(a)},getSaturated:function(a){return(new toxi.color.TColor(this)).saturate(a)},green:function(){return this.rgb[1]},hue:function(){return this.hsv[0]},invert:function(){this.rgb[0]=1-this.rgb[0];this.rgb[1]=1-this.rgb[1];this.rgb[2]=1-this.rgb[2];return this.setRGB(this.rgb)},isBlack:function(){return this.rgb[0]<=toxi.color.TColor.BLACK_POINT&&this.rgb[0]==this.rgb[1]&&this.rgb[0]==this.rgb[2]},isGrey:function(){return this.hsv[1]<
+toxi.color.TColor.GREY_THRESHOLD},isWhite:function(){return this.rgb[0]>=toxi.color.TColor.WHITE_POINT&&this.rgb[0]==this.rgb[1]&&this.rgb[0]==this.rgb[2]},lighten:function(a){this.hsv[2]=toxi.MathUtils.clip(this.hsv[2]+a,0,1);return this.setHSV(this.hsv)},luminance:function(){return this.rgb[0]*0.299+this.rgb[1]*0.587+this.rgb[2]*0.114},magenta:function(){return this.cmyk[1]},red:function(){return this.rgb[0]},rotateRYB:function(a){parseInt(toxi.MathUtils.degrees(a));var b=this.hsv[0]*360;a%=360;
+for(var d=0,c=0;c<toxi.color.TColor.RYB_WHEEL.length-1;c++){var e=toxi.color.TColor.RYB_WHEEL[c],f=toxi.color.TColor.RYB_WHEEL[c+1];if(f.y<e.y)f.y+=360;if(e.y<=b&&b<=f.y){d=e.x+(f.x-e.x)*(b-e.y)/(f.y-e.y);break}}d=(d+a)%360;for(c=0;c<toxi.color.TColor.RYB_WHEEL.length-1;c++){e=toxi.color.TColor.RYB_WHEEL[c];f=toxi.color.TColor.RYB_WHEEL[c+1];if(f.y<e.y)f.y+=360;if(e.x<=d&&d<=f.x){b=e.y+(f.y-e.y)*(d-e.x)/(f.x-e.x);break}}this.hsv[0]=b%360/360;return this.setHSV(hsv)},saturate:function(a){this.hsv[1]=
+toxi.MathUtils.clip(this.hsv[1]+a,0,1);return this.setHSV(this.hsv)},saturation:function(){return this.hsv[1]},setAlpha:function(a){this._alpha=a;return this},setARGB:function(a){this.setRGB((a>>16&255)*toxi.TColor.INV8BIT,(a>>8&255)*toxi.TColor.INV8BIT,(a&255)*toxi.TColor.INV8BIT);this._alpha=(a>>>24)*toxi.TColor.INV8BIT;return this},setBlack:function(a){this.cmyk[3]=a;return this.setCMYK(cmyk)},setBlue:function(a){this.rgb[2]=a;return this.setRGB(this.rgb)},setBrightness:function(a){this.hsv[2]=
+toxi.MathUtils.clip(a,0,1);return this.setHSV(this.hsv)},setCMYK:function(a,b,d,c){if(a instanceof Array){b=a[1];d=a[2];c=a[3];a=a[0]}this.cmyk[0]=a;this.cmyk[1]=b;this.cmyk[2]=d;this.cmyk[3]=c;this.rgb=toxi.color.TColor.cmykToRGB(this.cmyk[0],this.cmyk[1],this.cmyk[2],this.cmyk[3]);this.hsv=toxi.color.TColor.rgbToHSV(this.rgb[0],this.rgb[1],this.rgb[2]);return this},setCyan:function(a){this.cmyk[0]=a;return this.setCMYK(this.cmyk)},setGreen:function(a){this.rgb[1]=a;return this.setRGB(this.rgb)},
+setHSV:function(a,b,d){if(a instanceof Array){b=a[1];d=a[2];a=a[0]}a=[a,b,d];this.hsv[0]=a[0]%1;this.hsv[0]<0&&this.hsv[0]++;this.hsv[1]=toxi.MathUtils.clip(a[1],0,1);this.hsv[2]=toxi.MathUtils.clip(a[2],0,1);this.rgb=toxi.color.TColor.hsvToRGB(this.hsv[0],this.hsv[1],this.hsv[2]);this.cmyk=toxi.color.TColor.rgbToCMYK(this.rgb[0],this.rgb[1],this.rgb[2]);return this},setHue:function(a){a%=1;a<0&&a++;this.hsv[0]=a;this.setHSV(this.hsv)},setMagenta:function(a){this.cmyk[1]=a;return this.setCMYK(this.cmyk)},
+setRed:function(a){this.rgb[0]=a;return this.setRGB(this.rgb)},setRGB:function(a,b,d){if(a instanceof Array){b=a[1];d=a[2];a=a[0]}this.rgb[0]=toxi.MathUtils.clip(a,0,1);this.rgb[1]=toxi.MathUtils.clip(b,0,1);this.rgb[2]=toxi.MathUtils.clip(d,0,1);this.cmyk=toxi.color.TColor.rgbToCMYK(this.rgb[0],this.rgb[1],this.rgb[2]);this.hsv=toxi.color.TColor.rgbToHSV(this.rgb[0],this.rgb[1],this.rgb[2]);return this},setSaturation:function(a){this.hsv[1]=toxi.MathUtils.clip(a,0,1);return this.setHSV(this.hsv)},
+setYellow:function(a){this.cmyk[2]=a;return this.setCMYK(this.cmyk)},sub:function(a){return this.copy().subSelf(a)},subSelf:function(a){this.rgb[0]=toxi.MathUtils.max(this.rgb[0]-a.rgb[0],0);this.rgb[1]=toxi.MathUtils.max(this.rgb[1]-a.rgb[1],0);this.rgb[2]=toxi.MathUtils.max(this.rgb[2]-a.rgb[2],0);return this.setRGB(this.rgb)},toARGB:function(){return parseInt(this.rgb[0]*255)<<16|parseInt(this.rgb[1]*255)<<8|parseInt(this.rgb[2]*255)|parseInt(this._alpha*255)<<24},toCMYKAArray:function(a){if(a===
+undefined)a=[];a[0]=this.cmyk[0];a[1]=this.cmyk[1];a[2]=this.cmyk[2];a[3]=this._alpha;return a},toHex:function(){var a=this.toARGB().toString(16);if(a.length>6)a=a.substring(2);return a},toHSVAArray:function(a){if(a===undefined)a=[];a[0]=this.hsv[0];a[1]=this.hsv[1];a[2]=this.hsv[2];a[3]=this._alpha;return a},toRGBAArray:function(a,b){if(a===undefined){a=[];b=0}a[b++]=this.rgb[0];a[b++]=this.rgb[1];a[b++]=this.rgb[2];a[b]=this._alpha;return a},toString:function(){return"toxi.color.TColor: rgb: "+
+this.rgb[0]+", "+this.rgb[1]+", "+this.rgb[2]+" hsv: "+this.hsv[0]+","+this.hsv[1]+","+this.hsv[2]+" cmyk: "+this.cmyk[0]+", "+this.cmyk[1]+","+this.cmyk[2]+","+this.cmyk[3]+" alpha: "+this._alpha},yellow:function(){return this.cmyk[2]}};toxi.color.TColor.INV60DEGREES=60/360;toxi.color.TColor.INV8BIT=1/255;toxi.color.TColor.EPS=0.0010;toxi.color.TColor.BLACK_POINT=0.08;toxi.color.TColor.WHITE_POINT=1;toxi.color.TColor.GREY_THRESHOLD=0.01;
+toxi.color.TColor.cmykToRGB=function(a,b,d,c,e){if(e===undefined)e=[0,0,0];e[0]=1-Math.min(1,a+c);e[1]=1-Math.min(1,b+c);e[2]=1-Math.min(1,d+c);return e};toxi.color.TColor.hexToRGB=function(a,b){if(b===undefined)b=[];a=a.charAt(0)=="#"?a.substring(1,7):a;b[0]=parseInt(a.substring(0,2),16)*toxi.color.TColor.INV8BIT;b[1]=parseInt(a.substring(2,4),16)*toxi.color.TColor.INV8BIT;b[2]=parseInt(a.substring(4,6),16)*toxi.color.TColor.INV8BIT;return b};
+toxi.color.TColor.hsvToRGB=function(a,b,d,c){if(c===undefined)c=[];if(b==0)c[0]=c[1]=c[2]=d;else{a/=toxi.color.TColor.INV60DEGREES;var e=parseInt(a),f=a-e;a=d*(1-b);var g=d*(1-b*f);b=d*(1-b*(1-f));if(e==0){c[0]=d;c[1]=b;c[2]=a}else if(e==1){c[0]=g;c[1]=d;c[2]=a}else if(e==2){c[0]=a;c[1]=d;c[2]=b}else if(e==3){c[0]=a;c[1]=g;c[2]=d}else if(e==4){c[0]=b;c[1]=a;c[2]=d}else{c[0]=d;c[1]=a;c[2]=g}}return c};
+toxi.color.TColor.labToRGB=function(a,b,d,c){if(c===undefined)c=[];a=(a+16)/116;b=b/500+a;d=a-d/200;c[0]=b;c[1]=a;c[2]=d;for(d=0;d<3;d++){a=Math.pow(c[d],3);c[d]=a>0.008856?a:(c[d]-16/116)/7.787}b=c[0]*0.95047;a=c[1];d=c[2]*1.08883;c[0]=b*3.2406+a*-1.5372+d*-0.4986;c[1]=b*-0.9689+a*1.8758+d*0.0415;c[2]=b*0.0557+a*-0.204+d*1.057;a=1/2.4;for(d=0;d<3;d++)c[d]=c[d]>0.0031308?1.055*Math.pow(c[d],a)-0.055:12.92*c[d];return c};
+toxi.color.TColor.newARGB=function(a){return toxi.color.TColor.newRGBA((a>>16&255)*toxi.color.TColor.INV8BIT,(a>>8&255)*toxi.color.TColor.INV8BIT,(a&255)*toxi.color.TColor.INV8BIT,(a>>>24)*toxi.color.TColor.INV8BIT)};toxi.color.TColor.newCMYK=function(a,b,d,c){return toxi.color.TColor.newCMYKA(a,b,d,c,1)};toxi.color.TColor.newCMYKA=function(a,b,d,c,e){var f=new TColor;f.setCMYK([a,b,d,c]);f.alpha=toxi.MathUtils.clip(e,0,1);return f};
+toxi.color.TColor.newGray=function(a){return toxi.color.TColor.newGrayAlpha(a,1)};toxi.color.TColor.newGrayAlpha=function(a,b){var d=new toxi.color.TColor;d.setRGB([a,a,a]);d.alpha=b;return d};toxi.color.TColor.newHex=function(a){var b=new toxi.color.TColor;b.setRGB(toxi.color.TColor.hexToRGB(a));b.alpha=1;return b};toxi.color.TColor.newHSV=function(a,b,d){return toxi.color.TColor.newHSVA(a,b,d,1)};
+toxi.color.TColor.newHSVA=function(a,b,d,c){var e=new toxi.color.TColor;e.setHSV(a,b,d);e.alpha=toxi.MathUtils.clip(c,0,1);return e};toxi.color.TColor.newRandom=function(){return toxi.color.TColor.newRGBA(Math.random(),Math.random(),Math.random(),1)};toxi.color.TColor.newRGB=function(a,b,d){return toxi.color.TColor.newRGBA(a,b,d,1)};toxi.color.TColor.newRGBA=function(a,b,d,c){var e=new toxi.color.TColor;e.setRGB([a,b,d]);e.alpha=toxi.MathUtils.clip(c,0,1);return e};
+toxi.color.TColor.rgbToCMYK=function(a,b,d,c){if(c===undefined)c=[];c[0]=1-a;c[1]=1-b;c[2]=1-d;c[3]=toxi.MathUtils.min(c[0],c[1],c[2]);c[0]=toxi.MathUtils.clip(c[0]-c[3],0,1);c[1]=toxi.MathUtils.clip(c[1]-c[3],0,1);c[2]=toxi.MathUtils.clip(c[2]-c[3],0,1);c[3]=toxi.MathUtils.clip(c[3],0,1);return c};toxi.color.TColor.rgbToHex=function(a,b,d){return(toxi.MathUtils.clip(a,0,1)*255).toString(16)+(toxi.MathUtils.clip(b,0,1)*255).toString(16)+(toxi.MathUtils.clip(d,0,1)*255).toString(16)};
+toxi.color.TColor.rgbToHSV=function(a,b,d,c){if(c===undefined)c=[];var e=0,f=0,g=toxi.MathUtils.max(a,b,d),h=g-toxi.MathUtils.min(a,b,d);if(g!=0)f=h/g;if(f!=0)e=a==g?(b-d)/h:b==g?2+(d-a)/h:4+(a-b)/h;e*=toxi.color.TColor.INV60DEGREES;if(e<0)e+=1;c[0]=e;c[1]=f;c[2]=g;return c};toxi.color.TColor.RED=toxi.color.TColor.newRGB(1,0,0);
+toxi.color.TColor.RYB_WHEEL=[new toxi.Vec2D(0,0),new toxi.Vec2D(15,8),new toxi.Vec2D(30,17),new toxi.Vec2D(45,26),new toxi.Vec2D(60,34),new toxi.Vec2D(75,41),new toxi.Vec2D(90,48),new toxi.Vec2D(105,54),new toxi.Vec2D(120,60),new toxi.Vec2D(135,81),new toxi.Vec2D(150,103),new toxi.Vec2D(165,123),new toxi.Vec2D(180,138),new toxi.Vec2D(195,155),new toxi.Vec2D(210,171),new toxi.Vec2D(225,187),new toxi.Vec2D(240,204),new toxi.Vec2D(255,219),new toxi.Vec2D(270,234),new toxi.Vec2D(285,251),new toxi.Vec2D(300,
+267),new toxi.Vec2D(315,282),new toxi.Vec2D(330,298),new toxi.Vec2D(345,329),new toxi.Vec2D(360,0)];toxi.color.TColor.GREEN=toxi.color.TColor.newRGB(0,1,0);toxi.color.TColor.BLUE=toxi.color.TColor.newRGB(0,0,1);toxi.color.TColor.CYAN=toxi.color.TColor.newRGB(0,1,1);toxi.color.TColor.MAGENTA=toxi.color.TColor.newRGB(1,0,1);toxi.color.TColor.YELLOW=toxi.color.TColor.newRGB(1,1,0);toxi.color.TColor.BLACK=toxi.color.TColor.newRGB(0,0,0);toxi.color.TColor.WHITE=toxi.color.TColor.newRGB(1,1,1);
View
209 build/toxi-core.js
@@ -0,0 +1,209 @@
+// toxi-core.js r33 - http://github.com/hapticdata/toxiclibsjs
+var toxi=toxi||{};toxi.extend=function(e,g){e.prototype=new g;e.constructor=e;e.prototype.parent=g.prototype};toxi.MathUtils={};toxi.MathUtils.SQRT2=Math.sqrt(2);toxi.MathUtils.SQRT3=Math.sqrt(3);toxi.MathUtils.LOG2=Math.log(2);toxi.MathUtils.PI=3.141592653589793;toxi.MathUtils.INV_PI=1/toxi.MathUtils.PI;toxi.MathUtils.HALF_PI=toxi.MathUtils.PI/2;toxi.MathUtils.THIRD_PI=toxi.MathUtils.PI/3;toxi.MathUtils.QUARTER_PI=toxi.MathUtils.PI/4;toxi.MathUtils.TWO_PI=toxi.MathUtils.PI*2;
+toxi.MathUtils.THREE_HALVES_PI=toxi.MathUtils.TWO_PI-toxi.MathUtils.HALF_PI;toxi.MathUtils.PI_SQUARED=toxi.MathUtils.PI*toxi.MathUtils.PI;toxi.MathUtils.EPS=1.1920928955078125E-7;toxi.MathUtils.DEG2RAD=toxi.MathUtils.PI/180;toxi.MathUtils.RAD2DEG=180/toxi.MathUtils.PI;toxi.MathUtils.SHIFT23=8388608;toxi.MathUtils.INV_SHIFT23=1/toxi.MathUtils.SHIFT23;toxi.MathUtils.SIN_A=-4/(toxi.MathUtils.PI*toxi.MathUtils.PI);toxi.MathUtils.SIN_B=4/toxi.MathUtils.PI;toxi.MathUtils.SIN_P=0.225;
+toxi.MathUtils.abs=Math.abs;toxi.MathUtils.ceilPowerOf2=function(e){for(var g=1;g<e;)g<<=1;return g};toxi.MathUtils.clip=function(e,g,h){return e<g?g:e>h?h:e};toxi.MathUtils.clipNormalized=function(e){if(e<0)return 0;else if(e>1)return 1;return e};toxi.MathUtils.cos=Math.cos;toxi.MathUtils.fastCos=function(e){return toxi.MathUtils.fastSin(e+(e>toxi.MathUtils.HALF_PI?-toxi.MathUtils.THREE_HALVES_PI:toxi.MathUtils.HALF_PI))};
+toxi.MathUtils.fastSin=function(e){e=toxi.MathUtils.SIN_B*e+toxi.MathUtils.SIN_A*e*Math.abs(e);return toxi.MathUtils.SIN_P*(e*Math.abs(e)-e)+e};toxi.MathUtils.flipCoin=function(){return Math.random()<0.5};toxi.MathUtils.floor=function(e){var g=parseInt(e);e<0&&e!=g&&g--;return g};toxi.MathUtils.floorPowerOf2=function(e){return parseInt(Math.pow(2,parseInt(Math.log(e)/toxi.MathUtils.LOG2)))};toxi.MathUtils.max=function(e,g,h){if(!h)return Math.max(e,g);return e>g?e>h?e:h:g>h?g:h};
+toxi.MathUtils.min=function(e,g,h){if(!h)return Math.min(e,g);return e<g?e<h?e:h:g<h?g:h};toxi.MathUtils.normalizedRandom=function(){return Math.random()*2-1};toxi.MathUtils.radians=function(e){return e*toxi.MathUtils.DEG2RAD};toxi.MathUtils.random=function(e,g){if(!e&&!g)return Math.random();else if(!g){g=e;return Math.random()*g}return Math.random()*(g-e)+e};
+toxi.MathUtils.reduceAngle=function(e){e%=toxi.MathUtils.TWO_PI;if(Math.abs(e)>toxi.MathUtils.PI)e-=toxi.MathUtils.TWO_PI;if(Math.abs(e)>toxi.MathUtils.HALF_PI)e=toxi.MathUtils.PI-e;return e};toxi.MathUtils.sign=function(e){return e<0?-1:e>0?1:0};toxi.MathUtils.sin=function(e){e=toxi.MathUtils.reduceAngle(e);if(Math.abs(e)<=toxi.MathUtils.QUARTER_PI)return toxi.MathUtils.fastSin(e);return toxi.MathUtils.fastCos(toxi.MathUtils.HALF_PI-e)};toxi.BezierInterpolation=function(e,g){this.c1=e;this.c2=g};
+toxi.BezierInterpolation.prototype={interpolate:function(e,g,h){var i=h*h,j=1-h,k=j*j;return e*k*j+3*(this.c1*(g-e)+e)*h*k+3*(this.c2*(g-e)+g)*i*j+g*i*h},setCoefficients:function(e,g){this.c1=e;this.c2=g}};toxi.CircularInterpolation=function(){};toxi.CircularInterpolation.prototype={interpolate:function(e,g,h){if(this.isFlipped)return e-(g-e)*(Math.sqrt(1-h*h)-1);else{h=1-h;return e+(g-e)*Math.sqrt(1-h*h)}},setFlipped:function(e){this.isFlipped=e}};toxi.CosineInterpolation=function(){};
+toxi.CosineInterpolation.prototype={interpolate:function(e,g,h){return g+(e-g)*(0.5+0.5*Math.cos(h*Math.PI))}};toxi.DecimatedInterpolation=function(e,g){if(e===undefined)throw Error("steps was not passed to constructor");this.numSteps=e;this.strategy=g==undefined?new LinearInterpolation:g};toxi.DecimatedInterpolation.prototype={interpolate:function(e,g,h){return this.strategy.interpolate(e,g,Math.floor(h*this.numSteps)/this.numSteps)}};
+toxi.ExponentialInterpolation=function(e){this.exponent=e===undefined?2:e};toxi.ExponentialInterpolation.prototype={interpolate:function(e,g,h){return e+(g-e)*Math.pow(h,this.exponent)}};toxi.Interpolation2D={};toxi.Interpolation2D.bilinear=function(e,g,h,i,j,k,n,m,o,r){var s,u,A;if(e instanceof Vec2D){s=e.x;e=e.y;u=g.x;g=g.y;A=h.x;h=h.y;i=i;j=j;k=k;n=n}else{s=e;e=g;u=h;g=i;A=j;h=k;i=n;j=m;k=o;n=r}r=1/((A-u)*(h-g));u=(s-u)*r;s=(A-s)*r;g=e-g;e=h-e;return i*s*e+j*u*e+k*s*g+n*u*g};
+toxi.LinearInterpolation=function(){};toxi.LinearInterpolation.prototype={interpolate:function(e,g,h){return e+(g-e)*h}};toxi.SigmoidInterpolation=function(e){if(e===undefined)e=2;this.setSharpness(e)};toxi.SigmoidInterpolation.prototype={getSharpness:function(){return this.sharpness},interpolate:function(e,g,h){h=(h*2-1)*this.sharpPremult;h=1/(1+Math.exp(-h));return e+(g-e)*h},setSharpness:function(e){this.sharpness=e;this.sharpPremult=5*e}};
+toxi.ThresholdInterpolation=function(e){this.threshold=e};toxi.ThresholdInterpolation.prototype={interpolate:function(e,g,h){return h<this.threshold?e:g}};toxi.ZoomLensInterpolation=function(e,g){this.leftImpl=new CircularInterpolation;this.rightImpl=new CircularInterpolation;this.lensPos=lenPos===undefined?0.5:e;this.lensStrength=lenStrength==undefined?1:g;this.absStrength=Math.abs(this.lensStrength);this.leftImpl.setFlipped(this.lensStrength>0);this.rightImpl.setFlipped(this.lensStrength<0)};
+toxi.ZoomLensInterpolation.prototype={interpolate:function(e,g,h){var i=e+(g-e)*h;i+=h<this.lensPos?(this.leftImpl.interpolate(e,e+(g-e)*this.lensPos,h/this.lensPos)-i)*this.absStrength:(this.rightImpl.interpolate(e+(g-e)*this.lensPos,g,(h-this.lensPos)/(1-this.lensPos))-i)*this.absStrength;return i},setLensPos:function(e,g){this.lensPos+=(MathUtils.clipNormalized(e)-this.lensPos)*g},setLensStrength:function(e,g){this.lensStrength+=(MathUtils.clip(e,-1,1)-this.lensStrength)*g;this.absStrength=MathUtils.abs(this.lensStrength);
+this.leftImpl.setFlipped(this.lensStrength>0);this.rightImpl.setFlipped(this.lensStrength<0)}};toxi.Range=function(e,g){this.min=e;this.max=g};toxi.Range.prototype.toString=function(){return"{ min: "+this.min+", max: "+this.max+"}"};toxi.ScaleMap=function(e,g,h,i){this.mapFunction=new toxi.LinearInterpolation;this.setInputRange(e,g);this.setOutputRange(h,i)};
+toxi.ScaleMap.prototype={getClippedValueFor:function(e){return this.mapFunction.interpolate(0,this.mapRange,toxi.MathUtils.clipNormalized((e-this._in.min)/this._interval))+this._out.min},getInputMedian:function(){return(this._in.min+this._in.max)*0.5},getInputRange:function(){return this._in},getMappedMedian:function(){return this.getMappedValueFor(0.5)},getMappedValueFor:function(e){return this.mapFunction.interpolate(0,this.mapRange,(e-this._in.min)/this._interval)+this._out.min},getOutputMedian:function(){return(this._out.min+
+this._out.max)*0.5},getOutputRange:function(){return this._out},setInputRange:function(e,g){this._in=new toxi.Range(e,g);this._interval=g-e},setMapFunction:function(e){this.mapFunction=e},setOutputRange:function(e,g){this._out=new toxi.Range(e,g);this.mapRange=g-e},toString:function(){return"toxi.ScaleMap, inputRange: "+this._in.toString()+" outputRange: "+this._out.toString()}};toxi.AbstractWave=function(){};
+toxi.AbstractWave.prototype={init:function(e,g,h,i){if(e!==undefined||g!==undefined||h!==undefined||i!==undefined){this.setPhase(e);this.frequency=g;if(h===undefined)h=1;if(i===undefined)i=1;this.amp=h;this.offset=i}},cyclePhase:function(e){if(e===undefined)e=0;this.phase=(this.phase+e)%toxi.AbstractWave.TWO_PI;if(this.phase<0)this.phase+=toxi.AbstractWave.TWO_PI;return this.phase},getClass:function(){return"toxi.AbstractWave"},pop:function(){if(this.stateStack==null||this.stateStack!=null&&this.stateStack.length<=
+0){console.log(this.toString());console.log("no wave states on stack")}else{var e=this.stateStack.pop();this.phase=e.phase;this.frequency=e.frequency;this.amp=e.amp;this.offset=e.offset}},push:function(){if(this.stateStack==null)this.stateStack=[];this.stateStack.push(new toxi.WaveState(this.phase,this.frequency,this.amp,this.offset))},reset:function(){this.phase=this.origPhase},setPhase:function(e){this.phase=e;this.cyclePhase();this.origPhase=e},toString:function(){return this.getClass()+" phase:"+
+this.phase+" frequency: "+this.frequency+" amp: "+this.amp+" offset: "+this.offset},update:function(){console.log(this.getClass()+" this should be overridden")}};toxi.AbstractWave.PI=3.141592653589793;toxi.AbstractWave.TWO_PI=2*toxi.AbstractWave.PI;toxi.AbstractWave.hertzToRadians=function(e,g){return e/g*toxi.AbstractWave.TWO_PI};toxi.AbstractWave.radiansToHertz=function(e,g){return e/toxi.AbstractWave.TWO_PI*g};
+toxi.AMFMSineWave=function(e,g,h,i,j){if(typeof h=="number"){this.parent.init.call(this,e,g,1,h);this.amod=i;this.fmod=j}else{this.parent.init.call(this,e,g);this.amod=h;this.fmod=i}};toxi.AMFMSineWave.prototype=new toxi.AbstractWave;toxi.AMFMSineWave.constructor=toxi.AMFMSineWave;toxi.AMFMSineWave.prototype.parent=toxi.AbstractWave.prototype;toxi.AMFMSineWave.prototype.getClass=function(){return"AMFMSineWave"};
+toxi.AMFMSineWave.prototype.pop=function(){this.parent.pop.call(this);this.amod.pop();this.fmod.pop()};toxi.AMFMSineWave.prototype.push=function(){this.parent.push.call(this);this.amod.push();this.fmod.push()};toxi.AMFMSineWave.prototype.reset=function(){this.parent.reset.call(this);this.fmod.reset();this.amod.reset()};toxi.AMFMSineWave.prototype.update=function(){this.amp=this.amod.update();this.value=this.amp*Math.sin(this.phase)+this.offset;this.cyclePhase(this.frequency+this.fmod.update());return this.value};
+toxi.ConstantWave=function(e){this.parent.init.call(this);this.value=e};toxi.ConstantWave.prototype=new toxi.AbstractWave;toxi.ConstantWave.constructor=toxi.ConstantWave;toxi.ConstantWave.prototype.parent=toxi.AbstractWave.prototype;toxi.ConstantWave.prototype.getClass=function(){return"ConstantWave"};toxi.ConstantWave.prototype.update=function(){return this.value};
+toxi.FMHarmonicSquareWave=function(e,g,h,i,j){this.maxHarmonics=3;if(typeof h=="number"){if(j===undefined)j=new toxi.ConstantWave(0);this.parent.init.call(this,e,g,h,i);this.fmod=j}else{this.parent.init.call(this,e,g);this.fmod=h}};toxi.FMHarmonicSquareWave.prototype=new toxi.AbstractWave;toxi.FMHarmonicSquareWave.constructor=toxi.FMHarmonicSquareWave;toxi.FMHarmonicSquareWave.prototype.parent=toxi.AbstractWave.prototype;toxi.FMHarmonicSquareWave.prototype.getClass=function(){return"FMHarmonicSquareWave"};
+toxi.FMHarmonicSquareWave.prototype.pop=function(){this.parent.pop.call(this);this.fmod.pop()};toxi.FMHarmonicSquareWave.prototype.push=function(){this.parent.push.call(this);this.fmod.push()};toxi.FMHarmonicSquareWave.prototype.reset=function(){this.parent.reset.call(this);this.fmod.reset()};
+toxi.FMHarmonicSquareWave.prototype.update=function(){this.value=0;for(var e=1;e<=this.maxHarmonics;e+=2)this.value+=1/e*Math.sin(e*this.phase);this.value*=this.amp;this.value+=this.offset;this.cyclePhase(this.frequency+this.fmod.update());return this.value};toxi.FMSawtoothWave=function(e,g,h,i,j){if(typeof h=="number"){this.parent.init.call(this,e,g,h,i);this.fmod=j}else{this.parent.init.call(this,e,g);this.fmod=h}};toxi.FMSawtoothWave.prototype=new toxi.AbstractWave;
+toxi.FMSawtoothWave.constructor=toxi.FMSawtoothWave;toxi.FMSawtoothWave.prototype.parent=toxi.AbstractWave.prototype;toxi.FMSawtoothWave.prototype.getClass=function(){return"FMSawtoothWave"};toxi.FMSawtoothWave.prototype.pop=function(){this.parent.pop.call(this);this.fmod.pop()};toxi.FMSawtoothWave.prototype.push=function(){this.parent.push.call(this);this.fmod.push()};toxi.FMSawtoothWave.prototype.reset=function(){this.parent.reset.call(this);this.fmod.reset()};
+toxi.FMSawtoothWave.prototype.update=function(){this.value=(this.phase/toxi.AbstractWave.TWO_PI*2-1)*this.amp+this.offset;this.cyclePhase(this.frequency+this.fmod.update());return this.value};toxi.FMSineWave=function(e,g,h,i,j){if(typeof h=="number"){this.parent.init.call(this,e,g,h,i);this.fmod=j}else{this.parent.init.call(this,e,g);this.fmod=h}};toxi.FMSineWave.prototype=new toxi.AbstractWave;toxi.FMSineWave.constructor=toxi.FMSineWave;toxi.FMSineWave.prototype.parent=toxi.AbstractWave.prototype;
+toxi.FMSineWave.prototype.getClass=function(){return"FMSineWave"};toxi.FMSineWave.prototype.pop=function(){this.parent.pop.call(this);this.fmod.pop()};toxi.FMSineWave.prototype.push=function(){this.parent.push.call(this);this.fmod.push()};toxi.FMSineWave.prototype.reset=function(){this.parent.reset.call(this);this.fmod.reset()};toxi.FMSineWave.prototype.update=function(){this.value=Math.sin(this.phase)*this.amp+this.offset;this.cyclePhase(this.frequency+this.fmod.update());return this.value};
+toxi.FMSquareWave=function(e,g,h,i,j){if(typeof h=="number")if(j===undefined)this.parent.init.call(this,e,g,h,i,new toxi.ConstantWave(0));else{this.parent.init.call(this,e,g,h,i);this.fmod=j}else{this.parent.init.call(this,e,g);this.fmod=h}};toxi.FMSquareWave.prototype=new toxi.AbstractWave;toxi.FMSquareWave.constructor=toxi.FMSquareWave;toxi.FMSquareWave.prototype.parent=toxi.AbstractWave.prototype;toxi.FMSquareWave.prototype.getClass=function(){return"FMSquareWave"};
+toxi.FMSquareWave.prototype.pop=function(){this.parent.pop.call(this);this.fmod.pop()};toxi.FMSquareWave.prototype.push=function(){this.parent.push.call(this);this.fmod.push()};toxi.FMSquareWave.prototype.reset=function(){this.parent.reset.call(this);this.fmod.reset()};toxi.FMSquareWave.prototype.update=function(){this.value=(this.phase/toxi.AbstractWave.TWO_PI<0.5?1:-1)*this.amp+this.offset;this.cyclePhase(this.frequency+this.fmod.update());return this.value};
+toxi.FMTriangleWave=function(e,g,h,i,j){if(typeof h=="number")if(j!==undefined){this.parent.init.call(this,e,g,h,i);this.fmod=j}else this.parent.init.call(this,e,g,h,i,new toxi.ConstantWave(0));else this.parent.init.call(this,e,g,1,0)};toxi.FMTriangleWave.prototype=new toxi.AbstractWave;toxi.FMTriangleWave.constructor=toxi.FMTriangleWave;toxi.FMTriangleWave.prototype.parent=toxi.AbstractWave.prototype;toxi.FMTriangleWave.prototype.getClass=function(){return"FMTriangleWave"};
+toxi.FMTriangleWave.prototype.pop=function(){this.parent.pop.call(this);this.fmod.pop()};toxi.FMTriangleWave.prototype.push=function(){this.parent.push.call(this);this.fmod.push()};toxi.FMTriangleWave.prototype.reset=function(){this.parent.reset.call(this);this.fmod.reset()};toxi.FMTriangleWave.prototype.update=function(){this.value=2*this.amp*(Math.abs(toxi.AbstractWave.PI-this.phase)*toxi.MathUtils.INV_PI-0.5)+this.offset;this.cyclePhase(this.frequency+this.fmod.update());return this.value};
+toxi.SineWave=function(e,g,h,i){this.parent.init.call(this,e,g,h,i)};toxi.SineWave.prototype=new toxi.AbstractWave;toxi.SineWave.constructor=toxi.SineWave;toxi.SineWave.prototype.parent=toxi.AbstractWave.prototype;toxi.SineWave.prototype.getClass=function(){return"SineWave"};toxi.SineWave.prototype.pop=function(){this.parent.pop.call(this)};toxi.SineWave.prototype.push=function(){this.parent.push.call(this)};
+toxi.SineWave.prototype.update=function(){this.value=Math.sin(this.phase)*this.amp+this.offset;this.cyclePhase(this.frequency);return this.value};toxi.WaveState=function(e,g,h,i){this.phase=e;this.frequency=g;this.amp=h;this.offset=i};toxi.SinCosLUT=function(e){this.precision=e;this.period=360/this.precision;this.quadrant=this.period>>2;this.deg2rad=Math.PI/180*this.precision;this.rad2deg=180/Math.PI/this.precision;this.sinLUT=[];for(e=0;e<this.period;e++)this.sinLUT[e]=Math.sin(e*this.deg2rad)};
+toxi.SinCosLUT.prototype={cos:function(e){for(;e<0;)e+=toxi.MathUtils.TWO_PI;return this.sinLUT[(e*this.rad2deg+this.quadrant)%this.period]},getPeriod:function(){return this.period},getPrecision:function(){return this.precision},getSinLUT:function(){return this.sinLUT},sin:function(e){for(;e<0;)e+=toxi.MathUtils.TWO_PI;return this.sinLUT[e*this.rad2deg%this.period]}};toxi.SinCosLUT.DEFAULT_PRECISION=0.25;toxi.SinCosLUT.DEFAULT_INSTANCE=null;
+toxi.SinCosLUT.getDefaultInstance=function(){if(toxi.SinCosLUT.DEFAULT_INSTANCE==null)toxi.SinCosLUT.DEFAULT_INSTANCE=new toxi.SinCosLUT;return toxi.SinCosLUT.DEFAULT_INSTANCE};toxi.Vec2D=function(e,g){this.init(e,g)};
+toxi.Vec2D.prototype={abs:function(){this.x=Math.abs(this.x);this.y=Math.abs(this.y);return this},add:function(e,g){var h=this.getVector(e,g);return new toxi.Vec2D(this.x+h.x,this.y+h.y)},addSelf:function(e,g){var h=this.getVector(e,g);this.x+=h.x;this.y+=h.y;return this},angleBetween:function(e,g){var h;h=g!==undefined&&faceNormalize==true?this.getNormalized().dot(e.getNormalized()):this.dot(e);return Math.acos(h)},clear:function(){this.x=this.y=0;return this},compareTo:function(){if(this.x==v.x&&
+this.y==v.y)return 0;return this.magSquared()-v.magSquared()},constrain:function(e,g){if(e instanceof toxi.Vec2D&&g instanceof toxi.Vec2D){this.x=toxi.MathUtils.clip(this.x,min.x,max.x);this.y=toxi.MathUtils.clip(this.y,min.y,max.y)}else if(e.x!=undefined&&e.y!=undefined&&e.width!=undefined&&e.height!=undefined){this.x=toxi.MathUtils.clip(this.x,e.x,e.x+e.width);this.y=toxi.MathUtils.clip(this.y,e.y,e.y+e.height)}return this},copy:function(){return new toxi.Vec2D(this)},cross:function(e){return this.x*
+e.y-this.y*e.x},distanceTo:function(e){if(e!==undefined){var g=this.x-e.x;e=this.y-e.y;return Math.sqrt(g*g+e*e)}else return NaN},distanceToSquared:function(e){if(e!==undefined){var g=this.x-e.x;e=this.y-e.y;return g*g+e*e}else return NaN},dot:function(e){return this.x*e.x+this.y*e.y},equals:function(e){if(e instanceof toxi.Vec2D)return this.x==e.x&&this.y==e.y;return false},equalsWithTolerance:function(e,g){if(toxi.MathUtils.abs(this.x-e.x)<g)if(toxi.MathUtils.abs(this.y-e.y)<g)return true;return false},
+floor:function(){this.x=toxi.MathUtils.floor(this.x);this.y=toxi.MathUtils.floor(this.y);return this},frac:function(){this.x-=toxi.MathUtils.floor(this.x);this.y-=toxi.MathUtils.floor(this.y);return this},getAbs:function(){return(new toxi.Vec2D(this)).abs()},getComponent:function(e){if(e instanceof Number)switch(e){case 0:case 1:e=toxi.Vec2D.Axis.Y}switch(e){case toxi.Vec2D.Axis.X:return this.x;case toxi.Vec2D.Axis.Y:return this.y}return 0},getConstrained:function(e){return(new toxi.Vec2D(this)).constrain(e)},
+getFloored:function(){return(new toxi.Vec2D(this)).floor()},getFrac:function(){return(new toxi.Vec2D(this)).frac()},getInverted:function(){return new toxi.Vec2D(-this.x,-this.y)},getLimited:function(e){if(this.magSquared()>e*e)return this.getNormalizedTo(e);return new toxi.Vec2D(this)},getNormalized:function(){return(new toxi.Vec2D(this)).normalize()},getNormalizedTo:function(e){return(new toxi.Vec2D(this)).normalizeTo(e)},getPerpendicular:function(){return(new toxi.Vec2D(this)).perpendicular()},
+getReciprocal:function(){return this.copy().reciprocal()},getReflected:function(e){return this.copy().reflect(e)},getRotated:function(e){return(new toxi.Vec2D(this)).rotate(e)},getSignum:function(){return(new toxi.Vec2D(this)).signum()},getVector:function(e,g){if(e instanceof toxi.Vec2D){g=e.y;e=e.x}else if(e!=undefined&&g===undefined)g=e;else if(e===undefined)e=0;else if(g===undefined)g=0;return new toxi.Vec2D(e,g)},heading:function(){return Math.atan2(this.y,this.x)},init:function(e,g){if(e instanceof
+toxi.Vec2D){g=e.y;e=e.x}else{if(e===undefined)e=0;if(g===undefined)g=0}this.x=e;this.y=g},interpolateTo:function(e,g,h){if(h===undefined)return new toxi.Vec2D(this.x+(e.x-this.x)*g,this.y+(e.y-this.y)*g)},interpolateToSelf:function(e,g,h){if(h===undefined){this.x+=(e.x-this.x)*g;this.y+=(e.y-this.y)*g}else{this.x=h.interpolate(this.x,e.x,g);this.y=h.interpolate(this.y,e.y,g)}return this},invert:function(){this.x*=-1;this.y*=-1;return this},isInCircle:function(e,g){return this.sub(e).magSquared()<=
+g*g},isInRectangle:function(e){if(this.x<e.x||this.x>e.x+e.width)return false;if(this.y<e.y||this.y>e.y+e.height)return false;return true},isInTriangle:function(e,g,h){e=this.sub(e).normalize();g=this.sub(g).normalize();h=this.sub(h).normalize();var i=Math.acos(e.dot(g));i+=Math.acos(g.dot(h));i+=Math.acos(h.dot(e));return Math.abs(i-toxi.MathUtils.TWO_PI)<=0.0050},isMajorAxis:function(e){var g=Math.abs(this.x),h=Math.abs(this.y),i=1-e;if(g>i)return h<e;else if(h>i)return g<e;return false},isZeroVector:function(){return Math.abs(this.x)<
+toxi.MathUtils.EPS&&Math.abs(this.y)<toxi.MathUtils.EPS},jitter:function(e,g){var h=this.getVector(e,g);this.x+=toxi.MathUtils.normalizedRandom()*h.x;this.y+=toxi.MathUtils.normalizedRandom()*h.y;return this},limit:function(e){if(this.magSquared()>e*e)return this.normalize().scaleSelf(e);return this},magnitude:function(){return Math.sqrt(this.x*this.x+this.y*this.y)},magSquared:function(){return this.x*this.x+this.y*this.y},max:function(e){return new toxi.Vec2D(toxi.MathUtils.max(this.x,e.x),toxi.MathUtils.max(this.y,
+e.y))},maxSelf:function(e){this.x=toxi.MathUtils.max(this.x,e.x);this.y=toxi.MathUtils.max(this.y,e.y);return this},min:function(e){return new toxi.Vec2D(toxi.MathUtils.min(this.x,e.x),MathUtils.min(this.y,e.y))},minSelf:function(e){this.x=MathUtils.min(this.x,e.x);this.y=MathUtils.min(this.y,e.y);return this},normalize:function(){var e=this.x*this.x+this.y*this.y;if(e>0){e=1/Math.sqrt(e);this.x*=e;this.y*=e}return this},normalizeTo:function(e){var g=Math.sqrt(this.x*this.x+this.y*this.y);if(g>0){g=
+e/g;this.x*=g;this.y*=g}return this},perpendicular:function(){var e=this.x;this.x=-this.y;this.y=e;return this},reciprocal:function(){this.x=1/this.x;this.y=1/this.y;return this},reflect:function(e){return this.set(e.scale(this.dot(e)*2).subSelf(this))},rotate:function(e){var g=Math.cos(e);e=Math.sin(e);var h=g*this.x-e*this.y;this.y=e*this.x+g*this.y;this.x=h;return this},roundToAxis:function(){if(Math.abs(this.x)<0.5)this.x=0;else{this.x=this.x<0?-1:1;this.y=0}if(Math.abs(this.y)<0.5)this.y=0;else{this.y=
+this.y<0?-1:1;this.x=0}return this},scale:function(e){return new toxi.Vec2D(this.x*e,this.y*e)},scale:function(e,g){var h=this.getVector(e,g);return new toxi.Vec2D(this.x*h.x,this.y*h.y)},scaleSelf:function(e,g){var h=this.getVector(e,g);this.x*=h.x;this.y*=h.y;return this},set:function(e,g){var h=this.getVector(e,g);this.x=h.x;this.y=h.y;return this},setComponent:function(e,g){switch(e){case toxi.Vec2D.Axis.X:this.x=g;break;case toxi.Vec2D.Axis.Y:this.y=g}return this},signum:function(){this.x=this.x<
+0?-1:this.x==0?0:1;this.y=this.y<0?-1:this.y==0?0:1;return this},sub:function(e,g){var h=this.getVector(e,g);return new toxi.Vec2D(this.x-h.x,this.y-h.y)},subSelf:function(e,g){var h=this.getVector(e,g);this.x-=h.x;this.y-=h.y;return this},tangentNormalOfEllipse:function(e,g){var h=this.sub(e);return(new toxi.Vec2D(h.x/(g.x*g.x),h.y/(g.y*g.y))).normalize()},toArray:function(){return[this.x,this.y]},toCartesian:function(){var e=this.x*Math.cos(this.y);this.y=this.x*Math.sin(this.y);this.x=e;return this},
+toPolar:function(){var e=Math.sqrt(this.x*this.x+this.y*this.y);this.y=Math.atan2(this.y,this.x);this.x=e;return this},toString:function(){return"{x:"+this.x+", y:"+this.y+"}"}};toxi.Vec2D.X_AXIS=new toxi.Vec2D(1,0);toxi.Vec2D.Y_AXIS=new toxi.Vec2D(0,1);toxi.Vec2D.ZERO=new toxi.Vec2D;toxi.Vec2D.MIN_VALUE=new toxi.Vec2D(Number.MIN_VALUE,Number.MIN_VALUE);toxi.Vec2D.MAX_VALUE=new toxi.Vec2D(Number.MAX_VALUE,Number.MAX_VALUE);toxi.Vec2D.fromTheta=function(e){return new toxi.Vec2D(Math.cos(e),Math.sin(e))};
+toxi.Vec2D.max=function(e,g){return new toxi.Vec2D(toxi.MathUtils.max(e.x,g.x),toxi.MathUtils.max(e.y,g.y))};toxi.Vec2D.min=function(e,g){return new toxi.Vec2D(toxi.MathUtils.min(e.x,g.x),toxi.MathUtils.min(e.y,g.y))};toxi.Vec2D.randomVector=function(){return(new toxi.Vec2D(Math.random()*2-1,Math.random()*2-1)).normalize()};toxi.Vec2D.Axis={X:{getVector:function(){return toxi.Vec2D.X_AXIS}},Y:{getVector:function(){return toxi.Vec2D.Y_AXIS}}};toxi.Vec3D=function(e,g,h){this.init(e,g,h)};
+toxi.Vec3D.prototype={abs:function(){this.x=Math.abs(this.x);this.y=Math.abs(this.y);this.z=Math.abs(this.z);return this},add:function(e,g,h){if(e instanceof toxi.Vec3D)return new toxi.Vec3D(this.x+e.x,this.y+e.y,this.z+e.z);return new toxi.Vec3D(this.x+e,this.y+g,this.z+h)},addSelf:function(e,g,h){if(e!=undefined&&g!=undefined&&h!=undefined){this.x+=e;this.y+=g;this.z+=h}else{this.x+=e.x;this.y+=e.y;this.z+=e.z}return this},angleBetween:function(e,g){var h;h=g?this.getNormalized().dot(e.getNormalized()):
+this.dot(e);return Math.acos(h)},clear:function(){this.x=this.y=this.z=0;return this},compareTo:function(e){if(this.x==e.x&&this.y==e.y&&this.z==e.z)return 0;return this.magSquared()-e.magSqaured()},constrain:function(e){if(e instanceof AABB){e.getMax();e.getMin()}this.x=Math.clip(this.x,this.min.x,this.max.x);this.y=toxi.MathUtils.clip(this.y,this.min.y,this.max.y);this.z=toxi.MathUtils.clip(this.z,this.min.z,this.max.z);return this},copy:function(){return new toxi.Vec3D(this)},cross:function(e){return new toxi.Vec3D(this.y*
+e.z-e.y*this.z,this.z*e.x-e.z*this.x,this.x*e.y-e.x*this.y)},crossInto:function(e){var g=e.x,h=e.y;e=e.z;result.x=this.y*e-h*this.z;result.y=this.z*g-e*this.x;result.z=this.x*h-g*this.y;return result},crossSelf:function(e){var g=this.y*e.z-e.y*this.z,h=this.z*e.x-e.z*this.x;this.z=e.y-e.x*this.y;this.y=h;this.x=g;return this},distanceTo:function(e){if(e!=undefined){var g=this.x-e.x,h=this.y-e.y;e=this.z-e.z;return Math.sqrt(g*g+h*h+e*e)}return NaN},distanceToSquared:function(e){if(e!=undefined){var g=
+this.x-e.x,h=this.y-e.y;e=this.z-e.z;return g*g+h*h+e*e}return NaN},dot:function(e){return this.x*e.x+this.y*e.y+this.z*e.z},equals:function(e){if(e instanceof toxi.Vec3D)return this.x==e.x&&this.y==e.y&&this.z==e.z;return false},equalsWithTolerance:function(e,g){if(Math.abs(this.x-e.x)<g)if(Math.abs(this.y-e.y)<g)if(Math.abs(this.z-e.z)<g)return true;return false},floor:function(){this.x=Math.floor(this.x);this.y=Math.floor(this.y);this.z=Math.floor(this.z);return this},frac:function(){this.x-=Math.floor(this.x);
+this.y-=Math.floor(this.y);this.z-=Math.floor(this.z);return this},getAbs:function(){return(new toxi.Vec3D(this)).abs()},getComponent:function(e){switch(e){case 0:return this.x;case 1:return this.y;case 2:return this.z}},getConstrained:function(e){return(new toxi.Vec3D(this)).constrain(e)},getFloored:function(){return(new toxi.Vec3D(this)).floor()},getFrac:function(){return(new toxi.Vec3D(this)).frac()},getInverted:function(){return new toxi.Vec3D(-this.x,-this.y,-this.z)},getLimited:function(e){if(this.magSquared()>
+e*e)return this.getNormalizedTo(e);return new toxi.Vec3D(this)},getNormalized:function(){return(new toxi.Vec3D(this)).normalize()},getNormalizedTo:function(e){return(new toxi.Vec3D(this)).normalizeTo(e)},getReciprocal:function(){return this.copy().reciprocal()},getReflected:function(e){return this.copy().reflect(e)},getRotatedAroundAxis:function(e,g){return(new toxi.Vec3D(this)).rotateAroundAxis(e,g)},getRotatedX:function(e){return(new toxi.Vec3D(this)).rotateX(e)},getRotatedY:function(e){return(new toxi.Vec3D(this)).rotateY(e)},
+getRotatedZ:function(e){return(new toxi.Vec3D(this)).rotateZ(e)},getSignum:function(){return(new toxi.Vec3D(this)).signum()},headingXY:function(){return Math.atan2(this.y,this.x)},headingXZ:function(){return Math.atan2(this.z,this.x)},headingYZ:function(){return Math.atan2(this.y,this.z)},immutable:function(){return this},init:function(e,g,h){if(e instanceof toxi.Vec3D){this.x=e.x;this.y=e.y;this.z=e.z}else if(e===undefined)this.z=this.y=this.x=0;else{this.x=e;this.y=g;this.z=h}},interpolateTo:function(e,
+g,h){if(h===undefined)return new toxi.Vec3D(this.x+(e.x-this.x)*g,this.y+(e.y-this.y)*g,this.z+(e.z-z)*g);return new toxi.Vec3D(h.interpolate(this.y,e.y,g),h.interpolate(this.y,e.y,g),h.interpolate(this.z,e.z,g))},interpolateToSelf:function(e,g,h){if(h===undefined){this.x+=(e.x-this.x)*g;this.y+=(e.y-this.y)*g;this.z+=(e.z-this.z)*g}else{this.x=h.interpolate(this.x,e.x,g);this.y=h.interpolate(this.y,e.y,g);this.z=h.interpolate(this.z,e.z,g)}return this},invert:function(){this.x*=-1;this.y*=-1;this.z*=
+-1;return this},isInAABB:function(e,g){if(g){var h=g.x;if(this.x<e.x-h||this.x>e.x+h)return false;h=g.y;if(this.y<e.y-h||this.y>e.y+h)return false;h=g.y;if(this.z<e.z-h||this.y>e.z+h)return false}return true},isMajorAxis:function(e){var g=toxi.MathUtils.abs(this.x),h=toxi.MathUtils.abs(this.y),i=toxi.MathUtils.abs(this.z),j=1-e;if(g>j){if(h<e)return i<e}else if(h>j){if(g<e)return i<e}else if(i>j)if(g<e)return h<e;return false},isZeroVector:function(){return Math.abs(this.x)<toxi.MathUtils.EPS&&Math.abs(this.y)<
+toxi.MathUtils.EPS&&toxi.MathUtils.abs(this.z)<toxi.MathUtils.EPS},jitter:function(e,g,h){if(g==undefined||h==undefined)g=h=e;this.x+=toxi.MathUtils.normalizedRandom()*e;this.y+=toxi.MathUtils.normalizedRandom()*g;this.z+=toxi.MathUtils.normalizedRandom()*h;return this},limit:function(e){if(magSquared()>e*e)return this.normalize().scaleSelf(e);return this},magnitude:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)},magSquared:function(){return this.x*this.x+this.y*this.y+this.z*
+this.z},maxSelf:function(e){this.x=Math.max(this.x,e.x);this.y=Math.max(this.y,e.y);this.z=Math.max(this.z,e.z);return this},minSelf:function(e){this.x=Math.min(this.x,e.x);this.y=Math.min(this.y,e.y);this.z=Math.min(this.z,e.z);return this},modSelf:function(){this.x%=base;this.y%=base;this.z%=base;return this},normalize:function(){var e=Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z);if(e>0){e=1/e;this.x*=e;this.y*=e;this.z*=e}return this},normalizeTo:function(e){var g=Math.sqrt(this.x*this.x+
+this.y*this.y+this.z*this.z);if(g>0){g=e/g;this.x*=g;this.y*=g;this.z*=g}return this},reciprocal:function(){this.x=1/this.x;this.y=1/this.y;this.z=1/this.z;return this},reflect:function(e){return this.set(e.scale(this.dot(e)*2).subSelf(this))},rotateAroundAxis:function(e,g){var h=e.x,i=e.y,j=e.z,k=h*x,n=i*y,m=j*z,o=Math.sin(g),r=Math.cos(g),s=i*(k+n+m)+(y*(h*h+j*j)-i*(k+m))*r+(j*x-h*z)*o,u=j*(k+n+m)+(z*(h*h+i*i)-j*(k+n))*r+(-(i*x)+h*y)*o;this.x=h*(k+n+m)+(x*(i*i+j*j)-h*(n+m))*r+(-(j*y)+i*z)*o;this.y=
+s;this.z=u;return this},rotateX:function(e){var g=Math.cos(e);e=Math.sin(e);var h=g*this.z-e*this.y;this.y=e*this.z+g*this.y;this.z=h;return this},rotateY:function(e){var g=Math.cos(e);e=Math.sin(e);var h=g*this.x-e*this.z;this.z=e*this.x+g*this.z;this.x=h;return this},rotateZ:function(e){var g=Math.cos(e);e=Math.sin(e);var h=g*this.x-e*this.y;this.y=e*this.x+g*this.y;this.x=h;return this},roundToAxis:function(){if(Math.abs(this.x)<0.5)this.x=0;else{this.x=this.x<0?-1:1;this.y=this.z=0}if(Math.abs(this.y)<
+0.5)this.y=0;else{this.y=this.y<0?-1:1;this.x=this.z=0}if(Math.abs(this.z)<0.5)this.z=0;else{this.z=this.z<0?-1:1;this.x=this.y=0}return this},scale:function(e,g,h){if(e instanceof toxi.Vec3D)return new toxi.Vec3D(this.x*e.x,this.y*e.y,this.z*e.z);else if(g==undefined||h==undefined)g=h=e;return new toxi.Vec3D(this.x*e,this.y*g,this.z*h)},scaleSelf:function(e,g,h){if(e instanceof toxi.Vec3D){this.x*=e.x;this.y*=e.y;this.z*=e.z;return true}else if(g==undefined||h==undefined)g=h=e;this.x*=e;this.y*=
+g;this.z*=h;return this},set:function(e,g,h){if(e instanceof toxi.Vec3D){this.x=e.x;this.y=e.y;this.z=e.z;return this}else if(g==undefined||h==undefined)g=h=e;this.x=e;this.y=g;this.z=h;return this},setXY:function(e){this.x=e.x;this.y=e.y;return this},shuffle:function(e){for(var g,h=0;h<e;h++)switch(Math.floor(Math.random()*3)){case 0:g=this.x;this.x=this.y;this.z=g;break;case 1:g=this.x;this.x=this.z;this.z=g;break;case 2:g=this.y;this.y=this.z;this.z=g}return this},signum:function(){this.x=this.x<
+0?-1:this.x==0?0:1;this.y=this.y<0?-1:this.y==0?0:1;this.z=this.z<0?-1:this.z==0?0:1;return this},sub:function(e,g,h){if(e instanceof toxi.Vec3D)return new toxi.Vec3D(this.x-e.x,this.y-e.y,this.z-e.z);else if(g===undefined||h===undefined)g=h=e;return new toxi.Vec3D(this.x-e,this.y-g,this.z-h)},subSelf:function(e,g,h){if(e instanceof toxi.Vec3D){this.x-=e.x;this.y-=e.y;this.z-=e.z;return this}else if(g==undefined||h==undefined)g=h=e;this.x-=e;this.y-=g;this.z-=h;return this},to2DXY:function(){return new Vec2D(this.x,
+this.y)},to2DXZ:function(){return new Vec2D(this.x,this.z)},to2DYZ:function(){return new Vec2D(this.y,this.z)},toArray:function(){return[this.x,this.y,this.z]},toArray4:function(e){var g=toArray();g[3]=e;return g},toCartesian:function(){var e=this.x*Math.cos(this.z),g=this.x*Math.sin(this.z),h=e*Math.sin(this.y);this.x=e*Math.cos(this.y);this.y=g;this.z=h;return this},toSpherical:function(){var e=Math.abs(this.x)<=toxi.MathUtils.EPS?toxi.MathUtils.EPS:this.x,g=this.z,h=Math.sqrt(e*e+this.y*this.y+
+g*g);this.z=Math.asin(this.y/h);this.y=Math.atan(g/e)+(e<0?Math.PI:0);this.x=h;return this},toString:function(){return"[ x: "+this.x+", y: "+this.y+", z: "+this.z+"]"}};toxi.Vec3D.MIN_VALUE=new toxi.Vec3D(Number.MIN_VALUE,Number.MIN_VALUE,Number.MIN_VALUE);toxi.Vec3D.MAX_VALUE=new toxi.Vec3D(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE);toxi.Vec3D.fromXYTheta=function(e){return new toxi.Vec3D(Math.cos(e),Math.sin(e),0)};
+toxi.Vec3D.fromXZTheta=function(e){return new toxi.Vec3D(Math.cos(e),0,Math.sin(e))};toxi.Vec3D.fromYZTheta=function(e){return new toxi.Vec3D(0,Math.cos(e),Math.sin(e))};toxi.Vec3D.max=function(e,g){return new toxi.Vec3D(Math.max(e.x(),g.x()),Math.max(e.y(),g.y()),Math.max(e.z(),g.z()))};toxi.Vec3D.min=function(e,g){return new toxi.Vec3D(Math.min(e.x(),g.x()),Math.min(e.y(),g.y()),Math.min(e.z(),g.z()))};
+toxi.Vec3D.randomVector=function(){return(new toxi.Vec3D(Math.random()*2-1,Math.random()*2-1,Math.random()*2-1)).normalize()};toxi.Vec3D.X_AXIS=new toxi.Vec3D(1,0,0);toxi.Vec3D.Y_AXIS=new toxi.Vec3D(0,1,0);toxi.Vec3D.Z_AXIS=new toxi.Vec3D(0,0,1);toxi.Vec2D.prototype.bisect=function(e){var g=this.sub(e);e=this.add(e);e=g.dot(e);return new toxi.Vec3D(g.x,g.y,-e/2)};toxi.Vec2D.prototype.to3DXY=function(){return new toxi.Vec3D(this.x,this.y,0)};
+toxi.Vec2D.prototype.to3DXZ=function(){return new toxi.Vec3D(this.x,0,this.y)};toxi.Vec2D.prototype.to3DYZ=function(){return new toxi.Vec3D(0,this.x,this.y)};toxi.Polygon2D=function(){this.vertices=[];if(arguments.length>1)for(var e=agruments.length,g=0;g<e;g++)this.add(p.copy());else if(arguments.length==1){var h=arguments[0];if(h instanceof Array){e=h.length;for(g=0;g<e;g++)this.add(h[g].copy())}}};
+toxi.Polygon2D.prototype={add:function(e){this.vertices.indexOf(e)>=0||this.vertices.push(e)},containsPoint:function(e){var g=this.vertices.length,h=g-1,i=e.x,j=e.y;for(e=0;e<g;e++){var k=this.vertices[e];h=this.vertices[h];if(k.y<j&&h.y>=j||h.y<j&&k.y>=j)if(k.x+(j-k.y)/(h.y-k.y)*(h.x-k.x)<i)oddNodes=!oddNodes;h=e}return false},flipVertexOrder:function(){this.vertices.reverse();return this},getArea:function(){for(var e=0,g=this.vertices.length,h=0;h<g;h++){var i=this.vertices[h],j=this.vertices[(h+
+1)%g];e+=i.x*j.y;e-=i.y*j.x}e*=0.5;return e},getCentroid:function(){for(var e=new toxi.Vec2D,g=this.vertices.length,h=0;h<g;h++){var i=this.vertices[h],j=this.vertices[(h+1)%g],k=i.x*j.y-j.x*i.y;e.x+=(i.x+j.x)*k;e.y+=(i.y+j.y)*k}return e.scale(1/(this.getArea()*6))},getCircumference:function(){for(var e=0,g=0;num=this.vertices.length,g<num;g++)e+=this.vertices[g].distanceTo(this.vertices[(g+1)%num]);return e},getNumPoints:function(){return this.vertices.length},isClockwise:function(){if(this.vertices.length>
+2)return toxi.Triangle2D.isClockwise(this.vertices[0],this.vertices[1],this.vertices[2]);return false},smooth:function(e,g){for(var h=this.getCentroid(),i=this.vertices.length,j=[],k=0,n=i-1,m=1;k<i;k++){var o=this.vertices[k],r=this.vertices[n].sub(o).addSelf(this.vertices[m].sub(o)).addSelf(o.sub(h).scaleSelf(g));j.push(o.add(r.scaleSelf(e)));n++;if(n==i)n=0;m++;if(m==i)m=0}this.vertices=j;return this},toString:function(){for(var e="",g=0;g<this.vertices.length;g++){e+=this.vertices[g];if(g<this.vertices.length-
+1)e+=", "}return e}};toxi.BernsteinPolynomial=function(e){this.resolution=e;for(var g=Array(e),h=Array(e),i=Array(e),j=Array(e),k=0,n=1/(e-1),m=0;m<e;m++){var o=1-k,r=o*o,s=k*k;g[m]=o*r;h[m]=3*k*r;i[m]=3*s*o;j[m]=k*s;k+=n}this.b0=g;this.b1=h;this.b2=i;this.b3=j};
+toxi.Spline2D=function(e,g){if(arguments.length==0){this.setTightness(toxi.Spline2D.DEFAULT_TIGHTNESS);this.pointList=[]}else if(arguments.length>=3){this.pointList=e.slice(0);this.bernstein=g;this.setTightness(tightness)}else if(arguments.length==1){this.pointList=e;this.numP=e.length;this.coeffA=[];this.delta=[];this.bi=[];for(var h=0;h<this.numP;h++){this.coeffA[h]=new toxi.Vec2D;this.delta[h]=new toxi.Vec2D;this.bi[h]=0}}this.numP=this.pointList.length;this.bi=[]};
+toxi.Spline2D.prototype={add:function(e){this.pointList.push(e.copy());return this},computeVertices:function(e){this.updateCoefficients();if(this.bernstein==undefined||this.bernstein.resolution!=e)this.bernstein=new toxi.BernsteinPolynomial(e);e=this.bernstein;this.vertices=[];this.findCPoints();for(var g=new toxi.Vec2D,h=new toxi.Vec2D,i=0;i<this.numP-1;i++){var j=this.points[i],k=this.points[i+1];g.set(this.delta[i]).addSelf(j);h.set(k).subSelf(this.delta[i+1]);for(var n=0;n<e.resolution;n++)this.vertices.push(new toxi.Vec2D(j.x*
+e.b0[n]+g.x*e.b1[n]+h.x*e.b2[n]+k.x*e.b3[n],j.y*e.b0[n]+g.y*e.b1[n]+h.y*e.b2[n]+k.y*e.b3[n]))}return this.vertices},findCPoints:function(){this.bi[1]=-0.25;this.coeffA[1].set((this.points[2].x-this.points[0].x-this.delta[0].x)*this.tightness,(this.points[2].y-this.points[0].y-this.delta[0].y)*this.tightness);for(var e=2;e<this.numP-1;e++){this.bi[e]=-1/(this.invTightness+this.bi[e-1]);this.coeffA[e].set(-(this.points[e+1].x-this.points[e-1].x-this.coeffA[e-1].x)*this.bi[e],-(this.points[e+1].y-this.points[e-
+1].y-this.coeffA[e-1].y)*this.bi[e])}for(e=this.numP-2;e>0;e--)this.delta[e].set(this.coeffA[e].x+this.delta[e+1].x*this.bi[e],this.coeffA[e].y+this.delta[e+1].y*this.bi[e])},getDecimatedVertices:function(e,g){if(g===undefined)g=true;if(this.vertices===undefined||this.vertices.length<2)this.computeVertices(Spline2D.DEFAULT_RES);for(var h=this.getEstimatedArcLength(),i=[],j=e/h,k=0,n=0;n<1;n+=j){for(var m=n*h;m>=this.arcLenIndex[k];)k++;this.uniform.push(this.vertices[k-1].interpolateTo(this.vertices[k],
+(m-this.arcLenIndex[k-1])/(this.arcLenIndex[k]-this.arcLenIndex[k-1])))}g&&i.push(this.vertices[this.vertices.length-1]);return i},getEstimatedArcLength:function(){if(this.arcLenIndex===undefined||this.arcLenIndex!==undefined&&this.arcLenIndex.length!=this.vertices.length)this.arcLenIndex=[];for(var e=0,g=1;g<this.arcLenIndex.length;g++){e+=this.vertices[g-1].distanceTo(this.vertices[g]);this.arcLenIndex[g]=e}return e},getNumPoints:function(){return this.numP},getPointList:function(){return this.pointList},
+getTightness:function(){return this.tightness},setPointList:function(e){this.pointList=e.slice(0);return this},setTightness:function(e){this.tightness=e;this.invTightness=1/this.tightness;return this},updateCoefficients:function(){this.numP=this.pointList.length;if(this.points===undefined||this.points!=undefined&&this.points.length!=this.numP){this.coeffA=[];this.delta=[];this.bi=[];for(var e=0;e<this.numP;e++){this.coeffA[e]=new toxi.Vec2D;this.delta[e]=new toxi.Vec2D}this.setTightness(this.tightness)}this.points=
+this.pointList.slice(0)}};toxi.Spline2D.DEFAULT_TIGHTNESS=0.25;toxi.Spline2D.DEFAULT_RES=16;toxi.Ellipse=function(e,g,h,i){this.ellipseInit(e,g,h,i)};toxi.Ellipse.prototype=new toxi.Vec2D;toxi.Ellipse.prototype.constructor=toxi.Ellipse;toxi.Ellipse.prototype.parent=toxi.Vec2D.prototype;toxi.Ellipse.prototype.containsPoint=function(e){var g=this.getFoci();return e.distanceTo(g[0])+e.distanceTo(g[1])<2*MathUtils.max(this.radius.x,this.radius.y)};
+toxi.Ellipse.prototype.getArea=function(){return MathUtils.PI*radius.x*radius.y};toxi.Ellipse.prototype.getCircumference=function(){return Math.sqrt(0.5*this.radius.magSquared())*MathUtils.TWO_PI};toxi.Ellipse.prototype.getFoci=function(){var e=[];if(this.radius.x>this.radius.y){e[0]=this.sub(this.focus,0);e[1]=this.add(this.focus,0)}else{e[0]=this.sub(0,this.focus);e[1]=this.add(0,this.focus)}return e};toxi.Ellipse.prototype.getRadii=function(){return this.radius.copy()};
+toxi.Ellipse.prototype.ellipseInit=function(e,g,h,i){this.radius=new toxi.Vec2D;if(e===undefined){this.parent.init.call(this,0,0);this.setRadii(1,1)}else if(e instanceof toxi.Vec2D){this.parent.init.call(this,e.x,e.y);g instanceof toxi.Vec2D?this.setRadii(g.x,g.y):this.setRadii(g,g)}else if(i===undefined)if(h===undefined){this.parent.init.call(this,0,0);this.setRadii(e,g)}else{this.parent.init.call(this,e,g);this.setRadii(h,h)}else{this.parent.init.call(this,e,g);this.setRadii(h,i)}return this};
+toxi.Ellipse.prototype.setRadii=function(e,g){if(e instanceof toxi.Vec2D){g=e.y;e=e.x}this.radius.set(e,g);this.focus=this.radius.magnitude();return this};toxi.Ellipse.prototype.toPolygon2D=function(e){for(var g=new toxi.Polygon2D,h=MathUtils.TWO_PI/e,i=0;i<e;i++)g.add(toxi.Vec2D.fromTheta(i*h).scaleSelf(this.radius).addSelf(this));return g};
+toxi.Rect=function(e,g,h,i){if(arguments.length===2)if(e instanceof toxi.Vec2D){this.x=e.x;this.y=e.y;this.width=g.x-this.x;this.height=g.y-this.y}else throw Error("toxi.Rect received incorrect parameters");else if(arguments.length===4){this.x=e;this.y=g;this.width=h;this.height=i}else if(arguments.length>0)throw Error("toxi.Rect received incorrect parameters");};toxi.Rect.fromCenterExtent=function(e,g){return new toxi.Rect(e.sub(g),e.add(g))};
+toxi.Rect.prototype={containsPoint:function(e){var g=e.x;e=e.y;if(g<this.x||g>=this.x+this.width)return false;if(e<this.y||e>=this.y+this.height)return false;return true},copy:function(){return new toxi.Rect(this.x,this.y,this.width,this.height)},getArea:function(){return this.width*this.height},getAspect:function(){return this.width/this.height},getBottom:function(){return this.y+this.height},getBottomRight:function(){return new toxi.Vec2D(this.x+this.width,this.y+this.height)},getCentroid:function(){return new toxi.Vec2D(this.x+
+this.width*0.5,this.y+this.height*0.5)},getDimensions:function(){return new toxi.Vec2D(this.width,this.height)},getEdge:function(e){var g=undefined;switch(e){case 0:g=new toxi.Line2D(new toxi.Vec2D(this.x,this.y),new toxi.Vec2D(this.x+this.width,this.y));break;case 1:g=new toxi.Line2D(new toxi.Vec2D(this.x+this.width,this.y),new toxi.Vec2D(this.x+this.width,this.y+this.height));break;case 2:g=new toxi.Line2D(new toxi.Vec2D(this.x,this.y+this.height),new toxi.Vec2D(this.x+this.width,this.y+this.height));
+break;case 3:g=new toxi.Line2D(new toxi.Vec2D(this.x,this.y),new toxi.Vec2D(this.x,this.y+this.height));break;default:throw Error("edge ID needs to be 0...3");}return g},getLeft:function(){return this.x},getRight:function(){return this.x+this.width},getTop:function(){return this.y},getTopLeft:function(){return new toxi.Vec2D(this.x,this.y)},intersectsRay:function(e,g,h){var i=e.getDirection().reciprocal(),j=i.x<0,k=i.y<0,n=this.getTopLeft(),m=this.getBottomRight(),o=j?m:n,r=(o.x-e.x)*i.x;o=j?n:m;
+j=(o.x-e.x)*i.x;o=k?n:m;var s=(o.y-e.y)*i.y;o=k?n:m;i=(o.y-e.y)*i.y;if(!(r>i||s>j)){if(s>r)r=s;if(i<j)j=i;if(r<h&&j>g)return e.getPointAtDistance(r)}},intersectsRect:function(e){return!(this.x>e.x+e.width||this.x+this.width<e.x||this.y>e.y+e.height||this.y+this.height<e.y)},scale:function(e){var g=this.getCentroid();this.width*=e;this.height*=e;this.x=g.x-this.width*0.5;this.y=g.y-this.height*0.5;return this},set:function(e,g,h,i){if(arguments.length==-1){this.y=e.y;this.width=e.width;this.height=
+e.height;this.x=e.x}else if(arguments.length===4){this.x=e;this.y=g;this.width=h;this.height=i}else throw Error("toxi.Rect set() received wrong parameters");},setDimenions:function(e){this.width=e.x;this.height=e.y;return this},setPosition:function(e){this.x=e.x;this.y=e.y;return this},toPolygon2D:function(){var e=new toxi.Polygon2D;e.add(new toxi.Vec2D(this.x,this.y));e.add(new toxi.Vec2D(this.x+this.width,this.y));e.add(new toxi.Vec2D(this.x+this.width,this.y+this.height));e.add(new toxi.Vec2D(this.x,
+this.y+this.height));return e},toString:function(){return"rect: {x: "+this.x+", y: "+this.y+", width: "+this.width+", height: "+this.height+"}"},union:function(e){var g=MathUtils.max(this.x+this.width,e.x+e.width);this.x=MathUtils.min(this.x,e.x);this.width=g-this.x;g=MathUtils.max(this.y+this.height,e.y+e.height);this.y=MathUtils.min(this.y,e.y);this.height=g-this.y;return this}};toxi.Circle=function(e,g,h){this.circleInit(e,g,h)};toxi.Circle.prototype=new toxi.Ellipse;
+toxi.Circle.prototype.constructor=toxi.Circle;toxi.Circle.prototype.parent=toxi.Ellipse.prototype;toxi.Circle.from2Points=function(e,g){var h=e.interpolateTo(g,0.5),i=h.distanceTo(e);return new toxi.Circle(h,i)};
+toxi.Circle.from3Points=function(e,g,h){var i=undefined,j=g.sub(e),k=h.sub(g);if(toxi.MathUtils.abs(j.x)<=1.0E-7&&toxi.MathUtils.abs(k.y)<=1.0E-7){g=(new toxi.Vec2D(g.x+h.x,e.y+g.y)).scaleSelf(0.5);e=g.distanceTo(e);i=new toxi.Circle(g,e)}else{j=j.y/j.x;k=k.y/k.x;if(toxi.MathUtils.abs(j-k)>1.0E-7&&j!=0){h=(j*k*(e.y-h.y)+k*(e.x+g.x)-j*(g.x+h.x))/(2*(k-j));g=new toxi.Vec2D(h,-(h-(e.x+g.x)/2)/j+(e.y+g.y)/2);e=g.distanceTo(e);i=new toxi.Circle(g,e)}}return i};
+toxi.Circle.prototype.containsPoint=function(e){return this.distanceToSquared(e)<=this.radius.x*this.radius.x};toxi.Circle.prototype.getCircumference=function(){return toxi.MathUtils.TWO_PI*this.radius.x};toxi.Circle.prototype.getRadius=function(){return this.radius.x};toxi.Circle.prototype.getTangentPoints=function(e){var g=this.interpolateTo(e,0.5);return this.intersectsCircle(new toxi.Circle(g,g.distanceTo(e)))};
+toxi.Circle.prototype.circleInit=function(e,g,h){if(g===undefined)e instanceof toxi.Circle?this.parent.ellipseInit.call(this,e,e.radius.x):this.parent.ellipseInit.call(this,0,0,e);else h===undefined?this.parent.ellipseInit.call(this,e,g):this.parent.ellipseInit.call(this,e,g,h,h);return this};
+toxi.Circle.prototype.intersectsCircle=function(e){var g=null,h=e.sub(this),i=h.magnitude(),j=this.radius.x;e=e.radius.x;if(i<=j+e&&i>=Math.abs(j-e)){e=(j*j-e*e+i*i)/(2*i);i=1/i;g=this.add(h.scale(e*i));j=Math.sqrt(j*j-e*e);h.perpendicular().scaleSelf(j*i);i=g.add(h);h=g.sub(h);g=[i,h]}return g};toxi.Circle.prototype.setRadius=function(e){this.setRadii(e,e);return this};toxi.CircleIntersector=function(e){this.circle=e;this.isec=undefined};
+toxi.CircleIntersector.prototype={getIntersectionData:function(){return this.isec},intersectsRay:function(e){this.isec.clear();var g=circle.sub(e),h=g.magSquared();g=g.dot(e.getDirection());var i=circle.getRadius();h=i*i-(h-g*g);if(h>=0){this.isec.isIntersection=true;this.isec.dist=g-Math.sqrt(h);this.isec.pos=e.getPointAtDistance(isec.dist);this.isec.normal=this.isec.pos.sub(this.circle).normalize()}return this.isec.isIntersection}};toxi.Line2D=function(e,g){this.a=e;this.b=g};
+toxi.Line2D.prototype={closestPointTo:function(e){var g=this.b.sub(this.a);e=e.sub(this.a).dot(g)/g.magSquared();if(e<0)return this.a.copy();else if(e>1)return this.b.copy();return this.a.add(g.scaleSelf(e))},copy:function(){return new toxi.Line2D(this.a.copy(),this.b.copy())},equals:function(e){if(this==e)return true;if(!(e instanceof toxi.Line2D))return false;return(this.a.equals(e.a)||this.a.equals(e.b))&&(this.b.equals(e.b)||this.b.equals(e.a))},getDirection:function(){return this.b.sub(this.a).normalize()},
+getLength:function(){return this.a.distanceTo(this.b)},getLengthSquared:function(){return this.a.distanceToSquared(this.b)},getMidPoint:function(){return this.a.add(this.b).scaleSelf(0.5)},getNormal:function(){return this.b.sub(this.a).perpendicular()},getTheta:function(){return this.a.angleBetween(this.b,true)},hasEndPoint:function(e){return this.a.equals(e)||this.b.equals(e)},intersectLine:function(e){var g=null;g=(e.b.y-e.a.y)*(this.b.x-this.a.x)-(e.b.x-e.a.x)*(this.b.y-this.a.y);var h=(e.b.x-
+e.a.x)*(this.a.y-e.a.y)-(e.b.y-e.a.y)*(this.a.x-e.a.x);e=(this.b.x-this.a.x)*(this.a.y-e.a.y)-(this.b.y-this.a.y)*(this.a.x-e.a.x);if(g!=0){h=h/g;g=e/g;g=h>=0&&h<=1&&g>=0&&g<=1?new toxi.Line2D.LineIntersection(toxi.Line2D.LineIntersection.Type.INTERSECTING,this.a.interpolateTo(this.b,h)):new toxi.Line2D.LineIntersection(toxi.Line2D.LineIntersection.Type.NON_INTERSECTING,null)}else g=new toxi.Line2D.LineIntersection(toxi.Line2D.LineIntersection.Type.COINCIDENT,null);return g},offsetAndGrowBy:function(e,
+g,h){var i=this.getMidPoint(),j=this.getDirection(),k=j.getPerpendicular();h!=null&&i.sub(h).dot(k)<0&&k.invert();k.normalizeTo(e);this.a.addSelf(k);this.b.addSelf(k);j.scaleSelf(g);this.a.subSelf(j);this.b.addSelf(j);return this},scale:function(e){e=(1-e)*0.5;var g=a.interpolateTo(this.b,e);this.b.interpolateToSelf(this.a,e);this.a.set(g);return this},set:function(e,g){this.a=e;this.b=g;return this},splitIntoSegments:function(e,g,h){return toxi.Line2D.splitIntoSegments(this.a,this.b,g,e,h)},toRay2D:function(){return new toxi.Ray2D(this.a.copy(),
+this.b.sub(this.a).normalize())}};toxi.Line2D.splitIntoSegments=function(e,g,h,i,j){if(i==null)i=[];j&&i.push(e.copy());j=e.distanceTo(g);if(j>h){var k=e.copy();for(e=g.sub(e).limit(h);j>h;){k.addSelf(e);i.push(k.copy());j-=h}}i.push(g.copy());return i};toxi.Line2D.LineIntersection=function(e,g){this.type=e;this.pos=g};toxi.Line2D.LineIntersection.prototype={getPos:function(){return this.pos.copy()},getType:function(){return this.type},toString:function(){return"type: "+this.type+" pos: "+this.pos}};
+toxi.Line2D.LineIntersection.Type={COINCIDENT:0,PARALLEL:1,NON_INTERSECTING:2,INTERSECTING:3};toxi.Triangle=function(e,g,h){if(arguments.length==3){this.a=e;this.b=g;this.c=h}};toxi.Triangle.createEquilateralFrom=function(e,g){var h=e.interpolateTo(g,0.5),i=g.sub(e),j=e.cross(i.normalize());h.addSelf(j.normalizeTo(i.magnitude()*toxi.MathUtils.SQRT3/2));return new toxi.Triangle(e,g,h)};toxi.Triangle.isClockwiseInXY=function(e,g,h){return(g.x-e.x)*(h.y-e.y)-(h.x-e.x)*(g.y-e.y)<0};
+toxi.Triangle.isClockwiseInXZ=function(e,g,h){return(g.x-e.x)*(h.z-e.z)-(h.x-e.x)*(g.z-e.z)<0};toxi.Triangle.isClockwiseInYZ=function(e,g,h){return(g.y-e.y)*(h.z-e.z)-(h.y-e.y)*(g.z-e.z)<0};
+toxi.Triangle.prototype={closestPointOnSurface:function(e){var g=this.b.sub(this.a),h=this.c.sub(this.a),i=this.c.sub(this.b),j=e.sub(this.a),k=e.sub(this.b),n=e.sub(this.c);e=a.sub(this.p);var m=b.sub(this.p),o=c.sub(this.p),r=j.dot(g);j=j.dot(h);if(r<=0&&j<=0)return this.a;var s=k.dot(this.a.sub(this.b)),u=n.dot(this.a.sub(this.c)),A=k.dot(i);n=n.dot(this.b.sub(this.c));if(s<=0&&A<=0)return this.b;if(u<=0&&n<=0)return this.c;var B=g.cross(h);k=B.dot(e.crossSelf(m));if(k<=0&&r>=0&&s>=0)return this.a.add(g.scaleSelf(r/
+(r+s)));g=B.dot(m.crossSelf(o));if(g<=0&&A>=0&&n>=0)return this.b.add(i.scaleSelf(A/(A+n)));i=B.dot(o.crossSelf(e));if(i<=0&&j>=0&&u>=0)return this.a.add(h.scaleSelf(j/(j+u)));h=g/(g+i+k);i=i/(g+i+k);g=1-h-i;return this.a.scale(h).addSelf(this.b.scale(i)).addSelf(this.c.scale(g))},computeCentroid:function(){return this.centroid=this.a.add(this.b).addSelf(this.c).scaleSelf(1/3)},computeNormal:function(){return this.normal=this.a.sub(this.c).crossSelf(this.a.sub(this.b)).normalize()},containsPoint:function(e){if(e.equals(this.a)||
+e.equals(this.b)||e.equals(this.c))return true;var g=e.sub(this.a).normalize(),h=e.sub(this.b).normalize();e=e.sub(this.c).normalize();var i=Math.acos(g.dot(h));i+=Math.acos(h.dot(e));i+=Math.acos(e.dot(g));return toxi.MathUtils.abs(i-toxi.MathUtils.TWO_PI)<=0.0050},flipVertexOrder:function(){this.a=this.c;this.c=this.t;return this},fromBarycentric:function(e){return new toxi.Vec3D(this.a.x*e.x()+this.b.x*e.y()+this.c.x*e.z(),this.a.y*e.x()+this.b.y*e.y()+this.c.y*e.z(),this.a.z*e.x()+this.b.z*e.y()+
+this.c.z*e.z())},getBoundingBox:function(){var e=toxi.Vec3D.min(toxi.Vec3D.min(this.a,this.b),this.c),g=toxi.Vec3D.max(toxi.Vec3D.max(this.a,this.b),this.c);return toxi.AABB.fromMinMax(e,g)},getClosestPointTo:function(e){var g=new toxi.Line3D(this.a,this.b),h=g.closestPointTo(e),i=g.set(this.b,this.c).closestPointTo(e);g=g.set(this.c,this.a).closestPointTo(e);var j=e.sub(h).magSquared(),k=e.sub(i).magSquared();e=e.sub(g).magSquared();j=j;h=h;if(k<j){j=k;h=i}if(e<j)h=g;return h},isClockwiseInXY:function(){return toxi.Triangle.isClockwiseInXY(this.a,
+this.b,this.c)},isClockwiseInXZ:function(){return toxi.Triangle.isClockwiseInXY(this.a,this.b,this.c)},isClockwiseInYZ:function(){return toxi.Triangle.isClockwiseInXY(this.a,this.b,this.c)},set:function(e,g,h){this.a=e;this.b=g;this.c=h},toBarycentric:function(e){var g=b.sub(this.a).cross(this.c.sub(this.a)),h=g.getNormalized(),i=h.dot(g);g=h.dot(this.b.sub(e).cross(this.c.sub(e)))/i;e=h.dot(this.c.sub(e).cross(this.a.sub(e)))/i;return new toxi.Vec3D(g,e,1-g-e)},toString:function(){return"Triangle: "+
+this.a+","+this.b+","+this.c}};toxi.IsectData2D=function(e){if(e!==undefined){this.isIntersection=e.isIntersection;this.dist=e.dist;this.pos=e.pos.copy();this.dir=e.dir.copy();this.normal=e.normal.copy()}else this.clear()};
+toxi.IsectData2D.prototype={clear:function(){this.isIntersection=false;this.dist=0;this.pos=new toxi.Vec2D;this.dir=new toxi.Vec2D;this.normal=new toxi.Vec2D},toString:function(){var e="isec: "+this.isIntersection;if(this.isIntersection)e+=" at:"+this.pos+" dist:"+this.dist+" normal:"+this.normal;return e}};toxi.IsectData3D=function(e){if(e!==undefined){this.isIntersection=e.isIntersection;this.dist=e.dist;this.pos=e.pos.copy();this.dir=e.dir.copy();this.normal=e.normal.copy()}else this.clear()};
+toxi.IsectData3D.prototype={clear:function(){this.isIntersection=false;this.dist=0;this.pos=new toxi.Vec3D;this.dir=new toxi.Vec3D;this.normal=new toxi.Vec3D},toString:function(){var e="isec: "+this.isIntersection;if(this.isIntersection)e+=" at:"+this.pos+" dist:"+this.dist+" normal:"+this.normal;return e}};
+toxi.Matrix4x4=function(e,g,h,i,j,k,n,m,o,r,s,u,A,B,D,C){this.temp=[];if(arguments.length==0){this.matrix=[];this.matrix[0]=[1,0,0,0];this.matrix[1]=[0,1,0,0];this.matrix[2]=[0,0,1,0];this.matrix[3]=[0,0,0,1]}else if(typeof e=="number")this.matrix=[[e,g,h,i],[j,k,n,m],[o,r,s,u],[A,B,D,C]];else if(e instanceof Array){if(e.length!=9&&e.length!=16)throw Error("toxi.Matrix4x4: Array length must == 9 or 16");if(e.length==16){this.matrix=[];this.matrix[0]=e.slice(0,4);this.matrix[1]=e.slice(4,8);this.matrix[2]=
+e.slice(8,12);this.matrix[3]=e.slice(12)}else{this.matrix[0]=e.slice(0,3);this.matrix[0][3]=NaN;this.matrix[1]=e.slice(3,6);this.matrix[1][3]=NaN;this.matrix[2]=e.slice(6,9);this.matrix[2][3]=NaN;this.matrix[3]=[NaN,NaN,NaN,NaN]}}else if(e instanceof toxi.Matrix4x4)if(e.length==16)for(var t=0;t<4;t++)this.matrix[t]=[e.matrix[t][0],e.matrix[t][1],e.matrix[t][2],e.matrix[t][3]];else{for(t=0;t<3;t++)this.matrix[t]=[e.matrix[t][0],e.matrix[t][1],e.matrix[t][2],NaN];this.matrix[3]=[NaN,NaN,NaN,NaN]}else console.error("toxi.Matrix4x4: incorrect parameters used to construct new instance")};
+toxi.Matrix4x4.prototype={add:function(e){return(new toxi.Matrix4x4(this)).addSelf(e)},addSelf:function(e){for(var g=0;g<4;g++){var h=this.matrix[g],i=e.matrix[g];h[0]+=i[0];h[1]+=i[1];h[2]+=i[2];h[3]+=i[3]}return this},applyTo:function(e){return this.applyToSelf(new toxi.Vec3D(e))},applyToSelf:function(e){for(var g=0;g<4;g++){var h=this.matrix[g];this.temp[g]=e.x*h[0]+e.y*h[1]+e.z*h[2]+h[3]}e.set(this.temp[0],this.temp[1],this.temp[2]).scaleSelf(1/this.temp[3]);return e},copy:function(){return new toxi.Matrix4x4(this)},
+getInverted:function(){return(new toxi.Matrix4x4(this)).invert()},getRotatedAroundAxis:function(e,g){return(new toxi.Matrix4x4(this)).rotateAroundAxis(e,g)},getRotatedX:function(e){return(new toxi.Matrix4x4(this)).rotateX(e)},getRotatedY:function(e){return(new toxi.Matrix4x4(this)).rotateY(e)},getRotatedZ:function(e){return(new toxi.Matrix4x4(this)).rotateZ(e)},getTransposed:function(){return(new toxi.Matrix4x4(this)).transpose()},identity:function(){var e=this.matrix[0];e[1]=e[2]=e[3]=0;e=this.matrix[1];
+e[0]=e[2]=e[3]=0;e=this.matrix[2];e[0]=e[1]=e[3]=0;e=this.matrix[3];e[0]=e[1]=e[2]=0;this.matrix[0][0]=1;this.matrix[1][1]=1;this.matrix[2][2]=1;this.matrix[3][3]=1;return this},invert:function(){for(var e=[],g=[],h=[],i=this.toArray(),j=0;j<4;j++){var k=j<<2;g[j]=i[k];g[j+4]=i[k+1];g[j+8]=i[k+2];g[j+12]=i[k+3]}e[0]=g[10]*g[15];e[1]=g[11]*g[14];e[2]=g[9]*g[15];e[3]=g[11]*g[13];e[4]=g[9]*g[14];e[5]=g[10]*g[13];e[6]=g[8]*g[15];e[7]=g[11]*g[12];e[8]=g[8]*g[14];e[9]=g[10]*g[12];e[10]=g[8]*g[13];e[11]=
+g[9]*g[12];j=g[0];i=g[1];k=g[2];var n=g[3],m=g[4],o=g[5],r=g[6],s=g[7];h[0]=e[0]*o+e[3]*r+e[4]*s;h[0]-=e[1]*o+e[2]*r+e[5]*s;h[1]=e[1]*m+e[6]*r+e[9]*s;h[1]-=e[0]*m+e[7]*r+e[8]*s;h[2]=e[2]*m+e[7]*o+e[10]*s;h[2]-=e[3]*m+e[6]*o+e[11]*s;h[3]=e[5]*m+e[8]*o+e[11]*r;h[3]-=e[4]*m+e[9]*o+e[10]*r;h[4]=e[1]*i+e[2]*k+e[5]*n;h[4]-=e[0]*i+e[3]*k+e[4]*n;h[5]=e[0]*j+e[7]*k+e[8]*n;h[5]-=e[1]*j+e[6]*k+e[9]*n;h[6]=e[3]*j+e[6]*i+e[11]*n;h[6]-=e[2]*j+e[7]*i+e[10]*n;h[7]=e[4]*j+e[9]*i+e[10]*k;h[7]-=e[5]*j+e[8]*i+e[11]*
+k;e[0]=k*s;e[1]=n*r;e[2]=i*s;e[3]=n*o;e[4]=i*r;e[5]=k*o;e[6]=j*s;e[7]=n*m;e[8]=j*r;e[9]=k*m;e[10]=j*o;e[11]=i*m;j=g[8];i=g[9];k=g[10];n=g[11];m=g[12];o=g[13];r=g[14];s=g[15];h[8]=e[0]*o+e[3]*r+e[4]*s;h[8]-=e[1]*o+e[2]*r+e[5]*s;h[9]=e[1]*m+e[6]*r+e[9]*s;h[9]-=e[0]*m+e[7]*r+e[8]*s;h[10]=e[2]*m+e[7]*o+e[10]*s;h[10]-=e[3]*m+e[6]*o+e[11]*s;h[11]=e[5]*m+e[8]*o+e[11]*r;h[11]-=e[4]*m+e[9]*o+e[10]*r;h[12]=e[2]*k+e[5]*n+e[1]*i;h[12]-=e[4]*n+e[0]*i+e[3]*k;h[13]=e[8]*n+e[0]*j+e[7]*k;h[13]-=e[6]*k+e[9]*n+e[1]*
+j;h[14]=e[6]*i+e[11]*n+e[3]*j;h[14]-=e[10]*n+e[2]*j+e[7]*i;h[15]=e[10]*k+e[4]*j+e[9]*i;h[15]-=e[8]*i+e[11]*k+e[5]*j;e=1/(g[0]*h[0]+g[1]*h[1]+g[2]*h[2]+g[3]*h[3]);for(g=j=0;j<4;j++){i=this.matrix[j];for(k=0;k<4;k++)i[k]=h[g++]*e}return this},multiply:function(e){if(typeof e=="number")return(new toxi.Matrix4x4(this)).multiply(e);return(new toxi.Matrix4x4(this)).multiplySelf(e)},multiplySelf:function(e){if(typeof e=="number"){for(var g=0;g<4;g++){var h=matrix[g];h[0]*=e;h[1]*=e;h[2]*=e;h[3]*=e}return this}var i=
+e.matrix[0],j=e.matrix[1],k=e.matrix[2];e=e.matrix[3];for(g=0;g<4;g++){h=this.matrix[g];for(var n=0;n<4;n++)this.temp[n]=h[0]*i[n]+h[1]*j[n]+h[2]*k[n]+h[3]*e[n];h[0]=this.temp[0];h[1]=this.temp[1];h[2]=this.temp[2];h[3]=this.temp[3]}return this},rotateAroundAxis:function(e,g){var h,i,j,k,n,m,o,r;h=e.x();i=e.y();j=e.z();k=Math.sin(g);n=Math.cos(g);m=1-n;o=m*h;r=m*i;toxi.Matrix4x4.TEMP.set(o*h+n,o*i+k*j,o*j-k*i,0,o*i-k*j,r*i+n,r*j+k*h,0,o*j+k*i,r*j-k*h,m*j*j+n,0,0,0,0,1);return this.multiplySelf(toxi.Matrix4x4.TEMP)},
+rotateX:function(e){toxi.Matrix4x4.TEMP.identity();toxi.Matrix4x4.TEMP.matrix[1][1]=toxi.Matrix4x4.TEMP.matrix[2][2]=Math.cos(e);toxi.Matrix4x4.TEMP.matrix[2][1]=Math.sin(e);toxi.Matrix4x4.TEMP.matrix[1][2]=-toxi.Matrix4x4.TEMP.matrix[2][1];return this.multiplySelf(toxi.Matrix4x4.TEMP)},rotateY:function(e){toxi.Matrix4x4.TEMP.identity();toxi.Matrix4x4.TEMP.matrix[0][0]=toxi.Matrix4x4.TEMP.matrix[2][2]=Math.cos(e);toxi.Matrix4x4.TEMP.matrix[0][2]=Math.sin(e);toxi.Matrix4x4.TEMP.matrix[2][0]=-toxi.Matrix4x4.TEMP.matrix[0][2];
+return this.multiplySelf(toxi.Matrix4x4.TEMP)},rotateZ:function(e){toxi.Matrix4x4.TEMP.identity();toxi.Matrix4x4.TEMP.matrix[0][0]=toxi.Matrix4x4.TEMP.matrix[1][1]=Math.cos(e);toxi.Matrix4x4.TEMP.matrix[1][0]=Math.sin(e);toxi.Matrix4x4.TEMP.matrix[0][1]=-toxi.Matrix4x4.TEMP.matrix[1][0];return this.multiplySelf(toxi.Matrix4x4.TEMP)},scale:function(e,g,h){return(new toxi.Matrix4x4(this)).scaleSelf(e,g,h)},scaleSelf:function(e,g,h){if(e instanceof toxi.Vec3D){g=e.y;h=e.z;e=e.x}else if(g===undefined||
+h===undefined)h=g=e;toxi.Matrix4x4.TEMP.identity();toxi.Matrix4x4.TEMP.matrix[0][0]=e;toxi.Matrix4x4.TEMP.matrix[1][1]=g;toxi.Matrix4x4.TEMP.matrix[2][2]=h;return this.multiplySelf(toxi.Matrix4x4.TEMP)},set:function(e,g,h,i,j,k,n,m,o,r,s,u,A,B,D,C){if(typeof e=="number"){var t=this.matrix[0];t[0]=e;t[1]=g;t[2]=h;t[3]=i;t=this.matrix[1];t[0]=j;t[1]=k;t[2]=n;t[3]=m;t=this.matrix[2];t[0]=o;t[1]=r;t[2]=s;t[3]=u;t=this.matrix[3];t[0]=A;t[1]=B;t[2]=D;t[3]=C}else for(o=0;o<4;o++){A=this.matrix[o];B=t.matrix[o];
+A[0]=B[0];A[1]=B[1];A[2]=B[2];A[3]=B[3]}return this},sub:function(e){return(new toxi.Matrix4x4(this)).subSelf(e)},subSelf:function(e){for(var g=0;g<4;g++){var h=this.matrix[g],i=e.matrix[g];h[0]-=i[0];h[1]-=i[1];h[2]-=i[2];h[3]-=i[3]}return this},toArray:function(e){if(e===undefined)e=[];for(var g=0,h=0;g<4;g++)for(var i=this.matrix[g],j=0;j<4;j++)e[h++]=i[j];return e},toFloatArray:function(e){return toArray(e)},toString:function(){return"| "+this.matrix[0][0]+" "+this.matrix[0][1]+" "+this.matrix[0][2]+
+" "+this.matrix[0][3]+" |\n| "+this.matrix[1][0]+" "+this.matrix[1][1]+" "+this.matrix[1][2]+" "+this.matrix[1][3]+" |\n| "+this.matrix[2][0]+" "+this.matrix[2][1]+" "+this.matrix[2][2]+" "+this.matrix[2][3]+" |\n| "+this.matrix[3][0]+" "+this.matrix[3][1]+" "+this.matrix[3][2]+" "+this.matrix[3][3]+" |"},toTransposedFloatArray:function(e){if(e===undefined)e=[];for(var g=0,h=0;g<4;g++)for(var i=0;i<4;i++)e[h++]=this.matrix[i][g];return e},translate:function(e,g,h){return(new toxi.Matrix4x4(this)).translateSelf(e,
+g,h)},translateSelf:function(e,g,h){if(e instanceof toxi.Vec3D){g=e.y;h=e.z;e=e.x}toxi.Matrix4x4.TEMP.identity();toxi.Matrix4x4.TEMP.matrix[0][3]=e;toxi.Matrix4x4.TEMP.matrix[1][3]=g;toxi.Matrix4x4.TEMP.matrix[2][3]=h;return this.multiplySelf(toxi.Matrix4x4.TEMP)},transpose:function(){return this.set(this.matrix[0][0],this.matrix[1][0],this.matrix[2][0],this.matrix[3][0],this.matrix[0][1],this.matrix[1][1],this.matrix[2][1],this.matrix[3][1],this.matrix[0][2],this.matrix[1][2],this.matrix[2][2],this.matrix[3][2],
+this.matrix[0][3],this.matrix[1][3],this.matrix[2][3],this.matrix[3][3])}};toxi.Matrix4x4.TEMP=new toxi.Matrix4x4;toxi.Quaternion=function(e,g,h,i){if(arguments.length==4){this.w=e;this.x=g;this.y=h;this.z=i}else if(arguments.length==2){this.x=g.x;this.y=g.y;this.z=g.z;this.w=e}else if(arguments.length==1){this.w=q.w;this.x=q.x;this.y=q.y;this.z=q.z}};
+toxi.Quaternion.prototype={add:function(e){return new toxi.Quaternion(this.x+e.x,this.y+e.y,this.z+e.z,this.w+e.w)},addSelf:function(e){this.x+=e.x;this.y+=e.y;this.z+=e.z;return this},copy:function(){return new Quaternion(this.w,this.x,this.y,this.z)},dot:function(e){return this.x*e.x+this.y*e.y+this.z*e.z+this.w*e.w},getConjugate:function(){var e=new toxi.Quaternion;e.x=-this.x;e.y=-this.y;e.z=-this.z;e.w=w;return e},identity:function(){this.w=1;this.z=this.y=this.x=0;return this},interpolateTo:function(e,
+g,h){return arguments.length==3?this.copy().interpolateTo(e,h.interpolate(0,1,g)):this.copy().interpolateToSelf(e,g)},interpolateToSelf:function(e,g,h){if(arguments.length==3)g=h.interpolate(0,1,g);var i=undefined,j=undefined,k=toxi.MathUtils.clip(this.dot(e),-1,1);if(1-k>=toxi.MathUtils.EPS){j=Math.acos(k);var n=1/Math.sin(j);i=Math.sin(j*(1-g))*n;j=Math.sin(j*g)*n}else{i=1-g;j=g}if(k<0){this.w=i*this.w-j*e.w;this.x=i*this.x-j*e.x;this.y=i*this.y-j*e.y;this.z=i*this.z-j*e.z}else{this.w=i*w+j*e.w;
+this.x=i*x+j*e.x;this.y=i*y+j*e.y;this.z=i*z+j*e.z}return this},magnitude:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)},multiply:function(e){var g=new toxi.Quaternion;g.w=this.w*e.w-x*e.x-y*e.y-z*e.z;g.x=this.w*e.x+x*e.w+y*e.z-z*e.y;g.y=this.w*e.y+y*e.w+z*e.x-x*e.z;g.z=this.w*e.z+z*e.w+x*e.y-y*e.x;return g},normalize:function(){var e=Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w);if(e>toxi.MathUtils.EPS){e=1/e;this.x*=e;this.y*=e;this.z*=
+e;this.w*=e}return this},scale:function(e){return new toxi.Quaternion(this.x*e,this.y*e,this.z*e,this.w*e)},scaleSelf:function(e){this.x*=e;this.y*=e;this.z*=e;this.w*=e;return this},set:function(e,g,h,i){if(arguments.length==4){this.w=e;this.x=g;this.y=h;this.z=i}else if(arguments.length==2){this.w=e;this.x=v.x;this.y=v.y;this.z=v.z}else{this.w=q.w;this.x=q.x;this.y=q.y;this.z=q.z}return this},sub:function(e){return new toxi.Quaternion(this.x-e.x,this.y-e.y,this.z-e.z,this.w-e.w)},subSelf:function(e){this.x-=
+e.x;this.y-=e.y;this.z-=e.z;this.w-=e.w;return this},toArray:function(){return[this.w,this.x,this.y,this.z]},toAxisAngle:function(){var e=[],g=Math.sqrt(1-this.w*this.w);g=g<toxi.MathUtils.EPS?1:1/g;e[0]=Math.acos(this.w)*2;e[1]=this.x*g;e[2]=this.y*g;e[3]=this.z*g;return e},toMatrix4x4:function(e){if(e===undefined)e=new toxi.Matrix4x4;var g=this.x+this.x,h=this.y+this.y,i=this.z+this.z,j=this.x*g,k=this.x*h,n=this.x*i,m=this.y*h,o=this.y*i,r=this.z*i;g=this.w*g;h=this.w*h;i=this.w*i;return e.set(1-
+(m+r),k-i,n+h,0,k+i,1-(j+r),o-g,0,n-h,o+g,1-(j+m),0,0,0,0,1)},toString:function(){return"{axis: ["+this.x+","+this.y+","+this.z+"], w: "+this.w+"}"}};toxi.Quaternion.DOT_THRESHOLD=0.9995;toxi.Quaternion.createFromAxisAngle=function(e,g){g*=0.5;var h=toxi.MathUtils.sin(g),i=toxi.MathUtils.cos(g);return new toxi.Quaternion(i,e.getNormalizedTo(h))};
+toxi.Quaternion.createFromEuler=function(e,g,h){e*=0.5;g*=0.5;h*=0.5;var i=toxi.MathUtils.sin(e);cosPitch=toxi.MathUtils.cos(e);sinYaw=toxi.MathUtils.sin(g);cosYaw=toxi.MathUtils.cos(g);sinRoll=toxi.MathUtils.sin(h);cosRoll=toxi.MathUtils.cos(h);e=cosPitch*cosYaw;g=i*sinYaw;h=new toxi.Quaternion;h.x=sinRoll*e-cosRoll*g;h.y=cosRoll*i*cosYaw+sinRoll*cosPitch*sinYaw;h.z=cosRoll*cosPitch*sinYaw-sinRoll*i*cosYaw;h.w=cosRoll*e+sinRoll*g;return h};
+toxi.Quaternion.createFromMatrix=function(e){var g=0,h=[],i=e.matrix[0][0]+e.matrix[1][1]+e.matrix[2][2];if(i>0){g=Math.sqrt(i+1);h[3]=g*0.5;g=0.5/g;h[0]=e.matrix[1][2]-e.matrix[2][1]*g;h[1]=e.matrix[2][0]-e.matrix[0][2]*g;h[2]=e.matrix[0][1]-e.matrix[1][0]*g}else{g=[1,2,0];var j=i=0,k=0;if(e.matrix[1][1]>e.matrix[0][0])i=1;if(e.matrix[2][2]>e.matrix[i][i])i=2;j=g[i];k=g[j];g=Math.sqrt(e.matrix[i][i]-(e.matrix[j][j]+e.matrix[k][k])+1);h[i]=g*0.5;g=0.5/g;h[3]=(e.matrix[j][k]-e.matrix[k][j])*g;h[j]=
+(e.matrix[i][j]+e.matrix[j][i])*g;h[k]=(e.matrix[i][k]+e.matrix[k][i])*g}return new toxi.Quaternion(h[3],h[0],h[1],h[2])};toxi.Quaternion.getAlignmentQuat=function(e,g){var h=e.getNormalized(),i=g.cross(h),j=i.magnitude()+1.0E-4;h=Math.atan2(j,g.dot(h));return this.createFromAxisAngle(i,h)};toxi.Vertex=function(e,g){this.parent.init.call(this,e);this.id=g;this.normal=new toxi.Vec3D};toxi.Vertex.prototype=new toxi.Vec3D;toxi.Vertex.constructor=toxi.Vertex;toxi.Vertex.prototype.parent=toxi.Vec3D.prototype;
+toxi.Vertex.prototype.addFaceNormal=function(e){this.normal.addSelf(e)};toxi.Vertex.prototype.clearNormal=function(){this.normal.clear()};toxi.Vertex.prototype.computeNormal=function(){this.normal.normalize()};toxi.Vertex.prototype.toString=function(){return this.id+": p: "+this.parent.toString.call(this)+" n:"+this.normal.toString()};
+toxi.Face=function(e,g,h,i,j,k){this.a=e;this.b=g;this.c=h;this.normal=this.a.sub(this.c).crossSelf(this.a.sub(this.b)).normalize();this.a.addFaceNormal(this.normal);this.b.addFaceNormal(this.normal);this.c.addFaceNormal(this.normal);if(i!==undefined){this.uvA=i;this.uvB=j;this.uvC=k}};
+toxi.Face.prototype={computeNormal:function(){this.normal=this.a.sub(this.c).crossSelf(this.a.sub(this.b)).normalize()},flipVertexOrder:function(){var e=this.a;this.a=this.b;this.b=e;this.normal.invert()},getCentroid:function(){return this.a.add(this.b).addSelf(this.c).scale(1/3)},getClass:function(){return"toxi.Face"},getVertices:function(e){if(e!=null){e[0]=this.a;e[1]=this.b;e[2]=this.c}else e=[this.a,this.b,this.c];return e},toString:function(){return this.getClass()+" "+this.a+", "+this.b+", "+
+this.c},toTriangle:function(){return new toxi.Triangle3D(this.a.copy(),this.b.copy(),this.c.copy())}};toxi.Mesh3D=function(){};toxi.TriangleMesh=function(e){if(e===undefined)e="untitled";this.setName(e);this.vertices=[];this.faces=[];this.numFaces=this.numVertices=0;this.uniqueVertexID=-1;return this};toxi.TriangleMesh.DEFAULT_NUM_VERTICES=1E3;toxi.TriangleMesh.DEFAULT_NUM_FACES=3E3;toxi.TriangleMesh.DEFAULT_STRIDE=4;
+toxi.TriangleMesh.prototype={addFace:function(e,g,h,i,j,k,n){if(n===undefined)if(k===undefined){if(j===undefined)i=undefined;n=k=j=undefined}else{n=k;k=j;j=i}var m=this.checkVertex(e),o=this.checkVertex(g),r=this.checkVertex(h);if(m.id==o.id||m.id==r.id||o.id==r.id)console.log("ignoring invalid face: "+e+", "+g+", "+h);else{if(i!=undefined){e=m.sub(r).crossSelf(m.sub(o));if(i.dot(e)<0){i=m;m=o;o=i}}this.faces.push(new toxi.Face(m,o,r,j,k,n));this.numFaces++}return this},addMesh:function(e){for(var g=
+e.getFaces().length,h=0;h<g;h++){var i=e.getFaces()[h];this.addFace(i.a,i.b,i.c)}return this},center:function(e){this.computeCentroid();e=e!=undefined?e.sub(this.centroid):this.centroid.getInverted();for(var g=this.vertices.length,h=0;h<g;h++)this.vertices[h].addSelf(e);this.getBoundingBox();return this.bounds},checkVertex:function(e){var g=this.vertices[e];if(g===undefined){g=this.createVertex(e,this.uniqueVertexID++);this.vertices.push(g);this.numVertices++}return g},clear:function(){this.vertices=
+[];this.faces=[];this.bounds=undefined;this.numFaces=this.numVertices=0;return this},computeCentroid:function(){this.centroid.clear();for(var e=this.vertices.length,g=0;g<e;g++)this.centroid.addSelf(this.vertices[g]);return this.centroid.scaleSelf(1/this.numVertices).copy()},computeFaceNormals:function(){for(var e=this.faces.length,g=0;g<e;g++)this.faces[g].computeNormal()},computeVertexNormals:function(){for(var e=this.vertices.length,g=0;g<e;g++)this.vertices[g].clearNormal();e=this.faces.length;
+for(g=0;g<e;g++){var h=this.faces[g];h.a.addFaceNormal(h);h.b.addFaceNormal(h);h.c.addFaceNormal(h)}e=this.vertices.length;for(g=0;g<e;g++)this.vertices[g].computeNormal();return this},copy:function(){for(var e=new toxi.TriangleMesh(this.name+"-copy",this.numVertices,this.numFaces),g=this.faces.length,h=0;h<g;h++){var i=this.faces[h];e.addFace(i.a,i.b,i.c,i.normal,i.uvA,i.uvB,i.uvC)}return e},createVertex:function(e,g){return new toxi.Vertex(e,g)},faceOutwards:function(){this.computeCentroid();for(var e=
+this.faces.length,g=0;g<e;g++){var h=this.faces[g];h.getCentroid().sub(this.centroid).dot(h.normal)<0&&h.flipVertexOrder()}return this},flipVertexOrder:function(){for(var e=this.faces.length,g=0;g<e;g++){var h=this.faces[g],i=h.a;h.a=h.b;h.b=i;h.normal.invert()}return this},flipYAxis:function(){this.transform((new Matrix4x4).scaleSelf(1,-1,1));this.flipVertexOrder();return this},getBoundingBox:function(){for(var e=toxi.Vec3D.MAX_VALUE.copy(),g=toxi.Vec3D.MIN_VALUE.copy(),h=this.vertices.length,i=
+0;i<h;i++){this.minBounds.minSelf(v);this.maxBounds.maxSelf(v)}return this.bounds=toxi.AABB.fromMinMax(e,g)},getBoundingSphere:function(){var e=0;this.computeCentroid();for(var g=this.vertices.length,h=0;h<g;h++)e=toxi.MathUtils.max(e,this.vertices[h].distanceToSquared(this.centroid));return new toxi.Sphere(this.centroid,Math.sqrt(e))},getClosestVertexToPoint:function(e){for(var g=undefined,h=Number.MAX_VALUE,i=this.vertices.length,j=0;j<i;j++){var k=this.vertices[j],n=k.distanceToSquared(e);if(n<
+h){g=k;h=n}}return g},getFaceNormalsAsArray:function(){return this.getFaceNormalsAsArray(undefined,0,toxi.TriangleMesh.DEFAULT_STRIDE)},getFaceNormalsAsArray:function(e,g,h){h=toxi.MathUtils.max(h,3);if(e==undefined)e=[];g=g;var i=this.faces.length;for(g=0;g<i;g++){var j=this.faces[g];e[g]=j.normal.x;e[g+1]=j.normal.y;e[g+2]=j.normal.z;g+=h;e[g]=j.normal.x;e[g+1]=j.normal.y;e[g+2]=j.normal.z;g+=h;e[g]=j.normal.x;e[g+1]=j.normal.y;e[g+2]=j.normal.z;g+=h}return e},getFaces:function(){return this.faces},
+getFacesAsArray:function(){var e=[],g=0,h=this.faces.length;for(g=0;g<h;g++){var i=this.faces[g];e[g++]=i.a.id;e[g++]=i.b.id;e[g++]=i.c.id}return e},getIntersectionData:function(){return this.intersector.getIntersectionData()},getMeshAsVertexArray:function(e,g,h){if(e===undefined)e=undefined;if(h===undefined)h=toxi.TriangleMesh.DEFAULT_STRIDE;h=toxi.MathUtils.max(h,3);if(e==undefined)e=[];g=0;for(var i=this.faces.length,j=0;j<i;++j){var k=this.faces[j];e[g]=k.a.x;e[g+1]=k.a.y;e[g+2]=k.a.z;g+=h;e[g]=
+k.b.x;e[g+1]=k.b.y;e[g+2]=k.b.z;g+=h;e[g]=k.c.x;e[g+1]=k.c.y;e[g+2]=k.c.z;g+=h}return e},getNumFaces:function(){return this.numFaces},getNumVertices:function(){return this.numVertices},getRotatedAroundAxis:function(e,g){return this.copy().rotateAroundAxis(e,g)},getRotatedX:function(e){return this.copy().rotateX(e)},getRotatedY:function(e){return this.copy().rotateY(e)},getRotatedZ:function(e){return this.copy().rotateZ(e)},getScaled:function(e){return this.copy().scale(e)},getScaled:function(e){return this.copy().scale(e)},
+getTranslated:function(e){return this.copy().translate(e)},getUniqueVerticesAsArray:function(){var e=[],g=0,h=this.vertices.length;for(g=0;g<h;g++){var i=this.vertices[g];e[g++]=i.x;e[g++]=i.y;e[g++]=i.z}return e},getVertexAtPoint:function(e){return this.vertices.get(e)},getVertexIndex:function(e){for(var g=this.vertices.length,h=0;h<g;h++)if(this.vertices[h].equals(e))matchedVertex=h;return matchedVertex},getVertexForID:function(e){for(var g=undefined,h=this.vertices.length,i=0;i<h;i++){var j=this.vertices[i];
+if(j.id==e){g=j;break}}return g},getVertexNormalsAsArray:function(e,g,h){if(g===undefined)g=0;if(h===undefined)h=toxi.TriangleMesh.DEFAULT_STRIDE;h=toxi.MathUtils.max(h,3);if(e==undefined)e=[];g=g;for(var i=this.faces.length,j=0;j<i;j++){var k=this.faces[j];e[g]=k.a.normal.x;e[g+1]=k.a.normal.y;e[g+2]=k.a.normal.z;g+=h;e[g]=k.b.normal.x;e[g+1]=k.b.normal.y;e[g+2]=k.b.normal.z;g+=h;e[g]=k.c.normal.x;e[g+1]=k.c.normal.y;e[g+2]=k.c.normal.z;g+=h}return e},getVertices:function(){return this.vertices},
+handleSaveAsSTL:function(){console.log("toxi.TriangleMesh.handleSaveAsSTL() currently not implemented")},intersectsRay:function(e){for(var g=this.intersector.getTriangle(),h=this.faces.length,i=0;i<h;i++){g.a=f.a;g.b=f.b;g.c=f.c;if(this.intersector.intersectsRay(e))return true}return false},perforateFace:function(e,g){var h=e.getCentroid(),i=1-g,j=e.a.interpolateTo(h,i),k=e.b.interpolateTo(h,i);h=e.c.interpolateTo(h,i);this.removeFace(e);this.addFace(e.a,k,j);this.addFace(e.a,e.b,k);this.addFace(e.b,
+h,k);this.addFace(e.b,e.c,h);this.addFace(e.c,j,h);this.addFace(e.c,e.a,j);return new toxi.Triangle3D(j,k,h)},pointTowards:function(e){return this.transform(toxi.Quaternion.getAlignmentQuat(e,toxi.Vec3D.Z_AXIS).toMatrix4x4(),true)},removeFace:function(e){for(var g=-1,h=this.faces.length,i=0;i<h;i++)if(this.faces[i]==e){g=i;break}g>-1&&this.faces.splice(g,1)},rotateAroundAxis:function(e,g){return this.transform(this.matrix.identity().rotateAroundAxis(e,g))},rotateX:function(e){return this.transform(this.matrix.identity().rotateX(e))},
+rotateY:function(e){return this.transform(this.matrix.identity().rotateY(e))},rotateZ:function(e){return this.transform(this.matrix.identity().rotateZ(e))},saveAsOBJ:function(){console.log("toxi.TriangleMesh.saveAsOBJ() currently not implemented")},saveAsSTL:function(){console.log("toxi.TriangleMesh.saveAsSTL() currently not implemented")},scale:function(e){return this.transform(this.matrix.identity().scaleSelf(e))},setName:function(e){this.name=e;return this},toString:function(){return"toxi.TriangleMesh: "+
+this.name+" vertices: "+this.getNumVertices()+" faces: "+this.getNumFaces()},toWEMesh:function(){console.log("toxi.TriangleMesh.toWEMesh() currently not implemented")},transform:function(e,g){if(g===undefined)g=true;for(var h=this.vertices.length,i=0;i<h;i++){var j=this.vertices[i];j.set(e.applyTo(j))}g&&this.computeFaceNormals();return this},translate:function(e){return this.transform(this.matrix.identity().translateSelf(e))},updateVertex:function(e,g){var h=this.getVertexIndex(e);if(h>-1){this.vertices.splice(v,
+1);this.vertices[h].set(g);this.vertices.push(v)}return this}};toxi.Sphere=function(e,g){if(e===undefined){this.parent.init.call(this,new toxi.Vec3D);this.radius=1}else if(e instanceof toxi.Vec3D){this.parent.init.call(this,e);this.radius=e instanceof toxi.Sphere?e.radius:g}else{this.parent.init.call(this,new toxi.Vec3D);this.radius=e}};toxi.Sphere.prototype=new toxi.Vec3D;toxi.Sphere.constructor=toxi.Sphere;toxi.Sphere.prototype.parent=toxi.Vec3D.prototype;
+toxi.Sphere.prototype.containsPoint=function(e){return this.sub(e).magSquared()<=this.radius*this.radius};toxi.Sphere.prototype.intersectRay=function(e){var g=null,h=e.sub(this),i=h.magSquared();v=-h.dot(e.getDirection());d=this.radius*this.radius-(i-v*v);if(d>=0){d=Math.sqrt(d);a=v+d;b=v-d;if(!(a<0&&b<0))if(a>0&&b>0){if(a>b){e=a;a=b;b=e}}else if(b>0){e=a;a=b;b=e}g=[a,b]}return g};
+toxi.Sphere.prototype.intersectSphereTriangle=function(e,g){g.set(e.closestPointOnSurface(this));return g.sub(this).magSquared()<=this.radius*this.radius};toxi.Sphere.prototype.tangentPlaneNormalAt=function(e){return this.sub(e).normalize()};toxi.Sphere.prototype.toMesh=function(e,g){if(g===undefined){var h=null;g=e}else h=e;return(new toxi.SurfaceMeshBuilder(new toxi.SphereFunction(this))).createMesh(h,g,1)};toxi.VertexSelector=function(e){this.init(e)};
+toxi.VertexSelector.prototype={init:function(e){this.mesh=e;this.selection=[]},addSelection:function(e){this.checkMeshIdentity(e.getMesh());this.selection.addAll(e.getSelection());return this},checkMeshIdentity:function(e){if(e!=this.mesh)throw Error("The given selector is not using the same mesh instance");},clearSelection:function(){this.selection.clear();return this},getMesh:function(){return this.mesh},getSelection:function(){return this.selection},invertSelection:function(){for(var e=[],g=mesh.getVertices(),
+h=g.length,i=0;i<h;i++){var j=g[i];selection.contains(j)||e.add(j)}this.selection=e;return this},selectSimilar:function(e){for(var g=e.length,h=0;h<g;h++)this.selection.add(this.mesh.getClosestVertexToPoint(e[h]));return this},selectVertices:function(){return this},setMesh:function(e){this.mesh=e;this.clearSelection()},size:function(){return this.selection.size()},subtractSelection:function(e){this.checkMeshIdentity(e.getMesh());this.selection.removeAll(e.getSelection());return this}};
+toxi.BoxSelector=function(e,g){this.parent.init.call(this,e);this.box=g};toxi.BoxSelector.prototype.selectVertices=function(){this.clearSelection();for(var e=this.mesh.getVertices(),g=e.length,h=0;h<g;h++){var i=e[h];this.box.containsPoint(i)&&this.selection.add(i)}return this};toxi.BoxSelector.prototype=new toxi.VertexSelector;toxi.BoxSelector.constructor=toxi.BoxSelector;toxi.BoxSelector.prototype.parent=toxi.VertexSelector.prototype;toxi.DefaultSelector=function(e){this.parent.init.call(this,e)};
+toxi.DefaultSelector.prototype.selectVertices=function(){this.clearSelection();this.selection.addAll(this.mesh.getVertices());return this};toxi.DefaultSelector.prototype=new toxi.VertexSelector;toxi.DefaultSelector.constructor=toxi.DefaultSelector;toxi.DefaultSelector.prototype.parent=toxi.VertexSelector.prototype;toxi.PlaneSelector=function(e,g,h,i){this.parent.init.call(this,e);this.plane=g;this.classifier=h;this.tolerances=i===undefined?1.0E-4:i};
+toxi.PlaneSelector.prototype.selectVertices=function(){this.clearSelection();for(var e=this.mesh.getVertices(),g=e.length,h=0;h<g;h++){var i=e[h];this.plane.classifyPoint(i,this.tolerance)==this.classifier&&this.selection.add(i)}return this};toxi.PlaneSelector.prototype=new toxi.VertexSelector;toxi.PlaneSelector.constructor=toxi.PlaneSelector;toxi.PlaneSelector.prototype.parent=toxi.VertexSelector.prototype;
+toxi.SphereFunction=function(e){if(e===undefined)this.sphere=new toxi.Sphere(new toxi.Vec3D,1);this.sphere=e instanceof toxi.Sphere?e:new toxi.Sphere(new toxi.Vec3D,e);this.phiRange=toxi.MathUtils.PI;this.thetaRange=toxi.MathUtils.TWO_PI};
+toxi.SphereFunction.prototype={computeVertexFor:function(e,g,h){g-=toxi.MathUtils.HALF_PI;var i=toxi.MathUtils.cos(g),j=toxi.MathUtils.cos(h);g=toxi.MathUtils.sin(g);h=toxi.MathUtils.sin(h);i=toxi.MathUtils.sign(i)*toxi.MathUtils.abs(i);e.x=i*toxi.MathUtils.sign(j)*toxi.MathUtils.abs(j);e.y=toxi.MathUtils.sign(g)*toxi.MathUtils.abs(g);e.z=i*toxi.MathUtils.sign(h)*toxi.MathUtils.abs(h);return e.scaleSelf(this.sphere.radius).addSelf(this.sphere)},getPhiRange:function(){return this.phiRange},getPhiResolutionLimit:function(e){return e},
+getThetaRange:function(){return this.thetaRange},getThetaResolutionLimit:function(e){return e},setMaxPhi:function(e){this.phiRange=toxi.MathUtils.min(e/2,toxi.MathUtils.PI)},setMaxTheta:function(e){this.thetaRange=toxi.MathUtils.min(e,toxi.MathUtils.TWO_PI)}};toxi.SphericalHarmonics=function(e){this.m=e};
+toxi.SphericalHarmonics.prototype={computeVertexFor:function(e,g,h){var i=0;i+=Math.pow(toxi.MathUtils.sin(this.m[0]*h),this.m[1]);i+=Math.pow(toxi.MathUtils.cos(this.m[2]*h),this.m[3]);i+=Math.pow(toxi.MathUtils.sin(this.m[4]*g),this.m[5]);i+=Math.pow(toxi.MathUtils.cos(this.m[6]*g),this.m[7]);var j=toxi.MathUtils.sin(h);e.x=i*j*toxi.MathUtils.cos(g);e.y=i*toxi.MathUtils.cos(h);e.z=i*j*toxi.MathUtils.sin(g);return e},getPhiRange:function(){return toxi.MathUtils.TWO_PI},getPhiResolutionLimit:function(e){return e},
+getThetaRange:function(){return toxi.MathUtils.PI},getThetaResolutionLimit:function(e){return e}};toxi.SuperEllipsoid=function(e,g){this.p1=e;this.p2=g};
+toxi.SuperEllipsoid.prototype={computeVertexFor:function(e,g,h){g-=toxi.MathUtils.HALF_PI;var i=toxi.MathUtils.cos(g),j=toxi.MathUtils.cos(h);g=toxi.MathUtils.sin(g);h=toxi.MathUtils.sin(h);i=toxi.MathUtils.sign(i)*Math.pow(toxi.MathUtils.abs(i),this.p1);e.x=i*toxi.MathUtils.sign(j)*Math.pow(Math.abs(j),this.p2);e.y=toxi.MathUtils.sign(g)*Math.pow(Math.abs(g),this.p1);e.z=i*toxi.MathUtils.sign(h)*Math.pow(toxi.MathUtils.abs(h),this.p2);return e},getPhiRange:function(){return toxi.MathUtils.TWO_PI},
+getPhiResolutionLimit:function(e){return e/2},getThetaRange:function(){return toxi.MathUtils.TWO_PI},getThetaResolutionLimit:function(e){return e}};toxi.SurfaceMeshBuilder=function(e){this.func=e};
+toxi.SurfaceMeshBuilder.prototype={createMesh:function(e,g,h,i){if(e==null)e=undefined;if(g===undefined){g=e;e=new toxi.TriangleMesh}else{e=e;g=g}if(e===undefined)e=new toxi.TriangleMesh;if(h===undefined)h=1;if(i===undefined)i=true;for(var j=new toxi.Vec3D,k=new toxi.Vec3D,n=new toxi.Vec3D,m=new toxi.Vec3D,o=new toxi.Vec3D,r=new toxi.Vec3D,s=this.func.getPhiResolutionLimit(g),u=this.func.getPhiRange(),A=this.func.getThetaResolutionLimit(g),B=this.func.getThetaRange(),D=1/(1==g%2?g-0:g),C=0;C<s;C++)for(var t=
+C*u*D,H=(C+1)*u*D,E=0;E<=A;E++){var F=E*B/g,G=this.func;j=G.computeVertexFor(j,H,F).scaleSelf(h);k=G.computeVertexFor(k,t,F).scaleSelf(h);k.distanceTo(j)<1.0E-4&&k.set(j);if(E>0){if(E==A&&i){j.set(o);k.set(r)}e.addFace(n,m,j);e.addFace(m,k,j)}else{o.set(j);r.set(k)}n.set(j);m.set(k)}return e},getFunction:function(){return this.func},setFunction:function(e){this.func=e}};toxi.AxisAlignedCylinder=function(e,g,h){this.init(e,g,h)};
+toxi.AxisAlignedCylinder.prototype={init:function(e,g,h){this.pos=e===undefined?undefined:e.copy();this.setRadius(g);this.setLength(h)},containsPoint:function(){throw Error("AxisAlignedCylinder.containsPoint(): not implmented");},getLength:function(){return this.length},getMajorAxis:function(){throw Error("AxisAlignedCylinder.getMajorAxis(): not implemented");},getPosition:function(){return this.pos.copy()},getRadius:function(){return this.radius},setLength:function(e){this.length=e},setPosition:function(e){this.pos.set(e)},
+setRadius:function(e){this.radius=e;this.radiusSquared=e*e},toMesh:function(e,g,h){if(e===undefined)return(new toxi.Cone(this.pos,this.getMajorAxis().getVector(),this.radius,this.radius,this.length)).toMesh(null,12,0,true,true);else if(e instanceof toxi.TriangleMesh3D)return(new toxi.Cone(this.pos,this.getMajorAxis().getVector(),this.radius,this.radius,this.length)).toMesh(e,g,h,true,true);return(new toxi.Cone(this.pos,this.getMajorAxis().getVector(),this.radius,this.radius,this.length)).toMesh(null,
+e,g,true,true)}};toxi.AABB=function(e,g){if(e===undefined){this.parent.init.call(this);this.setExtent(new toxi.Vec3D)}else if(typeof e=="number"){this.parent.init.call(new toxi.Vec3D);this.setExtent(e)}else if(e instanceof toxi.Vec3D){this.parent.init.call(this,e);if(g===undefined&&e instanceof toxi.AABB)this.setExtent(e.getExtent());else typeof g=="number"?this.setExtent(new toxi.Vec3D(g,g,g)):this.setExtent(g)}};
+toxi.AABB.fromMinMax=function(e,g){var h=toxi.Vec3D.min(e),i=toxi.Vec3D.max(g);return new toxi.AABB(h.interpolateTo(i,0.5),i.sub(h).scaleSelf(0.5))};toxi.AABB.prototype=new toxi.Vec3D;toxi.AABB.prototype.constructor=toxi.AABB;toxi.AABB.prototype.parent=toxi.Vec3D.prototype;toxi.AABB.prototype.containsPoint=function(e){return e.isInAABB(this)};toxi.AABB.prototype.copy=function(){return new toxi.AABB(this)};toxi.AABB.prototype.getExtent=function(){return this.extent.copy()};
+toxi.AABB.prototype.getMax=function(){return this.max.copy()};toxi.AABB.prototype.getMin=function(){return this.min.copy()};toxi.AABB.prototype.getNormalForPoint=function(e){e=e.sub(this);var g=this.extent.sub(e.getAbs());e=e.getSignum();var h=Vec3D.X_AXIS.scale(e.x),i=g.x;if(g.y<i){i=g.y;h=Vec3D.Y_AXIS.scale(e.y)}if(g.z<i)h=Vec3D.Z_AXIS.scale(e.z);return h};
+toxi.AABB.prototype.includePoint=function(e){this.min.minSelf(e);this.max.maxSelf(e);this.set(this.min.interpolateTo(this.max,0.5));this.extent.set(this.max.sub(this.min).scaleSelf(0.5));return this};toxi.AABB.prototype.intersectsBox=function(e){var g=e.sub(this);return Math.abs(g.x)<=this.extent.x+e.extent.x&&Math.abs(g.y)<=this.extent.y+e.extent.y&&Math.abs(g.z)<=this.extent.z+e.extent.z};
+toxi.AABB.prototype.intersectsRay=function(e,g,h){var i=e.getDirection().reciprocal(),j=i.x<0,k=i.y<0,n=i.z<0,m=j?this.max:this.min,o=(m.x-e.x)*i.x;m=j?this.min:this.max;j=(m.x-e.x)*i.x;m=k?this.max:this.min;var r=(m.y-e.y)*i.y;m=k?this.min:this.max;m=(m.y-e.y)*i.y;if(o>m||r>j)return null;if(r>o)o=r;if(m<j)j=m;m=n?max:min;k=(m.z-e.z)*i.z;m=n?min:max;i=(m.z-e.z)*i.z;if(o>i||k>j)return null;if(k>o)o=k;if(i<j)j=i;if(o<h&&j>g)return e.getPointAtDistance(o)};
+toxi.AABB.prototype.intersectsSphere=function(e,g){if(arguments.length>1)g=e.radius;var h=undefined,i=0;if(e.x<this.min.x){h=e.x-this.min.x;i=h*h}else if(e.x>this.max.x){h=e.x-this.max.x;i+=h*h}if(e.y<this.min.y){h=e.y-this.min.y;i+=h*h}else if(e.y>this.max.y){h=e.y-this.max.y;i+=h*h}if(e.z<this.min.z){h=e.z-this.min.z;i+=h*h}else if(e.z>this.max.z){h=e.z-this.max.z;i+=h*h}return i<=g*g};
+toxi.AABB.prototype.intersectsTriangle=function(e){var g=undefined,h=undefined,i=undefined,j=h=undefined,k=undefined,n=undefined,m=undefined;g=e.a.sub(this);h=e.b.sub(this);i=e.c.sub(this);j=h.sub(g);k=i.sub(h);n=g.sub(i);m=j.getAbs();if(this.testAxis(j.z,-j.y,m.z,m.y,g.y,g.z,i.y,i.z,this.extent.y,this.extent.z))return false;if(this.testAxis(-j.z,j.x,m.z,m.x,g.x,g.z,i.x,i.z,this.extent.x,this.extent.z))return false;if(this.testAxis(j.y,-j.x,m.y,m.x,h.x,h.y,i.x,i.y,this.extent.x,this.extent.y))return false;
+m=k.getAbs();if(this.testAxis(k.z,-k.y,m.z,m.y,g.y,g.z,i.y,i.z,this.extent.y,this.extent.z))return false;if(this.testAxis(-k.z,k.x,m.z,m.x,g.x,g.z,i.x,i.z,this.extent.x,this.extent.z))return false;if(this.testAxis(k.y,-k.x,m.y,m.x,g.x,g.y,h.x,h.y,this.extent.x,this.extent.y))return false;m=n.getAbs();if(this.testAxis(n.z,-n.y,m.z,m.y,g.y,g.z,h.y,h.z,this.extent.y,this.extent.z))return false;if(this.testAxis(-n.z,n.x,m.z,m.x,g.x,g.z,h.x,h.z,this.extent.x,this.extent.z))return false;if(this.testAxis(n.y,
+-n.x,m.y,m.x,h.x,h.y,i.x,i.y,this.extent.x,this.extent.y))return false;if(toxi.MathUtils.min(g.x,h.x,i.x)>this.extent.x||toxi.MathUtils.max(g.x,h.x,i.x)<-this.extent.x)return false;if(toxi.MathUtils.min(g.y,h.y,i.y)>this.extent.y||toxi.MathUtils.max(g.y,h.y,i.y)<-this.extent.y)return false;if(toxi.MathUtils.min(g.z,h.z,i.z)>this.extent.z||toxi.MathUtils.max(g.z,h.z,i.z)<-this.extent.z)return false;h=j.cross(k);e=-h.dot(g);if(!this.planeBoxOverlap(h,e,extent))return false;return true};
+toxi.AABB.prototype.planeBoxOverlap=function(e,g,h){var i=new toxi.Vec3D,j=new toxi.Vec3D;if(e.x>0){i.x=-h.x;j.x=h.x}else{i.x=h.x;j.x=-h.x}if(e.y>0){i.y=-h.y;j.y=h.y}else{i.y=h.y;j.y=-h.y}if(e.z>0){i.z=-h.z;j.z=h.z}else{i.z=h.z;j.z=-h.z}if(e.dot(i)+g>0)return false;if(e.dot(j)+g>=0)return true;return false};
+toxi.AABB.prototype.set=function(e,g,h){if(typeof e==toxi.AABB){this.extent.set(e.extent);return this.parent.set.call(this,e)}if(typeof e==toxi.Vec3D){g=e.y;h=e.z;e=e.a}this.x=e;this.y=g;this.z=h;this.updateBounds();return this};toxi.AABB.prototype.setExtent=function(e){this.extent=e.copy();return this.updateBounds()};toxi.AABB.prototype.testAxis=function(e,g,h,i,j,k,n,m,o,r){j=e*j+g*k;g=e*n+g*m;if(j<g){e=j;g=g}else{e=g;g=j}h=h*o+i*r;return e>h||g<-h};
+toxi.AABB.prototype.toMesh=function(e){if(e===undefined)e=new toxi.TriangleMesh("aabb",8,12);var g=new toxi.Vec3D(this.min.x,this.max.y,this.max.z),h=new toxi.Vec3D(this.max.x,this.max.y,this.max.z),i=new toxi.Vec3D(this.max.x,this.min.y,this.max.z),j=new toxi.Vec3D(this.min.x,this.min.y,this.max.z),k=new toxi.Vec3D(this.min.x,this.max.y,this.min.z),n=new toxi.Vec3D(this.max.x,this.max.y,this.min.z),m=new toxi.Vec3D(this.max.x,this.min.y,this.min.z),o=new toxi.Vec3D(this.min.x,this.min.y,this.min.z);
+e.addFace(g,h,j,undefined,undefined,undefined,undefined);e.addFace(h,i,j,undefined,undefined,undefined,undefined);e.addFace(n,k,m,undefined,undefined,undefined,undefined);e.addFace(k,o,m,undefined,undefined,undefined,undefined);e.addFace(k,n,g,undefined,undefined,undefined,undefined);e.addFace(n,h,g,undefined,undefined,undefined,undefined);e.addFace(m,o,j,undefined,undefined,undefined,undefined);e.addFace(m,j,i,undefined,undefined,undefined,undefined);e.addFace(k,g,o,undefined,undefined,undefined,
+undefined);e.addFace(g,j,o,undefined,undefined,undefined,undefined);e.addFace(h,n,m,undefined,undefined,undefined,undefined);e.addFace(h,m,i,undefined,undefined,undefined,undefined);return e};toxi.AABB.prototype.toString=function(){return"<aabb> pos: "+this.parent.toString()+" ext: "+this.extent.toString()};toxi.AABB.prototype.updateBounds=function(){if(this.extent!=undefined){this.min=this.sub(this.extent);this.max=this.add(this.extent)}return this};
+toxi.BezierPatch=function(e){this.points=e===undefined?[]:e;for(e=0;e<4;e++)for(var g=0;g<4;g++)this.points[e][g]=new toxi.Vec3D};
+toxi.BezierPatch.prototype={computePointAt:function(e,g){return this.computePointAt(e,g,this.points)},set:function(e,g,h){this.points[g][e].set(h);return this},toMesh:function(e,g){if(g===undefined){var h=new toxi.TriangleMesh;g=e}else h=e;for(var i=new toxi.Vec3D[g+1],j=new toxi.Vec3D[g+1],k=1/g,n=0;n<=g;n++){for(var m=0;m<=g;m++){var o=this.computePointAt(m*k,n*k,this.points);if(m>0&&n>0){h.addFace(o,i[m-1],j[m-1]);h.addFace(o,j[m-1],j[m])}i[m]=o}m=j;j=i;i=m}return h}};
+toxi.BezierPatch.computePointAt=function(e,g,h){var i=1-e,j=i*i*3*e,k=i*i*i,n=e*e,m=1-g,o=m*m*m,r=g*g*g;i=i*n*3;e=e*n;n=m*g*g*3;g=m*m*3*g;m=h[0];var s=h[1],u=h[2];h=h[3];return new toxi.Vec3D(k*(m[0].x*o+m[1].x*g+m[2].x*n+m[3].x*r)+j*(s[0].x*o+s[1].x*g+s[2].x*n+s[3].x*r)+i*(u[0].x*o+u[1].x*g+u[2].x*n+u[3].x*r)+e*(h[0].x*o+h[1].x*g+h[2].x*n+h[3].x*r),k*(m[0].y*o+m[1].y*g+m[2].y*n+m[3].y*r)+j*(s[0].y*o+s[1].y*g+s[2].y*n+s[3].y*r)+i*(u[0].y*o+u[1].y*g+u[2].y*n+u[3].y*r)+e*(h[0].y*o+h[1].y*g+h[2].y*n+
+h[3].y*r),k*(m[0].z*o+m[1].z*g+m[2].z*n+m[3].z*r)+j*(s[0].z*o+s[1].z*g+s[2].z*n+s[3].z*r)+i*(u[0].z*o+u[1].z*g+u[2].z*n+u[3].z*r)+e*(h[0].z*o+h[1].z*g+h[2].z*n+h[3].z*r))};toxi.XAxisCylinder=function(e,g,h){this.init(e,g,h)};toxi.XAxisCylinder.prototype=new toxi.AxisAlignedCylinder;toxi.XAxisCylinder.constructor=toxi.XAxisCylinder;toxi.XAxisCylinder.prototype.parent=toxi.AxisAlignedCylinder.prototype;
+toxi.XAxisCylinder.prototype.containsPoint=function(e){if(toxi.MathUtils.abs(e.x-this.pos.x)<this.length*0.5){var g=e.y-this.pos.y;e=e.z-this.pos.z;if(Math.abs(e*e+g*g)<this.radiusSquared)return true}return false};toxi.XAxisCylinder.prototype.getMajorAxis=function(){return toxi.Vec3D.Axis.X};toxi.XAxisCylinder.prototype.init=function(e,g,h){this.parent.init.call(this,e,g,h)};toxi.YAxisCylinder=function(e,g,h){this.init(e,g,h)};toxi.YAxisCylinder.prototype=new toxi.AxisAlignedCylinder;
+toxi.YAxisCylinder.constructor=toxi.YAxisCylinder;toxi.YAxisCylinder.prototype.parent=toxi.AxisAlignedCylinder.prototype;toxi.YAxisCylinder.prototype.containsPoint=function(e){if(toxi.MathUtils.abs(e.y-this.pos.y)<this.length*0.5){var g=e.x-this.pos.x;e=e.z-this.pos.z;if(Math.abs(e*e+g*g)<this.radiusSquared)return true}return false};toxi.YAxisCylinder.prototype.getMajorAxis=function(){return toxi.Vec3D.Axis.Y};toxi.YAxisCylinder.prototype.init=function(e,g,h){this.parent.init.call(this,e,g,h)};
+toxi.ZAxisCylinder=function(e,g,h){this.parent.init.call(this,e,g,h)};toxi.ZAxisCylinder.prototype=new toxi.AxisAlignedCylinder;toxi.ZAxisCylinder.constructor=toxi.ZAxisCylinder;toxi.ZAxisCylinder.prototype.parent=toxi.AxisAlignedCylinder.prototype;toxi.ZAxisCylinder.prototype.containsPoint=function(e){if(MathUtils.abs(e.z-this.pos.z)<this.length*0.5){var g=e.x-this.pos.x;e=e.y-this.pos.y;if(Math.abs(g*g+e*e)<this.radiusSquared)return true}return false};toxi.ZAxisCylinder.prototype.getMajorAxis=function(){return toxi.Vec3D.Axis.Z};
+toxi.Line3D=function(e,g){this.a=e;this.b=g};
+toxi.Line3D.prototype={closestLineTo:function(e){var g=e.a.sub(e.b);if(g.isZeroVector())return new toxi.Line3D.LineIntersection(toxi.Line3D.LineIntersection.Type.NON_INTERSECTING);var h=this.b.sub(this.a);if(h.isZeroVector())return new toxi.Line3D.LineIntersection(toxi.Line3D.LineIntersection.Type.NON_INTERSECTING);var i=this.a.sub(e.a),j=i.x*g.x+i.y*g.y+i.z*g.z,k=g.x*h.x+g.y*h.y+g.z*h.z;i=i.x*h.x+i.y*h.y+i.z*h.z;var n=g.x*g.x+g.y*g.y+g.z*g.z,m=(h.x*h.x+h.y*h.y+h.z*h.z)*n-k*k;if(Math.abs(m)<toxi.MathUtils.EPS)return new toxi.Line3D.LineIntersection(toxi.Line3D.LineIntersection.Type.NON_INTERSECTING);
+i=(j*k-i*n)/m;j=(j+k*i)/n;h=this.a.add(h.scaleSelf(i));e=e.a.add(g.scaleSelf(j));return new toxi.Line3D.LineIntersection(toxi.Line3D.LineIntersection.Type.INTERSECTING,new toxi.Line3D(h,e),i,j)},closestPointTo:function(e){var g=this.b.sub(this.a);e=e.sub(this.a).dot(g)/g.magSquared();if(e<0)return this.a.copy();else if(e>1)return this.b.copy();return this.a.add(g.scaleSelf(e))},copy:function(){return new toxi.Line3D(this.a.copy(),this.b.copy())},equals:function(e){if(this==e)return true;if(typeof e!=
+toxi.Line3D)return false;return(this.a.equals(e.a)||this.a.equals(l.b))&&(this.b.equals(l.b)||this.b.equals(l.a))},getDirection:function(){return this.b.sub(this.a).normalize()},getLength:function(){return this.a.distanceTo(this.b)},getLengthSquared:function(){return this.a.distanceToSquared(this.b)},getMidPoint:function(){return this.a.add(this.b).scaleSelf(0.5)},getNormal:function(){return this.b.cross(this.a)},hasEndPoint:function(e){return this.a.equals(e)||this.b.equals(e)},offsetAndGrowBy:function(e,
+g,h){var i=this.getMidPoint(),j=this.getDirection(),k=this.a.cross(j).normalize();h!=null&&i.sub(h).dot(k)<0&&k.invert();k.normalizeTo(e);this.a.addSelf(k);this.b.addSelf(k);j.scaleSelf(g);this.a.subSelf(j);this.b.addSelf(j);return this},set:function(e,g){this.a=e;this.b=g;return this},splitIntoSegments:function(e,g,h){return toxi.Line3D.splitIntoSegments(this.a,this.b,g,e,h)},toString:function(){return this.a.toString()+" -> "+this.b.toString()}};
+toxi.Line3D.splitIntoSegments=function(e,g,h,i,j){if(i==null)i=[];j&&i.push(e.copy());j=e.distanceTo(g);if(j>h){var k=e.copy();for(e=g.sub(e).limit(h);j>h;){k.addSelf(e);i.push(k.copy());j-=h}}i.push(g.copy());return i};toxi.Line3D.LineIntersection=function(e,g,h,i){this.type=e;if(h==null)h=0;if(i==null)i=0;this.line=g;this.coeff=[h,i]};
+toxi.Line3D.LineIntersection.prototype={getCoefficient:function(){return this.coeff},getLength:function(){if(this.line==null)return null;return this.line.getLength()},getLine:function(){if(this.line==null)return null;return this.line.copy()},getType:function(){return this.type},isIntersectionInside:function(){return this.type==toxi.Line3D.LineIntersection.Type.INTERSECTING&&this.coeff[0]>=0&&this.coeff[0]<=1&&this.coeff[1]>=0&&this.coeff[1]<=1},toString:function(){return"type: "+this.type+" line: "+
+this.line}};toxi.Line3D.LineIntersection.Type={};toxi.Line3D.LineIntersection.Type.NON_INTERSECTING=0;toxi.Line3D.LineIntersection.Type.INTERSECTING=1;toxi.Ray2D=function(e,g,h){if(typeof e=="Number"){e=new toxi.Vec2D(e,g);g=h.getNormalized()}else if(e instanceof toxi.Vec2D){e=e;g=g.getNormalized()}else{e=new toxi.Vec2D;g=toxi.Vec2D.Y_AXIS.copy()}this.parent.init.call(this,e);this.dir=g};toxi.Ray2D.prototype=new toxi.Vec2D;toxi.Ray2D.constructor=toxi.Ray2D;toxi.Ray2D.prototype.parent=toxi.Vec2D.prototype;
+toxi.Ray2D.prototype.getDirection=function(){return this.dir.copy()};toxi.Ray2D.prototype.getDistanceToPoint=function(e){e=e.sub(this);return e.distanceTo(this.dir.scale(e.dot(this.dir)))};toxi.Ray2D.prototype.getPointAtDistance=function(e){return this.add(this.dir.scale(e))};toxi.Ray2D.prototype.setDirection=function(e){this.dir.set(e).normalize();return this};toxi.Ray2D.prototype.toLine2DWithPointAtDistance=function(e){return new toxi.Line2D(this.copy(),this.getPointAtDistance(e))};
+toxi.Ray2D.prototype.toString=function(){return"origin: "+this.parent.toString.call(this)+" dir: "+this.dir};toxi.IsectData2D=function(e){if(e!==undefined){this.isIntersection=e.isIntersection;this.dist=e.dist;this.pos=e.pos.copy();this.dir=e.dir.copy();this.normal=e.normal.copy()}else this.clear()};
+toxi.IsectData2D.prototype={clear:function(){this.isIntersection=false;this.dist=0;this.pos=new toxi.Vec2D;this.dir=new toxi.Vec2D;this.normal=new toxi.Vec2D},toString:function(){var e="isec: "+this.isIntersection;if(this.isIntersection)e+=" at:"+this.pos+" dist:"+this.dist+" normal:"+this.normal;return e}};
View
33 build/toxi-physics2d.js
@@ -0,0 +1,33 @@
+// toxi-physics2d.js r33 - http://github.com/hapticdata/toxiclibsjs
+toxi.physics2d=toxi.physics2d||{};toxi.physics2d.removeItemFrom=function(a,b){var c=b.indexOf(a);if(c>-1)return b.splice(c,1)};toxi.physics2d.VerletParticle2D=function(a,b,c){this.force=new toxi.Vec2D;if(a instanceof toxi.Vec2D)if(a instanceof toxi.physics2d.VerletParticle2D){b=a.y;c=a.weight;a=a.x;this.isLocked=a.isLocked}else{if(b===undefined){b=a.y;c=1}else{c=b;b=a.y}a=a.x}this.isLocked=false;this.init(a,b);this.prev=new toxi.Vec2D(this);this.temp=new toxi.Vec2D;c=c===undefined?1:c;this.setWeight(c)};
+toxi.extend(toxi.physics2d.VerletParticle2D,toxi.Vec2D);toxi.physics2d.VerletParticle2D.prototype.addBehavior=function(a,b){if(this.behaviors===undefined)this.behaviors=[];if(a===undefined)throw{name:"TypeError",message:"behavior was undefined"};b=b===undefined?1:b;a.configure(b);this.behaviors.push(a);return this};toxi.physics2d.VerletParticle2D.prototype.addConstraint=function(a){if(this.constraints===undefined)this.constraints=[];this.constraints.push(a);return this};
+toxi.physics2d.VerletParticle2D.prototype.addForce=function(a){this.force.addSelf(a);return this};toxi.physics2d.VerletParticle2D.prototype.addVelocity=function(a){this.prev.subSelf(a);return this};toxi.physics2d.VerletParticle2D.prototype.applyBehaviors=function(){if(this.behaviors!==undefined){var a=0;for(a=0;a<this.behaviors.length;a++)this.behaviors[a].applyBehavior(this)}};
+toxi.physics2d.VerletParticle2D.prototype.applyConstraints=function(){if(this.constraints!==undefined){var a=0;for(a=0;a<this.constraints.length;a++)this.constraints[a].applyConstraint(this)}};toxi.physics2d.VerletParticle2D.prototype.clearForce=function(){this.force.clear();return this};toxi.physics2d.VerletParticle2D.prototype.clearVelocity=function(){this.prev.set(this);return this};toxi.physics2d.VerletParticle2D.prototype.getInvWeight=function(){return this.invWeight};
+toxi.physics2d.VerletParticle2D.prototype.getPreviousPosition=function(){return this.prev};toxi.physics2d.VerletParticle2D.prototype.getVelocity=function(){return this.sub(this.prev)};toxi.physics2d.VerletParticle2D.prototype.getWeight=function(){return this.weight};toxi.physics2d.VerletParticle2D.prototype.lock=function(){this.isLocked=true;return this};toxi.physics2d.VerletParticle2D.prototype.removeAllBehaviors=function(){this.behaviors=[];return this};
+toxi.physics2d.VerletParticle2D.prototype.removeAllConstraints=function(){this.constraints=[];return this};toxi.physics2d.VerletParticle2D.prototype.removeBehavior=function(a){return toxi.physics2d.removeItemFrom(a,this.behaviors)};toxi.physics2d.VerletParticle2D.prototype.removeConstraint=function(a){return toxi.physics2d.removeItemFrom(a,this.constraints)};toxi.physics2d.VerletParticle2D.prototype.scaleVelocity=function(a){this.prev.interpolateToSelf(this,1-a);return this};
+toxi.physics2d.VerletParticle2D.prototype.setPreviousPosition=function(a){this.prev.set(a);return this};toxi.physics2d.VerletParticle2D.prototype.setWeight=function(a){this.weight=a;this.invWeight=a!==0?1/a:0};toxi.physics2d.VerletParticle2D.prototype.unlock=function(){this.clearVelocity();this.isLocked=false;return this};
+toxi.physics2d.VerletParticle2D.prototype.update=function(){if(!this.isLocked){this.applyBehaviors();this.temp.set(this);this.addSelf(this.sub(this.prev).addSelf(this.force.scale(this.weight)));this.prev.set(this.temp);this.force.clear();this.applyConstraints()}};toxi.physics2d.VerletSpring2D=function(a,b,c,d){this.a=a;this.b=b;this.restLength=c;this.strength=d};toxi.physics2d.VerletSpring2D.EPS=1.0E-6;
+toxi.physics2d.VerletSpring2D.prototype={getRestLength:function(){return this.restLength},getStrength:function(){return this.strength},lockA:function(a){this.isALocked=a;return this},lockB:function(a){this.isALocked=a;return this},setRestLength:function(a){this.restLength=a;this.restLengthSquared=a*a;return this},setStrength:function(a){this.strength=a;return this},update:function(a){var b=this.b.sub(this.a),c=b.magnitude()+toxi.physics2d.VerletSpring2D.EPS;c=(c-this.restLength)/(c*(this.a.invWeight+
+this.b.invWeight))*this.strength;if(!this.a.isLocked&&!this.isALocked){this.a.addSelf(b.scale(c*this.a.invWeight));a&&this.a.applyConstraints()}if(!this.b.isLocked&&!this.isBLocked){this.b.addSelf(b.scale(-c*this.b.invWeight));a&&this.b.applyConstraints()}}};toxi.physics2d.AttractionBehavior=function(a,b,c,d){if(arguments.length<3)throw{name:"IncorrectParameters",message:"Constructor received incorrect Parameters"};this.jitter=d||0;this.attractor=a;this.strength=c;this.setRadius(b)};
+toxi.physics2d.AttractionBehavior.prototype={applyBehavior:function(a){var b=this.attractor.sub(a),c=b.magSquared();if(c<this.radiusSquared){b=b.normalizeTo(1-c/this.radiusSquared).jitter(this.jitter).scaleSelf(this.attrStrength);a.addForce(b)}},configure:function(a){this.timeStep=a;this.setStrength(this.strength)},getAttractor:function(){return this.attractor},getJitter:function(){return this.jitter},getRadius:function(){return this.radius},getStrength:function(){return this.strength},setAttractor:function(a){this.attractor=
+a},setJitter:function(a){this.jitter=a},setRadius:function(a){this.radius=a;this.radiusSquared=a*a},setStrength:function(a){this.strength=a;this.attrStrength=a*this.timeStep}};toxi.physics2d.ConstantForceBehavior=function(a){this.initConstantForceBehavior(a)};
+toxi.physics2d.ConstantForceBehavior.prototype={applyBehavior:function(a){a.addForce(this.scaledForce)},configure:function(a){this.timeStep=a;this.setForce(this.force)},getForce:function(){return this.force},initConstantForceBehavior:function(a){this.force=a;this.scaleForce=new toxi.Vec2D;this.timeStep=0},setForce:function(a){this.force=a;this.scaledForce=this.force.scale(this.timeStep)},toString:function(){return"behavior force: "+this.force+" scaledForce: "+this.scaledForce+" timeStep: "+this.timeStep}};
+toxi.physics2d.GravityBehavior=function(a){this.initConstantForceBehavior(a)};toxi.physics2d.GravityBehavior.prototype=new toxi.physics2d.ConstantForceBehavior;toxi.physics2d.GravityBehavior.prototype.constructor=toxi.physics2d.GravityBehavior;toxi.physics2d.GravityBehavior.prototype.parent=toxi.physics2d.ConstantForceBehavior.prototype;toxi.physics2d.GravityBehavior.prototype.configure=function(a){this.timeStep=a;this.scaledForce=this.force.scale(a*a)};
+toxi.physics2d.AngularConstraint=function(a,b){if(arguments.length>1){this.theta=b;this.rootPos=new toxi.Vec2D(a)}else{this.rootPos=new toxi.Vec2D;this.theta=a}if(parseInt(this.theta)!=this.theta)this.theta=MathUtils.radians(this.theta)};toxi.physics2d.AngularConstraint.prototype.apply=function(a){var b=a.sub(this.rootPos),c=MathUtils.floor(b.heading()/this.theta)*this.theta;a.set(this.rootPos.add(toxi.Vec2D.fromTheta(c).scaleSelf(b.magnitude())))};
+toxi.physics2d.AxisConstraint=function(a,b){this.axis=a;this.constraint=b};toxi.physics2d.AxisConstraint.prototype.apply=function(a){a.setComponent(this.axis,this.constraint)};toxi.physics2d.CircularConstraint=function(a,b){this.circle=arguments.length==1?a:new toxi.Circle(a,b)};toxi.physics2d.CircularConstraint.prototype.apply=function(a){this.circle.containsPoint(a)&&a.set(this.circle.add(a.sub(this.circle).nomalizeTo(this.circle.getRadius())))};
+toxi.physics2d.MaxConstraint=function(a,b){this.axis=a;this.threshold=b};toxi.physics2d.MaxConstraint.prototype.apply=function(a){a.getComponent(this.axis)>this.threshold&&a.setComponent(this.axis,this.threshold)};toxi.physics2d.MinConstraint=function(a){this.axis=a;this.threshold=threhold};toxi.physics2d.MinConstraint.prototype.apply=function(a){a.getComponent(this.axis)<this.threshold&&a.setComponent(this.axis,this.threshold)};
+toxi.physics2d.RectConstraint=function(a,b){if(arguments.length==1)this.rect=a.copy();else if(arguments.lengt>1)this.rect=new toxi.Rect(a,b);this.intersectRay=new toxi.Ray2D(this.rect.getCentroid(),new toxi.Vec2D)};toxi.physics2d.RectConstraint.prototype={apply:function(a){this.rect.containsPoint(a)&&a.set(this.rect.intersectsRay(this.intersectRay.setDirection(this.intersectRay.sub(a)),0,Number.MAX_VALUE))},getBox:function(){return this.rect.copy()},setBox:function(a){this.rect=a.copy();this.intersectRay.set(this.rect.getCentroid())}};
+toxi.physics2d.ParticlePath2D=function(a){toxi.Spline2D.call(this,a);this.particles=[]};toxi.extend(toxi.physics2d.ParticlePath2D,toxi.Spline2D);(function(){toxi.physics2d.ParticlePath2D.prototype.createParticles=function(a,b,c,d){this.particles=[];this.computeVertices(b);b=0;c=this.getDecimatedVertices(c,true);for(b=0;b<c;b++){var f=this.createSingleParticle(v,d);this.particles.push(f);a.addParticle(f)}return this.particles}})();
+toxi.physics2d.ParticleString2D=function(a,b,c,d,f,j){this.physics=a;this.links=[];var g=undefined,e=undefined,i=undefined,h=0;if(arguments.length===3){j=c;this.particles=b||[];for(h=0;h<this.particles.length;h++){e=this.particles[h];this.physics.addParticle(e);if(g!==undefined){i=this.createSpring(g,e,g.distanceTo(e),stregnth_step);this.links.push(i);this.physics.addSpring(i)}g=e}}else{var k=b.copy(),l=c.magnitude();this.particles=[];for(h=0;h<d;h++){e=new toxi.physics2d.VerletParticle2D(k.copy(),
+f);this.particles.push(e);this.physics.particles.push(e);if(g!==undefined){i=this.createSpring(g,e,l,j);this.links.push(i);this.physics.addSpring(i)}g=e;k.addSelf(c)}}};
+toxi.physics2d.ParticleString2D.prototype={clear:function(){for(var a=0,b=this.links.length;a<b;a++)this.physics.removeSpringElements(s);this.particles.clear();this.links.clear()},createSpring:function(a,b,c,d){return new toxi.physics2d.VerletSpring2D(a,b,c,d)},getHead:function(){return this.particles[0]},getNumParticles:function(){return this.particles.length},getTail:function(){return this.particles[this.particles.length-1]}};
+toxi.physics2d.PullBackString2D=function(a,b,c){toxi.physics2d.VerletSpring2D.call(this,a,b,c);a.lock();this.setRestLength(0.5)};toxi.extend(toxi.physics2d.PullBackString2D,toxi.physics2d.VerletSpring2D);toxi.physics2d.PullBackString2D.prototype.update=function(a){this.b.distanceToSquared(this.a)>this.restLengthSquared&&this.parent.update.call(this,a)};
+toxi.physics2d.VerletConstrainedSpring2D=function(a,b,c,d,f){toxi.physics2d.VerletSpring2D.call(this,a,b,c,d);this.limit=f===undefined?Number.MAX_VALUE:f};toxi.extend(toxi.physics2d.VerletConstrainedSpring2D,toxi.physics2d.VerletSpring2D);
+toxi.physics2d.VerletConstrainedSpring2D.update=function(a){var b=this.b.sub(this.a),c=b.magnitude()+toxi.physics2d.VerletSpring2D.EPS;c=(c-this.restLength)/(c*(this.a.invWeight+this.b.invWeight))*this.strength;if(!this.a.isLocked&&!this.isALocked){this.a.addSelf(b.scale(c*this.a.invWeight).limit(this.limit));a&&this.a.applyConstraints()}if(!this.b.isLocked&&!this.isBLocked){this.b.subSelf(b.scale(c*this.b.invWeight).limit(this.limit));a&&this.b.applyConstraints()}};
+toxi.physics2d.VerletMinDistanceSpring2D=function(a,b,c,d){toxi.physics2d.VerletSpring2D.call(this,a,b,c,d);this.setRestLength(c)};toxi.extend(toxi.physics2d.VerletMinDistanceSpring2D,toxi.physics2d.VerletSpring2D);toxi.physics2d.VerletMinDistanceSpring2D.prototype.update=function(a){this.b.distanceToSquared(this.a)<this.restLengthSquared&&this.parent.update.call(this,a)};
+toxi.physics2d.VerletPhysics2D=function(a,b,c,d){this.behaviors=[];this.particles=[];this.springs=[];this.numIterations=b===undefined?50:b;this.timeStep=d===undefined?1:d;this.setDrag(c||0);a!==undefined&&this.addBehavior(new toxi.physics.GravityBehavior(a))};toxi.physics2d.VerletPhysics2D.addConstraintToAll=function(a,b){for(var c=0;c<b.length;c++)b[c].addConstraint(a)};toxi.physics2d.VerletPhysics2D.removeConstraintFromAll=function(a,b){for(var c=0;c<b.length;c++)b[c].removeConstraint(a)};
+toxi.physics2d.VerletPhysics2D.prototype={addBehavior:function(a){if(a===undefined)throw{name:"TypeError",message:"Incorrect Parameters for toxi.physics2d.VerletPhysics2D addBehavior"};a.configure(this.timeStep);this.behaviors.push(a)},addParticle:function(a){this.particles.push(a);return this},addSpring:function(a){this.getSpring(a.a,a.b)===undefined&&this.springs.push(a);return this},clear:function(){this.particles=[];this.springs=[];return this},constrainToBounds:function(){var a=undefined,b=0;
+for(b=0;b<this.particles.length;b++){a=this.particles[b];a.bounds!==undefined&&a.constrain(a.bounds)}if(this.worldBounds!==undefined)for(b=0;b<this.particles.length;b++){a=this.particles[b];a.constrain(this.worldBounds)}},getCurrentBounds:function(){var a=new toxi.Vec2D(Number.MAX_VALUE,Number.MAX_VALUE),b=new toxi.Vec2D(Number.MIN_VALUE,Number.MIN_VALUE),c=0,d=undefined;for(c=0;c<this.particles.length;c++){d=this.particles[c];a.minSelf(d);b.maxSelf(d)}return new toxi.Rect(a,b)},getDrag:function(){return 1-
+this.drag},getNumIterations:function(){return this.numIterations},getSpring:function(a,b){var c=0;for(c=0;c<this.springs.length;c++){var d=this.springs[c];if(d.a===a&&d.b===b||d.a===b&&d.b===b)return d}},getTimeStep:function(){return this.timeStep},getWorldBounds:function(){return this.worldBounds},removeBehavior:function(a){return toxi.physics2d.removeItemFrom(a,this.behaviors)},removeParticle:function(a){return toxi.physics2d.removeItemFrom(a,this.particles)},removeSpring:function(a){return toxi.physics2d.removeItemFrom(a,
+this.springs)},removeSpringElements:function(a){if(this.removeSpring(a)!==undefined)return this.removeParticle(a.a)&&this.removeParticle(a.b);return false},setDrag:function(a){this.drag=1-a},setNumIterations:function(a){this.numIterations=a},setTimeStep:function(a){this.timeStep=a;var b=0;for(b=0;b<this.behaviors.length;b++)this.behaviors[b].configure(a)},setWorldBounds:function(a){this.worldBounds=a;return this},update:function(){this.updateParticles();this.updateSprings();this.constrainToBounds();
+return this},updateParticles:function(){var a=0,b=0,c=undefined,d=undefined;for(a=0;a<this.behaviors.length;a++){c=this.behaviors[a];for(b=0;b<this.particles.length;b++){d=this.particles[b];c.applyBehavior(d)}}for(b=0;b<this.particles.length;b++){d=this.particles[b];d.scaleVelocity(this.drag);d.update()}},updateSprings:function(){var a=0,b=0;for(a=this.numIterations;a>0;a--)for(b=0;b<this.springs.length;b++)this.springs[b].update(a===1)}};
View
94 build/toxiclibs.js
@@ -1,13 +1,13 @@
-// toxiclibs.js r32 - http://github.com/hapticdata/toxiclibsjs
-var toxi=toxi||{};toxi.extend=function(e,g){e.prototype=new g;e.prototype.constructor=e;e.prototype.parent=g.prototype};toxi.MathUtils={};toxi.MathUtils.SQRT2=Math.sqrt(2);toxi.MathUtils.SQRT3=Math.sqrt(3);toxi.MathUtils.LOG2=Math.log(2);toxi.MathUtils.PI=3.141592653589793;toxi.MathUtils.INV_PI=1/toxi.MathUtils.PI;toxi.MathUtils.HALF_PI=toxi.MathUtils.PI/2;toxi.MathUtils.THIRD_PI=toxi.MathUtils.PI/3;toxi.MathUtils.QUARTER_PI=toxi.MathUtils.PI/4;toxi.MathUtils.TWO_PI=toxi.MathUtils.PI*2;
+// toxiclibs.js r33 - http://github.com/hapticdata/toxiclibsjs
+var toxi=toxi||{};toxi.extend=function(e,g){e.prototype=new g;e.constructor=e;e.prototype.parent=g.prototype};toxi.MathUtils={};toxi.MathUtils.SQRT2=Math.sqrt(2);toxi.MathUtils.SQRT3=Math.sqrt(3);toxi.MathUtils.LOG2=Math.log(2);toxi.MathUtils.PI=3.141592653589793;toxi.MathUtils.INV_PI=1/toxi.MathUtils.PI;toxi.MathUtils.HALF_PI=toxi.MathUtils.PI/2;toxi.MathUtils.THIRD_PI=toxi.MathUtils.PI/3;toxi.MathUtils.QUARTER_PI=toxi.MathUtils.PI/4;toxi.MathUtils.TWO_PI=toxi.MathUtils.PI*2;
toxi.MathUtils.THREE_HALVES_PI=toxi.MathUtils.TWO_PI-toxi.MathUtils.HALF_PI;toxi.MathUtils.PI_SQUARED=toxi.MathUtils.PI*toxi.MathUtils.PI;toxi.MathUtils.EPS=1.1920928955078125E-7;toxi.MathUtils.DEG2RAD=toxi.MathUtils.PI/180;toxi.MathUtils.RAD2DEG=180/toxi.MathUtils.PI;toxi.MathUtils.SHIFT23=8388608;toxi.MathUtils.INV_SHIFT23=1/toxi.MathUtils.SHIFT23;toxi.MathUtils.SIN_A=-4/(toxi.MathUtils.PI*toxi.MathUtils.PI);toxi.MathUtils.SIN_B=4/toxi.MathUtils.PI;toxi.MathUtils.SIN_P=0.225;
toxi.MathUtils.abs=Math.abs;toxi.MathUtils.ceilPowerOf2=function(e){for(var g=1;g<e;)g<<=1;return g};toxi.MathUtils.clip=function(e,g,h){return e<g?g:e>h?h:e};toxi.MathUtils.clipNormalized=function(e){if(e<0)return 0;else if(e>1)return 1;return e};toxi.MathUtils.cos=Math.cos;toxi.MathUtils.fastCos=function(e){return toxi.MathUtils.fastSin(e+(e>toxi.MathUtils.HALF_PI?-toxi.MathUtils.THREE_HALVES_PI:toxi.MathUtils.HALF_PI))};
toxi.MathUtils.fastSin=function(e){e=toxi.MathUtils.SIN_B*e+toxi.MathUtils.SIN_A*e*Math.abs(e);return toxi.MathUtils.SIN_P*(e*Math.abs(e)-e)+e};toxi.MathUtils.flipCoin=function(){return Math.random()<0.5};toxi.MathUtils.floor=function(e){var g=parseInt(e);e<0&&e!=g&&g--;return g};toxi.MathUtils.floorPowerOf2=function(e){return parseInt(Math.pow(2,parseInt(Math.log(e)/toxi.MathUtils.LOG2)))};toxi.MathUtils.max=function(e,g,h){if(!h)return Math.max(e,g);return e>g?e>h?e:h:g>h?g:h};
toxi.MathUtils.min=function(e,g,h){if(!h)return Math.min(e,g);return e<g?e<h?e:h:g<h?g:h};toxi.MathUtils.normalizedRandom=function(){return Math.random()*2-1};toxi.MathUtils.radians=function(e){return e*toxi.MathUtils.DEG2RAD};toxi.MathUtils.random=function(e,g){if(!e&&!g)return Math.random();else if(!g){g=e;return Math.random()*g}return Math.random()*(g-e)+e};
toxi.MathUtils.reduceAngle=function(e){e%=toxi.MathUtils.TWO_PI;if(Math.abs(e)>toxi.MathUtils.PI)e-=toxi.MathUtils.TWO_PI;if(Math.abs(e)>toxi.MathUtils.HALF_PI)e=toxi.MathUtils.PI-e;return e};toxi.MathUtils.sign=function(e){return e<0?-1:e>0?1:0};toxi.MathUtils.sin=function(e){e=toxi.MathUtils.reduceAngle(e);if(Math.abs(e)<=toxi.MathUtils.QUARTER_PI)return toxi.MathUtils.fastSin(e);return toxi.MathUtils.fastCos(toxi.MathUtils.HALF_PI-e)};toxi.BezierInterpolation=function(e,g){this.c1=e;this.c2=g};
toxi.BezierInterpolation.prototype={interpolate:function(e,g,h){var i=h*h,j=1-h,k=j*j;return e*k*j+3*(this.c1*(g-e)+e)*h*k+3*(this.c2*(g-e)+g)*i*j+g*i*h},setCoefficients:function(e,g){this.c1=e;this.c2=g}};toxi.CircularInterpolation=function(){};toxi.CircularInterpolation.prototype={interpolate:function(e,g,h){if(this.isFlipped)return e-(g-e)*(Math.sqrt(1-h*h)-1);else{h=1-h;return e+(g-e)*Math.sqrt(1-h*h)}},setFlipped:function(e){this.isFlipped=e}};toxi.CosineInterpolation=function(){};
toxi.CosineInterpolation.prototype={interpolate:function(e,g,h){return g+(e-g)*(0.5+0.5*Math.cos(h*Math.PI))}};toxi.DecimatedInterpolation=function(e,g){if(e===undefined)throw Error("steps was not passed to constructor");this.numSteps=e;this.strategy=g==undefined?new LinearInterpolation:g};toxi.DecimatedInterpolation.prototype={interpolate:function(e,g,h){return this.strategy.interpolate(e,g,Math.floor(h*this.numSteps)/this.numSteps)}};
-toxi.ExponentialInterpolation=function(e){this.exponent=e===undefined?2:e};toxi.ExponentialInterpolation.prototype={interpolate:function(e,g,h){return e+(g-e)*Math.pow(h,this.exponent)}};toxi.Interpolation2D={};toxi.Interpolation2D.bilinear=function(e,g,h,i,j,k,n,m,o,r){var s,u,A;if(e instanceof Vec2D){s=e.x;e=e.y;u=g.x;g=g.y;A=h.x;h=h.y;i=i;j=j;k=k;n=n}else{s=e;e=g;u=h;g=i;A=j;h=k;i=n;j=m;k=o;n=r}r=1/((A-u)*(h-g));u=(s-u)*r;s=(A-s)*r;g=e-g;e=h-e;return i*s*e+j*u*e+k*s*g+n*u*g};
+toxi.ExponentialInterpolation=function(e){this.exponent=e===undefined?2:e};toxi.ExponentialInterpolation.prototype={interpolate:function(e,g,h){return e+(g-e)*Math.pow(h,this.exponent)}};toxi.Interpolation2D={};toxi.Interpolation2D.bilinear=function(e,g,h,i,j,k,n,m,o,r){var t,A,B;if(e instanceof Vec2D){t=e.x;e=e.y;A=g.x;g=g.y;B=h.x;h=h.y;i=i;j=j;k=k;n=n}else{t=e;e=g;A=h;g=i;B=j;h=k;i=n;j=m;k=o;n=r}r=1/((B-A)*(h-g));A=(t-A)*r;t=(B-t)*r;g=e-g;e=h-e;return i*t*e+j*A*e+k*t*g+n*A*g};
toxi.LinearInterpolation=function(){};toxi.LinearInterpolation.prototype={interpolate:function(e,g,h){return e+(g-e)*h}};toxi.SigmoidInterpolation=function(e){if(e===undefined)e=2;this.setSharpness(e)};toxi.SigmoidInterpolation.prototype={getSharpness:function(){return this.sharpness},interpolate:function(e,g,h){h=(h*2-1)*this.sharpPremult;h=1/(1+Math.exp(-h));return e+(g-e)*h},setSharpness:function(e){this.sharpness=e;this.sharpPremult=5*e}};
toxi.ThresholdInterpolation=function(e){this.threshold=e};toxi.ThresholdInterpolation.prototype={interpolate:function(e,g,h){return h<this.threshold?e:g}};toxi.ZoomLensInterpolation=function(e,g){this.leftImpl=new CircularInterpolation;this.rightImpl=new CircularInterpolation;this.lensPos=lenPos===undefined?0.5:e;this.lensStrength=lenStrength==undefined?1:g;this.absStrength=Math.abs(this.lensStrength);this.leftImpl.setFlipped(this.lensStrength>0);this.rightImpl.setFlipped(this.lensStrength<0)};
toxi.ZoomLensInterpolation.prototype={interpolate:function(e,g,h){var i=e+(g-e)*h;i+=h<this.lensPos?(this.leftImpl.interpolate(e,e+(g-e)*this.lensPos,h/this.lensPos)-i)*this.absStrength:(this.rightImpl.interpolate(e+(g-e)*this.lensPos,g,(h-this.lensPos)/(1-this.lensPos))-i)*this.absStrength;return i},setLensPos:function(e,g){this.lensPos+=(MathUtils.clipNormalized(e)-this.lensPos)*g},setLensStrength:function(e,g){this.lensStrength+=(MathUtils.clip(e,-1,1)-this.lensStrength)*g;this.absStrength=MathUtils.abs(this.lensStrength);
@@ -37,18 +37,18 @@ toxi.SinCosLUT.getDefaultInstance=function(){if(toxi.SinCosLUT.DEFAULT_INSTANCE=
toxi.Vec2D.prototype={abs:function(){this.x=Math.abs(this.x);this.y=Math.abs(this.y);return this},add:function(e,g){var h=this.getVector(e,g);return new toxi.Vec2D(this.x+h.x,this.y+h.y)},addSelf:function(e,g){var h=this.getVector(e,g);this.x+=h.x;this.y+=h.y;return this},angleBetween:function(e,g){var h;h=g!==undefined&&faceNormalize==true?this.getNormalized().dot(e.getNormalized()):this.dot(e);return Math.acos(h)},clear:function(){this.x=this.y=0;return this},compareTo:function(){if(this.x==v.x&&
this.y==v.y)return 0;return this.magSquared()-v.magSquared()},constrain:function(e,g){if(e instanceof toxi.Vec2D&&g instanceof toxi.Vec2D){this.x=toxi.MathUtils.clip(this.x,min.x,max.x);this.y=toxi.MathUtils.clip(this.y,min.y,max.y)}else if(e.x!=undefined&&e.y!=undefined&&e.width!=undefined&&e.height!=undefined){this.x=toxi.MathUtils.clip(this.x,e.x,e.x+e.width);this.y=toxi.MathUtils.clip(this.y,e.y,e.y+e.height)}return this},copy:function(){return new toxi.Vec2D(this)},cross:function(e){return this.x*
e.y-this.y*e.x},distanceTo:function(e){if(e!==undefined){var g=this.x-e.x;e=this.y-e.y;return Math.sqrt(g*g+e*e)}else return NaN},distanceToSquared:function(e){if(e!==undefined){var g=this.x-e.x;e=this.y-e.y;return g*g+e*e}else return NaN},dot:function(e){return this.x*e.x+this.y*e.y},equals:function(e){if(e instanceof toxi.Vec2D)return this.x==e.x&&this.y==e.y;return false},equalsWithTolerance:function(e,g){if(toxi.MathUtils.abs(this.x-e.x)<g)if(toxi.MathUtils.abs(this.y-e.y)<g)return true;return false},
-floor:function(){this.x=toxi.MathUtils.floor(this.x);this.y=toxi.MathUtils.floor(this.y);return this},frac:function(){this.x-=toxi.MathUtils.floor(this.x);this.y-=toxi.MathUtils.floor(this.y);return this},getAbs:function(){return(new toxi.Vec2D(this)).abs()},getComponent:function(e){if(e instanceof Number)switch(e){case 0:case 1:e=Axis.Y}switch(e){case Axis.X:return this.x;case Axis.Y:return this.y}return 0},getConstrained:function(e){return(new toxi.Vec2D(this)).constrain(e)},getFloored:function(){return(new toxi.Vec2D(this)).floor()},
-getFrac:function(){return(new toxi.Vec2D(this)).frac()},getInverted:function(){return new toxi.Vec2D(-this.x,-this.y)},getLimited:function(e){if(this.magSquared()>e*e)return this.getNormalizedTo(e);return new toxi.Vec2D(this)},getNormalized:function(){return(new toxi.Vec2D(this)).normalize()},getNormalizedTo:function(e){return(new toxi.Vec2D(this)).normalizeTo(e)},getPerpendicular:function(){return(new toxi.Vec2D(this)).perpendicular()},getReciprocal:function(){return this.copy().reciprocal()},getReflected:function(e){return this.copy().reflect(e)},
-getRotated:function(e){return(new toxi.Vec2D(this)).rotate(e)},getSignum:function(){return(new toxi.Vec2D(this)).signum()},getVector:function(e,g){if(e instanceof toxi.Vec2D){g=e.y;e=e.x}else if(e!=undefined&&g===undefined)g=e;else if(e===undefined)e=0;else if(g===undefined)g=0;return new toxi.Vec2D(e,g)},heading:function(){return Math.atan2(this.y,this.x)},init:function(e,g){if(e instanceof toxi.Vec2D){g=e.y;e=e.x}else{if(e===undefined)e=0;if(g===undefined)g=0}this.x=e;this.y=g},interpolateTo:function(e,
-g,h){if(h===undefined)return new toxi.Vec2D(this.x+(e.x-this.x)*g,this.y+(e.y-this.y)*g)},interpolateToSelf:function(e,g,h){if(h===undefined){this.x+=(e.x-this.x)*g;this.y+=(e.y-this.y)*g}else{this.x=h.interpolate(this.x,e.x,g);this.y=h.interpolate(this.y,e.y,g)}return this},invert:function(){this.x*=-1;this.y*=-1;return this},isInCircle:function(e,g){return this.sub(e).magSquared()<=g*g},isInRectangle:function(e){if(this.x<e.x||this.x>e.x+e.width)return false;if(this.y<e.y||this.y>e.y+e.height)return false;
-return true},isInTriangle:function(e,g,h){e=this.sub(e).normalize();g=this.sub(g).normalize();h=this.sub(h).normalize();var i=Math.acos(e.dot(g));i+=Math.acos(g.dot(h));i+=Math.acos(h.dot(e));return Math.abs(i-toxi.MathUtils.TWO_PI)<=0.0050},isMajorAxis:function(e){var g=Math.abs(this.x),h=Math.abs(this.y),i=1-e;if(g>i)return h<e;else if(h>i)return g<e;return false},isZeroVector:function(){return Math.abs(this.x)<toxi.MathUtils.EPS&&Math.abs(this.y)<toxi.MathUtils.EPS},jitter:function(e,g){var h=
-this.getVector(e,g);this.x+=toxi.MathUtils.normalizedRandom()*h.x;this.y+=toxi.MathUtils.normalizedRandom()*h.y;return this},limit:function(e){if(this.magSquared()>e*e)return this.normalize().scaleSelf(e);return this},magnitude:function(){return Math.sqrt(this.x*this.x+this.y*this.y)},magSquared:function(){return this.x*this.x+this.y*this.y},max:function(e){return new toxi.Vec2D(toxi.MathUtils.max(this.x,e.x),toxi.MathUtils.max(this.y,e.y))},maxSelf:function(e){this.x=toxi.MathUtils.max(this.x,e.x);
-this.y=toxi.MathUtils.max(this.y,e.y);return this},min:function(e){return new toxi.Vec2D(toxi.MathUtils.min(this.x,e.x),MathUtils.min(this.y,e.y))},minSelf:function(e){this.x=MathUtils.min(this.x,e.x);this.y=MathUtils.min(this.y,e.y);return this},normalize:function(){var e=this.x*this.x+this.y*this.y;if(e>0){e=1/Math.sqrt(e);this.x*=e;this.y*=e}return this},normalizeTo:function(e){var g=Math.sqrt(this.x*this.x+this.y*this.y);if(g>0){g=e/g;this.x*=g;this.y*=g}return this},perpendicular:function(){var e=
-this.x;this.x=-this.y;this.y=e;return this},reciprocal:function(){this.x=1/this.x;this.y=1/this.y;return this},reflect:function(e){return this.set(e.scale(this.dot(e)*2).subSelf(this))},rotate:function(e){var g=Math.cos(e);e=Math.sin(e);var h=g*this.x-e*this.y;this.y=e*this.x+g*this.y;this.x=h;return this},roundToAxis:function(){if(Math.abs(this.x)<0.5)this.x=0;else{this.x=this.x<0?-1:1;this.y=0}if(Math.abs(this.y)<0.5)this.y=0;else{this.y=this.y<0?-1:1;this.x=0}return this},scale:function(e){return new toxi.Vec2D(this.x*
-e,this.y*e)},scale:function(e,g){var h=this.getVector(e,g);return new toxi.Vec2D(this.x*h.x,this.y*h.y)},scaleSelf:function(e,g){var h=this.getVector(e,g);this.x*=h.x;this.y*=h.y;return this},set:function(e,g){var h=this.getVector(e,g);this.x=h.x;this