Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'geo-clip' of git://github.com/jasondavies/d3 into 3.0.7

  • Loading branch information...
commit 3855a60b86db7807c2fc12f9b523fa18f5d8f2b0 2 parents ff137ed + b2c2f2c
@mbostock authored
Showing with 26 additions and 10 deletions.
  1. +9 −3 d3.js
  2. +2 −2 d3.min.js
  3. +15 −5 src/geo/clip.js
View
12 d3.js
@@ -5794,9 +5794,15 @@ d3 = function() {
function d3_geo_clipPolygon(segments, interpolate, listener) {
var subject = [], clip = [];
segments.forEach(function(segment) {
- var n = segment.length;
- if (n <= 1) return;
- var p0 = segment[0], p1 = segment[n - 1], a = {
+ if ((n = segment.length) <= 1) return;
+ var n, p0 = segment[0], p1 = segment[n - 1];
+ if (d3_geo_sphericalEqual(p0, p1)) {
+ listener.lineStart();
+ for (var i = 0; i < n; ++i) listener.point((p0 = segment[i])[0], p0[1]);
+ listener.lineEnd();
+ return;
+ }
+ var a = {
point: p0,
points: segment,
other: null,
View
4 d3.min.js
2 additions, 2 deletions not shown
View
20 src/geo/clip.js
@@ -115,11 +115,21 @@ function d3_geo_clipPolygon(segments, interpolate, listener) {
clip = [];
segments.forEach(function(segment) {
- var n = segment.length;
- if (n <= 1) return;
- var p0 = segment[0],
- p1 = segment[n - 1],
- a = {point: p0, points: segment, other: null, visited: false, entry: true, subject: true},
+ if ((n = segment.length) <= 1) return;
+ var n, p0 = segment[0], p1 = segment[n - 1];
+
+ // If the first and last points of a segment are coincident, then treat as
+ // a closed ring.
+ // TODO if all rings are closed, then the winding order of the exterior
+ // ring should be checked.
+ if (d3_geo_sphericalEqual(p0, p1)) {
+ listener.lineStart();
+ for (var i = 0; i < n; ++i) listener.point((p0 = segment[i])[0], p0[1]);
+ listener.lineEnd();
+ return;
+ }
+
+ var a = {point: p0, points: segment, other: null, visited: false, entry: true, subject: true},
b = {point: p0, points: [p0], other: a, visited: false, entry: false, subject: false};
a.other = b;
subject.push(a);
Please sign in to comment.
Something went wrong with that request. Please try again.