Skip to content

Commit

Permalink
upgrade deps and linting
Browse files Browse the repository at this point in the history
  • Loading branch information
mourner committed Jul 19, 2018
1 parent 492939b commit 10a422f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 26 deletions.
3 changes: 0 additions & 3 deletions .eslintrc

This file was deleted.

7 changes: 3 additions & 4 deletions index.js
Expand Up @@ -99,10 +99,9 @@ function polygonclip(points, bbox) {

function intersect(a, b, edge, bbox) {
return edge & 8 ? [a[0] + (b[0] - a[0]) * (bbox[3] - a[1]) / (b[1] - a[1]), bbox[3]] : // top
edge & 4 ? [a[0] + (b[0] - a[0]) * (bbox[1] - a[1]) / (b[1] - a[1]), bbox[1]] : // bottom
edge & 2 ? [bbox[2], a[1] + (b[1] - a[1]) * (bbox[2] - a[0]) / (b[0] - a[0])] : // right
edge & 1 ? [bbox[0], a[1] + (b[1] - a[1]) * (bbox[0] - a[0]) / (b[0] - a[0])] : // left
null;
edge & 4 ? [a[0] + (b[0] - a[0]) * (bbox[1] - a[1]) / (b[1] - a[1]), bbox[1]] : // bottom
edge & 2 ? [bbox[2], a[1] + (b[1] - a[1]) * (bbox[2] - a[0]) / (b[0] - a[0])] : // right
edge & 1 ? [bbox[0], a[1] + (b[1] - a[1]) * (bbox[0] - a[0]) / (b[0] - a[0])] : null; // left
}

// bit code reflects the point position relative to the bbox:
Expand Down
14 changes: 10 additions & 4 deletions package.json
Expand Up @@ -4,10 +4,10 @@
"description": "A fast polyline and polygon clipping library.",
"main": "index.js",
"devDependencies": {
"benchmark": "^2.1.1",
"eslint": "^3.7.1",
"eslint-config-mourner": "^2.0.1",
"tap": "^7.1.2"
"benchmark": "^2.1.4",
"eslint": "^5.1.0",
"eslint-config-mourner": "^2.0.3",
"tap": "^12.0.1"
},
"scripts": {
"test": "eslint index.js test.js && tap test.js",
Expand All @@ -27,6 +27,12 @@
"geo",
"cohen-sutherland"
],
"eslintConfig": {
"extends": "mourner",
"rules": {
"indent": [2, 4, {"flatTernaryExpressions": true}]
}
},
"author": "Vladimir Agafonkin",
"license": "ISC",
"bugs": {
Expand Down
22 changes: 7 additions & 15 deletions test.js
Expand Up @@ -7,7 +7,7 @@ test('clips line', function (t) {
var result = clip([
[-10, 10], [10, 10], [10, -10], [20, -10], [20, 10], [40, 10],
[40, 20], [20, 20], [20, 40], [10, 40], [10, 20], [5, 20], [-10, 20]],
[0, 0, 30, 30]);
[0, 0, 30, 30]);

t.same(result, [
[[0, 10], [10, 10], [10, 0]],
Expand All @@ -20,9 +20,7 @@ test('clips line', function (t) {
});

test('clips line crossing through many times', function (t) {
var result = clip(
[[10, -10], [10, 30], [20, 30], [20, -10]],
[0, 0, 20, 20]);
var result = clip([[10, -10], [10, 30], [20, 30], [20, -10]], [0, 0, 20, 20]);

t.same(result, [
[[10, 0], [10, 20]],
Expand All @@ -35,7 +33,7 @@ test('clips line crossing through many times', function (t) {
test('clips polygon', function (t) {
var result = clip.polygon([[-10, 10], [0, 10], [10, 10], [10, 5], [10, -5], [10, -10], [20, -10],
[20, 10], [40, 10], [40, 20], [20, 20], [20, 40], [10, 40], [10, 20], [5, 20], [-10, 20]],
[0, 0, 30, 30]);
[0, 0, 30, 30]);

t.same(result, [[0, 10], [0, 10], [10, 10], [10, 5], [10, 0], [20, 0], [20, 10], [30, 10],
[30, 20], [20, 20], [20, 30], [10, 30], [10, 20], [5, 20], [0, 20]]);
Expand Down Expand Up @@ -73,21 +71,15 @@ test('clips floating point lines', function (t) {
});

test('preserves line if no protrusions exist', function (t) {
var result = clip([
[1, 1], [2, 2], [3, 3]],
[0, 0, 30, 30]);
var result = clip([[1, 1], [2, 2], [3, 3]], [0, 0, 30, 30]);

t.same(result, [
[[1, 1], [2, 2], [3, 3]]
]);
t.same(result, [[[1, 1], [2, 2], [3, 3]]]);

t.end();
});

test('clips without leaving empty parts', function (t) {
var result = clip([
[40, 40], [50, 50]],
[0, 0, 30, 30]);
var result = clip([[40, 40], [50, 50]], [0, 0, 30, 30]);

t.same(result, []);

Expand All @@ -97,7 +89,7 @@ test('clips without leaving empty parts', function (t) {
test('still works when polygon never crosses bbox', function (t) {
var result = clip.polygon([
[3, 3], [5, 3], [5, 5], [3, 5], [3, 3]],
[0, 0, 2, 2]);
[0, 0, 2, 2]);

t.same(result, []);

Expand Down

0 comments on commit 10a422f

Please sign in to comment.