Skip to content

Commit 3eae02e

Browse files
committed
Fix projection.clipExtent regression.
A bug was introduced in fa514dd, where invisible line segments were incorrectly drawn. Thanks to @jfirebaugh of iD for spotting it!
1 parent 0c7d186 commit 3eae02e

5 files changed

Lines changed: 51 additions & 3 deletions

File tree

d3.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2752,7 +2752,7 @@ d3 = function() {
27522752
}
27532753
listener.point(b[0], b[1]);
27542754
if (!v) listener.lineEnd();
2755-
} else {
2755+
} else if (v) {
27562756
listener.lineStart();
27572757
listener.point(x, y);
27582758
}

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/clip-view.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ function d3_geo_clipView(x0, y0, x1, y1) {
136136
}
137137
listener.point(b[0], b[1]);
138138
if (!v) listener.lineEnd();
139-
} else {
139+
} else if (v) {
140140
listener.lineStart();
141141
listener.point(x, y);
142142
}

test/geo/clip-view-mock.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import "../../src/geo/geo";
2+
import "../../src/geo/clip-view";
3+
4+
d3.geo.clipView = d3_geo_clipView;

test/geo/clip-view-test.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
var vows = require("vows"),
2+
_ = require("../../"),
3+
load = require("../load"),
4+
assert = require("../assert");
5+
6+
var suite = vows.describe("d3.geo.clipView");
7+
8+
suite.addBatch({
9+
"clipView": {
10+
topic: load("../test/geo/clip-view-mock").expression("d3.geo.clipView"),
11+
"100⨯100": {
12+
topic: function(clipView) {
13+
return clipView(0, 0, 100, 100);
14+
},
15+
"invisible segments are dropped": function(clip) {
16+
_.geo.stream({type: "LineString", coordinates: [
17+
[-100, 50],
18+
[-50, 50],
19+
[50, 50]
20+
]}, clip(testContext));
21+
assert.deepEqual(testContext.buffer(), [
22+
{type: "lineStart"},
23+
{type: "point", x: 0, y: 50},
24+
{type: "point", x: 50, y: 50},
25+
{type: "lineEnd"}
26+
]);
27+
}
28+
}
29+
}
30+
});
31+
32+
suite.export(module);
33+
34+
var testBuffer = [];
35+
36+
var testContext = {
37+
point: function(x, y) { testBuffer.push({type: "point", x: Math.round(x), y: Math.round(y)}); },
38+
lineStart: function() { testBuffer.push({type: "lineStart"}); },
39+
lineEnd: function() { testBuffer.push({type: "lineEnd"}); },
40+
polygonStart: function() { testBuffer.push({type: "polygonStart"}); },
41+
polygonEnd: function() { testBuffer.push({type: "polygonEnd"}); },
42+
sphere: function() { testBuffer.push({type: "sphere"}); },
43+
buffer: function() { var result = testBuffer; testBuffer = []; return result; }
44+
};

0 commit comments

Comments
 (0)