/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
import{estimateNumberArrayMemory as t}from"../../core/memoryEstimations.js";class s{constructor(t=[],s=[],r=!1,o=!1){this.lengths=t??[],this.coords=s??[],this.hasZ=r,this.hasM=o}static fromJSON({lengths:t,coords:r,hasZ:o,hasM:e}){return new s(t,r,o||!1,e||!1)}static fromRect([t,r,o,e]){const i=o-t,h=e-r;return new s([5],[t,r,i,0,0,h,-i,0,0,-h])}get isPoint(){return 0===this.lengths.length&&this.coords.length>=2}get maxLength(){return Math.max(...this.lengths)}get size(){return this.isPoint?1:this.lengths.reduce((t,s)=>t+s,0)}get usedMemory(){return 64+t(this.lengths,this.coords)}get stride(){return 2+(this.hasZ?1:0)+(this.hasM?1:0)}area(){if(this.isPoint)return 0;let t=0,s=0;for(const r of this.lengths){if(r<3)continue;const{stride:o}=this;let e=this.coords[o*s],i=this.coords[o*s+1];for(let h=1;h<r;h+=1){const r=o*(s+h),n=this.coords[r],c=this.coords[r+1];t+=-.5*(n-e)*(c+i),e=n,i=c}s+=r}return t}forEachVertex(t){let s=0;if(this.isPoint)return t(this.coords[0],this.coords[1]);const{stride:r}=this;for(const o of this.lengths){for(let e=0;e<o;e++){const o=r*(s+e);t(this.coords[o],this.coords[o+1])}s+=o}}deltaDecode(){const t=this.clone(),{coords:s,lengths:r}=t;let o=0;const{stride:e}=this;for(const i of r){for(let t=1;t<i;t++){const r=e*(o+t);s[r]+=s[r-e],s[r+1]+=s[r+1-e]}o+=i}return t}clone(t){if(this.isPoint)return new s([],Array.from(this.coords.slice(0,this.stride)),this.hasZ,this.hasM);const r=Array.from(this.lengths),{stride:o,size:e}=this,i=this.coords.slice(0,e*o);return t?(t.set(i),new s(r,t,this.hasZ,this.hasM)):new s(r,Array.from(i),this.hasZ,this.hasM)}justXY(){const{stride:t,size:r}=this;if(2===t)return this;const o=new Array(r*t);for(let s=0,e=0;s<o.length;s+=t)o[e++]=this.coords[s],o[e++]=this.coords[s+1];return new s(this.lengths,o,!1,!1)}}export{s as default};
