/*
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/Evented","../../../../core/Handles","../../../../core/maybe","../../../../core/accessorSupport/decorators/property","../../../../core/arrayUtils","../../../../core/has","../../../../core/accessorSupport/ensureType","../../../../core/accessorSupport/decorators/subclass","../../../../chunks/vec3f64","../../../../geometry/support/aaBoundingRect","../../../support/Scheduler"],(function(e,t,r,s,o,n,a,c,i,p,d,u,l,y,h){"use strict";e.SurfaceGeometryUpdates=function(e){function r(){var t;return(t=e.apply(this,arguments)||this).handles=new n,t._tileGeometryUpdateExtent=y.empty(),t._tileGeometryUpdateSpatialReference=null,t.events=new o,t.updating=!1,t}t._inheritsLoose(r,e);var s=r.prototype;return s.initialize=function(){this.handles.add([this.surface.on("elevation-change",(e=>this._tileGeometryChanged(e))),this.scheduler.registerTask(h.TaskPriority.SURFACE_GEOMETRY_UPDATES,this)])},s.destroy=function(){this.handles=a.destroyMaybe(this.handles)},s.runTask=function(){this.updating&&(this._centerIntersectsExtent(this._tileGeometryUpdateExtent,this._tileGeometryUpdateSpatialReference)&&this.events.emit("request-update",f),y.empty(this._tileGeometryUpdateExtent),this._set("updating",!1))},s._tileGeometryChanged=function(e){this._tileGeometryUpdateSpatialReference=e.spatialReference,y.expand(this._tileGeometryUpdateExtent,e.tile.extent,this._tileGeometryUpdateExtent),this._set("updating",!0)},s._furthestCenterOnSurface=function(){let e=this.centerOnSurfaces[0];for(let t=1;t<this.centerOnSurfaces.length;t++){const r=this.centerOnSurfaces[t];r.distance>e.distance&&(e=r)}return e},s._centerIntersectsExtent=function(e,t){const r=this.state.camera.eye,s=S,o=this._furthestCenterOnSurface();return this.renderCoordsHelper.fromRenderCoords(r,_,t),this.renderCoordsHelper.fromRenderCoords(o.renderLocation,m,t),_[0]<m[0]?(s[0]=_[0],s[2]=m[0]):(s[0]=m[0],s[2]=_[0]),_[1]<m[1]?(s[1]=_[1],s[3]=m[1]):(s[1]=m[1],s[3]=_[1]),y.intersects(s,e)},t._createClass(r,[{key:"running",get:function(){return this.updating}}]),r}(s),r.__decorate([c.property({constructOnly:!0})],e.SurfaceGeometryUpdates.prototype,"state",void 0),r.__decorate([c.property({constructOnly:!0})],e.SurfaceGeometryUpdates.prototype,"centerOnSurfaces",void 0),r.__decorate([c.property({constructOnly:!0})],e.SurfaceGeometryUpdates.prototype,"renderCoordsHelper",void 0),r.__decorate([c.property({constructOnly:!0})],e.SurfaceGeometryUpdates.prototype,"scheduler",void 0),r.__decorate([c.property({constructOnly:!0})],e.SurfaceGeometryUpdates.prototype,"surface",void 0),r.__decorate([c.property({readOnly:!0})],e.SurfaceGeometryUpdates.prototype,"updating",void 0),e.SurfaceGeometryUpdates=r.__decorate([u.subclass("esri.views.3d.support.SurfaceGeometryUpdates")],e.SurfaceGeometryUpdates);const f={},_=l.create(),m=l.create(),S=y.empty();Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
