Skip to content

Commit 759947a

Browse files
committed
Add rotation.invert.
Fixes d3#1134.
1 parent 09f6c76 commit 759947a

4 files changed

Lines changed: 23 additions & 7 deletions

File tree

d3.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6774,10 +6774,15 @@ d3 = function() {
67746774
}
67756775
d3.geo.rotation = function(rotate) {
67766776
rotate = d3_geo_rotation(rotate[0] % 360 * d3_radians, rotate[1] * d3_radians, rotate.length > 2 ? rotate[2] * d3_radians : 0);
6777-
return function(coordinates) {
6777+
function forward(coordinates) {
67786778
coordinates = rotate(coordinates[0] * d3_radians, coordinates[1] * d3_radians);
67796779
return coordinates[0] *= d3_degrees, coordinates[1] *= d3_degrees, coordinates;
6780+
}
6781+
forward.invert = function(coordinates) {
6782+
coordinates = rotate.invert(coordinates[0] * d3_radians, coordinates[1] * d3_radians);
6783+
return coordinates[0] *= d3_degrees, coordinates[1] *= d3_degrees, coordinates;
67806784
};
6785+
return forward;
67816786
};
67826787
function d3_geo_rotation(δλ, δφ, δγ) {
67836788
return δλ ? δφ || δγ ? d3_geo_compose(d3_geo_rotationλ(δλ), d3_geo_rotationφγ(δφ, δγ)) : d3_geo_rotationλ(δλ) : δφ || δγ ? d3_geo_rotationφγ(δφ, δγ) : d3_geo_equirectangular;

d3.min.js

Lines changed: 5 additions & 5 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,9 +1,17 @@
11
d3.geo.rotation = function(rotate) {
22
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) {
3+
4+
function forward(coordinates) {
45
coordinates = rotate(coordinates[0] * d3_radians, coordinates[1] * d3_radians);
56
return coordinates[0] *= d3_degrees, coordinates[1] *= d3_degrees, coordinates;
7+
}
8+
9+
forward.invert = function(coordinates) {
10+
coordinates = rotate.invert(coordinates[0] * d3_radians, coordinates[1] * d3_radians);
11+
return coordinates[0] *= d3_degrees, coordinates[1] *= d3_degrees, coordinates;
612
};
13+
14+
return forward;
715
};
816

917
// Note: |δλ| must be < 2π

test/geo/rotation-test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ suite.addBatch({
2323
},
2424
"rotates longitude and latitude": function(rotation) {
2525
assert.inDelta(rotation([0, 0]), [-54.73561, 30], 1e-6);
26+
},
27+
"inverse rotation of longitude and latitude": function(rotation) {
28+
assert.inDelta(rotation.invert([-54.73561, 30]), [0, 0], 1e-6);
2629
}
2730
}
2831
});

0 commit comments

Comments
 (0)