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,121 @@
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
+
10
+ import { DataGridFace4, IDataGrid2d } from "./DataGrid2d";
11
+
12
+ type Triplet<T> = {
13
+ x: T;
14
+ y: T;
15
+ z: T;
16
+ };
17
+
18
+ type RasterPosition = {
19
+ xIndex: number;
20
+ yIndex: number;
21
+ xRel?: number;
22
+ yRel?: number;
23
+ };
24
+
25
+ export class DataGrid2dListAdapter<T> implements IDataGrid2d<T> {
26
+ /**
27
+ * @override
28
+ */
29
+ readonly xSegmentCount: number;
30
+
31
+ /**
32
+ * @override
33
+ */
34
+ readonly ySegmentCount: number;
35
+
36
+ minDataValue: T;
37
+ maxDataValue: T;
38
+ minXValue: T;
39
+ maxXValue: T;
40
+ minYValue: T;
41
+ maxYValue: T;
42
+ private _dataList: Array<Triplet<T>>;
43
+
44
+ /**
45
+ * Create a new DataGrid2d from the given
46
+ * @throws Error if xSegmentCount*ySegmentCount is larger than the capacity of the array/list.
47
+ * @param list
48
+ * @param xSegmentCount
49
+ * @param ySegmentCount
50
+ */
51
+ constructor(list: Array<Triplet<T>>, xSegmentCount: number, ySegmentCount: number) {
52
+ if (xSegmentCount * ySegmentCount > list.length) {
53
+ throw `Cannot create DataGrid2dListAdapter, the list (length ${list.length}) does not provide enough items for ${xSegmentCount}x${ySegmentCount} required entries.`;
54
+ }
55
+
56
+ // this.canvas = document.getElementById(canvasId);
57
+ this.xSegmentCount = xSegmentCount;
58
+ this.ySegmentCount = ySegmentCount;
59
+
60
+ this._dataList = list;
61
+ }
62
+
63
+ getIndicesFromBufferIndex(bufferIndex: number): RasterPosition {
64
+ return { xIndex: Math.floor(bufferIndex % this.xSegmentCount), yIndex: Math.floor(bufferIndex / this.xSegmentCount) };
65
+ }
66
+
67
+ getCoordsFromBufferIndex(bufferIndex: number): RasterPosition {
68
+ var index = this.getIndicesFromBufferIndex(bufferIndex);
69
+ // Note that the xSegmentCount and ySegmentCount counts plane squares, each consisting of four vertices
70
+ index.xRel = index.xIndex / (this.xSegmentCount - 1);
71
+ index.yRel = index.yIndex / (this.ySegmentCount - 1);
72
+ return index;
73
+ }
74
+
75
+ coordinateIndicesToBufferIndex(xIndex: number, yIndex: number): number {
76
+ return yIndex * this.xSegmentCount + xIndex;
77
+ }
78
+
79
+ /**
80
+ * @override
81
+ */
82
+ getMinDataValue(): T {
83
+ return this.minDataValue;
84
+ }
85
+
86
+ /**
87
+ * @override
88
+ */
89
+ getMaxDataValue(): T {
90
+ return this.maxDataValue;
91
+ }
92
+
93
+ /**
94
+ * @override
95
+ */
96
+ getDataValueAt(xIndex: number, yIndex: number, isDebug?: boolean): T | null {
97
+ // var bufferIndex = yIndex * this.xSegmentCount + xIndex;
98
+ var bufferIndex = this.coordinateIndicesToBufferIndex(xIndex, yIndex);
99
+ if (isDebug) {
100
+ console.log("xIndex", xIndex, "yIndex", yIndex, "bufferIndex", bufferIndex);
101
+ }
102
+ if (bufferIndex > this._dataList.length) {
103
+ console.error("ERR buffer index is out of bounds! xIndex", xIndex, "yIndex", yIndex, "bufferIndex", bufferIndex);
104
+ }
105
+ if (!this._dataList[bufferIndex]) {
106
+ console.error("ERR buffer element is null! xIndex", xIndex, "yIndex", yIndex, "bufferIndex", bufferIndex);
107
+ }
108
+ return this._dataList && bufferIndex < this._dataList.length ? this._dataList[bufferIndex].z : null;
109
+ }
110
+
111
+ /**
112
+ * @override
113
+ */
114
+ getDataFace4At(xIndex: number, yIndex: number, buffer: DataGridFace4<T>) {
115
+ // buffer: array[2][2]
116
+ buffer[0][0] = this.getDataValueAt(xIndex, yIndex);
117
+ buffer[1][0] = this.getDataValueAt(xIndex + 1, yIndex);
118
+ buffer[1][1] = this.getDataValueAt(xIndex + 1, yIndex + 1);
119
+ buffer[0][1] = this.getDataValueAt(xIndex, yIndex + 1);
120
+ }
121
+ }
@@ -1,7 +1,8 @@
1
1
  /**
2
- * @author Ikaros Kappler
3
- * @version 1.0.0
4
- * @date 2022-10-17
2
+ * @author Ikaros Kappler
3
+ * @version 1.1.0
4
+ * @date 2022-10-17
5
+ * @modified 2023-11-27 Added the `GenericPath.getAllStartEndPoints()` function.
5
6
  */
6
7
 
7
8
  import { Path, PathSegment } from "../../interfaces/additionals";
@@ -110,4 +111,21 @@ export class GenericPath implements Path {
110
111
  getEndTangent(): Vertex {
111
112
  return this.segments[this.segments.length - 1].getEndTangent();
112
113
  }
114
+
115
+ /**
116
+ * Get the sequence of all start/end points of this path.
117
+ * Assumption is: each path segment's end point is located on the next segment's start point
118
+ * to shape a full connected path.
119
+ *
120
+ * No arcs are considered here, just plain linear segments.
121
+ *
122
+ * @returns {Array<Vertex>}
123
+ */
124
+ getAllStartEndPoints(): Array<Vertex> {
125
+ const verts: Array<Vertex> = [this.segments[0].getStartPoint()];
126
+ this.segments.forEach((segment: PathSegment) => {
127
+ verts.push(segment.getEndPoint());
128
+ });
129
+ return verts;
130
+ }
113
131
  }