/*
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/Error","../core/maybe","./vec3","./vec3f64","../geometry/projection","../geometry/support/aaBoundingRect","../views/3d/terrain/TerrainConst","../views/3d/terrain/TilingScheme"],(function(e,t,n,o,i,r,s,c,a){"use strict";const l=i.create(),u=i.create(),f=i.create(),h=i.create();function g(e,t,o=0){const i=e.extent;if(n.isNone(i))return!1;if(0===o)return s.containsPoint(i,t);const r=Math.min(i[2]-i[0],i[3]-i[1]);return s.containsPointWithMargin(i,t,o*r)}function m(e,t,n,i){o.copy(l,n),l[i]=t[i];const r=o.subtract(l,l,t),s=o.subtract(u,e,t),c=o.dot(s,r),a=o.dot(r,r);let f;f=c<=0?t:a<=c?n:o.add(l,t,o.scale(r,r,c/a));const h=o.subtract(l,e,f);return Math.PI/2-Math.atan(h[2]/Math.sqrt(h[0]*h[0]+h[1]*h[1]))}function p(e,t,o){const i=e.extent;if(n.isNone(i))return 0;f[0]=i[0],f[1]=i[1],f[2]=o,h[0]=i[2],h[1]=i[3],h[2]=o;let r=1/0,s=1/0;return t[0]<f[0]?r=m(t,f,h,0):t[0]>h[0]&&(r=m(t,h,f,0)),t[1]<f[1]?s=m(t,f,h,1):t[1]>h[1]&&(s=m(t,h,f,1)),Math.min(r,s)}function d(e,o,i){if(n.isNone(e))return a.getMissingTileInfoError();if(e.spatialReference.isGeographic&&!r.canProjectToWGS84ComparableLonLat(e.spatialReference))return new t("tilingscheme:local-unsupported-spatial-reference","The tiling scheme spatial reference is not supported in local scenes");const s=a.TilingScheme.checkUnsupported(e);if(n.isSome(s))return s;if(n.isNone(i))return new t("tilingscheme:extent-not-exist","The layer does not provide a layer extent.");const c=S(e,i);if(c)return c;const l=e.spatialReference;return n.isSome(o)&&!(l.equals(o)||o.isWGS84&&l.isWebMercator)?new t("tilingscheme:spatial-reference-mismatch","The tiling scheme does not match the spatial reference of the local scene"):null}function S(e,n){const o=e.lods,i=o[0].resolution*2**o[0].level,r=[i*e.size[0],i*e.size[1]],l=[e.origin.x,e.origin.y],u=s.fromExtent(n),f=s.create();a.TilingScheme.computeRowColExtent(u,r,l,f);const h=(f[2]-f[0])*(f[3]-f[1]);if(h>c.MAX_ROOT_TILES){const n=o[0].scale*2**o[0].level;let r=Math.max((u[3]-u[1])/e.size[1],(u[2]-u[0])/e.size[0])*n/i;const s=Math.floor(Math.log(r)/Math.log(10));return r=Math.ceil(r/10**s)*10**s,new t("tilingscheme:too-many-root-tiles","Scale of level 0 of the tiling scheme (1:"+Math.floor(n).toLocaleString()+") is too large for the layer's extent. Suggested scale: 1:"+r.toLocaleString()+".",{level0Scale:n,suggestedLevel0Scale:r,requiredNumRootTiles:h,allowedNumRootTiles:c.MAX_ROOT_TILES})}return null}const T=Object.freeze(Object.defineProperty({__proto__:null,isInsideExtent:g,tiltToExtentEdge:p,checkIfTileInfoSupportedForViewSR:d},Symbol.toStringTag,{value:"Module"}));e.checkIfTileInfoSupportedForViewSR=d,e.isInsideExtent=g,e.terrainUtilsPlanar=T,e.tiltToExtentEdge=p}));
