plotboilerplate 1.21.0 → 1.22.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 (58) hide show
  1. package/dist/index.esm.js +30 -1
  2. package/dist/index.esm.js.map +1 -1
  3. package/dist/index.esm.min.js +1 -1
  4. package/dist/index.esm.min.js.map +1 -1
  5. package/dist/plotboilerplate.browser.min.js +1 -1
  6. package/dist/plotboilerplate.browser.min.js.map +1 -1
  7. package/dist/plotboilerplate.js +30 -1
  8. package/dist/plotboilerplate.min.js +1 -1
  9. package/package.json +3 -2
  10. package/src/cjs/Polygon.d.ts +13 -1
  11. package/src/cjs/Polygon.js +30 -1
  12. package/src/cjs/Polygon.js.map +1 -1
  13. package/src/cjs/utils/Params.d.ts +15 -0
  14. package/src/cjs/utils/Params.js +49 -0
  15. package/src/cjs/utils/Params.js.map +1 -0
  16. package/src/cjs/utils/algorithms/ContourLineDetection.d.ts +150 -0
  17. package/src/cjs/utils/algorithms/ContourLineDetection.js +367 -0
  18. package/src/cjs/utils/algorithms/ContourLineDetection.js.map +1 -0
  19. package/src/cjs/utils/algorithms/clearDuplicateVertices.d.ts +21 -0
  20. package/src/cjs/utils/algorithms/clearDuplicateVertices.js +48 -0
  21. package/src/cjs/utils/algorithms/clearDuplicateVertices.js.map +1 -0
  22. package/src/cjs/utils/datastructures/DataGrid2d.d.ts +47 -0
  23. package/src/cjs/utils/datastructures/DataGrid2d.js +20 -0
  24. package/src/cjs/utils/datastructures/DataGrid2d.js.map +1 -0
  25. package/src/cjs/utils/datastructures/DataGrid2dListAdapter.d.ts +65 -0
  26. package/src/cjs/utils/datastructures/DataGrid2dListAdapter.js +84 -0
  27. package/src/cjs/utils/datastructures/DataGrid2dListAdapter.js.map +1 -0
  28. package/src/cjs/utils/datastructures/GenericPath.d.ts +14 -3
  29. package/src/cjs/utils/datastructures/GenericPath.js +20 -3
  30. package/src/cjs/utils/datastructures/GenericPath.js.map +1 -1
  31. package/src/esm/Polygon.d.ts +13 -1
  32. package/src/esm/Polygon.js +30 -1
  33. package/src/esm/Polygon.js.map +1 -1
  34. package/src/esm/utils/Params.d.ts +15 -0
  35. package/src/esm/utils/Params.js +44 -0
  36. package/src/esm/utils/Params.js.map +1 -0
  37. package/src/esm/utils/algorithms/ContourLineDetection.d.ts +150 -0
  38. package/src/esm/utils/algorithms/ContourLineDetection.js +362 -0
  39. package/src/esm/utils/algorithms/ContourLineDetection.js.map +1 -0
  40. package/src/esm/utils/algorithms/clearDuplicateVertices.d.ts +21 -0
  41. package/src/esm/utils/algorithms/clearDuplicateVertices.js +44 -0
  42. package/src/esm/utils/algorithms/clearDuplicateVertices.js.map +1 -0
  43. package/src/esm/utils/datastructures/DataGrid2d.d.ts +47 -0
  44. package/src/esm/utils/datastructures/DataGrid2d.js +19 -0
  45. package/src/esm/utils/datastructures/DataGrid2d.js.map +1 -0
  46. package/src/esm/utils/datastructures/DataGrid2dListAdapter.d.ts +65 -0
  47. package/src/esm/utils/datastructures/DataGrid2dListAdapter.js +79 -0
  48. package/src/esm/utils/datastructures/DataGrid2dListAdapter.js.map +1 -0
  49. package/src/esm/utils/datastructures/GenericPath.d.ts +14 -3
  50. package/src/esm/utils/datastructures/GenericPath.js +20 -3
  51. package/src/esm/utils/datastructures/GenericPath.js.map +1 -1
  52. package/src/ts/Polygon.ts +31 -1
  53. package/src/ts/utils/Params.ts +47 -0
  54. package/src/ts/utils/algorithms/ContourLineDetection.ts +485 -0
  55. package/src/ts/utils/algorithms/clearDuplicateVertices.ts +49 -0
  56. package/src/ts/utils/datastructures/DataGrid2d.ts +54 -0
  57. package/src/ts/utils/datastructures/DataGrid2dListAdapter.ts +121 -0
  58. package/src/ts/utils/datastructures/GenericPath.ts +21 -3
