Skip to content
This repository has been archived by the owner on Dec 15, 2024. It is now read-only.

Commit

Permalink
filter duplicates before checking point count, remove unnecessary slice
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsears18 committed May 5, 2019
1 parent e2f2172 commit 48ae826
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ If you want to get involved with Hull.js development, just use <a href="https://

## Changelog

### 0.2.11 — 05.05.2019
Return the first point as the last point when fewer than 4 unique points are provided.
### 0.2.10 — 04.09.2016
Fixed missing "var" declaration
### 0.2.9 — 28.07.2016
Expand Down
8 changes: 4 additions & 4 deletions dist/hull.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,12 +316,12 @@ function hull(pointset, concavity, format) {
points,
maxEdgeLen = concavity || 20;

if (pointset.length < 4) {
return pointset.concat([pointset[0]]).slice();
}

points = _filterDuplicates(_sortByX(formatUtil.toXy(pointset, format)));

if (points.length < 4) {
return points.concat([points[0]]);
}

occupiedArea = _occupiedArea(points);
maxSearchArea = [
occupiedArea[0] * MAX_SEARCH_BBOX_SIZE_PERCENT,
Expand Down
8 changes: 4 additions & 4 deletions src/hull.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,12 @@ function hull(pointset, concavity, format) {
points,
maxEdgeLen = concavity || 20;

if (pointset.length < 4) {
return pointset.concat([pointset[0]]).slice();
}

points = _filterDuplicates(_sortByX(formatUtil.toXy(pointset, format)));

if (points.length < 4) {
return points.concat([points[0]]);
}

occupiedArea = _occupiedArea(points);
maxSearchArea = [
occupiedArea[0] * MAX_SEARCH_BBOX_SIZE_PERCENT,
Expand Down
14 changes: 13 additions & 1 deletion test/hull.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,21 @@ module.exports = function() {
assert.deepEqual(hull(points, 0.0011, ['.lng', '.lat']), expected);
});

it('should return first point as last point', function() {
it('should append the first point', function() {
var points = [[141, 408], [160, 400], [177, 430]];
var expected = [[141, 408], [160, 400], [177, 430], [141, 408]];
assert.deepEqual(hull(points, 50), expected);
});

it('should not append the first point', function() {
var points = [[141, 408], [160, 400], [141, 408]];
var expected = [[141, 408], [160, 400], [141, 408]];
assert.deepEqual(hull(points, 50), expected);
});

it('should not append the first point', function() {
var points = [[141, 408], [160, 400], [177, 430], [141, 408]];
var expected = [[141, 408], [160, 400], [177, 430], [141, 408]];
assert.deepEqual(hull(points, 50), expected);
});
}

0 comments on commit 48ae826

Please sign in to comment.