/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../../../../core/maybe","../../../ViewingMode","./I3SUtil","../../support/orientedBoundingBox","../../webgl-engine/lib/Intersector","../../webgl-engine/lib/IntersectorInterfaces","../../webgl-engine/lib/verticalOffsetUtils"],(function(e,t,i,n,r,s,l,o){"use strict";let d=function(){function e(e){this.type=l.IntersectorType.I3S,this._needVerticalOffset=!1,this.layerUid=e.layerUid,this.sublayerUid=e.sublayerUid,this.collection=e.collection,this.traverseNodeHierarchy=e.traverseNodeHierarchy,this.slicePlaneEnabled=e.slicePlaneEnabled,this.isGround=e.isGround}var d=e.prototype;return d.updateElevationAlignState=function(e,t){this._needVerticalOffset=e&&t===i.ViewingMode.Global},d.intersect=function(e,i,d,a){const u=e.results,b=e.options.store===l.StoreResults.ALL,f=e.ray.direction,y=e.tolerance;let h=e=>e,g=e=>e;const p=o.getVerticalOffsetI3S(t.isSome(e.verticalOffset)?e.verticalOffset:this._needVerticalOffset?0:null);t.isSome(e.verticalOffset)&&t.isSome(p)&&(h=e=>p.applyToMbs(e),g=e=>p.applyToObb(e)),this.traverseNodeHierarchy(((l,o)=>{if(0===l.childrenLoaded)return!1;const m=t.isSome(l.serviceObbInRenderSR)&&n.isValidObb(l.serviceObbInRenderSR)?l.serviceObbInRenderSR:null;return!(t.isSome(m)&&!r.intersectLine(g(m),d,f,y))&&(o&&(t.isSome(m)||!n.isValidMbs(l.renderMbs)||c(h(l.renderMbs),d,f,y))&&(t.isNone(l.geometryObb)||r.intersectLine(g(l.geometryObb),d,f,y))&&this.collection.intersect(o,d,a,y,p,((t,n,r,o)=>{if(n>=0){if(null!=i&&!i(d,a,n))return;const c=e=>{const i={layerUid:this.layerUid,sublayerUid:this.sublayerUid,nodeIndex:l.index,componentIndex:t,triangleNr:o};e.set(this.type,i,n,r)};if(this.isGround&&(null==u.ground.dist||n<u.ground.dist)&&c(u.ground),e.options.isFiltered)return;if((null==u.min.dist||n<u.min.dist)&&c(u.min),(null==u.max.dist||n>u.max.dist)&&c(u.max),b){const t=s.newIntersectorResult(e.ray);c(t),e.results.all.push(t)}}})),!0)}))},e}();function c(e,t,i,n=0){const r=e[3]+n,s=t[0]-e[0],l=t[1]-e[1],o=t[2]-e[2],d=i[0],c=i[1],a=i[2],u=d*s+c*l+a*o;return u*u-(d*d+c*c+a*a)*(s*s+l*l+o*o-r*r)>=0}e.I3SIntersectionHandler=d,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
