robust-predicates 2.0.2 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/esm/orient2d.js CHANGED
@@ -1,7 +1,4 @@
1
- import {
2
- epsilon, splitter, resulterrbound, estimate, vec,
3
- fast_expansion_sum_zeroelim
4
- } from './util.js';
1
+ import {epsilon, splitter, resulterrbound, estimate, vec, sum} from './util.js';
5
2
 
6
3
  const ccwerrboundA = (3 + 16 * epsilon) * epsilon;
7
4
  const ccwerrboundB = (2 + 12 * epsilon) * epsilon;
@@ -15,49 +12,48 @@ const u = vec(4);
15
12
 
16
13
  function orient2dadapt(ax, ay, bx, by, cx, cy, detsum) {
17
14
  let acxtail, acytail, bcxtail, bcytail;
18
- let detleft, detright, detlefttail, detrighttail;
19
- let B3, u3, s1, t1, s0, t0;
20
- let bvirt, c, ahi, alo, bhi, blo, _i, _j, _0;
15
+ let bvirt, c, ahi, alo, bhi, blo, _i, _j, _0, s1, s0, t1, t0, u3;
21
16
 
22
17
  const acx = ax - cx;
23
18
  const bcx = bx - cx;
24
19
  const acy = ay - cy;
25
20
  const bcy = by - cy;
26
21
 
27
- detleft = acx * bcy;
22
+ s1 = acx * bcy;
28
23
  c = splitter * acx;
29
24
  ahi = c - (c - acx);
30
25
  alo = acx - ahi;
31
26
  c = splitter * bcy;
32
27
  bhi = c - (c - bcy);
33
28
  blo = bcy - bhi;
34
- detlefttail = alo * blo - (detleft - ahi * bhi - alo * bhi - ahi * blo);
35
- detright = acy * bcx;
29
+ s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
30
+ t1 = acy * bcx;
36
31
  c = splitter * acy;
37
32
  ahi = c - (c - acy);
38
33
  alo = acy - ahi;
39
34
  c = splitter * bcx;
40
35
  bhi = c - (c - bcx);
41
36
  blo = bcx - bhi;
42
- detrighttail = alo * blo - (detright - ahi * bhi - alo * bhi - ahi * blo);
43
-
44
- _i = detlefttail - detrighttail;
45
- bvirt = detlefttail - _i;
46
- B[0] = detlefttail - (_i + bvirt) + (bvirt - detrighttail);
47
- _j = detleft + _i;
48
- bvirt = _j - detleft;
49
- _0 = detleft - (_j - bvirt) + (_i - bvirt);
50
- _i = _0 - detright;
37
+ t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
38
+ _i = s0 - t0;
39
+ bvirt = s0 - _i;
40
+ B[0] = s0 - (_i + bvirt) + (bvirt - t0);
41
+ _j = s1 + _i;
42
+ bvirt = _j - s1;
43
+ _0 = s1 - (_j - bvirt) + (_i - bvirt);
44
+ _i = _0 - t1;
51
45
  bvirt = _0 - _i;
52
- B[1] = _0 - (_i + bvirt) + (bvirt - detright);
53
- B3 = _j + _i;
54
- bvirt = B3 - _j;
55
- B[2] = _j - (B3 - bvirt) + (_i - bvirt);
56
- B[3] = B3;
46
+ B[1] = _0 - (_i + bvirt) + (bvirt - t1);
47
+ u3 = _j + _i;
48
+ bvirt = u3 - _j;
49
+ B[2] = _j - (u3 - bvirt) + (_i - bvirt);
50
+ B[3] = u3;
57
51
 
58
52
  let det = estimate(4, B);
59
53
  let errbound = ccwerrboundB * detsum;
60
- if (det >= errbound || -det >= errbound) return det;
54
+ if (det >= errbound || -det >= errbound) {
55
+ return det;
56
+ }
61
57
 
62
58
  bvirt = ax - acx;
63
59
  acxtail = ax - (acx + bvirt) + (bvirt - cx);
@@ -68,13 +64,13 @@ function orient2dadapt(ax, ay, bx, by, cx, cy, detsum) {
68
64
  bvirt = by - bcy;
69
65
  bcytail = by - (bcy + bvirt) + (bvirt - cy);
70
66
 
71
- if (acxtail === 0 && acytail === 0 && bcxtail === 0 && bcytail === 0) return det;
67
+ if (acxtail === 0 && acytail === 0 && bcxtail === 0 && bcytail === 0) {
68
+ return det;
69
+ }
72
70
 
73
71
  errbound = ccwerrboundC * detsum + resulterrbound * Math.abs(det);
74
72
  det += (acx * bcytail + bcy * acxtail) - (acy * bcxtail + bcx * acytail);
75
- if (det >= errbound || -det >= errbound) {
76
- return det;
77
- }
73
+ if (det >= errbound || -det >= errbound) return det;
78
74
 
79
75
  s1 = acxtail * bcy;
80
76
  c = splitter * acxtail;
@@ -105,7 +101,7 @@ function orient2dadapt(ax, ay, bx, by, cx, cy, detsum) {
105
101
  bvirt = u3 - _j;
106
102
  u[2] = _j - (u3 - bvirt) + (_i - bvirt);
107
103
  u[3] = u3;
108
- const C1length = fast_expansion_sum_zeroelim(4, B, 4, u, C1);
104
+ const C1len = sum(4, B, 4, u, C1);
109
105
 
110
106
  s1 = acx * bcytail;
111
107
  c = splitter * acx;
@@ -136,7 +132,7 @@ function orient2dadapt(ax, ay, bx, by, cx, cy, detsum) {
136
132
  bvirt = u3 - _j;
137
133
  u[2] = _j - (u3 - bvirt) + (_i - bvirt);
138
134
  u[3] = u3;
139
- const C2length = fast_expansion_sum_zeroelim(C1length, C1, 4, u, C2);
135
+ const C2len = sum(C1len, C1, 4, u, C2);
140
136
 
141
137
  s1 = acxtail * bcytail;
142
138
  c = splitter * acxtail;
@@ -167,37 +163,20 @@ function orient2dadapt(ax, ay, bx, by, cx, cy, detsum) {
167
163
  bvirt = u3 - _j;
168
164
  u[2] = _j - (u3 - bvirt) + (_i - bvirt);
169
165
  u[3] = u3;
170
- const Dlength = fast_expansion_sum_zeroelim(C2length, C2, 4, u, D);
166
+ const Dlen = sum(C2len, C2, 4, u, D);
171
167
 
172
- return D[Dlength - 1];
168
+ return D[Dlen - 1];
173
169
  }
174
170
 
175
171
  export function orient2d(ax, ay, bx, by, cx, cy) {
176
172
  const detleft = (ay - cy) * (bx - cx);
177
173
  const detright = (ax - cx) * (by - cy);
178
174
  const det = detleft - detright;
179
- let detsum;
180
-
181
- if (detleft > 0) {
182
- if (detright <= 0) {
183
- return det;
184
- }
185
- detsum = detleft + detright;
186
175
 
187
- } else if (detleft < 0) {
188
- if (detright >= 0) {
189
- return det;
190
- }
191
- detsum = -detleft - detright;
176
+ if (detleft === 0 || detright === 0 || (detleft > 0) !== (detright > 0)) return det;
192
177
 
193
- } else {
194
- return det;
195
- }
196
-
197
- const errbound = ccwerrboundA * detsum;
198
- if (det >= errbound || -det >= errbound) {
199
- return det;
200
- }
178
+ const detsum = Math.abs(detleft + detright);
179
+ if (Math.abs(det) >= ccwerrboundA * detsum) return det;
201
180
 
202
181
  return -orient2dadapt(ax, ay, bx, by, cx, cy, detsum);
203
182
  }