Skip to content

Commit 6132451

Browse files
committed
Fix stream invalidation on precision change.
1 parent a10b226 commit 6132451

4 files changed

Lines changed: 28 additions & 18 deletions

File tree

d3.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4013,9 +4013,9 @@
40134013
return stream;
40144014
}
40154015
function d3_geo_resample(project) {
4016-
var δ2 = .5, cosMinDistance = Math.cos(30 * d3_radians), maxDepth = 16;
4016+
var δ2 = .5, cosMinDistance = Math.cos(30 * d3_radians);
40174017
function resample(stream) {
4018-
return (maxDepth ? resampleRecursive : resampleNone)(stream);
4018+
return (δ2 > 0 ? resampleRecursive : resampleNone)(stream);
40194019
}
40204020
function resampleNone(stream) {
40214021
return d3_geo_transformPoint(stream, function(x, y) {
@@ -4049,7 +4049,7 @@
40494049
}
40504050
function linePoint(λ, φ) {
40514051
var c = d3_geo_cartesian([ λ, φ ]), p = project(λ, φ);
4052-
resampleLineTo(x0, y0, λ0, a0, b0, c0, x0 = p[0], y0 = p[1], λ0 = λ, a0 = c[0], b0 = c[1], c0 = c[2], maxDepth, stream);
4052+
resampleLineTo(x0, y0, λ0, a0, b0, c0, x0 = p[0], y0 = p[1], λ0 = λ, a0 = c[0], b0 = c[1], c0 = c[2], d3_geo_resampleMaxDepth, stream);
40534053
stream.point(x0, y0);
40544054
}
40554055
function lineEnd() {
@@ -4066,7 +4066,7 @@
40664066
resample.point = linePoint;
40674067
}
40684068
function ringEnd() {
4069-
resampleLineTo(x0, y0, λ0, a0, b0, c0, x00, y00, λ00, a00, b00, c00, maxDepth, stream);
4069+
resampleLineTo(x0, y0, λ0, a0, b0, c0, x00, y00, λ00, a00, b00, c00, d3_geo_resampleMaxDepth, stream);
40704070
resample.lineEnd = lineEnd;
40714071
lineEnd();
40724072
}
@@ -4085,11 +4085,12 @@
40854085
}
40864086
resample.precision = function(_) {
40874087
if (!arguments.length) return Math.sqrt(δ2);
4088-
maxDepth = (δ2 = _ * _) > 0 && 16;
4088+
δ2 = _ * _;
40894089
return resample;
40904090
};
40914091
return resample;
40924092
}
4093+
var d3_geo_resampleMaxDepth = 16;
40934094
d3.geo.path = function() {
40944095
var pointRadius = 4.5, projection, context, projectStream, contextStream, cacheStream;
40954096
function path(object) {
@@ -4258,7 +4259,11 @@
42584259
δγ = _.length > 2 ? _[2] % 360 * d3_radians : 0;
42594260
return reset();
42604261
};
4261-
d3.rebind(projection, projectResample, "precision");
4262+
projection.precision = function(_) {
4263+
if (!arguments.length) return projectResample.precision();
4264+
projectResample.precision(_);
4265+
return invalidate();
4266+
};
42624267
function reset() {
42634268
projectRotate = d3_geo_compose(rotate = d3_geo_rotation(δλ, δφ, δγ), project);
42644269
var center = project(λ, φ);

d3.min.js

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/geo/projection.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,11 @@ function d3_geo_projectionMutator(projectAt) {
9292
return reset();
9393
};
9494

95-
d3.rebind(projection, projectResample, "precision");
95+
projection.precision = function(_) {
96+
if (!arguments.length) return projectResample.precision();
97+
projectResample.precision(_);
98+
return invalidate();
99+
};
96100

97101
function reset() {
98102
projectRotate = d3_geo_compose(rotate = d3_geo_rotation(δλ, δφ, δγ), project);

src/geo/resample.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@ import "cartesian";
44

55
function d3_geo_resample(project) {
66
var δ2 = .5, // precision, px²
7-
cosMinDistance = Math.cos(30 * d3_radians), // cos(minimum angular distance)
8-
maxDepth = 16;
7+
cosMinDistance = Math.cos(30 * d3_radians); // cos(minimum angular distance)
98

109
function resample(stream) {
11-
return (maxDepth ? resampleRecursive : resampleNone)(stream);
10+
return (δ2 > 0 ? resampleRecursive : resampleNone)(stream);
1211
}
1312

1413
function resampleNone(stream) {
@@ -43,7 +42,7 @@ function d3_geo_resample(project) {
4342

4443
function linePoint(λ, φ) {
4544
var c = d3_geo_cartesian([λ, φ]), p = project(λ, φ);
46-
resampleLineTo(x0, y0, λ0, a0, b0, c0, x0 = p[0], y0 = p[1], λ0 = λ, a0 = c[0], b0 = c[1], c0 = c[2], maxDepth, stream);
45+
resampleLineTo(x0, y0, λ0, a0, b0, c0, x0 = p[0], y0 = p[1], λ0 = λ, a0 = c[0], b0 = c[1], c0 = c[2], d3_geo_resampleMaxDepth, stream);
4746
stream.point(x0, y0);
4847
}
4948

@@ -64,7 +63,7 @@ function d3_geo_resample(project) {
6463
}
6564

6665
function ringEnd() {
67-
resampleLineTo(x0, y0, λ0, a0, b0, c0, x00, y00, λ00, a00, b00, c00, maxDepth, stream);
66+
resampleLineTo(x0, y0, λ0, a0, b0, c0, x00, y00, λ00, a00, b00, c00, d3_geo_resampleMaxDepth, stream);
6867
resample.lineEnd = lineEnd;
6968
lineEnd();
7069
}
@@ -101,9 +100,11 @@ function d3_geo_resample(project) {
101100

102101
resample.precision = function(_) {
103102
if (!arguments.length) return Math.sqrt(δ2);
104-
maxDepth = (δ2 = _ * _) > 0 && 16;
103+
δ2 = _ * _;
105104
return resample;
106105
};
107106

108107
return resample;
109108
}
109+
110+
var d3_geo_resampleMaxDepth = 16;

0 commit comments

Comments
 (0)