/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports"],(function(t){"use strict";const e=16,n=8,o=4,r=2,h=1,c=new Float64Array(2),a=new Float64Array(2),s=-90,l=90,u=-180,f=180,i="0123456789bcdefghjkmnpqrstuvwxyz";function M(t){return t<=57?t-48:t<=104?t-88:t<=107?t-89:t<=110?t-90:t-91}function g(t){return i[t]}function d(t){return(t[0]+t[1])/2}function G(t,e,n){return t[0]=e,t[1]=n,t}function b(t,e){const n=d(t),o=e,r=!e;t[0]=r*t[0]+o*n,t[1]=r*n+o*t[1]}function X(t,e){const n=e>d(t);return b(t,n),n}function Y(t,i){const g=G(c,s,l),X=G(a,u,f);for(let c=0;c<i.length;c++){const t=M(i.charCodeAt(c));c%2==0?(b(X,!!(e&t)),b(X,!!(o&t)),b(X,!!(h&t)),b(g,!!(n&t)),b(g,!!(r&t))):(b(g,!!(e&t)),b(g,!!(o&t)),b(g,!!(h&t)),b(X,!!(n&t)),b(X,!!(r&t)))}return t[0]=d(g),t[1]=d(X),t}function m(t,e){let n=0,o=0,r=30,h=30;for(let c=0;c<e.length;c++){const t=M(e.charCodeAt(c)),a=c%2==0;r-=a?3:2,h-=a?2:3,n|=x(t,a)<<r,o|=k(t,a)<<h}return{geohashX:n,geohashY:o}}function p(t,e){let n=-90,o=90,r=-180,h=180;for(let c=0;c<e;c++){const e=Math.ceil((c+1)/2),a=Math.floor((c+1)/2),s=1-c%2,l=30-(3*e+2*a),u=30-(2*e+3*a),f=3*s+2*(1-s),i=2*s+3*(1-s),M=3*s+7*(1-s)<<u,g=(7*s+3*(1-s)<<l&t.geohashX)>>l,d=(M&t.geohashY)>>u;for(let t=f-1;t>=0;t--){const e=(r+h)/2,n=g&1<<t?1:0;r=(1-n)*r+n*e,h=(1-n)*e+n*h}for(let t=i-1;t>=0;t--){const e=(n+o)/2,r=d&1<<t?1:0;n=(1-r)*n+r*e,o=(1-r)*e+r*o}}return[r,n,h,o]}function A(t,e,n,o){o%2&&(o+=1);let r=0,h=0,c=-90,a=90,s=-180,l=180;for(let u=0;u<o/2;u++){for(let t=0;t<5;t++){const e=(s+l)/2,o=n>e?1:0;r|=o<<29-(t+5*u),s=(1-o)*s+o*e,l=(1-o)*e+o*l}for(let t=0;t<5;t++){const n=(c+a)/2,o=e>n?1:0;h|=o<<29-(t+5*u),c=(1-o)*c+o*n,a=(1-o)*n+o*a}}t.geohashX=r,t.geohashY=h}function v(t,e,n,o,r){r%2&&(r+=1);let h=0,c=0,a=-90,s=90,l=-180,u=180;for(let f=0;f<r/2;f++){for(let t=0;t<5;t++){const e=(l+u)/2,n=o>e?1:0;h|=n<<29-(t+5*f),l=(1-n)*l+n*e,u=(1-n)*e+n*u}for(let t=0;t<5;t++){const e=(a+s)/2,o=n>e?1:0;c|=o<<29-(t+5*f),a=(1-o)*a+o*e,s=(1-o)*e+o*s}}t[2*e]=h,t[2*e+1]=c}function y(t,e,n){let o="";const r=G(c,-90,90),h=G(a,-180,180);for(let c=0;c<n;c++){let n=0;!(c%2)?(n|=X(h,e)<<4,n|=X(r,t)<<3,n|=X(h,e)<<2,n|=X(r,t)<<1,n|=X(h,e)<<0):(n|=X(r,t)<<4,n|=X(h,e)<<3,n|=X(r,t)<<2,n|=X(h,e)<<1,n|=X(r,t)<<0),o+=g(n)}return o}function B(t){const e=Math.floor(5*t/2);return(l-s)/2**e}function C(t){const e=Math.ceil(5*t/2);return(f-u)/2**e}function w(t,e,n){return n?t&h|(e&h)<<1|(t&r)<<1|(e&r)<<2|(t&o)<<2:e&h|(t&h)<<1|(e&r)<<1|(t&r)<<2|(e&o)<<2}function x(t,c){return c?h&t|(o&t)>>1|(e&t)>>2:(r&t)>>1|(n&t)>>2}function k(t,c){return c?(r&t)>>1|(n&t)>>2:h&t|(o&t)>>1|(e&t)>>2}function P(t,c,a){const s=!((t.length-1)%2),l=t.substring(0,t.length-1),u=M(t.charCodeAt(t.length-1));let f=0,i=0,d=0,G=0;s?(f=8,i=4,d=h&u|(o&u)>>1|(e&u)>>2,G=(r&u)>>1|(n&u)>>2):(f=4,i=8,G=h&u|(o&u)>>1|(e&u)>>2,d=(r&u)>>1|(n&u)>>2);const b=d+c,X=G+a,Y=Math.floor(b/f),m=Math.floor(X/i),p=g(w(b-Y*f,X-m*i,s));return t.length>1&&(Y||m)?P(l,Y,m)+p:l+p}function j(t,e,n,o,r){const h=Math.abs(n-t),c=Math.abs(o-e),a=B(r),s=C(r),l=Math.ceil(c/s),u=Math.ceil(h/a),f=y(t,e,r),i=new Array;for(let M=0;M<l;M++)for(let t=0;t<u;t++)i.push(P(f,M,t));return i}function D(t,e,n,o,r,h){const c=Math.abs(n-t),a=Math.abs(o-e),s=B(r),l=C(r),u=Math.ceil(a/l),f=Math.ceil(c/s),i=y(t,e,r);for(let M=0;M<u;M++)for(let r=0;r<f;r++){const c=P(i,M,r),[a,u]=Y([0,0],c),f=a-s/2,g=u-l/2,d=a+s/2,G=u+l/2,b=s*l,X=Math.max(t,f),m=Math.max(e,g),p=Math.min(n,d)-X,A=Math.min(o,G)-m;h(c,Math.abs(p*A)/b)}}t.convertGeohash32ToXY=m,t.decodeBase32Char=M,t.decodeGeohash=Y,t.decodeGeohashXY=p,t.encodeBase32Char=g,t.encodeGeohash=y,t.forEachIntersectingGeohash=D,t.getIntersectingGeohashes=j,t.getRelativeGeohash=P,t.latDistPerGeohash=B,t.lonDistPerGeohash=C,t.setGeohashBuf=v,t.setGeohashXY=A,t.unpackXBits=x,t.unpackYBits=k,Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
