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

Improve line updates #779

Merged
merged 5 commits into from
Feb 28, 2018
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
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.
  • Loading branch information
manthey committed Feb 26, 2018
commit b06e0f23453b86458d72d004f01940a7a8afeddf
6 changes: 3 additions & 3 deletions src/lineFeature.js
Original file line number Diff line number Diff line change
@@ -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;
14 changes: 9 additions & 5 deletions src/polygonFeature.js
Original file line number Diff line number Diff line change
@@ -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) {
12 changes: 11 additions & 1 deletion tests/cases/lineFeature.js
Original file line number Diff line number Diff line change
@@ -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');