Skip to content

Commit 995b699

Browse files
committed
Merge branch 'rotation' into 3.1.0
2 parents cac8883 + dcf6b26 commit 995b699

4 files changed

Lines changed: 48 additions & 3 deletions

File tree

d3.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6653,6 +6653,13 @@ d3 = function() {
66536653
}
66546654
};
66556655
}
6656+
d3.geo.rotation = function(rotate) {
6657+
rotate = d3_geo_rotation(rotate[0] % 360 * d3_radians, rotate[1] * d3_radians, rotate.length > 2 ? rotate[2] * d3_radians : 0);
6658+
return function(coordinates) {
6659+
coordinates = rotate(coordinates[0] * d3_radians, coordinates[1] * d3_radians);
6660+
return coordinates[0] *= d3_degrees, coordinates[1] *= d3_degrees, coordinates;
6661+
};
6662+
};
66566663
function d3_geo_rotation(δλ, δφ, δγ) {
66576664
return δλ ? δφ || δγ ? d3_geo_compose(d3_geo_rotationλ(δλ), d3_geo_rotationφγ(δφ, δγ)) : d3_geo_rotationλ(δλ) : δφ || δγ ? d3_geo_rotationφγ(δφ, δγ) : d3_geo_equirectangular;
66586665
}

d3.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/geo/rotation.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
// Note: |δλ| and |δφ| must be < 2π
1+
d3.geo.rotation = function(rotate) {
2+
rotate = d3_geo_rotation(rotate[0] % 360 * d3_radians, rotate[1] * d3_radians, rotate.length > 2 ? rotate[2] * d3_radians : 0);
3+
return function(coordinates) {
4+
coordinates = rotate(coordinates[0] * d3_radians, coordinates[1] * d3_radians);
5+
return coordinates[0] *= d3_degrees, coordinates[1] *= d3_degrees, coordinates;
6+
};
7+
};
8+
9+
// Note: |δλ| must be < 2π
210
function d3_geo_rotation(δλ, δφ, δγ) {
311
return δλ ? (δφ || δγ ? d3_geo_compose(d3_geo_rotationλ(δλ), d3_geo_rotationφγ(δφ, δγ))
412
: d3_geo_rotationλ(δλ))

test/geo/rotation-test.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
require("../env");
2+
3+
var vows = require("vows"),
4+
assert = require("../env-assert");
5+
6+
var suite = vows.describe("d3.geo.rotation");
7+
8+
suite.addBatch({
9+
"a rotation of [+90°, 0°]": {
10+
topic: function() {
11+
return d3.geo.rotation([90, 0]);
12+
},
13+
"only rotates longitude": function(rotation) {
14+
assert.inDelta(rotation([0, 0]), [90, 0], 1e-6);
15+
},
16+
"wraps around when crossing the antimeridian": function(rotation) {
17+
assert.inDelta(rotation([150, 0]), [-120, 0], 1e-6);
18+
}
19+
},
20+
"a rotation of [-45°, -45°]": {
21+
topic: function() {
22+
return d3.geo.rotation([-45, 45]);
23+
},
24+
"rotates longitude and latitude": function(rotation) {
25+
assert.inDelta(rotation([0, 0]), [-54.73561, 30], 1e-6);
26+
}
27+
}
28+
});
29+
30+
suite.export(module);

0 commit comments

Comments
 (0)