Skip to content

Commit 2e07271

Browse files
committed
Fix path.bounds with fallback stream.
Fixes d3#987.
1 parent d2ad9f7 commit 2e07271

5 files changed

Lines changed: 32 additions & 13 deletions

File tree

d3.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5557,8 +5557,8 @@
55575557
(d3.geo.azimuthalEquidistant = function() {
55585558
return d3_geo_projection(d3_geo_azimuthalEquidistant);
55595559
}).raw = d3_geo_azimuthalEquidistant;
5560-
d3.geo.bounds = d3_geo_bounds();
5561-
function d3_geo_bounds(projection) {
5560+
d3.geo.bounds = d3_geo_bounds(d3_identity);
5561+
function d3_geo_bounds(projectStream) {
55625562
var x0, y0, x1, y1;
55635563
var bound = {
55645564
point: boundPoint,
@@ -5571,7 +5571,6 @@
55715571
bound.point = boundPoint;
55725572
}
55735573
};
5574-
var projectBound = projection ? projection.stream(bound) : bound;
55755574
function boundPoint(x, y) {
55765575
if (x < x0) x0 = x;
55775576
if (x > x1) x1 = x;
@@ -5583,7 +5582,7 @@
55835582
}
55845583
return function(feature) {
55855584
y1 = x1 = -(x0 = y0 = Infinity);
5586-
d3.geo.stream(feature, projectBound);
5585+
d3.geo.stream(feature, projectStream(bound));
55875586
return [ [ x0, y0 ], [ x1, y1 ] ];
55885587
};
55895588
}
@@ -6229,7 +6228,7 @@
62296228
return d3_geo_centroidZ ? [ d3_geo_centroidX / d3_geo_centroidZ, d3_geo_centroidY / d3_geo_centroidZ ] : undefined;
62306229
};
62316230
path.bounds = function(object) {
6232-
return d3_geo_bounds(projection)(object);
6231+
return d3_geo_bounds(projectStream)(object);
62336232
};
62346233
path.projection = function(_) {
62356234
if (!arguments.length) return projection;

d3.min.js

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

src/geo/bounds.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
d3.geo.bounds = d3_geo_bounds();
1+
d3.geo.bounds = d3_geo_bounds(d3_identity);
22

3-
function d3_geo_bounds(projection) {
3+
function d3_geo_bounds(projectStream) {
44
var x0, y0, x1, y1;
55

66
var bound = {
@@ -13,8 +13,6 @@ function d3_geo_bounds(projection) {
1313
polygonEnd: function() { bound.point = boundPoint; }
1414
};
1515

16-
var projectBound = projection ? projection.stream(bound) : bound;
17-
1816
function boundPoint(x, y) {
1917
if (x < x0) x0 = x;
2018
if (x > x1) x1 = x;
@@ -28,7 +26,7 @@ function d3_geo_bounds(projection) {
2826

2927
return function(feature) {
3028
y1 = x1 = -(x0 = y0 = Infinity);
31-
d3.geo.stream(feature, projectBound);
29+
d3.geo.stream(feature, projectStream(bound));
3230
return [[x0, y0], [x1, y1]];
3331
};
3432
}

src/geo/path.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ d3.geo.path = function() {
2929
};
3030

3131
path.bounds = function(object) {
32-
return d3_geo_bounds(projection)(object);
32+
return d3_geo_bounds(projectStream)(object);
3333
};
3434

3535
path.projection = function(_) {

test/geo/path-test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,22 @@ suite.addBatch({
186186
},
187187
"Sphere": function(area) {
188188
assert.strictEqual(area({type: "Sphere"}), 1620000);
189+
},
190+
"supports fallback stream": function() {
191+
var path = d3.geo.path(),
192+
area = path.area({type: "Polygon", coordinates: [[[-122, 37], [-71, 42], [-80, 25], [-122, 37]]]});
193+
assert.inDelta(area, 109021.503, 1e-3);
194+
}
195+
},
196+
197+
"bounds": {
198+
"supports fallback stream": function() {
199+
var path = d3.geo.path(),
200+
bounds = path.bounds({type: "LineString", coordinates: [[-122, 37], [-74, 40], [-100, 0]]});
201+
assert.inDelta(bounds[0][0], -5.1214, 1e-3);
202+
assert.inDelta(bounds[0][1], 174.825, 1e-3);
203+
assert.inDelta(bounds[1][0], 794.602, 1e-3);
204+
assert.inDelta(bounds[1][1], 856.501, 1e-3);
189205
}
190206
},
191207

@@ -321,6 +337,12 @@ suite.addBatch({
321337
assert.deepEqual(testContext.buffer().filter(function(d) { return d.type === "moveTo"; }), [
322338
{type: "moveTo", x: 1370, y: 243}
323339
]);
340+
},
341+
"supports fallback stream": function() {
342+
var path = d3.geo.path(),
343+
centroid = path.centroid({type: "LineString", coordinates: [[-122, 37], [-74, 40], [-100, 0]]});
344+
assert.inDelta(centroid[0], 434.655, 1e-3);
345+
assert.inDelta(centroid[1], 397.940, 1e-3);
324346
}
325347
},
326348

0 commit comments

Comments
 (0)