Skip to content

Commit 1a7810b

Browse files
committed
Adjust threshold for distortion resampling.
Includes test case.
1 parent 32b0449 commit 1a7810b

4 files changed

Lines changed: 14 additions & 5 deletions

File tree

d3.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5775,7 +5775,7 @@
57755775
var dx = x1 - x0, dy = y1 - y0, distance2 = dx * dx + dy * dy;
57765776
if (distance2 > 4 * δ2 && depth--) {
57775777
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;
5778-
if (dz * dz / distance2 > δ2 || Math.abs((dx * dx2 + dy * dy2) / distance2 - .5) > .4) {
5778+
if (dz * dz / distance2 > δ2 || Math.abs((dx * dx2 + dy * dy2) / distance2 - .5) > .3) {
57795779
resampleLineTo(x0, y0, λ0, a0, b0, c0, x2, y2, λ2, a /= m, b /= m, c, depth, listener);
57805780
listener.point(x2, y2);
57815781
resampleLineTo(x2, y2, λ2, a, b, c, x1, y1, λ1, a1, b1, c1, depth, listener);

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/resample.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ function d3_geo_resample(projectPoint) {
9898
dx2 = x2 - x0,
9999
dy2 = y2 - y0,
100100
dz = dy * dx2 - dx * dy2;
101-
if (dz * dz / distance2 > δ2 || (Math.abs((dx * dx2 + dy * dy2) / distance2 - .5) > .4)) {
101+
if (dz * dz / distance2 > δ2 || Math.abs((dx * dx2 + dy * dy2) / distance2 - .5) > .3) {
102102
resampleLineTo(x0, y0, λ0, a0, b0, c0, x2, y2, λ2, a /= m, b /= m, c, depth, listener);
103103
listener.point(x2, y2);
104104
resampleLineTo(x2, y2, λ2, a, b, c, x1, y1, λ1, a1, b1, c1, depth, listener);

test/geo/path-test.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ suite.addBatch({
627627
]);
628628
}
629629
},
630-
"albers.precision(1)": {
630+
"resampling near poles": {
631631
topic: function() {
632632
return d3.geo.path()
633633
.context(testContext)
@@ -636,11 +636,20 @@ suite.addBatch({
636636
.rotate([0, 0])
637637
.precision(1));
638638
},
639-
"resampling near poles": function(path) {
639+
"rotate([0, 0])": function(path) {
640640
path({type: "LineString", coordinates: [[0, 88], [180, 89]]});
641641
assert.isTrue(testContext.buffer().filter(function(d) { return d.type === "lineTo"; }).length > 1);
642642
path({type: "LineString", coordinates: [[180, 90], [1, 89.5]]});
643643
assert.isTrue(testContext.buffer().filter(function(d) { return d.type === "lineTo"; }).length > 1);
644+
},
645+
"rotate([11.5, 285])": function(path) {
646+
try {
647+
path.projection().rotate([11.5, 285]);
648+
path({type: "LineString", coordinates: [[170, 20], [170, 0]]});
649+
assert.isTrue(testContext.buffer().filter(function(d) { return d.type === "lineTo"; }).length > 1);
650+
} finally {
651+
path.projection().rotate([0, 0]);
652+
}
644653
}
645654
},
646655
"rotate([0, 0, 0])": {

0 commit comments

Comments
 (0)