/*
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/HandleOwner","../../../../../core/accessorSupport/decorators/property","../../../../../core/arrayUtils","../../../../../core/has","../../../../../core/accessorSupport/ensureType","../../../../../core/accessorSupport/decorators/subclass","../../../../../chunks/vec3f64","../../../../../core/workers/WorkerHandle","../../../../../chunks/sphere","../../../../../support/elevationInfoUtils","../../candidates/EdgeSnappingCandidate","../../candidates/VertexSnappingCandidate"],(function(e,t,n,r,o,i,a,c,s,d,p,l,u,h,f){"use strict";e.SceneLayerSnappingSourceWorkerHandle=function(e){function n(t){var n;return(n=e.call(this,t)||this).availability=0,n._ids=new Set,n.tmpP=d.create(),n}t._inheritsLoose(n,e);var r=n.prototype;return r.destroy=function(){this.workerHandle.destroy(),this.workerHandle=null},r.initialize=function(){this.workerHandle=new y(this.schedule,{fetchAllEdgeLocations:(e,t)=>this._fetchAllEdgeLocations(e,t)})},r.fetchCandidates=function(){var e=t._asyncToGenerator((function*(e,t){const n=e.coordinateHelper.toXYZ(e.point);this.view.renderCoordsHelper.toRenderCoords(n,e.coordinateHelper.spatialReference,n);const r="number"==typeof e.distance?e.distance:e.distance.pixelSize,o=yield this.workerHandle.invoke({bounds:l.fromValues(n[0],n[1],n[2],r),types:e.types},t),i=e.coordinateHelper;return o.candidates.sort(((e,t)=>e.distance-t.distance)),o.candidates.map((e=>this._convertCandidate(i,e)))}));function n(t,n){return e.apply(this,arguments)}return n}(),r.add=function(){var e=t._asyncToGenerator((function*(e,t){this._ids.add(e.id),yield this.workerHandle.invokeMethod("add",e,t)}));function n(t,n){return e.apply(this,arguments)}return n}(),r.remove=function(){var e=t._asyncToGenerator((function*(e,t){this._ids.delete(e.id),yield this.workerHandle.invokeMethod("remove",e,t)}));function n(t,n){return e.apply(this,arguments)}return n}(),r._convertCandidate=function(e,t){switch(t.type){case"edge":return new h.EdgeSnappingCandidate({coordinateHelper:e,objectId:t.objectId,targetPoint:this._convertRenderCoordinate(e,t.target),edgeStart:this._convertRenderCoordinate(e,t.start),edgeEnd:this._convertRenderCoordinate(e,t.end),elevationInfo:u.absoluteHeightElevationInfo});case"vertex":return new f.VertexSnappingCandidate({coordinateHelper:e,objectId:t.objectId,targetPoint:this._convertRenderCoordinate(e,t.target),elevationInfo:u.absoluteHeightElevationInfo})}},r._convertRenderCoordinate=function(e,t){return this.view.renderCoordsHelper.fromRenderCoords(t,this.tmpP,e.spatialReference),e.fromXYZ(this.tmpP)},r._fetchAllEdgeLocations=function(){var e=t._asyncToGenerator((function*(e,n){var r=this;const o=[],i=[];for(const{id:a,uid:c}of e.components)this._ids.has(a)&&o.push(t._asyncToGenerator((function*(){const e=yield r.fetchEdgeLocations(a,n.signal);return i.push(e.locations.buffer),{id:a,uid:c,objectIds:e.objectIds,locations:e.locations.buffer,origin:e.origin,type:e.type}}))());return{result:{components:(yield Promise.all(o)).filter((({id:e})=>this._ids.has(e)))},transferList:i}}));function n(t,n){return e.apply(this,arguments)}return n}(),n}(r.HandleOwner),n.__decorate([o.property({constructOnly:!0})],e.SceneLayerSnappingSourceWorkerHandle.prototype,"view",void 0),n.__decorate([o.property({constructOnly:!0})],e.SceneLayerSnappingSourceWorkerHandle.prototype,"fetchEdgeLocations",void 0),n.__decorate([o.property({constructOnly:!0})],e.SceneLayerSnappingSourceWorkerHandle.prototype,"schedule",void 0),n.__decorate([o.property({readOnly:!0})],e.SceneLayerSnappingSourceWorkerHandle.prototype,"availability",void 0),e.SceneLayerSnappingSourceWorkerHandle=n.__decorate([s.subclass("esri.views.interactive.snapping.featureSources.sceneLayerSource.SceneLayerSnappingSourceWorker")],e.SceneLayerSnappingSourceWorkerHandle);let y=function(e){function n(t,n){return e.call(this,"SceneLayerSnappingSourceWorker","fetchCandidates",{},t,{strategy:"dedicated",client:n})||this}return t._inheritsLoose(n,e),n}(p.WorkerHandle);Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
