Use Math.cosh

This commit is contained in:
Tim Schaub
2022-07-27 15:09:43 -06:00
parent f2d989b299
commit f32517a77f
3 changed files with 1 additions and 51 deletions
-26
View File
@@ -14,32 +14,6 @@ export function clamp(value, min, max) {
return Math.min(Math.max(value, min), max);
}
/**
* Return the hyperbolic cosine of a given number. The method will use the
* native `Math.cosh` function if it is available, otherwise the hyperbolic
* cosine will be calculated via the reference implementation of the Mozilla
* developer network.
*
* @param {number} x X.
* @return {number} Hyperbolic cosine of x.
*/
export const cosh = (function () {
// Wrapped in a iife, to save the overhead of checking for the native
// implementation on every invocation.
let cosh;
if ('cosh' in Math) {
// The environment supports the native Math.cosh function, use it…
cosh = Math.cosh;
} else {
// … else, use the reference implementation of MDN:
cosh = function (x) {
const y = /** @type {Math} */ (Math).exp(x);
return (y + 1 / y) / 2;
};
}
return cosh;
})();
/**
* Return the base 2 logarithm of a given number. The method will use the
* native `Math.log2` function if it is available, otherwise the base 2
+1 -2
View File
@@ -3,7 +3,6 @@
*/
import Projection from './Projection.js';
import Units from './Units.js';
import {cosh} from '../math.js';
/**
* Radius of WGS84 sphere
@@ -54,7 +53,7 @@ class EPSG3857Projection extends Projection {
global: true,
worldExtent: WORLD_EXTENT,
getPointResolution: function (resolution, point) {
return resolution / cosh(point[1] / RADIUS);
return resolution / Math.cosh(point[1] / RADIUS);
},
});
}