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

expose rbush tree, allowing extra flexibility if needed #2

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ function whichPolygon(data) {

var tree = rbush().load(bboxes);

return function query(p) {
var query = function (p) {
var result = tree.search([p[0], p[1], p[0], p[1]]);
for (var i = 0; i < result.length; i++) {
if (insidePolygon(result[i][4], p)) return result[i][5];
}
return null;
};
query.tree = tree;
return query;
}

// ray casting algorithm for detecting if point is in polygon
Expand Down
6 changes: 6 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,9 @@ test('queries polygons', function (t) {
t.equal(query([-50, 30]), null);
t.end();
});

test('returns tree', function (t) {
t.ok(query.tree);
t.type(query.tree, 'object');
t.end();
});