Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/geo-empty-polygon' into 3.4.5
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Apr 8, 2014
2 parents 253631c + a264d55 commit 378526d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 15 deletions.
16 changes: 10 additions & 6 deletions d3.js
Original file line number Diff line number Diff line change
Expand Up @@ -3224,7 +3224,6 @@
clip.lineEnd = ringEnd;
segments = [];
polygon = [];
listener.polygonStart();
},
polygonEnd: function() {
clip.point = point;
Expand All @@ -3233,13 +3232,15 @@
segments = d3.merge(segments);
var clipStartInside = d3_geo_pointInPolygon(rotatedClipStart, polygon);
if (segments.length) {
if (!polygonStarted) listener.polygonStart(), polygonStarted = true;
d3_geo_clipPolygon(segments, d3_geo_clipSort, clipStartInside, interpolate, listener);
} else if (clipStartInside) {
if (!polygonStarted) listener.polygonStart(), polygonStarted = true;
listener.lineStart();
interpolate(null, null, 1, listener);
listener.lineEnd();
}
listener.polygonEnd();
if (polygonStarted) listener.polygonEnd(), polygonStarted = false;
segments = polygon = null;
},
sphere: function() {
Expand Down Expand Up @@ -3267,7 +3268,7 @@
line.lineEnd();
}
var segments;
var buffer = d3_geo_clipBufferListener(), ringListener = clipLine(buffer), polygon, ring;
var buffer = d3_geo_clipBufferListener(), ringListener = clipLine(buffer), polygonStarted = false, polygon, ring;
function pointRing(λ, φ) {
ring.push([ λ, φ ]);
var point = rotate(λ, φ);
Expand All @@ -3288,9 +3289,12 @@
if (clean & 1) {
segment = ringSegments[0];
var n = segment.length - 1, i = -1, point;
listener.lineStart();
while (++i < n) listener.point((point = segment[i])[0], point[1]);
listener.lineEnd();
if (n > 0) {
if (!polygonStarted) listener.polygonStart(), polygonStarted = true;
listener.lineStart();
while (++i < n) listener.point((point = segment[i])[0], point[1]);
listener.lineEnd();
}
return;
}
if (n > 1 && clean & 2) ringSegments.push(ringSegments.pop().concat(ringSegments.shift()));
Expand Down
8 changes: 4 additions & 4 deletions d3.min.js

Large diffs are not rendered by default.

15 changes: 10 additions & 5 deletions src/geo/clip.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ function d3_geo_clip(pointVisible, clipLine, interpolate, clipStart) {
clip.lineEnd = ringEnd;
segments = [];
polygon = [];
listener.polygonStart();
},
polygonEnd: function() {
clip.point = point;
Expand All @@ -28,13 +27,15 @@ function d3_geo_clip(pointVisible, clipLine, interpolate, clipStart) {
segments = d3.merge(segments);
var clipStartInside = d3_geo_pointInPolygon(rotatedClipStart, polygon);
if (segments.length) {
if (!polygonStarted) listener.polygonStart(), polygonStarted = true;
d3_geo_clipPolygon(segments, d3_geo_clipSort, clipStartInside, interpolate, listener);
} else if (clipStartInside) {
if (!polygonStarted) listener.polygonStart(), polygonStarted = true;
listener.lineStart();
interpolate(null, null, 1, listener);
listener.lineEnd();
}
listener.polygonEnd();
if (polygonStarted) listener.polygonEnd(), polygonStarted = false;
segments = polygon = null;
},
sphere: function() {
Expand All @@ -61,6 +62,7 @@ function d3_geo_clip(pointVisible, clipLine, interpolate, clipStart) {

var buffer = d3_geo_clipBufferListener(),
ringListener = clipLine(buffer),
polygonStarted = false,
polygon,
ring;

Expand Down Expand Up @@ -96,9 +98,12 @@ function d3_geo_clip(pointVisible, clipLine, interpolate, clipStart) {
var n = segment.length - 1,
i = -1,
point;
listener.lineStart();
while (++i < n) listener.point((point = segment[i])[0], point[1]);
listener.lineEnd();
if (n > 0) {
if (!polygonStarted) listener.polygonStart(), polygonStarted = true;
listener.lineStart();
while (++i < n) listener.point((point = segment[i])[0], point[1]);
listener.lineEnd();
}
return;
}

Expand Down
4 changes: 4 additions & 0 deletions test/geo/path-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,10 @@ suite.addBatch({
"renders a small circle of 120°": function(p) {
p(_.geo.circle().angle(120)());
assert.deepEqual(testContext.buffer().filter(function(d) { return d.type === "moveTo"; }), [{type: "moveTo", x: 87, y: 700}]);
},
"degenerate polygon": function(p) {
p({type: "Polygon", coordinates: [[[0, 0], [0, 0], [0, 0], [0, 0]]]});
assert.deepEqual(testContext.buffer(), []);
}
},

Expand Down

0 comments on commit 378526d

Please sign in to comment.