Skip to content

Commit

Permalink
Robinson: remove unnecessary halfPi, use sign
Browse files Browse the repository at this point in the history
  • Loading branch information
mrhso authored and Fil committed Jun 8, 2021
1 parent c9031f0 commit 7894c74
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/robinson.js
Original file line number Diff line number Diff line change
@@ -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],
Expand All @@ -25,7 +25,7 @@ var K = [
];

K.forEach(function(d) {
d[1] *= 1.0144;
d[1] *= 1.593415793900743;
});

export function robinsonRaw(lambda, phi) {
Expand All @@ -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 {
Expand All @@ -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) {
Expand All @@ -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;
}
Expand Down

0 comments on commit 7894c74

Please sign in to comment.