From f32517a77f711cc9858079ee0e65b307a7a425d7 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Wed, 27 Jul 2022 15:09:43 -0600 Subject: [PATCH] Use Math.cosh --- src/ol/math.js | 26 -------------------------- src/ol/proj/epsg3857.js | 3 +-- test/node/ol/math.test.js | 23 ----------------------- 3 files changed, 1 insertion(+), 51 deletions(-) diff --git a/src/ol/math.js b/src/ol/math.js index 96087f0d03..cf47a81b4e 100644 --- a/src/ol/math.js +++ b/src/ol/math.js @@ -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 diff --git a/src/ol/proj/epsg3857.js b/src/ol/proj/epsg3857.js index 16a69df67d..1ffcf96d65 100644 --- a/src/ol/proj/epsg3857.js +++ b/src/ol/proj/epsg3857.js @@ -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); }, }); } diff --git a/test/node/ol/math.test.js b/test/node/ol/math.test.js index ab7fc0da1e..505a519b13 100644 --- a/test/node/ol/math.test.js +++ b/test/node/ol/math.test.js @@ -2,7 +2,6 @@ import expect from '../expect.js'; import { ceil, clamp, - cosh, floor, lerp, log2, @@ -37,28 +36,6 @@ describe('ol/math.js', () => { }); }); - describe('cosh', function () { - it('returns the correct value at -Infinity', function () { - expect(cosh(-Infinity)).to.eql(Infinity); - }); - - it('returns the correct value at -1', function () { - expect(cosh(-1)).to.roughlyEqual(1.5430806348152437, 1e-9); - }); - - it('returns the correct value at 0', function () { - expect(cosh(0)).to.eql(1); - }); - - it('returns the correct value at 1', function () { - expect(cosh(1)).to.roughlyEqual(1.5430806348152437, 1e-9); - }); - - it('returns the correct value at Infinity', function () { - expect(cosh(Infinity)).to.eql(Infinity); - }); - }); - describe('log2', function () { it('returns the correct value at Infinity', function () { expect(log2(Infinity)).to.eql(Infinity);