/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import{clamp as t}from"../../../../core/mathUtils.js";import{transformMat3 as r,normalize as o}from"../../../../core/libs/gl-matrix-2/math/vec3.js";import{create as n}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{newFloatArray as a}from"../../../../geometry/support/FloatArray.js";import{newShortArray as e}from"../../../../geometry/support/ShortArray.js";function s(t,r,o,n,a,e=2){const s=1/(Math.abs(o)+Math.abs(n)+Math.abs(a)),c=o*s,i=n*s,f=a<=0?(c>=0?1:-1)*(1-Math.abs(i)):c,h=a<=0?(i>=0?1:-1)*(1-Math.abs(c)):i,u=r*e;t[u]=m(f),t[u+1]=m(h)}function c(t){const r=t.length/3,o=e(2*r);let n=0;for(let a=0;a<r;++a)s(o,a,t[n++],t[n++],t[n++]);return o}function i(t,o){const a=t.length/3,e=new Int16Array(2*a);let c=0;const i=n();for(let n=0;n<a;++n)i[0]=t[c++],i[1]=t[c++],i[2]=t[c++],r(i,i,o),s(e,n,i[0],i[1],i[2]);return e}function f(t,r,n,a=2){const e=n*a,s=u(r[e]),c=u(r[e+1]),i=1-Math.abs(s)-Math.abs(c);return t[2]=i,i<0?(t[0]=(s>=0?1:-1)*(1-Math.abs(c)),t[1]=(c>=0?1:-1)*(1-Math.abs(s))):(t[0]=s,t[1]=c),o(t,t)}function h(t,r=2){const o=t.length/r,e=a(3*o),s=n();let c=0;for(let n=0;n<o;++n)f(s,t,n,r),e[c++]=s[0],e[c++]=s[1],e[c++]=s[2];return e}function m(r){return t(Math.round(32767*r),-32767,32767)}function u(r){return t(r/32767,-1,1)}export{i as compressAndTransformNormals,s as compressNormal,c as compressNormals,u as decodeInt16,f as decompressNormal,h as decompressNormals,m as encodeInt16};
