Skip to content

Commit 3f8097d

Browse files
committed
Resample using a great-circle distance threshold.
Projections will typically exhibit less curvature at larger scales, with geodesics becoming closer and closer to straight lines. Using a minimum angular distance for resampling therefore makes more sense than using an arbitrary scale-dependent threshold. It's not clear whether this new threshold should depend on the precision parameter, or be configurable separately.
1 parent 34544e3 commit 3f8097d

3 files changed

Lines changed: 12 additions & 10 deletions

File tree

d3.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3306,7 +3306,7 @@ d3 = function() {
33063306
return stream;
33073307
}
33083308
function d3_geo_resample(project) {
3309-
var δ2 = .5, maxDepth = 16;
3309+
var δ2 = .5, cosMinDistance = Math.cos(1 * d3_radians), maxDepth = 16;
33103310
function resample(stream) {
33113311
var λ00, φ00, x00, y00, a00, b00, c00, λ0, x0, y0, a0, b0, c0;
33123312
var resample = {
@@ -3367,8 +3367,8 @@ d3 = function() {
33673367
function resampleLineTo(x0, y0, λ0, a0, b0, c0, x1, y1, λ1, a1, b1, c1, depth, buffer) {
33683368
var dx = x1 - x0, dy = y1 - y0, d2 = dx * dx + dy * dy;
33693369
if (d2 > 4 * δ2 && depth--) {
3370-
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 = project(λ2, φ2), x2 = p[0], y2 = p[1], dx2 = x2 - x0, dy2 = y2 - y0, dz = dy * dx2 - dx * dy2, curve = dz * dz / d2 > δ2;
3371-
if (curve || d2 > 16384 * δ2) {
3370+
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 = project(λ2, φ2), x2 = p[0], y2 = p[1], dx2 = x2 - x0, dy2 = y2 - y0, dz = dy * dx2 - dx * dy2, curve = dz * dz / d2 > δ2 || Math.abs((dx * dx2 + dy * dy2) / d2 - .5) > .3;
3371+
if (curve || a0 * a1 + b0 * b1 + c0 * c1 < cosMinDistance) {
33723372
var s0 = resampleLineTo(x0, y0, λ0, a0, b0, c0, x2, y2, λ2, a /= m, b /= m, c, depth, buffer);
33733373
buffer.push(p);
33743374
var s1 = resampleLineTo(x2, y2, λ2, a, b, c, x1, y1, λ1, a1, b1, c1, depth, buffer);

0 commit comments

Comments
 (0)