Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix an edge case with polygon clipping #113

Merged
merged 1 commit into from
Oct 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/clip.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,11 @@ function clipLine(geom, newGeom, k1, k2, axis, isPolygon, trackMetrics) {

if (a < k1) {
// ---|--> | (line enters the clip region from the left)
if (b >= k1) {
if (b > k1) {
t = intersect(slice, ax, ay, bx, by, k1);
if (trackMetrics) slice.start = len + segLen * t;
}
} else if (a >= k2) {
} else if (a > k2) {
// | <--|--- (line enters the clip region from the right)
if (b < k2) {
t = intersect(slice, ax, ay, bx, by, k2);
Expand Down
23 changes: 23 additions & 0 deletions test/test-get-tile.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,29 @@ test('getTile: unbuffered tile top/bottom edges', function (t) {
t.end();
});

test('getTile: polygon clipping on the boundary', function (t) {
var index = geojsonvt({
type: 'Polygon',
coordinates: [[
[42.1875, 57.32652122521708],
[47.8125, 57.32652122521708],
[47.8125, 54.16243396806781],
[42.1875, 54.16243396806781],
[42.1875, 57.32652122521708]
]]
}, {
buffer: 1024
});

t.same(index.getTile(5, 19, 9).features, [{
geometry: [[[3072, 3072], [5120, 3072], [5120, 5120], [3072, 5120], [3072, 3072]]],
type: 3,
tags: null
}]);

t.end();
});

function getJSON(name) {
return JSON.parse(fs.readFileSync(path.join(__dirname, '/fixtures/' + name)));
}