@@ -16,17 +16,29 @@ function pointY(p) {
16
16
function area ( hull , points ) {
17
17
let n = hull . length , x0 , y0 ,
18
18
x1 = points [ 2 * hull [ n - 1 ] ] ,
19
- y1 = points [ 2 * hull [ n - 1 ] + 1 ] ,
20
- area = 0 ;
19
+ y1 = points [ 2 * hull [ n - 1 ] + 1 ] ;
21
20
21
+ const v = [ ] ;
22
22
for ( let i = 0 ; i < n ; i ++ ) {
23
23
x0 = x1 , y0 = y1 ;
24
- x1 = points [ 2 * hull [ i ] ] ;
25
- y1 = points [ 2 * hull [ i ] + 1 ] ;
26
- area += y0 * x1 - x0 * y1 ;
24
+ x1 = points [ 2 * hull [ i ] ] - points [ 2 * hull [ 0 ] ] ;
25
+ y1 = points [ 2 * hull [ i ] + 1 ] - points [ 2 * hull [ 0 ] + 1 ] ;
26
+ v . push ( y0 * x1 , - x0 * y1 ) ;
27
27
}
28
28
29
- return area / 2 ;
29
+ return kahansum ( v ) / 2 ;
30
+ }
31
+
32
+ function kahansum ( values ) {
33
+ let summ = 0 ,
34
+ c = 0 ;
35
+ for ( const num of values ) {
36
+ let y = num - c ,
37
+ t = summ + y ;
38
+ c = t - summ - y ;
39
+ summ = t ;
40
+ }
41
+ return summ ;
30
42
}
31
43
32
44
function jitter ( x , y , r ) {
@@ -50,7 +62,7 @@ export default class Delaunay {
50
62
const d = this . _delaunator , points = this . points ;
51
63
52
64
// check for collinear
53
- if ( d . hull && d . hull . length > 2 && area ( d . hull , points ) < 1e-10 ) {
65
+ if ( d . hull && d . hull . length > 2 && ( d . triangles . length === 0 || area ( d . hull , points ) < 1e-10 ) ) {
54
66
this . collinear = Int32Array . from ( { length : points . length / 2 } , ( _ , i ) => i )
55
67
. sort ( ( i , j ) => points [ 2 * i ] - points [ 2 * j ] || points [ 2 * i + 1 ] - points [ 2 * j + 1 ] ) ; // for exact neighbors
56
68
const e = this . collinear [ 0 ] , f = this . collinear [ this . collinear . length - 1 ] ,
0 commit comments