refactor(es modules): migrate numberUtils

This commit is contained in:
Azgaar 2022-06-26 02:11:36 +03:00
parent b425a9daf6
commit ad252b54e6
63 changed files with 97 additions and 56 deletions

View file

@ -1,5 +1,4 @@
"use strict";
// FMG helper functions
import {rn} from "/src/utils/numberUtils";
// clip polygon by graph bbox
function clipPoly(points, secure = 0) {

View file

@ -1,22 +0,0 @@
"use strict";
// FMG utils related to numbers
// round value to d decimals
function rn(v, d = 0) {
const m = Math.pow(10, d);
return Math.round(v * m) / m;
}
function minmax(value, min, max) {
return Math.min(Math.max(value, min), max);
}
// return value in range [0, 100]
function lim(v) {
return minmax(v, 0, 100);
}
// normalization function
function normalize(val, min, max) {
return minmax((val - min) / (max - min), 0, 1);
}

View file

@ -1,16 +0,0 @@
"use strict";
// replaceAll
if (String.prototype.replaceAll === undefined) {
String.prototype.replaceAll = function (str, newStr) {
if (Object.prototype.toString.call(str).toLowerCase() === "[object regexp]") return this.replace(str, newStr);
return this.replace(new RegExp(str, "g"), newStr);
};
}
// flat
if (Array.prototype.flat === undefined) {
Array.prototype.flat = function () {
return this.reduce((acc, val) => (Array.isArray(val) ? acc.concat(val.flat()) : acc.concat(val)), []);
};
}

View file

@ -1,5 +1,4 @@
"use strict";
// FMG utils related to randomness
import {rn, minmax} from "/src/utils/numberUtils";
// random number in a range
function rand(min, max) {

View file

@ -1,5 +1,4 @@
"use strict";
// FMG utils related to strings
import {rn} from "/src/utils/numberUtils";
// round numbers in string to d decimals
function round(s, d = 1) {

View file

@ -1,5 +1,4 @@
"use strict";
// FMG utils related to units
import {rn} from "/src/utils/numberUtils";
// conver temperature from °C to other scales
const temperatureConversionMap = {