/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import{__decorate as e}from"tslib";import{dedupeResult as t}from"../../../../core/dedupeResult.js";import{isIterable as r}from"../../../../core/iteratorUtils.js";import{equalsShallow as i}from"../../../../core/lang.js";import{equalsMaybe as o}from"../../../../core/maybe.js";import{watch as n,sync as s}from"../../../../core/reactiveUtils.js";import{getMetersPerVerticalUnitForSR as l}from"../../../../core/units.js";import{property as a,subclass as c}from"../../../../core/accessorSupport/decorators.js";import{h as p}from"../../../../chunks/vec32.js";import{create as u}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{getReferenceEllipsoid as m}from"../../../../geometry/ellipsoidUtils.js";import{create as d,fromPoints as y}from"../../../../geometry/support/ray.js";import{GeometryDescriptor as f}from"../../../../layers/support/GeometryDescriptor.js";import{externalToInternalIntersectOptions as h,testGraphicUidFilter as v}from"../../support/hitTest.js";import{Intersector as _}from"../../webgl-engine/lib/Intersector.js";import{toGraphic as g}from"../../webgl-engine/lib/intersectorUtilsConversions.js";import{getVisibleLayerIds as w}from"../../../analysis/ElevationProfile/elevationProfileLayerUtils.js";import{ElevationProfileLineComputation as I}from"../../../analysis/ElevationProfile/ElevationProfileLineComputation.js";const b=2e5;let D=class extends I{constructor(){super(...arguments),this.type="scene",this.numSamplesForPreview=50,this.numSamplesPerChunk=25,this._getStableElevationDependencies=t(()=>{const e=this._view;return e?.ready?{view:e,stationary:e.stationary,geometry:this.controller?.analysis.geometry,visibleLayerIds:this._getStableLayerIds(),maxIntersectionDistance:this._maxIntersectionDistance,intersectOptions:this._intersectOptions,spatialReference:this._getStableSpatialReference()}:null},i),this._getStableSpatialReference=t(()=>this._view?.spatialReference,o),this._getStableLayerIds=t(()=>w(this._view),i),this._getStablePointCloudLayers=t(()=>{const e=this._view;return e?.ready?e.allLayerViews.toArray().filter(e=>"point-cloud"===e.layer?.type).map(e=>e.layer):[]},i),this._vecA=u(),this._vecB=u(),this._ray=d()}get minDemResolution(){const e=this._view;if(!e?.ready)return null;const t=e.pointsOfInterest?.focus?.worldUnitsPerContentPixel;return null==t?null:t*l(e.spatialReference)}initialize(){const e=()=>this.onInvalidate(this);return this.addHandles([n(()=>this._queryElevationDependencies,e,s),this.controller.onElevationChange(e)])}async queryElevation(e,{noDataValue:t,signal:r}){const i=this._queryElevationDependencies;if(null==i)throw new Error(`${this.declaredClass}: no dependencies`);const o=this._intersector;if(null==o)throw new Error(`${this.declaredClass}: no view`);const{intersectOptions:n,view:s,spatialReference:l}=i,a=s.renderCoordsHelper,c=s.sceneIntersectionHelper,u=this._vecA,m=this._vecA,d=this._vecB,h=this._ray;if(!l)return{geometry:e,noDataValue:t};const v=await f.fromGeometry(e).project(l,r);if(!v)return{geometry:e,noDataValue:t};const _=v.coordinates,g=_.length;for(let f=0;f<g;++f){const e=_[f];p(d,e.x,e.y,e.z??0),a.toRenderCoords(d,l,d),a.setAltitude(u,b,d);const r=y(u,d,h);c.computeIntersection(r,o,!0,n);const s=j(i,o.results.all);s?(s.getIntersectionPoint(m),a.fromRenderCoords(m,m,l),e.z=m[2]):e.z=t}return{geometry:v.export(),noDataValue:t}}get _queryElevationDependencies(){return this._getStableElevationDependencies()}get _intersectOptions(){const e=this._view;if(!e?.ready)return{};const{include:t,exclude:i}=this.profile;return h(e,{include:t,exclude:[...this._pointCloudLayers,...r(i)?i:i?[i]:[]]})}get _pointCloudLayers(){return this._getStablePointCloudLayers()}get _view(){const e=this.controller.view;return"3d"===e.type?e:null}get _maxIntersectionDistance(){const e=this._view;return e?.ready&&e.renderCoordsHelper?m(e.spatialReference).radius/e.renderCoordsHelper.unitInMeters:Number.POSITIVE_INFINITY}get _intersector(){const e=this._view;if(!e?.ready)return null;const t=new _(e.state.viewingMode),r=t.options;return r.hud=!1,r.invisibleTerrain=!1,r.backfacesTerrain=!1,r.selectionMode=!1,r.store=2,t}};function j({intersectOptions:e,maxIntersectionDistance:t,view:r},i){const o=e.graphics,n=!(!o?.include&&!o?.exclude);for(const s of i)if(s.withinDistance(t)){if(n){const e=g(s,r);if(null!=e&&!v(o,e))continue}return s}return null}e([a({readOnly:!0})],D.prototype,"minDemResolution",null),e([a()],D.prototype,"_queryElevationDependencies",null),e([a()],D.prototype,"_intersectOptions",null),e([a()],D.prototype,"_pointCloudLayers",null),e([a()],D.prototype,"_view",null),e([a()],D.prototype,"_maxIntersectionDistance",null),e([a()],D.prototype,"_intersector",null),D=e([c("esri.views.3d.analysis.ElevationProfile.ElevationProfileLineSceneComputation")],D);export{D as ElevationProfileLineSceneComputation};
