Skip to content

Commit

Permalink
v1.6.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Fil committed Sep 17, 2018
1 parent 8259ff2 commit ab7ff70
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "d3-geo-polygon",
"version": "1.6.0",
"version": "1.6.1",
"description": "Clipping and geometric operations for spherical polygons.",
"keywords": [
"d3",
Expand Down
15 changes: 15 additions & 0 deletions src/clip/polygon.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,21 @@ function interpolate(segments, polygon) {
point = spherical(direction > 0 ? segment.to : segment.from);
stream.point(point[0], point[1]);
}
} else if (
from.index === to.index &&
from.t > to.t &&
from.index != null &&
to.index != null
) {
for (
i = 0;
i < segments.length;
i++
) {
segment = segments[(from.index + i * direction + segments.length)%segments.length],
point = spherical(direction > 0 ? segment.to : segment.from);
stream.point(point[0], point[1]);
}
}
};
}
Expand Down
15 changes: 15 additions & 0 deletions test/clip/polygon-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,18 @@ tape("clipPolygon clips line", function(test) {
test.end();
});


tape("clipPolygon interpolates when the intersections are on the same segment", function(test) {
var clipPolygon = d3.geoClipPolygon({
type: "Polygon",
coordinates: [[[-10, -11], [10, 10], [11, -10], [-10, -11]]]
}),
projection = d3_geo.geoEquirectangular().preclip(clipPolygon).precision(0.1),
path = d3_geo.geoPath().projection(projection);
test.equal(path({
type: "Polygon",
coordinates: [[[0, -11], [1, -11], [1, -10], [0, -10], [0, -11]]]
}).replace(/[.]\d+/g, ""),
"M482,278L482,276L480,276L480,278L466,279L453,279L506,223L509,276L495,277Z");
test.end();
});

0 comments on commit ab7ff70

Please sign in to comment.