define(["exports","./AttributeCompression-4d18cc04","./Matrix2-fc7e9822","./RuntimeError-c581ca93","./defaultValue-94c3e563","./ComponentDatatype-4a60b8d6","./Transforms-3ac41eb6","./EncodedCartesian3-d3e254ea","./GeometryAttribute-a441ff32","./IndexDatatype-db156785","./IntersectionTests-68fbc42d","./Plane-e20fba8c"],(function(e,t,r,n,i,a,o,s,u,l,p,c){"use strict";const d=new r.Cartesian3,f=new r.Cartesian3,m=new r.Cartesian3;function y(e,t,o,s,u){let l,p,c,y,h,v,C,b;if(n.Check.defined("point",e),n.Check.defined("p0",t),n.Check.defined("p1",o),n.Check.defined("p2",s),i.defined(u)||(u=new r.Cartesian3),i.defined(t.z)){if(r.Cartesian3.equalsEpsilon(e,t,a.CesiumMath.EPSILON14))return r.Cartesian3.clone(r.Cartesian3.UNIT_X,u);if(r.Cartesian3.equalsEpsilon(e,o,a.CesiumMath.EPSILON14))return r.Cartesian3.clone(r.Cartesian3.UNIT_Y,u);if(r.Cartesian3.equalsEpsilon(e,s,a.CesiumMath.EPSILON14))return r.Cartesian3.clone(r.Cartesian3.UNIT_Z,u);l=r.Cartesian3.subtract(o,t,d),p=r.Cartesian3.subtract(s,t,f),c=r.Cartesian3.subtract(e,t,m),y=r.Cartesian3.dot(l,l),h=r.Cartesian3.dot(l,p),v=r.Cartesian3.dot(l,c),C=r.Cartesian3.dot(p,p),b=r.Cartesian3.dot(p,c)}else{if(r.Cartesian2.equalsEpsilon(e,t,a.CesiumMath.EPSILON14))return r.Cartesian3.clone(r.Cartesian3.UNIT_X,u);if(r.Cartesian2.equalsEpsilon(e,o,a.CesiumMath.EPSILON14))return r.Cartesian3.clone(r.Cartesian3.UNIT_Y,u);if(r.Cartesian2.equalsEpsilon(e,s,a.CesiumMath.EPSILON14))return r.Cartesian3.clone(r.Cartesian3.UNIT_Z,u);l=r.Cartesian2.subtract(o,t,d),p=r.Cartesian2.subtract(s,t,f),c=r.Cartesian2.subtract(e,t,m),y=r.Cartesian2.dot(l,l),h=r.Cartesian2.dot(l,p),v=r.Cartesian2.dot(l,c),C=r.Cartesian2.dot(p,p),b=r.Cartesian2.dot(p,c)}u.y=C*v-h*b,u.z=y*b-h*v;const w=y*C-h*h;if(0!==w)return u.y/=w,u.z/=w,u.x=1-u.y-u.z,u}const h={calculateACMR:function(e){e=i.defaultValue(e,i.defaultValue.EMPTY_OBJECT);const t=e.indices;let r=e.maximumIndex;const a=i.defaultValue(e.cacheSize,24);if(!i.defined(t))throw new n.DeveloperError("indices is required.");const o=t.length;if(o<3||o%3!==0)throw new n.DeveloperError("indices length must be a multiple of three.");if(r<=0)throw new n.DeveloperError("maximumIndex must be greater than zero.");if(a<3)throw new n.DeveloperError("cacheSize must be greater than two.");if(!i.defined(r)){r=0;let e=0,n=t[e];while(er&&(r=n),++e,n=t[e]}const s=[];for(let n=0;na&&(s[t[n]]=u,++u);return(u-a+1)/(o/3)},tipsify:function(e){e=i.defaultValue(e,i.defaultValue.EMPTY_OBJECT);const t=e.indices,r=e.maximumIndex,a=i.defaultValue(e.cacheSize,24);let o;function s(e,t,r,n){while(t.length>=1){const r=t[t.length-1];if(t.splice(t.length-1,1),e[r].numLiveTriangles>0)return r}while(o0)return++o,o-1;++o}return-1}function u(e,t,r,n,i,a,o){let u,l=-1,p=-1,c=0;while(cp||-1===p)&&(p=u,l=e)),++c}return-1===l?s(n,a,e,o):l}if(!i.defined(t))throw new n.DeveloperError("indices is required.");const l=t.length;if(l<3||l%3!==0)throw new n.DeveloperError("indices length must be a multiple of three.");if(r<=0)throw new n.DeveloperError("maximumIndex must be greater than zero.");if(a<3)throw new n.DeveloperError("cacheSize must be greater than two.");let p=0,c=0,d=t[c];const f=l;if(i.defined(r))p=r+1;else{while(cp&&(p=d),++c,d=t[c];if(-1===p)return 0;++p}const m=[];let y;for(y=0;ya&&(g.timeStamp=C,++C),++c}v=u(t,a,b,m,C,w,p)}return E}},v={};function C(e,t,r,n,i){e[t++]=r,e[t++]=n,e[t++]=n,e[t++]=i,e[t++]=i,e[t]=r}function b(e){const t=e.length,r=t/3*6,n=l.IndexDatatype.createTypedArray(t,r);let i=0;for(let a=0;a=3){const r=6*(t-2),n=l.IndexDatatype.createTypedArray(t,r);C(n,0,e[0],e[1],e[2]);let i=6;for(let a=3;a0){const t=e.length-1,r=6*(t-1),n=l.IndexDatatype.createTypedArray(t,r),i=e[0];let a=0;for(let o=1;oi&&(i=r[e]);e.indices=h.tipsify({indices:r,maximumIndex:i,cacheSize:t})}return e},v.fitToUnsignedShortIndices=function(e){if(!i.defined(e))throw new n.DeveloperError("geometry is required.");if(i.defined(e.indices)&&e.primitiveType!==u.PrimitiveType.TRIANGLES&&e.primitiveType!==u.PrimitiveType.LINES&&e.primitiveType!==u.PrimitiveType.POINTS)throw new n.DeveloperError("geometry.primitiveType must equal to PrimitiveType.TRIANGLES, PrimitiveType.LINES, or PrimitiveType.POINTS.");const t=[],r=u.Geometry.computeNumberOfVertices(e);if(i.defined(e.indices)&&r>=a.CesiumMath.SIXTY_FOUR_KILOBYTES){let r=[],n=[],o=0,s=T(e.attributes);const l=e.indices,p=l.length;let c;e.primitiveType===u.PrimitiveType.TRIANGLES?c=3:e.primitiveType===u.PrimitiveType.LINES?c=2:e.primitiveType===u.PrimitiveType.POINTS&&(c=1);for(let d=0;d=a.CesiumMath.SIXTY_FOUR_KILOBYTES&&(t.push(new u.Geometry({attributes:s,indices:n,primitiveType:e.primitiveType,boundingSphere:e.boundingSphere,boundingSphereCV:e.boundingSphereCV})),r=[],n=[],o=0,s=T(e.attributes))}0!==n.length&&t.push(new u.Geometry({attributes:s,indices:n,primitiveType:e.primitiveType,boundingSphere:e.boundingSphere,boundingSphereCV:e.boundingSphereCV}))}else t.push(e);return t};const E=new r.Cartesian3,D=new r.Cartographic;v.projectTo2D=function(e,t,s,l,p){if(!i.defined(e))throw new n.DeveloperError("geometry is required.");if(!i.defined(t))throw new n.DeveloperError("attributeName is required.");if(!i.defined(s))throw new n.DeveloperError("attributeName3D is required.");if(!i.defined(l))throw new n.DeveloperError("attributeName2D is required.");if(!i.defined(e.attributes[t]))throw new n.DeveloperError(`geometry must have attribute matching the attributeName argument: ${t}.`);if(e.attributes[t].componentDatatype!==a.ComponentDatatype.DOUBLE)throw new n.DeveloperError("The attribute componentDatatype must be ComponentDatatype.DOUBLE.");const c=e.attributes[t];p=i.defined(p)?p:new o.GeographicProjection;const d=p.ellipsoid,f=c.values,m=new Float64Array(f.length);let y=0;for(let a=0;aA&&(A=n)}return new u.Geometry({attributes:h,indices:w,primitiveType:y,boundingSphere:i.defined(T)?new o.BoundingSphere(T,A):void 0})}v.combineInstances=function(e){if(!i.defined(e)||e.length<1)throw new n.DeveloperError("instances is required and must have length greater than zero.");const t=[],r=[],a=e.length;for(let n=0;n0&&o.push(G(t,"geometry")),r.length>0&&(o.push(G(r,"westHemisphereGeometry")),o.push(G(r,"eastHemisphereGeometry"))),o};const M=new r.Cartesian3,q=new r.Cartesian3,R=new r.Cartesian3,V=new r.Cartesian3;v.computeNormal=function(e){if(!i.defined(e))throw new n.DeveloperError("geometry is required.");if(!i.defined(e.attributes.position)||!i.defined(e.attributes.position.values))throw new n.DeveloperError("geometry.attributes.position.values is required.");if(!i.defined(e.indices))throw new n.DeveloperError("geometry.indices is required.");if(e.indices.length<2||e.indices.length%3!==0)throw new n.DeveloperError("geometry.indices length must be greater than 0 and be a multiple of 3.");if(e.primitiveType!==u.PrimitiveType.TRIANGLES)throw new n.DeveloperError("geometry.primitiveType must be PrimitiveType.TRIANGLES.");const t=e.indices,o=e.attributes,s=o.position.values,l=o.position.values.length/3,p=t.length,c=new Array(l),d=new Array(p/3),f=new Array(p);let m;for(m=0;m0){for(y=0;y3&&(r[3]=0,r[4]=2,r[5]=3);let i=6;for(let n=3;ni?n>o?a.CesiumMath.sign(e.y):a.CesiumMath.sign(r.y):i>o?a.CesiumMath.sign(t.y):a.CesiumMath.sign(r.y);const u=s<0;ee(e,u),ee(t,u),ee(r,u)}v.compressVertices=function(e){if(!i.defined(e))throw new n.DeveloperError("geometry is required.");const o=e.attributes.extrudeDirection;let s,l;if(i.defined(o)){const n=o.values;l=n.length/3;const i=new Float32Array(2*l);let p=0;for(s=0;s=0||t.x>=0||r.x>=0)return;te(e,t,r);const n=e.y<0,i=t.y<0,a=r.y<0;let o=0;o+=n?1:0,o+=i?1:0,o+=a?1:0;const s=ue.indices;1===o?(s[1]=3,s[2]=4,s[5]=6,s[7]=6,s[8]=5,n?(ne(e,t,ie,oe),ne(e,r,ae,se),s[0]=0,s[3]=1,s[4]=2,s[6]=1):i?(ne(t,r,ie,oe),ne(t,e,ae,se),s[0]=1,s[3]=2,s[4]=0,s[6]=2):a&&(ne(r,e,ie,oe),ne(r,t,ae,se),s[0]=2,s[3]=0,s[4]=1,s[6]=0)):2===o&&(s[2]=4,s[4]=4,s[5]=3,s[7]=5,s[8]=6,n?i?a||(ne(r,e,ie,oe),ne(r,t,ae,se),s[0]=0,s[1]=1,s[3]=0,s[6]=2):(ne(t,r,ie,oe),ne(t,e,ae,se),s[0]=2,s[1]=0,s[3]=2,s[6]=1):(ne(e,t,ie,oe),ne(e,r,ae,se),s[0]=1,s[1]=2,s[3]=1,s[6]=0));const u=ue.positions;return u[0]=e,u[1]=t,u[2]=r,u.length=3,1!==o&&2!==o||(u[3]=ie,u[4]=ae,u[5]=oe,u[6]=se,u.length=7),ue}function pe(e,t){const r=e.attributes;if(0===r.position.values.length)return;for(const o in r)if(r.hasOwnProperty(o)&&i.defined(r[o])&&i.defined(r[o].values)){const e=r[o];e.values=a.ComponentDatatype.createTypedArray(e.componentDatatype,e.values)}const n=u.Geometry.computeNumberOfVertices(e);return e.indices=l.IndexDatatype.createTypedArray(n,e.indices),t&&(e.boundingSphere=o.BoundingSphere.fromVertices(r.position.values)),e}function ce(e){const t=e.attributes,r={};for(const n in t)if(t.hasOwnProperty(n)&&i.defined(t[n])&&i.defined(t[n].values)){const e=t[n];r[n]=new u.GeometryAttribute({componentDatatype:e.componentDatatype,componentsPerAttribute:e.componentsPerAttribute,normalize:e.normalize,values:[]})}return new u.Geometry({attributes:r,indices:[],primitiveType:e.primitiveType})}function de(e,t,r){const n=i.defined(e.geometry.boundingSphere);t=pe(t,n),r=pe(r,n),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 fe(e,t){const r=new e,n=new e,i=new e;return function(a,o,s,u,l,p,c,d){const f=e.fromArray(l,a*t,r),m=e.fromArray(l,o*t,n),y=e.fromArray(l,s*t,i);e.multiplyByScalar(f,u.x,f),e.multiplyByScalar(m,u.y,m),e.multiplyByScalar(y,u.z,y);const h=e.add(f,m,f);e.add(h,y,h),d&&e.normalize(h,h),e.pack(h,p,c*t)}}const me=fe(r.Cartesian4,4),ye=fe(r.Cartesian3,3),he=fe(r.Cartesian2,2),ve=function(e,t,r,n,i,o,s){const u=i[e]*n.x,l=i[t]*n.y,p=i[r]*n.z;o[s]=u+l+p>a.CesiumMath.EPSILON6?1:0},Ce=new r.Cartesian3,be=new r.Cartesian3,we=new r.Cartesian3,ge=new r.Cartesian3;function Te(e,t,n,a,o,s,u,l,p,c,d,f,m,h,v,C){if(!i.defined(s)&&!i.defined(u)&&!i.defined(l)&&!i.defined(p)&&!i.defined(c)&&0===h)return;const b=r.Cartesian3.fromArray(o,3*e,Ce),w=r.Cartesian3.fromArray(o,3*t,be),g=r.Cartesian3.fromArray(o,3*n,we),T=y(a,b,w,g,ge);if(i.defined(T)){if(i.defined(s)&&ye(e,t,n,T,s,f.normal.values,C,!0),i.defined(c)){const i=r.Cartesian3.fromArray(c,3*e,Ce),a=r.Cartesian3.fromArray(c,3*t,be),o=r.Cartesian3.fromArray(c,3*n,we);let s;r.Cartesian3.multiplyByScalar(i,T.x,i),r.Cartesian3.multiplyByScalar(a,T.y,a),r.Cartesian3.multiplyByScalar(o,T.z,o),r.Cartesian3.equals(i,r.Cartesian3.ZERO)&&r.Cartesian3.equals(a,r.Cartesian3.ZERO)&&r.Cartesian3.equals(o,r.Cartesian3.ZERO)?(s=Ce,s.x=0,s.y=0,s.z=0):(s=r.Cartesian3.add(i,a,i),r.Cartesian3.add(s,o,s),r.Cartesian3.normalize(s,s)),r.Cartesian3.pack(s,f.extrudeDirection.values,3*C)}if(i.defined(d)&&ve(e,t,n,T,d,f.applyOffset.values,C),i.defined(u)&&ye(e,t,n,T,u,f.tangent.values,C,!0),i.defined(l)&&ye(e,t,n,T,l,f.bitangent.values,C,!0),i.defined(p)&&he(e,t,n,T,p,f.st.values,C),h>0)for(let r=0;r3){const r=I.positions,i=I.indices,D=i.length;for(let x=0;x0)continue;const t=r.Cartesian3.unpack(i,s,Me);(e.y<0&&t.y>0||e.y>0&&t.y<0)&&(s-3>0?(i[s]=n[s-3],i[s+1]=n[s-2],i[s+2]=n[s-1]):r.Cartesian3.pack(e,i,s));const u=r.Cartesian3.unpack(a,s,qe);(e.y<0&&u.y>0||e.y>0&&u.y<0)&&(s+30||o.BoundingSphere.intersectPlane(r,c.Plane.ORIGIN_ZX_PLANE)!==o.Intersect.INTERSECTING)return e}if(t.geometryType!==u.GeometryType.NONE)switch(t.geometryType){case u.GeometryType.POLYLINES:Ye(e);break;case u.GeometryType.TRIANGLES:xe(e);break;case u.GeometryType.LINES:Oe(e);break}else Q(t),t.primitiveType===u.PrimitiveType.TRIANGLES?xe(e):t.primitiveType===u.PrimitiveType.LINES&&Oe(e);return e},e.GeometryPipeline=v}));