/*
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","../../../geometry","../../../core/maybe","../../../chunks/mat2d","../../../chunks/mat2df64","../../../chunks/quat","../../../chunks/quatf64","../../../chunks/vec3","../../../chunks/vec3f64","../../../geometry/support/Axis","../../../geometry/Point"],(function(e,r,t,n,o,a,s,i,l,c,f,u){"use strict";function m(e,r,t=null){return n.isSome(t)?[e,r,t]:[e,r]}function d(e,r,t=null){return n.isSome(t)?{x:e,y:r,z:t}:{x:e,y:r}}let h=function(){function e(e){this.spatialReference=e}return e.prototype.mapToLocalMultiple=function(e){return n.filterNones(e.map((e=>this.mapToLocal(e))))},r._createClass(e,[{key:"doUnnormalization",get:function(){return!1}}]),e}(),p=function(e){function t(r,t,n=null){var s;return(s=e.call(this,t)||this).defaultZ=n,s.transform=a.create(),s.transformInv=a.create(),s.transform=a.clone(r),o.invert(s.transformInv,s.transform),s}r._inheritsLoose(t,e);var n=t.prototype;return n.makeMapPoint=function(e,r){return m(e,r,this.defaultZ)},n.mapToLocal=function(e){return d(this.transform[0]*e[0]+this.transform[2]*e[1]+this.transform[4],this.transform[1]*e[0]+this.transform[3]*e[1]+this.transform[5])},n.localToMap=function(e){return m(this.transformInv[0]*e.x+this.transformInv[2]*e.y+this.transformInv[4],this.transformInv[1]*e.x+this.transformInv[3]*e.y+this.transformInv[5],this.defaultZ)},t}(h),S=function(e){function t(r,t){var n;(n=e.call(this,r.spatialReference)||this).view=r,n.defaultZ=null,n.pWS=c.create(),n.tangentFrameUpWS=c.create(),n.tangentFrameRightWS=c.create(),n.tangentFrameForwardWS=c.create(),n.localFrameRightWS=c.create(),n.localFrameUpWS=c.create(),n.worldToLocalTransform=i.create(),n.localToWorldTransform=i.create(),n.scale=1,n.scale=r.resolution,n.referenceMapPoint=t,n.defaultZ=t.hasZ?t.z:null;const o=r.state.camera.viewRight;n.view.renderCoordsHelper.toRenderCoords(n.referenceMapPoint,n.pWS),n.view.renderCoordsHelper.worldBasisAtPosition(n.pWS,f.Axis.X,n.tangentFrameRightWS),n.view.renderCoordsHelper.worldBasisAtPosition(n.pWS,f.Axis.Y,n.tangentFrameUpWS),n.view.renderCoordsHelper.worldBasisAtPosition(n.pWS,f.Axis.Z,n.tangentFrameForwardWS);const a=c.create();return l.scale(a,n.tangentFrameForwardWS,l.dot(o,n.tangentFrameForwardWS)),l.subtract(n.localFrameRightWS,o,a),l.normalize(n.localFrameRightWS,n.localFrameRightWS),l.cross(n.localFrameUpWS,n.tangentFrameForwardWS,n.localFrameRightWS),s.rotationTo(n.worldToLocalTransform,n.localFrameRightWS,n.tangentFrameRightWS),s.invert(n.localToWorldTransform,n.worldToLocalTransform),n}r._inheritsLoose(t,e);var o=t.prototype;return o.makeMapPoint=function(e,r){return m(e,r,this.defaultZ)},o.mapToLocal=function(e){const r=c.create();this.view.renderCoordsHelper.toRenderCoords(new u({x:e[0],y:e[1],spatialReference:this.spatialReference}),r),l.transformQuat(r,r,this.worldToLocalTransform);const t=this.view.renderCoordsHelper.fromRenderCoords(r,this.view.spatialReference);return n.isSome(t)?d(t.x/this.scale,t.y/this.scale):null},o.localToMap=function(e){const r=c.create();this.view.renderCoordsHelper.toRenderCoords(new u({x:e.x*this.scale,y:e.y*this.scale,spatialReference:this.spatialReference}),r),l.transformQuat(r,r,this.localToWorldTransform);const t=this.view.renderCoordsHelper.fromRenderCoords(r,this.view.spatialReference);return n.isSome(t)?m(t.x,t.y,this.defaultZ):null},r._createClass(t,[{key:"doUnnormalization",get:function(){return"global"===this.view.viewingMode}}]),t}(h);function w(e,r){if("2d"===e.type)return new p(e.state.transform,e.spatialReference,r.length>2?r[2]:null);if("3d"===e.type){const t=r.length>2?new u({x:r[0],y:r[1],z:r[2],spatialReference:e.spatialReference}):new u({x:r[0],y:r[1],spatialReference:e.spatialReference});return new S(e,t)}return null}e.AffineCoordinateSystem=p,e.SceneViewCoordinateSystem=S,e.SurfaceCoordinateSystem=h,e.createViewAlignedCoordinateSystem=w,e.makeMapPoint=m,e.makeSurfacePoint=d,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
