// All material copyright Esri, All Rights Reserved, unless otherwise specified. // See https://js.arcgis.com/4.30/esri/copyright.txt for details. //>>built define(["exports","../core/lang","./geometryCursorCollectUtils","./support/jsonUtils","../layers/graphics/OptimizedGeometry"],function(r,t,u,g,m){function v(a){if(g.isPolygon(a))a=[a.rings,"esriGeometryPolygon"];else if(g.isPolyline(a))a=[a.paths,"esriGeometryPolyline"];else if(g.isMultipoint(a))a=[[a.points],"esriGeometryMultipoint"];else if(g.isExtent(a))a=[[[[a.xmin,a.ymin],[a.xmin,a.ymax],[a.xmax,a.ymax],[a.xmax,a.ymin],[a.xmin,a.ymin]]],"esriGeometryEnvelope"];else if(g.isPoint(a)){const b=[a.x, a.y];a.z&&b.push(a.z);a.m&&b.push(a.m);a=[[[b]],"esriGeometryPoint"]}else a=[[],"esriGeometryPolyline"];return a}class n{static fromOptimized(a,b,c=!1,d=!1,e=1){return(new k).initialize(a,b,c,d,e)}static fromJSON(a,b=!1,c=!1){const [d,e]=v(a);return(new l).initialize(d,e,b,c,1)}static fromOptimizedCIM(a,b,c=!1,d=!1,e=1){return(new p).initialize(a,b,c,d,e)}static fromJSONCIM(a,b=!1,c=!1,d=1){const [e,f]=v(a);return(new q).initialize(e,f,b,c,d)}static fromFeatureSetReader(a){const b=a.readGeometryForDisplay(); a=a.geometryType;return b&&a?this.fromOptimized(b,a):null}static fromFeatureSetReaderCIM(a){const b=a.readGeometryForDisplay();a=a.geometryType;return b&&a?this.fromOptimizedCIM(b,a):null}static createEmptyOptimized(a,b=!1,c=!1,d=1){return(new k).initialize(new m,a,b,c,d)}static createEmptyJSON(a,b=!1,c=!1){return(new l).initialize([],a,b,c,1)}static createEmptyOptimizedCIM(a,b=!1,c=!1,d=1){return(new p).initialize(new m,a,b,c,d)}static createEmptyJSONCIM(a,b=!1,c=!1,d=1){return(new q).initialize([], a,b,c,d)}asJSON(){const a=u.collectMultipath(this);return"esriGeometryEnvelope"===this.geometryType?{xmin:a[0][0][0],ymin:a[0][0][1],xmax:a[0][2][0],ymax:a[0][2][1]}:"esriGeometryMultipoint"===this.geometryType?{points:a.flat()}:"esriGeometryPoint"===this.geometryType?{x:a[0][0][0],y:a[0][0][1]}:"esriGeometryPolygon"===this.geometryType?{rings:a}:{paths:a}}getCurrentRingArea(){if(3>this.pathSize)return 0;let a=0,b,c;this.seekPathStart();if(!this.nextPoint())return 0;b=this.x;c=this.y;const d=b,e= c;for(;this.nextPoint();)a+=(b-this.x)*(c+this.y),b=this.x,c=this.y;return-.5*(a+(b-d)*(c+e))}invertY(){this.yFactor*=-1}}class k extends n{constructor(){super(...arguments);this._end=-1}initialize(a,b,c,d,e){this.hasZ=c;this.hasM=d;this.geometryType=b;this._stride=2+Number(c)+Number(d);this._geometry=a;this._pathIndex=-1;this._pathOffset=0;this._pointOffset=-this._stride;this._end=-1;this.yFactor=e;return this}reset(){this.initialize(this._geometry,this.geometryType,this.hasZ,this.hasM,this.yFactor)}seekPath(a){if(0<= a&&aa)for(;this._pathIndex>a&&this.prevPath(););return!0}return!1}seekPathStart(){this._pointOffset=this._pathOffset-this._stride}seekPathEnd(){this._pointOffset=this._end}seekInPath(a){a=this._pathOffset+a*this._stride;return 0<=a&&a=this._pathOffset}nextPath(){if(this.pathIndex>= this.totalSize-1)return!1;0<=this._pathIndex&&(this._pathOffset+=this._stride*this.pathSize);this._pathIndex++;this._pointOffset=this._pathOffset-this._stride;this._end=this._pointOffset+this._stride+this._stride*this.pathSize;return!0}prevPath(){if(0>=this.pathIndex)return!1;this._pathIndex--;this._end=this._pathOffset;this._pathOffset-=this._stride*this.pathSize;this._pointOffset=this._pathOffset-this._stride;return!0}pathLength(){const a=this._end,b=this._stride,c=this._geometry.coords;let d=0; for(let e=this._pathOffset+b;ea+b)}get pathSize(){const {lengths:a}=this._geometry;return this._geometry.isPoint?1:0>this._pathIndex||this._pathIndex>a.length-1?0:a[this._pathIndex]}get totalSize(){return this._geometry.isPoint?1:this._geometry.lengths.length}get x(){return this._geometry.coords[this._pointOffset]}set x(a){this._geometry.coords[this._pointOffset]= a}get y(){return this.yFactor*this._geometry.coords[this._pointOffset+1]}set y(a){this._geometry.coords[this._pointOffset+1]=this.yFactor*a}get z(){return this._geometry.coords[this._pointOffset+2]}set z(a){this._geometry.coords[this._pointOffset+2]=a}get m(){return this._geometry.coords[this._pointOffset+(this.hasZ?3:2)]}set m(a){this._geometry.coords[this._pointOffset+3]=a}get pathIndex(){return this._pathIndex}get _coordIndex(){return this._pointOffset/this._stride}}class l extends n{initialize(a, b,c,d,e){this._paths=a;this.geometryType=b;this.hasZ=c;this.hasM=d;this._pathIndex=this._pointIndex=-1;this.yFactor=e;this._mIndex=this.hasZ?3:2;return this}reset(){this._pathIndex=this._pointIndex=-1}seekPath(a){this._pathIndex=a;this._pointIndex=-1;return 0<=a&&aa.length).reduce((a,b)=>a+b)}get pathSize(){return 0>this._pathIndex||this._pathIndex>this.totalSize-1?-1:this._paths[this._pathIndex].length}get totalSize(){return this._paths.length}get x(){return this._currentPoint[0]}set x(a){this._currentPoint[0]=a}get y(){return this.yFactor*this._currentPoint[1]}set y(a){this._currentPoint[1]=this.yFactor*a}get z(){return this._currentPoint[2]}set z(a){this._currentPoint[2]=a}get m(){return this._currentPoint[this._mIndex]}set m(a){this._currentPoint[this._mIndex]= a}get pathIndex(){return this._pathIndex}}class p extends k{initialize(a,b,c,d,e){super.initialize(a,b,c,d,e);this._controlPoints||(this._controlPoints=this._controlPoints=Array(this.totalSize).fill(void 0).map(f=>new Set));return this}startPath(){super.startPath();this._controlPoints.push(new Set)}clone(){const a=(new p).initialize(this._geometry.clone(),this.geometryType,this.hasZ,this.hasM,this.yFactor);a._controlPoints=this._controlPoints;return a}setControlPoint(){this._controlPoints[this.pathIndex].add(this._coordIndex)}getControlPoint(){return this._controlPoints[this.pathIndex].has(this._coordIndex)}setControlPointAt(a){this._controlPoints[this.pathIndex].add(a)}getControlPointAt(a){return this._controlPoints[this.pathIndex].has(a)}} class q extends l{initialize(a,b,c,d,e){return super.initialize(a,b,c,d,e)}clone(){return(new q).initialize(t.clone(this._paths),this.geometryType,this.hasZ,this.hasM,this.yFactor)}setControlPoint(){this._paths[this.pathIndex][this._pointIndex][4]=1}getControlPoint(){return 1===this._paths[this.pathIndex][this._pointIndex][4]}setControlPointAt(a){this._paths[this.pathIndex][a][4]=1}getControlPointAt(a){return 1===this._paths[this.pathIndex][a][4]}}r.GeometryCursor=n;Object.defineProperty(r,Symbol.toStringTag, {value:"Module"})});