define(["exports","./AttributeCompression-90851096","./Cartesian2-47311507","./Cartographic-3309dd0d","./Check-7b2a090c","./when-b60132fc","./Math-119be1a3","./BoundingSphere-561b54d0","./Cartesian4-3ca25aab","./ComponentDatatype-c140a87d","./EncodedCartesian3-f1396b05","./GeometryAttribute-3a42bbdc","./IndexDatatype-8a5eead4","./IntersectionTests-0c6d0a14","./Plane-097b3a8f","./PrimitiveType-39acab88"],(function(e,t,r,a,i,n,s,o,u,p,d,l,v,y,f,c){"use strict";var m=new a.Cartesian3,C=new a.Cartesian3,h=new a.Cartesian3;var b={calculateACMR:function(e){var t=(e=n.defaultValue(e,n.defaultValue.EMPTY_OBJECT)).indices,r=e.maximumIndex,a=n.defaultValue(e.cacheSize,24),i=t.length;if(!n.defined(r)){r=0;for(var s=0,o=t[s];sr&&(r=o),o=t[++s]}for(var u=[],p=0;pa&&(u[t[l]]=d,++d);return(d-a+1)/(i/3)}};b.tipsify=function(e){var t,r=(e=n.defaultValue(e,n.defaultValue.EMPTY_OBJECT)).indices,a=e.maximumIndex,i=n.defaultValue(e.cacheSize,24);function s(e,r,a,i,n,s,o){for(var u,p=-1,d=-1,l=0;ld||-1===d)&&(d=u,p=v)),++l}return-1===p?function(e,r,a,i){for(;r.length>=1;){var n=r[r.length-1];if(r.splice(r.length-1,1),e[n].numLiveTriangles>0)return n}for(;t0)return++t-1;++t}return-1}(i,s,0,o):p}var o=r.length,u=0,p=0,d=r[p],l=o;if(n.defined(a))u=a+1;else{for(;pu&&(u=d),d=r[++p];if(-1===u)return 0;++u}var v,y=[];for(v=0;vi&&(C.timeStamp=m,++m),++p}c=s(0,i,A,y,m,T,u)}return P};var g={};function A(e,t,r,a,i){e[t++]=r,e[t++]=a,e[t++]=a,e[t++]=i,e[t++]=i,e[t]=r}function T(e){var t={};for(var r in e)if(e.hasOwnProperty(r)&&n.defined(e[r])&&n.defined(e[r].values)){var a=e[r];t[r]=new l.GeometryAttribute({componentDatatype:a.componentDatatype,componentsPerAttribute:a.componentsPerAttribute,normalize:a.normalize,values:[]})}return t}function x(e,t,r){for(var a in t)if(t.hasOwnProperty(a)&&n.defined(t[a])&&n.defined(t[a].values))for(var i=t[a],s=0;s=3){var r=6*(t-2),a=v.IndexDatatype.createTypedArray(t,r);A(a,0,e[0],e[1],e[2]);for(var i=6,n=3;n0){for(var t=e.length-1,r=6*(t-1),a=v.IndexDatatype.createTypedArray(t,r),i=e[0],n=0,s=1;si&&(i=r[s]);e.indices=b.tipsify({indices:r,maximumIndex:i,cacheSize:t})}return e},g.fitToUnsignedShortIndices=function(e){var t=[],r=l.Geometry.computeNumberOfVertices(e);if(n.defined(e.indices)&&r>=s.CesiumMath.SIXTY_FOUR_KILOBYTES){var a,i=[],o=[],u=0,p=T(e.attributes),d=e.indices,v=d.length;e.primitiveType===c.PrimitiveType.TRIANGLES?a=3:e.primitiveType===c.PrimitiveType.LINES?a=2:e.primitiveType===c.PrimitiveType.POINTS&&(a=1);for(var y=0;y=s.CesiumMath.SIXTY_FOUR_KILOBYTES&&(t.push(new l.Geometry({attributes:p,indices:o,primitiveType:e.primitiveType,boundingSphere:e.boundingSphere,boundingSphereCV:e.boundingSphereCV})),i=[],o=[],u=0,p=T(e.attributes))}0!==o.length&&t.push(new l.Geometry({attributes:p,indices:o,primitiveType:e.primitiveType,boundingSphere:e.boundingSphere,boundingSphereCV:e.boundingSphereCV}))}else t.push(e);return t};var P=new a.Cartesian3,w=new a.Cartographic;g.projectTo2D=function(e,t,r,i,s){for(var u=e.attributes[t],d=(s=n.defined(s)?s:new o.GeographicProjection).ellipsoid,v=u.values,y=new Float64Array(v.length),f=0,c=0;cN&&(N=L)}return new l.Geometry({attributes:g,indices:C,primitiveType:b,boundingSphere:n.defined(E)?new o.BoundingSphere(E,N):void 0})}g.combineInstances=function(e){for(var t=[],r=[],a=e.length,i=0;i0&&o.push(D(t,"geometry")),r.length>0&&(o.push(D(r,"westHemisphereGeometry")),o.push(D(r,"eastHemisphereGeometry"))),o};var M=new a.Cartesian3,G=new a.Cartesian3,R=new a.Cartesian3,V=new a.Cartesian3;g.computeNormal=function(e){var t,r=e.indices,i=e.attributes,n=i.position.values,o=i.position.values.length/3,u=r.length,d=new Array(o),v=new Array(u/3),y=new Array(u);for(t=0;t0){for(f=0;f3&&(r[3]=0,r[4]=2,r[5]=3);for(var a=6,i=3;i=0||t.x>=0||r.x>=0)){!function(e,t,r){if(0!==e.y&&0!==t.y&&0!==r.y)return W(e,e.y<0),W(t,t.y<0),void W(r,r.y<0);var a=Math.abs(e.y),i=Math.abs(t.y),n=Math.abs(r.y),o=(a>i?a>n?s.CesiumMath.sign(e.y):s.CesiumMath.sign(r.y):i>n?s.CesiumMath.sign(t.y):s.CesiumMath.sign(r.y))<0;W(e,o),W(t,o),W(r,o)}(e,t,r);var a=e.y<0,i=t.y<0,n=r.y<0,o=0;o+=a?1:0,o+=i?1:0;var u=ee.indices;1===(o+=n?1:0)?(u[1]=3,u[2]=4,u[5]=6,u[7]=6,u[8]=5,a?(j(e,t,J,Q),j(e,r,K,$),u[0]=0,u[3]=1,u[4]=2,u[6]=1):i?(j(t,r,J,Q),j(t,e,K,$),u[0]=1,u[3]=2,u[4]=0,u[6]=2):n&&(j(r,e,J,Q),j(r,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,a?i?n||(j(r,e,J,Q),j(r,t,K,$),u[0]=0,u[1]=1,u[3]=0,u[6]=2):(j(t,r,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,r,K,$),u[0]=1,u[1]=2,u[3]=1,u[6]=0));var p=ee.positions;return p[0]=e,p[1]=t,p[2]=r,p.length=3,1!==o&&2!==o||(p[3]=J,p[4]=K,p[5]=Q,p[6]=$,p.length=7),ee}}function re(e,t){var r=e.attributes;if(0!==r.position.values.length){for(var a in r)if(r.hasOwnProperty(a)&&n.defined(r[a])&&n.defined(r[a].values)){var i=r[a];i.values=p.ComponentDatatype.createTypedArray(i.componentDatatype,i.values)}var s=l.Geometry.computeNumberOfVertices(e);return e.indices=v.IndexDatatype.createTypedArray(s,e.indices),t&&(e.boundingSphere=o.BoundingSphere.fromVertices(r.position.values)),e}}function ae(e){var t=e.attributes,r={};for(var a in t)if(t.hasOwnProperty(a)&&n.defined(t[a])&&n.defined(t[a].values)){var i=t[a];r[a]=new l.GeometryAttribute({componentDatatype:i.componentDatatype,componentsPerAttribute:i.componentsPerAttribute,normalize:i.normalize,values:[]})}return new l.Geometry({attributes:r,indices:[],primitiveType:e.primitiveType})}function ie(e,t,r){var a=n.defined(e.geometry.boundingSphere);t=re(t,a),r=re(r,a),n.defined(r)&&!n.defined(t)?e.geometry=r:!n.defined(r)&&n.defined(t)?e.geometry=t:(e.westHemisphereGeometry=t,e.eastHemisphereGeometry=r,e.geometry=void 0)}function ne(e,t){var r=new e,a=new e,i=new e;return function(n,s,o,u,p,d,l,v){var y=e.fromArray(p,n*t,r),f=e.fromArray(p,s*t,a),c=e.fromArray(p,o*t,i);e.multiplyByScalar(y,u.x,y),e.multiplyByScalar(f,u.y,f),e.multiplyByScalar(c,u.z,c);var m=e.add(y,f,y);e.add(m,c,m),v&&e.normalize(m,m),e.pack(m,d,l*t)}}var se=ne(u.Cartesian4,4),oe=ne(a.Cartesian3,3),ue=ne(r.Cartesian2,2),pe=new a.Cartesian3,de=new a.Cartesian3,le=new a.Cartesian3,ve=new a.Cartesian3;function ye(e,t,i,o,u,p,d,l,v,y,f,c,b,g,A,T){if(n.defined(p)||n.defined(d)||n.defined(l)||n.defined(v)||n.defined(y)||0!==g){var x=function(e,t,i,o,u){var p,d,l,v,y,f,c,b;if(n.defined(u)||(u=new a.Cartesian3),n.defined(t.z)){if(a.Cartesian3.equalsEpsilon(e,t,s.CesiumMath.EPSILON14))return a.Cartesian3.clone(a.Cartesian3.UNIT_X,u);if(a.Cartesian3.equalsEpsilon(e,i,s.CesiumMath.EPSILON14))return a.Cartesian3.clone(a.Cartesian3.UNIT_Y,u);if(a.Cartesian3.equalsEpsilon(e,o,s.CesiumMath.EPSILON14))return a.Cartesian3.clone(a.Cartesian3.UNIT_Z,u);p=a.Cartesian3.subtract(i,t,m),d=a.Cartesian3.subtract(o,t,C),l=a.Cartesian3.subtract(e,t,h),v=a.Cartesian3.dot(p,p),y=a.Cartesian3.dot(p,d),f=a.Cartesian3.dot(p,l),c=a.Cartesian3.dot(d,d),b=a.Cartesian3.dot(d,l)}else{if(r.Cartesian2.equalsEpsilon(e,t,s.CesiumMath.EPSILON14))return a.Cartesian3.clone(a.Cartesian3.UNIT_X,u);if(r.Cartesian2.equalsEpsilon(e,i,s.CesiumMath.EPSILON14))return a.Cartesian3.clone(a.Cartesian3.UNIT_Y,u);if(r.Cartesian2.equalsEpsilon(e,o,s.CesiumMath.EPSILON14))return a.Cartesian3.clone(a.Cartesian3.UNIT_Z,u);p=r.Cartesian2.subtract(i,t,m),d=r.Cartesian2.subtract(o,t,C),l=r.Cartesian2.subtract(e,t,h),v=r.Cartesian2.dot(p,p),y=r.Cartesian2.dot(p,d),f=r.Cartesian2.dot(p,l),c=r.Cartesian2.dot(d,d),b=r.Cartesian2.dot(d,l)}u.y=c*f-y*b,u.z=v*b-y*f;var g=v*c-y*y;return 0!==u.y&&(u.y/=g),0!==u.z&&(u.z/=g),u.x=1-u.y-u.z,u}(o,a.Cartesian3.fromArray(u,3*e,pe),a.Cartesian3.fromArray(u,3*t,de),a.Cartesian3.fromArray(u,3*i,le),ve);if(n.defined(p)&&oe(e,t,i,x,p,c.normal.values,T,!0),n.defined(y)){var P,w=a.Cartesian3.fromArray(y,3*e,pe),S=a.Cartesian3.fromArray(y,3*t,de),I=a.Cartesian3.fromArray(y,3*i,le);a.Cartesian3.multiplyByScalar(w,x.x,w),a.Cartesian3.multiplyByScalar(S,x.y,S),a.Cartesian3.multiplyByScalar(I,x.z,I),a.Cartesian3.equals(w,a.Cartesian3.ZERO)&&a.Cartesian3.equals(S,a.Cartesian3.ZERO)&&a.Cartesian3.equals(I,a.Cartesian3.ZERO)?((P=pe).x=0,P.y=0,P.z=0):(P=a.Cartesian3.add(w,S,w),a.Cartesian3.add(P,I,P),a.Cartesian3.normalize(P,P)),a.Cartesian3.pack(P,c.extrudeDirection.values,3*T)}if(n.defined(f)&&function(e,t,r,a,i,n,o){var u=i[e]*a.x,p=i[t]*a.y,d=i[r]*a.z;n[o]=u+p+d>s.CesiumMath.EPSILON6?1:0}(e,t,i,x,f,c.applyOffset.values,T),n.defined(d)&&oe(e,t,i,x,d,c.tangent.values,T,!0),n.defined(l)&&oe(e,t,i,x,l,c.bitangent.values,T,!0),n.defined(v)&&ue(e,t,i,x,v,c.st.values,T),g>0)for(var O=0;O3)for(var z=L.positions,D=L.indices,M=D.length,G=0;G0)){var p=a.Cartesian3.unpack(i,o,Se);(u.y<0&&p.y>0||u.y>0&&p.y<0)&&(o-3>0?(i[o]=r[o-3],i[o+1]=r[o-2],i[o+2]=r[o-1]):a.Cartesian3.pack(u,i,o));var d=a.Cartesian3.unpack(n,o,Ie);(u.y<0&&d.y>0||u.y>0&&d.y<0)&&(o+30||o.BoundingSphere.intersectPlane(i,f.Plane.ORIGIN_ZX_PLANE)!==o.Intersect.INTERSECTING))return e;if(t.geometryType!==l.GeometryType.NONE)switch(t.geometryType){case l.GeometryType.POLYLINES:!function(e){var t,i,o,p=e.geometry,d=p.attributes,l=d.position.values,v=d.prevPosition.values,f=d.nextPosition.values,c=d.expandAndWidth.values,m=n.defined(d.st)?d.st.values:void 0,C=n.defined(d.color)?d.color.values:void 0,h=n.defined(d.dist)?d.dist.values:void 0,b=ae(p),g=ae(p),A=!1,T=l.length/3;for(t=0;t