@@ -0,0 +1,367 @@
1
+ "use strict";
2
+ /**
3
+ * A function to detect contour lines from 3D terrain data.
4
+ *
5
+ * For usage see demo `./demos/48-contour-plot`.
6
+ *
7
+ * @requires detectPaths
8
+ * @requires GenericPath
9
+ * @author Ikaros Kappler
10
+ * @date 2023-11-05
11
+ * @modified 2023-11-20 Addig path detection on a triangle based grid.
12
+ * @version 1.0.0
13
+ */
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.ContourLineDetection = void 0;
16
+ var Line_1 = require("../../Line");
17
+ var Vertex_1 = require("../../Vertex");
18
+ var detectPaths_1 = require("./detectPaths");
19
+ var clearDuplicateVertices_1 = require("./clearDuplicateVertices");
20
+ var ContourLineDetection = /** @class */ (function () {
21
+ /**
22
+ * Creates a new instance for calculating contour lines from the given data grid.
23
+ * @param {IDataGrid2d<number>} dataGrid - The data grid to use. Must not contain any NaN or null values.
24
+ * @param {boolean=?} debugMode - (optional) Pass `true` to log warnings on (rare) critical edge cases where the algorithm might fail.
25
+ */
26
+ function ContourLineDetection(dataGrid, debugMode) {
27
+ this.rawLinearPathSegments = [];
28
+ // Activates/deactivates warning messages on rare edge cases where local path detection fails.
29
+ this.debugMode = false;
30
+ this.dataGrid = dataGrid;
31
+ this.debugMode = Boolean(debugMode);
32
+ }
33
+ /**
34
+ * Detect contour paths from the underlying data source.
35
+ *
36
+ * @param {number} criticalHeightValue - The height value. If above data's maximum or below data's minimum then the result will be empty (no intersections).
37
+ * @param {number} options.closeGapType - `CLOSE_GAP_TYPE_NONE` or `CLOSE_GAP_TYPE_ABOVE` or `CLOSE_GAP_TYPE_BELOW`.
38
+ * @param {boolean=false} options.useTriangles - If set to true the detection will split each face3 quad into two triangle faces.
39
+ * @param {pathDetectEpsilon=0.000001} options.pathDetectEpsilon - (optional) The epsilon to tell if two points are located 'in the same place'. Used for connected path detection. If not specified the value `0.0000001` is used.
40
+ * @param {pointEliminationEpsilon=0.0000001} options.pointEliminationEpsilon - (optional) The epsilon for duplicate point elimination (default is 0.000001).
41
+ * @param {function?} onRawSegmentsDetected - (optional) Get the interim result of all detected single lines before path detection starts; DO NOT MODIFY the array.
42
+ * @returns {Array<GenericPath>} - A list of connected paths that resemble the contour lines of the data/terrain at the given height value.
43
+ */
44
+ ContourLineDetection.prototype.detectContourPaths = function (criticalHeightValue, options) {
45
+ var _a, _b;
46
+ options = options || { closeGapType: ContourLineDetection.CLOSE_GAP_TYPE_NONE };
47
+ // First: clear the buffer
48
+ this.rawLinearPathSegments = [];
49
+ // Imagine a face4 element like this
50
+ // (x,y) (x+1,y)
51
+ // A-----B
52
+ // | / |
53
+ // | / |
54
+ // D-----C
55
+ // (x,y+1) (x+1,y+1)
56
+ // then result in the buffer will be
57
+ // [ [A,B],
58
+ // [D,C] ]
59
+ // Note that the diagonal line (used for triangles) is optional; depends on `options.useTriangles`.
60
+ var heightFace = [
61
+ [0, 0],
62
+ [0, 0]
63
+ ];
64
+ for (var y = 0; y + 1 < this.dataGrid.ySegmentCount; y++) {
65
+ for (var x = 0; x + 1 < this.dataGrid.xSegmentCount; x++) {
66
+ this.dataGrid.getDataFace4At(x, y, heightFace);
67
+ this.findHeightFaceIntersectionLines(x, y, heightFace, criticalHeightValue, (_a = options.pointEliminationEpsilon) !== null && _a !== void 0 ? _a : 0.0000001, options.useTriangles);
68
+ }
69
+ }
70
+ // Collect value above/below on the y axis
71
+ if (options.closeGapType == ContourLineDetection.CLOSE_GAP_TYPE_ABOVE ||
72
+ options.closeGapType == ContourLineDetection.CLOSE_GAP_TYPE_BELOW) {
73
+ var xExtremes = [0, this.dataGrid.xSegmentCount - 1];
74
+ for (var i = 0; i < xExtremes.length; i++) {
75
+ var x_1 = xExtremes[i];
76
+ for (var y = 0; y + 1 < this.dataGrid.ySegmentCount; y++) {
77
+ var nextX = x_1;
78
+ var nextY = y + 1;
79
+ this.detectAboveBelowLerpSegment(x_1, y, nextX, nextY, criticalHeightValue, options.closeGapType);
80
+ }
81
+ }
82
+ var yExtremes = [0, this.dataGrid.ySegmentCount - 1];
83
+ for (var j = 0; j < yExtremes.length; j++) {
84
+ var y = yExtremes[j];
85
+ for (var x = 0; x + 1 < this.dataGrid.xSegmentCount; x++) {
86
+ var nextX = x + 1;
87
+ var nextY = y;
88
+ this.detectAboveBelowLerpSegment(x, y, nextX, nextY, criticalHeightValue, options.closeGapType);
89
+ }
90
+ }
91
+ }
92
+ if (options.onRawSegmentsDetected) {
93
+ options.onRawSegmentsDetected(this.rawLinearPathSegments);
94
+ }
95
+ // Detect connected paths
96
+ var pathSegments = detectPaths_1.detectPaths(this.rawLinearPathSegments, (_b = options.pathDetectEpsilon) !== null && _b !== void 0 ? _b : 0.0000001); // Epsilon
97
+ // Filter out segments with only a single line of length~=0
98
+ pathSegments = pathSegments.filter(function (pathSegment) {
99
+ return (pathSegment.segments.length != 1 ||
100
+ (pathSegment.segments.length === 1 && pathSegment.segments[0].length() > 0.1));
101
+ });
102
+ return pathSegments;
103
+ };
104
+ /**
105
+ * This function will calculate a single intersecion line of the given face4 data
106
+ * segment. If the given face does not intersect with the plane at the given `heightValue`
107
+ * then no segments will be stored.
108
+ *
109
+ * @param {number} xIndex - The x position (index) of the data face.
110
+ * @param {number} yIndex - The y position (index) of the data face.
111
+ * @param {[[number,number],[number,number]]} heightFace - The data sample that composes the face4 as a two-dimensional number array.
112
+ * @param {number} heightValue - The height value of the intersection plane to check for.
113
+ * @returns {Line|null}
114
+ */
115
+ ContourLineDetection.prototype.findHeight4FaceIntersectionLine = function (xIndex, yIndex, heightFace, heightValue, pointEliminationEpsilon) {
116
+ var heightValueA = heightFace[0][0]; // value at (x,y)
117
+ var heightValueB = heightFace[1][0];
118
+ var heightValueC = heightFace[1][1];
119
+ var heightValueD = heightFace[0][1];
120
+ if (heightValueA === null || heightValueB === null || heightValueC === null || heightValueD === null) {
121
+ throw "[findHeightFace4IntersectionLine] Cannot extract data face at (" + xIndex + "," + yIndex + "). Some values are null.";
122
+ }
123
+ var points = [];
124
+ // Case A: use full quad face
125
+ if (this.isBetween(heightValueA, heightValueB, heightValue)) {
126
+ var lerpValueByHeight = this.getLerpRatio(heightValueA, heightValueB, heightValue);
127
+ points.push(new Vertex_1.Vertex(this.lerp(xIndex, xIndex + 1, lerpValueByHeight), yIndex));
128
+ }
129
+ if (this.isBetween(heightValueB, heightValueC, heightValue)) {
130
+ var lerpValueByHeight = this.getLerpRatio(heightValueB, heightValueC, heightValue);
131
+ points.push(new Vertex_1.Vertex(xIndex + 1, this.lerp(yIndex, yIndex + 1, lerpValueByHeight)));
132
+ }
133
+ if (this.isBetween(heightValueC, heightValueD, heightValue)) {
134
+ var lerpValueByHeight = this.getLerpRatio(heightValueC, heightValueD, heightValue);
135
+ points.push(new Vertex_1.Vertex(this.lerp(xIndex + 1, xIndex, lerpValueByHeight), yIndex + 1));
136
+ }
137
+ if (this.isBetween(heightValueD, heightValueA, heightValue)) {
138
+ var lerpValueByHeight = this.getLerpRatio(heightValueD, heightValueA, heightValue);
139
+ points.push(new Vertex_1.Vertex(xIndex, this.lerp(yIndex + 1, yIndex, lerpValueByHeight)));
140
+ }
141
+ // Warning: if a plane intersection point is located EXACTLY on the corner
142
+ // edge of a face, then the two adjacent edges will result in 2x the same
143
+ // intersecion point. This must be handled as one, so filter the point list
144
+ // by an epsilon.
145
+ points = clearDuplicateVertices_1.clearDuplicateVertices(points, pointEliminationEpsilon); // 0.000001);
146
+ if (points.length >= 2) {
147
+ var startPoint = points[0];
148
+ var endPoint = points[1];
149
+ if (this.debugMode && points.length > 2) {
150
+ console.warn("[findHeightFace4IntersectionLine] Detected more than 2 points on one face whre only 0 or 2 should appear. At ", xIndex, yIndex, points);
151
+ }
152
+ return new Line_1.Line(startPoint, endPoint);
153
+ }
154
+ else {
155
+ if (this.debugMode && points.length === 1) {
156
+ console.warn("[findHeightFace4IntersectionLine] Point list has only one point (should not happen).");
157
+ }
158
+ return null;
159
+ }
160
+ };
161
+ /**
162
+ * This function will calculate a single intersecion line of the given face4 data
163
+ * segment. If the given face does not intersect with the plane at the given `heightValue`
164
+ * then no segments will be stored.
165
+ *
166
+ * @param {number} xIndex - The x position (index) of the data face.
167
+ * @param {number} yIndex - The y position (index) of the data face.
168
+ * @param {[[number,number],[number,number]]} heightFace - The data sample that composes the face4 as a two-dimensional number array.
169
+ * @param {number} heightValue - The height value of the intersection plane to check for.
170
+ * @returns {Line|null}
171
+ */
172
+ ContourLineDetection.prototype.findHeightFaceIntersectionLines = function (xIndex, yIndex, heightFace, criticalHeightValue, pointEliminationEpsilon, useTriangles) {
173
+ // Imagine a face4 element like this
174
+ // (x,y) (x+1,y)
175
+ // A-----B
176
+ // | / |
177
+ // | / |
178
+ // D-----C
179
+ // (x,y+1) (x+1,y+1)
180
+ // then result in the buffer will be
181
+ // [ [A,B],
182
+ // [D,C] ]
183
+ if (useTriangles) {
184
+ var lineA = this.findHeighteFace3IntersectionLine(xIndex, yIndex, xIndex, yIndex + 1, xIndex + 1, yIndex, [heightFace[0][0], heightFace[0][1], heightFace[1][0]], criticalHeightValue, pointEliminationEpsilon);
185
+ if (lineA) {
186
+ this.rawLinearPathSegments.push(lineA);
187
+ }
188
+ var lineB = this.findHeighteFace3IntersectionLine(xIndex, yIndex + 1, xIndex + 1, yIndex + 1, xIndex + 1, yIndex, [heightFace[0][1], heightFace[1][1], heightFace[1][0]], criticalHeightValue, pointEliminationEpsilon);
189
+ if (lineB) {
190
+ this.rawLinearPathSegments.push(lineB);
191
+ }
192
+ }
193
+ else {
194
+ var line = this.findHeight4FaceIntersectionLine(xIndex, yIndex, heightFace, criticalHeightValue, pointEliminationEpsilon);
195
+ if (line) {
196
+ this.rawLinearPathSegments.push(line);
197
+ }
198
+ }
199
+ };
200
+ /**
201
+ * This function will calculate a single intersecion line of the given face3 data
202
+ * segment. If the given face does not intersect with the plane at the given `heightValue`
203
+ * then no segments will be stored.
204
+ *
205
+ * @param {number} xIndexA - The x position (index) of the first triangle data point.
206
+ * @param {number} yIndexA - The y position (index) of the first triangle data point.
207
+ * @param {[[number,number],[number,number]]} heightFace - The data sample that composes the face4 as a two-dimensional number array.
208
+ * @param {number} heightValue - The height value of the intersection plane to check for.
209
+ * @returns {Line|null}
210
+ */
211
+ ContourLineDetection.prototype.findHeighteFace3IntersectionLine = function (xIndexA, yIndexA, xIndexB, yIndexB, xIndexC, yIndexC, heightFace, heightValue, pointEliminationEpsilon) {
212
+ var heightValueA = heightFace[0]; // value at (x,y)
213
+ var heightValueB = heightFace[1];
214
+ var heightValueC = heightFace[2];
215
+ if (heightValueA === null || heightValueB === null || heightValueC === null) {
216
+ throw "[findHeightFace3IntersectionLine] Cannot extract data face at (" + xIndexA + "," + yIndexA + "). Some values are null.";
217
+ }
218
+ var points = [];
219
+ // Case A: use full quad face
220
+ if (this.isBetween(heightValueA, heightValueB, heightValue)) {
221
+ var lerpValueByHeight = this.getLerpRatio(heightValueA, heightValueB, heightValue);
222
+ points.push(new Vertex_1.Vertex(this.lerp(xIndexA, xIndexB, lerpValueByHeight), this.lerp(yIndexA, yIndexB, lerpValueByHeight)));
223
+ }
224
+ if (this.isBetween(heightValueB, heightValueC, heightValue)) {
225
+ var lerpValueByHeight = this.getLerpRatio(heightValueB, heightValueC, heightValue);
226
+ // points.push(new Vertex(xIndex + 1, this.lerp(yIndex, yIndex + 1, lerpValueByHeight)));
227
+ points.push(new Vertex_1.Vertex(this.lerp(xIndexB, xIndexC, lerpValueByHeight), this.lerp(yIndexB, yIndexC, lerpValueByHeight)));
228
+ }
229
+ if (this.isBetween(heightValueC, heightValueA, heightValue)) {
230
+ var lerpValueByHeight = this.getLerpRatio(heightValueC, heightValueA, heightValue);
231
+ // points.push(new Vertex(this.lerp(xIndex + 1, xIndex, lerpValueByHeight), yIndex + 1));
232
+ points.push(new Vertex_1.Vertex(this.lerp(xIndexC, xIndexA, lerpValueByHeight), this.lerp(yIndexC, yIndexA, lerpValueByHeight)));
233
+ }
234
+ // Warning: if a plane intersection point is located EXACTLY on the corner
235
+ // edge of a face, then the two adjacent edges will result in 2x the same
236
+ // intersecion point. This must be handled as one, so filter the point list
237
+ // by an epsilon.
238
+ points = clearDuplicateVertices_1.clearDuplicateVertices(points, pointEliminationEpsilon); // 0.0000001);
239
+ if (points.length >= 2) {
240
+ var startPoint = points[0];
241
+ var endPoint = points[1];
242
+ if (this.debugMode && points.length > 2) {
243
+ console.warn("[findHeightFace3IntersectionLine] Detected more than 2 points on one face whre only 0 or 2 should appear. At ", xIndexA, yIndexA, points);
244
+ }
245
+ return new Line_1.Line(startPoint, endPoint);
246
+ }
247
+ else {
248
+ if (this.debugMode && points.length === 1) {
249
+ console.warn("[findHeightFace3IntersectionLine] Point list has only one point (should not happen).");
250
+ }
251
+ return null;
252
+ }
253
+ };
254
+ /**
255
+ * This procedure will look at the face4 at the ((x,y),(nextX,nextY)) position – which are four values –
256
+ * and determines the local contour lines for these cases.
257
+ *
258
+ * This is used to detect and calculate edge cases on the borders of the underliying height data:
259
+ * * left and right border (x=0, x=data.xSegmentCount)
260
+ * * top and bottom border (x=y, x=data.ySegmentCount)
261
+ *
262
+ * Resulting path segments will be stored in the global `rawLinearPathSegments` array for further processing.
263
+ *
264
+ * @param {number} x
265
+ * @param {number} y
266
+ * @param {number} nextX
267
+ * @param {number} nextY
268
+ * @param {number} criticalHeightValue
269
+ * @param {number} closeGapType - CLOSE_GAP_TYPE_ABOVE or CLOSE_GAP_TYPE_BELOW.
270
+ * @return {void}
271
+ */
272
+ ContourLineDetection.prototype.detectAboveBelowLerpSegment = function (x, y, nextX, nextY, criticalHeightValue, closeGapType) {
273
+ var heightValueA = this.dataGrid.getDataValueAt(x, y);
274
+ var heightValueB = this.dataGrid.getDataValueAt(nextX, nextY);
275
+ // if (heightValueA >= criticalHeightValue && heightValueB >= criticalHeightValue) {
276
+ if (this.areBothValuesOnRequiredPlaneSide(heightValueA, heightValueB, criticalHeightValue, closeGapType)) {
277
+ // Both above
278
+ var line = new Line_1.Line(new Vertex_1.Vertex(x, y), new Vertex_1.Vertex(nextX, nextY));
279
+ this.rawLinearPathSegments.push(line);
280
+ }
281
+ else if ((closeGapType == ContourLineDetection.CLOSE_GAP_TYPE_ABOVE &&
282
+ heightValueA >= criticalHeightValue &&
283
+ heightValueB <= criticalHeightValue) ||
284
+ (closeGapType == ContourLineDetection.CLOSE_GAP_TYPE_BELOW &&
285
+ heightValueA <= criticalHeightValue &&
286
+ heightValueB >= criticalHeightValue)) {
287
+ // Only one of both (first) is above -> interpolate to find exact intersection point
288
+ var lerpValueByHeight = this.getLerpRatio(heightValueA, heightValueB, criticalHeightValue);
289
+ var interpLine = new Line_1.Line(new Vertex_1.Vertex(x, y), new Vertex_1.Vertex(this.lerp(x, nextX, lerpValueByHeight), this.lerp(y, nextY, lerpValueByHeight)));
290
+ this.rawLinearPathSegments.push(interpLine);
291
+ }
292
+ else if ((closeGapType == ContourLineDetection.CLOSE_GAP_TYPE_ABOVE &&
293
+ heightValueA <= criticalHeightValue &&
294
+ heightValueB >= criticalHeightValue) ||
295
+ (closeGapType == ContourLineDetection.CLOSE_GAP_TYPE_BELOW &&
296
+ heightValueA >= criticalHeightValue &&
297
+ heightValueB <= criticalHeightValue)) {
298
+ // Only one of both (second) is above -> interpolate to find exact intersection point
299
+ var lerpValueByHeight = this.getLerpRatio(heightValueA, heightValueB, criticalHeightValue);
300
+ var interpLine = new Line_1.Line(new Vertex_1.Vertex(this.lerp(x, nextX, lerpValueByHeight), this.lerp(y, nextY, lerpValueByHeight)), new Vertex_1.Vertex(nextX, nextY));
301
+ this.rawLinearPathSegments.push(interpLine);
302
+ }
303
+ };
304
+ /**
305
+ * Checks if both value are on the same side of the critical value (above or below). The `closeGapType`
306
+ * indictes if `CLOSE_GAP_TYPE_BELOW` or `CLOSE_GAP_TYPE_ABOVE` should be used as a rule.
307
+ *
308
+ * @param {number} valueA
309
+ * @param {number} valueB
310
+ * @param {number} criticalValue
311
+ * @param {number} closeGapType
312
+ * @returns {boolean}
313
+ */
314
+ ContourLineDetection.prototype.areBothValuesOnRequiredPlaneSide = function (valueA, valueB, criticalValue, closeGapType) {
315
+ return ((closeGapType == ContourLineDetection.CLOSE_GAP_TYPE_BELOW && valueA <= criticalValue && valueB <= criticalValue) ||
316
+ (closeGapType == ContourLineDetection.CLOSE_GAP_TYPE_ABOVE && valueA >= criticalValue && valueB >= criticalValue));
317
+ };
318
+ /**
319
+ * Test if a given numeric value (`curValue`) is between the given values `valA` and `valB`.
320
+ * Value A and B don't need to be in ascending order, so `valA <= curValue <= valB` and `valB <= curvalue <= valA`
321
+ * will do the job.
322
+ *
323
+ * @param {number} valA - The first of the two bounds.
324
+ * @param {number} valB - The second of the two bounds.
325
+ * @param {number} curValue - The value to check if it is between (or equal) to the given bounds.
326
+ * @returns {boolean}
327
+ */
328
+ ContourLineDetection.prototype.isBetween = function (valA, valB, curValue) {
329
+ return (valA <= curValue && curValue <= valB) || (valB <= curValue && curValue <= valA);
330
+ };
331
+ /**
332
+ * Get a 'lerp' value - which is some sort of percentage/ratio for the `curValue` inside the
333
+ * range of the given interval `[valA ... valB]`.
334
+ *
335
+ * Examples:
336
+ * * getLerpRatio(0,100,50) === 0.5
337
+ * * getLerpRatio(50,100,75) === 0.5
338
+ * * getLerpRatio(0,100,0) === 0.0
339
+ * * getLerpRatio(0,100,100) === 1.0
340
+ * * getLerpRatio(0,100,-50) === -0.5
341
+ *
342
+ * @param {number} valA
343
+ * @param {number} valB
344
+ * @param {number} curValue
345
+ * @returns
346
+ */
347
+ ContourLineDetection.prototype.getLerpRatio = function (valA, valB, curValue) {
348
+ return (curValue - valA) / (valB - valA);
349
+ };
350
+ /**
351
+ * Helper function to lerp a numeric value.
352
+ *
353
+ * @param {number} min - The min (start) value. Doesn't necesarily need to be the smaller one.
354
+ * @param {number} max - The max (end) value. Doesn't necesarily need to be the larger one.
355
+ * @param {number} ratio - The lerp ratio; usually a value between 0.0 and 1.0, but other values a valid for linear interpolation, too.
356
+ * @returns {number}
357
+ */
358
+ ContourLineDetection.prototype.lerp = function (min, max, ratio) {
359
+ return min + (max - min) * ratio;
360
+ };
361
+ ContourLineDetection.CLOSE_GAP_TYPE_NONE = 0;
362
+ ContourLineDetection.CLOSE_GAP_TYPE_ABOVE = 1;
363
+ ContourLineDetection.CLOSE_GAP_TYPE_BELOW = 2;
364
+ return ContourLineDetection;
365
+ }());
366
+ exports.ContourLineDetection = ContourLineDetection;
367
+ //# sourceMappingURL=ContourLineDetection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ContourLineDetection.js","sourceRoot":"","sources":["../../../ts/utils/algorithms/ContourLineDetection.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;GAWG;;;AAEH,mCAAkC;AAClC,uCAAsC;AAEtC,6CAA4C;AAC5C,mEAAkE;AAQlE;IAYE;;;;OAIG;IACH,8BAAY,QAA6B,EAAE,SAAmB;QAdtD,0BAAqB,GAAgB,EAAE,CAAC;QAMhD,8FAA8F;QACvF,cAAS,GAAY,KAAK,CAAC;QAQhC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;IACtC,CAAC;IAED;;;;;;;;;;OAUG;IACH,iDAAkB,GAAlB,UACE,mBAA2B,EAC3B,OAMC;;QAED,OAAO,GAAG,OAAO,IAAI,EAAE,YAAY,EAAE,oBAAoB,CAAC,mBAAmB,EAAE,CAAC;QAEhF,0BAA0B;QAC1B,IAAI,CAAC,qBAAqB,GAAG,EAAE,CAAC;QAEhC,oCAAoC;QACpC,yBAAyB;QACzB,kBAAkB;QAClB,kBAAkB;QAClB,kBAAkB;QAClB,kBAAkB;QAClB,4BAA4B;QAC5B,uCAAuC;QACvC,aAAa;QACb,cAAc;QACd,mGAAmG;QACnG,IAAM,UAAU,GAA0B;YACxC,CAAC,CAAC,EAAE,CAAC,CAAC;YACN,CAAC,CAAC,EAAE,CAAC,CAAC;SACP,CAAC;QACF,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,aAAa,EAAE,CAAC,EAAE,EAAE;YACxD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,aAAa,EAAE,C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AQ,IAAI,QAAQ,IAAI,IAAI,CAAC,CAAC;IAC1F,CAAC;IAED;;;;;;;;;;;;;;;OAeG;IACK,2CAAY,GAApB,UAAqB,IAAY,EAAE,IAAY,EAAE,QAAgB;QAC/D,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC;IAC3C,CAAC;IAED;;;;;;;OAOG;IACK,mCAAI,GAAZ,UAAa,GAAW,EAAE,GAAW,EAAE,KAAa;QAClD,OAAO,GAAG,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC,GAAG,KAAK,CAAC;IACnC,CAAC;IArcM,wCAAmB,GAAG,CAAC,CAAC;IACxB,yCAAoB,GAAG,CAAC,CAAC;IACzB,yCAAoB,GAAG,CAAC,CAAC;IAoclC,2BAAC;CAAA,AA3cD,IA2cC;AA3cY,oDAAoB"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Remove duplicate vertices (2d) from an array.
3
+ *
4
+ * This method war taken and refactored from an older demo.
5
+ *
6
+ * @author Ikaros Kappler
7
+ * @date 2021-07-13
8
+ * @modified 2023-10-28 Refactored and ported to Typescript.
9
+ * @version 1.0.0
10
+ */
11
+ import { Vertex } from "../../Vertex";
12
+ /**
13
+ * Filter the array and clear all duplicates.
14
+ *
15
+ * The original array is left unchanged. The vertices in the array are not cloned.
16
+ *
17
+ * @param {Vertex[]} vertices
18
+ * @param {number=EPS} epsilon
19
+ * @return {Vertex[]}
20
+ */
21
+ export declare const clearDuplicateVertices: (vertices: Vertex[], epsilon?: number) => Vertex[];
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ /**
3
+ * Remove duplicate vertices (2d) from an array.
4
+ *
5
+ * This method war taken and refactored from an older demo.
6
+ *
7
+ * @author Ikaros Kappler
8
+ * @date 2021-07-13
9
+ * @modified 2023-10-28 Refactored and ported to Typescript.
10
+ * @version 1.0.0
11
+ */
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.clearDuplicateVertices = void 0;
14
+ var EPS = 0.000001;
15
+ /**
16
+ * Filter the array and clear all duplicates.
17
+ *
18
+ * The original array is left unchanged. The vertices in the array are not cloned.
19
+ *
20
+ * @param {Vertex[]} vertices
21
+ * @param {number=EPS} epsilon
22
+ * @return {Vertex[]}
23
+ */
24
+ var clearDuplicateVertices = function (vertices, epsilon) {
25
+ if (typeof epsilon === "undefined") {
26
+ epsilon = EPS;
27
+ }
28
+ var result = [];
29
+ for (var i = 0; i < vertices.length; i++) {
30
+ if (!containsElementFrom(vertices, vertices[i], i + 1, epsilon)) {
31
+ result.push(vertices[i]);
32
+ }
33
+ }
34
+ return result;
35
+ };
36
+ exports.clearDuplicateVertices = clearDuplicateVertices;
37
+ var isCloseTo = function (vertA, vertB, eps) {
38
+ return vertA.distance(vertB) < eps;
39
+ };
40
+ var containsElementFrom = function (vertices, vertex, fromIndex, epsilon) {
41
+ for (var i = fromIndex; i < vertices.length; i++) {
42
+ if (isCloseTo(vertices[i], vertex, epsilon)) {
43
+ return true;
44
+ }
45
+ }
46
+ return false;
47
+ };
48
+ //# sourceMappingURL=clearDuplicateVertices.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clearDuplicateVertices.js","sourceRoot":"","sources":["../../../ts/utils/algorithms/clearDuplicateVertices.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;AAIH,IAAM,GAAG,GAAW,QAAQ,CAAC;AAE7B;;;;;;;;GAQG;AACI,IAAM,sBAAsB,GAAG,UAAC,QAAkB,EAAE,OAAgB;IACzE,IAAI,OAAO,OAAO,KAAK,WAAW,EAAE;QAClC,OAAO,GAAG,GAAG,CAAC;KACf;IACD,IAAM,MAAM,GAAkB,EAAE,CAAC;IACjC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QACxC,IAAI,CAAC,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC,EAAE;YAC/D,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;SAC1B;KACF;IACD,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAXW,QAAA,sBAAsB,0BAWjC;AAEF,IAAM,SAAS,GAAG,UAAC,KAAa,EAAE,KAAa,EAAE,GAAW;IAC1D,OAAO,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC;AACrC,CAAC,CAAC;AAEF,IAAM,mBAAmB,GAAG,UAAC,QAAuB,EAAE,MAAc,EAAE,SAAiB,EAAE,OAAe;IACtG,KAAK,IAAI,CAAC,GAAG,SAAS,EAAE,CAAC,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QAChD,IAAI,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;YAC3C,OAAO,IAAI,CAAC;SACb;KACF;IACD,OAAO,KAAK,CAAC;AACf,CAAC,CAAC"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * A 2D datagrid interface for getting/storing data in some 2 dimensional array style types.
3
+ *
4
+ * _|---- xIndex --->
5
+ * | d[0][0], d[1][0], d[2][0], ..., d[xSegmentCount-1][0]
6
+ * yIndex
7
+ * | d[0][1], d[1][1], d[2][1], ..., d[xSegmentCount-1][1]
8
+ * |
9
+ * v ...
10
+ *
11
+ * d[0][ySegmentCount-1], ..., ..., d[xSegmentCount-1][ySegmentCount-1]
12
+ *
13
+ *
14
+ * @date 2023-11-04
15
+ * @author Ikaros Kappler
16
+ * @version 1.0.0
17
+ */
18
+ export declare type DataGridFace4<T> = [[T | null, T | null], [T | null, T | null]];
19
+ export interface IDataGrid2d<T> {
20
+ readonly xSegmentCount: number;
21
+ readonly ySegmentCount: number;
22
+ getMinDataValue(): T;
23
+ getMaxDataValue(): T;
24
+ getDataValueAt(xIndex: number, yIndex: number): T | null;
25
+ /**
26
+ * Extract a 2x2 matrix (a "face4") from the underlyting data.
27
+ *
28
+ * Imagine a face4 element like this
29
+ * (x,y) (x+1,y)
30
+ * A-----B
31
+ * | |
32
+ * | |
33
+ * D-----C
34
+ * (x,y+1) (x+1,y+1)
35
+ *
36
+ * then result in the buffer will be
37
+ * [ [A,B],
38
+ * [D,C] ]
39
+ *
40
+ * If any index is invalid then the resulting buffer element will be null.
41
+ *
42
+ * @param {number} xIndex - The x index in `0 <= xIndex < xSegmentCount`.
43
+ * @param {number} yIndex - The y index in `0 <= yIndex < ySegmentCount`.
44
+ * @param {[[T,T],[T,T]]} buffer - The result buffer for four elements.
45
+ */
46
+ getDataFace4At(xIndex: number, yIndex: number, buffer: DataGridFace4<T>): void;
47
+ }
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ /**
3
+ * A 2D datagrid interface for getting/storing data in some 2 dimensional array style types.
4
+ *
5
+ * _|---- xIndex --->
6
+ * | d[0][0], d[1][0], d[2][0], ..., d[xSegmentCount-1][0]
7
+ * yIndex
8
+ * | d[0][1], d[1][1], d[2][1], ..., d[xSegmentCount-1][1]
9
+ * |
10
+ * v ...
11
+ *
12
+ * d[0][ySegmentCount-1], ..., ..., d[xSegmentCount-1][ySegmentCount-1]
13
+ *
14
+ *
15
+ * @date 2023-11-04
16
+ * @author Ikaros Kappler
17
+ * @version 1.0.0
18
+ */
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ //# sourceMappingURL=DataGrid2d.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DataGrid2d.js","sourceRoot":"","sources":["../../../ts/utils/datastructures/DataGrid2d.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;GAgBG"}
@@ -0,0 +1,65 @@
1
+ /**
2
+ * A DataGrid2d implementation on a linear array of triplets/Vector3.
3
+ *
4
+ * @author Ikaros Kappler
5
+ * @date 2023-10-28
6
+ * @modified 2023-11-04 Converted to a Typescript class.
7
+ * @version 1.0.0
8
+ **/
9
+ import { DataGridFace4, IDataGrid2d } from "./DataGrid2d";
10
+ declare type Triplet<T> = {
11
+ x: T;
12
+ y: T;
13
+ z: T;
14
+ };
15
+ declare type RasterPosition = {
16
+ xIndex: number;
17
+ yIndex: number;
18
+ xRel?: number;
19
+ yRel?: number;
20
+ };
21
+ export declare class DataGrid2dListAdapter<T> implements IDataGrid2d<T> {
22
+ /**
23
+ * @override
24
+ */
25
+ readonly xSegmentCount: number;
26
+ /**
27
+ * @override
28
+ */
29
+ readonly ySegmentCount: number;
30
+ minDataValue: T;
31
+ maxDataValue: T;
32
+ minXValue: T;
33
+ maxXValue: T;
34
+ minYValue: T;
35
+ maxYValue: T;
36
+ private _dataList;
37
+ /**
38
+ * Create a new DataGrid2d from the given
39
+ * @throws Error if xSegmentCount*ySegmentCount is larger than the capacity of the array/list.
40
+ * @param list
41
+ * @param xSegmentCount
42
+ * @param ySegmentCount
43
+ */
44
+ constructor(list: Array<Triplet<T>>, xSegmentCount: number, ySegmentCount: number);
45
+ getIndicesFromBufferIndex(bufferIndex: number): RasterPosition;
46
+ getCoordsFromBufferIndex(bufferIndex: number): RasterPosition;
47
+ coordinateIndicesToBufferIndex(xIndex: number, yIndex: number): number;
48
+ /**
49
+ * @override
50
+ */
51
+ getMinDataValue(): T;
52
+ /**
53
+ * @override
54
+ */
55
+ getMaxDataValue(): T;
56
+ /**
57
+ * @override
58
+ */
59
+ getDataValueAt(xIndex: number, yIndex: number, isDebug?: boolean): T | null;
60
+ /**
61
+ * @override
62
+ */
63
+ getDataFace4At(xIndex: number, yIndex: number, buffer: DataGridFace4<T>): void;
64
+ }
65
+ export {};