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

Return information on which line segment is found. #1008

Merged
merged 2 commits into from
Jul 11, 2019
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
12 changes: 8 additions & 4 deletions src/lineFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,13 @@ var lineFeature = function (arg) {
* the narrow end.
*
* @param {geo.geoPosition} p point to search for in map interface gcs.
* @returns {object} An object with `index`: a list of line indices, and
* `found`: a list of quads that contain the specified coordinate.
* @returns {object} An object with `index`: a list of line indices, `found`:
* a list of quads that contain the specified coordinate, and `extra`: am
* object with keys that are line indices and values that are the first
* segement index for which the line was matched.
*/
this.pointSearch = function (p) {
var data = m_this.data(), indices = [], found = [];
var data = m_this.data(), indices = [], found = [], extra = {};
if (!data || !data.length || !m_this.layer()) {
return {
found: found,
Expand All @@ -219,13 +221,15 @@ var lineFeature = function (arg) {
if (util.distance2dToLineSquared(pt, record[j].u, record[j].v) <= record[j].r2 * scale2) {
found.push(data[i]);
indices.push(i);
extra[i] = j;
break;
}
}
}
return {
found: found,
index: indices
index: indices,
extra: extra
};
};

Expand Down
7 changes: 5 additions & 2 deletions src/quadFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,11 @@ var quadFeature = function (arg) {
*
* @param {geo.geoPosition} coordinate Coordinate in input gcs to check if it
* is located in any quad in map interface gcs.
* @returns {object} An object with `index`: a list of quad indices, and
* `found`: a list of quads that contain the specified coordinate.
* @returns {object} An object with `index`: a list of quad indices, `found`:
* a list of quads that contain the specified coordinate, and `extra`: an
* object with keys that are quad indices and values that are objects with
* `basis.x` and `basis.y`, values from 0 - 1 relative to interior of the
* quad.
*/
this.pointSearch = function (coordinate) {
var found = [], indices = [], extra = {},
Expand Down
2 changes: 2 additions & 0 deletions tests/cases/lineFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,12 @@ describe('geo.lineFeature', function () {
* line, but not on an open line */
pt = line.pointSearch({x: 31, y: 12.5});
expect(pt.found.length).toBe(1);
expect(pt.extra[1]).toBe(2);
pt = line.pointSearch({x: 31, y: 22.5});
expect(pt.found.length).toBe(0);
pt = line.pointSearch({x: 31, y: 32.5});
expect(pt.found.length).toBe(1);
expect(pt.extra[3]).toBe(2);
/* 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. */
Expand Down