/*
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","../../../../core/mathUtils","../../../ViewingMode"],(function(e,t,a,i){"use strict";function n(e,t){return new p(e,g,t)}function r(e,t){const{curvatureDependent:a,scaleStart:i,scaleFallOffRange:n}=g;return new p(e,{curvatureDependent:{min:{curvature:a.min.curvature,tiltAngle:a.min.tiltAngle,scaleFallOffFactor:v.curvatureDependent.min.scaleFallOffFactor},max:{curvature:a.max.curvature,tiltAngle:a.max.tiltAngle,scaleFallOffFactor:v.curvatureDependent.max.scaleFallOffFactor}},scaleStart:i,scaleFallOffRange:n,minPixelSize:v.minPixelSize},t)}function l(e){return Math.abs(e*e*e)}function c(e,t,a){const i=a.parameters,n=a.paddingPixelsOverride;return P.scale=Math.min(i.divisor/(t-i.offset),1),P.factor=l(e),P.minPixelSize=i.minPixelSize,P.paddingPixels=n,P}function s(e,t){return 0===e?t.minPixelSize:t.minPixelSize*(1+2*t.paddingPixels/e)}function o(e,t){return Math.max(a.lerp(e*t.scale,e,t.factor),s(e,t))}function u(e,t,a){const i=c(e,t,a);return i.minPixelSize=0,i.paddingPixels=0,o(1,i)}function d(e,t,a,i){i.scale=u(e,t,a),i.factor=0,i.minPixelSize=a.parameters.minPixelSize,i.paddingPixels=a.paddingPixelsOverride}function f(e,t,a=[0,0]){const i=Math.min(Math.max(t.scale,s(e[1],t)/Math.max(1e-5,e[1])),1);return a[0]=e[0]*i,a[1]=e[1]*i,a}function m(e,t,a,i){return o(e,c(t,a,i))}let p=function(){function e(e,t,a,n=h(),r){this.viewingMode=e,this.description=t,this.ellipsoidRadius=a,this.parameters=n,this._paddingPixelsOverride=r,this.viewingMode===i.ViewingMode.Local?(this.coverageCompensation=this._surfaceCoverageCompensationLocal,this.calculateCurvatureDependentParameters=this._calculateCurvatureDependentParametersLocal):(this.coverageCompensation=this._surfaceCoverageCompensationGlobal,this.calculateCurvatureDependentParameters=this._calculateCurvatureDependentParametersGlobal)}var n=e.prototype;return n.update=function(e){return(!this.parameters||this.parameters.camera.fovY!==e.fovY||this.parameters.camera.distance!==e.distance)&&(this._calculateParameters(e,this.ellipsoidRadius,this.parameters),!0)},n.overridePadding=function(t){return t!==this.paddingPixelsOverride?new e(this.viewingMode,this.description,this.ellipsoidRadius,this.parameters,t):this},n._calculateParameters=function(e,t,a){const{scaleStart:i,scaleFallOffRange:n,minPixelSize:r}=this.description,{fovY:l,distance:c}=e,s=this.calculateCurvatureDependentParameters(e,t),o=this.coverageCompensation(e,t,s),{tiltAngle:u,scaleFallOffFactor:d}=s,f=Math.sin(u)*c,m=.5*Math.PI-u-l*(.5-i*o),p=f/Math.cos(m),g=m+l*n*o,v=(p-d*(f/Math.cos(g)))/(1-d);return a.camera.fovY=e.fovY,a.camera.distance=e.distance,a.offset=v,a.divisor=p-v,a.minPixelSize=r,a},n._calculateCurvatureDependentParametersLocal=function(e,t,a=x){return a.tiltAngle=this.description.curvatureDependent.min.tiltAngle,a.scaleFallOffFactor=this.description.curvatureDependent.min.scaleFallOffFactor,a},n._calculateCurvatureDependentParametersGlobal=function(e,t,i=x){const n=this.description.curvatureDependent,r=1+e.distance/t,l=Math.sqrt(r*r-1),[c,s]=[n.min.curvature,n.max.curvature],o=a.clamp((l-c)/(s-c),0,1),[u,d]=[n.min,n.max];return i.tiltAngle=a.lerp(u.tiltAngle,d.tiltAngle,o),i.scaleFallOffFactor=a.lerp(u.scaleFallOffFactor,d.scaleFallOffFactor,o),i},n._surfaceCoverageCompensationLocal=function(e,t,a){return(e.fovY-a.tiltAngle)/e.fovY},n._surfaceCoverageCompensationGlobal=function(e,t,a){const i=t*t,n=a.tiltAngle+.5*Math.PI,{fovY:r,distance:l}=e,c=l*l+i-2*Math.cos(n)*l*t,s=Math.sqrt(c),o=Math.sqrt(c-i);return(Math.acos(o/s)-Math.asin(t/(s/Math.sin(n)))+.5*r)/r},t._createClass(e,[{key:"paddingPixelsOverride",get:function(){return this._paddingPixelsOverride||this.parameters.paddingPixels}}]),e}();const g={curvatureDependent:{min:{curvature:a.deg2rad(10),tiltAngle:a.deg2rad(12),scaleFallOffFactor:.5},max:{curvature:a.deg2rad(70),tiltAngle:a.deg2rad(40),scaleFallOffFactor:.8}},scaleStart:.3,scaleFallOffRange:.65,minPixelSize:0},v={curvatureDependent:{min:{scaleFallOffFactor:.7},max:{scaleFallOffFactor:.95}},minPixelSize:14};function h(){return{camera:{distance:0,fovY:0},divisor:0,offset:0,minPixelSize:0,paddingPixels:0}}const P={scale:0,factor:0,minPixelSize:0,paddingPixels:0},x={tiltAngle:0,scaleFallOffFactor:0};e.applyPrecomputedScaleFactor=f,e.applyScaleFactor=o,e.getLabelSettings=r,e.getSettings=n,e.precomputeScaleFactor=d,e.scale=m,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
