Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow projection.invert to return null. #992

Merged
merged 1 commit into from
Jan 11, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions d3.js
Original file line number Diff line number Diff line change
Expand Up @@ -6072,7 +6072,7 @@
return x = a(x, y), b(x[0], x[1]);
}
if (a.invert && b.invert) compose.invert = function(x, y) {
return x = b.invert(x, y), a.invert(x[0], x[1]);
return x = b.invert(x, y), x && a.invert(x[0], x[1]);
};
return compose;
}
Expand Down Expand Up @@ -6514,7 +6514,7 @@
}
function invert(point) {
point = projectRotate.invert((point[0] - δx) / k, (δy - point[1]) / k);
return [ point[0] * d3_degrees, point[1] * d3_degrees ];
return point && [ point[0] * d3_degrees, point[1] * d3_degrees ];
}
projection.stream = function(stream) {
return d3_geo_projectionRadiansRotate(rotate, clip(projectResample(stream)));
Expand Down
2 changes: 1 addition & 1 deletion d3.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/geo/compose.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ function d3_geo_compose(a, b) {
}

if (a.invert && b.invert) compose.invert = function(x, y) {
return x = b.invert(x, y), a.invert(x[0], x[1]);
return x = b.invert(x, y), x && a.invert(x[0], x[1]);
};

return compose;
Expand Down
2 changes: 1 addition & 1 deletion src/geo/projection.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function d3_geo_projectionMutator(projectAt) {

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

projection.stream = function(stream) {
Expand Down
21 changes: 21 additions & 0 deletions test/geo/projection-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require("../env");

var vows = require("vows"),
assert = require("assert");

var suite = vows.describe("d3.geo.projection");

suite.addBatch({
"projection": {
topic: function() {
function forward(λ, φ) { return [λ, φ]; }
forward.invert = function(x, y) {}
return d3.geo.projection(forward);
},
"non-existent inverse": function(projection) {
assert.isUndefined(projection.invert([0, 0]));
}
}
});

suite.export(module);