/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import s from"../../../core/Logger.js";import t from"../../../core/PooledArray.js";import{create as o}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{WorkerHandle as e}from"../../../core/workers/WorkerHandle.js";import{canProjectWithoutEngine as r}from"../../../geometry/projectionUtils.js";import{projectVectorToVector as n}from"../../../geometry/projection/projectVectorToVector.js";class i{constructor(s,t,o,e,r,n){this.layout=s,this.interleavedVertexData=t,this.indices=o,this.hasColors=e,this.hasModifications=r,this.positionData=n}}class h{constructor(s,t,o,e,r,n,i){this.componentOffsets=s,this.featureIds=t,this.anchorIds=o,this.anchors=e,this.transformedGeometry=r,this.globalTrafo=n,this.obb=i}}class a extends e{constructor(s){super("SceneLayerWorker","process",{process:s=>[s.geometryBuffer],project:s=>[s.positions.buffer],transformNormals:s=>[s.normals.buffer]},s,{hasInitialize:!0})}setModifications(s,t,o){const e={context:s,modifications:t,isGeodetic:o};return this.broadcast(e,"setModifications")}setLegacySchema(s,t){const o=JSON.stringify(t);return this.broadcast({context:s,jsonSchema:o},"setLegacySchema")}destroyContext(s){return this.broadcast(s,"destroyContext")}async destroyContextAndSelf(s){await this.destroyContext(s),this.destroy()}project(s,t){return this.invokeMethod("project",s,t)}transformNormals(s,t){return this.invokeMethod("transformNormals",s,t)}}const p=new t({deallocator:null}),c=o();function u(t,o,e){p.clear();let i=1/0,h=1/0,a=-1/0,u=-1/0,l=!1;for(const m of o){const t="clip"===m.type?2:"mask"===m.type?1:0,o=m.geometry;let f=s=>s;if(o.spatialReference){if(!r(o.spatialReference,e)){s.getLogger("esri.views.3d.layers.SceneLayerWorkerHandle").warn("im-modification-projection-failed","Can't project modification polygon into layer spatial reference, ignoring modification",{polygon:o});continue}f=s=>(n(s,o.spatialReference,c,e),c)}l=l||1===t;const g=o.rings.length,d=o.rings.some(s=>s.length<3);if(0===g||d)s.getLogger("esri.views.3d.layers.SceneLayerWorkerHandle").warn("im-modification-invalid-polygon","Ignoring invalid modification polygon (no rings or rings with less than 3 vertices).",{polygon:o});else{p.push(t),p.push(g);for(const s of o.rings){p.push(s.length);for(const t of s){const s=f(t);p.push(s[0]),p.push(s[1]),p.push(s[2]??0),i=Math.min(i,s[0]),h=Math.min(h,s[1]),a=Math.max(a,s[0]),u=Math.max(u,s[1])}}}}if(null!=t)if(l){const s=1e-4;p.push(2),p.push(2),p.push(4),p.push(i-s),p.push(h-s),p.push(0),p.push(a+s),p.push(h-s),p.push(0),p.push(a+s),p.push(u+s),p.push(0),p.push(i-s),p.push(u+s),p.push(0),p.push(4),p.push(t[0]),p.push(t[1]),p.push(0),p.push(t[2]),p.push(t[1]),p.push(0),p.push(t[2]),p.push(t[3]),p.push(0),p.push(t[0]),p.push(t[3]),p.push(0)}else p.push(1),p.push(1),p.push(4),p.push(t[0]),p.push(t[1]),p.push(0),p.push(t[2]),p.push(t[1]),p.push(0),p.push(t[2]),p.push(t[3]),p.push(0),p.push(t[0]),p.push(t[3]),p.push(0);p.push(3);const f=new Float64Array(p.length);for(let s=0;s<p.length;++s)f[s]=p.at(s);return f}function l(s,t){let o=0;for(const e of t){const t=e.geometry,r=t.rings.length,n=t.rings.some(s=>s.length<3);if(0!==r&&!n){o+=1,o+=1;for(let e=0;e<t.rings.length;++e){const r=t.rings[e];o+=1;for(let n=0;n<r.length;++n){const r=[s[o+0],s[o+1],s[o+2]];o+=3,t.setPoint(e,n,r)}}}}}export{a as SceneLayerWorkerHandle,h as TransformedData,i as TransformedGeometry,l as fromWasmModification,u as toWasmModification};
