
var neo={};var hub={};exports.neo=neo;neo.Nit=function(){this.parts={};};neo.Nit.prototype.apply=function(options,parts){return neo.apply(this,options,parts);};neo.childApply=function(parent,prop,options,parts){var c=parent[prop];parent[prop]=c.apply(options,parts);}
neo.Nit.prototype.newRepoVersion=function(tag){var r=this._repo;var cv=this._currentVersion;if(!cv)cv=[];if(!r){r=new neo.Repo();this._repo=r;this._currentVersion=[];}
if(tag){return tag;}
return r.newVersion(cv);}
neo.allocVersion=function(repo,o,tag){var vs=o._versionSet;if(!vs){vs=neo.allocVersionSet(repo,o,tag);}
return o;}
neo.Nit.prototype.clone=function(){var rs=new this.Class(this.options);neo.copyProps(rs,this,["value","_repo","Class","parts","_currentVersion","_currentTag","_id","_nodes"]);return rs;}
neo.Nit.prototype.newVersion=function(){var nv=this.newRepoVersion();var rs=this.clone();rs._currentVersion=nv;return rs;}
neo.Nit.prototype.applyParts=function(partOptions,newVersion,noReturnNeeded){if(newVersion){var nrepov=newVersion;}else{var nrepov=this.newRepoVersion();}
var r=this._repo;var cv=this._currentVersion;var cparts=this.parts;var n=0;if(noReturnNeeded){var rs=null;}else{rs=this.clone();if(nrepov){rs._currentVersion=nrepov;}}
for(var partname in partOptions){var ppath=this.parts[partname];var options=partOptions[partname];if($.isArray(ppath)){this.applyPartPath(ppath,options,nrepov,1);}else{partc=neo.vget(this,this.parts,partname,cv);var part=partc.value;if(!part)this.error("No such part "+partname);var pcv=neo.allocVersion(r,part);var pvs=pcv._versionSet;var apv=pcv.apply(options);neo.addVersionToObject(pvs,nrepov,apv);}
n++;}
return rs;}
neo.Nit.prototype.applyPart=function(partname,options,versionOrTag,noReturnNeeded){var partOptions={};partOptions[partname]=options;return this.applyParts(partOptions,versionOrTag,noReturnNeeded);}
neo.Nit.prototype.applyPartPath=function(path,options,newVersion,noReturnNeeded){if(newVersion){var nrepov=newVersion;}else{var nrepov=this.newRepoVersion();}
var ln=path.length;var fpe=path[0];if(ln==1){var po={};po[fpe]=options;return this.applyParts(po,nrepov,noReturnNeeded);}
var partc=neo.vget(this,this.parts,fpe,nrepov);var part=partc.value;var exact=partc.exact;if(!part)neo.error("No such path ",path);var cv=this._currentVersion;if(exact){part.applyPartPath(path.slice(1),options,part._currentVersion);}else{var partcv=neo.allocVersion(this._repo,part);var pnrepov=partcv.newRepoVersion();var np=part.applyPartPath(path.slice(1),options,pnrepov);neo.addVersionToObject(partcv._versionSet,nrepov,np);}
if(!noReturnNeeded){var rs=this.clone();rs._currentVersion=nrepov;return rs;}}
neo.Nit.prototype.applyPartPaths=function(pathOptions,newVersion){if(newVersion){var nrepov=newVersion;}else{var nrepov=this.newRepoVersion();}
var ln=pathOptions.length;for(var i=0;i<ln;i++){var cpo=pathOptions[i];var path=cpo[0];var options=cpo[1];this.applyPartPath(path,options,nrepov,1);}
var rs=this.clone();rs._currentVersion=nrepov;return rs;}
neo.Nit.prototype.selectPart=function(path,version){if(typeof path=="string"){return this.selectPart([path],version);}
if(version){var cv=version;}else{cv=this._currentVersion;}
var cn=this;var repo=this._repo;var ln=path.length;for(var i=0;i<ln;i++){var prop=path[i];var parts=cn.parts;var nnc=neo.vget(cn,parts,prop,cv);var nn=nnc.value;cv=null;if(!nn)return null;cn=nn;}
return cn;}
neo.Nit.prototype.dParts0=function(d,partname){var rs="";function padleft(n){for(var i=0;i<n;i++)rs+=" ";};if(!partname)partname="root";var parts=this.parts;padleft(d*2);var nodes=this._nodes;var cv=this._currentVersion;rs+=partname+" ";if(this._id){rs+=" id="+(this._id);}
if(nodes){var fn=nodes[0];var path=fn.path();rs+=" versionInParentRepo="+(path.join("."));}
if(cv){rs+=" versionOfThisRepo="+cv.join(".");}
rs+="\n";if(parts){for(var n in parts){var cp=parts[n];if($.isArray(cp))continue;var pv=neo.currentVersion(this,cp);rs+=pv.dParts0(d+1,n);}}
return rs;}
neo.Nit.prototype.dParts=function(){return this.dParts0(0,"root");}
neo.Ensemble=function(repo){this.repo=repo;this.values={};};neo.Variant=function(version,value){this.version=version;this.value=value;}
neo.Tree=function(value,parent,index){this.value=value;this.parent=parent;this.index=index;this.children=[];}
neo.Tree.prototype.addChild=function(v){var ch=this.children;var ln=ch.length;for(var i=0;i<ln;i++){var cch=ch[i];if(cch&&(cch.value==="removed")){cch.value=v;return cch;}}
var nch=new neo.Tree(v,this,ln);ch.push(nch);return nch;}
neo.Tree.prototype.select=function(s){var ch=this.children;if(typeof s==="number"){if(s>=ch.length)return undefined;var rs=ch[s];if(rs&&(rs.value==="removed"))return undefined;return rs;}
var ln=s.length;var cv=this;for(var i=0;i<ln;i++){var cs=s[i];ch=cv.children;if(cs>=ch.length)return undefined;var nv=ch[cs];if(!nv)return undefined;if(nv&&(nv.value==="removed"))return undefined;cv=nv;}
return cv;}
neo.Tree.prototype.selectOnPath=function(path){var ln=path.length;var cv=this;var cvv=cv.value;var rs=null;if(cvv&&(cvv!="removed")){rs=cv;}
for(var i=0;i<ln;i++){var cs=path[i];ch=cv.children;if(cs>=ch.length)return{exact:0,node:rs};var nv=ch[cs];if(!nv)return{exact:0,node:rs};if(nv&&(nv.value==="removed"))return{exact:0,node:rs};cv=nv;cvv=cv.value;if(cvv&&(cvv!="removed")){rs=cv;}}
return{exact:1,node:rs};}
neo.Tree.prototype.addAtPath=function(path,value){var ln=path.length;var cv=this;for(var i=0;i<ln;i++){var cs=path[i];var nv=cv.select(cs);if(nv){cv=nv;continue;}
var ch=cv.children;var chln=ch.length;if(cs<chln){var csch=ch[cs];if(csch){csch.value=null;cv=csch;}else{var nv=new neo.Tree(null,cv,cs);ch[cs]=nv;cv=nv;}}else{for(var j=chln;j<cs;j++){ch.push(null);}
var nv=new neo.Tree(null,cv,cs);ch.push(nv);cv=nv;}}
cv.value=value;var nodes=value._nodes;if(!nodes){nodes=[];value._nodes=nodes;}
nodes.push(cv);return cv;}
neo.Tree.prototype.remove=function(){if(this.value=="removed")return;var ch=this.children;var ln=ch.length;for(var i=0;i<ln;i++){var cch=ch[i];if(cch&&(cch.value!="removed")){cch.remove();}}
this.value="removed";}
neo.Tree.prototype.path=function(){var rsr=[];var cv=this;while(cv.parent){rsr.push(cv.index);cv=cv.parent;}
return rsr.reverse();}
neo.Tree.prototype.stringify=function(){var rs="[";var v=this.value;var ch=this.children;if(typeof v=="string"){rs+=v;}else if(v){rs+=" -object- "}else{rs+="null";}
if(v!="removed"){var srs=[];var ln=ch.length;if(ln>0){for(var i=0;i<ln;i++){var cch=ch[i];if(cch){if(cch.value=="removed"){srs.push("removed");}else{srs.push(cch.stringify());}}else{srs.push("null");}}
rs+="(";rs+=srs.join(",");rs+=")";}}
rs+="]";return rs;}
neo.Repo=function(){this.versionTree=new neo.Tree("value");}
neo.Repo.prototype.selectVersion=function(p){var vt=this.versionTree;return vt.select(p);}
neo.Repo.prototype.newVersion=function(vp){var vt=this.versionTree;var v=vt.select(vp);var nch=v.addChild("value");var rs=vp.concat();rs.push(nch.index);neo.collectVersion(nch);return rs;}
neo.selectVersion=function(o,vp){var vs=o._versionSet;if(!vs){return o;}
var vt=vs.versionTree;var rs=vt.selectOnPath(vp);if(!(rs.node))this.error("No such version: ",vp);return{exact:rs.exact,value:rs.node.value};}
neo.collectedVersions=[];neo.collectingVersions=false;neo.collectVersion=function(v){if(neo.collectingVersions&&(v.collectedIn!==neo.collectedVersions)){neo.collectedVersions.push(v);v.collectedIn=neo.collectedVersions;}}
neo.resetCollectedVersions=function(){var c=neo.collectedVersions;var ln=c.length;for(var i=0;i<ln;i++){var cv=c[i];cv.collectedIn=null;}
neo.collectedVesions=[];}
neo.stopCollectingVersions=function(){neo.resetCollectedVersions();neo.collectingVersion=false;}
neo.removeCollectedVersions=function(){var c=neo.collectedVersions;var ln=c.length;for(var i=0;i<ln;i++){var cv=c[i];cv.remove();cv.collectedIn=null;}
neo.collectedVersions=[];neo.collectingVersions=false;}
neo.startCollectingVersions=function(){neo.collectingVersions=true;}
neo.allocVersionSet=function(repo,o){if(o._versionSet)return o._versionSet;var vt=new neo.Tree(o);var vs={repo:repo,versionTree:vt};o._versionSet=vs;return vs;}
neo.addVersionToObject=function(versionSet,vp,o){o._versionSet=versionSet;var vt=versionSet.versionTree;var v=vt.addAtPath(vp,o);neo.collectVersion(v);}
neo.addVersion=function(repoVersion,versionSet,o){var repo=versionSet.repo;var nv=repo.newVersion(repoVersion);neo.addVersionToObject(versionSet,nv,o);return nv;}
neo.currentVersion=function(root,o){if(!root){return o;}
var vs=o._versionSet;if(!vs)return o;var cv=root._currentVersion;var repo=root._repo;if(!repo)neo.error("Expected repo");if((vs.repo)!==repo)neo.error("Wrong repo");var rs=neo.selectVersion(o,cv);return rs.value;}
neo.vget=function(root,o,prop,version){var repo=root._repo;if(version){var vp=version;}else{vp=root._currentVersion;}
if((!repo)||(!vp)){return{exact:0,value:o[prop]};}
var vs=o._versionSet;if(vs){neo.error("THIS CASE NO LONGER HANDLED BY VGET");if((vs.repo!==repo)){neo.error("Wrong repo");}
var ov=neo.selectVersion(o,vp)}else{ov=o;}
var pv=ov[prop];if(typeof pv!="object")return{exact:0,value:pv};if(!pv)return{exact:0,value:pv};var pvs=pv._versionSet;if(!pvs)return{exact:0,value:pv};if(pvs.repo!==repo)neo.error("Wrong repo");return neo.selectVersion(pv,vp);}
neo.shape={};neo.shape={};neo.shapes={};if((typeof window)=="undefined"){jQuery=require('/var/www/neo.com/lib/mini_jquery.js').jQuery;}
(function(){var $n=neo;$=jQuery;$n.activeConsoleTags=[];$n.log=function(tag){if(neo.theIEVersion||(typeof console=="undefined"))return;if(($.inArray("all",$n.activeConsoleTags)>=0)||($.inArray(tag,$n.activeConsoleTags)>=0)){console.log(tag,arguments);}};$n.error=function(a,b){console.log("Error "+a,b);foob();};$n.extend=function(deep,target){var ln=arguments.length;if(deep)lib.error("deep not yet supported");for(var i=2;i<ln;i++){var m=arguments[i];for(var j in m){if(m.hasOwnProperty(j)){target[j]=m[j];}}}
return target;};$n.copyProps=function(dest,src,props){var ln=props.length;for(var i=0;i<ln;i++){var p=props[i];var sv=src[p];if(typeof sv!="undefined"){dest[p]=sv;}}}
$n.inheritFrom=function(o){function F(){}
F.prototype=o;return new F();};$n.defined=function(){var n=arguments.length;for(var i=0;i<n;i++){if(typeof arguments[i]==="undefined")return false;}
return true;};$n.apply=function(nit,options,parts){if(options){var o=$n.inheritFrom(nit.options);$n.extend(null,o,options);var rs=new nit.Class(o);}else{rs=nit;}
var v=$n.inheritFrom(rs.options);rs.value=v;var oparts=nit.parts;if(oparts){if(parts){rs.parts=$n.extend(null,parts,oparts);}else{rs.parts=oparts;}}else{rs.parts=parts;}
if(nit._repo)rs._repo=nit._repo;if(nit._currentVersion)rs._currentVersion=nit._currentVersion;if(nit._currentTag)rs._currentTag=nit._currentTag;if(nit._id)rs._id=nit._id;if(nit._nodes)rs._nodes=nit._nodes;return rs;};$n.FofT=function(data,implementation){this.data=data;this.implementation=implementation;};neo.sortSegmentsByTimeStart=function(segments){var sorted=segments._sorted;function compareStartTimes(s0,s1){if(s0.timeStart<s1.timeStart){return-1;}
return 1;}
if(!sorted){segments.sort(compareStartTimes);segments._sorted=1;}
var ln=segments.length;for(var i=0;i<ln;i++){var csg=segments[i];csg.index=i;}}
neo.analyzeSegments=function(segments){neo.sortSegmentsByTimeStart(segments);var rs=[];var ln=segments.length;var cs=segments.length;for(var i=0;i<ln;i++){console.log(i);var cs=segments[i];rs.push(i);var csts=cs.timeStart;var cste=cs.timeEnd;rs.push(csts);rs.push(cste);rs.push(cs.value.name);if(i<ln-1){var ns=segments[i+1];var nsts=ns.timeStart;if(!nsts||!cste)continue;var nstst=neo.dateToTime(nsts);var cstet=neo.dateToTime(cste);var g=nstst-cstet;if(g<0){rs.push("overlap");rs.push(-g);}else if(g>0){rs.push("gap");rs.push(g);}}}
return rs;}
neo.selectSegment=function(segments,tm){var t=neo.timeToDate(tm);neo.sortSegmentsByTimeStart(segments);var ln=segments.length;for(var i=0;i<ln;i++){var sg=segments[i];var st=sg.timeStart;var et=sg.timeEnd;if(i<(ln-1)){var nxtsg=segments[i+1];}
if(i>0){var prevsg=segments[i-1];}
if(prevsg&&(prevsg.timeEnd)&&(sg.timeStart)&&(prevsg.timeEnd<t)&&(t<sg.timeStart)){return{inGap:1,prev:prevsg,nxt:nxtsg};}
if((i==0)&&(sg.timeStart)&&(t<sg.timeStart)){return{inGap:1,nxt:sg};}
if(!st){if(t<=et){if(nxtsg&&(nxtsg.timeStart<=t)){return nxtsg;}
return sg;}}
if(!et){if(t>=st)return sg;}
if((st<=t)&&(t<=et)){if(nxtsg&&(nxtsg.timeStart<=t)){return nxtsg;}
return sg;}}
return undefined;};neo.evalFromSegments=function(segments,t){var sg=neo.selectSegment(segments,t);if(sg&&(!sg.inGap)){var vl=sg.value;return vl;}}
neo.adjoiningSegmentStartTimes=function(datum,t){if(!t)t=neo.currentTime;var segments=datum;var sg=neo.selectSegment(segments,t);if(!sg)return undefined;if(sg.inGap){var rs={nxt:sg.nxt.timeStart};if(sg.prev){rs.prev=sg.prev.timeStart;}
return rs;}
var i=sg.index;var ln=segments.length;var nxt=null;var prv=null;if(i<(ln-1)){var nxt=segments[i+1].timeStart;}
if(i>0){var prv=segments[i-1].timeStart;}
return{prev:prv,nxt:nxt};}
neo.segmentIntervalAsString=function(segment){if(segment.inGap){var psg=segment.prev;var ts=psg?psg.timeEnd:"none";var nxt=segment.nxt;var te=nxt?nxt.timeStart:"none"}else{var ts=segment.timeStart;var te=segment.timeEnd;}
return(ts?ts:"none")+"_to_"+(te?te:"none");}
$n.FofT.prototype.evalAtT=function(t){var imp=this.implementation;return imp(this,t);};neo.FofTkind=function(x){if(typeof x!="object")return false;if($.isArray(x)){var ln=x.length;if(ln==0)return false;var fe=x[0];if(typeof fe!="object"){return false;}
var ts=fe.timeStart;if(ts)return"segments";}
if(x.constructor==neo.FofT)return"object";return false;};neo.currentTime="2010-01-01";neo.evalAtT=function(datum,t){if(!t)t=neo.currentTime;var k=neo.FofTkind(datum);if(!k)return datum;if(k=="segments"){return neo.evalFromSegments(datum,t);}
return k.evalAtT(t);};$n.gett=function(o,prop,t){var v=o[prop];if(!v)return v;return neo.evalAtT(v,t);};$n.temporalElements=[];neo.renderTemporalElements=function(){var te=neo.temporalElements;var ln=te.length;for(var i=0;i<ln;i++){var e=te[i];e.render();}};neo.setTheTime=function(tm){neo.currentTime=tm;neo.renderTemporalElements();}
neo.data={};neo.error=function(){var aa=arguments;if(typeof navigator=="undefined"){system.stdout("NEO ERROR: "+JSON.stringify(aa));}else{debugger;}
furbish();};neo.Topic=function(id,name,descriptors){this.id=id;this.name=name;if(descriptors){this.descriptors=descriptors;}else{this.descriptors=[];}};neo.addTopic=function(id,name,descriptors){var spid=id.split("/");var ln=spid.length;var lst=spid[ln-1];var data=neo.data;function idToName(s){var spi=s.split("_");var parts=$.map(spi,function(a){return a.charAt(0).toUpperCase()+a.substr(1);});return parts.join(" ");}
if(!name){name=idToName(lst);}
var co=data;for(i=1;i<ln-1;i++){var ct=spid[i];var cc=co[ct];if(!cc){cc={};co[ct]=cc;}
co=cc;}
var ctopic=co[lst];if(ctopic){if(name)ctopic.name=name;if(descriptors){var cd=ctopic.descriptors;if(!cd||(cd.length===0)){ctopic.descriptors=descriptors;}}
return ctopic;}
var rs=new neo.Topic(id,name,descriptors);co[lst]=rs;return rs;};neo.Descriptor=function(properties){neo.extend(false,this,properties);};neo.selectTopic=function(path,emitError,autoAddTopic){if(typeof path=="object")return path;var sp=path.split("/");var cv=neo.data;var ln=sp.length;for(var i=1;i<ln;i++){var id=sp[i];cv=cv[id];if(!cv){if(emitError)neo.error("Could not resolve "+path);if(autoAddTopic){return neo.addTopic(path);}
return null;}}
return cv;};neo.resolveRefs=function(o,autoAddTopics){if(!o)return o;var tp=typeof o;if(tp==="string"){var ln=o.length;if(ln==0)return o;var fc=o.charAt(0);if(fc==="/"){return neo.selectTopic(o,0,autoAddTopics);}
return o;}
if(tp==="object"){if($.isArray(o)){var rs=[];var ln=o.length;for(var i=0;i<ln;i++){rs.push(neo.resolveRefs(o[i],autoAddTopics));}
return rs;}
if(o.constructor==neo.Topic)return o;var rs={};for(var j in o){if(o.hasOwnProperty(j)){rs[j]=neo.resolveRefs(o[j],autoAddTopics);}}
return rs;}};neo.addDescriptor=function(topic,ids){if(ids.constructor===neo.Descriptor){var ds=ids;}else{ids._kind="Descriptor";ds=neo.internalize(ids);}
topic.descriptors.push(ds);};neo.cast=function(topic,type){var ds=topic.descriptors;var ln=ds.length;for(var i=0;i<ln;i++){var cd=ds[i];if(cd.type===type)return cd;}
return undefined;};neo.v8test=function(){system.stdout("HERE I AM");};neo.externalizeTopicsAsRefs=function(o){if(typeof o=="string"){if((o.length>0)&&(o.charAt(0)==="/")){return{_quote:o};}
return o;}
if(typeof o!="object")return o;if(!o)return o;if(o.constructor===neo.Topic){return o.id;}
return neo.externalize(o,true);};neo.externalize=function(o,innerCall){if(typeof o=="string"){if((o.length>0)&&(o.charAt(0)==="/")){return{_quote:o};}
return o;}
if(typeof o!="object")return o;if(!o)return o;if($.isArray(o)){var rs=[];var ln=o.length;for(var i=0;i<ln;i++){if(innerCall){rs.push(neo.externalizeTopicsAsRefs(o[i]));}else{rs.push(neo.externalize(o[i],true));}}
return rs;}
rs={};var cn=o.constructor;if(cn===neo.Topic){var k="Topic";}else if(cn===neo.Descriptor){k="Descriptor";}
if(k)rs._kind=k;for(var j in o){if(o.hasOwnProperty(j)){if((k=="Descriptor")&&(j=="topic"))continue;if((k=="Topic")&&(j=="id")){rs[j]=o[j];}else{rs[j]=neo.externalizeTopicsAsRefs(o[j]);}}}
return rs;};neo.findTopics=function(o,rs){if(!rs){rs=[];}
if(typeof o!="object")neo.error("unexpected non-object");if(o.constructor==neo.Topic){rs.push(o);}else{for(var i in o){neo.findTopics(o[i],rs);}}
return rs;};neo.externalizeTopics=function(d){var topics=neo.findTopics(d);return neo.externalize(topics);};neo.internalize=function(o){var tp=typeof o;if(tp=="string"){if((o.length>0)&&(o.charAt(0)=="/")){return neo.addTopic(o);}
return o;}
if(tp!="object")return o;if($.isArray(o)){var rs=[];var ln=o.length;for(var i=0;i<ln;i++){rs.push(neo.internalize(o[i]));}
return rs;}
var cn=o.constructor;if((cn===neo.Topic)||(cn===neo.Descriptor))return o;var qv=o._quote;if(qv)return qv;var k=o._kind;if(k=="Topic"){var rs=neo.addTopic(o.id,o.name);var ds=o.descriptors;if(ds){dsi=neo.internalize(ds);var ln=ds.length;for(var i=0;i<ln;i++){var cd=dsi[i];cd.topic=rs;rs.descriptors=dsi;}}
return rs;}
if(k=="Descriptor"){rs=new neo.Descriptor();}else{rs={};}
for(var j in o){if(j!="_kind"){rs[j]=neo.internalize(o[j]);}}
return rs;};neo.yearInMilliseconds=(function(y){var jan1=new Date(y,0,1,0,0,0);var dec31=new Date(y,11,31,23,59,59);return dec31-jan1;});neo.dateToTime=function(date){var ds=date.split("-");var y=ds[0];if(ds.length==3){var m=ds[1];var dy=ds[2];}else{m=1;dy=1;}
var ms=new Date(y,m-1,dy,0,0,0).getTime();var jan1=new Date(y,0,1,0,0,0).getTime();var dec31=new Date(y,11,31,23,59,59).getTime();var yearFraction=(ms-jan1)/(dec31-jan1);return parseInt(y)+yearFraction;}
neo.timeToDate=function(tm){var y=Math.floor(tm);var fr=tm-y;var jan1=new Date(y,0,1,0,0,0).getTime();var dec31=new Date(y,11,31,23,59,59).getTime();var utm=jan1+fr*(dec31-jan1);var jsd=new Date(utm);var y=jsd.getUTCFullYear();var m=jsd.getUTCMonth()+1;if(m<10)m="0"+m;var d=jsd.getUTCDate();if(d<10)d="0"+d;return y+"-"+m+"-"+d;}
neo.dateToUSformat=function(d){var sd=d.split("-");if(sd.length==3){return sd[1]+"/"+sd[2]+"/"+sd[0];}else{return d;}}
neo.timeToUSformat=function(t){return neo.dateToUSformat(neo.timeToDate(t));}})();var GEOM2D={};exports.GEOM2D=GEOM2D;(function(){var lib=GEOM2D;lib.Point=function(x,y){this.x=x;this.y=y;}
lib.Point.prototype.times=function(z){return new lib.Point(z*this.x,z*this.y);}
lib.Point.prototype.divideBy=function(z){var x=this.x;var y=this.y;if(typeof z=="number"){return new lib.Point(x/z,y/z);}
return new lib.Point(x/(z.x),y/(z.y));}
lib.Point.prototype.plus=function(p){return new lib.Point(this.x+p.x,this.y+p.y);}
lib.Point.prototype.minus=function(p){if(typeof p=="undefined"){return new lib.Point(-this.x,-this.y);}
return new lib.Point(this.x-p.x,this.y-p.y);}
lib.Rect=function(corner,extent){this.corner=corner;this.extent=extent;}
lib.Grid=function(rows,corner,extent){debugger;this.rows=rows;this.rowCount=rows.length;this.colCount=rows[0].length;var xInc=extent.x/(this.rowCount-1);var yInc=extent.y/(this.colCount-1);this.corner=corner;this.extent=extent;this.cellDim=new lib.Point(xInc,yInc);}
lib.Grid.prototype.inCell=function(p){var rc=p.minus(this.corner);var cellDim=this.cellDim;var xidx=Math.floor(rc.x/cellDim.x);var yidx=Math.floor(rc.y/cellDim.y);var cell=new lib.Point(xidx,yidx);var cellDim=this.cellDim;var relcell=p.minus(p,new lib.Point(xidx*cellDim.x,yidx*cellDim.y));var normalizedRelcell=relcell.divideBy(cellDim);return{cell:cell,withinCell:normalizedRelcell};}
lib.Grid.prototype.valueAtGridPoint=function(p){var rows=this.rows;var row=rows[p.y];return row[p.x];}
lib.Grid.prototype.valueAtPoint=function(p){debugger;var cin=this.inCell(p);var c=cin.cell;var incell=cin.withinCell;var vp0=this.valueAtGridPoint(c);var vp1=this.valueAtGridPoint(new lib.Point(c.x+1,c.y));var vp2=this.valueAtGridPoint(new lib.Point(c.x,c.y+1));var vp3=this.valueAtGridPoint(new lib.Point(c.x+1,c.y+1));var incx=incell.x;var incy=incell.y;var topI=vp0*(1-incx)+vp1*incx;var bottomI=vp2*(1-incx)+vp1*incx;var rs=topI*(1-incy)+bottomI*incy;return rs;}
lib.Grid1=function(values,lb,ub){this.values=values;this.count=values.length;this.increment=(ub-lb)/(this.count-1);this.lb=lb;this.ub=ub;}
lib.Grid1.prototype.inCell=function(x){var lb=this.lb;var r=x-lb;var inc=this.increment
var idx=Math.floor(r/inc);var relcell=(r-idx*inc)/inc;return{cell:idx,withinCell:relcell};}
lib.Grid1.prototype.valueAt=function(x){var cin=this.inCell(x);var idx=cin.cell;var incell=cin.withinCell;var values=this.values;var v0=values[idx];var v1=values[idx+1];var rs=v1*incell+v0*(1-incell);return rs;}})();