@stemy/ngx-utils 12.1.6 → 12.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundles/stemy-ngx-utils.umd.js +31 -0
- package/bundles/stemy-ngx-utils.umd.js.map +1 -1
- package/esm2015/ngx-utils/utils/math.utils.js +30 -1
- package/fesm2015/stemy-ngx-utils.js +29 -0
- package/fesm2015/stemy-ngx-utils.js.map +1 -1
- package/ngx-utils/utils/math.utils.d.ts +2 -0
- package/package.json +1 -1
|
@@ -1702,6 +1702,37 @@
|
|
|
1702
1702
|
precision = Math.pow(10, precision);
|
|
1703
1703
|
return Math.round(value * precision / divider) / precision;
|
|
1704
1704
|
};
|
|
1705
|
+
MathUtils.approxIndex = function (x, values, epsilon) {
|
|
1706
|
+
if (epsilon === void 0) { epsilon = null; }
|
|
1707
|
+
if (!Array.isArray(values) || values.length == 0) {
|
|
1708
|
+
return -1;
|
|
1709
|
+
}
|
|
1710
|
+
var s = 0;
|
|
1711
|
+
var e = values.length - 1;
|
|
1712
|
+
while (s <= e) {
|
|
1713
|
+
var i = Math.floor((s + e) / 2);
|
|
1714
|
+
var v = values[i];
|
|
1715
|
+
if (MathUtils.equal(v, x, epsilon)) {
|
|
1716
|
+
return i;
|
|
1717
|
+
}
|
|
1718
|
+
if (v < x) {
|
|
1719
|
+
s = i + 1;
|
|
1720
|
+
}
|
|
1721
|
+
else {
|
|
1722
|
+
e = i - 1;
|
|
1723
|
+
}
|
|
1724
|
+
}
|
|
1725
|
+
var m = Math.max(e, 0);
|
|
1726
|
+
var a = values[s];
|
|
1727
|
+
var b = values[m];
|
|
1728
|
+
return Math.abs(a - x) < Math.abs(b - x) ? s : m;
|
|
1729
|
+
};
|
|
1730
|
+
MathUtils.approximate = function (x, values, epsilon) {
|
|
1731
|
+
if (epsilon === void 0) { epsilon = null; }
|
|
1732
|
+
var _a;
|
|
1733
|
+
var index = MathUtils.approxIndex(x, values, epsilon);
|
|
1734
|
+
return (_a = values[index]) !== null && _a !== void 0 ? _a : null;
|
|
1735
|
+
};
|
|
1705
1736
|
return MathUtils;
|
|
1706
1737
|
}());
|
|
1707
1738
|
|