UNPKG

agentscript

Version:

AgentScript Model in Model/View architecture

5 lines (4 loc) 141 kB
var Bi=Object.defineProperty;var ut=(r,t)=>{for(var e in t)Bi(r,e,{get:t[e],enumerable:!0})};var S={};ut(S,{AsyncFunction:()=>Ui,PI:()=>Lt,RESTapi:()=>ro,addCssLink:()=>to,addCssStyle:()=>Bs,arrayExtent:()=>In,arrayLast:()=>Tn,arrayMax:()=>Rs,arrayMin:()=>Ds,arrayToMatrix:()=>Dn,arraysDiff:()=>Rn,arraysEqual:()=>Qe,arraysToString:()=>Ke,blobToData:()=>Zi,blobsEqual:()=>Hi,checkArg:()=>Ji,checkArgs:()=>Qi,clamp:()=>$,classHasStartup:()=>wn,clearCtx:()=>qt,cloneCanvas:()=>Ns,concatArrays:()=>tr,convertArrayType:()=>At,createCanvas:()=>Pt,createCtx:()=>A,cssTrace:()=>sn,ctxImageColors:()=>lr,ctxImageData:()=>xt,ctxImagePixels:()=>Hn,degToHeading:()=>hn,degToRad:()=>_s,degreesEqual:()=>As,degreesTowardXY:()=>xn,difference:()=>kn,distance:()=>ft,distance3:()=>pt,downloadBlob:()=>or,downloadCanvas:()=>ve,downloadJson:()=>Zn,downloadJsonModule:()=>qn,drawText:()=>cr,dump:()=>Kn,fetchCssStyle:()=>eo,fetchData:()=>xe,fetchImage:()=>Vn,fetchImageBitmap:()=>jn,fetchJson:()=>qi,fetchText:()=>Vi,fillCtxWithImage:()=>st,floatRamp:()=>Me,forLoop:()=>C,fps:()=>tn,getEventXY:()=>io,getQueryString:()=>$s,grep:()=>zn,hasCanvas:()=>Wi,headingAngleToRad:()=>fn,headingToDeg:()=>cn,headingToRad:()=>un,headingTowardXY:()=>gn,headingsEq:()=>mn,identityFcn:()=>Je,imagePromise:()=>gt,imageToCanvas:()=>Gn,imageToCtx:()=>Ot,inCone:()=>Ge,inDeno:()=>ge,inMain:()=>me,inNode:()=>$i,inWorker:()=>Ue,integerRamp:()=>Ut,intersection:()=>En,isArray:()=>Se,isArrayLike:()=>Ys,isBetween:()=>N,isCanvas:()=>Ce,isColorLikeArray:()=>Wn,isDataSet:()=>Ls,isFloatArray:()=>$n,isFunction:()=>ze,isImage:()=>Ln,isImageable:()=>Zt,isIntArray:()=>Bn,isInteger:()=>Fs,isLittleEndian:()=>Un,isNumber:()=>rt,isObject:()=>vt,isOneOfTypes:()=>nr,isOofA:()=>St,isPowerOf2:()=>we,isString:()=>D,isType:()=>Ct,isTypedArray:()=>_t,isUintArray:()=>Nn,lerp:()=>Bt,lerpScale:()=>qe,logAll:()=>rn,logOnce:()=>Cs,matrixToArray:()=>Xn,mod:()=>tt,mod180180:()=>ln,mod2pi:()=>Nt,mod360:()=>Y,nestedProperty:()=>On,nextPowerOf2:()=>an,noopFcn:()=>Mn,objectLength:()=>vn,objectToString:()=>Cn,objectsEqual:()=>_n,oneKeyOf:()=>Is,oneOf:()=>mt,oneValOf:()=>rr,oofaBuffers:()=>Yn,oofaObject:()=>Xs,otherOneOf:()=>er,parseQueryString:()=>Ws,pause:()=>Ss,pps:()=>en,precision:()=>ye,printToPage:()=>so,propFcn:()=>Wt,radToDeg:()=>Mt,radToHeading:()=>be,radToHeadingAngle:()=>dn,radiansTowardXY:()=>et,radsEqual:()=>pn,randomCentered:()=>nn,randomFloat:()=>Ze,randomFloat2:()=>K,randomInt:()=>B,randomInt2:()=>Q,randomNormal:()=>on,randomSeed:()=>vs,range:()=>Sn,removeArrayItem:()=>W,repeat:()=>R,resizeCtx:()=>ar,runModel:()=>yn,sampleModel:()=>bn,setCanvasSize:()=>_e,setCtxImage:()=>Jn,setIdentity:()=>Et,setTextProperties:()=>kt,shuffle:()=>ir,sortNums:()=>An,sortObjs:()=>sr,sqDistance:()=>$t,sqDistance3:()=>ks,step:()=>Ts,stringMetrics:()=>hr,subtractDegrees:()=>Es,subtractHeadings:()=>He,subtractRadians:()=>Ps,timeit:()=>Ki,timeoutLoop:()=>zs,toAofO:()=>zt,toDataURL:()=>ji,toDeg:()=>Ve,toJSON:()=>Os,toOofA:()=>Fn,toRad:()=>je,toWindow:()=>Qn,typeOf:()=>O,union:()=>Pn,waitUntilDone:()=>Gi,warn:()=>dt,wrap:()=>bt});function me(){return globalThis.document!==void 0}function Ue(){return globalThis.WorkerGlobalScope!==void 0}function $i(){return typeof globalThis.require<"u"}function ge(){return typeof globalThis.Deno<"u"}function Wi(){return globalThis.canvas!=="undefined"}function Ui(r,t){let e=Object.getPrototypeOf(async function(){}).constructor;return new e(...r,t)}function Zi(r,t="dataURL"){t=t[0].toUpperCase()+t.slice(1);let e=["Text","ArrayBuffer","DataURL"];if(!e.includes(t))throw Error("blobToData: data must be one of "+e.toString());let s=new FileReader;return new Promise((i,n)=>{s.addEventListener("load",()=>i(s.result)),s.addEventListener("error",a=>n(a)),s["readAs"+t](r)})}async function xe(r,t="blob"){let e=["arrayBuffer","blob","json","text"];if(!e.includes(t))throw Error("fetchData: data must be one of "+e.toString());return fetch(r).then(s=>s[t]())}async function qi(r){return xe(r,"json")}async function Vi(r){return xe(r,"text")}function ji(r,t=void 0){return r.toDataURL?r.toDataURL(t,t):(t||(t="text/plain;charset=US-ASCII"),`data:${t};base64,${btoa(r)}}`)}async function Hi(r,t){let e=await r.text(),s=await t.text();return e===s}function Ss(r=1e3){return new Promise(t=>{setTimeout(t,r)})}async function zs(r,t=-1,e=0){let s=0;for(;s++!==t;)r(s-1),await Ss(e)}function Gi(r,t=10){return new Promise(e=>{function s(){if(r())return e();setTimeout(s,t)}s()})}function Ji(r,t="number",e="Function"){}function Qi(r,t="number",e="Function"){}var Ms=new Set;function Cs(r,t=!1){Ms.has(r)||(t?console.warn(r):console.log(r),Ms.add(r))}function dt(r){Cs(r,!0)}function Ki(r,t=1e5,e="test"){e=e+"-"+t,console.time(e);for(let s=0;s<t;s++)r(s);console.timeEnd(e)}function tn(){let r=typeof performance>"u"?Date:performance,t=r.now(),e=0;function s(){e++;let i=r.now()-t,n=parseFloat((e/(i/1e3)).toFixed(2));Object.assign(s,{fps:n,ms:i,start:t,steps:e})}return s.steps=0,s}function en(r,t=""){t&&console.log(t);let e=1,s="";for(;r;){if(typeof r=="function")s=r.constructor.toString();else{let i=Object.keys(r);s=i.length>0?`[${i.join(", ")}]`:`[${r.constructor.name}]`}console.log(`[${e++}]: ${s}`),r=Object.getPrototypeOf(r)}}function rn(r){Object.keys(r).forEach(t=>console.log(" ",t,r[t]))}function sn(r,t=["position","cursor","display","width","height"]){let e=document.querySelector(r);for(;e;){let s=window.getComputedStyle(e);console.log("element:",e),console.log("tag:",e.tagName),t.forEach(i=>console.log(i+":",s[i])),console.log("------------------------"),e=e.parentElement}}var Lt=Math.PI;function B(r){return Math.floor(Math.random()*r)}function Q(r,t){return r+Math.floor(Math.random()*(t-r))}function Ze(r){return Math.random()*r}function K(r,t){return r+Math.random()*(t-r)}function nn(r){return K(-r/2,r/2)}function on(r=0,t=1){let[e,s]=[1-Math.random(),Math.random()];return Math.sqrt(-2*Math.log(e))*Math.cos(2*Lt*s)*t+r}function vs(r=123456){r=r%2147483647,Math.random=()=>(r=r*16807%2147483647,(r-1)/2147483646)}function ye(r,t=4){if(Math.abs(r)===0)return 0;if(Array.isArray(r))return r.map(s=>ye(s,t));let e=10**t;return Math.round(r*e)/e}var we=r=>(r&r-1)===0,an=r=>Math.pow(2,Math.ceil(Math.log2(r)));function tt(r,t){return(r%t+t)%t}var bt=(r,t,e)=>t+tt(r-t,e-t);function $(r,t,e){return r<t?t:r>e?e:r}var N=(r,t,e)=>t<=r&&r<=e,Bt=(r,t,e)=>r<=t?r+(t-r)*e:r-(r-t)*e;function qe(r,t,e){if(t===e)throw Error("lerpScale: lo === hi");return r=$(r,t,e),(r-t)/(e-t)}var Ve=180/Math.PI,je=Math.PI/180;function _s(r){return Nt(r*je)}function Mt(r){return Y(r*Ve)}var hn=r=>Y(90-r),cn=r=>Y(90-r);function Y(r){return tt(r,360)}function Nt(r){return tt(r,2*Lt)}function ln(r){let t=Y(r);return t>180&&(t-=360),t}function be(r){let t=r*Ve;return Y(90-t)}function un(r){return Y(90-r)*je}function dn(r){return-Mt(r)}function fn(r){return-_s(r)}function As(r,t){return Y(r)===Y(t)}function pn(r,t){return Nt(r)===Nt(t)}var mn=As;function Ps(r,t){let e=Nt(r-t);return e>Lt&&(e=e-2*Lt),e}function Es(r,t){let e=Y(r-t);return e>180&&(e=e-360),e}function He(r,t){return-Es(r,t)}function et(r,t,e,s){return Math.atan2(s-t,e-r)}function gn(r,t,e,s){return be(et(r,t,e,s))}function xn(r,t,e,s){return Mt(et(r,t,e,s))}function Ge(r,t,e,s,i,n,a){if($t(n,a,r,t)>e*e)return!1;let o=et(n,a,r,t);return s/2>=Math.abs(Ps(i,o))}var $t=(r,t,e,s)=>(r-e)**2+(t-s)**2,ft=(r,t,e,s)=>Math.sqrt($t(r,t,e,s)),ks=(r,t,e,s,i,n)=>(r-s)**2+(t-i)**2+(e-n)**2,pt=(r,t,e,s,i,n)=>Math.sqrt(ks(r,t,e,s,i,n));async function yn(r,t=500,e=!0){if(console.log("runModel: model",r),e&&vs(),D(r)&&(r=(await import(r)).default),ze(r)&&(r=new r),await r.startup(),r.setup(),me())await zs(()=>{r.step()},t);else for(let s=0;s<t;s++)r.step();return r}function wn(r){console.log("classHasStartup?",r);let e=r.toString().split(` `);return e=e.filter(s=>!/^ *\/\//.test(s)),e=e.filter(s=>/startup\(\)/.test(s)),e.length>0}function Os(r,t=0,e=!0){let s=e,i=["rectCache"];return JSON.stringify(r,(a,o)=>i.includes(a)?void 0:Array.isArray(o)&&o.length>0&&Number.isInteger(o[0].id)&&!s?o.map(c=>c.id):(s=!1,o),t)}function bn(r){let t={ticks:r.ticks,model:Object.keys(r),patches:r.patches.length,patch:r.patches.oneOf(),turtles:r.turtles.length,turtle:r.turtles.oneOf(),links:r.links.length,link:r.links.oneOf()},e=Os(t);return JSON.parse(e)}var Je=r=>r,Mn=()=>{},Wt=r=>t=>t[r];function Qe(r,t){if(r.length!==t.length)return!1;for(let e=0;e<r.length;e++)if(r[e]!==t[e])return!1;return!0}function W(r,t){let e=r.indexOf(t);if(e!==-1)r.splice(e,1);else throw Error(`removeArrayItem: ${t} not in array`);return r}var Ke=r=>r.map(t=>`${t}`).join(",");function C(r,t){if(r.slice)for(let e=0,s=r.length;e<s;e++)t(r[e],e,r);else Object.keys(r).forEach(e=>t(r[e],e,r))}function R(r,t,e=[]){for(let s=0;s<r;s++)t(s,e);return e}function Ts(r,t,e){for(let s=0;s<r;s+=t)e(s)}function Sn(r){return R(r,(t,e)=>{e[t]=t})}function zn(r,t){return r.reduce((e,s)=>(t.test(s)&&e.push(s),e),[])}function tr(r,t){let e=r.constructor;if(e===Array)return r.concat(At(t,Array));let s=new e(r.length+t.length);return s.set(r),s.set(t,r.length),s}function Cn(r,t=2,e=!0){let s=JSON.stringify(r,null,t);return e&&(s=s.replace(/"([^"]+)":/gm,"$1:")),s}function vn(r){return Object.keys(r).length}var _n=(r,t)=>JSON.stringify(r)===JSON.stringify(t);function mt(r){return r[B(r.length)]}function er(r,t){if(r.length<2)throw Error("otherOneOf: array.length < 2");let e;do e=mt(r);while(t===e);return e}var Is=r=>mt(Object.keys(r)),rr=r=>r[Is(r)];function An(r,t=!0){return r.sort((e,s)=>t?e-s:s-e)}function sr(r,t,e=!0){typeof t=="string"&&(t=Wt(t));let s=(i,n)=>t(i)-t(n);return r.sort((i,n)=>e?s(i,n):-s(i,n))}function ir(r){for(let t=r.length-1;t>0;t--){let e=B(t);[r[e],r[t]]=[r[t],r[e]]}return r}function Pn(r,t){return Array.from(new Set(r.concat(t)))}function En(r,t){let e=new Set(t);return r.filter(s=>e.has(s))}function kn(r,t){let e=new Set(t);return r.filter(s=>!e.has(s))}function Me(r,t,e){if(e<=1)throw Error("floatRamp: numItems must be > 1");let s=[];for(let i=0;i<e;i++)s.push(r+(t-r)*(i/(e-1)));return s}function Ut(r,t,e=t-r+1){return Me(r,t,e).map(s=>Math.round(s))}function On(r,t){switch(typeof t=="string"&&(t=t.split(".")),t.length){case 1:return r[t[0]];case 2:return r[t[0]][t[1]];case 3:return r[t[0]][t[1]][t[2]];case 4:return r[t[0]][t[1]][t[2]][t[3]];default:return t.reduce((e,s)=>e[s],r)}}var Tn=r=>r[r.length-1],Rs=r=>r.reduce((t,e)=>Math.max(t,e)),Ds=r=>r.reduce((t,e)=>Math.min(t,e)),In=r=>[Ds(r),Rs(r)],Rn=(r,t,e=s=>s)=>{if(r.length!==t.length)return console.log("lengths differ",r.length,t.length);let s=[];for(let i=0;i<r.length;i++)r[i]!==t[i]&&s.push([e(i),r[i],t[i]]);return s};function Dn(r,t,e){if(r.length!==t*e)throw Error("arrayToMatrix: length !== width * height");let s=[];for(let i=0;i<e;i++){let n=r.slice(i*t,(i+1)*t);s.push(n)}return s}var Xn=r=>r.flat();function St(r){return vt(r)?Object.values(r).every(t=>_t(t)):!1}function Fn(r,t){let e=r.length,s=Object.keys(t),i={};return s.forEach(n=>{i[n]=new t[n](e)}),C(r,(n,a)=>{s.forEach(o=>i[o][a]=n[o])}),i}function Xs(r,t,e){let s={};return e.forEach(i=>{s[i]=r[i][t]}),s}function zt(r,t=Object.keys(r)){let e=r[t[0]].length,s=new Array(e);return C(s,(i,n)=>{s[n]=Xs(r,n,t)}),s}function Yn(r){let t=[];return C(r,e=>C(e,s=>t.push(s.buffer))),t}var O=r=>({}).toString.call(r).match(/\s(\w+)/)[1].toLowerCase(),Ct=(r,t)=>O(r)===t,nr=(r,t)=>t.includes(O(r)),D=r=>Ct(r,"string"),vt=r=>Ct(r,"object"),Se=r=>Array.isArray(r),rt=r=>Ct(r,"number"),Fs=r=>Number.isInteger(r),ze=r=>Ct(r,"function"),Ln=r=>Ct(r,"image"),Ce=r=>nr(r,["htmlcanvaselement","offscreencanvas"]),Zt=r=>nr(r,["image","htmlimageelement","htmlcanvaselement","offscreencanvas","imagebitmap"]),_t=r=>O(r.buffer)==="arraybuffer",Nn=r=>/^uint.*array$/.test(O(r)),Bn=r=>/^int.*array$/.test(O(r)),$n=r=>/^float.*array$/.test(O(r)),Ys=r=>Se(r)||_t(r),Wn=r=>Ys(r)&&[3,4].includes(r.length)&&r.every(t=>Fs(t)&&N(t,0,255)||rt(t)&&N(t,0,1));function Un(){let r=new Uint32Array([16909060]);return new Uint8ClampedArray(r.buffer)[0]===4}function At(r,t){return r.constructor===t?r:t.from(r)}function Ls(r){return O(r)==="object"&&r.width&&r.height&&r.data}function ve(r,t="download.png",e=null){t.endsWith(".png")||t.endsWith(".jpeg")||(t=t+".png");let s=t.endsWith(".png")?"image/png":"image/jpeg",i=O(r)==="string"?r:r.toDataURL(s,e),n=document.createElement("a");n.download=t,n.href=i,n.click()}function or(r,t="download",e=!0){Ls(r)&&!Array.isArray(r.data)&&(r.data=Array.from(r.data)),_t(r)&&(r=Array.from(r)),(vt(r)||Array.isArray(r))&&(r=e?JSON.stringify(r,null,2):JSON.stringify(r));let s=O(r)==="blob"?r:new Blob([r]),i=URL.createObjectURL(s),n=document.createElement("a");n.download=t,n.href=i,n.click(),URL.revokeObjectURL(i)}function Zn(r,t="download.json"){or(r,t)}function qn(r,t="json.js"){let s=`const json = ${JSON.stringify(r,null,2)} export default json`;or(s,t)}async function gt(r,t=!0){if(me()&&t||ge())return new Promise((e,s)=>{let i=new Image;i.crossOrigin="Anonymous",i.onload=()=>e(i),i.onerror=()=>s(`Could not load image ${r}`),i.src=r});if(Ue()||!t){let e=await fetch(r).then(s=>s.blob());return createImageBitmap(e)}}async function Vn(r){return new Promise((t,e)=>{let s=new Image;s.crossOrigin="Anonymous",s.onload=()=>t(s),s.onerror=()=>e(`Could not load image ${r}`),s.src=r})}async function jn(r){let t=await xe(r,"blob");return createImageBitmap(t)}function Pt(r,t,e=!0){if(me()&&e){let s=document.createElement("canvas");return s.width=r,s.height=t,s}else{if(ge())return globalThis.createCanvas(r,t);if(Ue()||!e)return new OffscreenCanvas(r,t)}}function A(r,t,e=!0,s={}){let i=Pt(r,t,e),n=i.getContext("2d",s);if(ge()){let a={canvas:i};return Object.setPrototypeOf(a,n),a}else return n}function Ns(r,t=!0){let e=A(r.width,r.height,t);return e.drawImage(r,0,0),e.canvas}function ar(r,t,e){let s=Ns(r.canvas);r.canvas.width=t,r.canvas.height=e,r.drawImage(s,0,0)}function _e(r,t,e){(r.width!==t||r.height!=e)&&(r.width=t,r.height=e)}function Et(r){r.save(),r.resetTransform()}function kt(r,t,e="center",s="middle"){Object.assign(r,{font:t,textAlign:e,textBaseline:s})}var pe;function hr(r,t,e="center",s="middle"){pe||(pe=A(0,0)),kt(pe,t,e,s);let i=pe.measureText(r);return i.height=i.actualBoundingBoxAscent+i.actualBoundingBoxDescent,i}function cr(r,t,e,s,i,n=!0){n&&Et(r),r.fillStyle=i.css||i,r.fillText(t,e,s),n&&r.restore()}function xt(r){return r.getImageData(0,0,r.canvas.width,r.canvas.height)}function lr(r){let t=xt(r).data,e=[];return Ts(t.length,4,s=>e.push(t.subarray(s,s+4))),e}function Hn(r){let t=xt(r);return new Uint32Array(t.data.buffer)}function qt(r,t=void 0){let{width:e,height:s}=r.canvas;Et(r),!t||t==="transparent"?r.clearRect(0,0,e,s):(t=t.css||t,r.fillStyle=t,r.fillRect(0,0,e,s)),r.restore()}function Ot(r){let{width:t,height:e}=r,s=A(t,e);return st(s,r),s}function Gn(r){return Ot(r).canvas}function st(r,t){Et(r),r.drawImage(t,0,0,r.canvas.width,r.canvas.height),r.restore()}function Jn(r,t){_e(r.canvas,t.width,t.height),st(r,t)}function Qn(r){Object.assign(window,r),console.log("toWindow:",Object.keys(r).join(", "))}function Kn(r=window.model){let{patches:t,turtles:e,links:s}=r;Object.assign(window,{ps:t,ts:e,ls:s}),window.p=t.length>0?t.oneOf():{},window.t=e.length>0?e.oneOf():{},window.l=s.length>0?s.oneOf():{},console.log("debug: ps, ts, ls, p, t, l dumped to window")}function to(r){let t=document.createElement("link");t.setAttribute("rel","stylesheet"),t.setAttribute("href",r),document.head.appendChild(t)}async function eo(r){r.startsWith("/")&&(console.log("fetchCssStyle relative url",r),r=import.meta.resolve(r),console.log(" absolute url",r));let t=await fetch(r);if(!t.ok)throw Error(`fetchCssStyle: Not found: ${r}`);let e=await t.text();return Bs(e),e}function Bs(r){let t=document.createElement("style");t.innerHTML=r,document.head.appendChild(t)}function $s(){return window.location.search.substr(1)}function Ws(r=$s()){let t={},e=new URLSearchParams(r);for(let s of e.entries()){let[i,n]=s;(n.match(/^[0-9.]+$/)||n.match(/^[0-9.]+e[0-9]+$/))&&(n=Number(n)),["true","t",""].includes(n)&&(n=!0),["false","f"].includes(n)&&(n=!1),t[i]=n}return t}function ro(r){return Object.assign(r,Ws())}function so(r,t=document.body){typeof r=="object"&&(r=JSON.stringify(r,null,2)),r="<pre>"+r+"</pre>",typeof t=="string"&&(t=document.getElementById(t)),t.style.fontFamily="monospace",t.innerHTML+=r}function io(r,t){let e=r.getBoundingClientRect();return[t.clientX-e.left,t.clientY-e.top]}var Zs={};ut(Zs,{decode:()=>co,encode:()=>ho,stegMsgSize:()=>ur});async function Us(r){let t=O(r);switch(t){case"string":r=await gt(r);case"htmlimageelement":return Ot(r);case"htmlcanvaselement":case"offscreencanvas":return r.getContext("2d");case"canvasrenderingcontext2d":return r;default:throw Error("toContext: bad img type: "+t)}}function no(r){let t=O(r);switch(t){case"number":r=String.fromCharCode(r);case"string":return new TextEncoder().encode(r);case"uint8array":case"uint8clampedarray":return r;default:throw Error("toUint8Array: bad msg type: "+t)}}function oo(r){return[r>>T[0].shift,r>>T[1].shift&T[1].msgMask,r&T[2].msgMask]}var T=[{shift:5,msgMask:7,dataMask:248},{shift:3,msgMask:3,dataMask:252},{shift:0,msgMask:7,dataMask:248}];function ao(r,t,e){let s=t*e;if(s<r.length)throw Error(`encode: image size < msg.length: ${s} ${r.length}`)}function ur(r){for(let t=3;t<r.length;t=t+4)if(r[t]===254)return(t-3)/4;throw Error(`decode: no message terminator in image data, length = ${r.length}`)}async function ho(r,t){let e=await Us(r),{width:s,height:i}=e.canvas;ao(t,s,i);let n=no(t);console.log("msg buffer",n);let a=e.getImageData(0,0,s,i),o=a.data;console.log("imgageData.data",o);let h;return n.forEach((c,l)=>{let[u,d,f]=oo(c);h=l*4,o[h]=(o[h++]&T[0].dataMask)+u,o[h]=(o[h++]&T[1].dataMask)+d,o[h]=(o[h++]&T[2].dataMask)+f,o[h]=255}),o[h+4]=254,console.log("encoded imgageData.data",o),e.putImageData(a,0,0),console.log("msg length",t.length),console.log("encode: embedded msg size",ur(o)),e}async function co(r,t=!1){let e=await Us(r),{width:s,height:i}=e.canvas,n=e.getImageData(0,0,s,i).data,a=ur(n);console.log("decode: embedded msg size",a);let o=new Uint8Array(a);return o.forEach((h,c)=>{let l=c*4,u=(T[0].msgMask&n[l++])<<T[0].shift,d=(T[1].msgMask&n[l++])<<T[1].shift,f=(T[2].msgMask&n[l++])<<T[2].shift;o[c]=u+d+f}),console.log("decode msgArray",o),t?o:new TextDecoder().decode(o)}var ai={};ut(ai,{bbox:()=>Vt,bboxPolygon:()=>Oo,bearingToAzimuth:()=>xo,booleanPointInPolygon:()=>Fo,collectionOf:()=>Do,containsNumber:()=>ni,convertArea:()=>bo,convertLength:()=>wo,coordAll:()=>Co,coordEach:()=>Tt,coordReduce:()=>Mo,feature:()=>L,featureCollection:()=>Ee,featureEach:()=>ei,featureOf:()=>Ro,featureReduce:()=>zo,findPoint:()=>ko,findSegment:()=>Eo,flattenEach:()=>ke,flattenReduce:()=>_o,geojsonType:()=>Io,geomEach:()=>fr,geomReduce:()=>vo,geometry:()=>lo,geometryCollection:()=>mo,getCoord:()=>ii,getCoords:()=>To,getGeom:()=>oi,getType:()=>Xo,lengthToDegrees:()=>go,lengthToRadians:()=>dr,lineEach:()=>si,lineReduce:()=>Po,lineString:()=>Z,lineStrings:()=>po,multiLineString:()=>Hs,multiPoint:()=>Gs,multiPolygon:()=>Js,point:()=>U,points:()=>uo,polygon:()=>Pe,polygons:()=>fo,propEach:()=>ti,propReduce:()=>So,radiansToLength:()=>Qs,segmentEach:()=>ri,segmentReduce:()=>Ao});var k=63710088e-1,js={centimeters:k*100,centimetres:k*100,degrees:k/111325,feet:k*3.28084,inches:k*39.37,kilometers:k/1e3,kilometres:k/1e3,meters:k,metres:k,miles:k/1609.344,millimeters:k*1e3,millimetres:k*1e3,nauticalmiles:k/1852,radians:1,yards:k*1.0936},qs={acres:247105e-9,centimeters:1e4,centimetres:1e4,feet:10.763910417,hectares:1e-4,inches:1550.003100006,kilometers:1e-6,kilometres:1e-6,meters:1,metres:1,miles:386e-9,millimeters:1e6,millimetres:1e6,yards:1.195990046};function L(r,t,e){e===void 0&&(e={});var s={type:"Feature"};return(e.id===0||e.id)&&(s.id=e.id),e.bbox&&(s.bbox=e.bbox),s.properties=t||{},s.geometry=r,s}function lo(r,t,e){switch(r){case"Point":return U(t).geometry;case"LineString":return Z(t).geometry;case"Polygon":return Pe(t).geometry;case"MultiPoint":return Gs(t).geometry;case"MultiLineString":return Hs(t).geometry;case"MultiPolygon":return Js(t).geometry;default:throw new Error(r+" is invalid")}}function U(r,t,e){if(e===void 0&&(e={}),!r)throw new Error("coordinates is required");if(!Array.isArray(r))throw new Error("coordinates must be an Array");if(r.length<2)throw new Error("coordinates must be at least 2 numbers long");if(!Ae(r[0])||!Ae(r[1]))throw new Error("coordinates must contain numbers");var s={type:"Point",coordinates:r};return L(s,t,e)}function uo(r,t,e){return e===void 0&&(e={}),Ee(r.map(function(s){return U(s,t)}),e)}function Pe(r,t,e){e===void 0&&(e={});for(var s=0,i=r;s<i.length;s++){var n=i[s];if(n.length<4)throw new Error("Each LinearRing of a Polygon must have 4 or more Positions.");for(var a=0;a<n[n.length-1].length;a++)if(n[n.length-1][a]!==n[0][a])throw new Error("First and last Position are not equivalent.")}var o={type:"Polygon",coordinates:r};return L(o,t,e)}function fo(r,t,e){return e===void 0&&(e={}),Ee(r.map(function(s){return Pe(s,t)}),e)}function Z(r,t,e){if(e===void 0&&(e={}),r.length<2)throw new Error("coordinates must be an array of two or more positions");var s={type:"LineString",coordinates:r};return L(s,t,e)}function po(r,t,e){return e===void 0&&(e={}),Ee(r.map(function(s){return Z(s,t)}),e)}function Ee(r,t){t===void 0&&(t={});var e={type:"FeatureCollection"};return t.id&&(e.id=t.id),t.bbox&&(e.bbox=t.bbox),e.features=r,e}function Hs(r,t,e){e===void 0&&(e={});var s={type:"MultiLineString",coordinates:r};return L(s,t,e)}function Gs(r,t,e){e===void 0&&(e={});var s={type:"MultiPoint",coordinates:r};return L(s,t,e)}function Js(r,t,e){e===void 0&&(e={});var s={type:"MultiPolygon",coordinates:r};return L(s,t,e)}function mo(r,t,e){e===void 0&&(e={});var s={type:"GeometryCollection",geometries:r};return L(s,t,e)}function Qs(r,t){t===void 0&&(t="kilometers");var e=js[t];if(!e)throw new Error(t+" units is invalid");return r*e}function dr(r,t){t===void 0&&(t="kilometers");var e=js[t];if(!e)throw new Error(t+" units is invalid");return r/e}function go(r,t){return yo(dr(r,t))}function xo(r){var t=r%360;return t<0&&(t+=360),t}function yo(r){var t=r%(2*Math.PI);return t*180/Math.PI}function wo(r,t,e){if(t===void 0&&(t="kilometers"),e===void 0&&(e="kilometers"),!(r>=0))throw new Error("length must be a positive number");return Qs(dr(r,t),e)}function bo(r,t,e){if(t===void 0&&(t="meters"),e===void 0&&(e="kilometers"),!(r>=0))throw new Error("area must be a positive number");var s=qs[t];if(!s)throw new Error("invalid original units");var i=qs[e];if(!i)throw new Error("invalid final units");return r/s*i}function Ae(r){return!isNaN(r)&&r!==null&&!Array.isArray(r)}function Ks(r){return!!r&&r.constructor===Object}function Tt(r,t,e){if(r!==null)for(var s,i,n,a,o,h,c,l=0,u=0,d,f=r.type,p=f==="FeatureCollection",m=f==="Feature",g=p?r.features.length:1,x=0;x<g;x++){c=p?r.features[x].geometry:m?r.geometry:r,d=c?c.type==="GeometryCollection":!1,o=d?c.geometries.length:1;for(var w=0;w<o;w++){var b=0,y=0;if(a=d?c.geometries[w]:c,a!==null){h=a.coordinates;var M=a.type;switch(l=e&&(M==="Polygon"||M==="MultiPolygon")?1:0,M){case null:break;case"Point":if(t(h,u,x,b,y)===!1)return!1;u++,b++;break;case"LineString":case"MultiPoint":for(s=0;s<h.length;s++){if(t(h[s],u,x,b,y)===!1)return!1;u++,M==="MultiPoint"&&b++}M==="LineString"&&b++;break;case"Polygon":case"MultiLineString":for(s=0;s<h.length;s++){for(i=0;i<h[s].length-l;i++){if(t(h[s][i],u,x,b,y)===!1)return!1;u++}M==="MultiLineString"&&b++,M==="Polygon"&&y++}M==="Polygon"&&b++;break;case"MultiPolygon":for(s=0;s<h.length;s++){for(y=0,i=0;i<h[s].length;i++){for(n=0;n<h[s][i].length-l;n++){if(t(h[s][i][n],u,x,b,y)===!1)return!1;u++}y++}b++}break;case"GeometryCollection":for(s=0;s<a.geometries.length;s++)if(Tt(a.geometries[s],t,e)===!1)return!1;break;default:throw new Error("Unknown Geometry Type")}}}}}function Mo(r,t,e,s){var i=e;return Tt(r,function(n,a,o,h,c){a===0&&e===void 0?i=n:i=t(i,n,a,o,h,c)},s),i}function ti(r,t){var e;switch(r.type){case"FeatureCollection":for(e=0;e<r.features.length&&t(r.features[e].properties,e)!==!1;e++);break;case"Feature":t(r.properties,0);break}}function So(r,t,e){var s=e;return ti(r,function(i,n){n===0&&e===void 0?s=i:s=t(s,i,n)}),s}function ei(r,t){if(r.type==="Feature")t(r,0);else if(r.type==="FeatureCollection")for(var e=0;e<r.features.length&&t(r.features[e],e)!==!1;e++);}function zo(r,t,e){var s=e;return ei(r,function(i,n){n===0&&e===void 0?s=i:s=t(s,i,n)}),s}function Co(r){var t=[];return Tt(r,function(e){t.push(e)}),t}function fr(r,t){var e,s,i,n,a,o,h,c,l,u,d=0,f=r.type==="FeatureCollection",p=r.type==="Feature",m=f?r.features.length:1;for(e=0;e<m;e++){for(o=f?r.features[e].geometry:p?r.geometry:r,c=f?r.features[e].properties:p?r.properties:{},l=f?r.features[e].bbox:p?r.bbox:void 0,u=f?r.features[e].id:p?r.id:void 0,h=o?o.type==="GeometryCollection":!1,a=h?o.geometries.length:1,i=0;i<a;i++){if(n=h?o.geometries[i]:o,n===null){if(t(null,d,c,l,u)===!1)return!1;continue}switch(n.type){case"Point":case"LineString":case"MultiPoint":case"Polygon":case"MultiLineString":case"MultiPolygon":{if(t(n,d,c,l,u)===!1)return!1;break}case"GeometryCollection":{for(s=0;s<n.geometries.length;s++)if(t(n.geometries[s],d,c,l,u)===!1)return!1;break}default:throw new Error("Unknown Geometry Type")}}d++}}function vo(r,t,e){var s=e;return fr(r,function(i,n,a,o,h){n===0&&e===void 0?s=i:s=t(s,i,n,a,o,h)}),s}function ke(r,t){fr(r,function(e,s,i,n,a){var o=e===null?null:e.type;switch(o){case null:case"Point":case"LineString":case"Polygon":return t(L(e,i,{bbox:n,id:a}),s,0)===!1?!1:void 0}var h;switch(o){case"MultiPoint":h="Point";break;case"MultiLineString":h="LineString";break;case"MultiPolygon":h="Polygon";break}for(var c=0;c<e.coordinates.length;c++){var l=e.coordinates[c],u={type:h,coordinates:l};if(t(L(u,i),s,c)===!1)return!1}})}function _o(r,t,e){var s=e;return ke(r,function(i,n,a){n===0&&a===0&&e===void 0?s=i:s=t(s,i,n,a)}),s}function ri(r,t){ke(r,function(e,s,i){var n=0;if(e.geometry){var a=e.geometry.type;if(!(a==="Point"||a==="MultiPoint")){var o,h=0,c=0,l=0;if(Tt(e,function(u,d,f,p,m){if(o===void 0||s>h||p>c||m>l){o=u,h=s,c=p,l=m,n=0;return}var g=Z([o,u],e.properties);if(t(g,s,i,m,n)===!1)return!1;n++,o=u})===!1)return!1}}})}function Ao(r,t,e){var s=e,i=!1;return ri(r,function(n,a,o,h,c){i===!1&&e===void 0?s=n:s=t(s,n,a,o,h,c),i=!0}),s}function si(r,t){if(!r)throw new Error("geojson is required");ke(r,function(e,s,i){if(e.geometry!==null){var n=e.geometry.type,a=e.geometry.coordinates;switch(n){case"LineString":if(t(e,s,i,0,0)===!1)return!1;break;case"Polygon":for(var o=0;o<a.length;o++)if(t(Z(a[o],e.properties),s,i,o)===!1)return!1;break}}})}function Po(r,t,e){var s=e;return si(r,function(i,n,a,o){n===0&&e===void 0?s=i:s=t(s,i,n,a,o)}),s}function Eo(r,t){if(t=t||{},!Ks(t))throw new Error("options is invalid");var e=t.featureIndex||0,s=t.multiFeatureIndex||0,i=t.geometryIndex||0,n=t.segmentIndex||0,a=t.properties,o;switch(r.type){case"FeatureCollection":e<0&&(e=r.features.length+e),a=a||r.features[e].properties,o=r.features[e].geometry;break;case"Feature":a=a||r.properties,o=r.geometry;break;case"Point":case"MultiPoint":return null;case"LineString":case"Polygon":case"MultiLineString":case"MultiPolygon":o=r;break;default:throw new Error("geojson is invalid")}if(o===null)return null;var h=o.coordinates;switch(o.type){case"Point":case"MultiPoint":return null;case"LineString":return n<0&&(n=h.length+n-1),Z([h[n],h[n+1]],a,t);case"Polygon":return i<0&&(i=h.length+i),n<0&&(n=h[i].length+n-1),Z([h[i][n],h[i][n+1]],a,t);case"MultiLineString":return s<0&&(s=h.length+s),n<0&&(n=h[s].length+n-1),Z([h[s][n],h[s][n+1]],a,t);case"MultiPolygon":return s<0&&(s=h.length+s),i<0&&(i=h[s].length+i),n<0&&(n=h[s][i].length-n-1),Z([h[s][i][n],h[s][i][n+1]],a,t)}throw new Error("geojson is invalid")}function ko(r,t){if(t=t||{},!Ks(t))throw new Error("options is invalid");var e=t.featureIndex||0,s=t.multiFeatureIndex||0,i=t.geometryIndex||0,n=t.coordIndex||0,a=t.properties,o;switch(r.type){case"FeatureCollection":e<0&&(e=r.features.length+e),a=a||r.features[e].properties,o=r.features[e].geometry;break;case"Feature":a=a||r.properties,o=r.geometry;break;case"Point":case"MultiPoint":return null;case"LineString":case"Polygon":case"MultiLineString":case"MultiPolygon":o=r;break;default:throw new Error("geojson is invalid")}if(o===null)return null;var h=o.coordinates;switch(o.type){case"Point":return U(h,a,t);case"MultiPoint":return s<0&&(s=h.length+s),U(h[s],a,t);case"LineString":return n<0&&(n=h.length+n),U(h[n],a,t);case"Polygon":return i<0&&(i=h.length+i),n<0&&(n=h[i].length+n),U(h[i][n],a,t);case"MultiLineString":return s<0&&(s=h.length+s),n<0&&(n=h[s].length+n),U(h[s][n],a,t);case"MultiPolygon":return s<0&&(s=h.length+s),i<0&&(i=h[s].length+i),n<0&&(n=h[s][i].length-n),U(h[s][i][n],a,t)}throw new Error("geojson is invalid")}function Vt(r){var t=[1/0,1/0,-1/0,-1/0];return Tt(r,function(e){t[0]>e[0]&&(t[0]=e[0]),t[1]>e[1]&&(t[1]=e[1]),t[2]<e[0]&&(t[2]=e[0]),t[3]<e[1]&&(t[3]=e[1])}),t}Vt.default=Vt;function Oo(r,t){t===void 0&&(t={});var e=Number(r[0]),s=Number(r[1]),i=Number(r[2]),n=Number(r[3]);if(r.length===6)throw new Error("@turf/bbox-polygon does not support BBox with 6 positions");var a=[e,s],o=[e,n],h=[i,n],c=[i,s];return Pe([[a,c,h,o,a]],t.properties,{bbox:r,id:t.id})}function ii(r){if(!r)throw new Error("coord is required");if(!Array.isArray(r)){if(r.type==="Feature"&&r.geometry!==null&&r.geometry.type==="Point")return r.geometry.coordinates;if(r.type==="Point")return r.coordinates}if(Array.isArray(r)&&r.length>=2&&!Array.isArray(r[0])&&!Array.isArray(r[1]))return r;throw new Error("coord must be GeoJSON Point or an Array of numbers")}function To(r){if(Array.isArray(r))return r;if(r.type==="Feature"){if(r.geometry!==null)return r.geometry.coordinates}else if(r.coordinates)return r.coordinates;throw new Error("coords must be GeoJSON Feature, Geometry Object or an Array")}function ni(r){if(r.length>1&&Ae(r[0])&&Ae(r[1]))return!0;if(Array.isArray(r[0])&&r[0].length)return ni(r[0]);throw new Error("coordinates must only contain numbers")}function Io(r,t,e){if(!t||!e)throw new Error("type and name required");if(!r||r.type!==t)throw new Error("Invalid input to "+e+": must be a "+t+", given "+r.type)}function Ro(r,t,e){if(!r)throw new Error("No feature passed");if(!e)throw new Error(".featureOf() requires a name");if(!r||r.type!=="Feature"||!r.geometry)throw new Error("Invalid input to "+e+", Feature with geometry required");if(!r.geometry||r.geometry.type!==t)throw new Error("Invalid input to "+e+": must be a "+t+", given "+r.geometry.type)}function Do(r,t,e){if(!r)throw new Error("No featureCollection passed");if(!e)throw new Error(".collectionOf() requires a name");if(!r||r.type!=="FeatureCollection")throw new Error("Invalid input to "+e+", FeatureCollection required");for(var s=0,i=r.features;s<i.length;s++){var n=i[s];if(!n||n.type!=="Feature"||!n.geometry)throw new Error("Invalid input to "+e+", Feature with geometry required");if(!n.geometry||n.geometry.type!==t)throw new Error("Invalid input to "+e+": must be a "+t+", given "+n.geometry.type)}}function oi(r){return r.type==="Feature"?r.geometry:r}function Xo(r,t){return r.type==="FeatureCollection"?"FeatureCollection":r.type==="GeometryCollection"?"GeometryCollection":r.type==="Feature"&&r.geometry!==null?r.geometry.type:r.type}function Fo(r,t,e){if(e===void 0&&(e={}),!r)throw new Error("point is required");if(!t)throw new Error("polygon is required");var s=ii(r),i=oi(t),n=i.type,a=t.bbox,o=i.coordinates;if(a&&Yo(s,a)===!1)return!1;n==="Polygon"&&(o=[o]);for(var h=!1,c=0;c<o.length&&!h;c++)if(Vs(s,o[c][0],e.ignoreBoundary)){for(var l=!1,u=1;u<o[c].length&&!l;)Vs(s,o[c][u],!e.ignoreBoundary)&&(l=!0),u++;l||(h=!0)}return h}function Vs(r,t,e){var s=!1;t[0][0]===t[t.length-1][0]&&t[0][1]===t[t.length-1][1]&&(t=t.slice(0,t.length-1));for(var i=0,n=t.length-1;i<t.length;n=i++){var a=t[i][0],o=t[i][1],h=t[n][0],c=t[n][1],l=r[1]*(a-h)+o*(h-r[0])+c*(r[0]-a)===0&&(a-r[0])*(h-r[0])<=0&&(o-r[1])*(c-r[1])<=0;if(l)return!e;var u=o>r[1]!=c>r[1]&&r[0]<(h-a)*(r[1]-o)/(c-o)+a;u&&(s=!s)}return s}function Yo(r,t){return t[0]<=r[0]&&t[1]<=r[1]&&t[2]>=r[0]&&t[3]>=r[1]}var pr=class r extends Array{static get[Symbol.species](){return r}static fromArray(t){return Object.setPrototypeOf(t,r.prototype)}constructor(...t){super(...t)}toArray(){return Object.setPrototypeOf(this,Array.prototype),this}isEmpty(){return this.length===0}first(){return this[0]}last(){return this[this.length-1]}atIndex(t){if(this.length===0)return;let e=tt(t,this.length);return this[e]}all(t){return this.every(t)}props(t,e=r){let s=new e(this.length);for(let i=0;i<this.length;i++)s[i]=this[i][t];return s}typedSample(t){let e={};return C(t,(s,i)=>{e[i]=this.props(i,s)}),e}uniq(){return r.from(new Set(this))}forLoop(t){for(let e=0,s=this.length;e<s;e++)t(this[e],e,this);return this}ask(t){let e=this.length;for(let s=0;s<Math.min(e,this.length);s++)t(this[s],s,this);if(e!=this.length){let s=this.name||this.constructor.name,i=this.length<e?"decreasing":"increasing";dt(`AgentArray.ask array mutation: ${s}: ${i}`)}}with(t){return this.filter(t)}other(t){return this.filter(e=>e!==t)}getValues(t){let e=new r;return D(t)?this.forLoop(s=>e.push(s[t])):this.forLoop(s=>e.push(t(s))),e}count(t){return this.reduce((e,s)=>e+(t(s)?1:0),0)}sum(t){return this.reduce((e,s)=>e+(t?s[t]:s),0)}avg(t){return this.sum(t)/this.length}min(t){return this.reduce((e,s)=>Math.min(e,t?s[t]:s),1/0)}max(t){return this.reduce((e,s)=>Math.max(e,t?s[t]:s),-1/0)}extent(t){return[this.min(t),this.max(t)]}histogram(t,e=10,s=this.min(t),i=this.max(t)){let n=(i-s)/e,a=new r(e);return a.fill(0),this.ask(o=>{let h=t?o[t]:o;if(h<s||h>i)dt(`histogram bounds error: ${h}: ${s}-${i}`);else{let c=Math.floor((h-s)/n);c===e&&c--,a[c]++}}),a.parameters={key:t,bins:e,min:s,max:i,binSize:n,arraySize:this.length},a}clone(){return this.slice(0)}shuffle(){return ir(this)}sortBy(t,e=!0){return sr(this,t,e),this}remove(t,e){let s=this.agentIndex(t,e);return s!==-1?this.splice(s,1):console.log(`remove: ${t.id} not in AgentArray`),this}insert(t,e){let s=this.sortedIndex(t,e);if(this[s]===t){console.log(`insert: item ${t.id} already in AgentArray`);return}this.splice(s,0,t)}sortedIndex(t,e=Je){D(e)&&(e=Wt(e));let s=e(t),i=0,n=this.length;for(;i<n;){let a=i+n>>>1;e(this[a])<s?i=a+1:n=a}return i}agentIndex(t,e){if(!e)return this.indexOf(t);let s=this.sortedIndex(t,e);return this[s]===t?s:-1}contains(t,e){return this.agentIndex(t,e)>=0}oneOf(){return mt(this)}otherOneOf(t){return er(this,t)}otherNOf(t,e){if(this.length<t)throw Error("AgentArray: otherNOf: length < N");return this.clone().remove(e).shuffle().slice(0,t)}minOrMaxOf(t,e,s=!1){if(this.isEmpty())throw Error("min/max OneOf: empty array");typeof e=="string"&&(e=Wt(e));let i=null,n=t?1/0:-1/0;for(let a=0;a<this.length;a++){let o=this[a],h=e(o);(t&&h<n||!t&&h>n)&&([i,n]=[o,h])}return s?[i,n]:i}minOneOf(t){return this.minOrMaxOf(!0,t)}maxOneOf(t){return this.minOrMaxOf(!1,t)}minValOf(t){return this.minOrMaxOf(!0,t,!0)}maxValOf(t){return this.minOrMaxOf(!1,t,!0)}nOf(t){if(t>this.length)throw Error(`nOf: n larger than AgentArray: ${t} ${this.length}`);if(t===this.length)return this;let e=new r;for(;e.length<t;){let s=this.oneOf();s in e||e.push(s)}return e}minOrMaxNOf(t,e,s){if(e>this.length)throw Error("min/max nOf: n larger than AgentArray");let i=this.clone().sortBy(s);return t?i.slice(0,e):i.slice(i.length-e)}minNOf(t,e){return this.minOrMaxNOf(!0,t,e)}maxNOf(t,e){return this.minOrMaxNOf(!1,t,e)}},it=pr;var mr=class r extends it{constructor(t,...e){if(!t)throw Error("AgentList requires model");super(...e),this.model=t}inRect(t,e,s=e,i=!1){let n=new r(this.model),a=t.x-e,o=t.x+e,h=t.y-s,c=t.y+s;return this.ask(l=>{a<=l.x&&l.x<=o&&h<=l.y&&l.y<=c&&(i||t!==l)&&n.push(l)}),n}inRadius(t,e,s=!1){let i=new r(this.model),n=e*e,a=$t;return this.ask(o=>{a(t.x,t.y,o.x,o.y)<=n&&(s||t!==o)&&i.push(o)}),i}inCone(t,e,s,i,n=!1){i=this.model.toRads(i),s=this.model.toAngleRads(s);let a=new r(this.model);return this.ask(o=>{Ge(o.x,o.y,e,s,i,t.x,t.y)&&(n||t!==o)&&a.push(o)}),a}},X=mr;var gr=class r extends it{model;name;baseSet;AgentClass;static get[Symbol.species](){return it}constructor(t,e,s,i=null){if(s.length===0)debugger;super(),i=i||this,Object.assign(this,{model:t,name:s,baseSet:i,AgentClass:e}),this.isBaseSet()?(this.breeds={},this.ID=0):(Object.setPrototypeOf(this,Object.getPrototypeOf(i)),this.baseSet.breeds[s]=this),this.protoMixin(e)}protoMixin(t){this.agentProto=new t;let e=this.agentProto;Object.assign(e,{agentSet:this,model:this.model}),e[this.baseSet.name]=this.baseSet,e.setBreed?console.log("protoMixin: agentClass.proto already set",t):(Object.assign(e,{setBreed(s){s.setBreed(this)},getBreed(){return this.agentSet},isBreed(s){return this.agentSet===s}}),Object.defineProperty(e,"breed",{get:function(){return this.agentSet}}))}addAgent(t=void 0){return t=t||this.agentProto.newInstance(this.agentProto),this.isBreedSet()?this.baseSet.addAgent(t):t.id=this.ID++,this.push(t),t}removeAgent(t){return t.id!=-1&&(this.isBreedSet()&&this.baseSet.remove(t,"id"),this.remove(t,"id")),this}setBreed(t){if(t.breed.name!==this.name)return t.agentSet.isBreedSet()&&t.agentSet.remove(t,"id"),this.isBreedSet()&&this.insert(t,"id"),Object.setPrototypeOf(t,this.agentProto)}setDefault(t,e){return this.agentProto[t]=e,this}getDefault(t){return this.agentProto[t]}newBreed(t){return new r(this.model,this.AgentClass,t,this)}isBreedSet(){return this.baseSet!==this}isBaseSet(){return this.baseSet===this}withBreed(t){return this.filter(e=>e.agentSet===t)}create(){console.log(`AgentSet: Abstract method called: ${this}`)}clear(){for(;!this.isEmpty();)this.last().die()}ask(t){if(this.length===0)return;let e=this.last().id;for(let s=0;s<this.length&&this[s].id<=e;s++)t(this[s],s,this)}},yt=gr;var xr=class r{width;height;data;static emptyDataSet(t,e,s=Array){return new r(t,e,new s(t*e))}constructor(t,e,s){if(s.length!==t*e)throw Error(`new DataSet length: ${s.length} !== ${t} * ${e}`);Object.assign(this,{width:t,height:e,data:s})}checkXY(t,e){if(!this.inBounds(t,e))throw Error(`DataSet: x,y out of range: ${t}, ${e}`)}inBounds(t,e){return N(t,0,this.width-1)&&N(e,0,this.height-1)}dataType(){return this.data.constructor}type(){return this.constructor}toIndex(t,e){return t+e*this.width}toXY(t){return[t%this.width,Math.floor(t/this.width)]}getXY(t,e){return this.data[this.toIndex(t,e)]}setXY(t,e,s){this.data[this.toIndex(t,e)]=s}sample(t,e,s=!0){return this.checkXY(t,e),s?this.nearest(t,e):this.bilinear(t,e)}nearest(t,e){return this.getXY(Math.round(t),Math.round(e))}bilinear(t,e){let s=Math.floor(t),i=Math.floor(e),n=this.toIndex(s,i),a=this.width,o=t-s,h=e-i,c=1-o,l=1-h,u=this.data[n],d=this.data[n+1]||0,f=this.data[n+a]||0,p=this.data[n+1+a]||0;return u*c*l+d*o*l+f*c*h+p*o*h}clone(){return new r(this.width,this.height,this.data.slice(0))}emptyDataSet(t,e,s=this.dataType()){return r.emptyDataSet(t,e,s)}emptyArray(t){let e=this.type();return new e(t)}resample(t,e,s=!0,i=Array){if(t===this.width&&e===this.height)return this.clone();let n=r.emptyDataSet(t,e,i);for(let a=0;a<e;a++)for(let o=0;o<t;o++)n.setXY(o,a,this.sample(o*(this.width-1)/(t-1),a*(this.height-1)/(e-1),s));return n}scale(t,e){let s=this.min(),n=this.max()-s,o=(e-t)/n,h=t-o*s;return this.map(c=>o*c+h)}subset(t,e,s,i){if(t+s>this.width||e+i>this.height)throw console.log("subset: x+width",t+s,"this.width",this.width),console.log("subset: y+height",e+i,"this.height",this.height),Error("DataSet.subSet: params out of range");let n=this.emptyDataSet(s,i);for(let a=0;a<s;a++)for(let o=0;o<i;o++)n.setXY(a,o,this.getXY(a+t,o+e));return n}crop(t,e,s,i){if(e===void 0)var{top:t,bottom:e,left:s,right:i}=t;let n=this.width-s-i,a=this.height-t-e;return this.subset(s,t,n,a)}map(t){return new r(this.width,this.height,this.data.map(t))}col(t){let[e,s,i]=[this.width,this.height,this.data];if(t>=e)throw Error(`col: x out of range width: ${e} x: ${t}`);let n=this.emptyArray(s);for(let a=0;a<s;a++)n[a]=i[t+a*e];return n}row(t){let[e,s]=[this.width,this.height];if(t>=s)throw Error(`row: y out of range height: ${s} x: ${t}`);return this.data.slice(t*e,(t+1)*e)}convertType(t){this.data=At(this.data,t)}concatEast(t){let[e,s]=[this.width,this.height],[i,n]=[t.width,t.height];if(s!==n)throw Error(`concatEast: heights not equal ${s}, ${n}`);let a=this.emptyDataSet(e+i,s);for(let o=0;o<e;o++)for(let h=0;h<s;h++)a.setXY(o,h,this.getXY(o,h));for(let o=0;o<i;o++)for(let h=0;h<n;h++)a.setXY(o+e,h,t.getXY(o,h));return a}concatSouth(t){let[e,s,i]=[this.width,this.height,this.data];if(e!==t.width)throw Error(`concatSouth: widths not equal ${e}, ${t.width}`);let n=tr(i,t.data);return new r(e,s+t.height,n)}transformCoords(t,e,s,i,n,a){let o=(t-s)*(this.width-1)/n,h=(i-e)*(this.height-1)/a;return[o,h]}coordSample(t,e,s,i,n,a,o=!0){let[h,c]=this.transformCoords(t,e,s,i,n,a);return this.sample(h,c,o)}neighborhood(t,e,s=[]){s.length=0;let i=t===0||t===this.width-1||e===0||e===this.height-1;for(let n=-1;n<=1;n++)for(let a=-1;a<=1;a++){let o=t+a,h=e+n;i&&(o=$(o,0,this.width-1),h=$(h,0,this.height-1)),s.push(this.data[this.toIndex(o,h)])}return s}convolve(t,e=1,s=!1){let[i,n,a,o]=s?[1,1,this.height-1,this.width-1]:[0,0,this.height,this.width],h=this.emptyDataSet(o,a),c=h.data,l=0;for(let u=n;u<a;u++)for(let d=i;d<o;d++){let f=this.neighborhood(d,u),p=0;for(let m=0;m<t.length;m++)p=p+t[m]*f[m];c[l++]=p*e}return h}dzdx(t=2,e=1/8){return this.convolve([-1,0,1,-t,0,t,-1,0,1],e)}dzdy(t=2,e=1/8){return this.convolve([1,t,1,0,0,0,-1,-t,-1],e)}laplace8(){return this.convolve([-1,-1,-1,-1,8,-1,-1,-1,-1])}laplace4(){return this.convolve([0,-1,0,-1,4,-1,0,-1,0])}blur(t=.0625){return this.convolve([1,2,1,2,4,2,1,2,1],t)}edge(){return this.convolve([1,1,1,1,-7,1,1,1,1])}slopeAndAspect(t=1,e=!0){let s=this.dzdx(),i=this.dzdy(),[n,a]=[[],[]],[o,h]=[s.height,s.width];for(let c=0;c<o;c++)for(let l=0;l<h;l++){let[u,d]=[s.getXY(l,c),i.getXY(l,c)];a.push(Math.atan(ft(0,0,u,d))/t);let f=Math.atan2(-d,-u);e&&f<0&&(f+=2*Math.PI),n.push(f)}return a=new r(h,o,a),n=new r(h,o,n),{slope:a,aspect:n,dzdx:s,dzdy:i}}max(){return this.data.reduce((t,e)=>Math.max(t,e))}min(){return this.data.reduce((t,e)=>Math.min(t,e))}extent(){return[this.min(),this.max()]}sum(){return this.data.reduce((t,e)=>t+e)}normalize(t=0,e=1,s=!1){let[i,n]=this.extent(),a=1/(n-i),o=this.data.map(h=>Bt(t,e,a*(h-i)));return s&&(o=o.map(h=>Math.round(h))),new r(this.width,this.height,o)}equals(t){return this.width===t.width&&this.height===t.height&&Qe(this.data,t.data)}},q=xr;var yr=class r{static defaults={width:1,hidden:!1,agentSet:null,model:null,name:null};static variables={id:null,theta:0,x:0,y:0};constructor(){Object.assign(this,r.defaults)}newInstance(t){let e=Object.create(t);return Object.assign(e,r.variables),e}init(t,e){this.end0=t,this.end1=e,t.links.push(this),e.links.push(this)}die(){this.id!==-1&&(this.agentSet.removeAgent(this),W(this.end0.links,this),W(this.end1.links,this),this.id=-1)}isDead(){return this.id===-1}bothEnds(){return it.fromArray([this.end0,this.end1])}length(){return this.end0.distance(this.end1)}get heading(){let{x0:t,x1:e,y0:s,y1:i}=this,n=Math.atan2(i-s,e-t);return this.model.fromRads(n)}otherEnd(t){if(t===this.end0)return this.end1;if(t===this.end1)return this.end0;throw Error(`Link.otherEnd: turtle not a link turtle: ${t}`)}distanceXY(t,e){return this.bothEnds().map(s=>s.distanceXY(t,e)).sum()-this.length()}get x0(){return this.end0.x}get y0(){return this.end0.y}get z0(){return this.end0.z?this.end0.z:0}get x1(){return this.end1.x}get y1(){return this.end1.y}get z1(){return this.end1.z?this.end1.z:0}},wr=yr;var br=class extends yt{constructor(t,e,s,i=null){super(t,e,s,i)}createOne(t,e,s=i=>{}){let i=this.addAgent();return i.init(t,e),s(i),i}create(t,e,s=i=>{}){return Array.isArray(e)||(e=[e]),e.map(i=>this.createOne(t,i,s))}},Mr=br;var Sr=class r{maxX=16;minX=-16;maxY=16;minY=-16;maxZ=16;minZ=-16;static defaultOptions(t=16,e=t,s=Math.max(t,e)){return{minX:-t,maxX:t,minY:-e,maxY:e,minZ:-s,maxZ:s}}static defaultWorld(t=16,e=t,s=t){return new r(r.defaultOptions(t,e,s))}constructor(t={}){Object.assign(this,t),this.setWorld()}setWorld(){let{minX:t,maxX:e,minY:s,maxY:i,minZ:n,maxZ:a}=this;C({minX:t,maxX:e,minY:s,maxY:i,minZ:n,maxZ:a},(o,h)=>{if(!Number.isInteger(o))throw Error(`World: ${h}:${o} must be an integer`)}),this.numX=this.width=e-t+1,this.numY=this.height=i-s+1,this.numZ=this.depth=a-n+1,this.minXcor=t-.5,this.maxXcor=e+.5,this.minYcor=s-.5,this.maxYcor=i+.5,this.minZcor=n-.5,this.maxZcor=a+.5,this.centerX=(t+e)/2,this.centerY=(s+i)/2,this.centerZ=(n+a)/2,this.numPatches=this.numX*this.numY}getOptions(){let{minX:t,minY:e,minZ:s,maxX:i,maxY:n,maxZ:a}=this;return{minX:t,minY:e,minZ:s,maxX:i,maxY:n,maxZ:a}}randomPoint(){return[K(this.minXcor,this.maxXcor),K(this.minYcor,this.maxYcor)]}random3DPoint(){return[K(this.minXcor,this.maxXcor),K(this.minYcor,this.maxYcor),K(this.minZcor,this.maxZcor)]}randomPatchPoint(){return[Q(this.minX,this.maxX),Q(this.minY,this.maxY)]}isOnWorld(t,e,s=this.centerZ){return this.minXcor<=t&&t<=this.maxXcor&&this.minYcor<=e&&e<=this.maxYcor&&this.minZcor<=s&&s<=this.maxZcor}bboxTransform(t,e,s,i){return new zr(t,e,s,i,this)}getWorldSize(){return[this.numX,this.numY]}setEuclideanTransform(t,e){this.setCanvasSize(t.canvas,e),t.restore(),t.save(),t.scale(e,-e),t.translate(-this.minXcor,-this.maxYcor)}patchSize(t){let{numX:e,numY:s}=this,{clientWidth:i,clientHeight:n}=t,a=i/e,o=n/s;if(a!==o)throw Error(`World patchSize: x/y sizes differ ${a}, ${o}`);return a}setCanvasSize(t,e){_e(t,this.numX*e,this.numY*e)}pixelXYtoPatchXY(t,e,s){return[this.minXcor+t/s,this.maxYcor-e/s]}patchXYtoPixelXY(t,e,s){return[(t-this.minXcor)*s,(this.maxYcor-e)*s]}xyToPatchIndex(t,e){if(!this.isOnWorld(t,e))return;let{minX:s,maxX:i,maxY:n,numX:a,maxXcor:o,maxYcor:h}=this;return t=t===o?i:Math.round(t),e=e===h?n:Math.round(e),t-s+a*(n-e)}},It=Sr,zr=class{constructor(t,e,s,i,n){this.bbox=[t,e,s,i],t<s&&console.log("flipX"),i<e&&console.log("flipY"),t<s&&([t,s]=[s,t]),i<e&&([i,e]=[e,i]);let{maxXcor:a,maxYcor:o,minXcor:h,minYcor:c}=n,l=(t-s)/(a-h),u=(i-e)/(o-c),d=(t+s-l*(a+h))/2,f=(i+e-u*(o+c))/2;Object.assign(this,{mx:l,my:u,bx:d,by:f})}toWorld(t){let{mx:e,my:s,bx:i,by:n}=this,[a,o]=t,h=(a-i)/e,c=(o-n)/s;return[h,c]}toBBox(t){let{mx:e,my:s,bx:i,by:n}=this,[a,o]=t,h=e*a+i,c=s*o+n;return[h,c]}};var Te={};ut(Te,{Lbounds2bbox:()=>ia,attribution:()=>ya,bboxAspect:()=>fa,bboxBounds:()=>aa,bboxCenter:()=>Gt,bboxCoords:()=>Rt,bboxFeature:()=>Xr,bboxFromCenter:()=>Fr,bboxMetricAspect:()=>Lr,bboxMetricSize:()=>Jt,bboxSize:()=>bi,elevationTemplate:()=>Ma,fetchStreetsJson:()=>ma,getOsmURL:()=>Mi,isBBox:()=>oa,jsonToBBox:()=>ha,latlon:()=>mi,latz2y:()=>xi,latz2yFloat:()=>Tr,lonLat2meters:()=>kr,lonLatz2bbox:()=>sa,lonlatz2xy:()=>Ir,lonlatz2xyFloat:()=>yi,lonz2x:()=>gi,lonz2xFloat:()=>Or,newMexicoBBox:()=>Xe,newMexicoCenter:()=>ua,santaFeBBox:()=>ca,santaFeCenter:()=>Yr,santaFeSmallBBox:()=>la,template:()=>wa,tilesBBox:()=>na,url:()=>ba,usaBBox:()=>wi,usaCenter:()=>da,xyInBBox:()=>_r,xyz2bbox:()=>De,xyz2centerLonlat:()=>ra,xyz2lonlat:()=>Er,xz2lon:()=>Rr,yz2lat:()=>Dr});var vr={};ut(vr,{bboxFeature:()=>Bo,clone:()=>nt,flatten:()=>Oe,flattenMultiLineStrings:()=>hi,geojsonBBox:()=>Cr,getCoordinates:()=>jt,isGeojson:()=>Lo,lineStringsToLinks:()=>$o,minify:()=>No});function Lo(r){return typeof r=="object"&&r.type==="FeatureCollection"}function nt(r){return JSON.parse(JSON.stringify(r))}function No(r){return typeof r=="string"&&(r=JSON.parse(r)),JSON.stringify(r).replace(/},{/g,`}, {`)}function Bo(r,t={}){let e=Rt(r);return e.push(e[0]),{type:"Feature",geometry:{cordinates:e,type:"Polygon"},properties:t}}function hi(r,t=!0){return t&&(r=nt(r)),(r.features||r).reduce((i,n)=>{let a=n.geometry;return a.type==="LineString"?(a.coordinates.properties=n.properties,i.push(a.coordinates)):a.type==="MultiLineString"&&a.coordinates.forEach(o=>{o.properties=n.properties,i.push(o)}),i},[])}function $o(r,t,e){let s=r.world.xfm||r.world.bboxTransform(...t);e=hi(e);let i={},n=[],a=[];function o(l){let u=l.toString(),d=i[u];return d||(d=r.turtles.createOne(f=>{f.setxy(...s.toWorld(l)),f.lon=l[0],f.lat=l[1]}),i[u]=d,n.push(d),d)}function h(l,u){let d=o(l),f=o(u),p=r.links.createOne(d,f);return a.push(p),p}function c(l){l.reduce((u,d,f,p)=>{let m=h(p[f-1],d);return f===1?(u=[m],u.properties=l.properties):u.push(m),m.lineString=u,u})}return e.forEach(l=>c(l)),[n,a]}function Oe(r,t=!0){switch(t&&(r=nt(r)),r&&r.type||null){case"FeatureCollection":return r.features=r.features.reduce(function(e,s){return e.concat(Oe(s))},[]),r;case"Feature":return r.geometry?Oe(r.geometry).map(function(e){var s={type:"Feature",properties:JSON.parse(JSON.stringify(r.properties)),geometry:e};return r.id!==void 0&&(s.id=r.id),s}):[r];case"MultiPoint":return r.coordinates.map(function(e){return{type:"Point",coordinates:e}});case"MultiPolygon":return r.coordinates.map(function(e){return{type:"Polygon",coordinates:e}});case"MultiLineString":return r.coordinates.map(function(e){return{type:"LineString",coordinates:e}});case"GeometryCollection":return r.geometries.map(Oe).reduce(function(e,s){return e.concat(s)},[]);case"Point":case"Polygon":case"LineString":return[r]}}function Cr(r){var t,e;if(r.hasOwnProperty("type"))return t=jt(r),e=[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY,Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY],t.reduce(function(s,i){return[Math.min(i[0],s[0]),Math.min(i[1],s[1]),Math.max(i[0],s[2]),Math.max(i[1],s[3])]},e)}function jt(r){switch(r.type){case"Point":return[r.coordinates];case"LineString":case"MultiPoint":return r.coordinates;case"Polygon":case"MultiLineString":return r.coordinates.reduce(function(t,e){return t.concat(e)},[]);case"MultiPolygon":return r.coordinates.reduce(function(t,e){return t.concat(e.reduce(function(s,i){return s.concat(i)},[]))},[]);case"Fea