define(["exports","./AttributeCompression-e18a879a","./Matrix2-163b5a1d","./Matrix3-b6f074fa","./defaultValue-0a909f67","./Math-e97915da","./Transforms-713aa3a8","./ComponentDatatype-77274976","./EncodedCartesian3-de837603","./GeometryAttribute-0b8b7b82","./IndexDatatype-2149f06c","./IntersectionTests-87baf287","./Plane-1c5a21a3"],(function(e,t,n,i,r,a,s,o,u,c,l,p,d){"use strict";const f=new i.Cartesian3,y=new i.Cartesian3,m=new i.Cartesian3;const C={calculateACMR:function(e){const t=(e=r.defaultValue(e,r.defaultValue.EMPTY_OBJECT)).indices;let n=e.maximumIndex;const i=r.defaultValue(e.cacheSize,24),a=t.length;if(!r.defined(n)){n=0;let e=0,i=t[e];for(;en&&(n=i),++e,i=t[e]}const s=[];for(let e=0;ei&&(s[t[e]]=o,++o);return(o-i+1)/(a/3)}};C.tipsify=function(e){const t=(e=r.defaultValue(e,r.defaultValue.EMPTY_OBJECT)).indices,n=e.maximumIndex,i=r.defaultValue(e.cacheSize,24);let a;function s(e,t,n,i,r,s,o){let u,c=-1,l=-1,p=0;for(;pl||-1===l)&&(l=u,c=e)),++p}return-1===c?function(e,t,n,i){for(;t.length>=1;){const n=t[t.length-1];if(t.splice(t.length-1,1),e[n].numLiveTriangles>0)return n}for(;a0)return++a,a-1;++a}return-1}(i,s,0,o):c}const o=t.length;let u=0,c=0,l=t[c];const p=o;if(r.defined(n))u=n+1;else{for(;cu&&(u=l),++c,l=t[c];if(-1===u)return 0;++u}const d=[];let f;for(f=0;fi&&(b.timeStamp=C,++C),++c}m=s(0,i,h,d,C,v,u)}return T};var h=C;const v={};function b(e,t,n,i,r){e[t++]=n,e[t++]=i,e[t++]=i,e[t++]=r,e[t++]=r,e[t]=n}function g(e){const t={};for(const n in e)if(e.hasOwnProperty(n)&&r.defined(e[n])&&r.defined(e[n].values)){const i=e[n];t[n]=new c.GeometryAttribute({componentDatatype:i.componentDatatype,componentsPerAttribute:i.componentsPerAttribute,normalize:i.normalize,values:[]})}return t}function A(e,t,n){for(const i in t)if(t.hasOwnProperty(i)&&r.defined(t[i])&&r.defined(t[i].values)){const r=t[i];for(let t=0;t=3){const n=6*(t-2),i=l.IndexDatatype.createTypedArray(t,n);b(i,0,e[0],e[1],e[2]);let r=6;for(let n=3;n0){const t=e.length-1,n=6*(t-1),i=l.IndexDatatype.createTypedArray(t,n),r=e[0];let a=0;for(let n=1;nr&&(r=n[e]);e.indices=h.tipsify({indices:n,maximumIndex:r,cacheSize:t})}return e},v.fitToUnsignedShortIndices=function(e){const t=[],n=c.Geometry.computeNumberOfVertices(e);if(r.defined(e.indices)&&n>=a.CesiumMath.SIXTY_FOUR_KILOBYTES){let n=[],i=[],s=0,o=g(e.attributes);const u=e.indices,l=u.length;let p;e.primitiveType===c.PrimitiveType.TRIANGLES?p=3:e.primitiveType===c.PrimitiveType.LINES?p=2:e.primitiveType===c.PrimitiveType.POINTS&&(p=1);for(let d=0;d=a.CesiumMath.SIXTY_FOUR_KILOBYTES&&(t.push(new c.Geometry({attributes:o,indices:i,primitiveType:e.primitiveType,boundingSphere:e.boundingSphere,boundingSphereCV:e.boundingSphereCV})),n=[],i=[],s=0,o=g(e.attributes))}0!==i.length&&t.push(new c.Geometry({attributes:o,indices:i,primitiveType:e.primitiveType,boundingSphere:e.boundingSphere,boundingSphereCV:e.boundingSphereCV}))}else t.push(e);return t};const T=new i.Cartesian3,x=new i.Cartographic;v.projectTo2D=function(e,t,n,a,u){const l=e.attributes[t],p=(u=r.defined(u)?u:new s.GeographicProjection).ellipsoid,d=l.values,f=new Float64Array(d.length);let y=0;for(let e=0;eT&&(T=n)}return new c.Geometry({attributes:m,indices:b,primitiveType:y,boundingSphere:r.defined(A)?new s.BoundingSphere(A,T):void 0})}v.combineInstances=function(e){const t=[],n=[],i=e.length;for(let a=0;a0&&a.push(L(t,"geometry")),n.length>0&&(a.push(L(n,"westHemisphereGeometry")),a.push(L(n,"eastHemisphereGeometry"))),a};const M=new i.Cartesian3,z=new i.Cartesian3,D=new i.Cartesian3,G=new i.Cartesian3;v.computeNormal=function(e){const t=e.indices,n=e.attributes,r=n.position.values,s=n.position.values.length/3,u=t.length,l=new Array(s),p=new Array(u/3),d=new Array(u);let f;for(f=0;f0){for(y=0;y3&&(n[3]=0,n[4]=2,n[5]=3);let i=6;for(let e=3;e=0||t.x>=0||n.x>=0)return;!function(e,t,n){if(0!==e.y&&0!==t.y&&0!==n.y)return Z(e,e.y<0),Z(t,t.y<0),void Z(n,n.y<0);const i=Math.abs(e.y),r=Math.abs(t.y),s=Math.abs(n.y);let o;o=i>r?i>s?a.CesiumMath.sign(e.y):a.CesiumMath.sign(n.y):r>s?a.CesiumMath.sign(t.y):a.CesiumMath.sign(n.y);const u=o<0;Z(e,u),Z(t,u),Z(n,u)}(e,t,n);const i=e.y<0,r=t.y<0,s=n.y<0;let o=0;o+=i?1:0,o+=r?1:0,o+=s?1:0;const u=Q.indices;1===o?(u[1]=3,u[2]=4,u[5]=6,u[7]=6,u[8]=5,i?(W(e,t,X,J),W(e,n,j,K),u[0]=0,u[3]=1,u[4]=2,u[6]=1):r?(W(t,n,X,J),W(t,e,j,K),u[0]=1,u[3]=2,u[4]=0,u[6]=2):s&&(W(n,e,X,J),W(n,t,j,K),u[0]=2,u[3]=0,u[4]=1,u[6]=0)):2===o&&(u[2]=4,u[4]=4,u[5]=3,u[7]=5,u[8]=6,i?r?s||(W(n,e,X,J),W(n,t,j,K),u[0]=0,u[1]=1,u[3]=0,u[6]=2):(W(t,n,X,J),W(t,e,j,K),u[0]=2,u[1]=0,u[3]=2,u[6]=1):(W(e,t,X,J),W(e,n,j,K),u[0]=1,u[1]=2,u[3]=1,u[6]=0));const c=Q.positions;return c[0]=e,c[1]=t,c[2]=n,c.length=3,1!==o&&2!==o||(c[3]=X,c[4]=j,c[5]=J,c[6]=K,c.length=7),Q}function ee(e,t){const n=e.attributes;if(0===n.position.values.length)return;for(const e in n)if(n.hasOwnProperty(e)&&r.defined(n[e])&&r.defined(n[e].values)){const t=n[e];t.values=o.ComponentDatatype.createTypedArray(t.componentDatatype,t.values)}const i=c.Geometry.computeNumberOfVertices(e);return e.indices=l.IndexDatatype.createTypedArray(i,e.indices),t&&(e.boundingSphere=s.BoundingSphere.fromVertices(n.position.values)),e}function te(e){const t=e.attributes,n={};for(const e in t)if(t.hasOwnProperty(e)&&r.defined(t[e])&&r.defined(t[e].values)){const i=t[e];n[e]=new c.GeometryAttribute({componentDatatype:i.componentDatatype,componentsPerAttribute:i.componentsPerAttribute,normalize:i.normalize,values:[]})}return new c.Geometry({attributes:n,indices:[],primitiveType:e.primitiveType})}function ne(e,t,n){const i=r.defined(e.geometry.boundingSphere);t=ee(t,i),n=ee(n,i),r.defined(n)&&!r.defined(t)?e.geometry=n:!r.defined(n)&&r.defined(t)?e.geometry=t:(e.westHemisphereGeometry=t,e.eastHemisphereGeometry=n,e.geometry=void 0)}function ie(e,t){const n=new e,i=new e,r=new e;return function(a,s,o,u,c,l,p,d){const f=e.fromArray(c,a*t,n),y=e.fromArray(c,s*t,i),m=e.fromArray(c,o*t,r);e.multiplyByScalar(f,u.x,f),e.multiplyByScalar(y,u.y,y),e.multiplyByScalar(m,u.z,m);const C=e.add(f,y,f);e.add(C,m,C),d&&e.normalize(C,C),e.pack(C,l,p*t)}}const re=ie(n.Cartesian4,4),ae=ie(i.Cartesian3,3),se=ie(n.Cartesian2,2),oe=new i.Cartesian3,ue=new i.Cartesian3,ce=new i.Cartesian3,le=new i.Cartesian3;function pe(e,t,s,o,u,c,l,p,d,C,h,v,b,g,A,T){if(!(r.defined(c)||r.defined(l)||r.defined(p)||r.defined(d)||r.defined(C)||0!==g))return;const x=function(e,t,s,o,u){let c,l,p,d,C,h,v,b;if(r.defined(u)||(u=new i.Cartesian3),r.defined(t.z)){if(i.Cartesian3.equalsEpsilon(e,t,a.CesiumMath.EPSILON14))return i.Cartesian3.clone(i.Cartesian3.UNIT_X,u);if(i.Cartesian3.equalsEpsilon(e,s,a.CesiumMath.EPSILON14))return i.Cartesian3.clone(i.Cartesian3.UNIT_Y,u);if(i.Cartesian3.equalsEpsilon(e,o,a.CesiumMath.EPSILON14))return i.Cartesian3.clone(i.Cartesian3.UNIT_Z,u);c=i.Cartesian3.subtract(s,t,f),l=i.Cartesian3.subtract(o,t,y),p=i.Cartesian3.subtract(e,t,m),d=i.Cartesian3.dot(c,c),C=i.Cartesian3.dot(c,l),h=i.Cartesian3.dot(c,p),v=i.Cartesian3.dot(l,l),b=i.Cartesian3.dot(l,p)}else{if(n.Cartesian2.equalsEpsilon(e,t,a.CesiumMath.EPSILON14))return i.Cartesian3.clone(i.Cartesian3.UNIT_X,u);if(n.Cartesian2.equalsEpsilon(e,s,a.CesiumMath.EPSILON14))return i.Cartesian3.clone(i.Cartesian3.UNIT_Y,u);if(n.Cartesian2.equalsEpsilon(e,o,a.CesiumMath.EPSILON14))return i.Cartesian3.clone(i.Cartesian3.UNIT_Z,u);c=n.Cartesian2.subtract(s,t,f),l=n.Cartesian2.subtract(o,t,y),p=n.Cartesian2.subtract(e,t,m),d=n.Cartesian2.dot(c,c),C=n.Cartesian2.dot(c,l),h=n.Cartesian2.dot(c,p),v=n.Cartesian2.dot(l,l),b=n.Cartesian2.dot(l,p)}u.y=v*h-C*b,u.z=d*b-C*h;const g=d*v-C*C;if(0!==g)return u.y/=g,u.z/=g,u.x=1-u.y-u.z,u}(o,i.Cartesian3.fromArray(u,3*e,oe),i.Cartesian3.fromArray(u,3*t,ue),i.Cartesian3.fromArray(u,3*s,ce),le);if(r.defined(x)){if(r.defined(c)&&ae(e,t,s,x,c,v.normal.values,T,!0),r.defined(C)){const n=i.Cartesian3.fromArray(C,3*e,oe),r=i.Cartesian3.fromArray(C,3*t,ue),a=i.Cartesian3.fromArray(C,3*s,ce);let o;i.Cartesian3.multiplyByScalar(n,x.x,n),i.Cartesian3.multiplyByScalar(r,x.y,r),i.Cartesian3.multiplyByScalar(a,x.z,a),i.Cartesian3.equals(n,i.Cartesian3.ZERO)&&i.Cartesian3.equals(r,i.Cartesian3.ZERO)&&i.Cartesian3.equals(a,i.Cartesian3.ZERO)?(o=oe,o.x=0,o.y=0,o.z=0):(o=i.Cartesian3.add(n,r,n),i.Cartesian3.add(o,a,o),i.Cartesian3.normalize(o,o)),i.Cartesian3.pack(o,v.extrudeDirection.values,3*T)}if(r.defined(h)&&function(e,t,n,i,r,s,o){const u=r[e]*i.x,c=r[t]*i.y,l=r[n]*i.z;s[o]=u+c+l>a.CesiumMath.EPSILON6?1:0}(e,t,s,x,h,v.applyOffset.values,T),r.defined(l)&&ae(e,t,s,x,l,v.tangent.values,T,!0),r.defined(p)&&ae(e,t,s,x,p,v.bitangent.values,T,!0),r.defined(d)&&se(e,t,s,x,d,v.st.values,T),g>0)for(let n=0;n3){const i=O.positions,r=O.indices,w=r.length;for(let S=0;S0)continue;const o=i.Cartesian3.unpack(r,e,Pe);(t.y<0&&o.y>0||t.y>0&&o.y<0)&&(e-3>0?(r[e]=n[e-3],r[e+1]=n[e-2],r[e+2]=n[e-1]):i.Cartesian3.pack(t,r,e));const u=i.Cartesian3.unpack(a,e,we);(t.y<0&&u.y>0||t.y>0&&u.y<0)&&(e+30||s.BoundingSphere.intersectPlane(o,d.Plane.ORIGIN_ZX_PLANE)!==s.Intersect.INTERSECTING)return e}if(t.geometryType!==c.GeometryType.NONE)switch(t.geometryType){case c.GeometryType.POLYLINES:!function(e){const t=e.geometry,s=t.attributes,o=s.position.values,u=s.prevPosition.values,c=s.nextPosition.values,l=s.expandAndWidth.values,d=r.defined(s.st)?s.st.values:void 0,f=r.defined(s.color)?s.color.values:void 0,y=te(t),m=te(t);let C,h,v,b=!1;const g=o.length/3;for(C=0;C