@loaders.gl/terrain 3.4.13 → 3.4.15

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.
@@ -1,16 +1,12 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
5
  });
7
6
  exports.default = void 0;
8
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
9
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
10
- var Delatin = function () {
11
- function Delatin(data, width) {
12
- var height = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : width;
13
- (0, _classCallCheck2.default)(this, Delatin);
7
+ class Delatin {
8
+ constructor(data, width) {
9
+ let height = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : width;
14
10
  this.data = data;
15
11
  this.width = width;
16
12
  this.height = height;
@@ -25,384 +21,342 @@ var Delatin = function () {
25
21
  this._pending = [];
26
22
  this._pendingLen = 0;
27
23
  this._rmsSum = 0;
28
- var x1 = width - 1;
29
- var y1 = height - 1;
30
- var p0 = this._addPoint(0, 0);
31
- var p1 = this._addPoint(x1, 0);
32
- var p2 = this._addPoint(0, y1);
33
- var p3 = this._addPoint(x1, y1);
34
- var t0 = this._addTriangle(p3, p0, p2, -1, -1, -1);
24
+ const x1 = width - 1;
25
+ const y1 = height - 1;
26
+ const p0 = this._addPoint(0, 0);
27
+ const p1 = this._addPoint(x1, 0);
28
+ const p2 = this._addPoint(0, y1);
29
+ const p3 = this._addPoint(x1, y1);
30
+ const t0 = this._addTriangle(p3, p0, p2, -1, -1, -1);
35
31
  this._addTriangle(p0, p3, p1, t0, -1, -1);
36
32
  this._flush();
37
33
  }
38
- (0, _createClass2.default)(Delatin, [{
39
- key: "run",
40
- value: function run() {
41
- var maxError = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
42
- while (this.getMaxError() > maxError) {
43
- this.refine();
44
- }
45
- }
46
- }, {
47
- key: "refine",
48
- value: function refine() {
49
- this._step();
50
- this._flush();
51
- }
52
- }, {
53
- key: "getMaxError",
54
- value: function getMaxError() {
55
- return this._errors[0];
56
- }
57
- }, {
58
- key: "getRMSD",
59
- value: function getRMSD() {
60
- return this._rmsSum > 0 ? Math.sqrt(this._rmsSum / (this.width * this.height)) : 0;
61
- }
62
- }, {
63
- key: "heightAt",
64
- value: function heightAt(x, y) {
65
- return this.data[this.width * y + x];
34
+ run() {
35
+ let maxError = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
36
+ while (this.getMaxError() > maxError) {
37
+ this.refine();
66
38
  }
67
- }, {
68
- key: "_flush",
69
- value: function _flush() {
70
- var coords = this.coords;
71
- for (var i = 0; i < this._pendingLen; i++) {
72
- var t = this._pending[i];
73
- var a = 2 * this.triangles[t * 3 + 0];
74
- var b = 2 * this.triangles[t * 3 + 1];
75
- var c = 2 * this.triangles[t * 3 + 2];
76
- this._findCandidate(coords[a], coords[a + 1], coords[b], coords[b + 1], coords[c], coords[c + 1], t);
77
- }
78
- this._pendingLen = 0;
79
- }
80
- }, {
81
- key: "_findCandidate",
82
- value: function _findCandidate(p0x, p0y, p1x, p1y, p2x, p2y, t) {
83
- var minX = Math.min(p0x, p1x, p2x);
84
- var minY = Math.min(p0y, p1y, p2y);
85
- var maxX = Math.max(p0x, p1x, p2x);
86
- var maxY = Math.max(p0y, p1y, p2y);
87
- var w00 = orient(p1x, p1y, p2x, p2y, minX, minY);
88
- var w01 = orient(p2x, p2y, p0x, p0y, minX, minY);
89
- var w02 = orient(p0x, p0y, p1x, p1y, minX, minY);
90
- var a01 = p1y - p0y;
91
- var b01 = p0x - p1x;
92
- var a12 = p2y - p1y;
93
- var b12 = p1x - p2x;
94
- var a20 = p0y - p2y;
95
- var b20 = p2x - p0x;
96
- var a = orient(p0x, p0y, p1x, p1y, p2x, p2y);
97
- var z0 = this.heightAt(p0x, p0y) / a;
98
- var z1 = this.heightAt(p1x, p1y) / a;
99
- var z2 = this.heightAt(p2x, p2y) / a;
100
- var maxError = 0;
101
- var mx = 0;
102
- var my = 0;
103
- var rms = 0;
104
- for (var y = minY; y <= maxY; y++) {
105
- var dx = 0;
106
- if (w00 < 0 && a12 !== 0) {
107
- dx = Math.max(dx, Math.floor(-w00 / a12));
108
- }
109
- if (w01 < 0 && a20 !== 0) {
110
- dx = Math.max(dx, Math.floor(-w01 / a20));
111
- }
112
- if (w02 < 0 && a01 !== 0) {
113
- dx = Math.max(dx, Math.floor(-w02 / a01));
114
- }
115
- var w0 = w00 + a12 * dx;
116
- var w1 = w01 + a20 * dx;
117
- var w2 = w02 + a01 * dx;
118
- var wasInside = false;
119
- for (var x = minX + dx; x <= maxX; x++) {
120
- if (w0 >= 0 && w1 >= 0 && w2 >= 0) {
121
- wasInside = true;
122
- var z = z0 * w0 + z1 * w1 + z2 * w2;
123
- var dz = Math.abs(z - this.heightAt(x, y));
124
- rms += dz * dz;
125
- if (dz > maxError) {
126
- maxError = dz;
127
- mx = x;
128
- my = y;
129
- }
130
- } else if (wasInside) {
131
- break;
132
- }
133
- w0 += a12;
134
- w1 += a20;
135
- w2 += a01;
136
- }
137
- w00 += b12;
138
- w01 += b20;
139
- w02 += b01;
140
- }
141
- if (mx === p0x && my === p0y || mx === p1x && my === p1y || mx === p2x && my === p2y) {
142
- maxError = 0;
143
- }
144
- this._candidates[2 * t] = mx;
145
- this._candidates[2 * t + 1] = my;
146
- this._rms[t] = rms;
147
- this._queuePush(t, maxError, rms);
39
+ }
40
+ refine() {
41
+ this._step();
42
+ this._flush();
43
+ }
44
+ getMaxError() {
45
+ return this._errors[0];
46
+ }
47
+ getRMSD() {
48
+ return this._rmsSum > 0 ? Math.sqrt(this._rmsSum / (this.width * this.height)) : 0;
49
+ }
50
+ heightAt(x, y) {
51
+ return this.data[this.width * y + x];
52
+ }
53
+ _flush() {
54
+ const coords = this.coords;
55
+ for (let i = 0; i < this._pendingLen; i++) {
56
+ const t = this._pending[i];
57
+ const a = 2 * this.triangles[t * 3 + 0];
58
+ const b = 2 * this.triangles[t * 3 + 1];
59
+ const c = 2 * this.triangles[t * 3 + 2];
60
+ this._findCandidate(coords[a], coords[a + 1], coords[b], coords[b + 1], coords[c], coords[c + 1], t);
148
61
  }
149
- }, {
150
- key: "_step",
151
- value: function _step() {
152
- var t = this._queuePop();
153
- var e0 = t * 3 + 0;
154
- var e1 = t * 3 + 1;
155
- var e2 = t * 3 + 2;
156
- var p0 = this.triangles[e0];
157
- var p1 = this.triangles[e1];
158
- var p2 = this.triangles[e2];
159
- var ax = this.coords[2 * p0];
160
- var ay = this.coords[2 * p0 + 1];
161
- var bx = this.coords[2 * p1];
162
- var by = this.coords[2 * p1 + 1];
163
- var cx = this.coords[2 * p2];
164
- var cy = this.coords[2 * p2 + 1];
165
- var px = this._candidates[2 * t];
166
- var py = this._candidates[2 * t + 1];
167
- var pn = this._addPoint(px, py);
168
- if (orient(ax, ay, bx, by, px, py) === 0) {
169
- this._handleCollinear(pn, e0);
170
- } else if (orient(bx, by, cx, cy, px, py) === 0) {
171
- this._handleCollinear(pn, e1);
172
- } else if (orient(cx, cy, ax, ay, px, py) === 0) {
173
- this._handleCollinear(pn, e2);
174
- } else {
175
- var h0 = this._halfedges[e0];
176
- var h1 = this._halfedges[e1];
177
- var h2 = this._halfedges[e2];
178
- var t0 = this._addTriangle(p0, p1, pn, h0, -1, -1, e0);
179
- var t1 = this._addTriangle(p1, p2, pn, h1, -1, t0 + 1);
180
- var t2 = this._addTriangle(p2, p0, pn, h2, t0 + 2, t1 + 1);
181
- this._legalize(t0);
182
- this._legalize(t1);
183
- this._legalize(t2);
62
+ this._pendingLen = 0;
63
+ }
64
+ _findCandidate(p0x, p0y, p1x, p1y, p2x, p2y, t) {
65
+ const minX = Math.min(p0x, p1x, p2x);
66
+ const minY = Math.min(p0y, p1y, p2y);
67
+ const maxX = Math.max(p0x, p1x, p2x);
68
+ const maxY = Math.max(p0y, p1y, p2y);
69
+ let w00 = orient(p1x, p1y, p2x, p2y, minX, minY);
70
+ let w01 = orient(p2x, p2y, p0x, p0y, minX, minY);
71
+ let w02 = orient(p0x, p0y, p1x, p1y, minX, minY);
72
+ const a01 = p1y - p0y;
73
+ const b01 = p0x - p1x;
74
+ const a12 = p2y - p1y;
75
+ const b12 = p1x - p2x;
76
+ const a20 = p0y - p2y;
77
+ const b20 = p2x - p0x;
78
+ const a = orient(p0x, p0y, p1x, p1y, p2x, p2y);
79
+ const z0 = this.heightAt(p0x, p0y) / a;
80
+ const z1 = this.heightAt(p1x, p1y) / a;
81
+ const z2 = this.heightAt(p2x, p2y) / a;
82
+ let maxError = 0;
83
+ let mx = 0;
84
+ let my = 0;
85
+ let rms = 0;
86
+ for (let y = minY; y <= maxY; y++) {
87
+ let dx = 0;
88
+ if (w00 < 0 && a12 !== 0) {
89
+ dx = Math.max(dx, Math.floor(-w00 / a12));
184
90
  }
185
- }
186
- }, {
187
- key: "_addPoint",
188
- value: function _addPoint(x, y) {
189
- var i = this.coords.length >> 1;
190
- this.coords.push(x, y);
191
- return i;
192
- }
193
- }, {
194
- key: "_addTriangle",
195
- value: function _addTriangle(a, b, c, ab, bc, ca) {
196
- var e = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : this.triangles.length;
197
- var t = e / 3;
198
- this.triangles[e + 0] = a;
199
- this.triangles[e + 1] = b;
200
- this.triangles[e + 2] = c;
201
- this._halfedges[e + 0] = ab;
202
- this._halfedges[e + 1] = bc;
203
- this._halfedges[e + 2] = ca;
204
- if (ab >= 0) {
205
- this._halfedges[ab] = e + 0;
91
+ if (w01 < 0 && a20 !== 0) {
92
+ dx = Math.max(dx, Math.floor(-w01 / a20));
206
93
  }
207
- if (bc >= 0) {
208
- this._halfedges[bc] = e + 1;
94
+ if (w02 < 0 && a01 !== 0) {
95
+ dx = Math.max(dx, Math.floor(-w02 / a01));
209
96
  }
210
- if (ca >= 0) {
211
- this._halfedges[ca] = e + 2;
97
+ let w0 = w00 + a12 * dx;
98
+ let w1 = w01 + a20 * dx;
99
+ let w2 = w02 + a01 * dx;
100
+ let wasInside = false;
101
+ for (let x = minX + dx; x <= maxX; x++) {
102
+ if (w0 >= 0 && w1 >= 0 && w2 >= 0) {
103
+ wasInside = true;
104
+ const z = z0 * w0 + z1 * w1 + z2 * w2;
105
+ const dz = Math.abs(z - this.heightAt(x, y));
106
+ rms += dz * dz;
107
+ if (dz > maxError) {
108
+ maxError = dz;
109
+ mx = x;
110
+ my = y;
111
+ }
112
+ } else if (wasInside) {
113
+ break;
114
+ }
115
+ w0 += a12;
116
+ w1 += a20;
117
+ w2 += a01;
212
118
  }
213
- this._candidates[2 * t + 0] = 0;
214
- this._candidates[2 * t + 1] = 0;
215
- this._queueIndices[t] = -1;
216
- this._rms[t] = 0;
217
- this._pending[this._pendingLen++] = t;
218
- return e;
119
+ w00 += b12;
120
+ w01 += b20;
121
+ w02 += b01;
219
122
  }
220
- }, {
221
- key: "_legalize",
222
- value: function _legalize(a) {
223
- var b = this._halfedges[a];
224
- if (b < 0) {
225
- return;
226
- }
227
- var a0 = a - a % 3;
228
- var b0 = b - b % 3;
229
- var al = a0 + (a + 1) % 3;
230
- var ar = a0 + (a + 2) % 3;
231
- var bl = b0 + (b + 2) % 3;
232
- var br = b0 + (b + 1) % 3;
233
- var p0 = this.triangles[ar];
234
- var pr = this.triangles[a];
235
- var pl = this.triangles[al];
236
- var p1 = this.triangles[bl];
237
- var coords = this.coords;
238
- if (!inCircle(coords[2 * p0], coords[2 * p0 + 1], coords[2 * pr], coords[2 * pr + 1], coords[2 * pl], coords[2 * pl + 1], coords[2 * p1], coords[2 * p1 + 1])) {
239
- return;
240
- }
241
- var hal = this._halfedges[al];
242
- var har = this._halfedges[ar];
243
- var hbl = this._halfedges[bl];
244
- var hbr = this._halfedges[br];
245
- this._queueRemove(a0 / 3);
246
- this._queueRemove(b0 / 3);
247
- var t0 = this._addTriangle(p0, p1, pl, -1, hbl, hal, a0);
248
- var t1 = this._addTriangle(p1, p0, pr, t0, har, hbr, b0);
249
- this._legalize(t0 + 1);
250
- this._legalize(t1 + 2);
123
+ if (mx === p0x && my === p0y || mx === p1x && my === p1y || mx === p2x && my === p2y) {
124
+ maxError = 0;
251
125
  }
252
- }, {
253
- key: "_handleCollinear",
254
- value: function _handleCollinear(pn, a) {
255
- var a0 = a - a % 3;
256
- var al = a0 + (a + 1) % 3;
257
- var ar = a0 + (a + 2) % 3;
258
- var p0 = this.triangles[ar];
259
- var pr = this.triangles[a];
260
- var pl = this.triangles[al];
261
- var hal = this._halfedges[al];
262
- var har = this._halfedges[ar];
263
- var b = this._halfedges[a];
264
- if (b < 0) {
265
- var _t = this._addTriangle(pn, p0, pr, -1, har, -1, a0);
266
- var _t2 = this._addTriangle(p0, pn, pl, _t, -1, hal);
267
- this._legalize(_t + 1);
268
- this._legalize(_t2 + 2);
269
- return;
270
- }
271
- var b0 = b - b % 3;
272
- var bl = b0 + (b + 2) % 3;
273
- var br = b0 + (b + 1) % 3;
274
- var p1 = this.triangles[bl];
275
- var hbl = this._halfedges[bl];
276
- var hbr = this._halfedges[br];
277
- this._queueRemove(b0 / 3);
278
- var t0 = this._addTriangle(p0, pr, pn, har, -1, -1, a0);
279
- var t1 = this._addTriangle(pr, p1, pn, hbr, -1, t0 + 1, b0);
280
- var t2 = this._addTriangle(p1, pl, pn, hbl, -1, t1 + 1);
281
- var t3 = this._addTriangle(pl, p0, pn, hal, t0 + 2, t2 + 1);
126
+ this._candidates[2 * t] = mx;
127
+ this._candidates[2 * t + 1] = my;
128
+ this._rms[t] = rms;
129
+ this._queuePush(t, maxError, rms);
130
+ }
131
+ _step() {
132
+ const t = this._queuePop();
133
+ const e0 = t * 3 + 0;
134
+ const e1 = t * 3 + 1;
135
+ const e2 = t * 3 + 2;
136
+ const p0 = this.triangles[e0];
137
+ const p1 = this.triangles[e1];
138
+ const p2 = this.triangles[e2];
139
+ const ax = this.coords[2 * p0];
140
+ const ay = this.coords[2 * p0 + 1];
141
+ const bx = this.coords[2 * p1];
142
+ const by = this.coords[2 * p1 + 1];
143
+ const cx = this.coords[2 * p2];
144
+ const cy = this.coords[2 * p2 + 1];
145
+ const px = this._candidates[2 * t];
146
+ const py = this._candidates[2 * t + 1];
147
+ const pn = this._addPoint(px, py);
148
+ if (orient(ax, ay, bx, by, px, py) === 0) {
149
+ this._handleCollinear(pn, e0);
150
+ } else if (orient(bx, by, cx, cy, px, py) === 0) {
151
+ this._handleCollinear(pn, e1);
152
+ } else if (orient(cx, cy, ax, ay, px, py) === 0) {
153
+ this._handleCollinear(pn, e2);
154
+ } else {
155
+ const h0 = this._halfedges[e0];
156
+ const h1 = this._halfedges[e1];
157
+ const h2 = this._halfedges[e2];
158
+ const t0 = this._addTriangle(p0, p1, pn, h0, -1, -1, e0);
159
+ const t1 = this._addTriangle(p1, p2, pn, h1, -1, t0 + 1);
160
+ const t2 = this._addTriangle(p2, p0, pn, h2, t0 + 2, t1 + 1);
282
161
  this._legalize(t0);
283
162
  this._legalize(t1);
284
163
  this._legalize(t2);
285
- this._legalize(t3);
286
164
  }
287
- }, {
288
- key: "_queuePush",
289
- value: function _queuePush(t, error, rms) {
290
- var i = this._queue.length;
291
- this._queueIndices[t] = i;
292
- this._queue.push(t);
293
- this._errors.push(error);
294
- this._rmsSum += rms;
295
- this._queueUp(i);
165
+ }
166
+ _addPoint(x, y) {
167
+ const i = this.coords.length >> 1;
168
+ this.coords.push(x, y);
169
+ return i;
170
+ }
171
+ _addTriangle(a, b, c, ab, bc, ca) {
172
+ let e = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : this.triangles.length;
173
+ const t = e / 3;
174
+ this.triangles[e + 0] = a;
175
+ this.triangles[e + 1] = b;
176
+ this.triangles[e + 2] = c;
177
+ this._halfedges[e + 0] = ab;
178
+ this._halfedges[e + 1] = bc;
179
+ this._halfedges[e + 2] = ca;
180
+ if (ab >= 0) {
181
+ this._halfedges[ab] = e + 0;
296
182
  }
297
- }, {
298
- key: "_queuePop",
299
- value: function _queuePop() {
300
- var n = this._queue.length - 1;
301
- this._queueSwap(0, n);
302
- this._queueDown(0, n);
303
- return this._queuePopBack();
183
+ if (bc >= 0) {
184
+ this._halfedges[bc] = e + 1;
304
185
  }
305
- }, {
306
- key: "_queuePopBack",
307
- value: function _queuePopBack() {
308
- var t = this._queue.pop();
309
- this._errors.pop();
310
- this._rmsSum -= this._rms[t];
311
- this._queueIndices[t] = -1;
312
- return t;
186
+ if (ca >= 0) {
187
+ this._halfedges[ca] = e + 2;
313
188
  }
314
- }, {
315
- key: "_queueRemove",
316
- value: function _queueRemove(t) {
317
- var i = this._queueIndices[t];
318
- if (i < 0) {
319
- var it = this._pending.indexOf(t);
320
- if (it !== -1) {
321
- this._pending[it] = this._pending[--this._pendingLen];
322
- } else {
323
- throw new Error('Broken triangulation (something went wrong).');
324
- }
325
- return;
326
- }
327
- var n = this._queue.length - 1;
328
- if (n !== i) {
329
- this._queueSwap(i, n);
330
- if (!this._queueDown(i, n)) {
331
- this._queueUp(i);
332
- }
333
- }
334
- this._queuePopBack();
189
+ this._candidates[2 * t + 0] = 0;
190
+ this._candidates[2 * t + 1] = 0;
191
+ this._queueIndices[t] = -1;
192
+ this._rms[t] = 0;
193
+ this._pending[this._pendingLen++] = t;
194
+ return e;
195
+ }
196
+ _legalize(a) {
197
+ const b = this._halfedges[a];
198
+ if (b < 0) {
199
+ return;
335
200
  }
336
- }, {
337
- key: "_queueLess",
338
- value: function _queueLess(i, j) {
339
- return this._errors[i] > this._errors[j];
201
+ const a0 = a - a % 3;
202
+ const b0 = b - b % 3;
203
+ const al = a0 + (a + 1) % 3;
204
+ const ar = a0 + (a + 2) % 3;
205
+ const bl = b0 + (b + 2) % 3;
206
+ const br = b0 + (b + 1) % 3;
207
+ const p0 = this.triangles[ar];
208
+ const pr = this.triangles[a];
209
+ const pl = this.triangles[al];
210
+ const p1 = this.triangles[bl];
211
+ const coords = this.coords;
212
+ if (!inCircle(coords[2 * p0], coords[2 * p0 + 1], coords[2 * pr], coords[2 * pr + 1], coords[2 * pl], coords[2 * pl + 1], coords[2 * p1], coords[2 * p1 + 1])) {
213
+ return;
340
214
  }
341
- }, {
342
- key: "_queueSwap",
343
- value: function _queueSwap(i, j) {
344
- var pi = this._queue[i];
345
- var pj = this._queue[j];
346
- this._queue[i] = pj;
347
- this._queue[j] = pi;
348
- this._queueIndices[pi] = j;
349
- this._queueIndices[pj] = i;
350
- var e = this._errors[i];
351
- this._errors[i] = this._errors[j];
352
- this._errors[j] = e;
215
+ const hal = this._halfedges[al];
216
+ const har = this._halfedges[ar];
217
+ const hbl = this._halfedges[bl];
218
+ const hbr = this._halfedges[br];
219
+ this._queueRemove(a0 / 3);
220
+ this._queueRemove(b0 / 3);
221
+ const t0 = this._addTriangle(p0, p1, pl, -1, hbl, hal, a0);
222
+ const t1 = this._addTriangle(p1, p0, pr, t0, har, hbr, b0);
223
+ this._legalize(t0 + 1);
224
+ this._legalize(t1 + 2);
225
+ }
226
+ _handleCollinear(pn, a) {
227
+ const a0 = a - a % 3;
228
+ const al = a0 + (a + 1) % 3;
229
+ const ar = a0 + (a + 2) % 3;
230
+ const p0 = this.triangles[ar];
231
+ const pr = this.triangles[a];
232
+ const pl = this.triangles[al];
233
+ const hal = this._halfedges[al];
234
+ const har = this._halfedges[ar];
235
+ const b = this._halfedges[a];
236
+ if (b < 0) {
237
+ const t0 = this._addTriangle(pn, p0, pr, -1, har, -1, a0);
238
+ const t1 = this._addTriangle(p0, pn, pl, t0, -1, hal);
239
+ this._legalize(t0 + 1);
240
+ this._legalize(t1 + 2);
241
+ return;
353
242
  }
354
- }, {
355
- key: "_queueUp",
356
- value: function _queueUp(j0) {
357
- var j = j0;
358
- while (true) {
359
- var i = j - 1 >> 1;
360
- if (i === j || !this._queueLess(j, i)) {
361
- break;
362
- }
363
- this._queueSwap(i, j);
364
- j = i;
243
+ const b0 = b - b % 3;
244
+ const bl = b0 + (b + 2) % 3;
245
+ const br = b0 + (b + 1) % 3;
246
+ const p1 = this.triangles[bl];
247
+ const hbl = this._halfedges[bl];
248
+ const hbr = this._halfedges[br];
249
+ this._queueRemove(b0 / 3);
250
+ const t0 = this._addTriangle(p0, pr, pn, har, -1, -1, a0);
251
+ const t1 = this._addTriangle(pr, p1, pn, hbr, -1, t0 + 1, b0);
252
+ const t2 = this._addTriangle(p1, pl, pn, hbl, -1, t1 + 1);
253
+ const t3 = this._addTriangle(pl, p0, pn, hal, t0 + 2, t2 + 1);
254
+ this._legalize(t0);
255
+ this._legalize(t1);
256
+ this._legalize(t2);
257
+ this._legalize(t3);
258
+ }
259
+ _queuePush(t, error, rms) {
260
+ const i = this._queue.length;
261
+ this._queueIndices[t] = i;
262
+ this._queue.push(t);
263
+ this._errors.push(error);
264
+ this._rmsSum += rms;
265
+ this._queueUp(i);
266
+ }
267
+ _queuePop() {
268
+ const n = this._queue.length - 1;
269
+ this._queueSwap(0, n);
270
+ this._queueDown(0, n);
271
+ return this._queuePopBack();
272
+ }
273
+ _queuePopBack() {
274
+ const t = this._queue.pop();
275
+ this._errors.pop();
276
+ this._rmsSum -= this._rms[t];
277
+ this._queueIndices[t] = -1;
278
+ return t;
279
+ }
280
+ _queueRemove(t) {
281
+ const i = this._queueIndices[t];
282
+ if (i < 0) {
283
+ const it = this._pending.indexOf(t);
284
+ if (it !== -1) {
285
+ this._pending[it] = this._pending[--this._pendingLen];
286
+ } else {
287
+ throw new Error('Broken triangulation (something went wrong).');
365
288
  }
289
+ return;
366
290
  }
367
- }, {
368
- key: "_queueDown",
369
- value: function _queueDown(i0, n) {
370
- var i = i0;
371
- while (true) {
372
- var j1 = 2 * i + 1;
373
- if (j1 >= n || j1 < 0) {
374
- break;
375
- }
376
- var j2 = j1 + 1;
377
- var j = j1;
378
- if (j2 < n && this._queueLess(j2, j1)) {
379
- j = j2;
380
- }
381
- if (!this._queueLess(j, i)) {
382
- break;
383
- }
384
- this._queueSwap(i, j);
385
- i = j;
291
+ const n = this._queue.length - 1;
292
+ if (n !== i) {
293
+ this._queueSwap(i, n);
294
+ if (!this._queueDown(i, n)) {
295
+ this._queueUp(i);
386
296
  }
387
- return i > i0;
388
297
  }
389
- }]);
390
- return Delatin;
391
- }();
298
+ this._queuePopBack();
299
+ }
300
+ _queueLess(i, j) {
301
+ return this._errors[i] > this._errors[j];
302
+ }
303
+ _queueSwap(i, j) {
304
+ const pi = this._queue[i];
305
+ const pj = this._queue[j];
306
+ this._queue[i] = pj;
307
+ this._queue[j] = pi;
308
+ this._queueIndices[pi] = j;
309
+ this._queueIndices[pj] = i;
310
+ const e = this._errors[i];
311
+ this._errors[i] = this._errors[j];
312
+ this._errors[j] = e;
313
+ }
314
+ _queueUp(j0) {
315
+ let j = j0;
316
+ while (true) {
317
+ const i = j - 1 >> 1;
318
+ if (i === j || !this._queueLess(j, i)) {
319
+ break;
320
+ }
321
+ this._queueSwap(i, j);
322
+ j = i;
323
+ }
324
+ }
325
+ _queueDown(i0, n) {
326
+ let i = i0;
327
+ while (true) {
328
+ const j1 = 2 * i + 1;
329
+ if (j1 >= n || j1 < 0) {
330
+ break;
331
+ }
332
+ const j2 = j1 + 1;
333
+ let j = j1;
334
+ if (j2 < n && this._queueLess(j2, j1)) {
335
+ j = j2;
336
+ }
337
+ if (!this._queueLess(j, i)) {
338
+ break;
339
+ }
340
+ this._queueSwap(i, j);
341
+ i = j;
342
+ }
343
+ return i > i0;
344
+ }
345
+ }
392
346
  exports.default = Delatin;
393
347
  function orient(ax, ay, bx, by, cx, cy) {
394
348
  return (bx - cx) * (ay - cy) - (by - cy) * (ax - cx);
395
349
  }
396
350
  function inCircle(ax, ay, bx, by, cx, cy, px, py) {
397
- var dx = ax - px;
398
- var dy = ay - py;
399
- var ex = bx - px;
400
- var ey = by - py;
401
- var fx = cx - px;
402
- var fy = cy - py;
403
- var ap = dx * dx + dy * dy;
404
- var bp = ex * ex + ey * ey;
405
- var cp = fx * fx + fy * fy;
351
+ const dx = ax - px;
352
+ const dy = ay - py;
353
+ const ex = bx - px;
354
+ const ey = by - py;
355
+ const fx = cx - px;
356
+ const fy = cy - py;
357
+ const ap = dx * dx + dy * dy;
358
+ const bp = ex * ex + ey * ey;
359
+ const cp = fx * fx + fy * fy;
406
360
  return dx * (ey * cp - bp * fy) - dy * (ex * cp - bp * fx) + ap * (ex * fy - ey * fx) < 0;
407
361
  }
408
362
  //# sourceMappingURL=index.js.map