From 7894c74dc7ca5f3d1852e6878f50b11ac2241be2 Mon Sep 17 00:00:00 2001 From: mrhso Date: Tue, 8 Jun 2021 14:15:53 +0800 Subject: [PATCH] Robinson: remove unnecessary halfPi, use sign --- src/robinson.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/robinson.js b/src/robinson.js index 965a4034..52edd99f 100644 --- a/src/robinson.js +++ b/src/robinson.js @@ -1,5 +1,5 @@ import {geoProjection as projection} from "d3-geo"; -import {abs, degrees, epsilon2, floor, halfPi, max, min, pi, radians} from "./math.js"; +import {abs, degrees, epsilon2, floor, max, min, pi, radians, sign} from "./math.js"; var K = [ [0.9986, -0.062], @@ -25,7 +25,7 @@ var K = [ ]; K.forEach(function(d) { - d[1] *= 1.0144; + d[1] *= 1.593415793900743; }); export function robinsonRaw(lambda, phi) { @@ -41,13 +41,12 @@ export function robinsonRaw(lambda, phi) { k; return [ lambda * (bx + di * (cx - ax) / 2 + di * di * (cx - 2 * bx + ax) / 2), - (phi > 0 ? halfPi : -halfPi) * (by + di * (cy - ay) / 2 + di * di * (cy - 2 * by + ay) / 2) + sign(phi) * (by + di * (cy - ay) / 2 + di * di * (cy - 2 * by + ay) / 2) ]; } robinsonRaw.invert = function(x, y) { - var yy = y / halfPi, - phi = yy * 90, + var phi = y * 90, i = min(18, abs(phi / 5)), i0 = max(0, floor(i)); do { @@ -56,7 +55,7 @@ robinsonRaw.invert = function(x, y) { cy = K[min(19, i0 + 2)][1], u = cy - ay, v = cy - 2 * by + ay, - t = 2 * (abs(yy) - by) / u, + t = 2 * (abs(y) - by) / u, c = v / u, di = t * (1 - c * t * (1 - 2 * c * t)); if (di >= 0 || i0 === 1) { @@ -69,7 +68,7 @@ robinsonRaw.invert = function(x, y) { ay = K[i0][1]; by = K[i0 + 1][1]; cy = K[min(19, i0 + 2)][1]; - phi -= (delta = (y >= 0 ? halfPi : -halfPi) * (by + di * (cy - ay) / 2 + di * di * (cy - 2 * by + ay) / 2) - y) * degrees; + phi -= (delta = sign(y) * (by + di * (cy - ay) / 2 + di * di * (cy - 2 * by + ay) / 2) - y) * degrees; } while (abs(delta) > epsilon2 && --j > 0); break; }