Skip to content

Commit 475b18f

Browse files
committed
Allow projection.invert to return null.
Previously this would throw errors.
1 parent 63979e2 commit 475b18f

5 files changed

Lines changed: 26 additions & 5 deletions

File tree

d3.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6072,7 +6072,7 @@
60726072
return x = a(x, y), b(x[0], x[1]);
60736073
}
60746074
if (a.invert && b.invert) compose.invert = function(x, y) {
6075-
return x = b.invert(x, y), a.invert(x[0], x[1]);
6075+
return x = b.invert(x, y), x && a.invert(x[0], x[1]);
60766076
};
60776077
return compose;
60786078
}
@@ -6514,7 +6514,7 @@
65146514
}
65156515
function invert(point) {
65166516
point = projectRotate.invert((point[0] - δx) / k, (δy - point[1]) / k);
6517-
return [ point[0] * d3_degrees, point[1] * d3_degrees ];
6517+
return point && [ point[0] * d3_degrees, point[1] * d3_degrees ];
65186518
}
65196519
projection.stream = function(stream) {
65206520
return d3_geo_projectionRadiansRotate(rotate, clip(projectResample(stream)));

d3.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/geo/compose.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ function d3_geo_compose(a, b) {
55
}
66

77
if (a.invert && b.invert) compose.invert = function(x, y) {
8-
return x = b.invert(x, y), a.invert(x[0], x[1]);
8+
return x = b.invert(x, y), x && a.invert(x[0], x[1]);
99
};
1010

1111
return compose;

src/geo/projection.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function d3_geo_projectionMutator(projectAt) {
2525

2626
function invert(point) {
2727
point = projectRotate.invert((point[0] - δx) / k, (δy - point[1]) / k);
28-
return [point[0] * d3_degrees, point[1] * d3_degrees];
28+
return point && [point[0] * d3_degrees, point[1] * d3_degrees];
2929
}
3030

3131
projection.stream = function(stream) {

test/geo/projection-test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
require("../env");
2+
3+
var vows = require("vows"),
4+
assert = require("assert");
5+
6+
var suite = vows.describe("d3.geo.projection");
7+
8+
suite.addBatch({
9+
"projection": {
10+
topic: function() {
11+
function forward(λ, φ) { return [λ, φ]; }
12+
forward.invert = function(x, y) {}
13+
return d3.geo.projection(forward);
14+
},
15+
"non-existent inverse": function(projection) {
16+
assert.isUndefined(projection.invert([0, 0]));
17+
}
18+
}
19+
});
20+
21+
suite.export(module);

0 commit comments

Comments
 (0)