define(["exports","./AttributeCompression-8f752c03","./Cartesian2-bd414876","./Cartesian3-e0307675","./Check-741c5f3c","./defaultValue-81eec7ed","./Math-e73894ab","./BoundingSphere-9a3b5656","./Matrix4-4c545f70","./ComponentDatatype-aaeec80f","./EncodedCartesian3-aafcc30f","./GeographicProjection-c931c7fb","./GeometryAttribute-2b42a913","./IndexDatatype-3f3c99e8","./IntersectionTests-80510c7b","./Plane-bc8b6777"],(function(e,t,n,i,r,a,s,o,u,c,l,p,d,f,y,m){"use strict";const C=new i.Cartesian3,h=new i.Cartesian3,v=new i.Cartesian3;const b={calculateACMR:function(e){const t=(e=a.defaultValue(e,a.defaultValue.EMPTY_OBJECT)).indices;let n=e.maximumIndex;const i=a.defaultValue(e.cacheSize,24),r=t.length;if(!a.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)/(r/3)}};b.tipsify=function(e){const t=(e=a.defaultValue(e,a.defaultValue.EMPTY_OBJECT)).indices,n=e.maximumIndex,i=a.defaultValue(e.cacheSize,24);let r;function s(e,t,n,i,a,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(;r0)return++r,r-1;++r}return-1}(i,s,0,o):c}const o=t.length;let u=0,c=0,l=t[c];const p=o;if(a.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};const g={};function A(e,t,n,i,r){e[t++]=n,e[t++]=i,e[t++]=i,e[t++]=r,e[t++]=r,e[t]=n}function T(e){const t={};for(const n in e)if(e.hasOwnProperty(n)&&a.defined(e[n])&&a.defined(e[n].values)){const i=e[n];t[n]=new d.GeometryAttribute({componentDatatype:i.componentDatatype,componentsPerAttribute:i.componentsPerAttribute,normalize:i.normalize,values:[]})}return t}function x(e,t,n){for(const i in t)if(t.hasOwnProperty(i)&&a.defined(t[i])&&a.defined(t[i].values)){const r=t[i];for(let t=0;t=3){const n=6*(t-2),i=f.IndexDatatype.createTypedArray(t,n);A(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=f.IndexDatatype.createTypedArray(t,n),r=e[0];let a=0;for(let n=1;nr&&(r=n[e]);e.indices=b.tipsify({indices:n,maximumIndex:r,cacheSize:t})}return e},g.fitToUnsignedShortIndices=function(e){const t=[],n=d.Geometry.computeNumberOfVertices(e);if(a.defined(e.indices)&&n>=s.CesiumMath.SIXTY_FOUR_KILOBYTES){let n=[],i=[],r=0,o=T(e.attributes);const u=e.indices,c=u.length;let l;e.primitiveType===d.PrimitiveType.TRIANGLES?l=3:e.primitiveType===d.PrimitiveType.LINES?l=2:e.primitiveType===d.PrimitiveType.POINTS&&(l=1);for(let p=0;p=s.CesiumMath.SIXTY_FOUR_KILOBYTES&&(t.push(new d.Geometry({attributes:o,indices:i,primitiveType:e.primitiveType,boundingSphere:e.boundingSphere,boundingSphereCV:e.boundingSphereCV})),n=[],i=[],r=0,o=T(e.attributes))}0!==i.length&&t.push(new d.Geometry({attributes:o,indices:i,primitiveType:e.primitiveType,boundingSphere:e.boundingSphere,boundingSphereCV:e.boundingSphereCV}))}else t.push(e);return t};const P=new i.Cartesian3,w=new n.Cartographic;g.projectTo2D=function(e,t,n,r,s){const o=e.attributes[t],u=(s=a.defined(s)?s:new p.GeographicProjection).ellipsoid,l=o.values,f=new Float64Array(l.length);let y=0;for(let e=0;eT&&(T=n)}return new d.Geometry({attributes:m,indices:b,primitiveType:y,boundingSphere:a.defined(A)?new o.BoundingSphere(A,T):void 0})}g.combineInstances=function(e){const t=[],n=[],i=e.length;for(let r=0;r0&&r.push(D(t,"geometry")),n.length>0&&(r.push(D(n,"westHemisphereGeometry")),r.push(D(n,"eastHemisphereGeometry"))),r};const M=new i.Cartesian3,G=new i.Cartesian3,V=new i.Cartesian3,R=new i.Cartesian3;g.computeNormal=function(e){const t=e.indices,n=e.attributes,r=n.position.values,a=n.position.values.length/3,o=t.length,u=new Array(a),l=new Array(o/3),p=new Array(o);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 W(e,e.y<0),W(t,t.y<0),void W(n,n.y<0);const i=Math.abs(e.y),r=Math.abs(t.y),a=Math.abs(n.y);let o;o=i>r?i>a?s.CesiumMath.sign(e.y):s.CesiumMath.sign(n.y):r>a?s.CesiumMath.sign(t.y):s.CesiumMath.sign(n.y);const u=o<0;W(e,u),W(t,u),W(n,u)}(e,t,n);const i=e.y<0,r=t.y<0,a=n.y<0;let o=0;o+=i?1:0,o+=r?1:0,o+=a?1:0;const u=ee.indices;1===o?(u[1]=3,u[2]=4,u[5]=6,u[7]=6,u[8]=5,i?(j(e,t,J,Q),j(e,n,K,$),u[0]=0,u[3]=1,u[4]=2,u[6]=1):r?(j(t,n,J,Q),j(t,e,K,$),u[0]=1,u[3]=2,u[4]=0,u[6]=2):a&&(j(n,e,J,Q),j(n,t,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?a||(j(n,e,J,Q),j(n,t,K,$),u[0]=0,u[1]=1,u[3]=0,u[6]=2):(j(t,n,J,Q),j(t,e,K,$),u[0]=2,u[1]=0,u[3]=2,u[6]=1):(j(e,t,J,Q),j(e,n,K,$),u[0]=1,u[1]=2,u[3]=1,u[6]=0));const c=ee.positions;return c[0]=e,c[1]=t,c[2]=n,c.length=3,1!==o&&2!==o||(c[3]=J,c[4]=K,c[5]=Q,c[6]=$,c.length=7),ee}function ne(e,t){const n=e.attributes;if(0===n.position.values.length)return;for(const e in n)if(n.hasOwnProperty(e)&&a.defined(n[e])&&a.defined(n[e].values)){const t=n[e];t.values=c.ComponentDatatype.createTypedArray(t.componentDatatype,t.values)}const i=d.Geometry.computeNumberOfVertices(e);return e.indices=f.IndexDatatype.createTypedArray(i,e.indices),t&&(e.boundingSphere=o.BoundingSphere.fromVertices(n.position.values)),e}function ie(e){const t=e.attributes,n={};for(const e in t)if(t.hasOwnProperty(e)&&a.defined(t[e])&&a.defined(t[e].values)){const i=t[e];n[e]=new d.GeometryAttribute({componentDatatype:i.componentDatatype,componentsPerAttribute:i.componentsPerAttribute,normalize:i.normalize,values:[]})}return new d.Geometry({attributes:n,indices:[],primitiveType:e.primitiveType})}function re(e,t,n){const i=a.defined(e.geometry.boundingSphere);t=ne(t,i),n=ne(n,i),a.defined(n)&&!a.defined(t)?e.geometry=n:!a.defined(n)&&a.defined(t)?e.geometry=t:(e.westHemisphereGeometry=t,e.eastHemisphereGeometry=n,e.geometry=void 0)}function ae(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 se=ae(u.Cartesian4,4),oe=ae(i.Cartesian3,3),ue=ae(n.Cartesian2,2),ce=new i.Cartesian3,le=new i.Cartesian3,pe=new i.Cartesian3,de=new i.Cartesian3;function fe(e,t,r,o,u,c,l,p,d,f,y,m,b,g,A,T){if(!(a.defined(c)||a.defined(l)||a.defined(p)||a.defined(d)||a.defined(f)||0!==g))return;const x=function(e,t,r,o,u){let c,l,p,d,f,y,m,b;if(a.defined(u)||(u=new i.Cartesian3),a.defined(t.z)){if(i.Cartesian3.equalsEpsilon(e,t,s.CesiumMath.EPSILON14))return i.Cartesian3.clone(i.Cartesian3.UNIT_X,u);if(i.Cartesian3.equalsEpsilon(e,r,s.CesiumMath.EPSILON14))return i.Cartesian3.clone(i.Cartesian3.UNIT_Y,u);if(i.Cartesian3.equalsEpsilon(e,o,s.CesiumMath.EPSILON14))return i.Cartesian3.clone(i.Cartesian3.UNIT_Z,u);c=i.Cartesian3.subtract(r,t,C),l=i.Cartesian3.subtract(o,t,h),p=i.Cartesian3.subtract(e,t,v),d=i.Cartesian3.dot(c,c),f=i.Cartesian3.dot(c,l),y=i.Cartesian3.dot(c,p),m=i.Cartesian3.dot(l,l),b=i.Cartesian3.dot(l,p)}else{if(n.Cartesian2.equalsEpsilon(e,t,s.CesiumMath.EPSILON14))return i.Cartesian3.clone(i.Cartesian3.UNIT_X,u);if(n.Cartesian2.equalsEpsilon(e,r,s.CesiumMath.EPSILON14))return i.Cartesian3.clone(i.Cartesian3.UNIT_Y,u);if(n.Cartesian2.equalsEpsilon(e,o,s.CesiumMath.EPSILON14))return i.Cartesian3.clone(i.Cartesian3.UNIT_Z,u);c=n.Cartesian2.subtract(r,t,C),l=n.Cartesian2.subtract(o,t,h),p=n.Cartesian2.subtract(e,t,v),d=n.Cartesian2.dot(c,c),f=n.Cartesian2.dot(c,l),y=n.Cartesian2.dot(c,p),m=n.Cartesian2.dot(l,l),b=n.Cartesian2.dot(l,p)}u.y=m*y-f*b,u.z=d*b-f*y;const g=d*m-f*f;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,ce),i.Cartesian3.fromArray(u,3*t,le),i.Cartesian3.fromArray(u,3*r,pe),de);if(a.defined(x)){if(a.defined(c)&&oe(e,t,r,x,c,m.normal.values,T,!0),a.defined(f)){const n=i.Cartesian3.fromArray(f,3*e,ce),a=i.Cartesian3.fromArray(f,3*t,le),s=i.Cartesian3.fromArray(f,3*r,pe);let o;i.Cartesian3.multiplyByScalar(n,x.x,n),i.Cartesian3.multiplyByScalar(a,x.y,a),i.Cartesian3.multiplyByScalar(s,x.z,s),i.Cartesian3.equals(n,i.Cartesian3.ZERO)&&i.Cartesian3.equals(a,i.Cartesian3.ZERO)&&i.Cartesian3.equals(s,i.Cartesian3.ZERO)?(o=ce,o.x=0,o.y=0,o.z=0):(o=i.Cartesian3.add(n,a,n),i.Cartesian3.add(o,s,o),i.Cartesian3.normalize(o,o)),i.Cartesian3.pack(o,m.extrudeDirection.values,3*T)}if(a.defined(y)&&function(e,t,n,i,r,a,o){const u=r[e]*i.x,c=r[t]*i.y,l=r[n]*i.z;a[o]=u+c+l>s.CesiumMath.EPSILON6?1:0}(e,t,r,x,y,m.applyOffset.values,T),a.defined(l)&&oe(e,t,r,x,l,m.tangent.values,T,!0),a.defined(p)&&oe(e,t,r,x,p,m.bitangent.values,T,!0),a.defined(d)&&ue(e,t,r,x,d,m.st.values,T),g>0)for(let n=0;n3){const i=O.positions,a=O.indices,w=a.length;for(let S=0;S0)continue;const o=i.Cartesian3.unpack(r,e,Se);(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,Ie);(t.y<0&&u.y>0||t.y>0&&u.y<0)&&(e+30||o.BoundingSphere.intersectPlane(r,m.Plane.ORIGIN_ZX_PLANE)!==o.Intersect.INTERSECTING)return e}if(t.geometryType!==d.GeometryType.NONE)switch(t.geometryType){case d.GeometryType.POLYLINES:!function(e){const t=e.geometry,r=t.attributes,o=r.position.values,c=r.prevPosition.values,l=r.nextPosition.values,p=r.expandAndWidth.values,d=a.defined(r.st)?r.st.values:void 0,f=a.defined(r.color)?r.color.values:void 0,m=ie(t),C=ie(t);let h,v,b,g=!1;const A=o.length/3;for(h=0;h