From d464eaa14f2e7da4678eaafa20f69af70f14126b Mon Sep 17 00:00:00 2001 From: mattsears18 Date: Thu, 28 Mar 2019 11:16:48 -0400 Subject: [PATCH 1/5] return first point as last point when pointset length < 4 --- dist/hull.js | 2 +- src/hull.js | 2 +- test/hull.js | 8 +++++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/dist/hull.js b/dist/hull.js index 3aef2ec..c555c91 100755 --- a/dist/hull.js +++ b/dist/hull.js @@ -317,7 +317,7 @@ function hull(pointset, concavity, format) { maxEdgeLen = concavity || 20; if (pointset.length < 4) { - return pointset.slice(); + return pointset.concat([pointset[0]]); } points = _filterDuplicates(_sortByX(formatUtil.toXy(pointset, format))); diff --git a/src/hull.js b/src/hull.js index 4d473b7..fd8f65b 100644 --- a/src/hull.js +++ b/src/hull.js @@ -172,7 +172,7 @@ function hull(pointset, concavity, format) { maxEdgeLen = concavity || 20; if (pointset.length < 4) { - return pointset.slice(); + return pointset.concat([pointset[0]]); } points = _filterDuplicates(_sortByX(formatUtil.toXy(pointset, format))); diff --git a/test/hull.js b/test/hull.js index dda1f7a..5220770 100644 --- a/test/hull.js +++ b/test/hull.js @@ -19,4 +19,10 @@ 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 return first point as last 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); + }); +} From 949d2806d44d647f650b44e8ef43865d1e6078f5 Mon Sep 17 00:00:00 2001 From: mattsears18 Date: Thu, 28 Mar 2019 15:32:11 -0400 Subject: [PATCH 2/5] update node and devDependencies --- .travis.yml | 2 +- dist/hull.js | 4 ++-- package.json | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) 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/dist/hull.js b/dist/hull.js index c555c91..a4bef5f 100755 --- a/dist/hull.js +++ b/dist/hull.js @@ -1,4 +1,4 @@ -!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.hull=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o ./dist/hull.js\"", From 978e23e57a12ae8c9a730d3f27743955851d65ca Mon Sep 17 00:00:00 2001 From: mattsears18 Date: Thu, 28 Mar 2019 15:49:47 -0400 Subject: [PATCH 3/5] update package version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9ff239b..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": [ From e2f2172efc11f28609f6e8c843d27db00bba1961 Mon Sep 17 00:00:00 2001 From: mattsears18 Date: Thu, 28 Mar 2019 16:40:43 -0400 Subject: [PATCH 4/5] copy array length < 3 --- dist/hull.js | 7 ++++--- src/hull.js | 8 ++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/dist/hull.js b/dist/hull.js index a4bef5f..7aac291 100755 --- a/dist/hull.js +++ b/dist/hull.js @@ -284,7 +284,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)); @@ -317,7 +317,7 @@ function hull(pointset, concavity, format) { maxEdgeLen = concavity || 20; if (pointset.length < 4) { - return pointset.concat([pointset[0]]); + return pointset.concat([pointset[0]]).slice(); } points = _filterDuplicates(_sortByX(formatUtil.toXy(pointset, format))); @@ -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)); diff --git a/src/hull.js b/src/hull.js index fd8f65b..ab3ed70 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)); @@ -172,7 +172,7 @@ function hull(pointset, concavity, format) { maxEdgeLen = concavity || 20; if (pointset.length < 4) { - return pointset.concat([pointset[0]]); + return pointset.concat([pointset[0]]).slice(); } points = _filterDuplicates(_sortByX(formatUtil.toXy(pointset, format))); @@ -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; From 48ae8261ef7a3f46b4b91b7911606347257d388b Mon Sep 17 00:00:00 2001 From: mattsears18 Date: Sun, 5 May 2019 16:15:39 -0400 Subject: [PATCH 5/5] filter duplicates before checking point count, remove unnecessary slice --- README.md | 2 ++ dist/hull.js | 8 ++++---- src/hull.js | 8 ++++---- test/hull.js | 14 +++++++++++++- 4 files changed, 23 insertions(+), 9 deletions(-) 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