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