Fix a bug in `pointSearch` on closed lines.
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.
MODIFY
src/lineFeature.js
src/lineFeature.js
@@ -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) {
+ });
+ 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;

MODIFY
src/polygonFeature.js
src/polygonFeature.js
@@ -345,13 +345,17 @@ var polygonFeature = function (arg) {
continue;
}
loop = polygon.outer || (Array.isArray(polygon) ? polygon : []);
+ 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) {
return posFunc(d[0], d[1], d[2], d[3]);
});

MODIFY
tests/cases/lineFeature.js
tests/cases/lineFeature.js
@@ -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
}
];
@@ -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}));
@@ -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');

Fix a bug in `pointSearch` on closed lines.

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.