/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import{throwIfAborted as e}from"../../../../core/promiseUtils.js";import{create as o}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import t from"../../../../geometry/SpatialReference.js";import{projectPointToVectorAsync as r}from"../../../../geometry/projection/projectPointToVector.js";import{makeDehydratedPoint as i}from"../../../../layers/graphics/dehydratedPoint.js";import{getGeometryEffectiveElevationInfo as n}from"../../../../support/elevationInfoUtils.js";import{evaluateElevationInfoAtPoint as s,SampleElevationInfo as a}from"./elevationAlignmentUtils.js";import{ElevationContext as p}from"./ElevationContext.js";import{extractExpressionInfo as f,createContext as c}from"./featureExpressionInfoUtils.js";async function l(l,m,d,j,u){const{elevationProvider:v,renderCoordsHelper:g}=l,{elevationInfo:I}=m,{pointsInFeatures:x,spatialReference:y}=j,h=t.fromJSON(y),w=f(I,!0),R=await c(w,h,u);e(u);const S=[],b=new Set,z=new Set,E=new p,F=i(0,0,0,t.WGS84),P=new a,U=o();F.spatialReference=h;const C=l.elevationProvider.spatialReference??l.spatialReference;for(const{objectId:e,points:o}of x){const t=d(e);if(null==t){for(const e of o)S.push(e.z??0);b.add(e);continue}t.isDraped&&z.add(e);const i=t.graphic.geometry;E.setFromElevationInfo(n(i,I)),R&&E.updateFeatureExpressionInfoContextForGraphic(R,t.graphic,m);for(const{x:e,y:n,z:a}of o)F.x=e,F.y=n,F.z=a??0,await r(F,U,C,{signal:u}),s(U,v,E,g,P),S.push(P.z)}return{elevations:S,drapedObjectIds:z,failedObjectIds:b}}export{l as elevationAlignPointsInFeatures};
