Skip to content

Commit

Permalink
Adjust threshold for distortion resampling.
Browse files Browse the repository at this point in the history
Includes test case.
  • Loading branch information
jasondavies committed Dec 14, 2012
1 parent 32b0449 commit 1a7810b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion d3.js
Original file line number Diff line number Diff line change
Expand Up @@ -5775,7 +5775,7 @@
var dx = x1 - x0, dy = y1 - y0, distance2 = dx * dx + dy * dy;
if (distance2 > 4 * δ2 && depth--) {
var a = a0 + a1, b = b0 + b1, c = c0 + c1, m = Math.sqrt(a * a + b * b + c * c), φ2 = Math.asin(c /= m), λ2 = Math.abs(Math.abs(c) - 1) < ε ? (λ0 + λ1) / 2 : Math.atan2(b, a), p = projectPoint(λ2, φ2), x2 = p[0], y2 = p[1], dx2 = x2 - x0, dy2 = y2 - y0, dz = dy * dx2 - dx * dy2;
if (dz * dz / distance2 > δ2 || Math.abs((dx * dx2 + dy * dy2) / distance2 - .5) > .4) {
if (dz * dz / distance2 > δ2 || Math.abs((dx * dx2 + dy * dy2) / distance2 - .5) > .3) {
resampleLineTo(x0, y0, λ0, a0, b0, c0, x2, y2, λ2, a /= m, b /= m, c, depth, listener);
listener.point(x2, y2);
resampleLineTo(x2, y2, λ2, a, b, c, x1, y1, λ1, a1, b1, c1, depth, listener);
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/resample.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ function d3_geo_resample(projectPoint) {
dx2 = x2 - x0,
dy2 = y2 - y0,
dz = dy * dx2 - dx * dy2;
if (dz * dz / distance2 > δ2 || (Math.abs((dx * dx2 + dy * dy2) / distance2 - .5) > .4)) {
if (dz * dz / distance2 > δ2 || Math.abs((dx * dx2 + dy * dy2) / distance2 - .5) > .3) {
resampleLineTo(x0, y0, λ0, a0, b0, c0, x2, y2, λ2, a /= m, b /= m, c, depth, listener);
listener.point(x2, y2);
resampleLineTo(x2, y2, λ2, a, b, c, x1, y1, λ1, a1, b1, c1, depth, listener);
Expand Down
13 changes: 11 additions & 2 deletions test/geo/path-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ suite.addBatch({
]);
}
},
"albers.precision(1)": {
"resampling near poles": {
topic: function() {
return d3.geo.path()
.context(testContext)
Expand All @@ -636,11 +636,20 @@ suite.addBatch({
.rotate([0, 0])
.precision(1));
},
"resampling near poles": function(path) {
"rotate([0, 0])": function(path) {
path({type: "LineString", coordinates: [[0, 88], [180, 89]]});
assert.isTrue(testContext.buffer().filter(function(d) { return d.type === "lineTo"; }).length > 1);
path({type: "LineString", coordinates: [[180, 90], [1, 89.5]]});
assert.isTrue(testContext.buffer().filter(function(d) { return d.type === "lineTo"; }).length > 1);
},
"rotate([11.5, 285])": function(path) {
try {
path.projection().rotate([11.5, 285]);
path({type: "LineString", coordinates: [[170, 20], [170, 0]]});
assert.isTrue(testContext.buffer().filter(function(d) { return d.type === "lineTo"; }).length > 1);
} finally {
path.projection().rotate([0, 0]);
}
}
},
"rotate([0, 0, 0])": {
Expand Down

0 comments on commit 1a7810b

Please sign in to comment.