import{be as A,h1 as V,fR as Y,L as k,h2 as w,z as F,s as v,eL as M}from"./index-b5c8f851.js";import{y as C}from"./featureConversionUtils-6aca8295.js";import{h as x}from"./timeSupport-b4d06407.js";import{a as $,t as j}from"./OptimizedGeometry-d94e541f.js";function T(s,t){return s?t?4:3:t?3:2}function G(s,t,e,r,o){if(!(t!=null&&t.lengths.length))return null;const u=(o==null?void 0:o.originPosition)==="upperLeft"?-1:1;s.lengths.length&&(s.lengths.length=0),s.coords.length&&(s.coords.length=0);const n=s.coords,h=[],a=e?[Number.POSITIVE_INFINITY,Number.NEGATIVE_INFINITY,Number.POSITIVE_INFINITY,Number.NEGATIVE_INFINITY,Number.POSITIVE_INFINITY,Number.NEGATIVE_INFINITY]:[Number.POSITIVE_INFINITY,Number.NEGATIVE_INFINITY,Number.POSITIVE_INFINITY,Number.NEGATIVE_INFINITY],{lengths:f,coords:g}=t,b=T(e,r);let y=0;for(const i of f){const d=Z(a,g,y,i,e,r,u);d&&h.push(d),y+=i*b}if(h.sort((i,d)=>{let I=u*i[2]-u*d[2];return I===0&&e&&(I=i[4]-d[4]),I}),h.length){let i=6*h[0][2];n[0]=h[0][0]/i,n[1]=h[0][1]/i,e&&(i=6*h[0][4],n[2]=i!==0?h[0][3]/i:0),(n[0]a[1]||n[1]a[3]||e&&(n[2]a[5]))&&(n.length=0)}if(!n.length){const i=t.lengths[0]?O(g,0,f[0],e,r):null;if(!i)return null;n[0]=i[0],n[1]=i[1],e&&i.length>2&&(n[2]=i[2])}return s}function Z(s,t,e,r,o,u,n=1){const h=T(o,u);let a=e,f=e+h,g=0,b=0,y=0,i=0,d=0;for(let E=0,N=r-1;Es[1]&&(s[1]=c),_s[3]&&(s[3]=_),o&&(ls[5]&&(s[5]=l))}if(i*n>0&&(i*=-1),d*n>0&&(d*=-1),!i)return null;const I=[g,b,.5*i];return o&&(I[3]=y,I[4]=.5*d),I}function O(s,t,e,r,o){const u=T(r,o);let n=t,h=t+u,a=0,f=0,g=0,b=0;for(let y=0,i=e-1;y0?r?[f/a,g/a,b/a]:[f/a,g/a]:e>0?r?[s[t],s[t+1],s[t+2]]:[s[t],s[t+1]]:null}function P(s,t,e,r){const o=e-s,u=r-t;return Math.sqrt(o*o+u*u)}function L(s,t,e,r,o,u){const n=r-s,h=o-t,a=u-e;return Math.sqrt(n*n+h*h+a*a)}function R(s,t,e,r){return[s+.5*(e-s),t+.5*(r-t)]}function z(s,t,e,r,o,u){return[s+.5*(r-s),t+.5*(o-t),e+.5*(u-e)]}const q={getObjectId:s=>s.objectId,getAttributes:s=>s.attributes,getAttribute:(s,t)=>s.attributes[t],cloneWithGeometry:(s,t)=>new $(t,s.attributes,null,s.objectId),getGeometry:s=>s.geometry,getCentroid:(s,t)=>(s.centroid==null&&(s.centroid=G(new j,s.geometry,t.hasZ,t.hasM)),s.centroid)},U=A();class K{constructor(t){this.geometryInfo=t,this._boundsStore=new V,this._featuresById=new Map,this._markedIds=new Set,this.events=new Y,this.featureAdapter=q}get geometryType(){return this.geometryInfo.geometryType}get hasM(){return this.geometryInfo.hasM}get hasZ(){return this.geometryInfo.hasZ}get numFeatures(){return this._featuresById.size}get fullBounds(){return this._boundsStore.fullBounds}get storeStatistics(){let t=0;return this._featuresById.forEach(e=>{e.geometry!=null&&e.geometry.coords&&(t+=e.geometry.coords.length)}),{featureCount:this._featuresById.size,vertexCount:t/(this.hasZ?this.hasM?4:3:this.hasM?3:2)}}getFullExtent(t){if(this.fullBounds==null)return null;const[e,r,o,u]=this.fullBounds;return{xmin:e,ymin:r,xmax:o,ymax:u,spatialReference:x(t)}}add(t){this._add(t),this._emitChanged()}addMany(t){for(const e of t)this._add(e);this._emitChanged()}upsertMany(t){const e=t.map(r=>this._upsert(r));return this._emitChanged(),e.filter(k)}clear(){this._featuresById.clear(),this._boundsStore.clear(),this._emitChanged()}removeById(t){const e=this._featuresById.get(t);return e?(this._remove(e),this._emitChanged(),e):null}removeManyById(t){this._boundsStore.invalidateIndex();for(const e of t){const r=this._featuresById.get(e);r&&this._remove(r)}this._emitChanged()}forEachBounds(t,e){for(const r of t){const o=this._boundsStore.get(r.objectId);o&&e(w(U,o))}}getFeature(t){return this._featuresById.get(t)}has(t){return this._featuresById.has(t)}forEach(t){this._featuresById.forEach(e=>t(e))}forEachInBounds(t,e){this._boundsStore.forEachInBounds(t,r=>{e(this._featuresById.get(r))})}startMarkingUsedFeatures(){this._boundsStore.invalidateIndex(),this._markedIds.clear()}sweep(){let t=!1;this._featuresById.forEach((e,r)=>{this._markedIds.has(r)||(t=!0,this._remove(e))}),this._markedIds.clear(),t&&this._emitChanged()}_emitChanged(){this.events.emit("changed",void 0)}_add(t){var u,n;if(!t)return;const e=t.objectId;if(e==null)return void F.getLogger("esri.layers.graphics.data.FeatureStore").error(new v("featurestore:invalid-feature","feature id is missing",{feature:t}));const r=this._featuresById.get(e);let o;if(this._markedIds.add(e),r?(t.displayId=r.displayId,o=this._boundsStore.get(e),this._boundsStore.delete(e)):this.onFeatureAdd!=null&&this.onFeatureAdd(t),!((n=(u=t.geometry)==null?void 0:u.coords)!=null&&n.length))return this._boundsStore.set(e,null),void this._featuresById.set(e,t);o=C(o??M(),t.geometry,this.geometryInfo.hasZ,this.geometryInfo.hasM),o!=null&&this._boundsStore.set(e,o),this._featuresById.set(e,t)}_upsert(t){const e=t==null?void 0:t.objectId;if(e==null)return F.getLogger("esri.layers.graphics.data.FeatureStore").error(new v("featurestore:invalid-feature","feature id is missing",{feature:t})),null;const r=this._featuresById.get(e);if(!r)return this._add(t),t;this._markedIds.add(e);const{geometry:o,attributes:u}=t;for(const n in u)r.attributes[n]=u[n];return o&&(r.geometry=o,this._boundsStore.set(e,C(M(),o,this.geometryInfo.hasZ,this.geometryInfo.hasM)??null)),r}_remove(t){this.onFeatureRemove!=null&&this.onFeatureRemove(t);const e=t.objectId;return this._markedIds.delete(e),this._boundsStore.delete(e),this._featuresById.delete(e),t}}export{K as m};