Skip to content

Commit 2ba995a

Browse files
committed
fix an edge case with polygon clipping
1 parent b45f80a commit 2ba995a

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

src/clip.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,11 @@ function clipLine(geom, newGeom, k1, k2, axis, isPolygon, trackMetrics) {
118118

119119
if (a < k1) {
120120
// ---|--> | (line enters the clip region from the left)
121-
if (b >= k1) {
121+
if (b > k1) {
122122
t = intersect(slice, ax, ay, bx, by, k1);
123123
if (trackMetrics) slice.start = len + segLen * t;
124124
}
125-
} else if (a >= k2) {
125+
} else if (a > k2) {
126126
// | <--|--- (line enters the clip region from the right)
127127
if (b < k2) {
128128
t = intersect(slice, ax, ay, bx, by, k2);

test/test-get-tile.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,29 @@ test('getTile: unbuffered tile top/bottom edges', function (t) {
5959
t.end();
6060
});
6161

62+
test('getTile: polygon clipping on the boundary', function (t) {
63+
var index = geojsonvt({
64+
type: 'Polygon',
65+
coordinates: [[
66+
[42.1875, 57.32652122521708],
67+
[47.8125, 57.32652122521708],
68+
[47.8125, 54.16243396806781],
69+
[42.1875, 54.16243396806781],
70+
[42.1875, 57.32652122521708]
71+
]]
72+
}, {
73+
buffer: 1024
74+
});
75+
76+
t.same(index.getTile(5, 19, 9).features, [{
77+
geometry: [[[3072, 3072], [5120, 3072], [5120, 5120], [3072, 5120], [3072, 3072]]],
78+
type: 3,
79+
tags: null
80+
}]);
81+
82+
t.end();
83+
});
84+
6285
function getJSON(name) {
6386
return JSON.parse(fs.readFileSync(path.join(__dirname, '/fixtures/' + name)));
6487
}

0 commit comments

Comments
 (0)