/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../../../../chunks/_rollupPluginBabelHelpers","../../../../chunks/tslib.es6","../../../../core/Accessor","../../../../core/maybe","../../../../core/screenUtils","../../../../core/accessorSupport/decorators/property","../../../../core/arrayUtils","../../../../core/has","../../../../core/accessorSupport/ensureType","../../../../core/accessorSupport/decorators/subclass","../../../../chunks/vec3","../../../../chunks/vec3f64","../../../../geometry/support/ray","../../../../geometry/support/vectorStacks","../../../../layers/graphics/dehydratedFeatures","./LineOfSightIntersectionResult","../../layers/i3s/Intersector","../../support/geometryUtils/ray","../../terrain/Intersector","../../webgl-engine/lib/Intersector","../../webgl-engine/lib/IntersectorInterfaces","../../webgl-engine/lib/intersectorUtilsConversions"],(function(e,t,r,n,s,i,o,c,a,l,p,u,d,y,h,g,I,f,v,m,S,w,R){"use strict";e.LineOfSightRayIntersector=function(e){function r(t){var r;return(r=e.call(this,t)||this)._terrainIntersectionOptionsLayerUids=new Set(["terrain"]),r}t._inheritsLoose(r,e);var n=r.prototype;return n.initialize=function(){this.intersector=S.newIntersector(this.view.state.viewingMode),this.intersector.options.hud=!1,this.intersector.options.store=w.StoreResults.MIN},n.getScreenPointIntersection=function(e){const t=i.screenPointObjectToArray(e,h.sv2d.get()),r=v.fromScreen(this.view.state.camera,t,C);return this._getRayIntersection(r)},n._getRayIntersection=function(e,t){if(s.isNone(e)||s.isNone(this.view.sceneIntersectionHelper))return null;this.intersector.options.store=w.StoreResults.MIN,this.view.sceneIntersectionHelper.intersectToolIntersectorRay(e,this.intersector,t);const r=this.intersector.results.min;if(!r.getIntersectionPoint(b))return null;const n=this.view.renderCoordsHelper.fromRenderCoords(b,this.view.spatialReference),i=d.fromArray(r.normal);if(f.isI3sIntersectorResult(r))return new I.LineOfSightIntersectionResult({type:w.IntersectorType.OBJECT,id:`${r.target.layerUid}/${r.target.nodeIndex}/${r.target.componentIndex}`,point:n,normal:i,ray:y.copy(e),graphic:null});if(m.isTerrainIntersectorResult(r))return new I.LineOfSightIntersectionResult({type:w.IntersectorType.TERRAIN,id:r.target.lij.slice(),point:n,normal:i,ray:y.copy(e),graphic:null});const o=R.toGraphic(r,this.view);if(s.isSome(o)){const t=o.layer,r=o.sourceLayer;let s;if(r)if("scene"===r.type)s=g.getObjectId(o,r.objectIdField);else s=o.uid;else s=o.uid;return new I.LineOfSightIntersectionResult({type:w.IntersectorType.OBJECT,id:`${t.uid}/${s}`,point:n,normal:i,ray:y.copy(e),graphic:o})}return null},n.updateFromGroundIntersection=function(e,t,r){const n=b,i=O,o=L,c=_,a=T;u.copy(i,e),this.view.renderCoordsHelper.worldUpAtPosition(i,o),u.normalize(o,o);const l=this.view.basemapTerrain.elevationBounds,p=this.view.renderCoordsHelper.getAltitude(i),h=l?Math.abs(l.max-l.min):100,g=p>0?1:-1;u.scale(c,o,g*(h+Math.abs(t))),u.add(n,i,c),y.fromPoints(n,i,C);const I=this._getRayIntersection(C,{include:this._terrainIntersectionOptionsLayerUids});return s.isSome(I)&&s.isSome(I.point)?(this.view.renderCoordsHelper.toRenderCoords(I.point,a),u.scale(c,o,g*t),u.add(r,a,c),d.clone(I.normal)):(u.copy(r,e),null)},r}(n),r.__decorate([o.property()],e.LineOfSightRayIntersector.prototype,"view",void 0),r.__decorate([o.property()],e.LineOfSightRayIntersector.prototype,"intersector",void 0),e.LineOfSightRayIntersector=r.__decorate([p.subclass("esri.views.3d.analysis.LineOfSight.LineOfSightRayIntersector")],e.LineOfSightRayIntersector);const b=d.create(),O=d.create(),L=d.create(),_=d.create(),T=d.create(),C=y.create();Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
