@gisatcz/deckgl-geolib 1.12.0-dev.4 → 2.0.0

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.
Files changed (48) hide show
  1. package/README.md +67 -64
  2. package/dist/cjs/index.js +631 -641
  3. package/dist/cjs/index.js.map +1 -1
  4. package/dist/cjs/index.min.js +3 -3
  5. package/dist/cjs/index.min.js.map +1 -1
  6. package/dist/{esm/types/cogtiles/cogtiles.d.ts → cjs/types/core/CogTiles.d.ts} +12 -9
  7. package/dist/cjs/types/{geoimage/geoimage.d.ts → core/GeoImage.d.ts} +6 -6
  8. package/dist/cjs/types/core/index.d.ts +2 -0
  9. package/dist/cjs/types/index.d.ts +2 -11
  10. package/dist/{esm/types/cogbitmaplayer → cjs/types/layers}/CogBitmapLayer.d.ts +3 -5
  11. package/dist/cjs/types/{cogterrainlayer → layers}/CogTerrainLayer.d.ts +13 -8
  12. package/dist/cjs/types/layers/index.d.ts +2 -0
  13. package/dist/esm/index.js +628 -641
  14. package/dist/esm/index.js.map +1 -1
  15. package/dist/esm/index.min.js +3 -3
  16. package/dist/esm/index.min.js.map +1 -1
  17. package/dist/{cjs/types/cogtiles/cogtiles.d.ts → esm/types/core/CogTiles.d.ts} +12 -9
  18. package/dist/esm/types/{geoimage/geoimage.d.ts → core/GeoImage.d.ts} +6 -6
  19. package/dist/esm/types/core/index.d.ts +2 -0
  20. package/dist/esm/types/index.d.ts +2 -11
  21. package/dist/{cjs/types/cogbitmaplayer → esm/types/layers}/CogBitmapLayer.d.ts +3 -5
  22. package/dist/esm/types/{cogterrainlayer → layers}/CogTerrainLayer.d.ts +13 -8
  23. package/dist/esm/types/layers/index.d.ts +2 -0
  24. package/package.json +40 -4
  25. package/.eslintignore +0 -2
  26. package/.eslintrc.cjs +0 -3
  27. package/CHANGELOG.md +0 -166
  28. package/rollup.config.mjs +0 -77
  29. package/src/cogbitmaplayer/CogBitmapLayer.ts +0 -337
  30. package/src/cogbitmaplayer/README.md +0 -113
  31. package/src/cogterrainlayer/CogTerrainLayer.ts +0 -445
  32. package/src/cogterrainlayer/README.md +0 -118
  33. package/src/cogtiles/README.md +0 -72
  34. package/src/cogtiles/cogtiles.ts +0 -420
  35. package/src/cogtiles/lzw.js +0 -256
  36. package/src/geoimage/README.md +0 -129
  37. package/src/geoimage/delatin/index.ts +0 -495
  38. package/src/geoimage/geoimage.ts +0 -599
  39. package/src/geoimage/helpers/skirt.ts +0 -171
  40. package/src/index.ts +0 -11
  41. package/src/utilities/tileurls.ts +0 -21
  42. package/tsconfig.json +0 -6
  43. /package/dist/cjs/types/{geoimage → core}/delatin/index.d.ts +0 -0
  44. /package/dist/cjs/types/{geoimage → core}/helpers/skirt.d.ts +0 -0
  45. /package/dist/cjs/types/{utilities → utils}/tileurls.d.ts +0 -0
  46. /package/dist/esm/types/{geoimage → core}/delatin/index.d.ts +0 -0
  47. /package/dist/esm/types/{geoimage → core}/helpers/skirt.d.ts +0 -0
  48. /package/dist/esm/types/{utilities → utils}/tileurls.d.ts +0 -0
