maths.js 3.2 KB

12345
  1. /*
  2. All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  3. See https://js.arcgis.com/4.25/esri/copyright.txt for details.
  4. */
  5. import{y as n,b as t,k as r,a as u,m as e,c as o,L as i,g as a,h as f,x as s}from"../../chunks/languageUtils.js";import{parse as c}from"../../core/number.js";function l(n,t,r){return void 0===r||0==+r?Math[n](t):(t=+t,r=+r,isNaN(t)||"number"!=typeof r||r%1!=0?NaN:(t=t.toString().split("e"),+((t=(t=Math[n](+(t[0]+"e"+(t[1]?+t[1]-r:-r)))).toString().split("e"))[0]+"e"+(t[1]?+t[1]+r:r))))}function N(N,h){function m(n,t,r){const u=a(n);return isNaN(u)?u:isNaN(t)||isNaN(r)||t>r?NaN:u<t?t:u>r?r:u}N.number=function(a,f){return h(a,f,((s,l,N)=>{n(N,1,2,a,f);const h=N[0];if(t(h))return h;if(null===h)return 0;if(r(h))return Number(h);if(u(h))return Number(h);if(e(h))return NaN;if(""===h)return Number(h);if(void 0===h)return Number(h);if(o(h)){if(void 0!==N[1]){let n=i(N[1],"‰","");return n=i(n,"¤",""),c(h,{pattern:n})}return Number(h.trim())}return Number(h)}))},N.abs=function(t,r){return h(t,r,((u,e,o)=>(n(o,1,1,t,r),Math.abs(a(o[0])))))},N.acos=function(t,r){return h(t,r,((u,e,o)=>(n(o,1,1,t,r),Math.acos(a(o[0])))))},N.asin=function(t,r){return h(t,r,((u,e,o)=>(n(o,1,1,t,r),Math.asin(a(o[0])))))},N.atan=function(t,r){return h(t,r,((u,e,o)=>(n(o,1,1,t,r),Math.atan(a(o[0])))))},N.atan2=function(t,r){return h(t,r,((u,e,o)=>(n(o,2,2,t,r),Math.atan2(a(o[0]),a(o[1])))))},N.ceil=function(t,r){return h(t,r,((u,e,o)=>{if(n(o,1,2,t,r),2===o.length){let n=a(o[1]);return isNaN(n)&&(n=0),l("ceil",a(o[0]),-1*n)}return Math.ceil(a(o[0]))}))},N.round=function(t,r){return h(t,r,((u,e,o)=>{if(n(o,1,2,t,r),2===o.length){let n=a(o[1]);return isNaN(n)&&(n=0),l("round",a(o[0]),-1*n)}return Math.round(a(o[0]))}))},N.floor=function(t,r){return h(t,r,((u,e,o)=>{if(n(o,1,2,t,r),2===o.length){let n=a(o[1]);return isNaN(n)&&(n=0),l("floor",a(o[0]),-1*n)}return Math.floor(a(o[0]))}))},N.cos=function(t,r){return h(t,r,((u,e,o)=>(n(o,1,1,t,r),Math.cos(a(o[0])))))},N.isnan=function(t,r){return h(t,r,((u,e,o)=>(n(o,1,1,t,r),"number"==typeof o[0]&&isNaN(o[0]))))},N.exp=function(t,r){return h(t,r,((u,e,o)=>(n(o,1,1,t,r),Math.exp(a(o[0])))))},N.log=function(t,r){return h(t,r,((u,e,o)=>(n(o,1,1,t,r),Math.log(a(o[0])))))},N.pow=function(t,r){return h(t,r,((u,e,o)=>(n(o,2,2,t,r),a(o[0])**a(o[1]))))},N.random=function(t,r){return h(t,r,((u,e,o)=>(n(o,0,0,t,r),Math.random())))},N.sin=function(t,r){return h(t,r,((u,e,o)=>(n(o,1,1,t,r),Math.sin(a(o[0])))))},N.sqrt=function(t,r){return h(t,r,((u,e,o)=>(n(o,1,1,t,r),Math.sqrt(a(o[0])))))},N.tan=function(t,r){return h(t,r,((u,e,o)=>(n(o,1,1,t,r),Math.tan(a(o[0])))))},N.defaultvalue=function(t,r){return h(t,r,((u,e,o)=>(n(o,2,2,t,r),null===o[0]||""===o[0]||void 0===o[0]?o[1]:o[0])))},N.isempty=function(t,r){return h(t,r,((u,e,o)=>(n(o,1,1,t,r),null===o[0]||(""===o[0]||void 0===o[0]))))},N.boolean=function(t,r){return h(t,r,((u,e,o)=>{n(o,1,1,t,r);const i=o[0];return f(i)}))},N.constrain=function(t,r){return h(t,r,((u,o,i)=>{n(i,3,3,t,r);const f=a(i[1]),c=a(i[2]);if(e(i[0])){const n=[];for(const t of i[0])n.push(m(t,f,c));return n}if(s(i[0])){const n=[];for(let t=0;t<i[0].length();t++)n.push(m(i[0].get(t),f,c));return n}return m(i[0],f,c)}))}}export{N as registerFunctions};