/*
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/mathUtils","../../../../core/reactiveUtils","../../../../core/screenUtils","../../../../core/accessorSupport/decorators/property","../../../../core/arrayUtils","../../../../core/has","../../../../core/accessorSupport/ensureType","../../../../core/accessorSupport/decorators/subclass","../../../../chunks/vec3","../../../../chunks/vec3f64","../../../../geometry/Point","../../../../geometry/support/ray","../PropertiesPool","./PointOfInterest","../../webgl-engine/lib/Camera","../../../support/Scheduler"],(function(e,t,r,o,n,i,s,c,a,d,u,p,l,h,y,_,f,g,P){"use strict";const S=Array;e.Focus=function(e){function r(r){var o;return(o=e.call(this,r)||this)._propertiesPool=new _.PropertiesPool({location:h,renderLocation:S},t._assertThisInitialized(o)),o._dirty=!0,o.renderLocation=o._propertiesPool.get("renderLocation"),o}t._inheritsLoose(r,e);var s=r.prototype;return s.initialize=function(){this.handles.add([n.watch((()=>this.centerOnSurface.renderLocation),(()=>this.updateRenderLocation())),n.watch((()=>this.state.contentCamera),(()=>this.updateRenderLocation()))]),this.scheduler&&this.handles.add(this.scheduler.registerTask(P.TaskPriority.POINT_OF_INTEREST_FREQUENT,this))},s.destroy=function(){this._propertiesPool.destroy(),this._propertiesPool=null},s.runTask=function(){const e=this._get("renderLocation"),t=this.centerOnSurface.renderLocation,r=this.renderCoordsHelper,n=this.state.contentCamera;this._dirty=!1,r.worldUpAtPosition(t,O);const i=Math.max(0,(Math.acos(p.dot(O,n.viewForward))-.5*Math.PI)*(n.aboveGround?1:-1));if(Number.isNaN(i)){if(!e||!p.equals(e,t)){const e=this._propertiesPool.get("renderLocation");p.copy(e,t),this._set("renderLocation",e)}return}const s=1-o.clamp(i/(.5*Math.PI),0,1),c=s*s*s;this._calculateScreenHorizontalEdgeOnSurface(m);const a=this._propertiesPool.get("renderLocation");p.lerp(a,t,m,c),e&&p.equals(e,a)||this._set("renderLocation",a)},s._calculateScreenHorizontalEdgeOnSurface=function(e){const t=this.state.contentCamera,r=t.getRenderCenter(i.createRenderScreenPointArray3());if(r[1]=t.aboveGround?t.padding[g.PaddingSide.BOTTOM]:t.fullHeight-t.padding[g.PaddingSide.TOP],this.estimateSurfaceIntersectionAtRenderPoint(r,e))return e;const o=this.renderCoordsHelper.getAltitude(this.centerOnSurface.renderLocation);if(t.unprojectFromRenderScreen(r,L)){p.subtract(L,L,t.eye);const r=p.normalize(L,L);if(this.renderCoordsHelper.intersectManifold(y.wrap(t.eye,r),o,e))return e}return this.renderCoordsHelper.setAltitude(e,o,t.eye)},s.updateRenderLocation=function(){this._dirty=!0},t._createClass(r,[{key:"updating",get:function(){return this._dirty||this.centerOnSurface.updating}},{key:"location",get:function(){const e=this._propertiesPool.get("location");return this.renderCoordsHelper.fromRenderCoords(this.renderLocation,e,this.state.spatialReference),e}},{key:"running",get:function(){return this._dirty}}]),r}(f.PointOfInterest),r.__decorate([s.property()],e.Focus.prototype,"_dirty",void 0),r.__decorate([s.property({constructOnly:!0})],e.Focus.prototype,"scheduler",void 0),r.__decorate([s.property({constructOnly:!0})],e.Focus.prototype,"centerOnSurface",void 0),r.__decorate([s.property({constructOnly:!0})],e.Focus.prototype,"estimateSurfaceIntersectionAtRenderPoint",void 0),r.__decorate([s.property({readOnly:!0})],e.Focus.prototype,"updating",null),r.__decorate([s.property({readOnly:!0})],e.Focus.prototype,"location",null),r.__decorate([s.property({readOnly:!0})],e.Focus.prototype,"renderLocation",void 0),e.Focus=r.__decorate([u.subclass("esri.views.3d.support.CenterOnSurface")],e.Focus);const O=l.create(),L=l.create(),m=l.create();Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
