/* COPYRIGHT Esri - https://js.arcgis.com/5.0.18/LICENSE.txt */
import{rad2deg as t}from"../../../core/mathUtils.js";import{getMetersPerUnitForSR as e,getMetersPerCartesianUnitForSR as o}from"../../../core/units.js";import{set as r}from"../../../core/libs/gl-matrix-2/math/mat4.js";import{copy as i}from"../../../core/libs/gl-matrix-2/math/vec3.js";import{getReferenceEllipsoid as s}from"../../../geometry/ellipsoidUtils.js";import{getSphericalPCPF as n}from"../../../geometry/spatialReferenceEllipsoidUtils.js";import{projectPointToVector as a}from"../../../geometry/projection/projectPointToVector.js";import{projectVectorToPoint as m}from"../../../geometry/projection/projectVectorToPoint.js";import{projectVectorToVector as c}from"../../../geometry/projection/projectVectorToVector.js";import{create as l}from"../../../geometry/support/aaBoundingRect.js";import{create as p,setExtent as d,getExtent as h,altitudeAt as u,setAltitudeAt as y,setAltitudeOfTransformation as f,normalAt as g,axisAt as S,elevate as j,intersectRayClosestSilhouette as _,intersectRay as P,createGlobal as w,createLocal as A}from"../../../geometry/support/coordinateSystem.js";import{intersectRay as C}from"../../../geometry/support/plane.js";import{angleAroundAxis as R}from"../../../geometry/support/vector.js";import{sv3d as M}from"../../../geometry/support/vectorStacks.js";import{isDehydratedPoint as U}from"../../../layers/graphics/dehydratedFeatureUtils.js";class v{constructor(t,e,o,r){this.viewingMode=t,this.spatialReference=e,this.unitInMeters=o,this._coordinateSystem=r,this._tmpCoordinateSystem=p(r),this.referenceEllipsoid=s(e),this.sphericalPCPF=n(e)}set extent(t){t&&d(this._coordinateSystem,t,this._coordinateSystem)}get extent(){return h(this._coordinateSystem,l())}getAltitude(t){return u(this._coordinateSystem,t)}setAltitude(t,e,o=t){return y(this._coordinateSystem,o,e,t)}setAltitudeOfTransformation(t,e){f(this._coordinateSystem,e,t,e)}worldUpAtPosition(t,e){return g(this._coordinateSystem,t,e)}worldBasisAtPosition(t,e,o){return S(this._coordinateSystem,t,e,o)}basisMatrixAtPosition(t,e){const o=this.worldBasisAtPosition(t,0,M.get()),i=this.worldBasisAtPosition(t,1,M.get()),s=this.worldBasisAtPosition(t,2,M.get());return r(e,o[0],o[1],o[2],0,i[0],i[1],i[2],0,s[0],s[1],s[2],0,0,0,0,1),e}headingAtPosition(e,o){const r=this.worldUpAtPosition(e,M.get()),i=this.worldBasisAtPosition(e,1,M.get()),s=R(o,i,r);return t(s)}intersectManifoldClosestSilhouette(t,e,o){return j(this._coordinateSystem,e,this._tmpCoordinateSystem),_(this._tmpCoordinateSystem,t,o),o}intersectManifold(t,e,o){j(this._coordinateSystem,e,this._tmpCoordinateSystem);const r=M.get();return P(this._tmpCoordinateSystem,t,r)?i(o,r):null}intersectInfiniteManifold(t,e,o){if(1===this.viewingMode)return this.intersectManifold(t,e,o);j(this._coordinateSystem,e,this._tmpCoordinateSystem);const r=this._tmpCoordinateSystem.value,s=M.get();return C(r.plane,t,s)?i(o,s):null}toRenderCoords(t,e,o){return U(t)?a(t,e,this.spatialReference):c(t,e,o,this.spatialReference)}fromRenderCoords(t,e,o=null){return U(e)?(null!=o&&(e.spatialReference=o),m(t,this.spatialReference,e)?e:null):c(t,this.spatialReference,e,o)?e:null}static create(t,o){switch(t){case 2:return new v(2,o,e(o),A());case 1:return new v(1,o,1,w(o))}}static renderUnitScaleFactor(t,e){return o(t)/o(e)}}export{v as RenderCoordsHelper};
