text: define(["exports","./when-54c2dc71","./Check-6c0211bc","./Math-1124a290","./Cartesian2-36f5627e","./Transforms-441ed215","./ComponentDatatype-a26dd044","./AttributeCompression-b0deedfd"],function(e,S,u,f,b,T,o,C){"use strict";function t(e,t){u.Check.typeOf.object("ellipsoid",e),this._ellipsoid=e,this._cameraPosition=new b.Cartesian3,this._cameraPositionInScaledSpace=new b.Cartesian3,this._distanceToLimbInScaledSpaceSquared=0,S.defined(t)&&(this.cameraPosition=t)}Object.defineProperties(t.prototype,{ellipsoid:{get:function(){return this._ellipsoid}},cameraPosition:{get:function(){return this._cameraPosition},set:function(e){var t=this._ellipsoid.transformPositionToScaledSpace(e,this._cameraPositionInScaledSpace),i=b.Cartesian3.magnitudeSquared(t)-1;b.Cartesian3.clone(e,this._cameraPosition),this._cameraPositionInScaledSpace=t,this._distanceToLimbInScaledSpaceSquared=i}}});var s=new b.Cartesian3;t.prototype.isPointVisible=function(e){return x(this._ellipsoid.transformPositionToScaledSpace(e,s),this._cameraPositionInScaledSpace,this._distanceToLimbInScaledSpaceSquared)},t.prototype.isScaledSpacePointVisible=function(e){return x(e,this._cameraPositionInScaledSpace,this._distanceToLimbInScaledSpaceSquared)};var n=new b.Cartesian3;t.prototype.isScaledSpacePointVisiblePossiblyUnderEllipsoid=function(e,t){var i,r=this._ellipsoid,a=S.defined(t)&&t<0&&r.minimumRadius>-t?((i=n).x=this._cameraPosition.x/(r.radii.x+t),i.y=this._cameraPosition.y/(r.radii.y+t),i.z=this._cameraPosition.z/(r.radii.z+t),i.x*i.x+i.y*i.y+i.z*i.z-1):(i=this._cameraPositionInScaledSpace,this._distanceToLimbInScaledSpaceSquared);return x(e,i,a)},t.prototype.computeHorizonCullingPoint=function(e,t,i){return l(this._ellipsoid,e,t,i)};var c=b.Ellipsoid.clone(b.Ellipsoid.UNIT_SPHERE);t.prototype.computeHorizonCullingPointPossiblyUnderEllipsoid=function(e,t,i,r){return l(d(this._ellipsoid,i,c),e,t,r)},t.prototype.computeHorizonCullingPointFromVertices=function(e,t,i,r,a){return h(this._ellipsoid,e,t,i,r,a)},t.prototype.computeHorizonCullingPointFromVerticesPossiblyUnderEllipsoid=function(e,t,i,r,a,n){return h(d(this._ellipsoid,a,c),e,t,i,r,n)};var m=[];t.prototype.computeHorizonCullingPointFromRectangle=function(e,t,i){u.Check.typeOf.object("rectangle",e);var r=b.Rectangle.subsample(e,t,0,m),a=T.BoundingSphere.fromPoints(r);if(!(b.Cartesian3.magnitude(a.center)<.1*t.minimumRadius))return this.computeHorizonCullingPoint(a.center,r,i)};var a=new b.Cartesian3;function d(e,t,i){var r;return S.defined(t)&&t<0&&e.minimumRadius>-t&&(r=b.Cartesian3.fromElements(e.radii.x+t,e.radii.y+t,e.radii.z+t,a),e=b.Ellipsoid.fromCartesian3(r,i)),e}function l(e,t,i,r){u.Check.typeOf.object("directionToPoint",t),u.Check.defined("positions",i),S.defined(r)||(r=new b.Cartesian3);for(var a=v(e,t),n=0,o=0,s=i.length;o<s;++o){var c=M(e,i[o],a);if(c<0)return;n=Math.max(n,c)}return P(a,n,r)}var p=new b.Cartesian3;function h(e,t,i,r,a,n){u.Check.typeOf.object("directionToPoint",t),u.Check.defined("vertices",i),u.Check.typeOf.number("stride",r),S.defined(n)||(n=new b.Cartesian3),r=S.defaultValue(r,3),a=S.defaultValue(a,b.Cartesian3.ZERO);for(var o=v(e,t),s=0,c=0,m=i.length;c<m;c+=r){p.x=i[c]+a.x,p.y=i[c+1]+a.y,p.z=i[c+2]+a.z;var d=M(e,p,o);if(d<0)return;s=Math.max(s,d)}return P(o,s,n)}function x(e,t,i){var r=t,a=i,n=b.Cartesian3.subtract(e,r,s),o=-b.Cartesian3.dot(n,r);return!(a<0?0<o:a<o&&o*o/b.Cartesian3.magnitudeSquared(n)>a)}var y=new b.Cartesian3,g=new b.Cartesian3;function M(e,t,i){var r=e.transformPositionToScaledSpace(t,y),a=b.Cartesian3.magnitudeSquared(r),n=Math.sqrt(a),o=b.Cartesian3.divideByScalar(r,n,g),a=Math.max(1,a),s=1/(n=Math.max(1,n));return 1/(b.Cartesian3.dot(o,i)*s-b.Cartesian3.magnitude(b.Cartesian3.cross(o,i,o))*(Math.sqrt(a-1)*s))}function P(e,t,i){if(!(t<=0||t===1/0||t!=t))return b.Cartesian3.multiplyByScalar(e,t,i)}var i=new b.Cartesian3;function v(e,t){return b.Cartesian3.equals(t,b.Cartesian3.ZERO)?t:(e.transformPositionToScaledSpace(t,i),b.Cartesian3.normalize(i,i))}var z=Object.freeze({NONE:0,BITS12:1}),E=new b.Cartesian3,N=new b.Cartesian3,I=new b.Cartesian2,B=new T.Matrix4,_=new T.Matrix4,w=Math.pow(2,12);function r(e,t,i,r,a,n){var o,s,c,m,d,u,l,p,h,f,C,x,y=z.NONE;S.defined(e)&&S.defined(t)&&S.defined(i)&&S.defined(r)&&(s=e.minimum,c=e.maximum,m=b.Cartesian3.subtract(c,s,N),d=i-t,y=Math.max(b.Cartesian3.maximumComponent(m),d)<w-1?z.BITS12:z.NONE,u=e.center,l=T.Matrix4.inverseTransformation(r,new T.Matrix4),p=b.Cartesian3.negate(s,E),T.Matrix4.multiply(T.Matrix4.fromTranslation(p,B),l,l),(h=E).x=1/m.x,h.y=1/m.y,h.z=1/m.z,T.Matrix4.multiply(T.Matrix4.fromScale(h,B),l,l),o=T.Matrix4.clone(r),T.Matrix4.setTranslation(o,b.Cartesian3.ZERO,o),r=T.Matrix4.clone(r,new T.Matrix4),f=T.Matrix4.fromTranslation(s,B),C=T.Matrix4.fromScale(m,_),x=T.Matrix4.multiply(f,C,B),T.Matrix4.multiply(r,x,r),T.Matrix4.multiply(o,x,o)),this.quantization=y,this.minimumHeight=t,this.maximumHeight=i,this.center=u,this.toScaledENU=l,this.fromScaledENU=r,this.matrix=o,this.hasVertexNormals=a,this.hasWebMercatorT=S.defaultValue(n,!1)}r.prototype.encode=function(e,t,i,r,a,n,o){var s,c,m,d,u,l,p=r.x,h=r.y;return this.quantization===z.BITS12?((i=T.Matrix4.multiplyByPoint(this.toScaledENU,i,E)).x=f.CesiumMath.clamp(i.x,0,1),i.y=f.CesiumMath.clamp(i.y,0,1),i.z=f.CesiumMath.clamp(i.z,0,1),s=this.maximumHeight-this.minimumHeight,c=f.CesiumMath.clamp((a-this.minimumHeight)/s,0,1),b.Cartesian2.fromElements(i.x,i.y,I),m=C.AttributeCompression.compressTextureCoordinates(I),b.Cartesian2.fromElements(i.z,c,I),d=C.AttributeCompression.compressTextureCoordinates(I),b.Cartesian2.fromElements(p,h,I),u=C.AttributeCompression.compressTextureCoordinates(I),e[t++]=m,e[t++]=d,e[t++]=u,this.hasWebMercatorT&&(b.Cartesian2.fromElements(o,0,I),l=C.AttributeCompression.compressTextureCoordinates(I),e[t++]=l)):(b.Cartesian3.subtract(i,this.center,E),e[t++]=E.x,e[t++]=E.y,e[t++]=E.z,e[t++]=a,e[t++]=p,e[t++]=h,this.hasWebMercatorT&&(e[t++]=o)),this.hasVertexNormals&&(e[t++]=C.AttributeCompression.octPackFloat(n)),t},r.prototype.decodePosition=function(e,t,i){if(S.defined(i)||(i=new b.Cartesian3),t*=this.getStride(),this.quantization!==z.BITS12)return i.x=e[t],i.y=e[t+1],i.z=e[t+2],b.Cartesian3.add(i,this.center,i);var r=C.AttributeCompression.decompressTextureCoordinates(e[t],I);i.x=r.x,i.y=r.y;var a=C.AttributeCompression.decompressTextureCoordinates(e[t+1],I);return i.z=a.x,T.Matrix4.multiplyByPoint(this.fromScaledENU,i,i)},r.prototype.decodeTextureCoordinates=function(e,t,i){return S.defined(i)||(i=new b.Cartesian2),t*=this.getStride(),this.quantization===z.BITS12?C.AttributeCompression.decompressTextureCoordinates(e[t+2],i):b.Cartesian2.fromElements(e[t+4],e[t+5],i)},r.prototype.decodeHeight=function(e,t){return t*=this.getStride(),this.quantization!==z.BITS12?e[t+3]:C.AttributeCompression.decompressTextureCoordinates(e[t+1],I).y*(this.maximumHeight-this.minimumHeight)+this.minimumHeight},r.prototype.decodeWebMercatorT=function(e,t){return t*=this.getStride(),this.quantization===z.BITS12?C.AttributeCompression.decompressTextureCoordinates(e[t+3],I).x:e[t+6]},r.prototype.getOctEncodedNormal=function(e,t,i){var r=e[t=(t+1)*this.getStride()-1]/256,a=Math.floor(r),n=256*(r-a);return b.Cartesian2.fromElements(a,n,i)},r.prototype.getStride=function(){var e;switch(this.quantization){case z.BITS12:e=3;break;default:e=6}return this.hasWebMercatorT&&++e,this.hasVertexNormals&&++e,e};var A={position3DAndHeight:0,textureCoordAndEncodedNormals:1},q={compressed0:0,compressed1:1};r.prototype.getAttributes=function(e){var t,i=o.ComponentDatatype.FLOAT,r=o.ComponentDatatype.getSizeInBytes(i);if(this.quantization===z.NONE){var a=2;return this.hasWebMercatorT&&++a,this.hasVertexNormals&&++a,[{index:A.position3DAndHeight,vertexBuffer:e,componentDatatype:i,componentsPerAttribute:4,offsetInBytes:0,strideInBytes:t=(4+a)*r},{index:A.textureCoordAndEncodedNormals,vertexBuffer:e,componentDatatype:i,componentsPerAttribute:a,offsetInBytes:4*r,strideInBytes:t}]}var n=3;return(this.hasWebMercatorT||this.hasVertexNormals)&&++n,this.hasWebMercatorT&&this.hasVertexNormals?[{index:q.compressed0,vertexBuffer:e,componentDatatype:i,componentsPerAttribute:n,offsetInBytes:0,strideInBytes:t=(n+1)*r},{index:q.compressed1,vertexBuffer:e,componentDatatype:i,componentsPerAttribute:1,offsetInBytes:n*r,strideInBytes:t}]:[{index:q.compressed0,vertexBuffer:e,componentDatatype:i,componentsPerAttribute:n}]},r.prototype.getAttributeLocations=function(){return this.quantization===z.NONE?A:q},r.clone=function(e,t){return S.defined(t)||(t=new r),t.quantization=e.quantization,t.minimumHeight=e.minimumHeight,t.maximumHeight=e.maximumHeight,t.center=b.Cartesian3.clone(e.center),t.toScaledENU=T.Matrix4.clone(e.toScaledENU),t.fromScaledENU=T.Matrix4.clone(e.fromScaledENU),t.matrix=T.Matrix4.clone(e.matrix),t.hasVertexNormals=e.hasVertexNormals,t.hasWebMercatorT=e.hasWebMercatorT,t},e.EllipsoidalOccluder=t,e.TerrainEncoding=r});
  //# sourceMappingURL=TerrainEncoding-ec57b7fa.js.map
  