/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../../../core/maybe","../../../core/unitUtils","../../../chunks/mat3f64","../../../chunks/mat4","../../../chunks/mat4f64","../../../chunks/mat3","../../projection","../../projectionEllipsoid","../MeshTransform","../buffer/BufferView","../../../chunks/vec32","./geographicUtils","./projection"],(function(e,n,r,t,o,a,i,l,f,s,c,u,p,g){"use strict";function m(e,n,r){return p.isGeographicMesh(n.spatialReference,r)?w(e,n,r):T(e,n,r)}function y(e,r,t){const{position:o,normal:a,tangent:i}=e;if(n.isNone(r))return{position:o,normal:a,tangent:i};const l=r.localMatrix;return m({position:g.transformPosition(o,new Float64Array(o.length),l),normal:n.isSome(a)?g.transformNormal(a,new Float32Array(a.length),l):null,tangent:n.isSome(i)?g.transformTangent(i,new Float32Array(i.length),l):null},r.getOriginPoint(t),{geographic:r.geographic})}function h(e,n,r){if(null!=r&&r.useTransform){var t;const{position:o,normal:a,tangent:i}=e;return{vertexAttributes:{position:o,normal:a,tangent:i},transform:new s({origin:[n.x,n.y,null!=(t=n.z)?t:0],geographic:p.isGeographicMesh(n.spatialReference,r)})}}return{vertexAttributes:m(e,n,r),transform:null}}function A(e,n,r){return p.isGeographicMesh(n.spatialReference,r)?d(e,n,r):R(e,n,r)}function F(e,r,t,o){if(n.isNone(r))return A(e,t,o);const a=y(e,r,t.spatialReference);return t.equals(r.getOriginPoint(t.spatialReference))?R(a,t,o):p.isGeographicMesh(t.spatialReference,o)?d(a,t,o):R(a,t,o)}function T(e,n,r){const t=new Float64Array(e.position.length),o=e.position,a=n.x,i=n.y,l=n.z||0,{horizontal:f,vertical:s}=j(r?r.unit:null,n.spatialReference);for(let c=0;c<o.length;c+=3)t[c+0]=o[c+0]*f+a,t[c+1]=o[c+1]*f+i,t[c+2]=o[c+2]*s+l;return{position:t,normal:e.normal,tangent:e.tangent}}function w(e,n,r){const t=n.spatialReference,o=B(n,r,S),a=new Float64Array(e.position.length),l=P(e.position,o,t,a),f=i.normalFromMat4(x,o);return{position:l,normal:V(l,a,e.normal,f,t),tangent:M(l,a,e.tangent,f,t)}}function P(e,n,r,t){u.transformMat4(c.BufferViewVec3f64.fromTypedArray(t),c.BufferViewVec3f64.fromTypedArray(e),n);const o=new Float64Array(e.length);return g.projectFromPCPF(t,o,r)}function V(e,r,t,o,a){if(n.isNone(t))return null;const i=new Float32Array(t.length);return u.transformMat3(c.BufferViewVec3f.fromTypedArray(i),c.BufferViewVec3f.fromTypedArray(t),o),g.projectNormalFromPCPF(i,e,r,a,i),i}function M(e,r,t,o,a){if(n.isNone(t))return null;const i=new Float32Array(t.length);u.transformMat3(c.BufferViewVec3f.fromTypedArray(i,4*Float32Array.BYTES_PER_ELEMENT),c.BufferViewVec3f.fromTypedArray(t,4*Float32Array.BYTES_PER_ELEMENT),o);for(let n=3;n<i.length;n+=4)i[n]=t[n];return g.projectTangentFromPCPF(i,e,r,a,i),i}function R(e,n,r){const t=new Float64Array(e.position.length),o=e.position,a=n.x,i=n.y,l=n.z||0,{horizontal:f,vertical:s}=j(r?r.unit:null,n.spatialReference);for(let c=0;c<o.length;c+=3)t[c+0]=(o[c+0]-a)/f,t[c+1]=(o[c+1]-i)/f,t[c+2]=(o[c+2]-l)/s;return{position:t,normal:e.normal,tangent:e.tangent}}function d(e,n,r){const t=n.spatialReference;B(n,r,S);const a=o.invert(z,S),l=new Float64Array(e.position.length),f=E(e.position,t,a,l),s=i.normalFromMat4(x,a);return{position:f,normal:v(e.normal,e.position,l,t,s),tangent:N(e.tangent,e.position,l,t,s)}}function B(e,n,r){l.computeTranslationToOriginAndRotation(e.spatialReference,[e.x,e.y,e.z||0],r,f.getSphericalPCPF(e.spatialReference));const{horizontal:t,vertical:a}=j(n?n.unit:null,e.spatialReference);return o.scale(r,r,[t,t,a]),r}function E(e,n,r,t){const o=g.projectToPCPF(e,n,t),a=c.BufferViewVec3f64.fromTypedArray(o),i=new Float64Array(o.length),l=c.BufferViewVec3f64.fromTypedArray(i);return u.transformMat4(l,a,r),i}function v(e,r,t,o,a){if(n.isNone(e))return null;const i=g.projectNormalToPCPF(e,r,t,o,new Float32Array(e.length)),l=c.BufferViewVec3f.fromTypedArray(i);return u.transformMat3(l,l,a),i}function N(e,r,t,o,a){if(n.isNone(e))return null;const i=g.projectTangentToPCPF(e,r,t,o,new Float32Array(e.length)),l=c.BufferViewVec3f.fromTypedArray(i,4*Float32Array.BYTES_PER_ELEMENT);return u.transformMat3(l,l,a),i}function j(e,t){if(n.isNone(e))return _;const o=t.isGeographic?1:r.getMetersPerUnitForSR(t),a=t.isGeographic?1:r.getMetersPerVerticalUnitForSR(t),i=r.convertUnit(1,e,"meters");return{horizontal:i*o,vertical:i*a}}const S=a.create(),z=a.create(),x=t.create(),_={horizontal:1,vertical:1};e.georeference=m,e.georeferenceApplyTransform=y,e.georeferenceByTransform=h,e.ungeoreference=A,e.ungeoreferenceByTransform=F,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
