Skip to content

Commit

Permalink
test for issue #43 (broken hull)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fil committed Aug 26, 2019
1 parent cac168e commit a12c6cc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
7 changes: 7 additions & 0 deletions test/fixtures/issue43.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
[-537.7739674441619, -122.26130468750004],
[-495.533967444162, -183.39195703125006],
[-453.29396744416204, -244.5226093750001],
[-411.0539674441621, -305.6532617187501],
[-164, -122]
]
18 changes: 16 additions & 2 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Delaunator from '../index.js';

import points from './fixtures/ukraine.json';
import issue13 from './fixtures/issue13.json';
import issue43 from './fixtures/issue43.json';
import issue44 from './fixtures/issue44.json';
import robustness1 from './fixtures/robustness1.json';
import robustness2 from './fixtures/robustness2.json';
Expand Down Expand Up @@ -59,13 +60,18 @@ test('issue #11', (t) => {
t.end();
});

test('issue #13', (t) => {
validate(t, issue13);
t.end();
});

test('issue #24', (t) => {
validate(t, [[382, 302], [382, 328], [382, 205], [623, 175], [382, 188], [382, 284], [623, 87], [623, 341], [141, 227]]);
t.end();
});

test('issue #13', (t) => {
validate(t, issue13);
test('issue #43', (t) => {
validate(t, issue43);
t.end();
});

Expand Down Expand Up @@ -114,6 +120,12 @@ test('supports custom point format', (t) => {
t.end();
});

function convex(a, b, c) {
const dx = a[0] - b[0], dy = a[1] - b[1],
ex = a[0] - c[0], ey = a[1] - c[1];
return dx * ey - ex * dy <= 0;
}

function validate(t, points, d = Delaunator.from(points)) {
// validate halfedges
for (let i = 0; i < d.halfedges.length; i++) {
Expand All @@ -130,6 +142,8 @@ function validate(t, points, d = Delaunator.from(points)) {
const [x0, y0] = points[d.hull[j]];
const [x, y] = points[d.hull[i]];
hullAreas.push((x - x0) * (y + y0));
const c = convex(points[d.hull[j]], points[d.hull[(j + 1) % d.hull.length]], points[d.hull[(j + 3) % d.hull.length]]);
if (!c) t.fail(`hull is not convex at ${j}`);
}
const hullArea = sum(hullAreas);

Expand Down

0 comments on commit a12c6cc

Please sign in to comment.