define(["exports","./AttributeCompression-af389d04","./Matrix2-9aa31791","./RuntimeError-346a3079","./when-4bbc8319","./ComponentDatatype-93750d1a","./Transforms-d13cc04e","./EncodedCartesian3-f286cedc","./GeometryAttribute-43536dc0","./IndexDatatype-b7d979a6","./IntersectionTests-96a04219","./Plane-318d6937"],(function(e,t,r,a,i,n,s,o,u,p,d,l){"use strict";var v=new r.Cartesian3,y=new r.Cartesian3,f=new r.Cartesian3;var c={calculateACMR:function(e){var t=(e=i.defaultValue(e,i.defaultValue.EMPTY_OBJECT)).indices,r=e.maximumIndex,a=i.defaultValue(e.cacheSize,24),n=t.length;if(!i.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)/(n/3)}};c.tipsify=function(e){var t,r=(e=i.defaultValue(e,i.defaultValue.EMPTY_OBJECT)).indices,a=e.maximumIndex,n=i.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(i.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;vn&&(C.timeStamp=m,++m),++p}c=s(0,n,A,y,m,T,u)}return P};var m={};function C(e,t,r,a,i){e[t++]=r,e[t++]=a,e[t++]=a,e[t++]=i,e[t++]=i,e[t]=r}function h(e){var t={};for(var r in e)if(e.hasOwnProperty(r)&&i.defined(e[r])&&i.defined(e[r].values)){var a=e[r];t[r]=new u.GeometryAttribute({componentDatatype:a.componentDatatype,componentsPerAttribute:a.componentsPerAttribute,normalize:a.normalize,values:[]})}return t}function b(e,t,r){for(var a in t)if(t.hasOwnProperty(a)&&i.defined(t[a])&&i.defined(t[a].values))for(var n=t[a],s=0;s=3){var r=6*(t-2),a=p.IndexDatatype.createTypedArray(t,r);C(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=p.IndexDatatype.createTypedArray(t,r),i=e[0],n=0,s=1;sn&&(n=r[s]);e.indices=c.tipsify({indices:r,maximumIndex:n,cacheSize:t})}return e},m.fitToUnsignedShortIndices=function(e){var t=[],r=u.Geometry.computeNumberOfVertices(e);if(i.defined(e.indices)&&r>=n.CesiumMath.SIXTY_FOUR_KILOBYTES){var a,s=[],o=[],p=0,d=h(e.attributes),l=e.indices,v=l.length;e.primitiveType===u.PrimitiveType.TRIANGLES?a=3:e.primitiveType===u.PrimitiveType.LINES?a=2:e.primitiveType===u.PrimitiveType.POINTS&&(a=1);for(var y=0;y=n.CesiumMath.SIXTY_FOUR_KILOBYTES&&(t.push(new u.Geometry({attributes:d,indices:o,primitiveType:e.primitiveType,boundingSphere:e.boundingSphere,boundingSphereCV:e.boundingSphereCV})),s=[],o=[],p=0,d=h(e.attributes))}0!==o.length&&t.push(new u.Geometry({attributes:d,indices:o,primitiveType:e.primitiveType,boundingSphere:e.boundingSphere,boundingSphereCV:e.boundingSphereCV}))}else t.push(e);return t};var g=new r.Cartesian3,A=new r.Cartographic;m.projectTo2D=function(e,t,a,o,p){for(var d=e.attributes[t],l=(p=i.defined(p)?p:new s.GeographicProjection).ellipsoid,v=d.values,y=new Float64Array(v.length),f=0,c=0;cN&&(N=L)}return new u.Geometry({attributes:b,indices:m,primitiveType:h,boundingSphere:i.defined(E)?new s.BoundingSphere(E,N):void 0})}m.combineInstances=function(e){for(var t=[],r=[],a=e.length,n=0;n0&&o.push(E(t,"geometry")),r.length>0&&(o.push(E(r,"westHemisphereGeometry")),o.push(E(r,"eastHemisphereGeometry"))),o};var N=new r.Cartesian3,L=new r.Cartesian3,z=new r.Cartesian3,D=new r.Cartesian3;m.computeNormal=function(e){var t,a=e.indices,i=e.attributes,s=i.position.values,o=i.position.values.length/3,p=a.length,d=new Array(o),l=new Array(p/3),v=new Array(p);for(t=0;t0){for(y=0;y3&&(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 U(e,e.y<0),U(t,t.y<0),void U(r,r.y<0);var a=Math.abs(e.y),i=Math.abs(t.y),s=Math.abs(r.y),o=(a>i?a>s?n.CesiumMath.sign(e.y):n.CesiumMath.sign(r.y):i>s?n.CesiumMath.sign(t.y):n.CesiumMath.sign(r.y))<0;U(e,o),U(t,o),U(r,o)}(e,t,r);var a=e.y<0,i=t.y<0,s=r.y<0,o=0;o+=a?1:0,o+=i?1:0;var u=J.indices;1===(o+=s?1:0)?(u[1]=3,u[2]=4,u[5]=6,u[7]=6,u[8]=5,a?(Z(e,t,H,X),Z(e,r,W,j),u[0]=0,u[3]=1,u[4]=2,u[6]=1):i?(Z(t,r,H,X),Z(t,e,W,j),u[0]=1,u[3]=2,u[4]=0,u[6]=2):s&&(Z(r,e,H,X),Z(r,t,W,j),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?s||(Z(r,e,H,X),Z(r,t,W,j),u[0]=0,u[1]=1,u[3]=0,u[6]=2):(Z(t,r,H,X),Z(t,e,W,j),u[0]=2,u[1]=0,u[3]=2,u[6]=1):(Z(e,t,H,X),Z(e,r,W,j),u[0]=1,u[1]=2,u[3]=1,u[6]=0));var p=J.positions;return p[0]=e,p[1]=t,p[2]=r,p.length=3,1!==o&&2!==o||(p[3]=H,p[4]=W,p[5]=X,p[6]=j,p.length=7),J}}function Q(e,t){var r=e.attributes;if(0!==r.position.values.length){for(var a in r)if(r.hasOwnProperty(a)&&i.defined(r[a])&&i.defined(r[a].values)){var o=r[a];o.values=n.ComponentDatatype.createTypedArray(o.componentDatatype,o.values)}var d=u.Geometry.computeNumberOfVertices(e);return e.indices=p.IndexDatatype.createTypedArray(d,e.indices),t&&(e.boundingSphere=s.BoundingSphere.fromVertices(r.position.values)),e}}function $(e){var t=e.attributes,r={};for(var a in t)if(t.hasOwnProperty(a)&&i.defined(t[a])&&i.defined(t[a].values)){var n=t[a];r[a]=new u.GeometryAttribute({componentDatatype:n.componentDatatype,componentsPerAttribute:n.componentsPerAttribute,normalize:n.normalize,values:[]})}return new u.Geometry({attributes:r,indices:[],primitiveType:e.primitiveType})}function ee(e,t,r){var a=i.defined(e.geometry.boundingSphere);t=Q(t,a),r=Q(r,a),i.defined(r)&&!i.defined(t)?e.geometry=r:!i.defined(r)&&i.defined(t)?e.geometry=t:(e.westHemisphereGeometry=t,e.eastHemisphereGeometry=r,e.geometry=void 0)}function te(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 re=te(r.Cartesian4,4),ae=te(r.Cartesian3,3),ie=te(r.Cartesian2,2),ne=new r.Cartesian3,se=new r.Cartesian3,oe=new r.Cartesian3,ue=new r.Cartesian3;function pe(e,t,a,s,o,u,p,d,l,c,m,C,h,b,g,A){if(i.defined(u)||i.defined(p)||i.defined(d)||i.defined(l)||i.defined(c)||0!==b){var T=function(e,t,a,s,o){var u,p,d,l,c,m,C,h;if(i.defined(o)||(o=new r.Cartesian3),i.defined(t.z)){if(r.Cartesian3.equalsEpsilon(e,t,n.CesiumMath.EPSILON14))return r.Cartesian3.clone(r.Cartesian3.UNIT_X,o);if(r.Cartesian3.equalsEpsilon(e,a,n.CesiumMath.EPSILON14))return r.Cartesian3.clone(r.Cartesian3.UNIT_Y,o);if(r.Cartesian3.equalsEpsilon(e,s,n.CesiumMath.EPSILON14))return r.Cartesian3.clone(r.Cartesian3.UNIT_Z,o);u=r.Cartesian3.subtract(a,t,v),p=r.Cartesian3.subtract(s,t,y),d=r.Cartesian3.subtract(e,t,f),l=r.Cartesian3.dot(u,u),c=r.Cartesian3.dot(u,p),m=r.Cartesian3.dot(u,d),C=r.Cartesian3.dot(p,p),h=r.Cartesian3.dot(p,d)}else{if(r.Cartesian2.equalsEpsilon(e,t,n.CesiumMath.EPSILON14))return r.Cartesian3.clone(r.Cartesian3.UNIT_X,o);if(r.Cartesian2.equalsEpsilon(e,a,n.CesiumMath.EPSILON14))return r.Cartesian3.clone(r.Cartesian3.UNIT_Y,o);if(r.Cartesian2.equalsEpsilon(e,s,n.CesiumMath.EPSILON14))return r.Cartesian3.clone(r.Cartesian3.UNIT_Z,o);u=r.Cartesian2.subtract(a,t,v),p=r.Cartesian2.subtract(s,t,y),d=r.Cartesian2.subtract(e,t,f),l=r.Cartesian2.dot(u,u),c=r.Cartesian2.dot(u,p),m=r.Cartesian2.dot(u,d),C=r.Cartesian2.dot(p,p),h=r.Cartesian2.dot(p,d)}o.y=C*m-c*h,o.z=l*h-c*m;var b=l*C-c*c;if(0!==b)return o.y/=b,o.z/=b,o.x=1-o.y-o.z,o}(s,r.Cartesian3.fromArray(o,3*e,ne),r.Cartesian3.fromArray(o,3*t,se),r.Cartesian3.fromArray(o,3*a,oe),ue);if(i.defined(T)){if(i.defined(u)&&ae(e,t,a,T,u,C.normal.values,A,!0),i.defined(c)){var x,P=r.Cartesian3.fromArray(c,3*e,ne),w=r.Cartesian3.fromArray(c,3*t,se),S=r.Cartesian3.fromArray(c,3*a,oe);r.Cartesian3.multiplyByScalar(P,T.x,P),r.Cartesian3.multiplyByScalar(w,T.y,w),r.Cartesian3.multiplyByScalar(S,T.z,S),r.Cartesian3.equals(P,r.Cartesian3.ZERO)&&r.Cartesian3.equals(w,r.Cartesian3.ZERO)&&r.Cartesian3.equals(S,r.Cartesian3.ZERO)?((x=ne).x=0,x.y=0,x.z=0):(x=r.Cartesian3.add(P,w,P),r.Cartesian3.add(x,S,x),r.Cartesian3.normalize(x,x)),r.Cartesian3.pack(x,C.extrudeDirection.values,3*A)}if(i.defined(m)&&function(e,t,r,a,i,s,o){var u=i[e]*a.x,p=i[t]*a.y,d=i[r]*a.z;s[o]=u+p+d>n.CesiumMath.EPSILON6?1:0}(e,t,a,T,m,C.applyOffset.values,A),i.defined(p)&&ae(e,t,a,T,p,C.tangent.values,A,!0),i.defined(d)&&ae(e,t,a,T,d,C.bitangent.values,A,!0),i.defined(l)&&ie(e,t,a,T,l,C.st.values,A),b>0)for(var I=0;I3)for(var z=L.positions,D=L.indices,M=D.length,G=0;G0)){var p=r.Cartesian3.unpack(i,o,Te);(u.y<0&&p.y>0||u.y>0&&p.y<0)&&(o-3>0?(i[o]=a[o-3],i[o+1]=a[o-2],i[o+2]=a[o-1]):r.Cartesian3.pack(u,i,o));var d=r.Cartesian3.unpack(n,o,xe);(u.y<0&&d.y>0||u.y>0&&d.y<0)&&(o+30||s.BoundingSphere.intersectPlane(a,l.Plane.ORIGIN_ZX_PLANE)!==s.Intersect.INTERSECTING))return e;if(t.geometryType!==u.GeometryType.NONE)switch(t.geometryType){case u.GeometryType.POLYLINES:!function(e){var t,a,s,o=e.geometry,u=o.attributes,p=u.position.values,l=u.prevPosition.values,v=u.nextPosition.values,y=u.expandAndWidth.values,f=i.defined(u.st)?u.st.values:void 0,c=i.defined(u.color)?u.color.values:void 0,m=$(o),C=$(o),h=!1,b=p.length/3;for(t=0;t