PolygonGeometryLibrary-20c09e27.js 8.4 KB

1
  1. define(["exports","./ArcType-29cf2197","./arrayRemoveDuplicates-d2f048c5","./Cartesian2-47311507","./Cartographic-3309dd0d","./ComponentDatatype-c140a87d","./when-b60132fc","./EllipsoidRhumbLine-ed1a6bf4","./GeometryAttribute-c42d25b7","./GeometryAttributes-252e9929","./GeometryPipeline-6d9322f0","./IndexDatatype-8a5eead4","./Math-119be1a3","./Matrix4-cde86d0e","./PolygonPipeline-805ba13c","./buildModuleUrl-57a32107"],(function(e,t,r,i,a,n,o,s,u,l,h,c,f,p,d,y){"use strict";function g(){this._array=[],this._offset=0,this._length=0}Object.defineProperties(g.prototype,{length:{get:function(){return this._length}}}),g.prototype.enqueue=function(e){this._array.push(e),this._length++},g.prototype.dequeue=function(){if(0!==this._length){var e=this._array,t=this._offset,r=e[t];return e[t]=void 0,++t>10&&2*t>e.length&&(this._array=e.slice(t),t=0),this._offset=t,this._length--,r}},g.prototype.peek=function(){if(0!==this._length)return this._array[this._offset]},g.prototype.contains=function(e){return-1!==this._array.indexOf(e)},g.prototype.clear=function(){this._array.length=this._offset=this._length=0},g.prototype.sort=function(e){this._offset>0&&(this._array=this._array.slice(this._offset),this._offset=0),this._array.sort(e)};var v={computeHierarchyPackedLength:function(e){for(var t=0,r=[e];r.length>0;){var i=r.pop();if(o.defined(i)){t+=2;var n=i.positions,s=i.holes;if(o.defined(n)&&(t+=n.length*a.Cartesian3.packedLength),o.defined(s))for(var u=s.length,l=0;l<u;++l)r.push(s[l])}}return t},packPolygonHierarchy:function(e,t,r){for(var i=[e];i.length>0;){var n=i.pop();if(o.defined(n)){var s=n.positions,u=n.holes;if(t[r++]=o.defined(s)?s.length:0,t[r++]=o.defined(u)?u.length:0,o.defined(s))for(var l=s.length,h=0;h<l;++h,r+=3)a.Cartesian3.pack(s[h],t,r);if(o.defined(u))for(var c=u.length,f=0;f<c;++f)i.push(u[f])}}return r},unpackPolygonHierarchy:function(e,t){for(var r=e[t++],i=e[t++],n=new Array(r),o=i>0?new Array(i):void 0,s=0;s<r;++s,t+=a.Cartesian3.packedLength)n[s]=a.Cartesian3.unpack(e,t);for(var u=0;u<i;++u)o[u]=v.unpackPolygonHierarchy(e,t),t=o[u].startingIndex,delete o[u].startingIndex;return{positions:n,holes:o,startingIndex:t}}},m=new a.Cartesian3;function C(e,t,r,i){return a.Cartesian3.subtract(t,e,m),a.Cartesian3.multiplyByScalar(m,r/i,m),a.Cartesian3.add(e,m,m),[m.x,m.y,m.z]}v.subdivideLineCount=function(e,t,r){var i=a.Cartesian3.distance(e,t)/r,n=Math.max(0,Math.ceil(f.CesiumMath.log2(i)));return Math.pow(2,n)};var b=new a.Cartographic,w=new a.Cartographic,I=new a.Cartographic,T=new a.Cartesian3;v.subdivideRhumbLineCount=function(e,t,r,i){var a=e.cartesianToCartographic(t,b),n=e.cartesianToCartographic(r,w),o=new s.EllipsoidRhumbLine(a,n,e).surfaceDistance/i,u=Math.max(0,Math.ceil(f.CesiumMath.log2(o)));return Math.pow(2,u)},v.subdivideLine=function(e,t,r,i){var n=v.subdivideLineCount(e,t,r),s=a.Cartesian3.distance(e,t),u=s/n;o.defined(i)||(i=[]);var l=i;l.length=3*n;for(var h=0,c=0;c<n;c++){var f=C(e,t,c*u,s);l[h++]=f[0],l[h++]=f[1],l[h++]=f[2]}return l},v.subdivideRhumbLine=function(e,t,r,i,a){var n=e.cartesianToCartographic(t,b),u=e.cartesianToCartographic(r,w),l=new s.EllipsoidRhumbLine(n,u,e),h=l.surfaceDistance/i,c=Math.max(0,Math.ceil(f.CesiumMath.log2(h))),p=Math.pow(2,c),d=l.surfaceDistance/p;o.defined(a)||(a=[]);var y=a;y.length=3*p;for(var g=0,v=0;v<p;v++){var m=l.interpolateUsingSurfaceDistance(v*d,I),C=e.cartographicToCartesian(m,T);y[g++]=C.x,y[g++]=C.y,y[g++]=C.z}return y};var E=new a.Cartesian3,x=new a.Cartesian3,P=new a.Cartesian3,M=new a.Cartesian3;v.scaleToGeodeticHeightExtruded=function(e,t,r,n,s){n=o.defaultValue(n,i.Ellipsoid.WGS84);var u=E,l=x,h=P,c=M;if(o.defined(e)&&o.defined(e.attributes)&&o.defined(e.attributes.position))for(var f=e.attributes.position.values,p=f.length/2,d=0;d<p;d+=3)a.Cartesian3.fromArray(f,d,h),n.geodeticSurfaceNormal(h,u),c=n.scaleToGeodeticSurface(h,c),l=a.Cartesian3.multiplyByScalar(u,r,l),l=a.Cartesian3.add(c,l,l),f[d+p]=l.x,f[d+1+p]=l.y,f[d+2+p]=l.z,s&&(c=a.Cartesian3.clone(h,c)),l=a.Cartesian3.multiplyByScalar(u,t,l),l=a.Cartesian3.add(c,l,l),f[d]=l.x,f[d+1]=l.y,f[d+2]=l.z;return e},v.polygonOutlinesFromHierarchy=function(e,t,i){var n,s,u,l=[],h=new g;for(h.enqueue(e);0!==h.length;){var c=h.dequeue(),f=c.positions;if(t)for(u=f.length,n=0;n<u;n++)i.scaleToGeodeticSurface(f[n],f[n]);if(!((f=r.arrayRemoveDuplicates(f,a.Cartesian3.equalsEpsilon,!0)).length<3)){var p=c.holes?c.holes.length:0;for(n=0;n<p;n++){var d=c.holes[n],y=d.positions;if(t)for(u=y.length,s=0;s<u;++s)i.scaleToGeodeticSurface(y[s],y[s]);if(!((y=r.arrayRemoveDuplicates(y,a.Cartesian3.equalsEpsilon,!0)).length<3)){l.push(y);var v=0;for(o.defined(d.holes)&&(v=d.holes.length),s=0;s<v;s++)h.enqueue(d.holes[s])}}l.push(f)}}return l};var _=new a.Cartesian3(6378137,6378137,6378137);v.polygonsFromHierarchy=function(e,t,i,n){var s=[],u=[],l=new g;for(l.enqueue(e);0!==l.length;){var h,c,p,y=l.dequeue(),v=y.positions,m=y.holes,C=v.slice();if(i)for(c=v.length,h=0;h<c;h++)n.scaleToGeodeticSurface(v[h],C[h]);if(o.defined(n)&&!a.Cartesian3.equals(n._radii,_)&&(p=f.CesiumMath.EPSILON7),!((v=r.arrayRemoveDuplicates(C,a.Cartesian3.equalsEpsilon,!0,p)).length<3)){var b=t(v);if(o.defined(b)){var w=[],I=d.PolygonPipeline.computeWindingOrder2D(b);I===d.WindingOrder.CLOCKWISE&&(b.reverse(),v=v.slice().reverse());var T,E=v.slice(),x=o.defined(m)?m.length:0,P=[];for(h=0;h<x;h++){var M=m[h],A=M.positions;if(i)for(c=A.length,T=0;T<c;++T)n.scaleToGeodeticSurface(A[T],A[T]);if(!((A=r.arrayRemoveDuplicates(A,a.Cartesian3.equalsEpsilon,!0,f.CesiumMath.EPSILON7)).length<3)){var L=t(A);if(o.defined(L)){(I=d.PolygonPipeline.computeWindingOrder2D(L))===d.WindingOrder.CLOCKWISE&&(L.reverse(),A=A.slice().reverse()),P.push(A),w.push(E.length),E=E.concat(A),b=b.concat(L);var G=0;for(o.defined(M.holes)&&(G=M.holes.length),T=0;T<G;T++)l.enqueue(M.holes[T])}}}s.push({outerRing:v,holes:P}),u.push({positions:E,positions2D:b,holes:w})}}}return{hierarchy:s,polygons:u}};var A=new i.Cartesian2,L=new a.Cartesian3,G=new u.Quaternion,S=new p.Matrix3;v.computeBoundingRectangle=function(e,t,r,i,n){for(var s=u.Quaternion.fromAxisAngle(e,i,G),l=p.Matrix3.fromQuaternion(s,S),h=Number.POSITIVE_INFINITY,c=Number.NEGATIVE_INFINITY,f=Number.POSITIVE_INFINITY,d=Number.NEGATIVE_INFINITY,y=r.length,g=0;g<y;++g){var v=a.Cartesian3.clone(r[g],L);p.Matrix3.multiplyByVector(l,v,v);var m=t(v,A);o.defined(m)&&(h=Math.min(h,m.x),c=Math.max(c,m.x),f=Math.min(f,m.y),d=Math.max(d,m.y))}return n.x=h,n.y=f,n.width=c-h,n.height=d-f,n},v.createGeometryFromPositions=function(e,r,i,a,o,s){var l=d.PolygonPipeline.triangulate(r.positions2D,r.holes);l.length<3&&(l=[0,1,2]);var c=r.positions;if(a){for(var f=c.length,p=new Array(3*f),g=0,v=0;v<f;v++){var m=c[v];p[g++]=m.x,p[g++]=m.y,p[g++]=m.z}var C=new u.Geometry({attributes:{position:new u.GeometryAttribute({componentDatatype:n.ComponentDatatype.DOUBLE,componentsPerAttribute:3,values:p})},indices:l,primitiveType:y.PrimitiveType.TRIANGLES});return o.normal?h.GeometryPipeline.computeNormal(C):C}return s===t.ArcType.GEODESIC?d.PolygonPipeline.computeSubdivision(e,c,l,i):s===t.ArcType.RHUMB?d.PolygonPipeline.computeRhumbLineSubdivision(e,c,l,i):void 0};var D=[],N=new a.Cartesian3,R=new a.Cartesian3;v.computeWallGeometry=function(e,r,i,o,s){var h,p,d,g,m,C=e.length,b=0;if(o)for(p=3*C*2,h=new Array(2*p),d=0;d<C;d++)g=e[d],m=e[(d+1)%C],h[b]=h[b+p]=g.x,h[++b]=h[b+p]=g.y,h[++b]=h[b+p]=g.z,h[++b]=h[b+p]=m.x,h[++b]=h[b+p]=m.y,h[++b]=h[b+p]=m.z,++b;else{var w=f.CesiumMath.chordLength(i,r.maximumRadius),I=0;if(s===t.ArcType.GEODESIC)for(d=0;d<C;d++)I+=v.subdivideLineCount(e[d],e[(d+1)%C],w);else if(s===t.ArcType.RHUMB)for(d=0;d<C;d++)I+=v.subdivideRhumbLineCount(r,e[d],e[(d+1)%C],w);for(p=3*(I+C),h=new Array(2*p),d=0;d<C;d++){var T;g=e[d],m=e[(d+1)%C],s===t.ArcType.GEODESIC?T=v.subdivideLine(g,m,w,D):s===t.ArcType.RHUMB&&(T=v.subdivideRhumbLine(r,g,m,w,D));for(var E=T.length,x=0;x<E;++x,++b)h[b]=T[x],h[b+p]=T[x];h[b]=m.x,h[b+p]=m.x,h[++b]=m.y,h[b+p]=m.y,h[++b]=m.z,h[b+p]=m.z,++b}}C=h.length;var P=c.IndexDatatype.createTypedArray(C/3,C-6*e.length),M=0;for(C/=6,d=0;d<C;d++){var _=d,A=_+1,L=_+C,G=L+1;g=a.Cartesian3.fromArray(h,3*_,N),m=a.Cartesian3.fromArray(h,3*A,R),a.Cartesian3.equalsEpsilon(g,m,f.CesiumMath.EPSILON10,f.CesiumMath.EPSILON10)||(P[M++]=_,P[M++]=L,P[M++]=A,P[M++]=A,P[M++]=L,P[M++]=G)}return new u.Geometry({attributes:new l.GeometryAttributes({position:new u.GeometryAttribute({componentDatatype:n.ComponentDatatype.DOUBLE,componentsPerAttribute:3,values:h})}),indices:P,primitiveType:y.PrimitiveType.TRIANGLES})},e.PolygonGeometryLibrary=v}));