/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../../../chunks/_rollupPluginBabelHelpers","../../../core/Logger","../../../core/maybe","../../../core/PooledArray","../../../core/workers/WorkerHandle","../../../geometry/projection","../../../libs/i3s/enums"],(function(e,s,o,t,i,n,p,r){"use strict";const u=o.getLogger("esri.views.3d.layers.I3SMeshWorkerHandle");let h=function(e){function o(s){return e.call(this,"SceneLayerWorker","process",{process:e=>[e.geometryBuffer]},s,{hasInitialize:!0})||this}s._inheritsLoose(o,e);var t=o.prototype;return t.setModifications=function(e,s,o,t){const i={context:e,modifications:l(s,o,t),isGeodetic:t.isGeographic};this.broadcast(i,"setModifications")},t.setLegacySchema=function(e,s){const o=JSON.stringify(s);this.broadcast({context:e,jsonSchema:o},"setLegacySchema")},t.destroyContext=function(e){return this.broadcast(e,"destroyContext")},o}(n.WorkerHandle);const c=new i({deallocator:null}),a=[0,0,0];function l(e,s,o){c.clear();let i=1/0,n=1/0,h=-1/0,l=-1/0,f=!1;for(const t of s){const e="clip"===t.type?r.ModificationType.Inside:"mask"===t.type?r.ModificationType.Outside:r.ModificationType.Replace,s=t.geometry;let d=e=>e;if(s.spatialReference){if(!p.canProjectWithoutEngine(s.spatialReference,o)){u.warn("Can't project modification polygon into layer spatial reference, ignoring modification");continue}d=e=>(p.projectVectorToVector(e,s.spatialReference,a,o),a)}else s.hasZ||(a[2]=0,d=e=>(a[0]=e[0],a[1]=e[1],a));f=f||e===r.ModificationType.Outside,c.push(e),c.push(s.rings.length);for(const o of s.rings){c.push(o.length);for(const e of o){const s=d(e);c.push(s[0]),c.push(s[1]),c.push(s[2]),i=Math.min(i,s[0]),n=Math.min(n,s[1]),h=Math.max(h,s[0]),l=Math.max(l,s[1])}}}if(t.isSome(e))if(f){const s=1e-4;c.push(r.ModificationType.Inside),c.push(2),c.push(4),c.push(i-s),c.push(n-s),c.push(0),c.push(h+s),c.push(n-s),c.push(0),c.push(h+s),c.push(l+s),c.push(0),c.push(i-s),c.push(l+s),c.push(0),c.push(4),c.push(e[0]),c.push(e[1]),c.push(0),c.push(e[2]),c.push(e[1]),c.push(0),c.push(e[2]),c.push(e[3]),c.push(0),c.push(e[0]),c.push(e[3]),c.push(0)}else c.push(r.ModificationType.Outside),c.push(1),c.push(4),c.push(e[0]),c.push(e[1]),c.push(0),c.push(e[2]),c.push(e[1]),c.push(0),c.push(e[2]),c.push(e[3]),c.push(0),c.push(e[0]),c.push(e[3]),c.push(0);c.push(r.ModificationType.Finished);const d=new Float64Array(c.length);for(let t=0;t<c.length;++t)d[t]=c.getItemAt(t);return d}e.I3SMeshWorkerHandle=h,e.toWasmModification=l,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
