UNPKG

geos.js

Version:

an easy-to-use JavaScript wrapper over WebAssembly build of GEOS

2 lines (1 loc) 24.3 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).geos={})}(this,function(e){"use strict";const t=Symbol("ptr"),n=Symbol("finalization_registry"),r=Symbol("cleanup"),o=Symbol("prepared:ptr"),s=Symbol("prepared:finalization_registry"),i=Symbol("prepared:cleanup");class c{constructor(e,n){this[t]=e>>>=0,this.i4=e/4,this.l=n,this.l4=n/4}freeIfTmp(){this!==S.buff&&S.free(this[t])}}class a{constructor(e){this[t]=e>>>=0,this.i=e/4}get(){return S.U32[this.i]}set(e){S.U32[this.i]=e}}class l{constructor(e){this[t]=e>>>=0,this.i=e/8}get(){return S.F64[this.i]}set(e){S.F64[this.i]=e}}class u extends Error{constructor(e){super(e),this.name="GEOSError"}}class f{updateMemory(){const e=this.memory.buffer;this.U8=new Uint8Array(e),this.U32=new Uint32Array(e),this.F64=new Float64Array(e)}buffByL(e){let{buff:t}=this;if(e>t.l){const n=this.malloc(e);t=new c(n,e)}return t}buffByL4(e){let{buff:t}=this;if(e>t.l4){const n=4*e,r=this.malloc(n);t=new c(r,n)}return t}encodeString(e){const n=e.length,r=this.buffByL(n+1),o=r[t],s=this.U8.subarray(o,o+n+1);if(this.te.encodeInto(e,s).written!==n)throw new u("Unexpected string encoding result");return s[n]=0,r}decodeString(e){const t=e>>>0,n=this.U8;let r=t;for(;n[r];)r++;return this.td.decode(n.subarray(t,r))}addFunction(e,t){let n=this.functionsInTableMap.get(e);if(n)return n;n=this.freeTableIndexes.length?this.freeTableIndexes.pop():this.table.grow(1);const r=d(e,t);return this.table.set(n,r),this.functionsInTableMap.set(e,n),n}removeFunction(e){const t=this.functionsInTableMap.get(e);t&&(this.table.set(t,null),this.functionsInTableMap.delete(this.table.get(t)),this.freeTableIndexes.push(t))}constructor(e){this.td=new TextDecoder,this.te=new TextEncoder,this.functionsInTableMap=new Map,this.freeTableIndexes=[],this.t_r={},this.t_w={},this.b_r={},this.b_w={},this.b_p={},this.m_v={},this.onGEOSError=(e,t)=>{const n=this.decodeString(e),r=new u(n),o=n.indexOf(": ");throw o>0&&(r.name=`${r.name}::${n.slice(0,o)}`,r.message=n.slice(o+2)),r};const{memory:t,__indirect_function_table:n,...r}=e.exports;this.memory=t,this.updateMemory(),this.table=n,r._initialize();const o=r.GEOS_init_r();r.GEOSContext_setErrorMessageHandler_r(o,this.addFunction(this.onGEOSError,"vpp"),0);for(const e in r)e.endsWith("_r")?this[e.slice(0,-2)]=r[e].bind(null,o):this[e]=r[e];let s=r.malloc(4136);this.buff=new c(s,4096),this.u1=new a(s+=4096),this.u2=new a(s+=4),this.f1=new l(s+=4),this.f2=new l(s+=8),this.f3=new l(s+=8),this.f4=new l(s+8)}}const d=(e,t)=>{const n=[1,96],r=t.slice(0,1),o=t.slice(1),s={i:127,p:127,j:126,f:125,d:124};y(o.length,n);for(const e of o)n.push(s[e]);"v"===r?n.push(0):n.push(1,s[r]);const i=[0,97,115,109,1,0,0,0,1];y(n.length,i),i.push(...n),i.push(2,7,1,1,101,1,102,0,0,7,5,1,1,102,0,0);const c=new WebAssembly.Module(new Uint8Array(i));return new WebAssembly.Instance(c,{e:{f:e}}).exports.f},y=(e,t)=>{e<128?t.push(e):t.push(e%128|128,e>>7)},h={env:{emscripten_notify_memory_growth(){const e=256-S.memory.buffer.byteLength/65536%256;S.memory.grow(e),S.updateMemory()}},wasi_snapshot_preview1:{random_get:(e,t)=>(crypto.getRandomValues(S.U8.subarray(e>>>=0,e+t>>>0)),0)}},g=new Proxy({},{get(e,t){if(t.endsWith("destroy"))return()=>0;throw new u("GEOS.js not initialized")}});let S=g;async function m(e){let t,n;return e instanceof WebAssembly.Module?(t=e,n=await WebAssembly.instantiate(e,h)):({module:t,instance:n}=await WebAssembly.instantiateStreaming(e,h)),S=new f(n),t}const p={XY:{P:(e,t)=>[e[t],e[t+1]],C:(e,t,n,r,o)=>{const s=3+o,i=Array(t);for(let r=0;r<t;r++,n+=s)i[r]=[e[n],e[n+1]];return i}},XYZ:{P:(e,t,n)=>n?[e[t],e[t+1],e[t+2]]:[e[t],e[t+1]],C:(e,t,n,r,o)=>{const s=3+o,i=Array(t);for(let o=0;o<t;o++,n+=s)i[o]=r?[e[n],e[n+1],e[n+2]]:[e[n],e[n+1]];return i}},XYZM:{P:(e,t,n,r)=>r?[e[t],e[t+1],e[t+2],e[t+3]]:n?[e[t],e[t+1],e[t+2]]:[e[t],e[t+1]],C:(e,t,n,r,o)=>{const s=3+o,i=Array(t);for(let c=0;c<t;c++,n+=s)i[c]=o?[e[n],e[n+1],e[n+2],e[n+3]]:r?[e[n],e[n+1],e[n+2]]:[e[n],e[n+1]];return i}},XYM:{P:(e,t,n,r)=>r?[e[t],e[t+1],e[t+3]]:[e[t],e[t+1]],C:(e,t,n,r,o)=>{const s=3+o,i=Array(t);for(let r=0;r<t;r++,n+=s)i[r]=o?[e[n],e[n+1],e[n+3]]:[e[n],e[n+1]];return i}}},E=(e,t,n)=>{const{B:r,F:o}=e,s=r[e.b++],i=15&s,c=16&s,a=s>>5&1,l=s>>6&1;if(n||i<8){if(c&&i<9&&7!==i)return{type:_[2===i?1:i],coordinates:[]};switch(i){case 0:{const n=t.P(o,e.f,a,l);return e.f+=l?4:a?3:2,{type:_[i],coordinates:n}}case 4:{const n=r[e.b++],s=Array(n),c=l?4:a?3:2;for(let r=0;r<n;r++,e.f+=c)s[r]=t.P(o,e.f,a,l);return{type:_[i],coordinates:s}}case 1:case 2:case 8:{const n=t.C(o,r[e.b++],r[e.b++],a,l);return{type:_[2===i?1:i],coordinates:n}}case 3:case 5:{const n=r[e.b++],s=Array(n);for(let i=0;i<n;i++)s[i]=t.C(o,r[e.b++],r[e.b++],a,l);return{type:_[i],coordinates:s}}case 6:{const n=r[e.b++],s=Array(n);for(let i=0;i<n;i++){const n=r[e.b++],c=s[i]=Array(n);for(let s=0;s<n;s++)c[s]=t.C(o,r[e.b++],r[e.b++],a,l)}return{type:_[i],coordinates:s}}case 7:case 9:case 10:case 11:case 12:{const o=c?0:r[e.b++],s=Array(o);for(let r=0;r<o;r++)s[r]=E(e,t,n);const a=_[i],l=B[a];return{type:a,[l]:s}}}}throw new u(`${_[i]} is not standard GeoJSON geometry. Use 'extended' flavor to jsonify all geometry types.`)};function G(e,n,r){const o=p[n||"XYZ"],s=S.buff;let i;try{let n=S.U32,c=s.i4,a=c;n[c++]=0,n[c++]=1,n[c++]=e[t],n[c]=s.l4-3,S.jsonify_geoms(s[t]),n=S.U32;const l={B:n,b:c,F:S.F64,f:n[a+1]};return i=n[a],i&&(l.b=i/4),E(l,o,r)}finally{i&&S.free(i)}}function O(e,n,r){const o=p[n||"XYZ"],s=e.length,i=s+3,c=S.buffByL4(i);let a;try{let n=S.U32,l=c.i4,u=l;n[l++]=0,n[l++]=s;for(const r of e)n[l++]=r[t];n[l]=c.l4-i,S.jsonify_geoms(c[t]),n=S.U32;const f={B:n,b:l,F:S.F64,f:n[u+1]};a=n[u],a&&(f.b=a/4);const d=Array(s);for(let t=0;t<s;t++){const n=e[t];d[t]=w(n,E(f,o,r))}return d}finally{c.freeIfTmp(),a&&S.free(a)}}function w(e,t){return{id:e.id,type:"Feature",geometry:t,properties:e.props??null}}var b,P;const _=["Point","LineString","LinearRing","Polygon","MultiPoint","MultiLineString","MultiPolygon","GeometryCollection","CircularString","CompoundCurve","CurvePolygon","MultiCurve","MultiSurface"],C=_.reduce((e,t,n)=>(e[t]=n,e),{}),B={[_[7]]:"geometries",[_[9]]:"segments",[_[10]]:"rings",[_[11]]:"curves",[_[12]]:"surfaces"};class v{normalize(){return S.GEOSNormalize(this[t]),this}orientPolygons(e="cw"){return S.GEOSOrientPolygons(this[t],+("cw"===e)),this}clone(){const e=S.GEOSGeom_clone(this[t]),n=new v(e);return null!=this.id&&(n.id=this.id),null!=this.props&&(n.props=this.props),n}toJSON(){return w(this,G(this,"XYZM",!0))}free(){this[o]&&(v[s].unregister(this),v[i](this[o])),v[n].unregister(this),v[r](this[t]),this.detached=!0}constructor(e,r,o){v[n].register(this,e,this),this[t]=e,this.type=r||_[S.GEOSGeomTypeId(e)],o&&(null!=o.id&&(this.id=o.id),null!=o.properties&&(this.props=o.properties))}static[(b=n,P=s,r)](e){S.GEOSGeom_destroy(e)}static[i](e){S.GEOSPreparedGeom_destroy(e)}}function M(e){if(!e[o]){const n=S.GEOSPrepare(e[t]);v[s].register(e,n,e),e[o]=n}return e}v[b]=new FinalizationRegistry(v[r]),v[P]=new FinalizationRegistry(v[i]);const W={XY:{L:()=>2,H:e=>C[e],P:(e,t,n)=>(t[n++]=e[0],t[n++]=e[1],n),C:(e,t,n)=>{for(const r of e)t[n++]=r[0],t[n++]=r[1],t[n++]=NaN}},XYZ:{L:e=>e>2?3:2,H:(e,t)=>{const n=t?.length;return C[e]|(n>2?32:0)},P:(e,t,n,r)=>(t[n++]=e[0],t[n++]=e[1],r>2&&(t[n++]=e[2]),n),C:(e,t,n,r)=>{const o=r>2;for(const r of e)t[n++]=r[0],t[n++]=r[1],t[n++]=o?r[2]:NaN}},XYZM:{L:e=>e>2?e>3?4:3:2,H:(e,t)=>{const n=t?.length;return C[e]|(n>2?32:0)|(n>3?64:0)},P:(e,t,n,r)=>(t[n++]=e[0],t[n++]=e[1],r>2&&(t[n++]=e[2],r>3&&(t[n++]=e[3])),n),C:(e,t,n,r)=>{const o=r>2,s=r>3;for(const r of e)t[n++]=r[0],t[n++]=r[1],t[n++]=o?r[2]:NaN,s&&(t[n++]=r[3])}},XYM:{L:e=>e>2?4:2,H:(e,t)=>{const n=t?.length;return C[e]|(n>2?64:0)},P:(e,t,n,r)=>(t[n++]=e[0],t[n++]=e[1],r>2&&(t[n++]=NaN,t[n++]=e[2]),n),C:(e,t,n,r)=>{const o=r>2;for(const r of e)t[n++]=r[0],t[n++]=r[1],t[n++]=NaN,o&&(t[n++]=r[2])}}};class T extends u{constructor(e,t,n){super(t),this.name="InvalidGeoJSONError",this.details=n,this.geometry=e}}const I=(e,t,n,r)=>new T(e,`${r} must have at leat ${t} points`,`found ${n}`),L=(e,t,n,r)=>new T(e,r?`${r} ring must be closed`:`${e.type} segments must be continuous`,`points [${t.join()}] and [${n.join()}] are not equal`),F=(e,t,n,r="component")=>new T(e,`${e.type} ${r} must be ${n.map(e=>_[e]).join(", ").replace(/,( \w+)$/," or$1")}`,`"${_[t]}" is not allowed`),U=(e,t)=>{if(e.length!==t.length)return!0;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!0},A=(e,t)=>{const n=t.length;if(1===n)throw I(e,2,n,"LineString")},x=(e,t)=>{for(const n of t){const t=n.length;if(t){if(t<3)throw I(e,3,t,"Polygon ring");if(U(n[0],n[t-1]))throw L(e,n[0],n[t-1],"Polygon")}}},D=(e,t,n)=>{switch(e?.type){case"Point":{const r=e.coordinates,o=n.L(r.length);return t.f+=o,t.d+=1,0}case"MultiPoint":{const r=e.coordinates,o=n.L(r[0]?.length);return t.f+=r.length*o,t.d+=2,4}case"LineString":return A(e,e.coordinates),t.s+=1,t.d+=2,1;case"Polygon":{const n=e.coordinates,r=n.length;return x(e,n),t.s+=r,t.d+=2+r,3}case"MultiLineString":{const n=e.coordinates,r=n.length;for(const t of n)A(e,t);return t.s+=r,t.d+=2+r,5}case"MultiPolygon":{const n=e.coordinates;t.d+=2+n.length;for(const r of n){const n=r.length;x(e,r),t.s+=n,t.d+=n}return 6}case"GeometryCollection":{const r=e.geometries;for(const e of r)D(e,t,n);return t.d+=2,7}case"CircularString":{const n=e.coordinates.length;if(n){if(n<3)throw new T(e,`${e.type} must have at least one circular arc defined by 3 points`);if(!(n%2))throw new T(e,`${e.type} must have and odd number of points`)}return t.s+=1,t.d+=2,8}case"CompoundCurve":{const r=e.segments;if(r.length){let o;for(const s of r){const r=D(s,t,n);if(1!==r&&8!==r)throw F(e,r,[1,8],"segment");const i=s.coordinates;if(!i.length)throw new T(e,`${e.type} cannot contain empty segments`);if(o&&U(o,i[0]))throw L(e,o,i[0]);o=i[i.length-1]}}return t.d+=2,9}case"CurvePolygon":{const r=e.rings;if(r.length)for(const o of r){let r,s,i;const c=D(o,t,n);if(1===c||8===c)r=o.coordinates,s=r[0],i=r[r.length-1];else{if(9!==c)throw F(e,c,[1,8,9],"ring");{const e=o.segments;s=e[0].coordinates[0],r=e[e.length-1].coordinates,i=r[r.length-1]}}if(s&&i&&U(s,i))throw L(e,s,i,e.type)}return t.d+=2,10}case"MultiCurve":{const r=e.curves;for(const o of r){const r=D(o,t,n);if(1!==r&&8!==r&&9!==r)throw F(e,r,[1,8,9])}return t.d+=2,11}case"MultiSurface":{const r=e.surfaces;for(const o of r){const r=D(o,t,n);if(3!==r&&10!==r)throw F(e,r,[3,10])}return t.d+=2,12}}throw new T(e,"Invalid geometry")},R=(e,t,n)=>{const{B:r,F:o}=t;let{d:s,f:i}=t;const c=e.type;switch(c){case"Point":{const t=e.coordinates;t.length?(r[s++]=n.H(c,t),i=n.P(t,o,i,t.length)):r[s++]=16;break}case"MultiPoint":{const t=e.coordinates,a=t[0]?.length;r[s++]=n.H(c,t[0]),r[s++]=t.length;for(const e of t)i=n.P(e,o,i,a);break}case"LineString":case"CircularString":{const t=e.coordinates;r[s++]=n.H(c,t[0]),r[s++]=t.length;break}case"Polygon":case"MultiLineString":{const t=e.coordinates;r[s++]=n.H(c,t[0]?.[0]),r[s++]=t.length;for(const e of t)r[s++]=e.length;break}case"MultiPolygon":{const t=e.coordinates;r[s++]=n.H(c,t[0]?.[0]?.[0]),r[s++]=t.length;for(const e of t){r[s++]=e.length;for(const t of e)r[s++]=t.length}break}case"GeometryCollection":case"CompoundCurve":case"CurvePolygon":case"MultiCurve":case"MultiSurface":{const o=e[B[c]];r[t.d++]=C[c],r[t.d++]=o.length;for(const e of o)R(e,t,n);return}}t.f=i,t.d=s},N=(e,t,n)=>{const{B:r,F:o}=t;switch(e.type){case"LineString":case"CircularString":{const s=e.coordinates;n.C(s,o,r[t.s++],s[0]?.length);break}case"Polygon":case"MultiLineString":{const s=e.coordinates,i=s[0]?.[0]?.length;for(const e of s)n.C(e,o,r[t.s++],i);break}case"MultiPolygon":{const s=e.coordinates,i=s[0]?.[0]?.[0]?.length;for(const e of s)for(const s of e)n.C(s,o,r[t.s++],i);break}case"GeometryCollection":case"CompoundCurve":case"CurvePolygon":case"MultiCurve":case"MultiSurface":{const r=e[B[e.type]];for(const e of r)N(e,t,n)}}};function $(e,n,r){const o=W[n||"XYZM"],s={d:0,s:0,f:0};D(e,s,o);const i=S.buffByL4(3+s.d+s.s+2*s.f);try{let n,c,a=S.U32,l=i.i4;a[l++]=s.d,a[l++]=s.s,n=l+s.d,c=Math.ceil((n+s.s)/2);const u={B:a,d:l,F:S.F64,f:c};if(R(e,u,o),s.s){S.geosify_geomsCoords(i[t]);const r={B:S.U32,s:n,F:S.F64};N(e,r,o)}return S.geosify_geoms(i[t]),a=S.U32,new v(a[l],e.type,r)}finally{i.freeIfTmp()}}function K(e,t){return $({type:"Polygon",coordinates:e},t?.layout,t)}const j=e=>e.length&&Array.isArray(e[0]),z=(e,t)=>{for(const n of e)if(!(t&1<<C[n.type])){const e=[];for(let n=0,r=t;r;n++,r>>>=1)1&r&&e.push(_[n]);throw new u(`Geometry must be ${e.join(", ").replace(/,( \w+)$/," or$1")}. ${n.type} is not allowed`)}},X=(e,r,o)=>{let s=S.U32,i=e.i4;if(o?.consume)for(const e of r)s[i++]=e[t],v[n].unregister(e),e.detached=!0;else for(const e of r)s[i++]=S.GEOSGeom_clone(e[t])},Y=(e,n,r)=>{const o=n.length,s=S.buffByL4(o);try{X(s,n,r);const i=S.GEOSGeom_createCollection(e,s[t],o);return new v(i,_[e],r)}finally{s.freeIfTmp()}};function k(e){return Boolean(S.GEOSisEmpty(e[t]))}class q extends u{constructor(e,t){super(e),this.name="TopologyValidationError",this.location=t}}var V;class H{query(e){const n=S.u1,r=S.STRtree_query(this[t],e[t],n[t]);return Z(this.geometries,r,n)}nearest(e){const n=S.u1,r=S.STRtree_nearest(this[t],e[t],n[t]);if(n.get())return this.geometries[r]}nearestAll(e){const n=S.u1,r=S.STRtree_nearestAll(this[t],e[t],n[t]);return Z(this.geometries,r,n)}free(){H[n].unregister(this),H[r](this[t]),this.detached=!0}constructor(e,r){H[n].register(this,e,this),this[t]=e,this.geometries=r}static[(V=n,r)](e){S.STRtree_destroy(e)}}function Z(e,t,n){if(t){const r=n.get(),o=Array(r);let s=S.U32,i=t>>>2;for(let t=0;t<r;t++)o[t]=e[s[i++]];return S.free(t),o}return[]}H[V]=new FinalizationRegistry(H[r]),e.GEOSError=u,e.InvalidGeoJSONError=T,e.TopologyValidationError=q,e.area=function(e){const n=S.f1;return S.GEOSArea(e[t],n[t]),n.get()},e.bounds=function(e){const n=S.f1,r=S.f2,o=S.f3,s=S.f4;if(S.GEOSGeom_getExtent(e[t],n[t],r[t],o[t],s[t]))return[n.get(),r.get(),o.get(),s.get()];throw new u("Cannot calculate bounds of an empty geometry")},e.box=function(e,t){const[n,r,o,s]=e;if(n===o||r===s)throw new u("Degenerate box");return K([[[n,r],[n,s],[o,s],[o,r],[n,r]]],t)},e.buffer=function(e,n,r){const o=S.b_p,s=r?[r.quadrantSegments,r.endCapStyle,r.joinStyle,r.mitreLimit,r.singleSided].join():"";let i=o[s];if(!i){const e=S.GEOSBufferParams_create();if(r){const{quadrantSegments:t,endCapStyle:n,joinStyle:o,mitreLimit:s,singleSided:i}=r;if(null!=t&&S.GEOSBufferParams_setQuadrantSegments(e,t),null!=n){const t={round:1,flat:2,square:3};S.GEOSBufferParams_setEndCapStyle(e,t[n])}if(null!=o){const t={round:1,mitre:2,bevel:3};S.GEOSBufferParams_setJoinStyle(e,t[o])}null!=s&&S.GEOSBufferParams_setMitreLimit(e,s),null!=i&&S.GEOSBufferParams_setSingleSided(e,+i)}i=o[s]=e}const c=S.GEOSBufferWithParams(e[t],i,n);return new v(c)},e.circularString=function(e,t){return $({type:"CircularString",coordinates:e},t?.layout,t)},e.compoundCurve=function(e,n){z(e,258);const r=e.length,o=S.buffByL4(r);try{X(o,e,n);const s=r?S.GEOSGeom_createCompoundCurve(o[t],r):S.GEOSGeom_createEmptyCompoundCurve();return new v(s,"CompoundCurve",n)}finally{o.freeIfTmp()}},e.contains=function(e,n){return Boolean(e[o]?S.GEOSPreparedContains(e[o],n[t]):S.GEOSContains(e[t],n[t]))},e.containsProperly=function(e,n){return e[o]||M(e),Boolean(S.GEOSPreparedContainsProperly(e[o],n[t]))},e.coveredBy=function(e,n){return Boolean(e[o]?S.GEOSPreparedCoveredBy(e[o],n[t]):S.GEOSCoveredBy(e[t],n[t]))},e.covers=function(e,n){return Boolean(e[o]?S.GEOSPreparedCovers(e[o],n[t]):S.GEOSCovers(e[t],n[t]))},e.crosses=function(e,n){return Boolean(e[o]?S.GEOSPreparedCrosses(e[o],n[t]):S.GEOSCrosses(e[t],n[t]))},e.curvePolygon=function(e,n){z(e,770);const r=e.length,o=S.buffByL4(r);try{X(o,e,n);const s=r?S.GEOSGeom_createCurvePolygon(S.U32[o.i4],o[t]+4,r-1):S.GEOSGeom_createEmptyCurvePolygon();return new v(s,"CurvePolygon",n)}finally{o.freeIfTmp()}},e.difference=function(e,n,r){const o=null!=r?.gridSize?S.GEOSDifferencePrec(e[t],n[t],r.gridSize):S.GEOSDifference(e[t],n[t]);return new v(o)},e.disjoint=function(e,n){return Boolean(e[o]?S.GEOSPreparedDisjoint(e[o],n[t]):S.GEOSDisjoint(e[t],n[t]))},e.distance=function(e,n){const r=S.f1;e[o]?S.GEOSPreparedDistance(e[o],n[t],r[t]):S.GEOSDistance(e[t],n[t],r[t]);const s=r.get();if(!s&&(k(e)||k(n)))throw new u('"distance" called with empty inputs');return s},e.distanceWithin=function(e,n,r){return Boolean(e[o]?S.GEOSPreparedDistanceWithin(e[o],n[t],r):S.GEOSDistanceWithin(e[t],n[t],r))},e.equals=function(e,n){return Boolean(S.GEOSEquals(e[t],n[t]))},e.equalsExact=function(e,n,r){return Boolean(S.GEOSEqualsExact(e[t],n[t],r))},e.equalsIdentical=function(e,n){return Boolean(S.GEOSEqualsIdentical(e[t],n[t]))},e.frechetDistance=function(e,n,r){const o=S.f1;return null!=r?.densify?S.GEOSFrechetDistanceDensify(e[t],n[t],r.densify,o[t]):S.GEOSFrechetDistance(e[t],n[t],o[t]),o.get()},e.fromGeoJSON=function(e,n){const r=n?.layout;switch(e.type){case"FeatureCollection":return function(e,n){const r=W[n||"XYZM"],o={d:0,s:0,f:0};for(const t of e)D(t.geometry,o,r);const s=S.buffByL4(3+o.d+o.s+2*o.f);try{let n,i,c=S.U32,a=s.i4;c[a++]=o.d,c[a++]=o.s,n=a+o.d,i=Math.ceil((n+o.s)/2);const l={B:c,d:a,F:S.F64,f:i};for(const t of e)R(t.geometry,l,r);if(o.s){S.geosify_geomsCoords(s[t]);const o={B:S.U32,s:n,F:S.F64};for(const t of e)N(t.geometry,o,r)}S.geosify_geoms(s[t]),c=S.U32;const u=e.length,f=Array(u);for(let t=0;t<u;t++){const n=e[t];f[t]=new v(c[a++],n.geometry.type,n)}return f}finally{s.freeIfTmp()}}(e.features,r);case"Feature":return $(e.geometry,r,e)}return $(e,r)},e.fromWKB=function(e,n){const r=S.b_r,o=n?[n.fix].join():"";let s=r[o];if(!s){const e=S.GEOSWKBReader_create();if(n){const{fix:t}=n;null!=t&&S.GEOSWKBReader_setFixStructure(e,+t)}s=r[o]=e}const i=e.length,c=S.buffByL(i);try{S.U8.set(e,c[t]);const n=S.GEOSWKBReader_read(s,c[t],i);return new v(n)}finally{c.freeIfTmp()}},e.fromWKT=function(e,n){const r=S.t_r,o=n?[n.fix].join():"";let s=r[o];if(!s){const e=S.GEOSWKTReader_create();if(n){const{fix:t}=n;null!=t&&S.GEOSWKTReader_setFixStructure(e,+t)}s=r[o]=e}const i=S.encodeString(e);try{const e=S.GEOSWKTReader_read(s,i[t]);return new v(e)}finally{i.freeIfTmp()}},e.geometryCollection=function(e,t){return Y(7,e,t)},e.growMemory=function(e){const t=S.memory.buffer.byteLength,n="by"in e?t+e.by:e.to,r=t/65536,o=Math.min(65535,Math.ceil(n/65536))-r;return o>0&&(S.memory.grow(o),S.updateMemory()),S.memory.buffer.byteLength},e.hausdorffDistance=function(e,n,r){const o=S.f1;null!=r?.densify?S.GEOSHausdorffDistanceDensify(e[t],n[t],r.densify,o[t]):S.GEOSHausdorffDistance(e[t],n[t],o[t]);const s=o.get();if(isNaN(s))throw new u('"hausdorffDistance" called with empty inputs');return s},e.initialize=async function(e){return await m(e)},e.initializeFromBase64=async function(){const e=atob("ROLLUP_WILL_INSERT_WASM_BASE64_HERE"),t=e.length,n=new Uint8Array(t);for(let r=0;r<t;r++)n[r]=e.charCodeAt(r);const r=await WebAssembly.compile(n);return await m(r)},e.intersection=function(e,n,r){const o=null!=r?.gridSize?S.GEOSIntersectionPrec(e[t],n[t],r.gridSize):S.GEOSIntersection(e[t],n[t]);return new v(o)},e.intersects=function(e,n){return Boolean(e[o]?S.GEOSPreparedIntersects(e[o],n[t]):S.GEOSIntersects(e[t],n[t]))},e.isEmpty=k,e.isGeometry=function(e){return e instanceof v},e.isPrepared=function(e){return Boolean(e[o])},e.isSimple=function(e){return Boolean(S.GEOSisSimple(e[t]))},e.isValid=function(e,n){return Boolean(S.GEOSisValidDetail(e[t],n?.isInvertedRingValid?1:0,0,0))},e.isValidOrThrow=function(e,n){const r=S.u1,o=S.u2;if(!S.GEOSisValidDetail(e[t],n?.isInvertedRingValid?1:0,r[t],o[t])){const e=r.get(),t=S.decodeString(e),n=new v(o.get(),"Point"),s=G(n).coordinates;throw S.free(e),n.free(),new q(t,s)}},e.length=function(e){const n=S.f1;return S.GEOSLength(e[t],n[t]),n.get()},e.lineString=function(e,t){return $({type:"LineString",coordinates:e},t?.layout,t)},e.makeValid=function(e,n){const r=S.m_v,o=n?[n.method,n.keepCollapsed].join():"";let s=r[o];if(!s){const e=S.GEOSMakeValidParams_create();if(n){const{method:t,keepCollapsed:r}=n;null!=t&&S.GEOSMakeValidParams_setMethod(e,"structure"===t?1:0),null!=r&&S.GEOSMakeValidParams_setKeepCollapsed(e,+r)}s=r[o]=e}const i=S.GEOSMakeValidWithParams(e[t],s);return new v(i)},e.multiCurve=function(e,t){return z(e,770),Y(11,e,t)},e.multiLineString=function(e,t){return j(e)?$({type:"MultiLineString",coordinates:e},t?.layout,t):(z(e,2),Y(5,e,t))},e.multiPoint=function(e,t){return j(e)?$({type:"MultiPoint",coordinates:e},t?.layout,t):(z(e,1),Y(4,e,t))},e.multiPolygon=function(e,t){return j(e)?$({type:"MultiPolygon",coordinates:e},t?.layout,t):(z(e,8),Y(6,e,t))},e.multiSurface=function(e,t){return z(e,1032),Y(12,e,t)},e.nearestPoints=function(e,n){const r=e[o]?S.GEOSPreparedNearestPoints(e[o],n[t]):S.GEOSNearestPoints(e[t],n[t]);if(r){const o=S.f1,s=S.f2;S.GEOSCoordSeq_getXY(r,0,o[t],s[t]);const i=S.GEOSGeom_createPointFromXY(o.get(),s.get());S.GEOSSetSRID(i,S.GEOSGetSRID(e[t])),S.GEOSCoordSeq_getXY(r,1,o[t],s[t]);const c=S.GEOSGeom_createPointFromXY(o.get(),s.get());return S.GEOSSetSRID(c,S.GEOSGetSRID(n[t])),S.GEOSCoordSeq_destroy(r),[new v(i,"Point"),new v(c,"Point")]}if(k(e)||k(n))throw new u('"nearestPoints" called with empty inputs');throw new u("Curved geometry types are not supported.")},e.overlaps=function(e,n){return Boolean(e[o]?S.GEOSPreparedOverlaps(e[o],n[t]):S.GEOSOverlaps(e[t],n[t]))},e.point=function(e,t){return $({type:"Point",coordinates:e},t?.layout,t)},e.polygon=K,e.prepare=M,e.relate=function(e,n){const r=e[o]?S.GEOSPreparedRelate(e[o],n[t]):S.GEOSRelate(e[t],n[t]),s=S.decodeString(r);return S.free(r),s},e.relatePattern=function(e,n,r){const s=S.encodeString(r);return Boolean(e[o]?S.GEOSPreparedRelatePattern(e[o],n[t],s[t]):S.GEOSRelatePattern(e[t],n[t],s[t]))},e.simplify=function(e,n,r){const o=!1===r?.preserveTopology?S.GEOSSimplify(e[t],n):S.GEOSTopologyPreserveSimplify(e[t],n);return new v(o)},e.strTreeIndex=function(e,n){const r=n?.nodeCapacity??10;if(r<2)throw new u("Node capacity must be greater than 1");const o=e.length,s=S.malloc(4*o);try{let n=S.U32,i=s>>>2;for(const r of e)n[i++]=r[t];const c=S.STRtree_create(s,o,r);return new H(c,e)}catch(e){throw S.free(s),e}},e.symmetricDifference=function(e,n,r){const o=null!=r?.gridSize?S.GEOSSymDifferencePrec(e[t],n[t],r.gridSize):S.GEOSSymDifference(e[t],n[t]);return new v(o)},e.terminate=async function(){S!==g&&(S=g)},e.toGeoJSON=function(e,t){const n=t?.layout,r="extended"===t?.flavor;return Array.isArray(e)?{type:"FeatureCollection",features:O(e,n,r)}:w(e,G(e,n,r))},e.toWKB=function(e,n){const r=S.b_w,o=n?[n.dim,n.flavor,n.byteOrder,n.srid].join():"";let s=r[o];if(!s){const e=S.GEOSWKBWriter_create();if(n){const{dim:t,flavor:r,byteOrder:o,srid:s}=n;null!=t&&S.GEOSWKBWriter_setOutputDimension(e,t),null!=r&&S.GEOSWKBWriter_setFlavor(e,"iso"===r?2:1),null!=o&&S.GEOSWKBWriter_setByteOrder(e,"be"===o?0:1),null!=s&&S.GEOSWKBWriter_setIncludeSRID(e,+s)}s=r[o]=e}const i=S.u1,c=S.GEOSWKBWriter_write(s,e[t],i[t]),a=S.U8.slice(c,c+i.get());return S.free(c),a},e.toWKT=function(e,n){const r=S.t_w,o=n?[n.dim,n.precision,n.trim].join():"";let s=r[o];if(!s){const e=S.GEOSWKTWriter_create();if(n){const{dim:t,precision:r,trim:o}=n;null!=t&&S.GEOSWKTWriter_setOutputDimension(e,t),null!=r&&S.GEOSWKTWriter_setRoundingPrecision(e,r),null!=o&&S.GEOSWKTWriter_setTrim(e,+o)}s=r[o]=e}const i=S.GEOSWKTWriter_write(s,e[t]),c=S.decodeString(i);return S.free(i),c},e.touches=function(e,n){return Boolean(e[o]?S.GEOSPreparedTouches(e[o],n[t]):S.GEOSTouches(e[t],n[t]))},e.unaryUnion=function(e,n){const r=null!=n?.gridSize?S.GEOSUnaryUnionPrec(e[t],n.gridSize):S.GEOSUnaryUnion(e[t]);return new v(r)},e.union=function(e,n,r){const o=null!=r?.gridSize?S.GEOSUnionPrec(e[t],n[t],r.gridSize):S.GEOSUnion(e[t],n[t]);return new v(o)},e.unprepare=function(e){return e[o]&&(v[s].unregister(e),v[i](e[o]),delete e[o]),e},e.version=function(){const e=S.GEOSversion();return S.decodeString(e)},e.within=function(e,n){return Boolean(e[o]?S.GEOSPreparedWithin(e[o],n[t]):S.GEOSWithin(e[t],n[t]))}});