Adjust threshold for distortion resampling.

Includes test case.
This commit is contained in:
Jason Davies 2012-12-14 01:12:10 +00:00
Родитель 32b0449333
Коммит 1a7810bddd
4 изменённых файлов: 14 добавлений и 5 удалений

2
d3.js поставляемый
Просмотреть файл

@ -5775,7 +5775,7 @@
var dx = x1 - x0, dy = y1 - y0, distance2 = dx * dx + dy * dy; var dx = x1 - x0, dy = y1 - y0, distance2 = dx * dx + dy * dy;
if (distance2 > 4 * δ2 && depth--) { 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; 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); resampleLineTo(x0, y0, λ0, a0, b0, c0, x2, y2, λ2, a /= m, b /= m, c, depth, listener);
listener.point(x2, y2); listener.point(x2, y2);
resampleLineTo(x2, y2, λ2, a, b, c, x1, y1, λ1, a1, b1, c1, depth, listener); resampleLineTo(x2, y2, λ2, a, b, c, x1, y1, λ1, a1, b1, c1, depth, listener);

2
d3.min.js поставляемый

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Просмотреть файл

@ -98,7 +98,7 @@ function d3_geo_resample(projectPoint) {
dx2 = x2 - x0, dx2 = x2 - x0,
dy2 = y2 - y0, dy2 = y2 - y0,
dz = dy * dx2 - dx * dy2; 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); resampleLineTo(x0, y0, λ0, a0, b0, c0, x2, y2, λ2, a /= m, b /= m, c, depth, listener);
listener.point(x2, y2); listener.point(x2, y2);
resampleLineTo(x2, y2, λ2, a, b, c, x1, y1, λ1, a1, b1, c1, depth, listener); resampleLineTo(x2, y2, λ2, a, b, c, x1, y1, λ1, a1, b1, c1, depth, listener);

Просмотреть файл

@ -627,7 +627,7 @@ suite.addBatch({
]); ]);
} }
}, },
"albers.precision(1)": { "resampling near poles": {
topic: function() { topic: function() {
return d3.geo.path() return d3.geo.path()
.context(testContext) .context(testContext)
@ -636,11 +636,20 @@ suite.addBatch({
.rotate([0, 0]) .rotate([0, 0])
.precision(1)); .precision(1));
}, },
"resampling near poles": function(path) { "rotate([0, 0])": function(path) {
path({type: "LineString", coordinates: [[0, 88], [180, 89]]}); path({type: "LineString", coordinates: [[0, 88], [180, 89]]});
assert.isTrue(testContext.buffer().filter(function(d) { return d.type === "lineTo"; }).length > 1); assert.isTrue(testContext.buffer().filter(function(d) { return d.type === "lineTo"; }).length > 1);
path({type: "LineString", coordinates: [[180, 90], [1, 89.5]]}); path({type: "LineString", coordinates: [[180, 90], [1, 89.5]]});
assert.isTrue(testContext.buffer().filter(function(d) { return d.type === "lineTo"; }).length > 1); 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])": { "rotate([0, 0, 0])": {