@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.
- package/dist/es5/bundle.js +1 -1
- package/dist/es5/bundle.js.map +1 -1
- package/dist/es5/index.js +11 -30
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/lib/decode-quantized-mesh.js +105 -116
- package/dist/es5/lib/decode-quantized-mesh.js.map +1 -1
- package/dist/es5/lib/delatin/index.js +309 -355
- package/dist/es5/lib/delatin/index.js.map +1 -1
- package/dist/es5/lib/helpers/skirt.js +40 -50
- package/dist/es5/lib/helpers/skirt.js.map +1 -1
- package/dist/es5/lib/parse-quantized-mesh.js +43 -45
- package/dist/es5/lib/parse-quantized-mesh.js.map +1 -1
- package/dist/es5/lib/parse-terrain.js +82 -97
- package/dist/es5/lib/parse-terrain.js.map +1 -1
- package/dist/es5/lib/utils/version.js +1 -1
- package/dist/es5/lib/utils/version.js.map +1 -1
- package/dist/es5/quantized-mesh-loader.js +2 -2
- package/dist/es5/quantized-mesh-loader.js.map +1 -1
- package/dist/es5/terrain-loader.js +2 -2
- package/dist/es5/terrain-loader.js.map +1 -1
- package/dist/esm/lib/utils/version.js +1 -1
- package/dist/quantized-mesh-worker.js +1 -1
- package/dist/terrain-worker.js +1 -1
- package/package.json +5 -5
|
@@ -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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
(
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
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 (
|
|
208
|
-
|
|
94
|
+
if (w02 < 0 && a01 !== 0) {
|
|
95
|
+
dx = Math.max(dx, Math.floor(-w02 / a01));
|
|
209
96
|
}
|
|
210
|
-
|
|
211
|
-
|
|
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
|
-
|
|
214
|
-
|
|
215
|
-
|
|
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
|
-
|
|
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
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
this.
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
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
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
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
|
-
|
|
338
|
-
|
|
339
|
-
|
|
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
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
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
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
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
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
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
|
-
|
|
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
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
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
|