/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
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{set as n,scaleAndAdd as e,squaredLength as s}from"../../core/libs/gl-matrix-2/math/vec3.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 l,getNormal as u,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=x()){return h(t,o)}function j(t,o=x()){return h(t,o,!1)}function h(r,g,j=r.hasZ){const h=a(r.spatialReference),x=o(h);if(null==x)return null;const v=(t,o)=>!(o.length<2)&&(n(t,o[0],o[1],j&&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 j=y,x=n(d,0,0,0),R=1/o;for(let n=0;n<o;n++){if(!v(j,t[n]))return null;if(!c(j,r.spatialReference,a[n],h))return null;e(x,x,a[n],R)}const V=f(a[0],a[1],x,l());if(0===s(u(V)))continue;for(let t=0;t<o;t++)m(V,x,a[t],a[t]);const W=b(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,x)}const y=i(),d=i();function x(){return{positionsWorldCoords:[]}}function b(t){return r(v(t),[],2)}function v(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{h as computeEuclideanPlanarArea,x as createEuclideanPlanarAreaCache,j as euclideanHorizontalPlanarArea,g as euclideanPlanarArea,v as flatten2DVertexDataToArray,b as triangulate};
