Skip to content

Commit

Permalink
Merge pull request #1 from d3/master
Browse files Browse the repository at this point in the history
feat: New updated code
  • Loading branch information
vzan2012 committed Aug 9, 2019
2 parents 8108762 + d697731 commit d806180
Show file tree
Hide file tree
Showing 22 changed files with 438 additions and 240 deletions.
461 changes: 236 additions & 225 deletions README.md

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions bin/geograticule
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ commander
.option("--step <value>", "the major and minor step", parseStep)
.option("--step-minor <value>", "the minor step; defaults to " + graticule.stepMinor(), parseStep)
.option("--step-major <value>", "the major step; defaults to " + graticule.stepMajor(), parseStep)
.option("--precision <value>", "the precision; defaults to " + graticule.precision(), graticule.precision())
.option("--precision <value>", "the precision; defaults to " + graticule.precision(), graticule.precision)
.parse(process.argv);

if (commander.args.length !== 0) {
Expand All @@ -37,7 +37,6 @@ if (commander.extentMinor != null) graticule.extentMinor(commander.extentMinor);
if (commander.extentMajor != null) graticule.extentMajor(commander.extentMajor);
if (commander.stepMinor != null) graticule.stepMinor(commander.stepMinor);
if (commander.stepMajor != null) graticule.stepMajor(commander.stepMajor);
if (commander.precision != null) graticule.precision(commander.precision);

var writer = write(commander.out);
writer.write(JSON.stringify(graticule()) + "\n");
Expand Down
Binary file modified img/armadillo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified img/healpix.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/interruptedQuarticAuthalic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/nicolosi.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "d3-geo-projection",
"version": "2.5.1",
"version": "2.7.0",
"description": "Extended geographic projections for d3-geo.",
"keywords": [
"d3",
Expand Down Expand Up @@ -54,7 +54,8 @@
"dependencies": {
"commander": "2",
"d3-array": "1",
"d3-geo": "^1.10.0"
"d3-geo": "^1.10.0",
"resolve": "^1.1.10"
},
"devDependencies": {
"canvas": "1",
Expand Down
8 changes: 5 additions & 3 deletions src/armadillo.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,14 @@ export default function() {
p.stream = function(stream) {
var rotate = p.rotate(),
rotateStream = stream_(stream),
sphereStream = (p.rotate([0, 0]), stream_(stream));
sphereStream = (p.rotate([0, 0]), stream_(stream)),
precision = p.precision();
p.rotate(rotate);
rotateStream.sphere = function() {
sphereStream.polygonStart(), sphereStream.lineStart();
for (var lambda = sPhi0 * -180; sPhi0 * lambda < 180; lambda += sPhi0 * 90) sphereStream.point(lambda, sPhi0 * 90);
while (sPhi0 * (lambda -= phi0) >= -180) { // TODO precision?
for (var lambda = sPhi0 * -180; sPhi0 * lambda < 180; lambda += sPhi0 * 90)
sphereStream.point(lambda, sPhi0 * 90);
if (phi0) while (sPhi0 * (lambda -= 3 * sPhi0 * precision) >= -180) {
sphereStream.point(lambda, sPhi0 * -atan2(cos(lambda * radians / 2), tanPhi0) * degrees);
}
sphereStream.lineEnd(), sphereStream.polygonEnd();
Expand Down
8 changes: 6 additions & 2 deletions src/gilbert.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ export default function(projectionType) {
};

function property(name) {
gilbert[name] = function(_) {
return arguments.length ? (projection[name](_), gilbert) : projection[name]();
gilbert[name] = function() {
return arguments.length ? (projection[name].apply(projection, arguments), gilbert) : projection[name]();
};
}

Expand All @@ -51,6 +51,10 @@ export default function(projectionType) {
property("angle");
property("clipAngle");
property("clipExtent");
property("fitExtent");
property("fitHeight");
property("fitSize");
property("fitWidth");
property("scale");
property("translate");
property("precision");
Expand Down
5 changes: 3 additions & 2 deletions src/healpix.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import {range} from "d3-array";
import {geoStream, geoProjectionMutator as projectionMutator} from "d3-geo";
import {collignonRaw} from "./collignon";
import {cylindricalEqualAreaRaw} from "./cylindricalEqualArea";
import {abs, epsilon, floor, max, min, pi, radians, sqrtPi, tau} from "./math";
import {abs, asin, degrees, epsilon, floor, max, min, pi, radians, sqrtPi, tau} from "./math";

var healpixParallel = 41 + 48 / 36 + 37 / 3600, // for K=3; TODO automate
var K = 3,
healpixParallel = asin(1 - 1 / K) * degrees,
healpixLambert = cylindricalEqualAreaRaw(0);

export function healpixRaw(H) {
Expand Down
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ export {default as geoMtFlatPolarSinusoidal, mtFlatPolarSinusoidalRaw as geoMtFl
export {geoNaturalEarth1 as geoNaturalEarth, geoNaturalEarth1Raw as geoNaturalEarthRaw} from "d3-geo"; // DEPRECATED moved to d3-geo
export {default as geoNaturalEarth2, naturalEarth2Raw as geoNaturalEarth2Raw} from "./naturalEarth2";
export {default as geoNellHammer, nellHammerRaw as geoNellHammerRaw} from "./nellHammer";
export {default as geoInterruptedQuarticAuthalic} from "./interrupted/quarticAuthalic";
export {default as geoNicolosi, nicolosiRaw as geoNicolosiRaw} from "./nicolosi";
export {default as geoPatterson, pattersonRaw as geoPattersonRaw} from "./patterson";
export {default as geoPolyconic, polyconicRaw as geoPolyconicRaw} from "./polyconic";
export {default as geoPolyhedral} from "./polyhedral/index.js";
Expand Down
16 changes: 16 additions & 0 deletions src/interrupted/quarticAuthalic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import {hammerRaw} from "../hammer";
import interrupt from "./index";

var lobes = [[ // northern hemisphere
[[-180, 0], [-90, 90], [ 0, 0]],
[[ 0, 0], [ 90, 90], [ 180, 0]]
], [ // southern hemisphere
[[-180, 0], [-90, -90], [ 0, 0]],
[[ 0, 0], [ 90, -90], [180, 0]]
]];

export default function() {
return interrupt(hammerRaw(Infinity), lobes)
.rotate([20, 0])
.scale(152.63);
}
64 changes: 64 additions & 0 deletions src/nicolosi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import {geoProjection as projection} from "d3-geo";
import {abs, cos, halfPi, pi, sign, sin, sqrt} from "./math";
import {solve} from "./newton.js";

// Based on Torben Jansen's implementation
// https://beta.observablehq.com/@toja/nicolosi-globular-projection
// https://beta.observablehq.com/@toja/nicolosi-globular-inverse

export function nicolosiRaw(lambda, phi) {
var sinPhi = sin(phi),
q = cos(phi),
s = sign(lambda);

if (lambda === 0 || abs(phi) === halfPi) return [0, phi];
else if (phi === 0) return [lambda, 0];
else if (abs(lambda) === halfPi) return [lambda * q, halfPi * sinPhi];

var b = pi / (2 * lambda) - (2 * lambda) / pi,
c = (2 * phi) / pi,
d = (1 - c * c) / (sinPhi - c);

var b2 = b * b,
d2 = d * d,
b2d2 = 1 + b2 / d2,
d2b2 = 1 + d2 / b2;

var M = ((b * sinPhi) / d - b / 2) / b2d2,
N = ((d2 * sinPhi) / b2 + d / 2) / d2b2,
m = M * M + (q * q) / b2d2,
n = N * N - ((d2 * sinPhi * sinPhi) / b2 + d * sinPhi - 1) / d2b2;

return [
halfPi * (M + sqrt(m) * s),
halfPi * (N + sqrt(n < 0 ? 0 : n) * sign(-phi * b) * s)
];
}

nicolosiRaw.invert = function(x, y) {

x /= halfPi;
y /= halfPi;

var x2 = x * x,
y2 = y * y,
x2y2 = x2 + y2,
pi2 = pi * pi;

return [
x ? (x2y2 -1 + sqrt((1 - x2y2) * (1 - x2y2) + 4 * x2)) / (2 * x) * halfPi : 0,
solve(function(phi) {
return (
x2y2 * (pi * sin(phi) - 2 * phi) * pi +
4 * phi * phi * (y - sin(phi)) +
2 * pi * phi -
pi2 * y
);
}, 0)
];
};

export default function() {
return projection(nicolosiRaw)
.scale(127.267);
}
21 changes: 19 additions & 2 deletions src/quantize.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,24 @@ export default function(input, digits) {
return input.map(quantizePoint);
}

function quantizePointsNoDuplicates(input) {
var point0 = quantizePoint(input[0]);
var output = [point0];
for (var i = 1; i < input.length; i++) {
var point = quantizePoint(input[i]);
if (point.length > 2 || point[0] != point0[0] || point[1] != point0[1]) {
output.push(point);
point0 = point;
}
}
if (output.length === 1 && input.length > 1) {
output.push(quantizePoint(input[input.length - 1]));
}
return output;
}

function quantizePolygon(input) {
return input.map(quantizePoints);
return input.map(quantizePointsNoDuplicates);
}

function quantizeGeometry(input) {
Expand All @@ -23,7 +39,8 @@ export default function(input, digits) {
switch (input.type) {
case "GeometryCollection": output = {type: "GeometryCollection", geometries: input.geometries.map(quantizeGeometry)}; break;
case "Point": output = {type: "Point", coordinates: quantizePoint(input.coordinates)}; break;
case "MultiPoint": case "LineString": output = {type: input.type, coordinates: quantizePoints(input.coordinates)}; break;
case "MultiPoint": output = {type: input.type, coordinates: quantizePoints(input.coordinates)}; break;
case "LineString": output = {type: input.type, coordinates: quantizePointsNoDuplicates(input.coordinates)}; break;
case "MultiLineString": case "Polygon": output = {type: input.type, coordinates: quantizePolygon(input.coordinates)}; break;
case "MultiPolygon": output = {type: "MultiPolygon", coordinates: input.coordinates.map(quantizePolygon)}; break;
default: return input;
Expand Down
7 changes: 6 additions & 1 deletion test/armadillo-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var tape = require("tape"),
d3 = require("../");
d3 = Object.assign({}, require("d3-geo"), require("../"));

require("./projectionEqual");

Expand All @@ -19,3 +19,8 @@ tape("geoArmadillo(point) returns the expected value", function(test) {
test.projectionEqual(armadillo, [ 45, 87], [540.406730, 56.511657]);
test.end();
});

tape("geoArmadillo.parallel(0) sphere works (#163)", function(test) {
test.assert(d3.geoPath(d3.geoArmadillo().parallel(0))({type:"Sphere"}));
test.end();
});
2 changes: 2 additions & 0 deletions test/compare-images
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ for i in \
interruptedMollweideHemispheres \
interruptedSinusoidal \
interruptedSinuMollweide \
interruptedQuarticAuthalic \
kavrayskiy7 \
lagrange \
larrivee \
Expand All @@ -70,6 +71,7 @@ for i in \
naturalEarth \
naturalEarth2 \
nellHammer \
nicolosi \
patterson \
peirceQuincuncial \
polyconic \
Expand Down
15 changes: 15 additions & 0 deletions test/gilbert-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
var tape = require("tape"),
d3 = require("../");

require("./inDelta");

tape("geoGilbert(point) returns the expected values", function(test) {
var gilbert = d3.geoGilbert().scale(150);
test.projectionEqual(gilbert, [ 0, 0], [480.0000000, 250.000000]);
test.assert("fitExtent" in gilbert);
test.inDelta(gilbert.fitExtent([[0,0],[10,10]], {type:"Sphere"}).scale(), 5, 1e-12);
test.inDelta(gilbert.fitSize([10,10], {type:"Sphere"}).scale(), 5, 1e-12);
test.inDelta(gilbert.fitWidth(10, {type:"Sphere"}).scale(), 5, 1e-12);
test.inDelta(gilbert.fitHeight(10, {type:"Sphere"}).scale(), 5, 1e-12);
test.end();
});
26 changes: 26 additions & 0 deletions test/inDelta.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
var tape = require("tape");

tape.Test.prototype.inDelta = function(actual, expected, delta) {
delta = delta || 1e-6;
this._assert(inDelta(actual, expected, delta), {
message: "should be in delta " + delta,
operator: "inDelta",
actual: actual,
expected: expected
});
};

function inDelta(actual, expected, delta) {
return (Array.isArray(expected) ? inDeltaArray : inDeltaNumber)(actual, expected, delta);
}

function inDeltaArray(actual, expected, delta) {
var n = expected.length, i = -1;
if (actual.length !== n) return false;
while (++i < n) if (!inDelta(actual[i], expected[i], delta)) return false;
return true;
}

function inDeltaNumber(actual, expected, delta) {
return actual >= expected - delta && actual <= expected + delta;
}
2 changes: 2 additions & 0 deletions test/invert-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ var points = [[0, 0], [30.3, 24.1], [-10, 42], [-2, -5], [0,-55]];
d3.geoInterruptedMollweideHemispheres,
// d3.geoInterruptedSinuMollweide,
d3.geoInterruptedSinusoidal,
d3.geoInterruptedQuarticAuthalic,
d3.geoKavrayskiy7,
d3.geoLagrange,
d3.geoLarrivee,
Expand All @@ -77,6 +78,7 @@ var points = [[0, 0], [30.3, 24.1], [-10, 42], [-2, -5], [0,-55]];
d3.geoNaturalEarth,
d3.geoNaturalEarth2,
d3.geoNellHammer,
d3.geoNicolosi,
d3.geoPatterson,
d3.geoPeirceQuincuncial,
// d3.geoPierceQuincuncial, // Alias of Peirce (typo)
Expand Down
22 changes: 22 additions & 0 deletions test/quantize-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,28 @@ tape("quantize(LineString) quantizes coordinates", function(test) {
test.end();
});

tape("quantize(LineString) does not repeat coordinates", function(test) {
test.deepEqual(d3.geoQuantize({
type: "LineString",
coordinates: [[0, 0], [0.3, 0.3], [1, 1]]
}, 0), {
type: "LineString",
coordinates: [[0, 0], [1, 1]]
});
test.end();
});

tape("quantize() does not return an invalid LineString", function(test) {
test.deepEqual(d3.geoQuantize({
type: "LineString",
coordinates: [[0, 0], [0.3, 0.3]]
}, 0), {
type: "LineString",
coordinates: [[0, 0], [0, 0]]
});
test.end();
});

tape("quantize(MultiLineString) quantizes coordinates", function(test) {
test.deepEqual(d3.geoQuantize({
type: "MultiLineString",
Expand Down
1 change: 1 addition & 0 deletions test/render-world
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ switch (projectionName) {
case "interruptedSinuMollweide":
case "interruptedMollweide":
case "interruptedMollweideHemispheres":
case "interruptedQuarticAuthalic":
case "littrow":
case "modifiedStereographicGs50":
case "modifiedStereographicMiller":
Expand Down
10 changes: 9 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -691,9 +691,10 @@ path-key@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/path-key/-/path-key-2.0.1.tgz#411cadb574c5a140d3a4b1910d40d80cc9f40b40"

path-parse@^1.0.5:
path-parse@^1.0.5, path-parse@^1.0.6:
version "1.0.6"
resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.6.tgz#d62dbb5679405d72c4737ec58600e9ddcf06d24c"
integrity sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==

pify@^2.0.0:
version "2.3.0"
Expand Down Expand Up @@ -740,6 +741,13 @@ resolve-from@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-1.0.1.tgz#26cbfe935d1aeeeabb29bc3fe5aeb01e93d44226"

resolve@^1.1.10:
version "1.10.0"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.10.0.tgz#3bdaaeaf45cc07f375656dfd2e54ed0810b101ba"
integrity sha512-3sUr9aq5OfSg2S9pNtPA9hL1FVEAjvfOC4leW0SNf/mpnaakz2a9femSd6LqAww2RaFctwyf1lCqnTHuF1rxDg==
dependencies:
path-parse "^1.0.6"

resolve@~1.7.1:
version "1.7.1"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.7.1.tgz#aadd656374fd298aee895bc026b8297418677fd3"
Expand Down

0 comments on commit d806180

Please sign in to comment.