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

Commit

Permalink
Merge pull request #13 from mattsears18/length-3-pointsets
Browse files Browse the repository at this point in the history
Length 3 pointsets
  • Loading branch information
andriiheonia authored May 6, 2019
2 parents a53fa57 + 48ae826 commit 49e27f0
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
language: node_js
node_js:
- "0.10"
- "10.15.3"
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
17 changes: 9 additions & 8 deletions dist/hull.js
Original file line number Diff line number Diff line change
@@ -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<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.hull = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
function _cross(o, a, b) {
return (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0]);
}
Expand Down Expand Up @@ -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));

Expand Down Expand Up @@ -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,
Expand All @@ -338,14 +338,15 @@ 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;

},{"./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));
Expand All @@ -363,4 +364,4 @@ function intersect(seg1, seg2) {

module.exports = intersect;
},{}]},{},[4])(4)
});
});
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand All @@ -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\"",
Expand Down
14 changes: 7 additions & 7 deletions src/hull.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down Expand Up @@ -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,
Expand All @@ -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;
module.exports = hull;
20 changes: 19 additions & 1 deletion test/hull.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}

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 49e27f0

Please sign in to comment.