/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import{createArea as t}from"../../core/quantity.js";import{areaUnitFromSpatialReference as o}from"../../core/units.js";import{e as r}from"../../chunks/earcut.js";import{h as n,c as e,D as s}from"../../chunks/vec32.js";import{create as i}from"../../core/libs/gl-matrix-2/factories/vec3f64.js";import{projectVectorToVector as c}from"../../geometry/projection/projectVectorToVector.js";import{fromPoints as f,wrap as u,getNormal as l,projectPointLocal as m}from"../../geometry/support/plane.js";import{areaPoints2d as p}from"../../geometry/support/triangle.js";import{computeEuclideanMeasurementSR as a}from"./measurementUtils.js";function g(t,o=k()){return j(t,o)}function h(t,o=k()){return j(t,o,!1)}function j(r,g,h=r.hasZ){const j=a(r.spatialReference),k=o(j);if(null==k)return null;const x=(t,o)=>!(o.length<2)&&(n(t,o[0],o[1],h&&o[2]||0),!0);let C=0;for(const t of r.rings){const o=t.length;if(o<3)continue;const{positionsWorldCoords:a}=g;for(;a.length<o;)a.push(i());const h=y,k=n(d,0,0,0),R=1/o;for(let n=0;n<o;n++){if(!x(h,t[n]))return null;if(!c(h,r.spatialReference,a[n],j))return null;e(k,k,a[n],R)}const V=f(a[0],a[1],k,u());if(0===s(l(V)))continue;for(let t=0;t<o;t++)m(V,k,a[t],a[t]);const W=v(a);for(let t=0;t<W.length;t+=3)C+=p(a[W[t]],a[W[t+1]],a[W[t+2]])}return t(C,k)}const y=i(),d=i();function k(){return{positionsWorldCoords:[]}}function v(t){return r(x(t),[],2)}function x(t){const o=new Float64Array(2*t.length);for(let r=0;r<t.length;++r){const n=t[r],e=2*r;o[e]=n[0],o[e+1]=n[1]}return o}export{j as computeEuclideanPlanarArea,k as createEuclideanPlanarAreaCache,h as euclideanHorizontalPlanarArea,g as euclideanPlanarArea,v as triangulate};
