-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathpt.min.js
6 lines (4 loc) · 88.5 KB
/
pt.min.js
1
2
3
4
5
6
/* Licensed under the Apache License, Version 2.0. (http://www.apache.org/licenses/LICENSE-2.0). Copyright 2015-2016 William Ngan. (https://github.com/williamngan/pt/) */
var CanvasSpace,Circle,Color,Const,Curve,DOMSpace,Delaunay,Easing,Form,Grid,GridCascade,Line,Matrix,Noise,Pair,Particle,ParticleEmitter,ParticleField,ParticleSystem,Point,PointSet,QuadTree,Rectangle,SVGForm,SVGSpace,SamplePoints,Space,StripeBound,Timer,Triangle,UI,Util,Vector,bind=function(t,i){return function(){return t.apply(i,arguments)}},extend=function(t,i){function e(){this.constructor=t}for(var n in i)hasProp.call(i,n)&&(t[n]=i[n]);return e.prototype=i.prototype,t.prototype=new e,t.__super__=i.prototype,t},hasProp={}.hasOwnProperty,slice=[].slice;Const=function(){function t(){}return t.xy="xy",t.yz="yz",t.xz="xz",t.xyz="xyz",t.identical=-1,t.right=3,t.bottom_right=4,t.bottom=5,t.bottom_left=6,t.left=7,t.top_left=0,t.top=1,t.top_right=2,t.sideLabels=["identical","right","bottom right","bottom","bottom left","left","top left","top","top right"],t.epsilon=1e-4,t.pi=Math.PI,t.two_pi=6.283185307179586,t.half_pi=1.5707963267948966,t.quarter_pi=.7853981633974483,t.one_degree=.017453292519943295,t.rad_to_deg=57.29577951308232,t.deg_to_rad=.017453292519943295,t.gravity=9.81,t.newton=.10197,t.gaussian=.3989422804014327,t}(),this.Const=Const,Matrix=function(){function t(){}return t.rotateAnchor2D=function(t,i,e){var n,s,o;return null==e&&(e=Const.xy),n=i.get2D(e),s=Math.cos(t),o=Math.sin(t),[s,o,0,-o,s,0,n.x*(1-s)+n.y*o,n.y*(1-s)-n.x*o,1]},t.reflectAnchor2D=function(t,i){var e,n,s,o;return null==i&&(i=Const.xy),s=t.intercept(i),e=2*Math.atan(s.slope),n=Math.cos(e),o=Math.sin(e),[n,o,0,o,-n,0,-s.yi*o,s.yi+s.yi*n,1]},t.shearAnchor2D=function(t,i,e,n){var s,o,r;return null==n&&(n=Const.xy),s=e.get2D(n),o=Math.tan(t),r=Math.tan(i),[1,o,0,r,1,0,-s.y*r,-s.x*o,1]},t.scaleAnchor2D=function(t,i,e,n){var s;return null==n&&(n=Const.xy),s=e.get2D(n),[t,0,0,0,i,0,-s.x*t+s.x,-s.y*i+s.y,1]},t.scale2D=function(t,i){return[t,0,0,0,i,0,0,0,1]},t.shear2D=function(t,i){return[1,Math.tan(t),0,Math.tan(i),1,0,0,0,1]},t.rotate2D=function(t,i){return[t,i,0,-i,t,0,0,0,1]},t.translate2D=function(t,i){return[1,0,0,0,1,0,t,i,1]},t.transform2D=function(t,i,e,n){var s,o,r;return null==e&&(e=Const.xy),null==n&&(n=!1),s=t.get2D(e),o=s.x*i[0]+s.y*i[3]+i[6],r=s.x*i[1]+s.y*i[4]+i[7],s.x=o,s.y=r,s=s.get2D(e,!0),n?s:(t.set(s),t)},t}(),this.Matrix=Matrix,Util=function(){function t(){}return t.toRadian=function(t){return t*Const.deg_to_rad},t.toDegree=function(t){return t*Const.rad_to_deg},t.toHexColor=function(t){var i;return i=Math.floor(t).toString(16),1===i.length?"0"+i:i},t.toRGBColor=function(t,i,e){var n,s,o;return null==i&&(i=!1),null==e&&(e=1),"#"===t[0]&&(t=t.substr(1)),3===t.length?(o=parseInt(t[0]+t[0],16),s=parseInt(t[1]+t[1],16),n=parseInt(t[2]+t[2],16)):t.length>=6?(o=parseInt(t[0]+t[1],16),s=parseInt(t[2]+t[3],16),n=parseInt(t[4]+t[5],16)):(o=0,s=0,n=0),i?"rgba("+o+","+s+","+n+","+e+")":[o,s,n,e]},t.bound=function(t,i,e){var n,s;return null==e&&(e=!1),n=t%i,s=i/2,n>s?n-=i:n<-s&&(n+=i),e&&n<0?n+i:n},t.boundAngle=function(i,e){return t.bound(i,360,e)},t.boundRadian=function(i,e){return t.bound(i,Const.two_pi,e)},t.boundingBox=function(t,i){var e,n,s,o,r;for(null==i&&(i=!1),o=new Point(Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY),s=new Point(Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY),e=0,n=t.length;e<n;e++)r=t[e],r.x<o.x&&(o.x=r.x),r.y<o.y&&(o.y=r.y),r.x>s.x&&(s.x=r.x),r.y>s.y&&(s.y=r.y),i&&(r.z<o.z&&(o.z=r.z),r.z>s.z&&(s.z=r.z));return new Rectangle(o).to(s)},t.lerp=function(t,i,e){return(1-e)*t+e*i},t.centroid=function(t){var i,e,n,s;for(e=new Vector,i=0,n=t.length;i<n;i++)s=t[i],e.add(s);return e.divide(t.length)},t.same=function(t,i,e){return null==e&&(e=Const.epsilon),Math.abs(t-i)<e},t.within=function(t,i,e){return t>=Math.min(i,e)&&t<=Math.max(i,e)},t.randomRange=function(t,i){var e;return null==i&&(i=0),e=t>i?t-i:i-t,t+Math.random()*e},t.mixin=function(t,i){var e,n;for(e in i)n=i[e],i.hasOwnProperty(e)&&(t.prototype[e]=i[e]);return t},t.extend=function(t,i){return t.prototype=Object.create(i.prototype),t.prototype.constructor=t,t},t.clonePoints=function(t){var i,e,n,s;for(s=[],i=0,e=t.length;i<e;i++)n=t[i],s.push(n.clone());return s},t.contextRotateOrigin=function(t,i,e,n,s){var o,r;return null==n&&(n=!1),r=i.size(),n||(n=r.$multiply(.5),n.add(i)),s&&(o=s.size(),Form.rect(t,s),t.clip()),t.translate(n.x,n.y),t.rotate(e),t.translate(-n.x,-n.y)},t.sinCosTable=function(){var t,i,e,n;for(i=[],n=[],e=t=0;t<=360;e=t+=1)i[e]=Math.cos(e*Math.PI/180),n[e]=Math.sin(e*Math.PI/180);return{sin:n,cos:i}},t.chance=function(t){return Math.random()<t},t.gaussian=function(t,i,e){return null==i&&(i=0),null==e&&(e=1),t=(t-i)/e,Const.gaussian*Math.exp(-.5*t*t)/e},t.mapToRange=function(t,i,e,n,s){if(i===e)throw"[min1, max1] must be a non-degenerate interval (that is, min1 != max1)";return(t-i)/(e-i)*(s-n)+n},t}(),this.Util=Util,Timer=function(){function t(t){null==t&&(t=1e3),this.duration=t,this._time=0,this._ease=function(t,i,e,n){return t/n},this._intervalID=-1}return t.prototype.start=function(t){var i;if(i=Math.min(Date.now()-this._time,this.duration),t||i>=this.duration)return this._time=Date.now()},t.prototype.setEasing=function(t){return this._ease=t},t.prototype.check=function(){var t;return t=Math.min(Date.now()-this._time,this.duration),this._ease(t,0,1,this.duration)},t.prototype.track=function(t){var i;return clearInterval(this._intervalID),this.start(!0),i=this,this._intervalID=setInterval(function(){var e;if(e=i.check(),t(e),e>=1)return clearInterval(i._intervalID)},25),this._intervalID},t}(),this.Timer=Timer,Space=function(){function t(t){if("string"!=typeof t||0===t.length)throw"id parameter is not valid";this.id=t,this.size=new Vector,this.center=new Vector,this._timePrev=0,this._timeDiff=0,this._timeEnd=-1,this.items={},this._animID=-1,this._animCount=0,this._animPause=!1,this._refresh=!0}return t.prototype.refresh=function(t){return this._refresh=t,this},t.prototype.render=function(t){return this},t.prototype.resize=function(t,i){},t.prototype.clear=function(){},t.prototype.add=function(t){var i;if(null==t.animate||"function"!=typeof t.animate)throw"a player object for Space.add must define animate()";return i=this._animCount++,this.items[i]=t,t.animateID=i,null!=t.onSpaceResize&&t.onSpaceResize(this.size.x,this.size.y),this},t.prototype.remove=function(t){return delete this.items[t.animateID],this},t.prototype.removeAll=function(){return this.items={},this},t.prototype.play=function(t){var i,e;if(null==t&&(t=0),this._animID=requestAnimationFrame(function(t){return function(i){return t.play(i)}}(this)),!this._animPause){this._timeDiff=t-this._timePrev;try{this._playItems(t)}catch(e){throw i=e,cancelAnimationFrame(this._animID),console.error(i.stack),i}return this._timePrev=t,this}},t.prototype._playItems=function(t){var i,e,n;this._refresh&&this.clear(),e=this.items;for(i in e)n=e[i],n.animate(t,this._timeDiff,this.ctx);return this._timeEnd>=0&&t>this._timeEnd&&cancelAnimationFrame(this._animID),this},t.prototype.pause=function(t){return null==t&&(t=!1),this._animPause=!t||!this._animPause,this},t.prototype.resume=function(){return this._animPause=!1,this},t.prototype.stop=function(t){return null==t&&(t=0),this._timeEnd=t,this},t.prototype.playTime=function(t){return null==t&&(t=5e3),this.play(),this.stop(t)},t.prototype.bindCanvas=function(t,i){if(this.space.addEventListener)return this.space.addEventListener(t,i)},t.prototype.bindMouse=function(t){if(null==t&&(t=!0),this.space.addEventListener&&this.space.removeEventListener)return t?(this.space.addEventListener("mousedown",this._mouseDown.bind(this)),this.space.addEventListener("mouseup",this._mouseUp.bind(this)),this.space.addEventListener("mouseover",this._mouseOver.bind(this)),this.space.addEventListener("mouseout",this._mouseOut.bind(this)),this.space.addEventListener("mousemove",this._mouseMove.bind(this))):(this.space.removeEventListener("mousedown",this._mouseDown.bind(this)),this.space.removeEventListener("mouseup",this._mouseUp.bind(this)),this.space.removeEventListener("mouseover",this._mouseOver.bind(this)),this.space.removeEventListener("mouseout",this._mouseOut.bind(this)),this.space.removeEventListener("mousemove",this._mouseMove.bind(this)))},t.prototype.bindTouch=function(t){if(null==t&&(t=!0),this.space.addEventListener&&this.space.removeEventListener)return t?(this.space.addEventListener("touchstart",this._mouseDown.bind(this)),this.space.addEventListener("touchend",this._mouseUp.bind(this)),this.space.addEventListener("touchmove",function(t){return function(i){return i.preventDefault(),t._mouseMove(i)}}(this)),this.space.addEventListener("touchcancel",this._mouseOut.bind(this))):(this.space.removeEventListener("touchstart",this._mouseDown.bind(this)),this.space.removeEventListener("touchend",this._mouseUp.bind(this)),this.space.removeEventListener("touchmove",this._mouseMove.bind(this)),this.space.removeEventListener("touchcancel",this._mouseOut.bind(this)))},t.prototype.touchesToPoints=function(t,i){var e;return null==i&&(i="touches"),t&&t[i]?function(){var n,s,o,r;for(o=t[i],r=[],n=0,s=o.length;n<s;n++)e=o[n],r.push(new Vector(e.pageX-this.boundRect.left,e.pageY-this.boundRect.top));return r}.call(this):[]},t.prototype._mouseAction=function(t,i){var e,n,s,o,r,h,u,c,a;if(i.touches||i.changedTouches){r=this.items,u=[];for(n in r)a=r[n],null!=a.onTouchAction?(e=i.changedTouches&&i.changedTouches.length>0,s=e?i.changedTouches.item(0).pageX:0,o=e?i.changedTouches.item(0).pageY:0,u.push(a.onTouchAction(t,s,o,i))):u.push(void 0);return u}h=this.items,c=[];for(n in h)a=h[n],null!=a.onMouseAction?(s=i.offsetX||i.layerX,o=i.offsetY||i.layerY,c.push(a.onMouseAction(t,s,o,i))):c.push(void 0);return c},t.prototype._mouseDown=function(t){return this._mouseAction("down",t),this._mdown=!0},t.prototype._mouseUp=function(t){return this._mouseAction("up",t),this._mdrag&&this._mouseAction("drop",t),this._mdown=!1,this._mdrag=!1},t.prototype._mouseMove=function(t){if(this._mouseAction("move",t),this._mdown)return this._mdrag=!0,this._mouseAction("drag",t)},t.prototype._mouseOver=function(t){return this._mouseAction("over",t)},t.prototype._mouseOut=function(t){return this._mouseAction("out",t),this._mdrag&&this._mouseAction("drop",t),this._mdrag=!1},t}(),this.Space=Space,CanvasSpace=function(t){function i(t,e){this._resizeHandler=bind(this._resizeHandler,this);var n,s,o;t||(t="pt"),i.__super__.constructor.call(this,t),this.id="#"===this.id[0]?this.id.substr(1):this.id,this.space=null,this.bound=null,this.boundRect={top:0,left:0,width:0,height:0},this.pixelScale=1,this._autoResize=!0,s=document.querySelector("#"+this.id),n=!0,s?"canvas"!==s.nodeName.toLowerCase()?(this.bound=s,this.space=this._createElement("canvas",this.id+"_canvas"),this.bound.appendChild(this.space)):(this.space=s,this.bound=this.space.parentElement):(this.bound=this._createElement("div",this.id+"_container"),this.space=this._createElement("canvas",this.id),this.bound.appendChild(this.space),document.body.appendChild(this.bound),n=!1),n&&(o=this.bound.getBoundingClientRect(),this.resize(o.width,o.height)),this._mdown=!1,this._mdrag=!1,setTimeout(this._ready.bind(this,e),50),this.bgcolor="#F3F7FA",this.ctx=this.space.getContext("2d")}return extend(i,t),i.prototype._createElement=function(t,i){var e;return null==t&&(t="div"),e=document.createElement(t),e.setAttribute("id",i),e},i.prototype._ready=function(t){if(!this.bound)throw"Cannot initiate #"+this.id+" element";if(this.boundRect=this.bound.getBoundingClientRect(),this.resize(this.boundRect.width,this.boundRect.height),this.autoResize(this._autoResize),this.bgcolor&&this.clear(this.bgcolor),this.space.dispatchEvent(new Event("ready")),t&&"function"==typeof t)return t(this.boundRect,this.space)},i.prototype.display=function(){return console.warn("space.display(...) function is deprecated as of version 0.2.0. You can now set the canvas element in the constructor. Please see the release note for details."),this},i.prototype.setup=function(t){var i,e;return t.bgcolor&&(this.bgcolor=t.bgcolor),this._autoResize=t.resize!==!1,this.pixelScale=1,t.retina!==!1&&(i=window.devicePixelRatio||1,e=this.ctx.webkitBackingStorePixelRatio||this.ctx.mozBackingStorePixelRatio||this.ctx.msBackingStorePixelRatio||this.ctx.oBackingStorePixelRatio||this.ctx.backingStorePixelRatio||1,this.pixelScale=i/e),this},i.prototype._resizeHandler=function(t){return this.boundRect=this.bound.getBoundingClientRect(),this.resize(this.boundRect.width,this.boundRect.height,t)},i.prototype.autoResize=function(t){return null==t&&(t=!0),t?window.addEventListener("resize",this._resizeHandler):window.removeEventListener("resize",this._resizeHandler),this},i.prototype.resize=function(t,i,e){var n,s,o;t=Math.floor(t),i=Math.floor(i),this.size.set(t,i),this.center=new Vector(t/2,i/2),this.boundRect.width=t,this.boundRect.height=i,this.space.width=t*this.pixelScale,this.space.height=i*this.pixelScale,this.space.style.width=t+"px",this.space.style.height=i+"px",1!==this.pixelScale&&this.ctx.scale(this.pixelScale,this.pixelScale),o=this.items;for(n in o)s=o[n],null!=s.onSpaceResize&&s.onSpaceResize(t,i,e);return this.render(this.ctx),this},i.prototype.clear=function(t){var i;return t&&(this.bgcolor=t),i=this.ctx.fillStyle,this.bgcolor?(this.ctx.fillStyle=this.bgcolor,this.ctx.fillRect(0,0,this.size.x,this.size.y)):this.ctx.clearRect(0,0,this.size.x,this.size.y),this.ctx.fillStyle=i,this},i.prototype.animate=function(t){var i,e,n;this.ctx.save(),this._refresh&&this.clear(),e=this.items;for(i in e)n=e[i],n.animate(t,this._timeDiff,this.ctx);return this._timeEnd>=0&&t>this._timeEnd&&cancelAnimationFrame(this._animID),this.ctx.restore(),this},i}(Space),this.CanvasSpace=CanvasSpace,DOMSpace=function(t){function i(t,e,n){var s;null==n&&(n="div"),this._resizeHandler=bind(this._resizeHandler,this),t||(t="pt"),i.__super__.constructor.call(this,t),this.id="#"===this.id[0]?this.id.substr(1):this.id,this.space=null,this.bound=null,this.boundRect={top:0,left:0,width:0,height:0},this.css={},s=document.querySelector("#"+this.id),s?(this.space=s,this.bound=this.space.parentElement):(this.space=this._createElement(n,this.id),document.body.appendChild(this.space),this.bound=this.space.parentElement),this._mdown=!1,this._mdrag=!1,setTimeout(this._ready.bind(this,e),50),this.bgcolor=!1,this.ctx={}}return extend(i,t),i.prototype._createElement=function(t,i){var e;return null==t&&(t="div"),e=document.createElement(t),e.setAttribute("id",i),e},i.prototype._ready=function(t){if(!this.bound)throw"Cannot initiate #"+this.id+" element";if(this.boundRect=this.bound.getBoundingClientRect(),this.resize(this.boundRect.width,this.boundRect.height),this.autoResize(this._autoResize),this.bgcolor&&this.setCSS("backgroundColor",this.bgcolor),this.updateCSS(),this.space.dispatchEvent(new Event("ready")),t)return t(this.boundRect,this.space)},i.prototype.setCSS=function(t,i,e){return null==e&&(e=!1),this.css[t]=e?i+"px":i,this},i.prototype.updateCSS=function(){var t,i,e,n;i=this.css,e=[];for(t in i)n=i[t],e.push(this.space.style[t]=n);return e},i.prototype.display=function(){return console.warn("space.display(...) function is deprecated as of version 0.2.0. You can now set the DOM element in the constructor. Please see the release note for details."),this},i.prototype.setup=function(t){return t.bgcolor&&(this.bgcolor=t.bgcolor),this._autoResize=t.resize!==!1,this},i.prototype._resizeHandler=function(t){return this.boundRect=this.bound.getBoundingClientRect(),this.resize(this.boundRect.width,this.boundRect.height,t)},i.prototype.resize=function(t,i,e){var n,s,o;this.size.set(t,i),this.center=new Vector(t/2,i/2),o=this.items;for(n in o)s=o[n],null!=s.onSpaceResize&&s.onSpaceResize(t,i,e);return this},i.prototype.autoResize=function(t){return null==t&&(t=!0),t?(this.css.width="100%",this.css.height="100%",window.addEventListener("resize",this._resizeHandler)):(delete this.css.width,delete this.css.height,window.removeEventListener("resize",this._resizeHandler)),this},i.prototype.clear=function(){return this.space.innerHML=""},i.prototype.animate=function(t){var i,e,n;e=this.items;for(i in e)n=e[i],n.animate(t,this._timeDiff,this.ctx);return this._timeEnd>=0&&t>this._timeEnd&&cancelAnimationFrame(this._animID),this},i.attr=function(t,i){var e,n,s;n=[];for(e in i)s=i[e],n.push(t.setAttribute(e,s));return n},i.css=function(t){var i,e,n;e="";for(i in t)n=t[i],n&&(e+=i+": "+n+"; ");return e},i}(Space),this.DOMSpace=DOMSpace,SVGForm=function(){function t(t){this.cc=t.ctx||{},this.cc.group=this.cc.group||null,this.cc.groupID="ptx",this.cc.groupCount=0,this.cc.currentID="ptx0",this.cc.style={fill:"#999",stroke:"#666","stroke-width":1,"stroke-linejoin":!1,"stroke-linecap":!1},this.cc.font="11px sans-serif",this.cc.fontSize=11,this.cc.fontFace="sans-serif"}return t._domId=0,t.prototype.fill=function(t){return this.cc.style.fill=!!t&&t,this},t.prototype.stroke=function(t,i,e,n){return this.cc.style.stroke=!!t&&t,i&&(this.cc.style["stroke-width"]=i),e&&(this.cc.style["stroke-linejoin"]=e),n&&(this.cc.style["stroke-linecap"]=e),this},t.prototype.scope=function(t,i){return null==i&&(i=!1),i&&(this.cc.group=i),this.cc.groupID=t,this.cc.groupCount=0,this.nextID(),this.cc},t.prototype.enterScope=function(i){if(!i||null===i.animateID)throw"getScope()'s item must be added to a Space, and has an animateID property. Otherwise, use scope() instead.";return this.scope(t._scopeID(i))},t.prototype.getScope=function(t){return this._warn1||(console.warn("form.getScope(...) function is deprecated as of version 0.2.0. It is renamed as `enterScope()`."),this._warn1=!0),this.enterScope(t)},t.prototype.nextID=function(){return this.cc.groupCount++,this.cc.currentID=this.cc.groupID+"-"+this.cc.groupCount,this.cc.currentID},t.id=function(i){return i.currentID||"p-"+t._domId++},t._scopeID=function(t){return"item-"+t.animateID},t.style=function(t,i){var e,n,s;n=[];for(e in i)s=i[e],s?n.push(e+":"+s):"fill"===e?n.push("fill: none"):"stroke"===e&&n.push("stroke: none");return DOMSpace.attr(t,{style:n.join(";")})},t.point=function(i,e,n,s,o,r){var h;if(null==n&&(n=2),null==s&&(s=!0),null==o&&(o=!0),null==r&&(r=!1),h=SVGSpace.svgElement(i.group,r?"circle":"rect",t.id(i)))return r?DOMSpace.attr(h,{cx:e.x,cy:e.y,r:n}):DOMSpace.attr(h,{x:e.x-n,y:e.y-n,width:n+n,height:n+n}),t.style(h,i.style),h},t.prototype.point=function(i,e,n){return null==e&&(e=2),null==n&&(n=!1),this.nextID(),t.point(this.cc,i,e,!0,!0,n),this},t.points=function(i,e,n,s,o,r){var h;return null==n&&(n=2),null==s&&(s=!0),null==o&&(o=!0),null==r&&(r=!1),function(){var u,c,a;for(a=[],u=0,c=e.length;u<c;u++)h=e[u],a.push(t.point(i,h,n,s,o,r));return a}()},t.prototype.points=function(t,i,e){var n,s,o;for(null==i&&(i=2),null==e&&(e=!1),n=0,s=t.length;n<s;n++)o=t[n],this.point(o,i,e);return this},t.line=function(i,e){var n;if(!e.p1)throw e.toString()+" is not a Pair";return n=SVGSpace.svgElement(i.group,"line",t.id(i)),DOMSpace.attr(n,{x1:e.x,y1:e.y,x2:e.p1.x,y2:e.p1.y}),t.style(n,i.style),n},t.prototype.line=function(i){return this.nextID(),t.line(this.cc,i),this},t.lines=function(i,e){var n;return function(){var s,o,r;for(r=[],s=0,o=e.length;s<o;s++)n=e[s],r.push(t.line(i,n));return r}()},t.prototype.lines=function(t){var i,e,n;for(i=0,e=t.length;i<e;i++)n=t[i],this.line(n);return this},t.rect=function(i,e,n,s){var o,r;if(null==n&&(n=!0),null==s&&(s=!0),!e.p1)throw""+(e.toString()===!a(Pair));return o=SVGSpace.svgElement(i.group,"rect",t.id(i)),r=e.size(),DOMSpace.attr(o,{x:e.x,y:e.y,width:r.x,height:r.y}),t.style(o,i.style),o},t.prototype.rect=function(i,e){var n;return null==e&&(e=!0),this.nextID(),n=e?i.bounds():i,t.rect(this.cc,n),this},t.circle=function(i,e,n,s){var o;if(null==n&&(n=!0),null==s&&(s=!1),o=SVGSpace.svgElement(i.group,"circle",t.id(i)))return DOMSpace.attr(o,{cx:e.x,cy:e.y,r:e.radius}),t.style(o,i.style),o},t.prototype.circle=function(i){return this.nextID(),t.circle(this.cc,i),this},t.polygon=function(i,e,n,s,o){var r,h,u;if(null==n&&(n=!0),null==s&&(s=!0),null==o&&(o=!0),r=SVGSpace.svgElement(i.group,n?"polygon":"polyline",t.id(i)),r&&!(e.length<=1))return u=function(){var t,i,n;for(n=[],h=t=0,i=e.length;t<i;h=t+=1)n.push(e[h].x+","+e[h].y);return n}(),DOMSpace.attr(r,{points:u.join(" ")}),t.style(r,i.style),r},t.prototype.polygon=function(i,e){return this.nextID(),t.polygon(this.cc,i,e),this},t.triangle=function(i,e,n,s){return null==n&&(n=!0),null==s&&(s=!1),t.polygon(i,e.toArray())},t.prototype.triangle=function(i){return this.nextID(),t.triangle(this.cc,i),this},t.curve=function(i,e,n){return null==n&&(n=!1),t.polygon(i,e,n)},t.prototype.curve=function(i,e){return null==e&&(e=!1),this.nextID(),t.curve(this.cc,i,e),this},t.text=function(i,e,n,s,o,r){var h;if(null==s&&(s=0),null==o&&(o=0),null==r&&(r=0),h=SVGSpace.svgElement(i.group,"text",t.id(i)))return DOMSpace.attr(h,{"pointer-events":"none",x:e.x,y:e.y,dx:0,dy:0}),h.textContent=n,t.style(h,{fill:i.style.fill,stroke:i.style.stroke,"font-family":i.fontFace||!1,"font-size":i.fontSize||!1}),h},t.prototype.text=function(i,e,n,s,o){return null==n&&(n=1e3),this.nextID(),t.text(this.cc,i,e,n,s,o),this},t.prototype.font=function(t,i){return null==i&&(i=!1),this.cc.fontFace=i,this.cc.fontSize=t,this.cc.font=t+"px "+i,this},t.prototype.draw=function(t){return this.sketch(t)},t.prototype.sketch=function(i){return i.floor(),i instanceof Circle?t.circle(this.cc,i,this.filled,this.stroked):i instanceof Rectangle?t.rect(this.cc,i,this.filled,this.stroked):i instanceof Triangle?t.triangle(this.cc,i,this.filled,this.stroked):i instanceof Line||i instanceof Pair?t.line(this.cc,i):i instanceof PointSet?t.polygon(this.cc,i.points):(i instanceof Vector||i instanceof Point)&&t.point(this.cc,i),this},t}(),this.SVGForm=SVGForm,SVGSpace=function(t){function i(t,e){var n,s;i.__super__.constructor.call(this,t,e,"svg"),"svg"!==this.space.nodeName.toLowerCase()&&(s=this._createElement("svg",this.id+"_svg"),this.space.appendChild(s),this.bound=this.space,this.space=s,n=this.bound.getBoundingClientRect(),this.resize(n.width,n.height))}return extend(i,t),i.prototype._createElement=function(t,i){var e;return null==t&&(t="svg"),e=document.createElementNS("http://www.w3.org/2000/svg",t),i&&e.setAttribute("id",i),e},i.svgElement=function(t,i,e){var n;if(!(t&&t.appendChild||(t=this.space)))throw"parent parameter needs to be a DOM node";return n=document.querySelector("#"+e),n||(n=document.createElementNS("http://www.w3.org/2000/svg",i),n.setAttribute("id",e),n.setAttribute("class",e.substring(0,e.indexOf("-"))),t.appendChild(n)),n},i.prototype.remove=function(t){var i,e,n,s;for(s=this.space.querySelectorAll("."+SVGForm._scopeID(t)),i=0,e=s.length;i<e;i++)n=s[i],n.parentNode.removeChild(n);return delete this.items[t.animateID],this},i.prototype.removeAll=function(){for(;this.space.firstChild;)return this.space.removeChild(this.space.firstChild),this},i}(DOMSpace),this.SVGSpace=SVGSpace,Form=function(){function t(t){this.space=t,this.cc=t.ctx,this.cc.fillStyle="#999",this.cc.strokeStyle="#666",this.cc.lineWidth=1,this.cc.font="11px sans-serif",this.filled=!0,this.stroked=!0,this.fontSize=11,this.fontFace="sans-serif"}return t.context=function(t){var i,e;if(e=document.getElementById(t),i=!(!e||!e.getContext)&&e.getContext("2d"),!i)throw"Cannot initiate canvas 2d context";return i},t.line=function(t,i){if(!i.p1)throw i.toString()+" is not a Pair";return t.beginPath(),t.moveTo(i.x,i.y),t.lineTo(i.p1.x,i.p1.y),t.stroke()},t.lines=function(i,e){var n,s,o,r;for(r=[],n=0,s=e.length;n<s;n++)o=e[n],r.push(t.line(i,o));return r},t.rect=function(t,i,e,n){if(null==e&&(e=!0),null==n&&(n=!1),!i.p1)throw""+(i.toString()===!a(Pair));if(t.beginPath(),t.moveTo(i.x,i.y),t.lineTo(i.x,i.p1.y),t.lineTo(i.p1.x,i.p1.y),t.lineTo(i.p1.x,i.y),t.closePath(),n&&t.stroke(),e)return t.fill()},t.circle=function(t,i,e,n){null==e&&(e=!0),null==n&&(n=!1),t.beginPath(),t.arc(i.x,i.y,i.radius,0,Const.two_pi,!1),e&&t.fill(),n&&t.stroke()},t.arc=function(t,i,e,n,s){return t.beginPath(),t.arc(i.x,i.y,e,n,s),t.stroke()},t.triangle=function(t,i,e,n){null==e&&(e=!0),null==n&&(n=!1),t.beginPath(),t.moveTo(i.x,i.y),t.lineTo(i.p1.x,i.p1.y),t.lineTo(i.p2.x,i.p2.y),t.closePath(),e&&t.fill(),n&&t.stroke()},t.point=function(t,i,e,n,s,o){var r,h,u,c;return null==e&&(e=2),null==n&&(n=!0),null==s&&(s=!1),null==o&&(o=!1),o?(t.beginPath(),t.arc(i.x,i.y,e,0,Const.two_pi,!1)):(r=i.x-e,u=i.y-e,h=i.x+e,c=i.y+e,t.beginPath(),t.moveTo(r,u),t.lineTo(r,c),t.lineTo(h,c),t.lineTo(h,u),t.closePath()),n&&t.fill(),s&&t.stroke(),i},t.points=function(i,e,n,s,o,r){var h,u,c,a;for(null==n&&(n=2),null==s&&(s=!0),null==o&&(o=!1),null==r&&(r=!1),a=[],h=0,u=e.length;h<u;h++)c=e[h],a.push(t.point(i,c,n,s,o,r));return a},t.polygon=function(t,i,e,n,s){var o,r,h;if(null==e&&(e=!0),null==n&&(n=!0),null==s&&(s=!0),!(i.length<=1)){for(t.beginPath(),t.moveTo(i[0].x,i[0].y),r=o=1,h=i.length;o<h;r=o+=1)t.lineTo(i[r].x,i[r].y);e&&t.closePath(),n&&t.fill(),s&&t.stroke()}},t.curve=function(i,e){return t.polygon(i,e,!1,!1,!0)},t.text=function(t,i,e,n){return t.fillText(e,i.x,i.y,n)},t.prototype.fill=function(t){return this.cc.fillStyle=t?t:"transparent",this.filled=!!t,this},t.prototype.stroke=function(t,i,e){return this.cc.strokeStyle=t?t:"transparent",this.stroked=!!t,i&&(this.cc.lineWidth=i),e&&(this.cc.lineJoin=e),this},t.prototype.font=function(t,i){return null==i&&(i=this.fontFace),this.fontSize=t,this.cc.font=t+"px "+i,this},t.prototype.draw=function(t){return this.sketch(t)},t.prototype.sketch=function(i){return i.floor(),i instanceof Circle?t.circle(this.cc,i,this.filled,this.stroked):i instanceof Rectangle?t.rect(this.cc,i,this.filled,this.stroked):i instanceof Triangle?t.triangle(this.cc,i,this.filled,this.stroked):i instanceof Line||i instanceof Pair?t.line(this.cc,i):i instanceof PointSet?t.polygon(this.cc,i.points):(i instanceof Vector||i instanceof Point)&&t.point(this.cc,i),this},t.prototype.point=function(i,e,n){return null==e&&(e=2),null==n&&(n=!1),t.point(this.cc,i,e,this.filled,this.stroked,n),this},t.prototype.points=function(i,e,n){return null==e&&(e=2),null==n&&(n=!1),t.points(this.cc,i,e,this.filled,this.stroked,n),this},t.prototype.line=function(i){return t.line(this.cc,i),this},t.prototype.lines=function(i){return t.lines(this.cc,i),this},t.prototype.rect=function(i){return t.rect(this.cc,i,this.filled,this.stroked),this},t.prototype.circle=function(i){return t.circle(this.cc,i,this.filled,this.stroked),this},t.prototype.arc=function(i,e,n){return t.arc(this.cc,i,i.radius,e,n),this},t.prototype.triangle=function(i){return t.triangle(this.cc,i,this.filled,this.stroked),this},t.prototype.polygon=function(i,e){return t.polygon(this.cc,i,e,this.filled,this.stroked),this},t.prototype.curve=function(i){return t.curve(this.cc,i),this},t.prototype.text=function(t,i,e,n,s){var o;return null==e&&(e=1e3),o=new Vector(t),n&&o.add(n,0),s&&o.add(0,s),this.cc.fillText(i,o.x,o.y,e),this},t.prototype.scope=function(){return this.cc},t.prototype.enterScope=function(){return this.cc},t}(),this.Form=Form,Point=function(){function t(i){this.copy(t.get(arguments))}return t.get=function(t){return t.length>0?"object"==typeof t[0]?t[0]instanceof Array||t[0].length>0?{x:t[0][0]||0,y:t[0][1]||0,z:t[0][2]||0}:{x:t[0].x||0,y:t[0].y||0,z:t[0].z||0}:{x:t[0]||0,y:t[1]||0,z:t[2]||0}:{x:0,y:0,z:0}},t.prototype.quadrant=function(t,i){return null==i&&(i=Const.epsilon),t.near(this)?Const.identical:Math.abs(t.x-this.x)<i?t.y<this.y?Const.top:Const.bottom:Math.abs(t.y-this.y)<i?t.x<this.x?Const.left:Const.right:t.y<this.y&&t.x>this.x?Const.top_right:t.y<this.y&&t.x<this.x?Const.top_left:t.y>this.y&&t.x<this.x?Const.bottom_left:Const.bottom_right},t.prototype.set=function(i){var e;return e=t.get(arguments),this.x=e.x,this.y=e.y,this.z=e.z,this},t.prototype.copy=function(t){return this.x=t.x,this.y=t.y,this.z=t.z,this},t.prototype.clone=function(){return new t(this)},t.prototype.toString=function(){return"Point "+this.x+", "+this.y+", "+this.z},t.prototype.toArray=function(){return[this]},t.prototype.get2D=function(t,i){return null==i&&(i=!1),t===Const.xy?new this.__proto__.constructor(this):t===Const.xz?new this.__proto__.constructor(this.x,this.z,this.y):t===Const.yz?i?new this.__proto__.constructor(this.z,this.x,this.y):new this.__proto__.constructor(this.y,this.z,this.x):new this.__proto__.constructor(this)},t.prototype.min=function(i){var e;return e=t.get(arguments),this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this.z=Math.min(this.z,e.z),this},t.prototype.$min=function(i){var e;return e=t.get(arguments),new this.__proto__.constructor(Math.min(this.x,e.x),Math.min(this.y,e.y),Math.min(this.z,e.z))},t.prototype.max=function(i){var e;return e=t.get(arguments),this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this.z=Math.max(this.z,e.z),this},t.prototype.$max=function(i){var e;return e=t.get(arguments),new this.__proto__.constructor(Math.max(this.x,e.x),Math.max(this.y,e.y),Math.max(this.z,e.z))},t.prototype.equal=function(i){var e;return e=t.get(arguments),e.x===this.x&&e.y===this.y&&e.z===this.z},t.prototype.near=function(i,e){var n;return null==e&&(e=Const.epsilon),n=t.get(arguments),Math.abs(n.x-this.x)<e&&Math.abs(n.y-this.y)<e&&Math.abs(n.z-this.z)<e},t.prototype.floor=function(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this},t.prototype.ceil=function(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this},t}(),this.Point=Point,Vector=function(t){function i(){i.__super__.constructor.apply(this,arguments)}return extend(i,t),i.prototype._getArgs=function(t){return"number"==typeof t[0]&&t.length>1?t:t[0]},i.prototype.add=function(t){var i;return"number"==typeof arguments[0]&&1===arguments.length?(this.x+=arguments[0],this.y+=arguments[0],this.z+=arguments[0]):(i=Point.get(arguments),this.x+=i.x,this.y+=i.y,this.z+=i.z),this},i.prototype.$add=function(t){var e;return e=this._getArgs(arguments),new i(this).add(e)},i.prototype.subtract=function(t){var i;return"number"==typeof arguments[0]&&1===arguments.length?(this.x-=arguments[0],this.y-=arguments[0],this.z-=arguments[0]):(i=Point.get(arguments),this.x-=i.x,this.y-=i.y,this.z-=i.z),this},i.prototype.$subtract=function(t){var e;return e=this._getArgs(arguments),new i(this).subtract(e)},i.prototype.multiply=function(t){var i;return 1===arguments.length&&("number"==typeof arguments[0]||"object"==typeof arguments[0]&&1===arguments[0].length)?(this.x*=arguments[0],this.y*=arguments[0],this.z*=arguments[0]):(i=Point.get(arguments),this.x*=i.x,this.y*=i.y,this.z*=i.z),this},i.prototype.$multiply=function(t){var e;return e=this._getArgs(arguments),new i(this).multiply(e)},i.prototype.divide=function(t){var i;return 1===arguments.length&&("number"==typeof arguments[0]||"object"==typeof arguments[0]&&1===arguments[0].length)?(this.x/=arguments[0],this.y/=arguments[0],this.z/=arguments[0]):(i=Point.get(arguments),this.x/=i.x,this.y/=i.y,this.z/=i.z),this},i.prototype.$divide=function(t){var e;return e=this._getArgs(arguments),new i(this).divide(e)},i.prototype.op=function(){var t,i,e,n,s,o;for(n=arguments[0],i=2<=arguments.length?slice.call(arguments,1):[],o=this.toArray(),t=0,e=o.length;t<e;t++)s=o[t],s[n].apply(s,i);return this},i.prototype.$op=function(){var t,i,e,n,s,o,r;for(s=arguments[0],i=2<=arguments.length?slice.call(arguments,1):[],e=this.clone(),r=e.toArray(),t=0,n=r.length;t<n;t++)o=r[t],o[s].apply(o,i);return e},i.prototype.angle=function(t){var i,e;return 0===arguments.length?Math.atan2(this.y,this.x):("string"==typeof arguments[0]?(i=arguments[0],e=arguments.length>1?this.$subtract(arguments[1]).multiply(-1):void 0):(e=this.$subtract(arguments[0]).multiply(-1),i=!1),e&&!i?Math.atan2(e.y,e.x):i===Const.xy?e?Math.atan2(e.y,e.x):Math.atan2(this.y,this.x):i===Const.yz?e?Math.atan2(e.z,e.y):Math.atan2(this.z,this.y):i===Const.xz?e?Math.atan2(e.z,e.x):Math.atan2(this.z,this.x):void 0)},i.prototype.angleBetween=function(t,i){return null==i&&(i=Const.xy),Util.boundRadian(this.angle(i),!0)-Util.boundRadian(t.angle(i),!0);
},i.prototype.magnitude=function(t){var i,e,n,s,o,r;return n={x:this.x*this.x,y:this.y*this.y,z:this.z*this.z},r=arguments.length>=1&&!arguments[arguments.length-1],i=r?function(t){return t}:Math.sqrt,0===arguments.length?i(n.x+n.y+n.z):("string"==typeof arguments[0]?(e=arguments[0],o=arguments.length>1&&arguments[1]?this.$subtract(arguments[1]):void 0):(o=this.$subtract(arguments[0]),e=!1),s=o?{x:o.x*o.x,y:o.y*o.y,z:o.z*o.z}:n,o&&!e?i(s.x+s.y+s.z):e===Const.xy?i(s.x+s.y):e===Const.yz?i(s.y+s.z):e===Const.xz?i(s.x+s.z):void 0)},i.prototype.distance=function(t,i){return null==i&&(i=Const.xy),this.magnitude(i,t)},i.prototype.normalize=function(){return this.set(this.$normalize()),this},i.prototype.$normalize=function(){var t;return t=this.magnitude(),0===t?new i:new i(this.x/t,this.y/t,this.z/t)},i.prototype.abs=function(){return this.x=Math.abs(this.x),this.y=Math.abs(this.y),this.z=Math.abs(this.z),this},i.prototype.dot=function(t,i){return null==i&&(i=Const.xyz),i===Const.xyz?this.x*t.x+this.y*t.y+this.z*t.z:i===Const.xy?this.x*t.x+this.y*t.y:i===Const.yz?this.y*t.y+this.z*t.z:i===Const.xz?this.x*t.x+this.z*t.z:this.x*t.x+this.y*t.y+this.z*t.z},i.prototype.projection=function(t,e){var n,s,o,r;return null==e&&(e=Const.xyz),r=t.magnitude(),n=this.$normalize(),s=new i(t.x/r,t.y/r,t.z/r),o=n.dot(s,e),n.$multiply(r*o)},i.prototype.cross=function(t){return new i(this.y*t.z-this.z*t.y,this.z*t.x-this.x*t.z,this.x*t.y-this.y*t.x)},i.prototype.bisect=function(t,i){return null==i&&(i=!1),i?this.$add(t).divide(2):this.$normalize().add(t.$normalize()).divide(2)},i.prototype.perpendicular=function(t){switch(null==t&&(t=Const.xy),t){case Const.xy:return[new i((-this.y),this.x,this.z),new i(this.y,(-this.x),this.z)];case Const.yz:return[new i(this.x,(-this.z),this.y),new i(this.x,this.z,(-this.y))];case Const.xz:return[new i((-this.z),this.y,this.x),new i(this.z,(-this.y),this.x)];default:return[new i((-this.y),this.x,this.z),new i(this.y,(-this.x),this.z)]}},i.prototype.isPerpendicular=function(t,i){return null==i&&(i=Const.xyz),0===this.dot(t,i)},i.prototype.surfaceNormal=function(t){return this.cross(t).normalize(!0)},i.prototype.moveTo=function(t){var i,e,n,s,o,r;for(r=Point.get(arguments),e=this.$subtract(r),o=this.toArray(),i=0,n=o.length;i<n;i++)s=o[i],s.subtract(e);return this},i.prototype.moveBy=function(t){var i,e,n,s,o;for(e=Point.get(arguments),o=this.toArray(),i=0,n=o.length;i<n;i++)s=o[i],s.add(e);return this},i.prototype.rotate2D=function(t,i,e){var n,s,o,r,h;for(null==e&&(e=Const.xy),i||(i=new Point(0,0,0)),o=Matrix.rotateAnchor2D(t,i,e),h=this.toArray(),n=0,s=h.length;n<s;n++)r=h[n],Matrix.transform2D(r,o,e);return this},i.prototype.reflect2D=function(t,i){var e,n,s,o,r;for(null==i&&(i=Const.xy),s=Matrix.reflectAnchor2D(t,i),r=this.toArray(),e=0,n=r.length;e<n;e++)o=r[e],Matrix.transform2D(o,s,i);return this},i.prototype.scale2D=function(t,i,e,n){var s,o,r,h,u;for(null==n&&(n=Const.xy),e||(e=new Point(0,0,0)),r=Matrix.scaleAnchor2D(t,i,e,n),u=this.toArray(),s=0,o=u.length;s<o;s++)h=u[s],Matrix.transform2D(h,r,n);return this},i.prototype.shear2D=function(t,i,e,n){var s,o,r,h,u;for(null==n&&(n=Const.xy),e||(e=new Point(0,0,0)),r=Matrix.shearAnchor2D(t,i,e,n),u=this.toArray(),s=0,o=u.length;s<o;s++)h=u[s],Matrix.transform2D(h,r,n);return this},i.prototype.clone=function(){return new i(this)},i.prototype.toString=function(){return"Vector "+this.x+", "+this.y+", "+this.z},i}(Point),this.Vector=Vector,Color=function(t){function i(t){var e;i.__super__.constructor.apply(this,arguments),e=Array.isArray(arguments[0])&&void 0!==arguments[0][3]?arguments[0]:arguments,this.alpha=e.length>=4?Math.min(1,Math.max(e[3],0)):1,this.mode="rgb",arguments.length>=5&&(this.mode=arguments[4]),"string"==typeof arguments[1]&&(this.mode=arguments[1])}return extend(i,t),i.XYZ={D65:{x:95.047,y:100,z:108.883}},i.parseHex=function(t,e){var n,s;return null==e&&(e=!1),0===t.indexOf("#")&&(t=t.substr(1)),3===t.length&&(t=""+t[0]+t[0]+t[1]+t[1]+t[2]+t[2]),8===t.length&&(this.alpha=1&t.substr(6),t=t.substring(0,6)),n=parseInt(t,16),s=[n>>16,n>>8&255,255&n],e?new i(s[0],s[1],s[2]):s},i.prototype.setMode=function(t){if(t=t.toLowerCase(),t!==this.mode){switch(this.mode){case"hsl":this.copy(Point.get(i.HSLtoRGB(this.x,this.y,this.z)));break;case"hsb":this.copy(Point.get(i.HSBtoRGB(this.x,this.y,this.z)));break;case"lab":this.copy(Point.get(i.LABtoRGB(this.x,this.y,this.z)));break;case"lch":this.copy(Point.get(i.LCHtoRGB(this.x,this.y,this.z)));break;case"xyz":this.copy(Point.get(i.XYZtoRGB(this.x,this.y,this.z)))}switch(t){case"hsl":this.copy(Point.get(i.RGBtoHSL(this.x,this.y,this.z)));break;case"hsb":this.copy(Point.get(i.RGBtoHSB(this.x,this.y,this.z)));break;case"lab":this.copy(Point.get(i.RGBtoLAB(this.x,this.y,this.z)));break;case"lch":this.copy(Point.get(i.RGBtoLCH(this.x,this.y,this.z)));break;case"xyz":this.copy(Point.get(i.RGBtoXYZ(this.x,this.y,this.z)))}}return this.mode=t,this},i.prototype.hex=function(){var t,i,e,n;return"rgb"===this.mode&&this.floor(),i=this.values("rgb"!==this.mode),t=function(t){return t=t.toString(16),t.length<2?"0"+t:t},e=function(){var e,s,o;for(o=[],e=0,s=i.length;e<s;e++)n=i[e],o.push(t(n));return o}(),"#"+e[0]+e[1]+e[2]},i.prototype.rgb=function(){var t;return"rgb"===this.mode&&this.floor(),t=this.values("rgb"!==this.mode),"rgb("+t[0]+", "+t[1]+", "+t[2]+")"},i.prototype.rgba=function(){var t;return"rgb"===this.mode&&this.floor(),t=this.values("rgb"!==this.mode),"rgba("+t[0]+", "+t[1]+", "+t[2]+", "+this.alpha+")"},i.prototype.values=function(t){var e,n;if(null==t&&(t=!1),e=[this.x,this.y,this.z],t&&"rgb"!==this.mode)switch(this.mode){case"hsl":e=i.HSLtoRGB(this.x,this.y,this.z);break;case"hsb":e=i.HSBtoRGB(this.x,this.y,this.z);break;case"lab":e=i.LABtoRGB(this.x,this.y,this.z);break;case"lch":e=i.LCHtoRGB(this.x,this.y,this.z);break;case"xyz":e=i.XYZtoRGB(this.x,this.y,this.z)}return function(){var t,i,s;for(s=[],t=0,i=e.length;t<i;t++)n=e[t],s.push(Math.floor(n));return s}()},i.prototype.clone=function(){var t;return t=new i(this.x,this.y,this.z,this.alpha),t.mode=this.mode,t},i.prototype.toString=function(){return"Color ("+this.mode+" mode): "+this.x+", "+this.y+", "+this.z+" "+this.alpha},i.RGBtoHSL=function(t,i,e,n,s){var o,r,h,u,c,a;if(n||(t/=255,i/=255,e/=255),u=Math.max(t,i,e),c=Math.min(t,i,e),r=(u+c)/2,a=r,h=r,u===c)r=0,a=0;else switch(o=u-c,a=h>.5?o/(2-u-c):o/(u+c),u){case t:r=(i-e)/o+(i<e?6:0);break;case i:r=(e-t)/o+2;break;case e:r=(t-i)/o+4;break;default:r=0}return s?[r/60,a,h]:[60*r,a,h]},i.HSLtoRGB=function(t,i,e,n,s){var o,r,h,u,c,a;return 0===i?s?[1,1,1]:[255,255,255]:(n||(t/=360),c=e<=.5?e*(1+i):e+i-e*i,u=2*e-c,h=function(t,i,e){return e<0?e+=1:e>1&&(e-=1),6*e<1?t+(i-t)*e*6:2*e<1?i:3*e<2?t+(i-t)*(2/3-e)*6:t},a=h(u,c,t+1/3),r=h(u,c,t),o=h(u,c,t-1/3),s?[a,r,o]:[255*a,255*r,255*o])},i.RGBtoHSB=function(t,i,e,n,s){var o,r,h,u,c,a;if(n||(t/=255,i/=255,e/=255),h=Math.max(t,i,e),u=Math.min(t,i,e),o=h-u,c=0===h?0:o/h,a=h,h===u)r=0;else switch(h){case t:r=(i-e)/o+(i<e?6:0);break;case i:r=(e-t)/o+2;break;case e:r=(t-i)/o+4;break;default:r=0}return s?[r/60,c,a]:[60*r,c,a]},i.HSBtoRGB=function(t,i,e,n,s){var o,r,h,u,c,a;switch(n||(t/=360),r=Math.floor(6*t),o=6*t-r,h=e*(1-i),u=e*(1-o*i),a=e*(1-(1-o)*i),r%6){case 0:c=[e,a,h];break;case 1:c=[u,e,h];break;case 2:c=[h,e,a];break;case 3:c=[h,u,e];break;case 4:c=[a,h,e];break;case 5:c=[e,h,u];break;default:c=[0,0,0]}return s?c:[255*c[0],255*c[1],255*c[2]]},i.RGBtoLAB=function(t,e,n,s,o){var r;return s&&(t*=255,e*=255,n*=255),r=i.RGBtoXYZ(t,e,n),i.XYZtoLAB(r[0],r[1],r[2])},i.LABtoRGB=function(t,e,n,s,o){var r,h;return s&&(t*=100,e=127*(e-.5),n=127*(n-.5)),h=i.LABtoXYZ(t,e,n),r=i.XYZtoRGB(h[0],h[1],h[2]),o?[r[0]/255,r[1]/255,r[2]/255]:r},i.RGBtoLCH=function(t,e,n,s,o){var r,h;return s&&(t*=255,e*=255,n*=255),r=i.RGBtoLAB(t,e,n),h=i.LABtoLCH(r[0],r[1],r[2]),o?[h[0]/100,h[1]/100,h[2]/360]:h},i.LCHtoRGB=function(t,e,n,s,o){var r,h,u;return s&&(t*=100,e*=100,n*=360),r=i.LCHtoLAB(t,e,n),u=i.LABtoXYZ(r[0],r[1],r[2]),h=i.XYZtoRGB(u[0],u[1],u[2]),o?[h[0]/255,h[1]/255,h[2]/255]:h},i.XYZtoRGB=function(t,i,e,n,s){var o,r,h,u,c;for(n||(t/=100,i/=100,e/=100),c=[3.2404542*t+i*-1.5371385+e*-.4985314,t*-.969266+1.8760108*i+.041556*e,.0556434*t+i*-.2040259+1.0572252*e],h=o=0,u=c.length;o<u;h=++o)r=c[h],r<0?c[h]=0:c[h]=Math.min(1,r>.0031308?1.055*Math.pow(r,1/2.4)-.055:12.92*r);return s?c:[Math.round(255*c[0]),Math.round(255*c[1]),Math.round(255*c[2])]},i.RGBtoXYZ=function(t,i,e,n,s){return n||(t/=255,i/=255,e/=255),t=t>.04045?Math.pow((t+.055)/1.055,2.4):t/12.92,i=i>.04045?Math.pow((i+.055)/1.055,2.4):i/12.92,e=e>.04045?Math.pow((e+.055)/1.055,2.4):e/12.92,s||(t=100*t,i=100*i,e=100*e),[.4124564*t+.3575761*i+.1804375*e,.2126729*t+.7151522*i+.072175*e,.0193339*t+.119192*i+.9503041*e]},i.XYZtoLAB=function(t,e,n){var s,o;return t/=i.XYZ.D65.x,e/=i.XYZ.D65.y,n/=i.XYZ.D65.z,s=function(t){return t>.008856?Math.pow(t,1/3):7.787*t+16/116},o=s(e),[116*o-16,500*(s(t)-o),200*(o-s(n))]},i.LABtoXYZ=function(t,e,n){var s,o,r,h,u;return h=(t+16)/116,o=e/500+h,u=h-n/200,s=function(t){var i;return i=Math.pow(t,3),i>.008856?i:(t-16/116)/7.787},r=[Math.min(i.XYZ.D65.x,i.XYZ.D65.x*s(o)),Math.min(i.XYZ.D65.y,i.XYZ.D65.y*s(h)),Math.min(i.XYZ.D65.y,i.XYZ.D65.z*s(u))]},i.XYZtoLUV=function(t,e,n){var s,o,r,h,u;return h=4*t/(t+15*e+3*n),u=9*e/(t+15*e+3*n),e/=100,e=e>.008856?Math.pow(e,1/3):7.787*e+16/116,o=4*i.XYZ.D65.x/(i.XYZ.D65.x+15*i.XYZ.D65.y+3*i.XYZ.D65.z),r=9*i.XYZ.D65.y/(i.XYZ.D65.x+15*i.XYZ.D65.y+3*i.XYZ.D65.z),s=116*e-16,[s,13*s*(h-o),13*s*(u-r)]},i.LUVtoXYZ=function(t,e,n){var s,o,r,h,u;return u=(t+16)/116,s=u*u*u,u=s>.008856?s:(u-16/116)/7.787,o=4*i.XYZ.D65.x/(i.XYZ.D65.x+15*i.XYZ.D65.y+3*i.XYZ.D65.z),r=9*i.XYZ.D65.y/(i.XYZ.D65.x+15*i.XYZ.D65.y+3*i.XYZ.D65.z),e=e/(13*t)+o,n=n/(13*t)+r,u=100*u,h=-1*(9*u*e)/((e-4)*n-e*n),[h,u,(9*u-15*n*u-n*h)/(3*n)]},i.LABtoLCH=function(t,i,e){var n;return n=Math.atan2(e,i),n=n>0?180*n/Math.PI:360-180*Math.abs(n)/Math.PI,[t,Math.sqrt(i*i+e*e),n]},i.LCHtoLAB=function(t,i,e){var n;return n=Math.PI*e/180,[t,Math.cos(n)*i,Math.sin(n)*i]},i.LUVtoLCH=function(t,i,e){return LABtoLCH(t,i,e)},i.LCHtoLUV=function(t,i,e){return LCHtoLAB(t,i,e)},i}(Vector),this.Color=Color,Circle=function(t){function i(){i.__super__.constructor.apply(this,arguments),this.radius=null!=arguments[3]?arguments[3]:0}return extend(i,t),i.prototype.setRadius=function(t){return this.radius=t,this},i.prototype.intersectPoint=function(t){var i,e;return e=new Vector(Point.get(arguments)),i=e.$subtract(this),i.x*i.x+i.y*i.y<this.radius*this.radius},i.prototype.intersectPath=function(t,i){var e,n,s,o,r,h,u,c,a,p,l,y,f;return null==i&&(i=!0),!(!t instanceof Pair)&&(o=t.direction(),u=this.$subtract(t),e=o.dot(o,Const.xy),n=u.dot(o,Const.xy),s=u.dot(u,Const.xy)-this.radius*this.radius,c=n/e,l=s/e,r=c*c-l,r<0?!!i&&[]:!i||(h=Math.sqrt(r),y=-c+h,f=-c-h,a=new Point(t.x-o.x*y,t.y-o.y*y),p=new Point(t.x-o.x*f,t.y-o.y*f),0===r?[a]:[a,p]))},i.prototype.intersectLine=function(t,i){var e,n,s,o,r,h;if(null==i&&(i=!0),h=this.intersectPath(t),h&&h.length>0){for(r=[],n=t.bounds(),e=0,s=h.length;e<s;e++)if(o=h[e],Rectangle.contain(o,n,n.p1)){if(!i)return!0;r.push(o)}return i?r:r.length>0}return!!i&&[]},i.prototype.intersectLines=function(t,i){return null==i&&(i=!0),Line.intersectLines(this,t,i)},i.prototype.intersectCircle=function(t,i){var e,n,s,o,r,h,u,c;return null==i&&(i=!0),h=t.$subtract(this),r=h.magnitude(!1),o=Math.sqrt(r),n=this.radius*this.radius,s=t.radius*t.radius,o>this.radius+t.radius?!!i&&[]:o<Math.abs(this.radius-t.radius)?!i||[new Vector(this),new Vector(t)]:!i||(e=(n-s+r)/(2*o),u=Math.sqrt(n-e*e),c=h.$multiply(e/o).add(this),[new Vector(c.x+u*h.y/o,c.y-u*h.x/o),new Vector(c.x-u*h.y/o,c.y+u*h.x/o)])},i.prototype.hasIntersect=function(t,e){var n,s;return null==e&&(e=!1),t instanceof i?this.intersectCircle(t,e):t instanceof Rectangle||t instanceof PointSet||t instanceof Triangle?this.intersectLines(t.sides(),e):t instanceof Pair?(s=this.intersectLine(t),e?s:s.length>0):t instanceof Point?(n=t.$subtract(this),n.x*n.x+n.y*n.y<this.radius*this.radius):!!e&&[]},i.prototype.toString=function(){return"Circle of "+this.radius+" radius at center "+this.x+", "+this.y+", "+this.z},i}(Vector),this.Circle=Circle,Particle=function(t){function i(){i.__super__.constructor.apply(this,arguments),this.id=0,this.life={age:0,maxAge:0,active:!0,complete:!1},this.momentum=new Vector,this.velocity=new Vector,this.mass=2,this.friction=0,this.frame_ms=20}return extend(i,t),i.prototype.play=function(t,i){var e,n,s;for(s=0,n=[];i>0;)e=Math.min(i,this.frame_ms),this.integrate(s/1e3,e/1e3),i-=e,s+=e,n.push(this.life.age++);return n},i.prototype.integrate=function(t,i){return this.integrateRK4(t,i)},i.prototype.forces=function(t,i){return{force:new Vector}},i.prototype.impulse=function(t){return this.momentum.add(t),this.velocity=this.momentum.$divide(this.mass)},i.prototype._evaluate=function(t,i,e){var n,s;return null==i&&(i=0),null==e&&(e=!1),s=0!==i&&e?{position:this.$add(e.velocity.$multiply(i)),momentum:this.momentum.$add(e.force.$multiply(i))}:{position:new Vector(this),momentum:new Vector(this.momentum)},s.velocity=s.momentum.$divide(this.mass),n=this.forces(s,t+i),{velocity:s.velocity,force:n.force}},i.prototype.integrateRK4=function(t,i){var e,n,s,o,r;return e=function(t,i,e,n){var s;return s=new Vector((t.x+2*(i.x+e.x)+n.x)/6,(t.y+2*(i.y+e.y)+n.y)/6,(t.z+2*(i.z+e.z)+n.z)/6)},n=this._evaluate(t,0),s=this._evaluate(t,.5*i,n),o=this._evaluate(t,.5*i,s),r=this._evaluate(t,i,o),this.add(e(n.velocity,s.velocity,o.velocity,r.velocity)),this.momentum.add(e(n.force,s.force,o.force,r.force))},i.prototype.integrateEuler=function(t,i){var e;return e=this.forces({position:new Vector(this),momentum:new Vector(this.momentum)},t+i),this.add(this.velocity),this.momentum.add(e.force),this.velocity=this.momentum.$divide(this.mass)},i.prototype.collideLine2d=function(t,i){var e,n,s,o,r,h,u,c,a,p,l,y,f,d,m,x,g,v,z,_;if(null==i&&(i=!0),r=new Vector(this),o=Math.abs(t.getDistanceFromPoint(r)),n=Math.abs(o)<this.radius,i&&(a=this.$add(this.velocity),c=Math.abs(t.getDistanceFromPoint(a)),s=t.intersectLine(new Line(r).to(a)),s&&(a=s.$add(this.velocity.$normalize().$multiply(-this.radius/2)),c=Math.abs(t.getDistanceFromPoint(a)),n=!0)),n){if(x=t.getPerpendicularFromPoint(r),_=t.$subtract(t.p1),e=!1,!t.withinBounds(x,Const.xy)){if(this.intersectPoint(t)&&(e=!0,u=this.$subtract(t)),this.intersectPoint(t.p1)&&(e=!0,u=this.$subtract(t.p1)),!e)return!1;_=new Vector((-u.y),u.x)}h=_.dot(this.velocity),f=_.$multiply(h/_.dot(_)),z=f.$subtract(this.velocity),this.velocity=f.$add(z),this.momentum=this.velocity.$multiply(this.mass),i&&!e&&(l=new Line(x).to(r),y=t.getPerpendicularFromPoint(a),p=new Line(x).to(y),g=p.direction(),v=(this.radius-o)/(c-o),d=g.$multiply(v).$add(p),m=d.$add(l.direction().$normalize().$multiply(this.radius)),this.set(m.$add(this.velocity.$normalize())))}return n},i.prototype.collideWithinBounds=function(t){return this.x-this.radius<t.x||this.x+this.radius>t.p1.x?(this.x-this.radius<t.x?this.x=t.x+this.radius:this.x+this.radius>t.p1.x&&(this.x=t.p1.x-this.radius),this.velocity.x*=-1,this.momentum=this.velocity.$multiply(this.mass),!0):(this.y-this.radius<t.y||this.y+this.radius>t.p1.y)&&(this.y-this.radius<t.y?this.y=t.y+this.radius:this.y+this.radius>t.p1.y&&(this.y=t.p1.y-this.radius),this.velocity.y*=-1,this.momentum=this.velocity.$multiply(this.mass),!0)},i.prototype.collideParticle2d=function(t){return!!this.hasIntersect(t)&&i.collideParticle2d(this,t,!0)},i.collideParticle2d=function(t,i,e,n){var s,o,r,h,u,c,a,p,l,y,f,d,m,x,g,v,z;return null==e&&(e=!0),null==n&&(n=!0),y=t.$subtract(i).normalize(),m=new Vector((-y.y),y.x),h=y.dot(t.velocity),u=m.dot(t.velocity),c=y.dot(i.velocity),a=m.dot(i.velocity),s=(h*(t.mass-i.mass)+2*i.mass*c)/(t.mass+i.mass),o=(c*(i.mass-t.mass)+2*t.mass*h)/(t.mass+i.mass),x=y.$multiply(s),g=m.$multiply(u),v=y.$multiply(o),z=m.$multiply(a),f=x.$add(g),d=v.$add(z),n&&(p=t.magnitude(i),p<t.radius+i.radius&&(r=t.$subtract(i).normalize(),l=Math.abs(p-t.radius-i.radius)/1.98,t.add(r.multiply(l)),i.add(r.multiply(-l)))),e&&(t.velocity=f,i.velocity=d,t.momentum=t.velocity.$multiply(t.mass),i.momentum=i.velocity.$multiply(i.mass)),[f,d]},i.force_gravitation=function(t,i,e,n,s){var o,r,h,u;return null==s&&(s=.0067),u=30,o=n.$subtract(t.position),h=o.magnitude()/u,r=0===h?0:i*s*e.mass*n.mass/(h*h),o.normalize().multiply(r),{force:o}},i.RK4=function(t,i,e,n,s){var o,r,h,u,c,a,p,l,y,f,d,m,x;return u=t,l=i,o=e(u,l,0,s),c=t+.5*l*n,y=i+.5*o*n,r=e(c,y,n/2,s),a=t+.5*y*n,f=i+.5*r*n,h=e(a,f,n/2,s),p=t+f*n,d=i+h*n,m=(u+2*(c+a)+p)/6,x=(l+2*(y+f)+d)/6,{c:t+m*n,d:i+x*n}},i}(Circle),this.Particle=Particle,ParticleSystem=function(){function t(){this.count=0,this.particles=[],this.time=0}return t.prototype.add=function(t){return t.id=this.count++,this.particles.push(t),this},t.prototype.remove=function(t){return t&&t.life&&(t.life.complete=!0),this},t.prototype.animate=function(t,i,e){var n,s,o,r,h,u,c,a,p,l;for(this.time++,n=[],p=this.particles,r=s=0,u=p.length;s<u;r=++s)a=p[r],a.life.complete?n.push(r):a.life.active&&a.animate(t,i,e);if(n.length>0){for(l=[],o=0,c=n.length;o<c;o++)h=n[o],l.push(this.particles.splice(h,1));return l}},t}(),this.ParticleSystem=ParticleSystem,Pair=function(t){function i(){i.__super__.constructor.apply(this,arguments),this.p1=new Vector(this.x,this.y,this.z),4===arguments.length?(this.z=0,this.p1.set(arguments[2],arguments[3])):6===arguments.length&&this.p1.set(arguments[3],arguments[4],arguments[5])}return extend(i,t),i.prototype.to=function(){return this.p1=new Vector(Point.get(arguments)),this},i.prototype.getAt=function(t){return 1===t||"p1"===t?this.p1:this},i.prototype.$getAt=function(t){return new Vector(this.getAt(t))},i.prototype.relative=function(){return this.p1.add(this),this},i.prototype.$relative=function(){return this.$add(this.p1)},i.prototype.bounds=function(){return new i(this.$min(this.p1)).to(this.$max(this.p1))},i.prototype.withinBounds=function(t,i){var e,n;return i?(e=this.get2D(i),n=this.p1.get2D(i),e.x===n.x?t.y>=Math.min(e.y,n.y)&&t.y<=Math.max(e.y,n.y):e.y===n.y?t.x>=Math.min(e.x,n.x)&&t.x<=Math.max(e.x,n.x):t.x>=Math.min(e.x,n.x)&&t.y>=Math.min(e.y,n.y)&&t.x<=Math.max(e.x,n.x)&&t.y<=Math.max(e.y,n.y)):t.x>=Math.min(this.x,this.p1.x)&&t.y>=Math.min(this.y,this.p1.y)&&t.z>=Math.min(this.z,this.p1.z)&&t.x<=Math.max(this.x,this.p1.x)&&t.y<=Math.max(this.y,this.p1.y)&&t.z<=Math.max(this.z,this.p1.z)},i.prototype.interpolate=function(t,i){var e;return null==i&&(i=!1),e=i?this.$relative():this.p1,new Vector((1-t)*this.x+t*e.x,(1-t)*this.y+t*e.y,(1-t)*this.z+t*e.z)},i.prototype.midpoint=function(){return this.interpolate(.5)},i.prototype.direction=function(t){return t?this.$subtract(this.p1):this.p1.$subtract(this)},i.prototype.size=function(){return arguments.length>0?(this.p1=this.$add(Point.get(arguments)),this):this.p1.$subtract(this).abs()},i.prototype.length=function(t){var i,e,n,s;return null==t&&(t=!0),s=this.z-this.p1.z,n=this.y-this.p1.y,e=this.x-this.p1.x,i=e*e+n*n+s*s,t?Math.sqrt(i):i},i.prototype.collinear=function(t){return(this.p1.x-this.x)*(t.y-this.y)-(t.x-this.x)*(this.p1.y-this.y)},i.prototype.resetBounds=function(){var t;return t=this.$min(this.p1),this.p1.set(this.$max(this.p1)),this.set(t),this},i.prototype.equal=function(t){return null==t&&(t=!1),arguments[0]instanceof i?i.__super__.equal.call(this,arguments[0])&&this.p1.equal(arguments[0].p1):i.__super__.equal.apply(this,arguments)},i.prototype.clone=function(){var t;return t=new i(this),t.to(this.p1.clone()),t},i.prototype.floor=function(){return i.__super__.floor.apply(this,arguments),this.p1.floor()},i.prototype.toString=function(){return"Pair of vectors from ("+this.x+", "+this.y+", "+this.z+") to ("+this.p1.x+", "+this.p1.y+", "+this.p1.z+")"},i.prototype.toArray=function(){return[this,this.p1]},i}(Vector),this.Pair=Pair,Line=function(t){function i(){i.__super__.constructor.apply(this,arguments)}return extend(i,t),i.slope=function(t,i,e){var n,s;return null==e&&(e=Const.xy),n=t.get2D(e),s=i.get2D(e),s.x-n.x!==0&&(s.y-n.y)/(s.x-n.x)},i.intercept=function(t,i,e){var n,s,o,r;return null==e&&(e=Const.xy),o=t.get2D(e),r=i.get2D(e),r.x-o.x!==0&&(s=(r.y-o.y)/(r.x-o.x),n=o.y-s*o.x,{slope:s,yi:n,xi:0!==s&&-n/s})},i.isPerpendicularLine=function(t,e,n){var s,o;return null==n&&(n=Const.xy),s=i.slope(t,t.p1,n),o=i.slope(e,e.p1,n),s===!1?0===o:o===!1?0===s:s*o===-1},i.prototype.slope=function(t){return null==t&&(t=Const.xy),i.slope(this,this.p1,t)},i.prototype.intercept=function(t){return null==t&&(t=Const.xy),i.intercept(this,this.p1,t)},i.prototype.getPerpendicular=function(t,e,n,s){var o,r,h;return null==e&&(e=10),null==n&&(n=!1),null==s&&(s=Const.xy),r=this.direction().normalize().perpendicular(s),h=n?r[1]:r[0],o=new i(this.interpolate(t)),o.to(h.multiply(e).add(o)),o},i.prototype.getDistanceFromPoint=function(t){var i,e;return e=this.$subtract(this.p1),i=new Vector((-e.y),e.x).normalize(),this.$subtract(t).dot(i)},i.prototype.getPerpendicularFromPoint=function(t,i){var e;return null==i&&(i=!0),e=this.p1.$subtract(this).projection(t.$subtract(this)),i?e.add(this):e},i.prototype.intersectPath=function(t,i){var e,n,s,o,r,h,u;return null==i&&(i=Const.xy),e=this.intercept(i),n=t.intercept(i),o=this.get2D(i),s=t.get2D(i),e===!1?n!==!1&&(u=-n.slope*(s.x-o.x)+s.y,i===Const.xy?new Vector(o.x,u):new Vector(o.x,u).get2D(i,!0)):n===!1?(u=-e.slope*(o.x-s.x)+o.y,new Vector(s.x,u)):n.slope!==e.slope?(r=(e.slope*o.x-n.slope*s.x+s.y-o.y)/(e.slope-n.slope),h=e.slope*(r-o.x)+o.y,i===Const.xy?new Vector(r,h):new Vector(r,h).get2D(i,!0)):e.yi===n.yi&&null},i.prototype.intersectLine=function(t,i){var e;return null==i&&(i=Const.xy),e=this.intersectPath(t,i),e&&this.withinBounds(e,i)&&t.withinBounds(e,i)?e:null===e&&null},i.intersectLines=function(t,i,e){var n,s,o,r,h,u,c;if(null==e&&(e=!0),!t.intersectLine)throw"No intersectLine function found in "+t.toString();c=[];for(s in i)if(h=i[s],o=t.intersectLine(h,e)){if(!e)return!0;if(o.length>0)for(n=0,r=o.length;n<r;n++)u=o[n],c.push(u)}return!!e&&c},i.prototype.intersectGridLine=function(t,i,e){var n,s,o,r;if(null==i&&(i=!1),null==e&&(e=Const.xy),n=this.get2D(e),s=this.p1.get2D(e),o=t.get2D(e),r=t.p1.get2D(e),s.x-n.x===0){if(r.y-o.y===0&&Util.within(n.x,o.x,r.x)&&(i||Util.within(o.y,n.y,s.y)))return new Vector(n.x,o.y)}else{if(s.y-n.y!==0)return!1;if(r.x-o.x===0&&Util.within(n.y,o.y,r.y)&&(i||Util.within(o.x,n.x,s.x)))return new Vector(o.x,n.y)}},i.prototype.subpoints=function(t){var i,e,n,s;for(n=[],s=i=0,e=t;0<=e?i<=e:i>=e;s=0<=e?++i:--i)n.push(this.interpolate(s/t));return n},i.prototype.clone=function(t){return new i(this).to(this.p1)},i}(Pair),this.Line=Line,Rectangle=function(t){function i(){i.__super__.constructor.apply(this,arguments),this.center=new Vector}return extend(i,t),i.contain=function(t,i,e){return t.x>=i.x&&t.x<=e.x&&t.y>=i.y&&t.y<=e.y&&t.z>=i.z&&t.z<=e.z},i.prototype.toString=function(){var t;return t=this.size(),"Rectangle x1 "+this.x+", y1 "+this.y+", z1 "+this.z+", x2 "+this.p1.x+", y2 "+this.p1.y+", z2 "+this.p1.z+", width "+t.x+", height "+t.y},i.prototype.toPointSet=function(){var t;return t=this.corners(),new PointSet(this).to([t.topRight,t.bottomRight,t.bottomLeft,t.topLeft])},i.prototype.to=function(t){return this.p1=new Vector(Point.get(arguments)),this.resetBounds(),this.center=this.midpoint(),this},i.prototype.setCenter=function(t){var i;return 0===arguments.length?void(this.center=this.midpoint()):(i=this.size().$divide(2),this.center.set(Point.get(arguments)),this.set(this.center.$subtract(i)),this.p1.set(this.center.$add(i)),this)},i.prototype.resizeTo=function(){return this.p1=new Vector(Point.get(arguments)),this.relative(),this.center=this.midpoint(),this},i.prototype.resizeCenterTo=function(){var t;return t=new Vector(Point.get(arguments)).divide(2),this.set(this.center.$subtract(t)),this.p1.set(this.center.$add(t)),this},i.prototype.enclose=function(t){return this.set(this.$min(t)),this.p1.set(this.p1.$max(t.p1)),this.center=this.midpoint(),this},i.prototype.$enclose=function(t){return this.clone().enclose(t)},i.prototype.isEnclosed=function(t){var i,e;return i=this.$subtract(t).multiply(this.p1.$subtract(t.p1)),e=this.size().subtract(t.size()),i.x<=0&&i.y<=0&&i.z<=0&&e.x*e.y>=0},i.prototype.isLarger=function(t){var i,e;return i=this.size(),e=t.size(),i.x*i.y>e.x*e.y},i.prototype.intersectPoint=function(){var t;return t=Point.get(arguments),t.x>=this.x&&t.x<=this.p1.x&&t.y>=this.y&&t.y<=this.p1.y&&t.z>=this.z&&t.z<=this.p1.z},i.prototype.intersectPath=function(t,i){var e,n,s,o,r,h;for(null==i&&(i=!0),h=this.sides(),o=[],e=0,n=h.length;e<n;e++)if(r=h[e],s=r.intersectPath(t),s&&this.intersectPoint(s)){if(!i)return!0;o.push(s)}return!!i&&o},i.prototype.intersectLine=function(t,i){var e,n,s,o,r,h,u,c,a;if(null==i&&(i=!0),n=this.intersectPoint(t),s=this.intersectPoint(t.p1),n&&s&&i)return[];if(!n&&!s&&(o=t.bounds(),!this.intersectRectangle(o,!1)))return!!i&&[];for(a=this.sides(),u=[],e=0,r=a.length;e<r;e++)if(c=a[e],h=t.intersectLine(c)){if(!i)return!0;u.push(h)}return!!i&&u},i.prototype.intersectLines=function(t,i){return null==i&&(i=!0),Line.intersectLines(this,t,i)},i.prototype.intersectRectangle=function(t,i){var e,n,s,o,r,h,u,c,a,p,l,y,f,d;if(null==i&&(i=!0),y=this.p1.x>=t.x&&this.x<=t.p1.x,f=this.p1.y>=t.y&&this.y<=t.p1.y,d=this.p1.z>=t.z&&this.z<=t.p1.z,s=y&&f&&d,!i)return s;if(this.isEnclosed(t))return!i||[];if(!s)return[];for(p=this.sides(),l=t.sides(),u=[],e=0,o=p.length;e<o;e++)for(c=p[e],n=0,r=l.length;n<r;n++)a=l[n],h=c.intersectGridLine(a),h&&u.push(h);return u},i.prototype.hasIntersect=function(t,e){return null==e&&(e=!1),t instanceof Circle?t.intersectLines(this.sides(),e):t instanceof i?this.intersectRectangle(t,e):t instanceof PointSet||t instanceof Triangle?this.intersectLines(t.sides(),e):t instanceof Pair?this.intersectLine(t,e):t instanceof Point?i.contain(t,this,this.p1):!!e&&[]},i.prototype.corners=function(){return{topLeft:new Vector(Math.min(this.x,this.p1.x),Math.min(this.y,this.p1.y),Math.max(this.z,this.p1.z)),topRight:new Vector(Math.max(this.x,this.p1.x),Math.min(this.y,this.p1.y),Math.min(this.z,this.p1.z)),bottomLeft:new Vector(Math.min(this.x,this.p1.x),Math.max(this.y,this.p1.y),Math.max(this.z,this.p1.z)),bottomRight:new Vector(Math.max(this.x,this.p1.x),Math.max(this.y,this.p1.y),Math.min(this.z,this.p1.z))}},i.prototype.sides=function(){var t;return t=this.corners(),[new Line(t.topLeft).to(t.topRight),new Line(t.topRight).to(t.bottomRight),new Line(t.bottomRight).to(t.bottomLeft),new Line(t.bottomLeft).to(t.topLeft)]},i.prototype.quadrants=function(){var t;return t=this.corners(),{topLeft:new this.__proto__.constructor(t.topLeft).to(this.center),topRight:new this.__proto__.constructor(t.topRight).to(this.center),bottomLeft:new this.__proto__.constructor(t.bottomLeft).to(this.center),bottomRight:new this.__proto__.constructor(t.bottomRight).to(this.center)}},i.prototype.clone=function(){var t;return t=new i(this).to(this.p1),t.to(this.p1.clone()),t},i}(Pair),this.Rectangle=Rectangle,Grid=function(t){function i(){i.__super__.constructor.apply(this,arguments),this.cell={type:"fix-fix",size:new Vector},this.rows=0,this.columns=0,this.layout=[],this.cellCallback=null}return extend(i,t),i.prototype.toString=function(){var t;return t=this.size(),"Grid width "+t.x+", height "+t.y+", columns "+this.columns+", rows "+this.rows+", "+("cell ("+this.cell.size.x+", "+this.cell.size.y+"), type "+this.cell.type)},i.prototype.init=function(t,i,e,n){var s;return null==e&&(e="fix"),null==n&&(n="fix"),s=this.size(),this.cell.type=e+"-"+n,this.rows=i,this.columns=t,"stretch"===e?(this.cell.size.x=s.x/t,this.columns=t):"flex"===e?(this.columns=Math.round(s.x/t),this.cell.size.x=s.x/this.columns):(this.cell.size.x=t,this.columns=Math.floor(s.x/this.cell.size.x)),"stretch"===n?(this.cell.size.y=s.y/i,this.rows=i):"flex"===n?(this.rows=Math.round(s.y/i),this.cell.size.y=s.y/this.rows):(this.cell.size.y=i,this.rows=Math.floor(s.y/this.cell.size.y)),this.layout.length<1&&this.resetLayout(),this},i.prototype.generate=function(t){return"function"==typeof t&&(this.cellCallback=t),this},i.prototype.create=function(){var t,i,e,n,s,o,r,h,u;if(!this.cellCallback)return this;for(e=t=0,h=this.columns;0<=h?t<h:t>h;e=0<=h?++t:--t)for(r=i=0,u=this.rows;0<=u?i<u:i>u;r=0<=u?++i:--i)n=this.cell.size.clone(),o=this.$add(n.$multiply(e,r)),s=this.layout.length>0&&this.layout[0].length>0&&1===this.layout[r][e],this.cellCallback(n,o,r,e,this.cell.type,s);return this},i.prototype.getCellSize=function(){return this.cell.size.clone()},i.prototype.cellToRectangle=function(t,i,e){var n;return null==e&&(e=!1),!!(e||t>=0&&t<this.columns&&i>=0&&i<this.rows)&&(n=new Rectangle(this.$add(this.cell.size.$multiply(t,i))).resizeTo(this.cell.size))},i.prototype.positionToCell=function(t){var i,e;return e=new Vector(this._getArgs(arguments)),i=e.$subtract(this).$divide(this.cell.size).floor(),i.max(0,0).min(this.columns-1,this.rows-1),i},i.prototype.resetLayout=function(t){var i,e,n,s,o,r;for(this.layout=[],s=i=0,o=this.rows;0<=o?i<o:i>o;s=0<=o?++i:--i)for(this.layout[s]=[],n=e=0,r=this.columns;0<=r?e<r:e>r;n=0<=r?++e:--e)this.layout[s][n]=0,t&&t(this,s,n);return this},i.prototype.occupy=function(t,i,e,n,s){var o,r,h,u,c,a;if(null==s&&(s=!0),this.rows<=0||this.columns<=0)return this;for(this.layout.length<1&&this.resetLayout(),h=o=0,c=e;0<=c?o<c:o>c;h=0<=c?++o:--o)for(u=r=0,a=n;0<=a?r<a:r>a;u=0<=a?++r:--r)this.layout[Math.min(this.layout.length-1,i+u)][t+h]=s?1:0;return this},i.prototype.canFit=function(t,i,e,n){var s,o,r,h,u,c,a,p,l;for(u=s=c=i,a=Math.min(this.rows,i+n);c<=a?s<a:s>a;u=c<=a?++s:--s)for(h=o=p=t,l=Math.min(this.columns,t+e);p<=l?o<l:o>l;h=p<=l?++o:--o)if(r=this.layout[u][h],null!=r&&r>0)return!1;return!0},i.prototype.fit=function(t,i){var e,n,s,o,r,h,u,c,a,p,l;for(h=Math.min(t,this.columns),c=e=0,p=this.rows;0<=p?e<p:e>p;c=0<=p?++e:--e)for(r=h,a=0,u=n=0,l=this.columns;0<=l?n<l:n>l;u=0<=l?++n:--n)if(o=this.layout[c][u],null!=o&&o>0)a++,r=h;else if(r--,r<=0)return this.occupy(a,c,h,i),s=new Rectangle(this.$add(this.cell.size.$multiply(a,c))),s.resizeTo(this.cell.size.$multiply(h,i)),{row:c,column:a,columnSize:h,rowSize:i,bound:s};return!1},i.prototype.neighbors=function(t,i){var e,n,s,o,r;for(r=[[t-1,i-1],[t,i-1],[t+1,i-1],[t+1,i],[t+1,i+1],[t,i+1],[t-1,i+1],[t-1,i]],o=[],e=0,n=r.length;e<n;e++)s=r[e],s[0]>=0&&s[0]<this.columns&&s[1]>=0&&s[1]<this.rows?o.push(new Vector(s[0],s[1],this.layout[s[1]][s[0]])):o.push(!1);return o},i}(Rectangle),this.Grid=Grid,PointSet=function(t){function i(){i.__super__.constructor.apply(this,arguments),this.points=[]}return extend(i,t),i.prototype.toString=function(){var t,i,e,n,s;for(s="PointSet [ ",n=this.points,t=0,i=n.length;t<i;t++)e=n[t],s+=e.x+","+e.y+","+e.z+", ";return s+" ]"},i.prototype.toArray=function(){return this.points.slice()},i.prototype.to=function(t){var i,e,n,s;if(arguments.length>0)if(Array.isArray(arguments[0])&&arguments[0].length>0&&"object"==typeof arguments[0][0])for(s=arguments[0],i=0,e=s.length;i<e;i++)n=s[i],this.points.push(new Vector(n));else this.points.push(new Vector(Point.get(arguments)));return this},i.prototype.getAt=function(t){return this.points[Math.min(this.points.length-1,Math.max(0,t))]},i.prototype.$getAt=function(t){return new Vector(this.getAt(t))},i.prototype.setAt=function(t,i){return this.points[t]=i,this},i.prototype.count=function(){return this.points.length},i.prototype.connectFromAnchor=function(t){var i,e,n,s;if(arguments.length>0)if(Array.isArray(arguments[0])&&arguments[0].length>0)for(s=arguments[0],i=0,e=s.length;i<e;i++)n=s[i],this.points.push(this.$add(n));else this.points.push(this.$add(Point.get(arguments)));return this},i.prototype.disconnect=function(t){return null==t&&(t=-1),t<0?this.points=this.points.slice(0,this.points.length+t):this.points=this.points.slice(t+1),this},i.prototype.clear=function(){return this.points=[],this},i.prototype.sides=function(t){
var i,e,n,s,o,r;for(null==t&&(t=!0),e=null,r=[],o=this.points,i=0,n=o.length;i<n;i++)s=o[i],e&&r.push(new Line(e).to(s)),e=s;return this.points.length>1&&t&&r.push(new Line(e).to(this.points[0])),r},i.prototype.angles=function(t){var i,e,n,s,o,r;for(null==t&&(t=Const.xy),e=[],n=i=1,s=this.points.length-1;i<s;n=i+=1)o=this.points[n-1].$subtract(this.points[n]),r=this.points[n+1].$subtract(this.points[n]),e.push({p0:this.points[n-1],p1:this.points[n],p2:this.points[n+1],angle:o.angleBetween(r)});return e},i.prototype.bounds=function(){return Util.boundingBox(this.points)},i.prototype.centroid=function(){return Util.centroid(this.points)},i.prototype.convexHull=function(t){var i,e,n,s,o;if(null==t&&(t=!0),this.points.length<3)return[];for(t?(o=this.points.slice(),o.sort(function(t,i){return t.x-i.x})):o=this.points,n=function(t,i,e){return(i.x-t.x)*(e.y-t.y)-(e.x-t.x)*(i.y-t.y)>0},i=[],n(o[0],o[1],o[2])?(i.push(o[0]),i.push(o[1])):(i.push(o[1]),i.push(o[0])),i.unshift(o[2]),i.push(o[2]),e=3;e<o.length;)if(s=o[e],n(s,i[0],i[1])&&n(i[i.length-2],i[i.length-1],s))e++;else{for(;!n(i[i.length-2],i[i.length-1],s);)i.pop();for(i.push(s);!n(i[0],i[1],s);)i.shift();i.unshift(s),e++}return i},i.prototype.clone=function(){return new i(this).to(Util.clonePoints(this.points))},i}(Vector),this.PointSet=PointSet,Curve=function(t){function i(){i.__super__.constructor.apply(this,arguments),this.is3D=!1}return extend(i,t),i.prototype._getSteps=function(t){var i,e,n,s,o;for(o=[],n=i=0,e=t;i<=e;n=i+=1)s=n/t,o.push([s,s*s,s*s*s]);return o},i.prototype.controlPoints=function(t,i){var e,n,s,o,r;return null==t&&(t=0),null==i&&(i=!1),e=function(t){return function(i){var e;return e=i<t.points.length-1?i:t.points.length-1}}(this),n=this.points[t],null!=n.x&&(t=i?t:t+1,s=this.points[e(t++)],o=this.points[e(t++)],r=this.points[e(t++)],{p0:n,p1:s,p2:o,p3:r})},i.prototype.catmullRom=function(t){var i,e,n,s,o,r,h,u,c;if(null==t&&(t=10),this.points.length<2)return[];for(r=[],c=this._getSteps(t),n=this.controlPoints(0,!0),s=i=0,h=t;i<=h;s=i+=1)r.push(this.catmullRomPoint(c[s],n));for(o=0;o<this.points.length-2;)if(n=this.controlPoints(o)){for(s=e=0,u=t;e<=u;s=e+=1)r.push(this.catmullRomPoint(c[s],n));o++}return r},i.prototype.catmullRomPoint=function(t,i){var e,n,s,o,r,h,u,c,a,p;return r=t[0],h=t[1],u=t[2],e=-.5*u+h-.5*r,n=1.5*u-2.5*h+1,s=-1.5*u+2*h+.5*r,o=.5*u-.5*h,c=e*i.p0.x+n*i.p1.x+s*i.p2.x+o*i.p3.x,a=e*i.p0.y+n*i.p1.y+s*i.p2.y+o*i.p3.y,p=this.is3D?e*i.p0.z+n*i.p1.z+s*i.p2.z+o*i.p3.z:0,new Point(c,a,p)},i.prototype.cardinal=function(t,i){var e,n,s,o,r,h,u,c,a;if(null==t&&(t=10),null==i&&(i=.5),this.points.length<2)return[];for(h=[],a=this._getSteps(t),s=this.controlPoints(0,!0),o=e=0,u=t;e<=u;o=e+=1)h.push(this.cardinalPoint(a[o],s,i));for(r=0;r<this.points.length-2;)if(s=this.controlPoints(r)){for(o=n=0,c=t;n<=c;o=n+=1)h.push(this.cardinalPoint(a[o],s,i));r++}return h},i.prototype.cardinalPoint=function(t,i,e){var n,s,o,r,h,u,c,a,p,l,y,f;return null==e&&(e=.5),c=t[0],a=t[1],p=t[2],n=e*(-1*p+2*a-c),s=e*(-1*p+a),o=2*p-3*a+1,r=e*(p-2*a+c),h=-2*p+3*a,u=e*(p-a),l=i.p0.x*n+i.p1.x*s+o*i.p1.x+i.p2.x*r+h*i.p2.x+i.p3.x*u,y=i.p0.y*n+i.p1.y*s+o*i.p1.y+i.p2.y*r+h*i.p2.y+i.p3.y*u,f=this.is3D?i.p0.z*n+i.p1.z*s+o*i.p1.z+i.p2.z*r+h*i.p2.z+i.p3.z*u:0,new Point(l,y,f)},i.prototype.bezier=function(t){var i,e,n,s,o,r,h;if(null==t&&(t=10),this.points.length<4)return[];for(o=[],h=this._getSteps(t),s=0;s<=this.points.length-3;)if(e=this.controlPoints(s)){for(n=i=0,r=t;i<=r;n=i+=1)o.push(this.bezierPoint(h[n],e));s+=3}return o},i.prototype.bezierPoint=function(t,i){var e,n,s,o,r,h,u,c,a,p;return r=t[0],h=t[1],u=t[2],e=-1*u+3*h-3*r+1,n=3*u-6*h+3*r,s=-3*u+3*h,o=u,c=e*i.p0.x+n*i.p1.x+s*i.p2.x+o*i.p3.x,a=e*i.p0.y+n*i.p1.y+s*i.p2.y+o*i.p3.y,p=this.is3D?e*i.p0.z+n*i.p1.z+s*i.p2.z+o*i.p3.z:0,new Point(c,a,p)},i.prototype.bspline=function(t,i){var e,n,s,o,r,h,u,c,a;if(null==t&&(t=10),null==i&&(i=!1),this.points.length<2)return[];for(h=[],a=this._getSteps(t),r=0;r<this.points.length-2;)if(s=this.controlPoints(r)){if(i)for(o=n=0,c=t;n<=c;o=n+=1)h.push(this.bsplineTensionPoint(a[o],s,i));else for(o=e=0,u=t;e<=u;o=e+=1)h.push(this.bsplinePoint(a[o],s));r++}return h},i.prototype.bsplinePoint=function(t,i){var e,n,s,o,r,h,u,c,a,p;return r=t[0],h=t[1],u=t[2],e=-.16666666666*u+.5*h-.5*r+.16666666666,n=.5*u-h+.66666666666,s=-.5*u+.5*h+.5*r+.16666666666,o=.16666666666*u,c=e*i.p0.x+n*i.p1.x+s*i.p2.x+o*i.p3.x,a=e*i.p0.y+n*i.p1.y+s*i.p2.y+o*i.p3.y,p=this.is3D?e*i.p0.z+n*i.p1.z+s*i.p2.z+o*i.p3.z:0,new Point(c,a,p)},i.prototype.bsplineTensionPoint=function(t,i,e){var n,s,o,r,h,u,c,a,p,l,y,f;return null==e&&(e=1),c=t[0],a=t[1],p=t[2],n=e*(-.16666666666*p+.5*a-.5*c+.16666666666),s=e*(-1.5*p+2*a-.33333333333),o=2*p-3*a+1,r=e*(1.5*p-2.5*a+.5*c+.16666666666),h=-2*p+3*a,u=e*(.16666666666*p),l=n*i.p0.x+s*i.p1.x+o*i.p1.x+r*i.p2.x+h*i.p2.x+u*i.p3.x,y=n*i.p0.y+s*i.p1.y+o*i.p1.y+r*i.p2.y+h*i.p2.y+u*i.p3.y,f=this.is3D?n*i.p0.z+s*i.p1.z+o*i.p1.y+r*i.p2.z+h*i.p2.z+u*i.p3.z:0,new Point(l,y,f)},i}(PointSet),this.Curve=Curve,Triangle=function(t){function i(){i.__super__.constructor.apply(this,arguments),this.p1=new Vector(this.x-1,this.y-1,this.z),this.p2=new Vector(this.x+1,this.y+1,this.z)}return extend(i,t),i.prototype.to=function(t){return arguments.length>0&&("object"==typeof arguments[0]&&2===arguments.length?(this.p1.set(arguments[0]),this.p2.set(arguments[1])):arguments.length<6?(this.p1.set([arguments[0],arguments[1]]),this.p2.set([arguments[2],arguments[3]])):(this.p1.set([arguments[0],arguments[1],arguments[2]]),this.p2.set([arguments[3],arguments[4],arguments[5]]))),this},i.prototype.toArray=function(){return[this,this.p1,this.p2]},i.prototype.toString=function(){return"Triangle ("+this.x+", "+this.y+", "+this.z+"), ("+this.p1.x+", "+this.p1.y+", "+this.p1.z+"), ("+this.p2.x+", "+this.p2.y+", "+this.p2.z+")"},i.prototype.getAt=function(t){return 1===t||"p1"===t?this.p1:2===t||"p2"===t?this.p2:this},i.prototype.$getAt=function(t){return new Vector(this.getAt(t))},i.prototype.toPointSet=function(){var t;return t=new Vector(this),new PointSet(t).to([t,this.p1,this.p2])},i.prototype.sides=function(){return[new Line(this).to(this.p1),new Line(this.p1).to(this.p2),new Line(this.p2).to(this)]},i.prototype.angles=function(t){var i;return null==t&&(t=Const.xy),i=[this.p2.$subtract(this).angleBetween(this.p1.$subtract(this),t),this.$subtract(this.p1).angleBetween(this.p2.$subtract(this.p1),t)],i.push(Math.PI-i[0]-i[1]),i},i.prototype.medial=function(){var t,e,n;return n=this.sides(),t=function(){var t,i,s;for(s=[],t=0,i=n.length;t<i;t++)e=n[t],s.push(e.midpoint());return s}(),new i(t[0]).to(t[1],t[2])},i.prototype.perimeter=function(){var t,i;return i=this.sides(),t=[i[0].length(),i[1].length(),i[2].length()],{sides:i,value:t[0]+t[1]+t[2],lengths:t}},i.prototype.area=function(){var t,i;return i=this.perimeter(),t=i.value/2,{value:Math.sqrt(t*(t-i.lengths[0])*(t-i.lengths[1])*(t-i.lengths[2])),perimeter:i}},i.prototype.oppositeSide=function(t){return"p1"===t?new Line(this).to(this.p2):"p2"===t?new Line(this).to(this.p1):new Line(this.p1).to(this.p2)},i.prototype.adjacentSides=function(t){return"p1"===t?[new Line(this.p1).to(this),new Line(this.p1).to(this.p2)]:"p2"===t?[new Line(this.p2).to(this),new Line(this.p2).to(this.p1)]:[new Line(this).to(this.p1),new Line(this).to(this.p2)]},i.prototype.bisector=function(t,i,e){var n,s,o;return null==i&&(i=!1),null==e&&(e=100),n=this.adjacentSides(t),o=new Vector(n[0]),n[0].moveTo(0,0),n[1].moveTo(0,0),s=n[0].p1.bisect(n[1].p1),i?new Line(o).to(s.multiply(e).add(o)):s},i.prototype.altitude=function(t){return"p1"===t||"p2"===t?new Line(this[t]).to(this.oppositeSide(t).getPerpendicularFromPoint(this[t])):new Line(this).to(this.oppositeSide().getPerpendicularFromPoint(this))},i.prototype.centroid=function(){var t,i,e;return t=this.$divide(3),i=this.p1.$divide(3),e=this.p2.$divide(3),new Vector(t.x+i.x+e.x,t.y+i.y+e.y,t.z+i.z+e.z)},i.prototype.orthocenter=function(){var t,i;return t=this.altitude(),i=this.altitude("p1"),t.intersectPath(i,Const.xyz)},i.prototype.incenter=function(){var t,i;return t=this.bisector("p0",!0),i=this.bisector("p1",!0),t.intersectPath(i,Const.xyz)},i.prototype.incircle=function(){var t,i,e;return i=this.incenter(),t=this.area(),e=2*t.value/t.perimeter.value,new Circle(i).setRadius(e)},i.prototype.circumcenter=function(){var t,i;return t=this.medial(),i=[new Line(t).to(this.$subtract(t).perpendicular()[0].$add(t)),new Line(t.p1).to(this.p1.$subtract(t.p1).perpendicular()[0].$add(t.p1)),new Line(t.p2).to(this.p2.$subtract(t.p2).perpendicular()[0].$add(t.p2))],{center:i[0].intersectPath(i[1],Const.xyz),bisectors:i}},i.prototype.circumcircle=function(){var t,i;return t=this.circumcenter(),i=this.magnitude(t.center),new Circle(t.center).setRadius(i)},i.prototype.intersectPoint=function(t){var i,e,n;return n=this.sides(),i=function(){var i,s,o;for(o=[],i=0,s=n.length;i<s;i++)e=n[i],o.push(e.collinear(t)>0);return o}(),i[0]===i[1]&&i[1]===i[2]},i.prototype.intersectPath=function(t,i,e){var n,s,o,r,h,u;for(null==i&&(i=!0),null==e&&(e=Const.xy),u=this.sides(),r=[],n=0,s=u.length;n<s;n++)if(h=u[n],o=h.intersectPath(t),o&&h.withinBounds(o,e)){if(!i)return!0;r.push(o)}return!!i&&r},i.prototype.intersectLine=function(t,i,e){var n,s,o,r,h;for(null==i&&(i=!0),null==e&&(e=Const.xy),s=this.intersectPath(t,!0,e),h=[],n=0,o=s.length;n<o;n++)if(r=s[n],t.withinBounds(r)){if(!i)return!0;h.push(r)}return!!i&&h},i.prototype.intersectLines=function(t,i){return null==i&&(i=!0),Line.intersectLines(this,t,i)},i.prototype.intersectPath3D=function(t,i){var e,n,s,o,r,h,u,c,a,p,l;return s=this.p1.$subtract(this),o=this.p2.$subtract(this),n=t.direction().normalize(),h=n.cross(o),e=s.dot(h),!(e>-Const.epsilon&&e<Const.epsilon)&&(r=1/e,a=t.$subtract(this),p=a.dot(h)*r,!(p<0||p>1)&&(u=a.cross(s),l=n.dot(u)*r,!(l<0||l>1)&&(c=o.dot(u)*r,c>Const.epsilon&&(!i||[p,l,c]))))},i.prototype.intersectRectangle=function(t,i){return null==i&&(i=!0),t.intersectLines(this.sides(),i)},i.prototype.intersectCircle=function(t,i){return null==i&&(i=!0),t.intersectLines(this.sides(),i)},i.prototype.intersectTriangle=function(t,i){return null==i&&(i=!0),t.intersectLines(this.sides(),i)},i.prototype.clone=function(){return new i(this).to(this.p1,this.p2)},i}(Vector),this.Triangle=Triangle,Easing=function(){function t(){}return t.linear=function(t,i,e,n){return e*(t/=n)+i},t._linear=function(i){return t.linear(i,0,1,1)},t.quadIn=function(t,i,e,n){return e*(t/=n)*t+i},t._quadIn=function(i){return t.quadIn(i,0,1,1)},t.quadOut=function(t,i,e,n){return-e*(t/=n)*(t-2)+i},t._quadOut=function(i){return t.quadOut(i,0,1,1)},t.cubicIn=function(t,i,e,n){return t/=n,e*t*t*t+i},t._cubicIn=function(i){return t.cubicIn(i,0,1,1)},t.cubicOut=function(t,i,e,n){return t/=n,e*((t-1)*t*t+1)+i},t._cubicOut=function(i){return t.cubicOut(i,0,1,1)},t.elastic=function(t,i,e,n,s){var o,r,h;return null==s&&(s=.3),h=1.70158,r=n*s,o=e,0===t?i:(t/=n,1===t?i+e:(o<Math.abs(e)?(o=e,h=r/4):h=0!==o?r/Const.two_pi*Math.asin(e/o):0,o*Math.pow(2,-10*t)*Math.sin((t*n-h)*Const.two_pi/r)+e+i))},t._elastic=function(i){return t.elastic(i,0,1,1)},t.bounce=function(t,i,e,n){return(t/=n)<1/2.75?e*(7.5625*t*t)+i:t<2/2.75?e*(7.5625*(t-=1.5/2.75)*t+.75)+i:t<2.5/2.75?e*(7.5625*(t-=2.25/2.75)*t+.9375)+i:e*(7.5625*(t-=2.625/2.75)*t+.984375)+i},t._bounce=function(i){return t.bounce(i,0,1,1)},t}(),this.Easing=Easing,GridCascade=function(t){function i(){i.__super__.constructor.apply(this,arguments),this.startRow=0}return extend(i,t),i.prototype.resetLayout=function(){return this.layout=[],this.startRow=0},i.prototype.occupy=function(t,i,e,n){var s,o,r,h,u,c,a,p;for(r=s=u=t,c=e+t;u<=c?s<c:s>c;r=u<=c?++s:--s)for(h=o=a=i,p=n+i;a<=p?o<p:o>p;h=a<=p?++o:--o)null==this.layout[h]&&(this.layout[h]=[]),this.layout[h][r]=1;return this},i.prototype.findStartRow=function(){var t,i,e,n,s,o,r,h;for(n=this.startRow,s=t=o=this.startRow,r=this.rows;o<=r?t<r:t>r;s=o<=r?++t:--t)for(n=s,e=i=0,h=this.columns;0<=h?i<h:i>h;e=0<=h?++i:--i)if(null!=this.layout[s]&&(null==this.layout[s][e]||this.layout[s][e]<=0))return n;return n},i.prototype.fit=function(t,i){var e,n,s,o,r,h,u,c,a,p,l,y,f,d,m,x,g;for(c=Math.min(t,this.columns),p=e=f=this.startRow,d=this.rows;f<=d?e<d:e>d;p=f<=d?++e:--e)for(u=c,l=0,p+i>=this.rows&&(this.rows+=i),null==this.layout[p]&&(this.layout[p]=[]),a=n=0,m=this.columns;0<=m?n<m:n>m;a=0<=m?++n:--n)if(h=this.layout[p][a],null!=h&&h>0)l=a+1,u=c;else if(u--,0===u){if(o=!0,i>1)for(y=s=x=p,g=p+i;x<=g?s<g:s>g;y=x<=g?++s:--s)if(y<=this.rows&&null!=this.layout[y]&&this.layout[y][l]>0){o=!1;break}if(o)return this.occupy(l,p,c,i),p>this.startRow&&(this.startRow=this.findStartRow()),r=new Rectangle(this.$add(this.cell.size.$multiply(l,p))),r.resizeTo(this.cell.size.$multiply(c,i)),{row:p,column:l,columnSize:c,rowSize:i,bound:r}}return console.error("cannot fit "+p+" "+l+" "+t+" "+i),!1},i}(Grid),this.GridCascade=GridCascade,ParticleEmitter=function(t){function i(){i.__super__.constructor.apply(this,arguments),this.system=null,this.lastTime=0,this.period=0,this.animateID=-1}return extend(i,t),i.prototype.init=function(t){return this.system=t},i.prototype.frequency=function(t){return this.period=1e3/t,this},i.prototype.emit=function(){},i.prototype.animate=function(t,i,e){if(t-this.lastTime>this.period)return this.emit(),this.lastTime=t},i}(Vector),this.ParticleEmitter=ParticleEmitter,ParticleField=function(t){function i(){i.__super__.constructor.apply(this,arguments),this.system=void 0}return extend(i,t),i.prototype.check=function(t,i){var e,n,s,o;for(null==i&&(i=!1),o=[],e=0,n=t.length;e<n;e++)s=t[e],this.hasIntersect(s)?this.work(s):o.push(s);return i?o:t},i.prototype.work=function(t){},i}(Rectangle),this.ParticleField=ParticleField,QuadTree=function(t){function i(){i.__super__.constructor.apply(this,arguments),this.quads=!1,this.items=[],this.depth=0,this.max_depth=6,this.max_items=2}return extend(i,t),i.prototype.getQuads=function(t,i){var e,n,s;if(null==i&&(i=[]),this.intersectPoint(t)&&(i.push(this),this.quads)){s=this.quads;for(e in s)n=s[e],n.intersectPoint(t)&&n.getQuads(t,i)}return i},i.prototype.getItems=function(t){var i,e,n;if(this.intersectPoint(t)){if(!this.quads)return this.items;if(this.quads){n=this.quads;for(i in n)if(e=n[i],e.intersectPoint(t))return e.getItems(t)}}return[]},i.prototype.addToQuad=function(t){var i,e,n,s;if(!t)return-1;if(this.quads){s=this.quads;for(e in s)if(n=s[e],i=n.addToQuad(t),i>0)return i;return-1}return!this.quads&&this.intersectPoint(t)?this.items.length>=this.max_items?this.depth<this.max_depth?(this.splitQuad(),this.addToQuad(t)):-1:(this.items.push(t),this.depth):-1},i.prototype.splitQuad=function(){var t,i,e,n,s,o,r,h,u,c,a,p,l,y;this.quads=this.quadrants(),c=this.quads;for(o in c)u=c[o],u.depth=this.depth+1;for(a=this.items,n=i=0,r=a.length;i<r;n=++i)s=a[n],t=this.addToQuad(s),t>this.depth&&(this.items[n]=null);for(p=this.items,l=[],e=0,h=p.length;e<h;e++)y=p[e],y?l.push(void 0):l.push(this.items.splice(y,1));return l},i.prototype.resetQuad=function(){var t,i,e;if(this.items=[],this.quads){e=this.quads;for(t in e)i=e[t],i.resetQuad();return this.quads=!1}},i}(Rectangle),this.QuadTree=QuadTree,SamplePoints=function(t){function i(){i.__super__.constructor.apply(this,arguments),this.bestcandidate=null,this.poisson=null,this.bound=null,this.boundsize=null}return extend(i,t),i.prototype.setBounds=function(t,i){return null==i&&(i=!1),i&&this.set(t),this.bound=new Rectangle(this).size(t.size()),this},i.prototype.bestCandidateSampler=function(){return this.points=[],this.bound||(this.bound=(new Rectangle).size(500,500)),this.boundsize=this.bound.size(),this.bestcandidate={halfsize:this.boundsize.$divide(2),quartersize:this.boundsize.$divide(4),maxDist:this.boundsize.x*this.boundsize.x+this.boundsize.y*this.boundsize.y},this},i.prototype.poissonSampler=function(t){var i;return this.points=[],this.bound||(this.bound=(new Rectangle).size(500,500)),this.boundsize=this.bound.size(),i=t*Math.SQRT1_2,this.poisson={grid:[],gridWidth:Math.ceil(this.boundsize.x/i),gridHeight:Math.ceil(this.boundsize.y/i),cellSize:i,radius:t,radius2:t*t,R:3*t*t,queue:[],queueSize:0,sampleSize:0,sincos:Util.sinCosTable()},this},i.prototype.sample=function(t,i){var e,n,s,o,r,h,u,c,a,p,l,y,f,d,m;if(null==t&&(t=10),null==i&&(i=!1),this.poisson&&"poisson"===i){if(this.poisson.sampleSize>0&&0===this.poisson.queueSize)return!1;if(!this.poisson.sampleSize)return this._poissonSample(this.bound.x+this.boundsize.x/2,this.bound.y+this.boundsize.y/2);for(;this.poisson.queueSize;){for(h=Math.floor(Math.random()*this.poisson.queueSize),f=this.poisson.queue[h],u=n=0,l=t;n<l;u=n+=1)if(e=Math.floor(360*Math.random()),p=Math.sqrt(Math.random()*this.poisson.R+this.poisson.radius2),d=f.x+p*this.poisson.sincos.cos[e],m=f.y+p*this.poisson.sincos.sin[e],d>=this.bound.x&&d<this.boundsize.x&&m>=this.bound.y&&m<this.boundsize.y&&this._poissonCheck(d,m))return this._poissonSample(d,m);this.poisson.queue[h]=this.poisson.queue[--this.poisson.queueSize],this.poisson.queue.length=this.poisson.queueSize}return!0}if(this.bestcandidate){for(o=null,r=-1,h=s=0,y=t;s<y;h=s+=1){if(a=new Vector(this.bound.x+this.boundsize.x*Math.random(),this.bound.y+this.boundsize.y*Math.random()),0===this.points.length){o=a;break}c=this._bestCandidateCheck(a),c>r&&(o=a,r=c)}return o&&this.points.push(o),o}},i.prototype._bestCandidateCheck=function(t){var i,e,n,s,o,r,h,u,c,a;for(i=this.bestcandidate.maxDist,r=new Rectangle(t.x-this.bestcandidate.quartersize.x,t.y-this.bestcandidate.quartersize.y).size(this.bestcandidate.halfsize.x,this.bestcandidate.halfsize.y),c=function(){var t,i,e,n;for(e=this.points,n=[],t=0,i=e.length;t<i;t++)h=e[t],r.intersectPoint(h)&&n.push(h);return n}.call(this),e=0,u=c.length;e<u;e++)a=c[e],s=a.x-t.x,o=a.y-t.y,n=s*s+o*o,n<i&&(i=n);return i},i.prototype._poissonSample=function(t,i){var e;return e=new Point(t,i),this.poisson.queue.push(e),this.poisson.grid[this.poisson.gridWidth*(i/this.poisson.cellSize|0)+(t/this.poisson.cellSize|0)]=e,this.poisson.sampleSize++,this.poisson.queueSize++,e},i.prototype._poissonCheck=function(t,i){var e,n,s,o,r,h,u,c,a,p,l,y,f,d,m,x;for(r=Math.floor(t/this.poisson.cellSize),c=Math.floor(i/this.poisson.cellSize),h=Math.max(r-2,0),a=Math.max(c-2,0),u=Math.min(r+3,this.poisson.gridWidth),p=Math.min(c+3,this.poisson.gridHeight),c=e=y=a,f=p;e<f;c=e+=1)for(l=c*this.poisson.gridWidth,r=n=d=h,m=u;n<m;r=n+=1)if(x=this.poisson.grid[l+r],x&&(s=x.x-t,o=x.y-i,s*s+o*o<this.poisson.radius2))return!1;return!0},i.bestCandidate=function(t,i,e){var n,s,o,r,h,u,c,a,p,l,y,f;for(null==e&&(e=10),f=t.size(),h=f.$divide(2),l=f.$divide(4),c=f.x*f.x+f.y*f.y,n=function(t){var e,n,s,o,r,u,a,p,y,f;for(e=c,u=new Rectangle(t.x-l.x,t.y-l.y).size(h.x,h.y),y=function(){var t,e,n;for(n=[],t=0,e=i.length;t<e;t++)a=i[t],u.intersetPoint(a)&&n.push(a);return n}(),n=0,p=y.length;n<p;n++)f=y[n],o=f.x-t.x,r=f.y-t.y,s=o*o+r*r,s<e&&(e=s);return e},o=null,r=-1,u=s=0,y=e;0<=y?s<y:s>y;u=0<=y?++s:--s){if(p=new Vector(t.x+f.x*Math.random(),t.y+f.y*Math.random()),0===i.length)return p;a=n(p),a>r&&(o=p,r=a)}return o},i}(PointSet),this.SamplePoints=SamplePoints,StripeBound=function(t){function i(){i.__super__.constructor.apply(this,arguments),this.frequency=new Point,this.stripes=new Point,this.method="frequency",this.mask=null}return extend(i,t),i.prototype.setFrequency=function(t,i){return this.frequency=new Vector(t,i),this.method="frequency"},i.prototype.setStripes=function(t,i){return this.stripes=new Point(t,i),this.method="stripes"},i.prototype.getStripes=function(){var t,i,e,n,s,o,r,h,u,c,a,p;for(p=this.size(),a={columns:[],rows:[]},r="frequency"===this.method?this.frequency.clone():p.$divide(this.stripes).floor(),n=p.$divide(r),e=t=0,u=r.y-1;0<=u?t<=u:t>=u;e=0<=u?++t:--t)o=n.y*e,h=new Pair(0,o).to(p.x,o+n.y).add(this),h.p1.add(this),a.rows.push(h);for(e=i=0,c=r.x-1;0<=c?i<=c:i>=c;e=0<=c?++i:--i)s=n.x*e,h=new Pair(s,0).to(s+n.x+.5,p.y).add(this),h.p1.add(this),a.columns.push(h);return a},i.prototype.getStripeLines=function(){var t,i,e,n,s,o,r,h,u,c,a,p;for(p=this.size(),a={columns:[],rows:[]},r="frequency"===this.method?this.frequency.clone():p.$divide(this.stripes).floor(),n=p.$divide(r),e=t=0,u=r.y;0<=u?t<=u:t>=u;e=0<=u?++t:--t)o=n.y*e,h=new Pair(0,o).to(p.x,o).add(this),h.p1.add(this),a.rows.push(h);for(e=i=0,c=r.x;0<=c?i<=c:i>=c;e=0<=c?++i:--i)s=n.x*e,h=new Pair(s,0).to(s,p.y).add(this),h.p1.add(this),a.columns.push(h);return a},i.prototype.setMask=function(t,i,e){var n,s;return null==e&&(e=!1),this.mask=new Rectangle(this.x,this.y),s=this.size(),e?e=this.$add(e):(n=s.$subtract(t,i).divide(2),e=new Point(this.x+n.x,this.y+n.y)),this.mask.set(e.x,e.y).size(t,i)},i.prototype.anchorMask=function(){var t;return t=this.$subtract(this.mask),this.moveBy(t),this.mask.moveBy(t)},i}(Rectangle),this.StripeBound=StripeBound,UI=function(t){function i(){i.__super__.constructor.apply(this,arguments),this.dragging=!1}return extend(i,t),i.dragTarget=null,i.prototype.animate=function(t,i,e){return e.fillStyle="#f00",Form.rect(e,this)},i.prototype.onMouseAction=function(t,e,n,s){if(this.intersectPoint(e,n)&&("drag"!==t||i.dragTarget||(this.dragging=!0,i.dragTarget=this)),this.dragging&&"move"===t&&this.moveTo(e,n).moveBy(this.size().multiply(-.5)),"drop"===t)return this.dragging=!1,i.dragTarget=null},i}(Rectangle),this.UI=UI,Noise=function(t){function i(){var t;i.__super__.constructor.apply(this,arguments),this.p=[151,160,137,91,90,15,131,13,201,95,96,53,194,233,7,225,140,36,103,30,69,142,8,99,37,240,21,10,23,190,6,148,247,120,234,75,0,26,197,62,94,252,219,203,117,35,11,32,57,177,33,88,237,149,56,87,174,20,125,136,171,168,68,175,74,165,71,134,139,48,27,166,77,146,158,231,83,111,229,122,60,211,133,230,220,105,92,41,55,46,245,40,244,102,143,54,65,25,63,161,1,216,80,73,209,76,132,187,208,89,18,169,200,196,135,130,116,188,159,86,164,100,109,198,173,186,3,64,52,217,226,250,124,123,5,202,38,147,118,126,255,82,85,212,207,206,59,227,47,16,58,17,182,189,28,42,223,183,170,213,119,248,152,2,44,154,163,70,221,153,101,155,167,43,172,9,129,22,39,253,9,98,108,110,79,113,224,232,178,185,112,104,218,246,97,228,251,34,242,193,238,210,144,12,191,179,162,241,81,51,145,235,249,14,239,107,49,192,214,31,181,199,106,157,184,84,204,176,115,121,50,45,127,4,150,254,138,236,205,93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180],this.perm=function(){var i,e;for(e=[],t=i=0;i<512;t=++i)e.push(this.p[255&t]);return e}.call(this)}return extend(i,t),i.prototype.grad3=[[1,1,0],[-1,1,0],[1,-1,0],[-1,-1,0],[1,0,1],[-1,0,1],[1,0,-1],[-1,0,-1],[0,1,1],[0,-1,1],[0,1,-1],[0,-1,-1]],i.prototype.simplex=[[0,1,2,3],[0,1,3,2],[0,0,0,0],[0,2,3,1],[0,0,0,0],[0,0,0,0],[0,0,0,0],[1,2,3,0],[0,2,1,3],[0,0,0,0],[0,3,1,2],[0,3,2,1],[0,0,0,0],[0,0,0,0],[0,0,0,0],[1,3,2,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[1,2,0,3],[0,0,0,0],[1,3,0,2],[0,0,0,0],[0,0,0,0],[0,0,0,0],[2,3,0,1],[2,3,1,0],[1,0,2,3],[1,0,3,2],[0,0,0,0],[0,0,0,0],[0,0,0,0],[2,0,3,1],[0,0,0,0],[2,1,3,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[2,0,1,3],[0,0,0,0],[0,0,0,0],[0,0,0,0],[3,0,1,2],[3,0,2,1],[0,0,0,0],[3,1,2,0],[2,1,0,3],[0,0,0,0],[0,0,0,0],[0,0,0,0],[3,1,0,2],[0,0,0,0],[3,2,0,1],[3,2,1,0]],i.prototype.seed=function(t){var i,e,n,s;for(t>0&&t<1&&(t*=65536),t=Math.floor(t),t<256&&(t|=t<<8),n=[],e=i=0;i<=255;e=++i)s=1&e?this.p[e]^255&t:this.p[e]^t>>8&255,n.push(this.perm[e]=this.perm[e+256]=s);return n},i.prototype._dot=function(t,i,e){return t[0]*i+t[1]*e},i.prototype.perlin2d=function(t,i){var e,n,s,o,r,h,u,c,a,p;return null==t&&(t=this.x),null==i&&(i=this.y),e=function(t){return t*t*t*(t*(6*t-15)+10)},n=Math.floor(t)%255,s=Math.floor(i)%255,a=t-n,p=i-s,o=this._dot(this.grad3[(n+this.perm[s])%12],a,p),r=this._dot(this.grad3[(n+this.perm[s+1])%12],a,p-1),h=this._dot(this.grad3[(n+1+this.perm[s])%12],a-1,p),u=this._dot(this.grad3[(n+1+this.perm[s+1])%12],a-1,p-1),c=e(a),Util.lerp(Util.lerp(o,h,c),Util.lerp(r,u,c),e(p))},i.prototype.simplex2d=function(t,i){var e,n,s,o,r,h,u,c,a,p,l,y,f,d,m,x,g,v,z,_,b,w,P,M,S,C,L;return null==t&&(t=this.x),null==i&&(i=this.y),e=.5*(Math.sqrt(3)-1),g=(t+i)*e,c=Math.floor(t+g),l=Math.floor(i+g),n=(3-Math.sqrt(3))/6,v=(c+l)*n,s=c-v,o=l-v,w=t-s,S=i-o,w>S?(a=1,y=0):(a=0,y=1),P=w-a+n,C=S-y+n,M=w-1+2*n,L=S-1+2*n,p=255&c,f=255&l,r=this.perm[p+this.perm[f]]%12,h=this.perm[p+a+this.perm[f+y]]%12,u=this.perm[p+1+this.perm[f+1]]%12,z=.5-w*w-S*S,z<0?d=0:(z*=z,d=z*z*this._dot(this.grad3[r],w,S)),_=.5-P*P-C*C,_<0?m=0:(_*=_,m=_*_*this._dot(this.grad3[h],P,C)),b=.5-M*M-L*L,b<0?x=0:(b*=b,x=b*b*this._dot(this.grad3[u],M,L)),70*(d+m+x)},i}(Vector),Delaunay=function(t){function i(){i.__super__.constructor.apply(this,arguments),this.mesh=[]}return extend(i,t),i.prototype.generate=function(){var t,i,e,n,s,o,r,h,u,c,a,p,l,y,f,d,m,x,g,v;if(!(this.points.length<3)){for(f=this.points.length,a=[],c=t=0,g=f;t<g;c=t+=1)a[c]=c;for(a.sort(function(t){return function(i,e){return t.points[e].x-t.points[i].x}}(this)),x=this.points.slice(),v=this._supertriangle(),x.push(new Vector(v),new Vector(v.p1),new Vector(v.p2)),m=[this._circum(f,f+1,f+2,v)],o=[],u=[],i=0,l=a.length;i<l;i++){for(n=a[i],u=[],p=m.length;p--;)s=m[p],r=x[n].x-s.circle.x,h=x[n].y-s.circle.y,r>0&&r*r>s.circle.radius*s.circle.radius?(o.push(s),m.splice(p,1)):r*r+h*h-s.circle.radius*s.circle.radius>Const.epsilon||(u.push(s.i,s.j,s.j,s.k,s.k,s.i),m.splice(p,1));for(this._dedupe(u),p=u.length;p>1;)m.push(this._circum(u[--p],u[--p],n,null,x))}for(e=0,y=m.length;e<y;e++)d=m[e],d.i<f&&d.j<f&&d.k<f&&o.push(d);return this.mesh=o,this.mesh}},i.prototype._supertriangle=function(){var t,i,e,n,s,o,r,h,u;for(r=new Vector,s=new Vector,u=this.points,t=0,n=u.length;t<n;t++)h=u[t],r.min(h),s.max(h);return i=s.$subtract(r),o=r.$add(s).divide(2),e=Math.max(i.x,i.y),new Triangle(o.$subtract(20*e,e)).to(o.$add(0,20*e),o.$add(20*e,-e))},i.prototype._triangle=function(t,i,e,n){return null==n&&(n=this.points),new Triangle(n[t]).to(n[i],n[e])},i.prototype._circum=function(t,i,e,n,s){return null==n&&(n=null),null==s&&(s=this.points),n=n||this._triangle(t,i,e,s),{i:t,j:i,k:e,triangle:n,circle:n.circumcircle()}},i.prototype._dedupe=function(t){var i,e,n,s,o,r;for(s=t.length;s>1;)for(e=t[--s],i=t[--s],n=s;n>1;)if(r=t[--n],o=t[--n],i===o&&e===r||i===r&&e===o){t.splice(s,2),t.splice(n,2);break}return t},i}(PointSet),this.Delaunay=Delaunay;