/**
 * @license
 * Cesium - https://github.com/CesiumGS/cesium
 * Version 1.126
 *
 * Copyright 2011-2022 Cesium Contributors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Columbus View (Pat. Pend.)
 *
 * Portions licensed separately.
 * See https://github.com/CesiumGS/cesium/blob/main/LICENSE.md for full licensing details.
 */
import{a as et}from"./chunk-A4R6HP5H.js";import{a as U}from"./chunk-NOHRD3OR.js";import"./chunk-REP6L7BH.js";import{a as y}from"./chunk-FSU6RZ6S.js";import"./chunk-VSCNOKDU.js";import{a as I}from"./chunk-YGC52UMX.js";import{a as $}from"./chunk-XLESIVYV.js";import"./chunk-MNEOPOLK.js";import"./chunk-I4G5DYCC.js";import{a as u}from"./chunk-HZQ2LRMY.js";import"./chunk-EP544XEE.js";import"./chunk-MDIGQ5JT.js";import{b as ot}from"./chunk-WV3AQKZG.js";import{a as tt}from"./chunk-K4QHJFYW.js";import"./chunk-CZ6DDD6J.js";import"./chunk-26PPBGHW.js";import"./chunk-FMJWH3RL.js";import{a as J}from"./chunk-E25VRLIZ.js";import{a as X}from"./chunk-FZEJ65E6.js";import{b as W,c as Y,d as z}from"./chunk-SPFUTSGC.js";import{d as K}from"./chunk-E2NX4UJ2.js";import{f as Q}from"./chunk-JBPQP6LH.js";import{a as N}from"./chunk-NLPIV6OK.js";import{a as i,c as x,d as m,e as P}from"./chunk-IIT3SHXK.js";import{a as q}from"./chunk-DLCTHPIV.js";import"./chunk-GMF7KJHC.js";import"./chunk-NYFH7JC3.js";import{a as f}from"./chunk-I2ICH2LD.js";import{b as B}from"./chunk-R6A52HT4.js";import{e as g}from"./chunk-D32DZSEC.js";var st=new i,at=new et,pt=new x,lt=new x,mt=new i,ft=new i,ut=new i,V=new i,yt=new i,ht=new i,nt=new Q,dt=new P,gt=new P,Pt=new i;function wt(t,e,n,o,r,a,s,c,p){let l=t.positions,u=ot.triangulate(t.positions2D,t.holes);u.length<3&&(u=[0,1,2]);let m=J.createTypedArray(l.length,u.length);m.set(u);let h=dt;if(0!==o){let t=Q.fromAxisAngle(s,o,nt);if(h=P.fromQuaternion(t,h),e.tangent||e.bitangent){t=Q.fromAxisAngle(s,-o,nt);let n=P.fromQuaternion(t,gt);c=i.normalize(P.multiplyByVector(n,c,c),c),e.bitangent&&(p=i.normalize(i.cross(s,c,p),p))}}else h=P.clone(P.IDENTITY,h);let y=lt;e.st&&(y.x=n.x,y.y=n.y);let d=l.length,f=3*d,k=new Float64Array(f),w=e.normal?new Float32Array(f):void 0,j=e.tangent?new Float32Array(f):void 0,E=e.bitangent?new Float32Array(f):void 0,H=e.st?new Float32Array(2*d):void 0,v=0,F=0,A=0,L=0,_=0;for(let i=0;i<d;i++){let t=l[i];if(k[v++]=t.x,k[v++]=t.y,k[v++]=t.z,e.st)if(g(r)&&r.positions.length===d)H[_++]=r.positions[i].x,H[_++]=r.positions[i].y;else{let e=P.multiplyByVector(h,t,st),o=a(e,pt);x.subtract(o,y,o);let i=q.clamp(o.x/n.width,0,1),r=q.clamp(o.y/n.height,0,1);H[_++]=i,H[_++]=r}e.normal&&(w[F++]=s.x,w[F++]=s.y,w[F++]=s.z),e.tangent&&(j[L++]=c.x,j[L++]=c.y,j[L++]=c.z),e.bitangent&&(E[A++]=p.x,E[A++]=p.y,E[A++]=p.z)}let b=new X;return e.position&&(b.position=new z({componentDatatype:N.DOUBLE,componentsPerAttribute:3,values:k})),e.normal&&(b.normal=new z({componentDatatype:N.FLOAT,componentsPerAttribute:3,values:w})),e.tangent&&(b.tangent=new z({componentDatatype:N.FLOAT,componentsPerAttribute:3,values:j})),e.bitangent&&(b.bitangent=new z({componentDatatype:N.FLOAT,componentsPerAttribute:3,values:E})),e.st&&(b.st=new z({componentDatatype:N.FLOAT,componentsPerAttribute:2,values:H})),new Y({attributes:b,indices:m,primitiveType:W.TRIANGLES})}function E(t){t=f(t,f.EMPTY_OBJECT);let e=t.polygonHierarchy,n=t.textureCoordinates;B.defined("options.polygonHierarchy",e);let o=f(t.vertexFormat,u.DEFAULT);this._vertexFormat=u.clone(o),this._polygonHierarchy=e,this._stRotation=f(t.stRotation,0),this._ellipsoid=m.clone(f(t.ellipsoid,m.default)),this._workerName="createCoplanarPolygonGeometry",this._textureCoordinates=n,this.packedLength=y.computeHierarchyPackedLength(e,i)+u.packedLength+m.packedLength+(g(n)?y.computeHierarchyPackedLength(n,x):1)+2}E.fromPositions=function(t){t=f(t,f.EMPTY_OBJECT),B.defined("options.positions",t.positions);let e={polygonHierarchy:{positions:t.positions},vertexFormat:t.vertexFormat,stRotation:t.stRotation,ellipsoid:t.ellipsoid,textureCoordinates:t.textureCoordinates};return new E(e)},E.pack=function(t,e,n){return B.typeOf.object("value",t),B.defined("array",e),n=f(n,0),n=y.packPolygonHierarchy(t._polygonHierarchy,e,n,i),m.pack(t._ellipsoid,e,n),n+=m.packedLength,u.pack(t._vertexFormat,e,n),n+=u.packedLength,e[n++]=t._stRotation,g(t._textureCoordinates)?n=y.packPolygonHierarchy(t._textureCoordinates,e,n,x):e[n++]=-1,e[n++]=t.packedLength,e};var _t=m.clone(m.UNIT_SPHERE),At=new u,bt={polygonHierarchy:{}};E.unpack=function(t,e,n){B.defined("array",t),e=f(e,0);let o=y.unpackPolygonHierarchy(t,e,i);e=o.startingIndex,delete o.startingIndex;let r=m.unpack(t,e,_t);e+=m.packedLength;let a=u.unpack(t,e,At);e+=u.packedLength;let s=t[e++],c=-1===t[e]?void 0:y.unpackPolygonHierarchy(t,e,x);g(c)?(e=c.startingIndex,delete c.startingIndex):e++;let p=t[e++];return g(n)||(n=new E(bt)),n._polygonHierarchy=o,n._ellipsoid=m.clone(r,n._ellipsoid),n._vertexFormat=u.clone(a,n._vertexFormat),n._stRotation=s,n._textureCoordinates=c,n.packedLength=p,n},E.createGeometry=function(t){let e=t._vertexFormat,n=t._polygonHierarchy,o=t._stRotation,r=t._textureCoordinates,a=g(r),s=n.positions;if(s=tt(s,i.equalsEpsilon,!0),s.length<3)return;let c=mt,p=ft,l=ut,u=yt,m=ht;if(!U.computeProjectTo2DArguments(s,V,u,m))return;if(c=i.cross(u,m,c),c=i.normalize(c,c),!i.equalsEpsilon(V,i.ZERO,q.EPSILON6)){let e=t._ellipsoid.geodeticSurfaceNormal(V,Pt);i.dot(c,e)<0&&(c=i.negate(c,c),u=i.negate(u,u))}let h=U.createProjectPointsTo2DFunction(V,u,m),d=U.createProjectPointTo2DFunction(V,u,m);e.tangent&&(p=i.clone(u,p)),e.bitangent&&(l=i.clone(m,l));let f=y.polygonsFromHierarchy(n,a,h,!1),k=f.hierarchy,P=f.polygons,x=function(t){return t},w=a?y.polygonsFromHierarchy(r,!0,x,!1).polygons:void 0;if(0===k.length)return;s=k[0].outerRing;let j=K.fromPoints(s),E=y.computeBoundingRectangle(c,d,s,o,at),H=[];for(let i=0;i<P.length;i++){let t=new I({geometry:wt(P[i],e,E,o,a?w[i]:void 0,d,c,p,l)});H.push(t)}let v=$.combineInstances(H)[0];v.attributes.position.values=new Float64Array(v.attributes.position.values),v.indices=J.createTypedArray(v.attributes.position.values.length/3,v.indices);let F=v.attributes;return e.position||delete F.position,new Y({attributes:F,indices:v.indices,primitiveType:v.primitiveType,boundingSphere:j})};var Z=E;function kt(t,e){return g(e)&&(t=Z.unpack(t,e)),Z.createGeometry(t)}var Xt=kt;export{Xt as default};