mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-30 03:46:29 -05:00
2 lines
49 KiB
JavaScript
2 lines
49 KiB
JavaScript
|
|
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).mlcontour=t()}(this,(function(){"use strict";var e,t,r;function i(i,n){if(e)if(t){var s="var sharedChunk = {}; ("+e+")(sharedChunk); ("+t+")(sharedChunk);",o={};e(o),r=n(o),"undefined"!=typeof window&&(r.workerUrl=window.URL.createObjectURL(new Blob([s],{type:"text/javascript"})))}else t=n;else e=n}return i(0,(function(e){class t{constructor(e,t){this.start=e,this.end=t,this.points=[],this.append=this.append.bind(this),this.prepend=this.prepend.bind(this)}append(e,t){this.points.push(Math.round(e),Math.round(t))}prepend(e,t){this.points.splice(0,0,Math.round(e),Math.round(t))}lineString(){return this.toArray()}isEmpty(){return this.points.length<2}appendFragment(e){this.points.push(...e.points),this.end=e.end}toArray(){return this.points}}const r=[[],[[[1,2],[0,1]]],[[[2,1],[1,2]]],[[[2,1],[0,1]]],[[[1,0],[2,1]]],[[[1,2],[0,1]],[[1,0],[2,1]]],[[[1,0],[1,2]]],[[[1,0],[0,1]]],[[[0,1],[1,0]]],[[[1,2],[1,0]]],[[[0,1],[1,0]],[[2,1],[1,2]]],[[[2,1],[1,0]]],[[[0,1],[2,1]]],[[[1,2],[2,1]]],[[[0,1],[1,2]]],[]];function i(e,t,r,i){return(t=2*t+i[0])+(r=2*r+i[1])*(e+1)*2}function n(e,t,r){return(t-e)/(r-e)}function s(e,s,o=4096,a=1){if(!e)return{};const l=o/(s.width-1);let h,c,d,u,f,p;const g={},m=new Map,w=new Map;function y(e,t,r){0===e[0]?r(l*(p-1),l*(f-n(d,t,h))):2===e[0]?r(l*p,l*(f-n(u,t,c))):0===e[1]?r(l*(p-n(c,t,h)),l*(f-1)):r(l*(p-n(u,t,d)),l*f)}for(f=1-a;f<s.height+a;f++){c=s.get(0,f-1),u=s.get(0,f);let n=Math.min(c,u),o=Math.max(c,u);for(p=1-a;p<s.width+a;p++){h=c,d=u,c=s.get(p,f-1),u=s.get(p,f);const a=n,l=o;if(n=Math.min(c,u),o=Math.max(c,u),isNaN(h)||isNaN(c)||isNaN(u)||isNaN(d))continue;const v=Math.min(a,n),b=Math.max(l,o),x=Math.ceil(v/e)*e,T=Math.floor(b/e)*e;for(let n=x;n<=T;n+=e){const e=h>n,o=c>n,a=d>n,l=u>n;for(const h of r[(e?8:0)|(o?4:0)|(l?2:0)|(a?1:0)]){let e=m.get(n);e||m.set(n,e=new Map);let r=w.get(n);r||w.set(n,r=new Map);const o=h[0],a=h[1],l=i(s.width,p,f,o),c=i(s.width,p,f,a);let d,u;if(d=r.get(l))if(r.delete(l),u=e.get(c))if(e.delete(c),d===u){if(y(a,n,d.append),!d.isEmpty()){let e=g[n];e||(g[n]=e=[]),e.push(d.lineString())}}else d.appendFragment(u),r.set(d.end=u.end,d);else y(a,n,d.append),r.set(d.end=c,d);else if(d=e.get(c))e.delete(c),y(o,n,d.prepend),e.set(d.start=l,d);else{const i=new t(l,c);y(o,n,i.append),y(a,n,i.append),e.set(l,i),r.set(c,i)}}}}}for(const[e,t]of m.entries()){let r=null;for(const i of t.values())i.isEmpty()||(null==r&&(r=g[e]||(g[e]=[])),r.push(i.lineString()))}return g}function o(e,t){var r={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(r[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(i=Object.getOwnPropertySymbols(e);n<i.length;n++)t.indexOf(i[n])<0&&Object.prototype.propertyIsEnumerable.call(e,i[n])&&(r[i[n]]=e[i[n]])}return r}function a(e,t,r,i){return new(r||(r=Promise))((function(n,s){function o(e){try{l(i.next(e))}catch(e){s(e)}}function a(e){try{l(i.throw(e))}catch(e){s(e)}}function l(e){var t;e.done?n(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(o,a)}l((i=i.apply(e,t||[])).next())}))}function l(e){const t=Object.entries(e);return t.sort((([e],[t])=>e<t?-1:e>t?1:0)),t}function h(e){return l(e).map((([e,t])=>[e,..."number"==typeof t?[t]:t].join("*"))).join("~")}function c(e){return l(e).map((([e,t])=>`${encodeURIComponent(e)}=${encodeURIComponent(t)}`)).join(",")}"function"==typeof SuppressedError&&SuppressedError;let d=null;function u(){return null==d&&(d="undefined"!=typeof OffscreenCanvas&&new OffscreenCanvas(1,1).getContext("2d")&&"function"==typeof createImageBitmap),d||!1}let f=null;function p(e,t,r){let i=()=>{};const n=setTimeout((()=>{i(new Error("timed out")),null==r||r.abort()}),e);g(r,(()=>{i(new Error("aborted")),clearTimeout(n)}));const s=new Promise(((e,t)=>{i=t}));return Promise.race([s,t.finally((()=>clearTimeout(n)))])}function g(e,t){t&&(null==e||e.signal.addEventListener("a
|