Skip to content

Commit

Permalink
Use cylindrical projection when appropriate.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Oct 3, 2016
1 parent 186e82a commit 717ed0c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/projection/conicEqualArea.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
import {abs, asin, atan2, cos, epsilon, sign, sin, sqrt} from "../math";
import {conicProjection} from "./conic";
import {cylindricalEqualAreaRaw} from "./cylindricalEqualArea";

export function conicEqualAreaRaw(y0, y1) {
var sy0 = sin(y0),
n = (sy0 + sin(y1)) / 2,
c = 1 + sy0 * (2 * n - sy0);
var sy0 = sin(y0), n = (sy0 + sin(y1)) / 2;

// gracefully handle the limit case where the two standard parallels
// are symetrical with the Equator
if (abs(n) < epsilon) {
n = (n < 0 ? -1 : 1) * epsilon;
}
// Are the parallels symmetrical around the Equator?
if (abs(n) < epsilon) return cylindricalEqualAreaRaw(y0);

var r0 = sqrt(c) / n;
var c = 1 + sy0 * (2 * n - sy0), r0 = sqrt(c) / n;

function project(x, y) {
var r = sqrt(c - 2 * n * sin(y)) / n;
Expand Down
15 changes: 15 additions & 0 deletions src/projection/cylindricalEqualArea.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import {asin, cos, sin} from "../math";

export function cylindricalEqualAreaRaw(phi0) {
var cosPhi0 = cos(phi0);

function forward(lambda, phi) {
return [lambda * cosPhi0, sin(phi) / cosPhi0];
}

forward.invert = function(x, y) {
return [x / cosPhi0, asin(y * cosPhi0)];
};

return forward;
}

0 comments on commit 717ed0c

Please sign in to comment.