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