/*
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/maybe","../../../../../core/promiseUtils","../../../../../core/Logger","../../../../../core/accessorSupport/ensureType","../../../../../core/arrayUtils","../../../../../core/has","../../../../../core/accessorSupport/set","../../../../../core/accessorSupport/decorators/subclass","../../../../../chunks/vec3","../../../../../chunks/vec3f64","../../../../../geometry/support/lineSegment","../../../../../chunks/sphere","../../../../../layers/graphics/data/QueryEngineResult","../../../../3d/webgl-engine/lib/Octree","../../../../3d/webgl-engine/lib/edgeRendering/EdgeProcessingWorker"],(function(e,n,t,o,i,s,r,c,d,a,u,p,h,g,l,f,_,m){"use strict";function y(){return new e.SceneLayerSnappingSourceWorker}e.SceneLayerSnappingSourceWorker=function(){function e(){this._idToComponent=new Map,this._components=new _((e=>e.bounds)),this._edges=new _((e=>e.bounds)),this._tmpLineSegment=g.create(),this._tmpP1=h.create(),this._tmpP2=h.create(),this._tmpP3=h.create(),this.remoteClient=null}var t=e.prototype;return t.fetchCandidates=function(){var e=n._asyncToGenerator((function*(e,n){yield Promise.resolve(),i.throwIfAborted(n),yield this._ensureEdgeLocations(e,n);const t=[];return this._edges.forEachNeighbor((n=>this._addCandidates(e,n,t)),e.bounds),{result:{candidates:t}}}));function t(n,t){return e.apply(this,arguments)}return t}(),t._ensureEdgeLocations=function(){var e=n._asyncToGenerator((function*(e,n){const t=[];if(this._components.forEachNeighbor((e=>{if(o.isNone(e.info)){const{id:n,uid:o}=e;t.push({id:n,uid:o})}}),e.bounds),!t.length)return;const i={components:t},s=yield this.remoteClient.invoke("fetchAllEdgeLocations",i,o.unwrapOr(n,{}));for(const o of s.components)this._setFetchEdgeLocations(o)}));function t(n,t){return e.apply(this,arguments)}return t}(),t.add=function(){var e=n._asyncToGenerator((function*(e){const n=new b(e.id,e.bounds);return this._idToComponent.set(n.id,n),this._components.add([n]),{result:{}}}));function t(n){return e.apply(this,arguments)}return t}(),t.remove=function(){var e=n._asyncToGenerator((function*(e){const n=this._idToComponent.get(e.id);if(n){const e=[];this._edges.forEachNeighbor((t=>{t.component===n&&e.push(t)}),n.bounds),this._edges.remove(e),this._components.remove([n]),this._idToComponent.delete(n.id)}return{result:{}}}));function t(n){return e.apply(this,arguments)}return t}(),t._setFetchEdgeLocations=function(e){const n=this._idToComponent.get(e.id);if(o.isNone(n)||e.uid!==n.uid)return;const t=m.extractComponentsEdgeLocationsLayout.createView(e.locations),i=new Array(t.count),s=h.create(),r=h.create();for(let o=0;o<t.count;o++){const c=l.create(),d=l.getCenter(c);t.position0.getVec(o,s),t.position1.getVec(o,r),p.scaleAndAdd(d,d,s,.5),p.scaleAndAdd(d,d,r,.5),p.add(d,d,e.origin),c[3]=p.distance(d,s);const a=new S(n,o,c);i[o]=a}this._edges.add(i);const{objectIds:c,origin:d}=e;n.info={locations:t,objectIds:c,origin:d}},t._addCandidates=function(e,n,t){const{locations:o,origin:i,objectIds:s}=n.component.info,r=o.position0.getVec(n.index,this._tmpP1),c=o.position1.getVec(n.index,this._tmpP2);p.add(r,r,i),p.add(c,c,i);const d=s[o.componentIndex.get(n.index)];this._addEdgeCandidate(e,d,r,c,t),this._addVertexCandidate(e,d,r,t),this._addVertexCandidate(e,d,c,t)},t._addEdgeCandidate=function(e,n,t,o,i){if(!(e.types&f.SnappingTypes.EDGE))return;const s=l.getCenter(e.bounds),r=g.fromPoints(t,o,this._tmpLineSegment),c=g.projectPoint(r,s,this._tmpP3);if(!l.containsPoint(e.bounds,c))return null;i.push({type:"edge",objectId:n,target:h.clone(c),distance:p.distance(s,c),start:h.clone(t),end:h.clone(o)})},t._addVertexCandidate=function(e,n,t,o){if(!(e.types&f.SnappingTypes.VERTEX))return;const i=l.getCenter(e.bounds);if(!l.containsPoint(e.bounds,t))return null;o.push({type:"vertex",objectId:n,target:h.clone(t),distance:p.distance(i,t)})},e}(),e.SceneLayerSnappingSourceWorker=t.__decorate([u.subclass("esri.views.interactive.snapping.featureSources.sceneLayerSource.SceneLayerSnappingSourceWorker")],e.SceneLayerSnappingSourceWorker);let b=function e(n,t){this.id=n,this.bounds=t,this.info=null,this.uid=++e.uid};b.uid=0;let S=function(e,n,t){this.component=e,this.index=n,this.bounds=t};e.default=y,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
