Skip to content

Commit

Permalink
Fix a bug in pointSearch on closed lines.
Browse files Browse the repository at this point in the history
Some code was in a loop that should have been out of it.  This adds a
test for the correct behavior.

Also, if a polygon is degenerate, it should not generate stroke
information.
  • Loading branch information
manthey committed Feb 26, 2018
1 parent 9c36186 commit b06e0f2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/lineFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,10 @@ var lineFeature = function (arg) {
if (!first && closed) {
first = {p: p, r2: r2};
}
if (closed && last.x !== first.p.x && last.y !== first.p.y) {
record.push({u: last, v: first.p, r2: lastr2 > first.r2 ? lastr2 : first.r2});
}
});
if (closed && first && (last.x !== first.p.x || last.y !== first.p.y)) {
record.push({u: last, v: first.p, r2: lastr2 > first.r2 ? lastr2 : first.r2});
}
m_pointSearchInfo.push(record);
});
return m_pointSearchInfo;
Expand Down
14 changes: 9 additions & 5 deletions src/polygonFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,11 +345,15 @@ var polygonFeature = function (arg) {
continue;
}
loop = polygon.outer || (Array.isArray(polygon) ? polygon : []);
lineData.push(m_this._getLoopData(data[i], i, loop));
if (polygon.inner) {
polygon.inner.forEach(function (loop) {
lineData.push(m_this._getLoopData(data[i], i, loop));
});
if (loop.length >= 2) {
lineData.push(m_this._getLoopData(data[i], i, loop));
if (polygon.inner) {
polygon.inner.forEach(function (loop) {
if (loop.length >= 2) {
lineData.push(m_this._getLoopData(data[i], i, loop));
}
});
}
}
}
m_lineFeature.position(function (d, i, item, itemIndex) {
Expand Down
12 changes: 11 additions & 1 deletion tests/cases/lineFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ describe('geo.lineFeature', function () {
coord: [{x: 50, y: 10}, {x: 50, y: 10}]
}, {
coord: [{x: 60, y: 10}]
}, {
coord: [{x: 70, y: 10}, {x: 75, y: 12}, {x: 72, y: 15}, {x: 70, y: 15}],
closed: true
}
];

Expand Down Expand Up @@ -124,6 +127,13 @@ describe('geo.lineFeature', function () {
expect(pt.found.length).toBe(0);
pt = line.pointSearch({x: 31, y: 32.5});
expect(pt.found.length).toBe(1);
/* On a closed line, we should find a point between the first and last
* point, but not between the first and a point that isn't the second or
* last. */
pt = line.pointSearch({x: 70, y: 12.5});
expect(pt.found.length).toBe(1);
pt = line.pointSearch({x: 71, y: 12.5});
expect(pt.found.length).toBe(0);
/* Variable width should match the widest of either end point */
p = line.featureGcsToDisplay({x: 40, y: 20});
pt = line.pointSearch(map.displayToGcs({x: p.x, y: p.y + 6.95}));
Expand Down Expand Up @@ -218,7 +228,7 @@ describe('geo.lineFeature', function () {
}).data(testLines);
line.draw();
stepAnimationFrame();
expect(layer.node().find('path').length).toBe(7);
expect(layer.node().find('path').length).toBe(8);
var paths = layer.node().find('path');
expect(paths.eq(0).css('stroke-linecap')).toBe('butt');
expect(paths.eq(1).css('stroke-linecap')).toBe('round');
Expand Down

0 comments on commit b06e0f2

Please sign in to comment.