createPolygonGeometry.js 20 KB

1234567891011121314151617181920212223242526
  1. /**
  2. * @license
  3. * Cesium - https://github.com/CesiumGS/cesium
  4. * Version 1.110.1
  5. *
  6. * Copyright 2011-2022 Cesium Contributors
  7. *
  8. * Licensed under the Apache License, Version 2.0 (the "License");
  9. * you may not use this file except in compliance with the License.
  10. * You may obtain a copy of the License at
  11. *
  12. * http://www.apache.org/licenses/LICENSE-2.0
  13. *
  14. * Unless required by applicable law or agreed to in writing, software
  15. * distributed under the License is distributed on an "AS IS" BASIS,
  16. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. * See the License for the specific language governing permissions and
  18. * limitations under the License.
  19. *
  20. * Columbus View (Pat. Pend.)
  21. *
  22. * Portions licensed separately.
  23. * See https://github.com/CesiumGS/cesium/blob/main/LICENSE.md for full licensing details.
  24. */
  25. import{a as Pt}from"./chunk-UBTZOT6V.js";import{a as S}from"./chunk-4H2WV7QE.js";import{a as X}from"./chunk-LEGXNNON.js";import{a as ft}from"./chunk-CE6W255B.js";import{a as It}from"./chunk-54EUFFXI.js";import"./chunk-CAKU43HZ.js";import"./chunk-WNXNCTQK.js";import{a as At}from"./chunk-W6HUVIKD.js";import{a as Tt}from"./chunk-ML5MKDLJ.js";import{a as dt}from"./chunk-HL2OONDA.js";import{a as Q}from"./chunk-FEU4H2YL.js";import{a as J}from"./chunk-BV3RKX5O.js";import"./chunk-XQLAWHTP.js";import{a as _t,b as at}from"./chunk-P2SABSEB.js";import"./chunk-FO3UCCVP.js";import"./chunk-GTKXIG42.js";import{a as bt,b as Et}from"./chunk-EVUMPJJC.js";import"./chunk-BXMC6F3B.js";import{a as ut}from"./chunk-EUSUDYW7.js";import"./chunk-XYZU5ZKW.js";import{c as pt,d as ot}from"./chunk-ADEEKX5Q.js";import{d as Ot,f as mt}from"./chunk-O5E7EBKP.js";import"./chunk-LEJDAZA7.js";import{c as lt,d as b}from"./chunk-GMFQULD7.js";import{a as et}from"./chunk-IS523WNE.js";import{a as h,b as K,c as v,d as U}from"./chunk-4ZQSV4FU.js";import{a as c}from"./chunk-CLQ5X6HS.js";import"./chunk-6Y3U6IMI.js";import"./chunk-7DENS74L.js";import{a as H}from"./chunk-FOJGNIAW.js";import{a as rt,b as G}from"./chunk-UGI536VH.js";import{e as P}from"./chunk-BQUQ5TPM.js";function Dt(t,e){if(!P(t)||!P(e))throw new rt("identifier and message are required.");At(t,e)}var Nt=Dt;function O(t,e){this.position=t,P(this.position)||(this.position=new b),this.tangentPlane=e,P(this.tangentPlane)||(this.tangentPlane=O.NORTH_POLE_TANGENT_PLANE)}Object.defineProperties(O.prototype,{ellipsoid:{get:function(){return this.tangentPlane.ellipsoid}},x:{get:function(){return this.position.x}},y:{get:function(){return this.position.y}},conformalLatitude:{get:function(){let t=b.magnitude(this.position),e=2*this.ellipsoid.maximumRadius;return this.tangentPlane.plane.normal.z*(c.PI_OVER_TWO-2*Math.atan2(t,e))}},longitude:{get:function(){let t=c.PI_OVER_TWO+Math.atan2(this.y,this.x);return t>Math.PI&&(t-=c.TWO_PI),t}}});var st=new K,Vt=new h;O.prototype.getLatitude=function(t){P(t)||(t=v.WGS84),st.latitude=this.conformalLatitude,st.longitude=this.longitude,st.height=0;let e=this.ellipsoid.cartographicToCartesian(st,Vt);return t.cartesianToCartographic(e,st),st.latitude};var Mt=new bt,Bt=new h,jt=new h;O.fromCartesian=function(t,e){G.defined("cartesian",t);let o=c.signNotZero(t.z),n=O.NORTH_POLE_TANGENT_PLANE,i=O.SOUTH_POLE;o<0&&(n=O.SOUTH_POLE_TANGENT_PLANE,i=O.NORTH_POLE);let r=Mt;r.origin=n.ellipsoid.scaleToGeocentricSurface(t,r.origin),r.direction=h.subtract(r.origin,i,Bt),h.normalize(r.direction,r.direction);let a=Et.rayPlane(r,n.plane,jt),f=h.subtract(a,i,a),l=h.dot(n.xAxis,f),u=o*h.dot(n.yAxis,f);return P(e)?(e.position=new b(l,u),e.tangentPlane=n,e):new O(new b(l,u),n)};O.fromCartesianArray=function(t,e){G.defined("cartesians",t);let o=t.length;P(e)?e.length=o:e=new Array(o);for(let n=0;n<o;n++)e[n]=O.fromCartesian(t[n],e[n]);return e};O.clone=function(t,e){if(P(t))return P(e)?(e.position=t.position,e.tangentPlane=t.tangentPlane,e):new O(t.position,t.tangentPlane)};O.HALF_UNIT_SPHERE=Object.freeze(new v(.5,.5,.5));O.NORTH_POLE=Object.freeze(new h(0,0,.5));O.SOUTH_POLE=Object.freeze(new h(0,0,-.5));O.NORTH_POLE_TANGENT_PLANE=Object.freeze(new J(O.NORTH_POLE,O.HALF_UNIT_SPHERE));O.SOUTH_POLE_TANGENT_PLANE=Object.freeze(new J(O.SOUTH_POLE,O.HALF_UNIT_SPHERE));var k=O;var Wt=new K,Ht=new K;function Gt(t,e,o,n){let r=n.cartesianToCartographic(t,Wt).height,a=n.cartesianToCartographic(e,Ht);a.height=r,n.cartographicToCartesian(a,e);let f=n.cartesianToCartographic(o,Ht);f.height=r-100,n.cartographicToCartesian(f,o)}var Ct=new Pt,kt=new h,zt=new h,Ut=new h,Yt=new h,qt=new h,Qt=new h,gt=new h,Z=new h,ct=new h,Jt=new b,Zt=new b,Kt=new h,xt=new mt,Xt=new U,$t=new U;function wt(t){let e=t.vertexFormat,o=t.geometry,n=t.shadowVolume,i=o.attributes.position.values,r=P(o.attributes.st)?o.attributes.st.values:void 0,a=i.length,f=t.wall,l=t.top||f,u=t.bottom||f;if(e.st||e.normal||e.tangent||e.bitangent||n){let g=t.boundingRectangle,s=t.rotationAxis,E=t.projectTo2d,I=t.ellipsoid,B=t.stRotation,C=t.perPositionHeight,R=Jt;R.x=g.x,R.y=g.y;let V=e.st?new Float32Array(2*(a/3)):void 0,d;e.normal&&(C&&l&&!f?d=o.attributes.normal.values:d=new Float32Array(a));let A=e.tangent?new Float32Array(a):void 0,N=e.bitangent?new Float32Array(a):void 0,F=n?new Float32Array(a):void 0,w=0,y=0,T=zt,m=Ut,_=Yt,j=!0,q=Xt,$=$t;if(B!==0){let M=mt.fromAxisAngle(s,B,xt);q=U.fromQuaternion(M,q),M=mt.fromAxisAngle(s,-B,xt),$=U.fromQuaternion(M,$)}else q=U.clone(U.IDENTITY,q),$=U.clone(U.IDENTITY,$);let p=0,L=0;l&&u&&(p=a/2,L=a/3,a/=2);for(let M=0;M<a;M+=3){let W=h.fromArray(i,M,Kt);if(e.st&&!P(r)){let x=U.multiplyByVector(q,W,kt);x=I.scaleToGeodeticSurface(x,x);let D=E(x,Zt);b.subtract(D,R,D);let tt=c.clamp(D.x/g.width,0,1),it=c.clamp(D.y/g.height,0,1);u&&(V[w+L]=tt,V[w+1+L]=it),l&&(V[w]=tt,V[w+1]=it),w+=2}if(e.normal||e.tangent||e.bitangent||n){let x=y+1,D=y+2;if(f){if(M+3<a){let tt=h.fromArray(i,M+3,qt);if(j){let it=h.fromArray(i,M+a,Qt);C&&Gt(W,tt,it,I),h.subtract(tt,W,tt),h.subtract(it,W,it),T=h.normalize(h.cross(it,tt,T),T),j=!1}h.equalsEpsilon(tt,W,c.EPSILON10)&&(j=!0)}(e.tangent||e.bitangent)&&(_=I.geodeticSurfaceNormal(W,_),e.tangent&&(m=h.normalize(h.cross(_,T,m),m)))}else T=I.geodeticSurfaceNormal(W,T),(e.tangent||e.bitangent)&&(C&&(gt=h.fromArray(d,y,gt),Z=h.cross(h.UNIT_Z,gt,Z),Z=h.normalize(U.multiplyByVector($,Z,Z),Z),e.bitangent&&(ct=h.normalize(h.cross(gt,Z,ct),ct))),m=h.cross(h.UNIT_Z,T,m),m=h.normalize(U.multiplyByVector($,m,m),m),e.bitangent&&(_=h.normalize(h.cross(T,m,_),_)));e.normal&&(t.wall?(d[y+p]=T.x,d[x+p]=T.y,d[D+p]=T.z):u&&(d[y+p]=-T.x,d[x+p]=-T.y,d[D+p]=-T.z),(l&&!C||f)&&(d[y]=T.x,d[x]=T.y,d[D]=T.z)),n&&(f&&(T=I.geodeticSurfaceNormal(W,T)),F[y+p]=-T.x,F[x+p]=-T.y,F[D+p]=-T.z),e.tangent&&(t.wall?(A[y+p]=m.x,A[x+p]=m.y,A[D+p]=m.z):u&&(A[y+p]=-m.x,A[x+p]=-m.y,A[D+p]=-m.z),l&&(C?(A[y]=Z.x,A[x]=Z.y,A[D]=Z.z):(A[y]=m.x,A[x]=m.y,A[D]=m.z))),e.bitangent&&(u&&(N[y+p]=_.x,N[x+p]=_.y,N[D+p]=_.z),l&&(C?(N[y]=ct.x,N[x]=ct.y,N[D]=ct.z):(N[y]=_.x,N[x]=_.y,N[D]=_.z))),y+=3}}e.st&&!P(r)&&(o.attributes.st=new ot({componentDatatype:et.FLOAT,componentsPerAttribute:2,values:V})),e.normal&&(o.attributes.normal=new ot({componentDatatype:et.FLOAT,componentsPerAttribute:3,values:d})),e.tangent&&(o.attributes.tangent=new ot({componentDatatype:et.FLOAT,componentsPerAttribute:3,values:A})),e.bitangent&&(o.attributes.bitangent=new ot({componentDatatype:et.FLOAT,componentsPerAttribute:3,values:N})),n&&(o.attributes.extrudeDirection=new ot({componentDatatype:et.FLOAT,componentsPerAttribute:3,values:F}))}if(t.extrude&&P(t.offsetAttribute)){let g=i.length/3,s=new Uint8Array(g);if(t.offsetAttribute===dt.TOP)l&&u||f?s=s.fill(1,0,g/2):l&&(s=s.fill(1));else{let E=t.offsetAttribute===dt.NONE?0:1;s=s.fill(E)}o.attributes.applyOffset=new ot({componentDatatype:et.UNSIGNED_BYTE,componentsPerAttribute:1,values:s})}return o}var te=new K,ee=new K,nt={westOverIDL:0,eastOverIDL:0},ht=new Tt;function oe(t,e,o,n,i){if(i=H(i,new lt),!P(t)||t.length<3)return i.west=0,i.north=0,i.south=0,i.east=0,i;if(o===X.RHUMB)return lt.fromCartesianArray(t,e,i);ht.ellipsoid.equals(e)||(ht=new Tt(void 0,void 0,e)),i.west=Number.POSITIVE_INFINITY,i.east=Number.NEGATIVE_INFINITY,i.south=Number.POSITIVE_INFINITY,i.north=Number.NEGATIVE_INFINITY,nt.westOverIDL=Number.POSITIVE_INFINITY,nt.eastOverIDL=Number.NEGATIVE_INFINITY;let r=1/c.chordLength(n,e.maximumRadius),a=t.length,f=e.cartesianToCartographic(t[0],ee),l=te,u;for(let g=1;g<a;g++)u=l,l=f,f=e.cartesianToCartographic(t[g],u),ht.setEndPoints(l,f),Rt(ht,r,i,nt);return u=l,l=f,f=e.cartesianToCartographic(t[0],u),ht.setEndPoints(l,f),Rt(ht,r,i,nt),i.east-i.west>nt.eastOverIDL-nt.westOverIDL&&(i.west=nt.westOverIDL,i.east=nt.eastOverIDL,i.east>c.PI&&(i.east=i.east-c.TWO_PI),i.west>c.PI&&(i.west=i.west-c.TWO_PI)),i}var ne=new K;function Rt(t,e,o,n){let i=t.surfaceDistance,r=Math.ceil(i*e),a=r>0?i/(r-1):Number.POSITIVE_INFINITY,f=0;for(let l=0;l<r;l++){let u=t.interpolateUsingSurfaceDistance(f,ne);f+=a;let g=u.longitude,s=u.latitude;o.west=Math.min(o.west,g),o.east=Math.max(o.east,g),o.south=Math.min(o.south,s),o.north=Math.max(o.north,s);let E=g>=0?g:g+c.TWO_PI;n.westOverIDL=Math.min(n.westOverIDL,E),n.eastOverIDL=Math.max(n.eastOverIDL,E)}}var Lt=[];function ie(t,e,o,n,i,r,a,f,l,u){let g={walls:[]},s;if(a||f){let d=S.createGeometryFromPositions(t,e,o,n,r,l,u),A=d.attributes.position.values,N=d.indices,F,w;if(a&&f){let y=A.concat(A);F=y.length/3,w=ut.createTypedArray(F,N.length*2),w.set(N);let T=N.length,m=F/2;for(s=0;s<T;s+=3){let _=w[s]+m,j=w[s+1]+m,q=w[s+2]+m;w[s+T]=q,w[s+1+T]=j,w[s+2+T]=_}if(d.attributes.position.values=y,r&&l.normal){let _=d.attributes.normal.values;d.attributes.normal.values=new Float32Array(y.length),d.attributes.normal.values.set(_)}if(l.st&&P(o)){let _=d.attributes.st.values;d.attributes.st.values=new Float32Array(F*2),d.attributes.st.values=_.concat(_)}d.indices=w}else if(f){for(F=A.length/3,w=ut.createTypedArray(F,N.length),s=0;s<N.length;s+=3)w[s]=N[s+2],w[s+1]=N[s+1],w[s+2]=N[s];d.indices=w}g.topAndBottom=new ft({geometry:d})}let E=i.outerRing,I=J.fromPoints(E,t),B=I.projectPointsOntoPlane(E,Lt),C=at.computeWindingOrder2D(B);C===_t.CLOCKWISE&&(E=E.slice().reverse());let R=S.computeWallGeometry(E,o,t,n,r,u);g.walls.push(new ft({geometry:R}));let V=i.holes;for(s=0;s<V.length;s++){let d=V[s];I=J.fromPoints(d,t),B=I.projectPointsOntoPlane(d,Lt),C=at.computeWindingOrder2D(B),C===_t.COUNTER_CLOCKWISE&&(d=d.slice().reverse()),R=S.computeWallGeometry(d,o,t,n,r,u),g.walls.push(new ft({geometry:R}))}return g}function z(t){if(G.typeOf.object("options",t),G.typeOf.object("options.polygonHierarchy",t.polygonHierarchy),P(t.perPositionHeight)&&t.perPositionHeight&&P(t.height))throw new rt("Cannot use both options.perPositionHeight and options.height");if(P(t.arcType)&&t.arcType!==X.GEODESIC&&t.arcType!==X.RHUMB)throw new rt("Invalid arcType. Valid options are ArcType.GEODESIC and ArcType.RHUMB.");let e=t.polygonHierarchy,o=H(t.vertexFormat,Q.DEFAULT),n=H(t.ellipsoid,v.WGS84),i=H(t.granularity,c.RADIANS_PER_DEGREE),r=H(t.stRotation,0),a=t.textureCoordinates,f=H(t.perPositionHeight,!1),l=f&&P(t.extrudedHeight),u=H(t.height,0),g=H(t.extrudedHeight,u);if(!l){let s=Math.max(u,g);g=Math.min(u,g),u=s}this._vertexFormat=Q.clone(o),this._ellipsoid=v.clone(n),this._granularity=i,this._stRotation=r,this._height=u,this._extrudedHeight=g,this._closeTop=H(t.closeTop,!0),this._closeBottom=H(t.closeBottom,!0),this._polygonHierarchy=e,this._perPositionHeight=f,this._perPositionHeightExtrude=l,this._shadowVolume=H(t.shadowVolume,!1),this._workerName="createPolygonGeometry",this._offsetAttribute=t.offsetAttribute,this._arcType=H(t.arcType,X.GEODESIC),this._rectangle=void 0,this._textureCoordinateRotationPoints=void 0,this._textureCoordinates=a,this.packedLength=S.computeHierarchyPackedLength(e,h)+v.packedLength+Q.packedLength+(a?S.computeHierarchyPackedLength(a,b):1)+12}z.fromPositions=function(t){t=H(t,H.EMPTY_OBJECT),G.defined("options.positions",t.positions);let e={polygonHierarchy:{positions:t.positions},height:t.height,extrudedHeight:t.extrudedHeight,vertexFormat:t.vertexFormat,stRotation:t.stRotation,ellipsoid:t.ellipsoid,granularity:t.granularity,perPositionHeight:t.perPositionHeight,closeTop:t.closeTop,closeBottom:t.closeBottom,offsetAttribute:t.offsetAttribute,arcType:t.arcType,textureCoordinates:t.textureCoordinates};return new z(e)};z.pack=function(t,e,o){return G.typeOf.object("value",t),G.defined("array",e),o=H(o,0),o=S.packPolygonHierarchy(t._polygonHierarchy,e,o,h),v.pack(t._ellipsoid,e,o),o+=v.packedLength,Q.pack(t._vertexFormat,e,o),o+=Q.packedLength,e[o++]=t._height,e[o++]=t._extrudedHeight,e[o++]=t._granularity,e[o++]=t._stRotation,e[o++]=t._perPositionHeightExtrude?1:0,e[o++]=t._perPositionHeight?1:0,e[o++]=t._closeTop?1:0,e[o++]=t._closeBottom?1:0,e[o++]=t._shadowVolume?1:0,e[o++]=H(t._offsetAttribute,-1),e[o++]=t._arcType,P(t._textureCoordinates)?o=S.packPolygonHierarchy(t._textureCoordinates,e,o,b):e[o++]=-1,e[o++]=t.packedLength,e};var re=v.clone(v.UNIT_SPHERE),ae=new Q,se={polygonHierarchy:{}};z.unpack=function(t,e,o){G.defined("array",t),e=H(e,0);let n=S.unpackPolygonHierarchy(t,e,h);e=n.startingIndex,delete n.startingIndex;let i=v.unpack(t,e,re);e+=v.packedLength;let r=Q.unpack(t,e,ae);e+=Q.packedLength;let a=t[e++],f=t[e++],l=t[e++],u=t[e++],g=t[e++]===1,s=t[e++]===1,E=t[e++]===1,I=t[e++]===1,B=t[e++]===1,C=t[e++],R=t[e++],V=t[e]===-1?void 0:S.unpackPolygonHierarchy(t,e,b);P(V)?(e=V.startingIndex,delete V.startingIndex):e++;let d=t[e++];return P(o)||(o=new z(se)),o._polygonHierarchy=n,o._ellipsoid=v.clone(i,o._ellipsoid),o._vertexFormat=Q.clone(r,o._vertexFormat),o._height=a,o._extrudedHeight=f,o._granularity=l,o._stRotation=u,o._perPositionHeightExtrude=g,o._perPositionHeight=s,o._closeTop=E,o._closeBottom=I,o._shadowVolume=B,o._offsetAttribute=C===-1?void 0:C,o._arcType=R,o._textureCoordinates=V,o.packedLength=d,o};var ce=new b,he=new b,fe=new k;function vt(t,e,o,n,i,r){let a=t.longitude,f=a>=0?a:a+c.TWO_PI;i.westOverIdl=Math.min(i.westOverIdl,f),i.eastOverIdl=Math.max(i.eastOverIdl,f),r.west=Math.min(r.west,a),r.east=Math.max(r.east,a);let l=t.getLatitude(o),u=l;if(r.south=Math.min(r.south,l),r.north=Math.max(r.north,l),n!==X.RHUMB){let E=b.subtract(e.position,t.position,ce),I=b.dot(e.position,E)/b.dot(E,E);if(I>0&&I<1){let B=b.add(e.position,b.multiplyByScalar(E,-I,E),he),C=k.clone(e,fe);C.position=B;let R=C.getLatitude(o);r.south=Math.min(r.south,R),r.north=Math.max(r.north,R),Math.abs(l)>Math.abs(R)&&(u=R)}}let g=e.x*t.y-t.x*e.y,s=Math.sign(g);s!==0&&(s*=b.angleBetween(e.position,t.position)),u>=0&&(i.northAngle+=s),u<=0&&(i.southAngle+=s)}var St=new k,le=new k,Y={northAngle:0,southAngle:0,westOverIdl:0,eastOverIdl:0};z.computeRectangleFromPositions=function(t,e,o,n){if(G.defined("positions",t),P(n)||(n=new lt),t.length<3)return n;n.west=Number.POSITIVE_INFINITY,n.east=Number.NEGATIVE_INFINITY,n.south=Number.POSITIVE_INFINITY,n.north=Number.NEGATIVE_INFINITY,Y.northAngle=0,Y.southAngle=0,Y.westOverIdl=Number.POSITIVE_INFINITY,Y.eastOverIdl=Number.NEGATIVE_INFINITY;let i=t.length,r=k.fromCartesian(t[0],le);for(let a=1;a<i;a++){let f=k.fromCartesian(t[a],St);vt(f,r,e,o,Y,n),r=k.clone(f,r)}return vt(k.fromCartesian(t[0],St),r,e,o,Y,n),n.east-n.west>Y.eastOverIdl-Y.westOverIdl&&(n.west=Y.westOverIdl,n.east=Y.eastOverIdl,n.east>c.PI&&(n.east=n.east-c.TWO_PI),n.west>c.PI&&(n.west=n.west-c.TWO_PI)),c.equalsEpsilon(Math.abs(Y.northAngle),c.TWO_PI,c.EPSILON10)&&(n.north=c.PI_OVER_TWO,n.east=c.PI,n.west=-c.PI),c.equalsEpsilon(Math.abs(Y.southAngle),c.TWO_PI,c.EPSILON10)&&(n.south=-c.PI_OVER_TWO,n.east=c.PI,n.west=-c.PI),n};z.computeRectangle=function(t,e){G.typeOf.object("options",t),G.typeOf.object("options.polygonHierarchy",t.polygonHierarchy),Nt("PolygonGeometry.computeRectangle","PolygonGeometry.computeRectangle was deprecated in CesiumJS 1.110. It will be removed in CesiumJS 1.112. Use PolygonGeometry.computeRectangleFromPositions instead.");let o=H(t.granularity,c.RADIANS_PER_DEGREE),n=H(t.arcType,X.GEODESIC);if(n!==X.GEODESIC&&n!==X.RHUMB)throw new rt("Invalid arcType. Valid options are ArcType.GEODESIC and ArcType.RHUMB.");let i=t.polygonHierarchy,r=H(t.ellipsoid,v.WGS84);return oe(i.positions,r,n,o,e)};var me=new k;function ue(t,e,o){return t.height>=c.PI||t.width>=c.PI?k.fromCartesian(e[0],me).tangentPlane:J.fromPoints(e,o)}var Ft=new K;function de(t,e){return(o,n)=>{if(t.height>=c.PI||t.width>=c.PI){if(t.south<0&&t.north>0){P(n)||(n=[]);for(let r=0;r<o.length;++r){let a=e.cartesianToCartographic(o[r],Ft);n[r]=new b(a.longitude/c.PI,a.latitude/c.PI_OVER_TWO)}return n.length=o.length,n}return k.fromCartesianArray(o,n)}return J.fromPoints(o,e).projectPointsOntoPlane(o,n)}}function ge(t,e,o){if(t.height>=c.PI||t.width>=c.PI)return(i,r)=>{if(t.south<0&&t.north>0){let a=o.cartesianToCartographic(i,Ft);return P(r)||(r=new b),r.x=a.longitude/c.PI,r.y=a.latitude/c.PI_OVER_TWO,r}return k.fromCartesian(i,r)};let n=J.fromPoints(e,o);return(i,r)=>n.projectPointsOntoPlane(i,r)}function pe(t,e,o,n){return(i,r)=>!n&&(t.height>=c.PI_OVER_TWO||t.width>=2*c.PI_OVER_THREE)?S.splitPolygonsOnEquator(i,e,o,r):i}function Pe(t,e,o,n){if(e.height>=c.PI||e.width>=c.PI)return Pt.fromRectangle(e,void 0,Ct);let i=t,r=J.fromPoints(i,o);return S.computeBoundingRectangle(r.plane.normal,r.projectPointOntoPlane.bind(r),i,n,Ct)}z.createGeometry=function(t){let e=t._vertexFormat,o=t._ellipsoid,n=t._granularity,i=t._stRotation,r=t._polygonHierarchy,a=t._perPositionHeight,f=t._closeTop,l=t._closeBottom,u=t._arcType,g=t._textureCoordinates,s=P(g);if(r.positions.length<3)return;let I=t.rectangle,B=S.polygonsFromHierarchy(r,s,de(I,o),!a,o,pe(I,o,u,a)),C=B.hierarchy,R=B.polygons,V=function(p){return p},d=s?S.polygonsFromHierarchy(g,!0,V,!1,o).polygons:void 0;if(C.length===0)return;let A=C[0].outerRing,N=Pe(A,I,o,i),F=[],w=t._height,y=t._extrudedHeight,T=t._perPositionHeightExtrude||!c.equalsEpsilon(w,y,0,c.EPSILON2),m={perPositionHeight:a,vertexFormat:e,geometry:void 0,rotationAxis:ue(I,A,o).plane.normal,projectTo2d:ge(I,A,o),boundingRectangle:N,ellipsoid:o,stRotation:i,textureCoordinates:void 0,bottom:!1,top:!0,wall:!1,extrude:!1,arcType:u},_;if(T)for(m.extrude=!0,m.top=f,m.bottom=l,m.shadowVolume=t._shadowVolume,m.offsetAttribute=t._offsetAttribute,_=0;_<R.length;_++){let p=ie(o,R[_],s?d[_]:void 0,n,C[_],a,f,l,e,u),L;f&&l?(L=p.topAndBottom,m.geometry=S.scaleToGeodeticHeightExtruded(L.geometry,w,y,o,a)):f?(L=p.topAndBottom,L.geometry.attributes.position.values=at.scaleToGeodeticHeight(L.geometry.attributes.position.values,w,o,!a),m.geometry=L.geometry):l&&(L=p.topAndBottom,L.geometry.attributes.position.values=at.scaleToGeodeticHeight(L.geometry.attributes.position.values,y,o,!0),m.geometry=L.geometry),(f||l)&&(m.wall=!1,L.geometry=wt(m),F.push(L));let M=p.walls;m.wall=!0;for(let W=0;W<M.length;W++){let x=M[W];m.geometry=S.scaleToGeodeticHeightExtruded(x.geometry,w,y,o,a),x.geometry=wt(m),F.push(x)}}else for(_=0;_<R.length;_++){let p=new ft({geometry:S.createGeometryFromPositions(o,R[_],s?d[_]:void 0,n,a,e,u)});if(p.geometry.attributes.position.values=at.scaleToGeodeticHeight(p.geometry.attributes.position.values,w,o,!a),m.geometry=p.geometry,p.geometry=wt(m),P(t._offsetAttribute)){let L=p.geometry.attributes.position.values.length,M=t._offsetAttribute===dt.NONE?0:1,W=new Uint8Array(L/3).fill(M);p.geometry.attributes.applyOffset=new ot({componentDatatype:et.UNSIGNED_BYTE,componentsPerAttribute:1,values:W})}F.push(p)}let j=It.combineInstances(F)[0];j.attributes.position.values=new Float64Array(j.attributes.position.values),j.indices=ut.createTypedArray(j.attributes.position.values.length/3,j.indices);let q=j.attributes,$=Ot.fromVertices(q.position.values);return e.position||delete q.position,new pt({attributes:q,indices:j.indices,primitiveType:j.primitiveType,boundingSphere:$,offsetAttribute:t._offsetAttribute})};z.createShadowVolume=function(t,e,o){let n=t._granularity,i=t._ellipsoid,r=e(n,i),a=o(n,i);return new z({polygonHierarchy:t._polygonHierarchy,ellipsoid:i,stRotation:t._stRotation,granularity:n,perPositionHeight:!1,extrudedHeight:r,height:a,vertexFormat:Q.POSITION_ONLY,shadowVolume:!0,arcType:t._arcType})};function _e(t){let e=-t._stRotation;if(e===0)return[0,0,0,1,1,0];let o=t._ellipsoid,n=t._polygonHierarchy.positions,i=t.rectangle;return pt._textureCoordinateRotationPoints(n,e,o,i)}Object.defineProperties(z.prototype,{rectangle:{get:function(){if(!P(this._rectangle)){let t=this._polygonHierarchy.positions;this._rectangle=z.computeRectangleFromPositions(t,this._ellipsoid,this._arcType)}return this._rectangle}},textureCoordinateRotationPoints:{get:function(){return P(this._textureCoordinateRotationPoints)||(this._textureCoordinateRotationPoints=_e(this)),this._textureCoordinateRotationPoints}}});var yt=z;function Te(t,e){return P(e)&&(t=yt.unpack(t,e)),t._ellipsoid=v.clone(t._ellipsoid),yt.createGeometry(t)}var po=Te;export{po as default};