/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import{geodesicBuffer as e,buffer as t,convexHull as r,geodesicArea as n,planarArea as o,cut as i,planarLength as s}from"../../../geometry/geometryEngine.js";import a from"../../../geometry/Polyline.js";import{project as l,load as c}from"../../../geometry/projectionUtils.js";import p from"../../../geometry/SpatialReference.js";function f(e){return"polygon"===e.type||"polyline"===e.type}function u(e){return e.hasOwnProperty("points")}function y(e){return u(e)&&2===e.points.length}class g{createBuffer(r,n,o,i){if(Array.isArray(r)){if(r.length>0){const s=p.fromJSON(r[0].spatialReference);return s.isWGS84||s.isWebMercator?e(r,n,o,i):t(r,n,o,i)}return}const s=p.fromJSON(r.spatialReference);return s.isWGS84||s.isWebMercator?e(r,n[0],o):t(r,n[0],o)}createConvexHull(e){if(Array.isArray(e)){if(1===e.length&&y(e[0])){const t=r(e[0]);if(f(t))return t}return r(e,!0).filter(f)}const t=r(e);if(f(t))return t}calculateArea(e,t){const r=new p({wkid:e.spatialReference.wkid});return r.isWGS84||r.isWebMercator?parseFloat(n(e,t).toFixed(2)):parseFloat(o(e,t).toFixed(2))}mergeAggregatedToGeometries(e){const t=[],{line:r,multipoint:n,polygon:o}=e;return r&&t.push(r),n&&t.push(n),o&&t.push(o),t}getPercentageAlong(e,t,r){let n=e;const o=this._createPolyline(e.paths,r.wkid);if("point"===t.type){const e=t.x-.5,a=t.x+.5,c=[[[e,t.y-.5],[a,t.y+.5]]];n=this._createPolyline(c,t.spatialReference.wkid);n=l(n,r);const p=i(o,n);if(p.length>0){const e=s(o,"feet");let t;t=p[0].paths[0][0][0]===o.paths[0][0][0]?s(p[0],"feet"):s(p[1],"feet");return[t/e]}return[.5]}n=l(t,r);const a=i(o,n);if(a.length>0){const e=s(o,"feet");return[s(a[0],"feet")/e]}return[.5]}async projectGeometry(e,t){return await c(),l(e,t,{zConversionDisabled:!0})}_createPolyline(e,t){return new a({hasZ:!1,hasM:!0,paths:e,spatialReference:new p({wkid:t})})}}export{g as GeometryHandler};