@@ -1,129 +0,0 @@
1
- # Geoimage
2
- ##### A Javascript library for rendering bitmaps and terrain out of **geoTIFF** files.
3
- <img src = "/images/example0crop1.png" width = "100%">
4
-
5
- ### Features
6
- ##### Color texture generation
7
- - Create RGB pictures out of RGB geoTIFF data.
8
- - Generate pictures out of non-RGB geoTIFF data with different processing options.
9
-
10
- ##### Terrain texture generation
11
- - Generate heightmaps out of single-channel geoTIFF elevation data.
12
- - Create tiled mesh layer which represents height values fron geoTIFF without any compression to height PNG.
13
- - Created mesh is TIN generated by [martini algorithm](https://github.com/mapbox/martini).
14
-
15
-
16
- ##### Data visualisation options
17
- - Color
18
- - Transparency
19
- - Heatmap (custom color scale example [here](../cogbitmaplayer/README.md#custom-heatmap-color-scale))
20
- - Data slice
21
- - Automatic data range
22
- - Manual data range
23
- - Assign color to specific data value (example [here](../cogbitmaplayer/README.md#assigning-color-to-specific-data-value))
24
-
25
- ### Data processing options
26
- - `useAutoRange : boolean` - set automatic range of color gradient **(default false)**
27
- - `useDataForOpacity : boolean` - visualise data with opacity of each pixel according to its value **(default false)**
28
- - `alpha : number` - visualise entire image with specified opacity **(if useDataOpacity is false)**, values 0-100 **(default 100)**
29
- - `useHeatMap : boolean` - generate data as a color heatmap **(default true)**
30
- - `useChannel : number | null` - specify a single channel to use; first channel is equal to 1, etc... for RGB(A) imagery leave it to `null` **(default null)**
31
- - `multiplier : number ` - multiplies each value **(default 1.00)**
32
- - `clipLow : number | null`- generate only data greater than this **(default null)**
33
-
34
- - `clipHigh : number | null`- generate only data less than this **(default null)**
35
- - `clippedColor: chroma.Color` - set color for clipped values when using `clipLow` or `clipHigh`, **(default [0, 0, 0, 0])**
36
- - `colorScale:chroma.Color[]` - array of colors, supports chroma.js color definition (more below)
37
- - `colorScaleValueRange: number[]` - set min and max range values or set any array of values to set exact colors to values, **if useAutoRange is false**, **(default [0,255])**
38
- - `useColorsBasedOnValues: boolean` - assign pixels colors based on defined data values **(default false)**
39
- - `colorsBasedOnValues : [number, chroma.Color][]` - array of value-color pairs, used **if useColorsBasedOnValues is true**, supports chroma.js color definition such as `'red'`, `[255,0,0]`, `'#FF0000'`, etc.
40
- - `useColorClasses: boolean` - determines whether pixel colors are assigned based on predefined data classes (intervals) **(default false)**
41
- - `colorClasses : [chroma.Color, [number, number], [boolean, boolean]?][]` - array of color-interval(-intervalBounds) triples, where the color is defined as chroma.js color; interval is defined as [min, max] array; and optional inteval bound as [boolean, boolean] array (default is [true, false] for all intervals except the last one which is [false, true]; used **if useColorClasses is true**, the values that don't belong to any interval are visualized as `unidentifiedColor`
42
- - `unidentifiedColor: chroma.Color` - set color for not identified values **if useColorsBasedOnValues or useColorClasses is true**, **(default [0, 0, 0, 0])**
43
- - `nullColor : chroma.Color` - set color for noData values **(default [0, 0, 0, 0])**
44
- - `useSingleColor : boolean` - display data values only with single color **(default false)**
45
- - `color : chroma.Color` - set color when **if useSingleColor is true**, **(default [255, 0, 255, 255])**
46
- - `blurredTexture : boolean` - define blurring behaviour for textures when zoomed in = magnification filter parameter (`gl.TEXTURE_MAG_FILTER`). Default is `true` for blurry textures (corresponds to `GL.LINEAR`), to not blur textures use `false` (corresponds to `GL.NEAREST`)
47
-
48
- #### Chroma.Color definition
49
- Type `chroma.Color` means any color definition that is supported by chroma.js such as `'red'`, `[255,0,0]`, `[255,0,0, 180]`, `'#FF0000'`,
50
- etc. and [Color Brewer pallete names](https://www.datanovia.com/en/wp-content/uploads/dn-tutorials/ggplot2/figures/0101-rcolorbrewer-palette-rcolorbrewer-palettes-colorblind-friendly-1.png)
51
- in this format: `chroma.brewer.Greens`
52
-
53
- #### Additional terrain processing options
54
- - `terrainMinValue: number` - noData value retrieved from input file's metadata is substitute by this value **(default 0)**
55
- - `terrainSkirtHeight: number` - defines height of individual tiles edges, so there are no white spaces between individual 3D tiles **(default 100)**
56
-
57
- [//]: # (- `terrainColor: chroma.Color` - color of terrain model **&#40;default [133, 133, 133, 255]&#41;**)
58
-
59
- - Setting **opacity for terrain layers**: Terrayin layer is ordinary Deck.gl layer instance, so opacity is common prop.
60
-
61
- ### Return options
62
- **Method returns Image DataUrl**
63
-
64
- - `getMap(returnFormat : "image" | "terrain", input : string | { width : number, height : number, rasters : any[] }, options?: { opacity : number })`
65
-
66
- If `returnFormat` = `"image"` - If the input has 3 or 4 color channels, return standard RGB or RGBA image. If the input has 1 channel, data gets processed according to data processing options.
67
-
68
- If `returnFormat` = `"terrain"` - Ignores all options except `multiplier` and returns [Mapbox Terrain-RGB](https://docs.mapbox.com/data/tilesets/guides/access-elevation-data/#decode-data)
69
-
70
- ### Basic example
71
- ##### Initialize the library
72
- ```typescript
73
- import GeoImage from 'geoimage';
74
-
75
- const g = new GeoImage();
76
- ```
77
- ##### Get bitmap
78
- ```typescript
79
- const bitmap = await g.getMap("image", 'image.tif');
80
- ```
81
- ```typescript
82
- const bitmap = await g.getMap("image", { width : 512, height : 512, rasters : [[...data]] });
83
- ```
84
-
85
-
86
-
87
- ##### Get heightmap
88
-
89
- ```typescript
90
- const heightmap = await g.getMap("terrain", 'image.tif');
91
- ```
92
- ```typescript
93
- const bitmap = await g.getMap("terrain", { width : 512, height : 512, rasters : [[...data]] });
94
- ```
95
-
96
- ### Advanced example
97
-
98
- ```typescript
99
- //Import the library and initiate GeoImage object:
100
- import GeoImage from 'geoimage';
101
-
102
- const g = new GeoImage();
103
-
104
- //Single-channel geotiff as a transparent heatmap with auto-rage:
105
- g.useAutoRange(true);
106
- g.useHeatMap(true);
107
- g.alpha(100);
108
- const firstImage = await g.getMap("image", 'image.tif');
109
-
110
- //Single-channel geotiff as a transparent heatmap with manual range in meters:
111
- g.useAutoRange(false);
112
- g.useDataRange(0,250); //Blue at 0m, red at 250m
113
- g.useHeatMap(true);
114
- g.alpha(80);
115
- const secondImage = await g.getBitmap("image", 'image.tif');
116
-
117
- //Single-channel geotiff with data as transparency:
118
- g.useAutoRange(true);
119
- g.useHeatMap(false);
120
- g.useDataForOpacity(true);
121
- const thirdImage = await g.getBitmap("image", 'image.tif');
122
-
123
- //Single-channel geotiff with data slice from 350m to 360m in custom color:
124
- g.clipLow(350); //generate only data between 350m and 360m
125
- g.clipHigh(360);
126
- g.useHeatMap(false);
127
- g.color[0,255,100];
128
- const fourthImage = await g.getBitmap("image", 'image.tif');
129
- ```
@@ -1,495 +0,0 @@
1
- // loaders.gl
2
- // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
4
-
5
- // ISC License
6
- // Copyright(c) 2019, Michael Fogleman, Vladimir Agafonkin
7
-
8
- // @ts-nocheck
9
-
10
- /* eslint-disable complexity, max-params, max-statements, max-depth, no-constant-condition */
11
- export default class Delatin {
12
- constructor(data, width, height = width) {
13
- this.data = data; // height data
14
- this.width = width;
15
- this.height = height;
16
-
17
- this.coords = []; // vertex coordinates (x, y)
18
- this.triangles = []; // mesh triangle indices
19
-
20
- // additional triangle data
21
- this._halfedges = [];
22
- this._candidates = [];
23
- this._queueIndices = [];
24
-
25
- this._queue = []; // queue of added triangles
26
- this._errors = [];
27
- this._rms = [];
28
- this._pending = []; // triangles pending addition to queue
29
- this._pendingLen = 0;
30
-
31
- this._rmsSum = 0;
32
-
33
- const x1 = width - 1;
34
- const y1 = height - 1;
35
- const p0 = this._addPoint(0, 0);
36
- const p1 = this._addPoint(x1, 0);
37
- const p2 = this._addPoint(0, y1);
38
- const p3 = this._addPoint(x1, y1);
39
-
40
- // add initial two triangles
41
- const t0 = this._addTriangle(p3, p0, p2, -1, -1, -1);
42
- this._addTriangle(p0, p3, p1, t0, -1, -1);
43
- this._flush();
44
- }
45
-
46
- // refine the mesh until its maximum error gets below the given one
47
- run(maxError = 1) {
48
- while (this.getMaxError() > maxError) {
49
- this.refine();
50
- }
51
- }
52
-
53
- // refine the mesh with a single point
54
- refine() {
55
- this._step();
56
- this._flush();
57
- }
58
-
59
- // max error of the current mesh
60
- getMaxError() {
61
- return this._errors[0];
62
- }
63
-
64
- // root-mean-square deviation of the current mesh
65
- getRMSD() {
66
- return this._rmsSum > 0 ? Math.sqrt(this._rmsSum / (this.width * this.height)) : 0;
67
- }
68
-
69
- // height value at a given position
70
- heightAt(x, y) {
71
- return this.data[this.width * y + x];
72
- }
73
-
74
- // rasterize and queue all triangles that got added or updated in _step
75
- _flush() {
76
- const { coords } = this;
77
- for (let i = 0; i < this._pendingLen; i++) {
78
- const t = this._pending[i];
79
- // rasterize triangle to find maximum pixel error
80
- const a = 2 * this.triangles[t * 3 + 0];
81
- const b = 2 * this.triangles[t * 3 + 1];
82
- const c = 2 * this.triangles[t * 3 + 2];
83
- this._findCandidate(
84
- coords[a],
85
- coords[a + 1],
86
- coords[b],
87
- coords[b + 1],
88
- coords[c],
89
- coords[c + 1],
90
- t,
91
- );
92
- }
93
- this._pendingLen = 0;
94
- }
95
-
96
- // rasterize a triangle, find its max error, and queue it for processing
97
- _findCandidate(p0x, p0y, p1x, p1y, p2x, p2y, t) {
98
- // triangle bounding box
99
- const minX = Math.min(p0x, p1x, p2x);
100
- const minY = Math.min(p0y, p1y, p2y);
101
- const maxX = Math.max(p0x, p1x, p2x);
102
- const maxY = Math.max(p0y, p1y, p2y);
103
-
104
- // forward differencing variables
105
- let w00 = orient(p1x, p1y, p2x, p2y, minX, minY);
106
- let w01 = orient(p2x, p2y, p0x, p0y, minX, minY);
107
- let w02 = orient(p0x, p0y, p1x, p1y, minX, minY);
108
- const a01 = p1y - p0y;
109
- const b01 = p0x - p1x;
110
- const a12 = p2y - p1y;
111
- const b12 = p1x - p2x;
112
- const a20 = p0y - p2y;
113
- const b20 = p2x - p0x;
114
-
115
- // pre-multiplied z values at vertices
116
- const a = orient(p0x, p0y, p1x, p1y, p2x, p2y);
117
- const z0 = this.heightAt(p0x, p0y) / a;
118
- const z1 = this.heightAt(p1x, p1y) / a;
119
- const z2 = this.heightAt(p2x, p2y) / a;
120
-
121
- // iterate over pixels in bounding box
122
- let maxError = 0;
123
- let mx = 0;
124
- let my = 0;
125
- let rms = 0;
126
- for (let y = minY; y <= maxY; y++) {
127
- // compute starting offset
128
- let dx = 0;
129
- if (w00 < 0 && a12 !== 0) {
130
- dx = Math.max(dx, Math.floor(-w00 / a12));
131
- }
132
- if (w01 < 0 && a20 !== 0) {
133
- dx = Math.max(dx, Math.floor(-w01 / a20));
134
- }
135
- if (w02 < 0 && a01 !== 0) {
136
- dx = Math.max(dx, Math.floor(-w02 / a01));
137
- }
138
-
139
- let w0 = w00 + a12 * dx;
140
- let w1 = w01 + a20 * dx;
141
- let w2 = w02 + a01 * dx;
142
-
143
- let wasInside = false;
144
-
145
- for (let x = minX + dx; x <= maxX; x++) {
146
- // check if inside triangle
147
- if (w0 >= 0 && w1 >= 0 && w2 >= 0) {
148
- wasInside = true;
149
-
150
- // compute z using barycentric coordinates
151
- const z = z0 * w0 + z1 * w1 + z2 * w2;
152
- const dz = Math.abs(z - this.heightAt(x, y));
153
- rms += dz * dz;
154
- if (dz > maxError) {
155
- maxError = dz;
156
- mx = x;
157
- my = y;
158
- }
159
- } else if (wasInside) {
160
- break;
161
- }
162
-
163
- w0 += a12;
164
- w1 += a20;
165
- w2 += a01;
166
- }
167
-
168
- w00 += b12;
169
- w01 += b20;
170
- w02 += b01;
171
- }
172
-
173
- if ((mx === p0x && my === p0y) || (mx === p1x && my === p1y) || (mx === p2x && my === p2y)) {
174
- maxError = 0;
175
- }
176
-
177
- // update triangle metadata
178
- this._candidates[2 * t] = mx;
179
- this._candidates[2 * t + 1] = my;
180
- this._rms[t] = rms;
181
-
182
- // add triangle to priority queue
183
- this._queuePush(t, maxError, rms);
184
- }
185
-
186
- // process the next triangle in the queue, splitting it with a new point
187
- _step() {
188
- // pop triangle with highest error from priority queue
189
- const t = this._queuePop();
190
-
191
- const e0 = t * 3 + 0;
192
- const e1 = t * 3 + 1;
193
- const e2 = t * 3 + 2;
194
-
195
- const p0 = this.triangles[e0];
196
- const p1 = this.triangles[e1];
197
- const p2 = this.triangles[e2];
198
-
199
- const ax = this.coords[2 * p0];
200
- const ay = this.coords[2 * p0 + 1];
201
- const bx = this.coords[2 * p1];
202
- const by = this.coords[2 * p1 + 1];
203
- const cx = this.coords[2 * p2];
204
- const cy = this.coords[2 * p2 + 1];
205
- const px = this._candidates[2 * t];
206
- const py = this._candidates[2 * t + 1];
207
-
208
- const pn = this._addPoint(px, py);
209
-
210
- if (orient(ax, ay, bx, by, px, py) === 0) {
211
- this._handleCollinear(pn, e0);
212
- } else if (orient(bx, by, cx, cy, px, py) === 0) {
213
- this._handleCollinear(pn, e1);
214
- } else if (orient(cx, cy, ax, ay, px, py) === 0) {
215
- this._handleCollinear(pn, e2);
216
- } else {
217
- const h0 = this._halfedges[e0];
218
- const h1 = this._halfedges[e1];
219
- const h2 = this._halfedges[e2];
220
-
221
- const t0 = this._addTriangle(p0, p1, pn, h0, -1, -1, e0);
222
- const t1 = this._addTriangle(p1, p2, pn, h1, -1, t0 + 1);
223
- const t2 = this._addTriangle(p2, p0, pn, h2, t0 + 2, t1 + 1);
224
-
225
- this._legalize(t0);
226
- this._legalize(t1);
227
- this._legalize(t2);
228
- }
229
- }
230
-
231
- // add coordinates for a new vertex
232
- _addPoint(x, y) {
233
- const i = this.coords.length >> 1;
234
- this.coords.push(x, y);
235
- return i;
236
- }
237
-
238
- // add or update a triangle in the mesh
239
- _addTriangle(a, b, c, ab, bc, ca, e = this.triangles.length) {
240
- const t = e / 3; // new triangle index
241
-
242
- // add triangle vertices
243
- this.triangles[e + 0] = a;
244
- this.triangles[e + 1] = b;
245
- this.triangles[e + 2] = c;
246
-
247
- // add triangle halfedges
248
- this._halfedges[e + 0] = ab;
249
- this._halfedges[e + 1] = bc;
250
- this._halfedges[e + 2] = ca;
251
-
252
- // link neighboring halfedges
253
- if (ab >= 0) {
254
- this._halfedges[ab] = e + 0;
255
- }
256
- if (bc >= 0) {
257
- this._halfedges[bc] = e + 1;
258
- }
259
- if (ca >= 0) {
260
- this._halfedges[ca] = e + 2;
261
- }
262
-
263
- // init triangle metadata
264
- this._candidates[2 * t + 0] = 0;
265
- this._candidates[2 * t + 1] = 0;
266
- this._queueIndices[t] = -1;
267
- this._rms[t] = 0;
268
-
269
- // add triangle to pending queue for later rasterization
270
- this._pending[this._pendingLen++] = t;
271
-
272
- // return first halfedge index
273
- return e;
274
- }
275
-
276
- _legalize(a) {
277
- // if the pair of triangles doesn't satisfy the Delaunay condition
278
- // (p1 is inside the circumcircle of [p0, pl, pr]), flip them,
279
- // then do the same check/flip recursively for the new pair of triangles
280
- //
281
- // pl pl
282
- // /||\ / \
283
- // al/ || \bl al/ \a
284
- // / || \ / \
285
- // / a||b \ flip /___ar___\
286
- // p0\ || /p1 => p0\---bl---/p1
287
- // \ || / \ /
288
- // ar\ || /br b\ /br
289
- // \||/ \ /
290
- // pr pr
291
-
292
- const b = this._halfedges[a];
293
-
294
- if (b < 0) {
295
- return;
296
- }
297
-
298
- const a0 = a - (a % 3);
299
- const b0 = b - (b % 3);
300
- const al = a0 + ((a + 1) % 3);
301
- const ar = a0 + ((a + 2) % 3);
302
- const bl = b0 + ((b + 2) % 3);
303
- const br = b0 + ((b + 1) % 3);
304
- const p0 = this.triangles[ar];
305
- const pr = this.triangles[a];
306
- const pl = this.triangles[al];
307
- const p1 = this.triangles[bl];
308
- const { coords } = this;
309
-
310
- if (
311
- !inCircle(
312
- coords[2 * p0],
313
- coords[2 * p0 + 1],
314
- coords[2 * pr],
315
- coords[2 * pr + 1],
316
- coords[2 * pl],
317
- coords[2 * pl + 1],
318
- coords[2 * p1],
319
- coords[2 * p1 + 1],
320
- )
321
- ) {
322
- return;
323
- }
324
-
325
- const hal = this._halfedges[al];
326
- const har = this._halfedges[ar];
327
- const hbl = this._halfedges[bl];
328
- const hbr = this._halfedges[br];
329
-
330
- this._queueRemove(a0 / 3);
331
- this._queueRemove(b0 / 3);
332
-
333
- const t0 = this._addTriangle(p0, p1, pl, -1, hbl, hal, a0);
334
- const t1 = this._addTriangle(p1, p0, pr, t0, har, hbr, b0);
335
-
336
- this._legalize(t0 + 1);
337
- this._legalize(t1 + 2);
338
- }
339
-
340
- // handle a case where new vertex is on the edge of a triangle
341
- _handleCollinear(pn, a) {
342
- const a0 = a - (a % 3);
343
- const al = a0 + ((a + 1) % 3);
344
- const ar = a0 + ((a + 2) % 3);
345
- const p0 = this.triangles[ar];
346
- const pr = this.triangles[a];
347
- const pl = this.triangles[al];
348
- const hal = this._halfedges[al];
349
- const har = this._halfedges[ar];
350
-
351
- const b = this._halfedges[a];
352
-
353
- if (b < 0) {
354
- const t0 = this._addTriangle(pn, p0, pr, -1, har, -1, a0);
355
- const t1 = this._addTriangle(p0, pn, pl, t0, -1, hal);
356
- this._legalize(t0 + 1);
357
- this._legalize(t1 + 2);
358
- return;
359
- }
360
-
361
- const b0 = b - (b % 3);
362
- const bl = b0 + ((b + 2) % 3);
363
- const br = b0 + ((b + 1) % 3);
364
- const p1 = this.triangles[bl];
365
- const hbl = this._halfedges[bl];
366
- const hbr = this._halfedges[br];
367
-
368
- this._queueRemove(b0 / 3);
369
-
370
- const t0 = this._addTriangle(p0, pr, pn, har, -1, -1, a0);
371
- const t1 = this._addTriangle(pr, p1, pn, hbr, -1, t0 + 1, b0);
372
- const t2 = this._addTriangle(p1, pl, pn, hbl, -1, t1 + 1);
373
- const t3 = this._addTriangle(pl, p0, pn, hal, t0 + 2, t2 + 1);
374
-
375
- this._legalize(t0);
376
- this._legalize(t1);
377
- this._legalize(t2);
378
- this._legalize(t3);
379
- }
380
-
381
- // priority queue methods
382
-
383
- _queuePush(t, error, rms) {
384
- const i = this._queue.length;
385
- this._queueIndices[t] = i;
386
- this._queue.push(t);
387
- this._errors.push(error);
388
- this._rmsSum += rms;
389
- this._queueUp(i);
390
- }
391
-
392
- _queuePop() {
393
- const n = this._queue.length - 1;
394
- this._queueSwap(0, n);
395
- this._queueDown(0, n);
396
- return this._queuePopBack();
397
- }
398
-
399
- _queuePopBack() {
400
- const t = this._queue.pop();
401
- this._errors.pop();
402
- this._rmsSum -= this._rms[t];
403
- this._queueIndices[t] = -1;
404
- return t;
405
- }
406
-
407
- _queueRemove(t) {
408
- const i = this._queueIndices[t];
409
- if (i < 0) {
410
- const it = this._pending.indexOf(t);
411
- if (it !== -1) {
412
- this._pending[it] = this._pending[--this._pendingLen];
413
- } else {
414
- throw new Error('Broken triangulation (something went wrong).');
415
- }
416
- return;
417
- }
418
- const n = this._queue.length - 1;
419
- if (n !== i) {
420
- this._queueSwap(i, n);
421
- if (!this._queueDown(i, n)) {
422
- this._queueUp(i);
423
- }
424
- }
425
- this._queuePopBack();
426
- }
427
-
428
- _queueLess(i, j) {
429
- return this._errors[i] > this._errors[j];
430
- }
431
-
432
- _queueSwap(i, j) {
433
- const pi = this._queue[i];
434
- const pj = this._queue[j];
435
- this._queue[i] = pj;
436
- this._queue[j] = pi;
437
- this._queueIndices[pi] = j;
438
- this._queueIndices[pj] = i;
439
- const e = this._errors[i];
440
- this._errors[i] = this._errors[j];
441
- this._errors[j] = e;
442
- }
443
-
444
- _queueUp(j0) {
445
- let j = j0;
446
- while (true) {
447
- const i = (j - 1) >> 1;
448
- if (i === j || !this._queueLess(j, i)) {
449
- break;
450
- }
451
- this._queueSwap(i, j);
452
- j = i;
453
- }
454
- }
455
-
456
- _queueDown(i0, n) {
457
- let i = i0;
458
- while (true) {
459
- const j1 = 2 * i + 1;
460
- if (j1 >= n || j1 < 0) {
461
- break;
462
- }
463
- const j2 = j1 + 1;
464
- let j = j1;
465
- if (j2 < n && this._queueLess(j2, j1)) {
466
- j = j2;
467
- }
468
- if (!this._queueLess(j, i)) {
469
- break;
470
- }
471
- this._queueSwap(i, j);
472
- i = j;
473
- }
474
- return i > i0;
475
- }
476
- }
477
-
478
- function orient(ax, ay, bx, by, cx, cy) {
479
- return (bx - cx) * (ay - cy) - (by - cy) * (ax - cx);
480
- }
481
-
482
- function inCircle(ax, ay, bx, by, cx, cy, px, py) {
483
- const dx = ax - px;
484
- const dy = ay - py;
485
- const ex = bx - px;
486
- const ey = by - py;
487
- const fx = cx - px;
488
- const fy = cy - py;
489
-
490
- const ap = dx * dx + dy * dy;
491
- const bp = ex * ex + ey * ey;
492
- const cp = fx * fx + fy * fy;
493
-
494
- return dx * (ey * cp - bp * fy) - dy * (ex * cp - bp * fx) + ap * (ex * fy - ey * fx) < 0;
495
- }