/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import e from"../../Graphic.js";import{clone as t}from"../../core/lang.js";import{isFloat32Array as n,isFloat64Array as r}from"../../core/typedArrayUtil.js";import a from"../../geometry/SpatialReference.js";import{fromJSON as s}from"../../geometry/support/jsonUtils.js";import{makeDehydratedPoint as i}from"./dehydratedPoint.js";function o(e){return"declaredClass"in e}function m(e){return"declaredClass"in e}function l(e){return"declaredClass"in e}function c(n,r,a){return n?l(n)?(n.origin!==a&&(n.origin=a),n):new e({layer:r,sourceLayer:r,origin:a,visible:n.visible,symbol:t(n.symbol),attributes:t(n.attributes),geometry:u(n.geometry)}):null}function u(e){return null==e?null:o(e)?e:s(f(e))}function f(e){const{wkid:t,wkt:n,wkt2:r,latestWkid:a}=e.spatialReference,s={wkid:t,wkt:n,wkt2:r,latestWkid:a};switch(e.type){case"point":{const{x:t,y:n,z:r,m:a}=e;return{x:t,y:n,z:r,m:a,spatialReference:s}}case"polygon":{const{rings:t,hasZ:n,hasM:r}=e;return{rings:p(t),hasZ:n,hasM:r,spatialReference:s}}case"polyline":{const{paths:t,hasZ:n,hasM:r}=e;return{paths:p(t),hasZ:n,hasM:r,spatialReference:s}}case"extent":{const{xmin:t,xmax:n,ymin:r,ymax:a,zmin:i,zmax:o,mmin:m,mmax:l,hasZ:c,hasM:u}=e;return{xmin:t,xmax:n,ymin:r,ymax:a,zmin:i,zmax:o,mmin:m,mmax:l,hasZ:c,hasM:u,spatialReference:s}}case"multipoint":{const{points:t,hasZ:n,hasM:r}=e;return{points:d(t)?h(t):t,hasZ:n,hasM:r,spatialReference:s}}default:return}}function p(e){return y(e)?e.map(e=>h(e)):e}function h(e){return e.map(e=>Array.from(e))}function y(e){for(const t of e)if(0!==t.length)return d(t);return!1}function d(e){return e.length>0&&(n(e[0])||r(e[0]))}function x(e,t){if(!e)return null;let n;if(m(e)){if(null==t)return e.clone();if(m(t))return t.copy(e)}return null!=t?(n=t,n.x=e.x,n.y=e.y,n.spatialReference=e.spatialReference,e.hasZ?(n.z=e.z,n.hasZ=e.hasZ):(n.z=void 0,n.hasZ=!1),e.hasM?(n.m=e.m,n.hasM=!0):(n.m=void 0,n.hasM=!1)):(n=i(e.x,e.y,e.z,e.spatialReference),e.hasM&&(n.m=e.m,n.hasM=!0)),n}function k(e){const{wkid:t,wkt:n,wkt2:r,latestWkid:s}=e,i={wkid:t,wkt:n,wkt2:r,latestWkid:s};return a.fromJSON(i)}export{x as clonePoint,u as hydrateGeometry,c as hydrateGraphic,k as hydratedSpatialReference,o as isHydratedGeometry,l as isHydratedGraphic,m as isHydratedPoint};
