mirror of
https://github.com/thepaperpilot/Advent-Incremental.git
synced 2024-11-25 18:00:25 +00:00
1 line
7 KiB
JavaScript
1 line
7 KiB
JavaScript
var ee=typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:{};function ne(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function re(e){if(e.__esModule)return e;var r=Object.defineProperty({},"__esModule",{value:!0});return Object.keys(e).forEach(function(n){var t=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(r,n,t.get?t:{enumerable:!0,get:function(){return e[n]}})}),r}var C={exports:{}};C.exports=k;C.exports.default=k;function k(e,r,n){n=n||2;var t=r&&r.length,x=t?r[0]*n:e.length,u=B(e,0,x,n,!0),f=[];if(!u||u.next===u.prev)return f;var i,v,o,c,p,l,Z;if(t&&(u=Q(e,r,u,n)),e.length>80*n){i=o=e[0],v=c=e[1];for(var h=n;h<x;h+=n)p=e[h],l=e[h+1],p<i&&(i=p),l<v&&(v=l),p>o&&(o=p),l>c&&(c=l);Z=Math.max(o-i,c-v),Z=Z!==0?32767/Z:0}return L(u,f,n,i,v,Z,0),f}function B(e,r,n,t,x){var u,f;if(x===j(e,r,n,t)>0)for(u=r;u<n;u+=t)f=$(u,e[u],e[u+1],f);else for(u=n-t;u>=r;u-=t)f=$(u,e[u],e[u+1],f);return f&&z(f,f.next)&&(a(f),f=f.next),f}function w(e,r){if(!e)return e;r||(r=e);var n=e,t;do if(t=!1,!n.steiner&&(z(n,n.next)||g(n.prev,n,n.next)===0)){if(a(n),n=r=n.prev,n===n.next)break;t=!0}else n=n.next;while(t||n!==r);return r}function L(e,r,n,t,x,u,f){if(!!e){!f&&u&&X(e,t,x,u);for(var i=e,v,o;e.prev!==e.next;){if(v=e.prev,o=e.next,u?V(e,t,x,u):R(e)){r.push(v.i/n|0),r.push(e.i/n|0),r.push(o.i/n|0),a(e),e=o.next,i=o.next;continue}if(e=o,e===i){f?f===1?(e=J(w(e),r,n),L(e,r,n,t,x,u,2)):f===2&&K(e,r,n,t,x,u):L(w(e),r,n,t,x,u,1);break}}}}function R(e){var r=e.prev,n=e,t=e.next;if(g(r,n,t)>=0)return!1;for(var x=r.x,u=n.x,f=t.x,i=r.y,v=n.y,o=t.y,c=x<u?x<f?x:f:u<f?u:f,p=i<v?i<o?i:o:v<o?v:o,l=x>u?x>f?x:f:u>f?u:f,Z=i>v?i>o?i:o:v>o?v:o,h=t.next;h!==r;){if(h.x>=c&&h.x<=l&&h.y>=p&&h.y<=Z&&F(x,i,u,v,f,o,h.x,h.y)&&g(h.prev,h,h.next)>=0)return!1;h=h.next}return!0}function V(e,r,n,t){var x=e.prev,u=e,f=e.next;if(g(x,u,f)>=0)return!1;for(var i=x.x,v=u.x,o=f.x,c=x.y,p=u.y,l=f.y,Z=i<v?i<o?i:o:v<o?v:o,h=c<p?c<l?c:l:p<l?p:l,M=i>v?i>o?i:o:v>o?v:o,O=c>p?c>l?c:l:p>l?p:l,D=E(Z,h,r,n,t),T=E(M,O,r,n,t),s=e.prevZ,y=e.nextZ;s&&s.z>=D&&y&&y.z<=T;){if(s.x>=Z&&s.x<=M&&s.y>=h&&s.y<=O&&s!==x&&s!==f&&F(i,c,v,p,o,l,s.x,s.y)&&g(s.prev,s,s.next)>=0||(s=s.prevZ,y.x>=Z&&y.x<=M&&y.y>=h&&y.y<=O&&y!==x&&y!==f&&F(i,c,v,p,o,l,y.x,y.y)&&g(y.prev,y,y.next)>=0))return!1;y=y.nextZ}for(;s&&s.z>=D;){if(s.x>=Z&&s.x<=M&&s.y>=h&&s.y<=O&&s!==x&&s!==f&&F(i,c,v,p,o,l,s.x,s.y)&&g(s.prev,s,s.next)>=0)return!1;s=s.prevZ}for(;y&&y.z<=T;){if(y.x>=Z&&y.x<=M&&y.y>=h&&y.y<=O&&y!==x&&y!==f&&F(i,c,v,p,o,l,y.x,y.y)&&g(y.prev,y,y.next)>=0)return!1;y=y.nextZ}return!0}function J(e,r,n){var t=e;do{var x=t.prev,u=t.next.next;!z(x,u)&&G(x,t,t.next,u)&&P(x,u)&&P(u,x)&&(r.push(x.i/n|0),r.push(t.i/n|0),r.push(u.i/n|0),a(t),a(t.next),t=e=u),t=t.next}while(t!==e);return w(t)}function K(e,r,n,t,x,u){var f=e;do{for(var i=f.next.next;i!==f.prev;){if(f.i!==i.i&&q(f,i)){var v=N(f,i);f=w(f,f.next),v=w(v,v.next),L(f,r,n,t,x,u,0),L(v,r,n,t,x,u,0);return}i=i.next}f=f.next}while(f!==e)}function Q(e,r,n,t){var x=[],u,f,i,v,o;for(u=0,f=r.length;u<f;u++)i=r[u]*t,v=u<f-1?r[u+1]*t:e.length,o=B(e,i,v,t,!1),o===o.next&&(o.steiner=!0),x.push(b(o));for(x.sort(U),u=0;u<x.length;u++)n=W(x[u],n);return n}function U(e,r){return e.x-r.x}function W(e,r){var n=I(e,r);if(!n)return r;var t=N(n,e);return w(t,t.next),w(n,n.next)}function I(e,r){var n=r,t=e.x,x=e.y,u=-1/0,f;do{if(x<=n.y&&x>=n.next.y&&n.next.y!==n.y){var i=n.x+(x-n.y)*(n.next.x-n.x)/(n.next.y-n.y);if(i<=t&&i>u&&(u=i,f=n.x<n.next.x?n:n.next,i===t))return f}n=n.next}while(n!==r);if(!f)return null;var v=f,o=f.x,c=f.y,p=1/0,l;n=f;do t>=n.x&&n.x>=o&&t!==n.x&&F(x<c?t:u,x,o,c,x<c?u:t,x,n.x,n.y)&&(l=Math.abs(x-n.y)/(t-n.x),P(n,e)&&(l<p||l===p&&(n.x>f.x||n.x===f.x&&S(f,n)))&&(f=n,p=l)),n=n.next;while(n!==v);return f}function S(e,r){return g(e.prev,e,r.prev)<0&&g(r.next,e,e.next)<0}function X(e,r,n,t){var x=e;do x.z===0&&(x.z=E(x.x,x.y,r,n,t)),x.prevZ=x.prev,x.nextZ=x.next,x=x.next;while(x!==e);x.prevZ.nextZ=null,x.prevZ=null,Y(x)}function Y(e){var r,n,t,x,u,f,i,v,o=1;do{for(n=e,e=null,u=null,f=0;n;){for(f++,t=n,i=0,r=0;r<o&&(i++,t=t.nextZ,!!t);r++);for(v=o;i>0||v>0&&t;)i!==0&&(v===0||!t||n.z<=t.z)?(x=n,n=n.nextZ,i--):(x=t,t=t.nextZ,v--),u?u.nextZ=x:e=x,x.prevZ=u,u=x;n=t}u.nextZ=null,o*=2}while(f>1);return e}function E(e,r,n,t,x){return e=(e-n)*x|0,r=(r-t)*x|0,e=(e|e<<8)&16711935,e=(e|e<<4)&252645135,e=(e|e<<2)&858993459,e=(e|e<<1)&1431655765,r=(r|r<<8)&16711935,r=(r|r<<4)&252645135,r=(r|r<<2)&858993459,r=(r|r<<1)&1431655765,e|r<<1}function b(e){var r=e,n=e;do(r.x<n.x||r.x===n.x&&r.y<n.y)&&(n=r),r=r.next;while(r!==e);return n}function F(e,r,n,t,x,u,f,i){return(x-f)*(r-i)>=(e-f)*(u-i)&&(e-f)*(t-i)>=(n-f)*(r-i)&&(n-f)*(u-i)>=(x-f)*(t-i)}function q(e,r){return e.next.i!==r.i&&e.prev.i!==r.i&&!m(e,r)&&(P(e,r)&&P(r,e)&&d(e,r)&&(g(e.prev,e,r.prev)||g(e,r.prev,r))||z(e,r)&&g(e.prev,e,e.next)>0&&g(r.prev,r,r.next)>0)}function g(e,r,n){return(r.y-e.y)*(n.x-r.x)-(r.x-e.x)*(n.y-r.y)}function z(e,r){return e.x===r.x&&e.y===r.y}function G(e,r,n,t){var x=_(g(e,r,n)),u=_(g(e,r,t)),f=_(g(n,t,e)),i=_(g(n,t,r));return!!(x!==u&&f!==i||x===0&&H(e,n,r)||u===0&&H(e,t,r)||f===0&&H(n,e,t)||i===0&&H(n,r,t))}function H(e,r,n){return r.x<=Math.max(e.x,n.x)&&r.x>=Math.min(e.x,n.x)&&r.y<=Math.max(e.y,n.y)&&r.y>=Math.min(e.y,n.y)}function _(e){return e>0?1:e<0?-1:0}function m(e,r){var n=e;do{if(n.i!==e.i&&n.next.i!==e.i&&n.i!==r.i&&n.next.i!==r.i&&G(n,n.next,e,r))return!0;n=n.next}while(n!==e);return!1}function P(e,r){return g(e.prev,e,e.next)<0?g(e,r,e.next)>=0&&g(e,e.prev,r)>=0:g(e,r,e.prev)<0||g(e,e.next,r)<0}function d(e,r){var n=e,t=!1,x=(e.x+r.x)/2,u=(e.y+r.y)/2;do n.y>u!=n.next.y>u&&n.next.y!==n.y&&x<(n.next.x-n.x)*(u-n.y)/(n.next.y-n.y)+n.x&&(t=!t),n=n.next;while(n!==e);return t}function N(e,r){var n=new A(e.i,e.x,e.y),t=new A(r.i,r.x,r.y),x=e.next,u=r.prev;return e.next=r,r.prev=e,n.next=x,x.prev=n,t.next=n,n.prev=t,u.next=t,t.prev=u,t}function $(e,r,n,t){var x=new A(e,r,n);return t?(x.next=t.next,x.prev=t,t.next.prev=x,t.next=x):(x.prev=x,x.next=x),x}function a(e){e.next.prev=e.prev,e.prev.next=e.next,e.prevZ&&(e.prevZ.nextZ=e.nextZ),e.nextZ&&(e.nextZ.prevZ=e.prevZ)}function A(e,r,n){this.i=e,this.x=r,this.y=n,this.prev=null,this.next=null,this.z=0,this.prevZ=null,this.nextZ=null,this.steiner=!1}k.deviation=function(e,r,n,t){var x=r&&r.length,u=x?r[0]*n:e.length,f=Math.abs(j(e,0,u,n));if(x)for(var i=0,v=r.length;i<v;i++){var o=r[i]*n,c=i<v-1?r[i+1]*n:e.length;f-=Math.abs(j(e,o,c,n))}var p=0;for(i=0;i<t.length;i+=3){var l=t[i]*n,Z=t[i+1]*n,h=t[i+2]*n;p+=Math.abs((e[l]-e[h])*(e[Z+1]-e[l+1])-(e[l]-e[Z])*(e[h+1]-e[l+1]))}return f===0&&p===0?0:Math.abs((p-f)/f)};function j(e,r,n,t){for(var x=0,u=r,f=n-t;u<n;u+=t)x+=(e[f]-e[u])*(e[u+1]+e[f+1]),f=u;return x}k.flatten=function(e){for(var r=e[0][0].length,n={vertices:[],holes:[],dimensions:r},t=0,x=0;x<e.length;x++){for(var u=0;u<e[x].length;u++)for(var f=0;f<r;f++)n.vertices.push(e[x][u][f]);x>0&&(t+=e[x-1].length,n.holes.push(t))}return n};var te=C.exports;export{ne as a,ee as c,te as e,re as g};
|