/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import{clone as n}from"../../core/lang.js";import{assertNotMesh as t}from"../asserts.js";import e from"../SpatialReference.js";import{earth as i}from"./Ellipsoid.js";import{webMercatorValid as r,equals as s,isWebMercator as a,isWGS84 as o}from"./spatialReferenceUtils.js";const l=57.29577951308232,u=.017453292519943;function f(n){return n*l}function p(n){return n*u}function c(n){return n/i.radius}function h(n){return Math.PI/2-2*Math.atan(Math.exp(-n/i.radius))}function m(n){return null!=n.wkid||null!=n.wkt}const x=[0,0];function g(n,t,e,i,r){const s=n,a=r;if(a.spatialReference=e,"x"in s&&"x"in a)[a.x,a.y]=t(s.x,s.y,x,i);else if("xmin"in s&&"xmin"in a)[a.xmin,a.ymin]=t(s.xmin,s.ymin,x,i),[a.xmax,a.ymax]=t(s.xmax,s.ymax,x,i);else if("paths"in s&&"paths"in a||"rings"in s&&"rings"in a){const n="paths"in s?s.paths:s.rings,e=[];let r;for(let s=0;s<n.length;s++){const a=n[s];r=[],e.push(r);for(let n=0;n<a.length;n++)r.push(t(a[n][0],a[n][1],[0,0],i)),a[n].length>2&&r[n].push(a[n][2]),a[n].length>3&&r[n].push(a[n][3])}"paths"in a?a.paths=e:a.rings=e}else if("points"in s&&"points"in a){const n=s.points,e=[];for(let r=0;r<n.length;r++)e[r]=t(n[r][0],n[r][1],[0,0],i),n[r].length>2&&e[r].push(n[r][2]),n[r].length>3&&e[r].push(n[r][3]);a.points=e}return r}function M(n,t){const e=n&&(m(n)?n:n.spatialReference),i=t&&(m(t)?t:t.spatialReference);return!(n&&"type"in n&&"mesh"===n.type||t&&"type"in t&&"mesh"===t.type||!e||!i)&&(!!s(i,e)||(a(i)&&o(e)||a(e)&&o(i)))}function y(t,i){if(null==t)return null;const r=t.spatialReference,l=i&&(m(i)?i:i.spatialReference);return M(r,l)?s(r,l)?n(t):a(l)?g(t,d,e.WebMercator,!1,n(t)):o(l)?g(t,R,e.WGS84,!1,n(t)):null:null}function d(n,t,e=[0,0]){t>89.99999?t=89.99999:t<-89.99999&&(t=-89.99999);const r=p(t);return e[0]=p(n)*i.radius,e[1]=i.halfSemiMajorAxis*Math.log((1+Math.sin(r))/(1-Math.sin(r))),e}function R(n,t,e=[0,0],s=!1){if(n===r[0])e[0]=-180;else if(n===r[1])e[0]=180;else{const t=f(n/i.radius);e[0]=s?t:t-360*Math.floor((t+180)/360)}return e[1]=f(Math.PI/2-2*Math.atan(Math.exp(-t/i.radius))),e}function j(i,r=!1,s=n(i)){return t(i),t(s),g(i,d,e.WebMercator,r,s)}function S(i,r=!1,s=n(i)){return t(i),t(s),g(i,R,e.WGS84,r,s)}export{M as canProject,j as geographicToWebMercator,d as lngLatToXY,y as project,S as webMercatorToGeographic,c as x2lon,R as xyToLngLat,h as y2lat};
