diff --git a/.travis.yml b/.travis.yml index 87f8cd9..ec14367 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,3 @@ language: node_js node_js: - - "0.10" \ No newline at end of file + - "10.15.3" diff --git a/README.md b/README.md index 67ca304..aa33d67 100755 --- a/README.md +++ b/README.md @@ -69,6 +69,8 @@ If you want to get involved with Hull.js development, just use bBoxWidth || maxSearchArea[1] > bBoxHeight)); @@ -316,12 +316,12 @@ function hull(pointset, concavity, format) { points, maxEdgeLen = concavity || 20; - if (pointset.length < 4) { - return pointset.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, @@ -338,7 +338,7 @@ function hull(pointset, concavity, format) { concave = _concave( convex, Math.pow(maxEdgeLen, 2), maxSearchArea, grid(innerPoints, cellSize), {}); - + return formatUtil.fromXy(concave, format); } @@ -346,6 +346,7 @@ var MAX_CONCAVE_ANGLE_COS = Math.cos(90 / (180 / Math.PI)); // angle = 90 deg var MAX_SEARCH_BBOX_SIZE_PERCENT = 0.6; module.exports = hull; + },{"./convex.js":1,"./format.js":2,"./grid.js":3,"./intersect.js":5}],5:[function(require,module,exports){ function ccw(x1, y1, x2, y2, x3, y3) { var cw = ((y3 - y1) * (x2 - x1)) - ((y2 - y1) * (x3 - x1)); @@ -363,4 +364,4 @@ function intersect(seg1, seg2) { module.exports = intersect; },{}]},{},[4])(4) -}); \ No newline at end of file +}); diff --git a/package.json b/package.json index e8eecb4..31052db 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hull.js", - "version": "0.2.10", + "version": "0.2.11", "description": "JavaScript library that builds concave hulls (shapes) by set of points", "homepage": "https://github.com/AndriiHeonia/hull", "keywords": [ @@ -17,10 +17,10 @@ }, "main": "./src/hull.js", "devDependencies": { - "nodemon": "~1.9.0", - "mocha": "~1.18.2", - "jshint": "~2.5.0", - "browserify": "~5.11.0" + "nodemon": "~1.18.0", + "mocha": "~6.0.2", + "jshint": "~2.10.2", + "browserify": "~16.2.3" }, "scripts": { "watch": "./node_modules/nodemon/bin/nodemon.js --watch src --exec \"./node_modules/browserify/bin/cmd.js ./src/hull.js --standalone hull > ./dist/hull.js\"", diff --git a/src/hull.js b/src/hull.js index 4d473b7..84b6f50 100644 --- a/src/hull.js +++ b/src/hull.js @@ -139,7 +139,7 @@ function _concave(convex, maxSqEdgeLen, maxSearchArea, grid, edgeSkipList) { bBoxWidth = bBoxAround[2] - bBoxAround[0]; bBoxHeight = bBoxAround[3] - bBoxAround[1]; - midPoint = _midPoint(edge, grid.rangePoints(bBoxAround), convex); + midPoint = _midPoint(edge, grid.rangePoints(bBoxAround), convex); scaleFactor++; } while (midPoint === null && (maxSearchArea[0] > bBoxWidth || maxSearchArea[1] > bBoxHeight)); @@ -171,12 +171,12 @@ function hull(pointset, concavity, format) { points, maxEdgeLen = concavity || 20; - if (pointset.length < 4) { - return pointset.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, @@ -193,11 +193,11 @@ function hull(pointset, concavity, format) { concave = _concave( convex, Math.pow(maxEdgeLen, 2), maxSearchArea, grid(innerPoints, cellSize), {}); - + return formatUtil.fromXy(concave, format); } var MAX_CONCAVE_ANGLE_COS = Math.cos(90 / (180 / Math.PI)); // angle = 90 deg var MAX_SEARCH_BBOX_SIZE_PERCENT = 0.6; -module.exports = hull; \ No newline at end of file +module.exports = hull; diff --git a/test/hull.js b/test/hull.js index dda1f7a..6398ecd 100644 --- a/test/hull.js +++ b/test/hull.js @@ -19,4 +19,22 @@ module.exports = function() { var expected = [{lng: -0.206792373176235, lat: 51.4911165465815 }, {lng: -0.207062672933557, lat: 51.4915703125214 }, {lng: -0.207465840096923, lat: 51.4912077781219 }, {lng: -0.210193421020222, lat: 51.4918159814458 }, {lng: -0.214944392455692, lat: 51.4929945001276 }, {lng: -0.216849005460861, lat: 51.4921781720221 }, {lng: -0.214162055384851, lat: 51.4905275966855 }, {lng: -0.212571431609104, lat: 51.4903145141462 }, {lng: -0.209680931181673, lat: 51.4901894811742 }, {lng: -0.208161917730384, lat: 51.4903551232517 }, {lng: -0.208133371509344, lat: 51.4910830915252 }, {lng: -0.206792373176235, lat: 51.4911165465815}]; assert.deepEqual(hull(points, 0.0011, ['.lng', '.lat']), expected); }); -} \ No newline at end of file + + 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); + }); +}