/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
import{sub as e,length as t,scaleAndAdd as r}from"../core/libs/gl-matrix-2/math/vec3.js";import{create as l}from"../core/libs/gl-matrix-2/factories/vec3f64.js";import{create as n,fromPoints as o}from"../geometry/support/ray.js";import{toGraphic as u,hasLod as i,getIntersectedFeatureBSRadius as a}from"../views/3d/webgl-engine/lib/intersectorUtilsConversions.js";function c(e,t){return s(e)===s(t)}function s(e){if(null==e)return null;const t=null!=e.layer?e.layer.id:"";let r=null;return r=null!=e.objectId?e.objectId:null!=e.layer&&"objectIdField"in e.layer&&null!=e.layer.objectIdField&&null!=e.attributes?e.attributes[e.layer.objectIdField]:e.uid,null==r?null:`o-${t}-${r}`}const d={json:{write:{writer:b,target:{"feature.layerId":{type:[Number,String],isRequired:!0},"feature.objectId":{type:[Number,String],isRequired:!0}}},origins:{"web-scene":{read:f}}},clonable:"reference"};function b(e,t){null!=e?.layer?.objectIdField&&null!=e.attributes&&(t.feature={layerId:e.layer.id,objectId:e.attributes[e.layer.objectIdField]})}function f(e){if(null!=e.layerId&&null!=e.objectId)return{uid:null,layer:{id:e.layerId,objectIdField:"ObjectId"},attributes:{ObjectId:e.objectId}}}function I(n,i,a,c){const{sceneIntersectionHelper:d}=n,{observer:b,observerFeatureId:f,targetFeatureId:I,target:j}=a;if(null==f&&null==I)return;c||(c=e=>e),e(g,b,j);const p=t(g),S=1;r(g,b,g,S/p);const v=o(g,j,y);i.options.store=2,d.intersectToolIntersectorRay(v,i);let F=null,N=null,R=null,w=null;for(const e of i.results.all){const t=u(e,n);if(null==t||null==e.distanceInRenderSpace)continue;const r=s(t);null!=r&&(null!=f&&r===f&&(F??=c(m(e,n,p)),e.distanceInRenderSpace-S<F&&(R=e)),null!=I&&r===I&&(N??=c(m(e,n,p)),null==w&&e.distanceInRenderSpace-S<p&&p-e.distanceInRenderSpace+S<N&&(w=e)))}const{observerAdjusted:x,targetAdjusted:T}=a;R?.getIntersectionPoint(x)?a.observerSurfaceNormal=R.getTransformedNormal(l()):a.observerSurfaceNormal=null,w?.getIntersectionPoint(T)?a.targetSurfaceNormal=w.getTransformedNormal(l()):a.targetSurfaceNormal=null}function m(e,t,r){if(i(e)){const l=a(e,t);if(null!=l)return Math.min(l*j,r)}return 1e-5*r}const j=.05,y=n(),g=l();export{c as featureReferenceEquals,d as featureReferenceProperty,s as getFeatureId,I as updatePointsFromFeatureReference};
