/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
import{isSome as t}from"../../../core/arrayUtils.js";import{isArrayBuffer as r}from"../../../core/typedArrayUtil.js";import{conjugate as e}from"../../../core/libs/gl-matrix-2/math/quat.js";import{create as o}from"../../../core/libs/gl-matrix-2/factories/quatf64.js";import{transformQuat as a}from"../../../core/libs/gl-matrix-2/math/vec3.js";import{clone as i,create as f}from"../../../core/libs/gl-matrix-2/factories/vec3f32.js";import n from"../../../geometry/SpatialReference.js";import{projectBuffer as s}from"../../../geometry/projection/projectBuffer.js";import{readGeometry as u,getAttributeValues as l,evaluateRenderer as m,filterInPlace as b}from"./i3s/PointCloudWorkerUtil.js";import{Obb as p}from"../support/orientedBoundingBox.js";class c{transform(t){const e=this._transform(t),o=[e.points.buffer,e.rgb.buffer];null!=e.pointIdFilterMap&&o.push(e.pointIdFilterMap.buffer);for(const a of e.attributes)"buffer"in a.values&&r(a.values.buffer)&&a.values.buffer!==e.rgb.buffer&&o.push(a.values.buffer);return Promise.resolve({result:e,transferList:o})}_transform(r){const e=u(r.schema,r.geometryBuffer);let o=e.length/3,a=null;const i=new Array,f=l(r.primaryAttributeData,e,o);null!=r.primaryAttributeData&&f&&i.push({attributeInfo:r.primaryAttributeData.attributeInfo,values:f});const s=l(r.modulationAttributeData,e,o);null!=r.modulationAttributeData&&s&&i.push({attributeInfo:r.modulationAttributeData.attributeInfo,values:s});let c=m(r.rendererInfo,f,s,o);if(r.filterInfo&&r.filterInfo.length>0&&null!=r.filterAttributesData){const f=r.filterAttributesData.filter(t).map(t=>{const r=l(t,e,o),a={attributeInfo:t.attributeInfo,values:r};return i.push(a),a});a=new Uint32Array(o),o=b(e,c,a,r.filterInfo,f)}for(const t of r.userAttributesData){const r=l(t,e,o);i.push({attributeInfo:t.attributeInfo,values:r})}3*o<c.length&&(c=c.slice(0,3*o)),I(e,o,r.elevationOffset);const g=h(e,o,p.fromData(r.obbData),n.fromJSON(r.inSR),n.fromJSON(r.outSR));return{obbData:r.obbData,points:g,rgb:c,attributes:i,pointIdFilterMap:a}}}function h(t,r,o,n,u){if(!s(t,n,0,t,u,0,r))throw new Error("Can't reproject");const l=i(o.center),m=f(),b=f(),p=i(o.halfSize);e(g,o.quaternion);const c=new Float32Array(3*r);for(let e=0;e<r;e++){let r=3*e;m[0]=t[r]-l[0],m[1]=t[r+1]-l[1],m[2]=t[r+2]-l[2],a(b,m,g),p[0]=Math.max(p[0],Math.abs(b[0])),p[1]=Math.max(p[1],Math.abs(b[1])),p[2]=Math.max(p[2],Math.abs(b[2])),c[r++]=m[0],c[r++]=m[1],c[r]=m[2]}return o.halfSize=p,c}function I(t,r,e){if(0!==e)for(let o=0;o<r;o++)t[3*o+2]+=e}const g=o();function j(){return new c}export{j as default};
