@itwin/core-geometry 4.5.0-dev.3 → 4.5.0-dev.32

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 (107) hide show
  1. package/CHANGELOG.md +47 -1
  2. package/LICENSE.md +1 -1
  3. package/lib/cjs/Geometry.d.ts +15 -0
  4. package/lib/cjs/Geometry.d.ts.map +1 -1
  5. package/lib/cjs/Geometry.js +27 -0
  6. package/lib/cjs/Geometry.js.map +1 -1
  7. package/lib/cjs/curve/CoordinateXYZ.d.ts +10 -13
  8. package/lib/cjs/curve/CoordinateXYZ.d.ts.map +1 -1
  9. package/lib/cjs/curve/CoordinateXYZ.js +16 -15
  10. package/lib/cjs/curve/CoordinateXYZ.js.map +1 -1
  11. package/lib/cjs/curve/GeometryQuery.d.ts +17 -17
  12. package/lib/cjs/curve/GeometryQuery.d.ts.map +1 -1
  13. package/lib/cjs/curve/GeometryQuery.js +16 -15
  14. package/lib/cjs/curve/GeometryQuery.js.map +1 -1
  15. package/lib/cjs/curve/PointString3d.d.ts +17 -13
  16. package/lib/cjs/curve/PointString3d.d.ts.map +1 -1
  17. package/lib/cjs/curve/PointString3d.js +35 -20
  18. package/lib/cjs/curve/PointString3d.js.map +1 -1
  19. package/lib/cjs/curve/spiral/MXCubicAlongArcSpiralEvaluator.js +1 -1
  20. package/lib/cjs/curve/spiral/MXCubicAlongArcSpiralEvaluator.js.map +1 -1
  21. package/lib/cjs/curve/spiral/PolishCubicSpiralEvaluator.js +1 -1
  22. package/lib/cjs/curve/spiral/PolishCubicSpiralEvaluator.js.map +1 -1
  23. package/lib/cjs/geometry3d/FrameBuilder.d.ts.map +1 -1
  24. package/lib/cjs/geometry3d/FrameBuilder.js +3 -0
  25. package/lib/cjs/geometry3d/FrameBuilder.js.map +1 -1
  26. package/lib/cjs/geometry3d/GrowableXYZArray.d.ts +8 -2
  27. package/lib/cjs/geometry3d/GrowableXYZArray.d.ts.map +1 -1
  28. package/lib/cjs/geometry3d/GrowableXYZArray.js +11 -2
  29. package/lib/cjs/geometry3d/GrowableXYZArray.js.map +1 -1
  30. package/lib/cjs/polyface/IndexedPolyfaceVisitor.d.ts +42 -50
  31. package/lib/cjs/polyface/IndexedPolyfaceVisitor.d.ts.map +1 -1
  32. package/lib/cjs/polyface/IndexedPolyfaceVisitor.js +81 -105
  33. package/lib/cjs/polyface/IndexedPolyfaceVisitor.js.map +1 -1
  34. package/lib/cjs/polyface/Polyface.d.ts +166 -120
  35. package/lib/cjs/polyface/Polyface.d.ts.map +1 -1
  36. package/lib/cjs/polyface/Polyface.js +251 -162
  37. package/lib/cjs/polyface/Polyface.js.map +1 -1
  38. package/lib/cjs/polyface/PolyfaceBuilder.d.ts +18 -10
  39. package/lib/cjs/polyface/PolyfaceBuilder.d.ts.map +1 -1
  40. package/lib/cjs/polyface/PolyfaceBuilder.js +27 -21
  41. package/lib/cjs/polyface/PolyfaceBuilder.js.map +1 -1
  42. package/lib/cjs/polyface/PolyfaceData.d.ts +142 -86
  43. package/lib/cjs/polyface/PolyfaceData.d.ts.map +1 -1
  44. package/lib/cjs/polyface/PolyfaceData.js +305 -164
  45. package/lib/cjs/polyface/PolyfaceData.js.map +1 -1
  46. package/lib/cjs/serialization/GeometrySamples.js.map +1 -1
  47. package/lib/cjs/topology/Graph.d.ts +2 -8
  48. package/lib/cjs/topology/Graph.d.ts.map +1 -1
  49. package/lib/cjs/topology/Graph.js +0 -3
  50. package/lib/cjs/topology/Graph.js.map +1 -1
  51. package/lib/cjs/topology/Triangulation.d.ts +18 -7
  52. package/lib/cjs/topology/Triangulation.d.ts.map +1 -1
  53. package/lib/cjs/topology/Triangulation.js +50 -9
  54. package/lib/cjs/topology/Triangulation.js.map +1 -1
  55. package/lib/esm/Geometry.d.ts +15 -0
  56. package/lib/esm/Geometry.d.ts.map +1 -1
  57. package/lib/esm/Geometry.js +27 -0
  58. package/lib/esm/Geometry.js.map +1 -1
  59. package/lib/esm/curve/CoordinateXYZ.d.ts +10 -13
  60. package/lib/esm/curve/CoordinateXYZ.d.ts.map +1 -1
  61. package/lib/esm/curve/CoordinateXYZ.js +16 -15
  62. package/lib/esm/curve/CoordinateXYZ.js.map +1 -1
  63. package/lib/esm/curve/GeometryQuery.d.ts +17 -17
  64. package/lib/esm/curve/GeometryQuery.d.ts.map +1 -1
  65. package/lib/esm/curve/GeometryQuery.js +16 -15
  66. package/lib/esm/curve/GeometryQuery.js.map +1 -1
  67. package/lib/esm/curve/PointString3d.d.ts +17 -13
  68. package/lib/esm/curve/PointString3d.d.ts.map +1 -1
  69. package/lib/esm/curve/PointString3d.js +35 -20
  70. package/lib/esm/curve/PointString3d.js.map +1 -1
  71. package/lib/esm/curve/spiral/MXCubicAlongArcSpiralEvaluator.js +1 -1
  72. package/lib/esm/curve/spiral/MXCubicAlongArcSpiralEvaluator.js.map +1 -1
  73. package/lib/esm/curve/spiral/PolishCubicSpiralEvaluator.js +1 -1
  74. package/lib/esm/curve/spiral/PolishCubicSpiralEvaluator.js.map +1 -1
  75. package/lib/esm/geometry3d/FrameBuilder.d.ts.map +1 -1
  76. package/lib/esm/geometry3d/FrameBuilder.js +3 -0
  77. package/lib/esm/geometry3d/FrameBuilder.js.map +1 -1
  78. package/lib/esm/geometry3d/GrowableXYZArray.d.ts +8 -2
  79. package/lib/esm/geometry3d/GrowableXYZArray.d.ts.map +1 -1
  80. package/lib/esm/geometry3d/GrowableXYZArray.js +11 -2
  81. package/lib/esm/geometry3d/GrowableXYZArray.js.map +1 -1
  82. package/lib/esm/polyface/IndexedPolyfaceVisitor.d.ts +42 -50
  83. package/lib/esm/polyface/IndexedPolyfaceVisitor.d.ts.map +1 -1
  84. package/lib/esm/polyface/IndexedPolyfaceVisitor.js +80 -103
  85. package/lib/esm/polyface/IndexedPolyfaceVisitor.js.map +1 -1
  86. package/lib/esm/polyface/Polyface.d.ts +166 -120
  87. package/lib/esm/polyface/Polyface.d.ts.map +1 -1
  88. package/lib/esm/polyface/Polyface.js +251 -162
  89. package/lib/esm/polyface/Polyface.js.map +1 -1
  90. package/lib/esm/polyface/PolyfaceBuilder.d.ts +18 -10
  91. package/lib/esm/polyface/PolyfaceBuilder.d.ts.map +1 -1
  92. package/lib/esm/polyface/PolyfaceBuilder.js +27 -21
  93. package/lib/esm/polyface/PolyfaceBuilder.js.map +1 -1
  94. package/lib/esm/polyface/PolyfaceData.d.ts +142 -86
  95. package/lib/esm/polyface/PolyfaceData.d.ts.map +1 -1
  96. package/lib/esm/polyface/PolyfaceData.js +305 -164
  97. package/lib/esm/polyface/PolyfaceData.js.map +1 -1
  98. package/lib/esm/serialization/GeometrySamples.js.map +1 -1
  99. package/lib/esm/topology/Graph.d.ts +2 -8
  100. package/lib/esm/topology/Graph.d.ts.map +1 -1
  101. package/lib/esm/topology/Graph.js +0 -3
  102. package/lib/esm/topology/Graph.js.map +1 -1
  103. package/lib/esm/topology/Triangulation.d.ts +18 -7
  104. package/lib/esm/topology/Triangulation.d.ts.map +1 -1
  105. package/lib/esm/topology/Triangulation.js +50 -9
  106. package/lib/esm/topology/Triangulation.js.map +1 -1
  107. package/package.json +4 -3
@@ -9,6 +9,7 @@ exports.IndexedPolyface = exports.Polyface = void 0;
9
9
  * @module Polyface
10
10
  */
11
11
  /* eslint-disable @typescript-eslint/naming-convention, no-empty */
12
+ // cspell:word internaldocs
12
13
  const GeometryQuery_1 = require("../curve/GeometryQuery");
13
14
  const Geometry_1 = require("../Geometry");
14
15
  const GrowableXYArray_1 = require("../geometry3d/GrowableXYArray");
@@ -24,6 +25,7 @@ const PolyfaceData_1 = require("./PolyfaceData");
24
25
  * @public
25
26
  */
26
27
  class Polyface extends GeometryQuery_1.GeometryQuery {
28
+ /** Constructor */
27
29
  constructor(data) {
28
30
  super();
29
31
  /** String name for schema properties */
@@ -31,70 +33,103 @@ class Polyface extends GeometryQuery_1.GeometryQuery {
31
33
  this.data = data;
32
34
  }
33
35
  /** Flag indicating if the mesh display must assume both sides are visible. */
34
- get twoSided() { return this.data.twoSided; }
35
- set twoSided(value) { this.data.twoSided = value; }
36
- /** Flag indicating if the mesh closure is unknown (0), open sheet (1), closed (2) */
37
- get expectedClosure() { return this.data.expectedClosure; }
38
- set expectedClosure(value) { this.data.expectedClosure = value; }
36
+ get twoSided() {
37
+ return this.data.twoSided;
38
+ }
39
+ set twoSided(value) {
40
+ this.data.twoSided = value;
41
+ }
42
+ /**
43
+ * Flag indicating if the mesh closure is unknown (0), open sheet (1), closed solid (2).
44
+ * * A boundary edge of a mesh is defined as an edge with only one connected facet.
45
+ * * Closed solid is a mesh with no boundary edge. Open sheet is a mesh that has boundary edge(s).
46
+ */
47
+ get expectedClosure() {
48
+ return this.data.expectedClosure;
49
+ }
50
+ set expectedClosure(value) {
51
+ this.data.expectedClosure = value;
52
+ }
39
53
  /**
40
- * Check validity of indices into a data array.
41
- * * It is valid to have both indices and data undefined.
42
- * * It is NOT valid for just one to be defined.
43
- * * Index values at indices[indexPositionA <= i < indexPositionB] must be valid indices to the data array.
44
- * @param indices array of indices.
45
- * @param indexPositionA first index to test
46
- * @param indexPositionB one past final index to test
47
- * @param data data array
48
- * @param dataLength length of data array
49
- */
54
+ * Check validity of indices into a data array.
55
+ * * It is valid to have both indices and data undefined.
56
+ * * It is NOT valid for just one to be defined.
57
+ * * Index values at indices[indexPositionA <= i < indexPositionB] must be valid indices to the data array.
58
+ * @param indices array of indices.
59
+ * @param indexPositionA first index to test.
60
+ * @param indexPositionB one past final index to test.
61
+ * @param data data array.
62
+ * @param dataLength length of data array.
63
+ */
50
64
  static areIndicesValid(indices, indexPositionA, indexPositionB, data, dataLength) {
51
65
  if (indices === undefined && data === undefined)
52
66
  return true;
53
- if (!indices || !data)
67
+ if (indices === undefined || data === undefined)
54
68
  return false;
55
69
  if (indexPositionA < 0 || indexPositionA >= indices.length)
56
70
  return false;
57
- if (indexPositionB < indexPositionA || indexPositionB > indices.length)
71
+ if (indexPositionB <= indexPositionA || indexPositionB > indices.length)
58
72
  return false;
59
73
  for (let i = indexPositionA; i < indexPositionB; i++)
60
74
  if (indices[i] < 0 || indices[i] >= dataLength)
61
75
  return false;
62
76
  return true;
63
77
  }
64
- /**
65
- * Returns the number of facets of this polyface. Subclasses should override.
66
- */
78
+ /** Returns the number of facets of this polyface. Subclasses should override. */
67
79
  get facetCount() {
68
80
  return undefined;
69
81
  }
70
82
  }
71
83
  exports.Polyface = Polyface;
72
84
  /**
73
- * An `IndexedPolyface` is a set of facets which can have normal, param, and color arrays with independent point, normal, param, and color indices.
85
+ * An `IndexedPolyface` is a set of facets which can have normal, param, and color arrays with independent point,
86
+ * normal, param, and color indices.
74
87
  * @public
75
88
  */
76
89
  class IndexedPolyface extends Polyface {
90
+ /**
91
+ * Constructor for a new polyface.
92
+ * @param data PolyfaceData arrays to capture.
93
+ * @param facetStart optional array of facet start indices (e.g. known during clone)
94
+ * @param facetToFacetData optional array of face identifiers (e.g. known during clone)
95
+ */
96
+ constructor(data, facetStart, facetToFaceData) {
97
+ super(data);
98
+ if (facetStart)
99
+ this._facetStart = facetStart.slice(); // deep copy
100
+ else {
101
+ this._facetStart = [];
102
+ this._facetStart.push(0);
103
+ }
104
+ if (facetToFaceData)
105
+ this._facetToFaceData = facetToFaceData.slice(); // deep copy
106
+ else
107
+ this._facetToFaceData = [];
108
+ }
77
109
  /** Test if other is an instance of `IndexedPolyface` */
78
- isSameGeometryClass(other) { return other instanceof IndexedPolyface; }
110
+ isSameGeometryClass(other) {
111
+ return other instanceof IndexedPolyface;
112
+ }
79
113
  /** Tests for equivalence between two IndexedPolyfaces. */
80
114
  isAlmostEqual(other) {
81
115
  if (other instanceof IndexedPolyface) {
82
- return this.data.isAlmostEqual(other.data) && PointHelpers_1.NumberArray.isExactEqual(this._facetStart, other._facetStart) &&
116
+ return this.data.isAlmostEqual(other.data) &&
117
+ PointHelpers_1.NumberArray.isExactEqual(this._facetStart, other._facetStart) &&
83
118
  PointHelpers_1.NumberArray.isExactEqual(this._facetToFaceData, other._facetToFaceData);
84
119
  }
85
120
  return false;
86
121
  }
122
+ /** Returns true if either the point array or the point index array is empty. */
123
+ get isEmpty() {
124
+ return this.data.pointCount === 0 || this.data.pointIndex.length === 0;
125
+ }
87
126
  /**
88
- * Returns true if either the point array or the point index array is empty.
89
- */
90
- get isEmpty() { return this.data.pointCount === 0 || this.data.pointIndex.length === 0; }
91
- /**
92
- * * apply the transform to points
93
- * * apply the (inverse transpose of) the matrix part to normals
94
- * * If determinant is negative, also
127
+ * Transform the mesh.
128
+ * * Apply the transform to points.
129
+ * * Apply the (inverse transpose of the) matrix part to normals.
130
+ * * If determinant of the transform matrix is negative, also
95
131
  * * negate normals
96
132
  * * reverse index order around each facet.
97
- * @param transform
98
133
  */
99
134
  tryTransformInPlace(transform) {
100
135
  if (!this.data.tryTransformInPlace(transform))
@@ -115,52 +150,47 @@ class IndexedPolyface extends Polyface {
115
150
  const result = new IndexedPolyface(this.data.clone(), this._facetStart.slice(), this._facetToFaceData.slice());
116
151
  return result;
117
152
  }
118
- /** Return a deep clone with transformed points and normals */
153
+ /**
154
+ * Return a deep clone with transformed points and normals.
155
+ * @see [[IndexedPolyface.tryTransformInPlace]] for details of how transform is done.
156
+ */
119
157
  cloneTransformed(transform) {
120
158
  const result = this.clone();
121
159
  result.tryTransformInPlace(transform);
122
160
  return result;
123
161
  }
124
162
  /** Reverse the order of indices around all facets. */
125
- reverseIndices() { this.data.reverseIndices(this._facetStart); }
163
+ reverseIndices() {
164
+ this.data.reverseIndices(this._facetStart);
165
+ }
126
166
  /** Reverse the direction of all normal vectors. */
127
- reverseNormals() { this.data.reverseNormals(); }
128
- /** return face data using a facet index. This is the REFERENCE to the FacetFaceData, not a copy. Returns undefined if none found. */
167
+ reverseNormals() {
168
+ this.data.reverseNormals();
169
+ }
170
+ /**
171
+ * Return face data using a facet index.
172
+ * * Returns `undefined` if none found.
173
+ * * This is the REFERENCE to the FacetFaceData not a copy.
174
+ */
129
175
  tryGetFaceData(i) {
176
+ if (i < 0 || i >= this._facetToFaceData.length)
177
+ return undefined;
130
178
  const faceIndex = this._facetToFaceData[i];
131
- if (faceIndex >= this.data.face.length)
179
+ if (faceIndex < 0 || faceIndex >= this.data.face.length)
132
180
  return undefined;
133
181
  return this.data.face[faceIndex];
134
182
  }
135
183
  /**
136
- * Constructor for a new polyface.
137
- * @param data PolyfaceData arrays to capture.
138
- * @param facetStart optional array of facet start indices (e.g. known during clone)
139
- * @param facetToFacetData optional array of face identifiers (e.g. known during clone)
140
- */
141
- constructor(data, facetStart, facetToFaceData) {
142
- super(data);
143
- if (facetStart)
144
- this._facetStart = facetStart.slice();
145
- else {
146
- this._facetStart = [];
147
- this._facetStart.push(0);
148
- }
149
- if (facetToFaceData)
150
- this._facetToFaceData = facetToFaceData.slice();
151
- else
152
- this._facetToFaceData = [];
153
- }
154
- /**
155
- * * Add facets from source to this polyface.
156
- * * Optionally reverse facet indices as per PolyfaceData.reverseIndicesSingleFacet() with preserveStart = false, and invert source normals.
157
- * * Optionally apply a transform to points and normals.
184
+ * Add facets from `source` to `this` polyface.
185
+ * * Optionally reverse facet indices as per `PolyfaceData.reverseIndicesSingleFacet()` with `preserveStart = false` and
186
+ * invert source normals.
187
+ * * Optionally apply a `transform` to points and normals.
158
188
  * * Will only copy param, normal, color, and face data if we are already tracking them AND/OR the source contains them.
159
189
  */
160
190
  addIndexedPolyface(source, reversed, transform) {
161
191
  const numSourceFacets = source.facetCount;
162
- // Add point, point index, and edge visibility data
163
- // Note: there is no need to build an intermediate index map since all points are added
192
+ // add point, point index, and edge visibility data
193
+ // note that there is no need to build an intermediate index map since all points are added
164
194
  const startOfNewPoints = this.data.point.length;
165
195
  const xyz = Point3dVector3d_1.Point3d.create();
166
196
  for (let i = 0; i < source.data.point.length; i++) {
@@ -187,11 +217,11 @@ class IndexedPolyface extends Polyface {
187
217
  }
188
218
  this.terminateFacet(false);
189
219
  }
190
- // Add param and param index data
220
+ // add param and param index data
191
221
  if (undefined !== this.data.param && undefined !== source.data.param && undefined !== source.data.paramIndex) {
192
222
  const startOfNewParams = this.data.param.length;
193
223
  this.data.param.pushFromGrowableXYArray(source.data.param);
194
- for (let i = 0; i < numSourceFacets; i++) { // Expect facet start and ends for points to match normals
224
+ for (let i = 0; i < numSourceFacets; i++) { // expect facet start and ends for points to match normals
195
225
  const i0 = source._facetStart[i];
196
226
  const i1 = source._facetStart[i + 1];
197
227
  if (reversed) {
@@ -204,7 +234,7 @@ class IndexedPolyface extends Polyface {
204
234
  }
205
235
  }
206
236
  }
207
- // Add normal and normal index data
237
+ // add normal and normal index data
208
238
  if (undefined !== this.data.normal && undefined !== source.data.normal && undefined !== source.data.normalIndex) {
209
239
  const startOfNewNormals = this.data.normal.length;
210
240
  for (let i = 0; i < source.data.normal.length; i++) {
@@ -215,7 +245,7 @@ class IndexedPolyface extends Polyface {
215
245
  sourceNormal.scaleInPlace(-1.0);
216
246
  this.addNormal(sourceNormal);
217
247
  }
218
- for (let i = 0; i < numSourceFacets; i++) { // Expect facet start and ends for points to match normals
248
+ for (let i = 0; i < numSourceFacets; i++) { // expect facet start and ends for points to match normals
219
249
  const i0 = source._facetStart[i];
220
250
  const i1 = source._facetStart[i + 1];
221
251
  if (reversed) {
@@ -228,12 +258,12 @@ class IndexedPolyface extends Polyface {
228
258
  }
229
259
  }
230
260
  }
231
- // Add color and color index data
261
+ // add color and color index data
232
262
  if (undefined !== this.data.color && undefined !== source.data.color && undefined !== source.data.colorIndex) {
233
263
  const startOfNewColors = this.data.color.length;
234
264
  for (const sourceColor of source.data.color)
235
265
  this.addColor(sourceColor);
236
- for (let i = 0; i < numSourceFacets; i++) { // Expect facet start and ends for points to match colors
266
+ for (let i = 0; i < numSourceFacets; i++) { // expect facet start and ends for points to match colors
237
267
  const i0 = source._facetStart[i];
238
268
  const i1 = source._facetStart[i + 1];
239
269
  if (reversed) {
@@ -246,7 +276,7 @@ class IndexedPolyface extends Polyface {
246
276
  }
247
277
  }
248
278
  }
249
- // Add face and facetToFace index data
279
+ // add face and facetToFace index data
250
280
  if (source.data.face.length !== 0) {
251
281
  const startOfNewFaceData = this.data.face.length;
252
282
  for (const face of source.data.face) {
@@ -258,25 +288,31 @@ class IndexedPolyface extends Polyface {
258
288
  }
259
289
  }
260
290
  }
261
- /** Return the total number of param indices in zero-terminated style, which includes
262
- * * all the indices in the packed zero-based table
291
+ /**
292
+ * Return the total number of indices in zero-terminated style, which includes
293
+ * * all the indices in the packed zero-based table.
263
294
  * * one additional index for the zero-terminator of each facet.
264
- * @note Note that all index arrays (point, normal, param, color) have the same counts, so there
295
+ * @note Note that all index arrays (pointIndex, normalIndex, paramIndex, colorIndex) have the same counts, so there
265
296
  * is not a separate query for each of them.
266
297
  */
267
- get zeroTerminatedIndexCount() { return this.data.pointIndex.length + this._facetStart.length - 1; }
268
- /** Create an empty facet set, with coordinate and index data to be supplied later.
269
- * @param needNormals true if normals will be constructed
270
- * @param needParams true if uv parameters will be constructed
271
- * @param needColors true if colors will e constructed.
298
+ get zeroTerminatedIndexCount() {
299
+ return this.data.pointIndex.length + this._facetStart.length - 1;
300
+ }
301
+ /**
302
+ * Create an empty facet set with coordinate and index data to be supplied later.
303
+ * @param needNormals `true` to allocate empty normal data and index arrays; `false` (default) to leave undefined.
304
+ * @param needParams `true` to allocate empty uv parameter data and index arrays; `false` (default) to leave undefined.
305
+ * @param needColors `true` to allocate empty color data and index arrays; `false` (default) to leave undefined.
306
+ * @param twoSided `true` if the facets are to be considered viewable from the back; `false` (default) if not.
272
307
  */
273
308
  static create(needNormals = false, needParams = false, needColors = false, twoSided = false) {
274
309
  return new IndexedPolyface(new PolyfaceData_1.PolyfaceData(needNormals, needParams, needColors, twoSided));
275
310
  }
276
- /** add (a clone of ) a point. return its 0 based index.
277
- * @param point point coordinates
278
- * @param priorIndex optional index of prior point to check for repeated coordinates
279
- * @returns Returns the zero-based index of the added or reused point.
311
+ /**
312
+ * Add (a clone of) a point to point array.
313
+ * @param point the point.
314
+ * @param priorIndex (optional) index of prior point to check for possible duplicate value.
315
+ * @returns the zero-based index of the added or duplicate point.
280
316
  */
281
317
  addPoint(point, priorIndex) {
282
318
  if (priorIndex !== undefined) {
@@ -287,12 +323,21 @@ class IndexedPolyface extends Polyface {
287
323
  this.data.point.pushXYZ(point.x, point.y, point.z);
288
324
  return this.data.point.length - 1;
289
325
  }
290
- /** add a point.
291
- * @returns Returns the zero-based index of the added point.
326
+ /**
327
+ * Add a point to point array.
328
+ * @param x the x coordinate of point.
329
+ * @param y the y coordinate of point.
330
+ * @param z the z coordinate of point.
331
+ * @returns the zero-based index of the added point.
292
332
  */
293
- addPointXYZ(x, y, z) { this.data.point.pushXYZ(x, y, z); return this.data.point.length - 1; }
294
- /** Add a uv param.
295
- * @returns 0-based index of the added param.
333
+ addPointXYZ(x, y, z) {
334
+ this.data.point.pushXYZ(x, y, z);
335
+ return this.data.point.length - 1;
336
+ }
337
+ /**
338
+ * Add (a clone of) a uv parameter to the parameter array.
339
+ * @param param the parameter.
340
+ * @returns zero-based index of the added param.
296
341
  */
297
342
  addParam(param) {
298
343
  if (!this.data.param)
@@ -300,10 +345,13 @@ class IndexedPolyface extends Polyface {
300
345
  this.data.param.push(param);
301
346
  return this.data.param.length - 1;
302
347
  }
303
- /** Add a uv parameter to the parameter array.
348
+ /**
349
+ * Add a uv parameter to the parameter array.
350
+ * @param u the u part of parameter.
351
+ * @param v the v part of parameter.
304
352
  * @param priorIndexA first index to check for possible duplicate value.
305
353
  * @param priorIndexB second index to check for possible duplicate value.
306
- * @returns 0-based index of the added or reused param.
354
+ * @returns zero-based index of the added or duplicate parameter.
307
355
  */
308
356
  addParamUV(u, v, priorIndexA, priorIndexB) {
309
357
  if (!this.data.param)
@@ -315,37 +363,39 @@ class IndexedPolyface extends Polyface {
315
363
  this.data.param.pushXY(u, v);
316
364
  return this.data.param.length - 1;
317
365
  }
318
- /** Add a normal vector
366
+ /**
367
+ * Add (a clone of) a normal vector to the normal array.
368
+ * @param normal the normal vector.
319
369
  * @param priorIndexA first index to check for possible duplicate value.
320
370
  * @param priorIndexB second index to check for possible duplicate value.
321
- * @returns 0-based index of the added or reused normal.
371
+ * @returns zero-based index of the added or duplicate normal.
322
372
  */
323
373
  addNormal(normal, priorIndexA, priorIndexB) {
374
+ // check if `normal` is duplicate of `dataNormal` at index `i`
375
+ const normalIsDuplicate = (i) => {
376
+ const distance = this.data.normal.distanceIndexToPoint(i, normal);
377
+ return distance !== undefined && Geometry_1.Geometry.isSmallMetricDistance(distance);
378
+ };
324
379
  if (this.data.normal !== undefined) {
325
- let distance;
326
- if (priorIndexA !== undefined) {
327
- distance = this.data.normal.distanceIndexToPoint(priorIndexA, normal);
328
- if (distance !== undefined && Geometry_1.Geometry.isSmallMetricDistance(distance))
329
- return priorIndexA;
330
- }
331
- if (priorIndexB !== undefined) {
332
- distance = this.data.normal.distanceIndexToPoint(priorIndexB, normal);
333
- if (distance !== undefined && Geometry_1.Geometry.isSmallMetricDistance(distance))
334
- return priorIndexB;
335
- }
336
- // Note: Do NOT attempt to chain to tail if no prior indices given.
337
- // But if they are, look also to the tail.
380
+ if (priorIndexA !== undefined && normalIsDuplicate(priorIndexA))
381
+ return priorIndexA;
382
+ if (priorIndexB !== undefined && normalIsDuplicate(priorIndexB))
383
+ return priorIndexB;
384
+ // check the tail index for possible duplicate
338
385
  if (priorIndexA !== undefined || priorIndexB !== undefined) {
339
386
  const tailIndex = this.data.normal.length - 1;
340
- distance = this.data.normal.distanceIndexToPoint(tailIndex, normal);
341
- if (distance !== undefined && Geometry_1.Geometry.isSmallMetricDistance(distance))
387
+ if (normalIsDuplicate(tailIndex))
342
388
  return tailIndex;
343
389
  }
344
390
  }
345
391
  return this.addNormalXYZ(normal.x, normal.y, normal.z);
346
392
  }
347
- /** Add a normal vector given by direct coordinates
348
- * @returns 0-based index of the added or reused param.
393
+ /**
394
+ * Add a normal vector to the normal array.
395
+ * @param x the x coordinate of normal.
396
+ * @param y the y coordinate of normal.
397
+ * @param z the z coordinate of normal.
398
+ * @returns zero-based index of the added normal vector.
349
399
  */
350
400
  addNormalXYZ(x, y, z) {
351
401
  if (!this.data.normal)
@@ -353,8 +403,10 @@ class IndexedPolyface extends Polyface {
353
403
  this.data.normal.pushXYZ(x, y, z);
354
404
  return this.data.normal.length - 1;
355
405
  }
356
- /** Add a color
357
- * @returns 0-based index of the added or reused color.
406
+ /**
407
+ * Add a color to the color array
408
+ * @param color the color.
409
+ * @returns zero-based index of the added color.
358
410
  */
359
411
  addColor(color) {
360
412
  if (!this.data.color)
@@ -363,46 +415,54 @@ class IndexedPolyface extends Polyface {
363
415
  return this.data.color.length - 1;
364
416
  }
365
417
  /** Add a point index with edge visibility flag. */
366
- addPointIndex(index, visible = true) { this.data.pointIndex.push(index); this.data.edgeVisible.push(visible); }
367
- /** Add a normal index */
418
+ addPointIndex(index, visible = true) {
419
+ this.data.pointIndex.push(index);
420
+ this.data.edgeVisible.push(visible);
421
+ }
422
+ /** Add a normal index. */
368
423
  addNormalIndex(index) {
369
424
  if (!this.data.normalIndex)
370
425
  this.data.normalIndex = [];
371
426
  this.data.normalIndex.push(index);
372
427
  }
373
- /** Add a param index */
428
+ /** Add a param index. */
374
429
  addParamIndex(index) {
375
430
  if (!this.data.paramIndex)
376
431
  this.data.paramIndex = [];
377
432
  this.data.paramIndex.push(index);
378
433
  }
379
- /** Add a color index */
434
+ /** Add a color index. */
380
435
  addColorIndex(index) {
381
436
  if (!this.data.colorIndex)
382
437
  this.data.colorIndex = [];
383
438
  this.data.colorIndex.push(index);
384
439
  }
385
- /** clean up the open facet. return the returnValue (so caller can easily return cleanupOpenFacet("message")) */
440
+ /**
441
+ * Clean up the open facet.
442
+ * @deprecated in 4.x to remove nebulous "open facet" concept from the API. Call [[PolyfaceData.trimAllIndexArrays]]
443
+ * instead.
444
+ */
386
445
  cleanupOpenFacet() {
387
446
  this.data.trimAllIndexArrays(this.data.pointIndex.length);
388
447
  }
389
- /** announce the end of construction of a facet.
390
- *
391
- * * The "open" facet is checked for:
392
- *
393
- * ** Same number of indices among all active index arrays -- point, normal, param, color
394
- * ** All indices are within bounds of the respective data arrays.
395
- * * in error cases, all index arrays are trimmed back to the size when previous facet was terminated.
396
- * * "undefined" return is normal. Any other return is a description of an error.
448
+ /**
449
+ * Announce the end of construction of a facet.
450
+ * * Optionally check for:
451
+ * * Same number of indices among all active index arrays -- point, normal, param, color
452
+ * * All indices are within bounds of the respective data arrays.
453
+ * * In error cases, all index arrays are trimmed back to the size when previous facet was terminated.
454
+ * * A return value of `undefined` is normal. Otherwise, a string array of error messages is returned.
397
455
  */
398
456
  terminateFacet(validateAllIndices = true) {
399
457
  const numFacets = this._facetStart.length - 1;
400
- const lengthA = this._facetStart[numFacets]; // number of indices in accepted facets
401
- const lengthB = this.data.pointIndex.length; // number of indices including the open facet
458
+ // number of indices in accepted facets
459
+ const lengthA = this._facetStart[numFacets];
460
+ // number of indices in all facets (accepted facet plus the last facet to be accepted)
461
+ const lengthB = this.data.pointIndex.length;
402
462
  if (validateAllIndices) {
403
463
  const messages = [];
404
464
  if (lengthB < lengthA + 2)
405
- messages.push("Less than 3 indices in open facet");
465
+ messages.push("Less than 3 indices in the last facet");
406
466
  if (this.data.normalIndex && this.data.normalIndex.length !== lengthB)
407
467
  messages.push("normalIndex count must match pointIndex count");
408
468
  if (this.data.paramIndex && this.data.paramIndex.length !== lengthB)
@@ -411,71 +471,100 @@ class IndexedPolyface extends Polyface {
411
471
  messages.push("colorIndex count must equal pointIndex count");
412
472
  if (this.data.edgeVisible.length !== lengthB)
413
473
  messages.push("visibleIndex count must equal pointIndex count");
474
+ if (!Polyface.areIndicesValid(this.data.pointIndex, lengthA, lengthB, this.data.point, this.data.point ? this.data.point.length : 0))
475
+ messages.push("invalid point indices in the last facet");
414
476
  if (!Polyface.areIndicesValid(this.data.normalIndex, lengthA, lengthB, this.data.normal, this.data.normal ? this.data.normal.length : 0))
415
- messages.push("invalid normal indices in open facet");
477
+ messages.push("invalid normal indices in the last facet");
478
+ if (!Polyface.areIndicesValid(this.data.paramIndex, lengthA, lengthB, this.data.param, this.data.param ? this.data.param.length : 0))
479
+ messages.push("invalid param indices in the last facet");
480
+ if (!Polyface.areIndicesValid(this.data.colorIndex, lengthA, lengthB, this.data.color, this.data.color ? this.data.color.length : 0))
481
+ messages.push("invalid color indices in the last facet");
416
482
  if (messages.length > 0) {
417
- this.cleanupOpenFacet();
483
+ this.data.trimAllIndexArrays(lengthA);
418
484
  return messages;
419
485
  }
420
486
  }
421
- // appending to facetStart accepts the facet !!!
422
- this._facetStart.push(lengthB);
487
+ this._facetStart.push(lengthB); // append start index of the future facet
423
488
  return undefined;
424
489
  }
425
- /**
426
- * All terminated facets added since the declaration of the previous face
427
- * will be grouped into a new face with their own 2D range.
428
- */
429
- /** (read-only property) number of facets */
430
- get facetCount() { return this._facetStart.length - 1; }
431
- /** (read-only property) number of faces */
432
- get faceCount() { return this.data.faceCount; }
433
- /** (read-only property) number of points */
434
- get pointCount() { return this.data.pointCount; }
435
- /** (read-only property) number of colors */
436
- get colorCount() { return this.data.colorCount; }
437
- /** (read-only property) number of parameters */
438
- get paramCount() { return this.data.paramCount; }
439
- /** (read-only property) number of normals */
440
- get normalCount() { return this.data.normalCount; }
490
+ /** Number of facets (read-only property). */
491
+ get facetCount() {
492
+ return this._facetStart.length - 1;
493
+ }
494
+ /** Number of faces (read-only property). */
495
+ get faceCount() {
496
+ return this.data.faceCount;
497
+ }
498
+ /** Number of points (read-only property). */
499
+ get pointCount() {
500
+ return this.data.pointCount;
501
+ }
502
+ /** Number of colors (read-only property). */
503
+ get colorCount() {
504
+ return this.data.colorCount;
505
+ }
506
+ /** Number of parameters (read-only property). */
507
+ get paramCount() {
508
+ return this.data.paramCount;
509
+ }
510
+ /** Number of normals (read-only property). */
511
+ get normalCount() {
512
+ return this.data.normalCount;
513
+ }
514
+ /** Test if `index` is a valid facet index. */
515
+ isValidFacetIndex(index) {
516
+ return index >= 0 && index < this.facetCount;
517
+ }
441
518
  /** Return the number of edges in a particular facet. */
442
519
  numEdgeInFacet(facetIndex) {
443
520
  if (this.isValidFacetIndex(facetIndex))
444
521
  return this._facetStart[facetIndex + 1] - this._facetStart[facetIndex];
445
522
  return 0;
446
523
  }
447
- /** test if `index` is a valid facet index. */
448
- isValidFacetIndex(index) { return index >= 0 && index + 1 < this._facetStart.length; }
449
- /** ASSUME valid facet index . .. return its start index in index arrays. */
450
- facetIndex0(index) { return this._facetStart[index]; }
451
- /** ASSUME valid facet index . .. return its end index in index arrays. */
452
- facetIndex1(index) { return this._facetStart[index + 1]; }
453
- /** create a visitor for this polyface */
454
- createVisitor(numWrap = 0) { return IndexedPolyfaceVisitor_1.IndexedPolyfaceVisitor.create(this, numWrap); }
524
+ /** ASSUME valid facet index. Return start index of facet in pointIndex arrays. */
525
+ facetIndex0(index) {
526
+ return this._facetStart[index];
527
+ }
528
+ /** ASSUME valid facet index. Return one past end index of facet in pointIndex arrays. */
529
+ facetIndex1(index) {
530
+ return this._facetStart[index + 1];
531
+ }
532
+ /** Create a visitor for this polyface */
533
+ createVisitor(numWrap = 0) {
534
+ return IndexedPolyfaceVisitor_1.IndexedPolyfaceVisitor.create(this, numWrap);
535
+ }
455
536
  /** Return the range of (optionally transformed) points in this mesh. */
456
- range(transform, result) { return this.data.range(result, transform); }
457
- /** Extend `range` with coordinates from this mesh */
458
- extendRange(range, transform) { this.data.range(range, transform); }
459
- /** Given the index of a facet, return the data pertaining to the face it is a part of. */
537
+ range(transform, result) {
538
+ return this.data.range(result, transform);
539
+ }
540
+ /** Extend `range` with coordinates from this mesh. */
541
+ extendRange(range, transform) {
542
+ this.data.range(range, transform);
543
+ }
544
+ /**
545
+ * Given the index of a facet, return the data pertaining to the face it is a part of.
546
+ * @deprecated in 4.x. Use [[IndexedPolyface.tryGetFaceData]], which verifies the index is in range.
547
+ */
460
548
  getFaceDataByFacetIndex(facetIndex) {
461
549
  return this.data.face[this._facetToFaceData[facetIndex]];
462
550
  }
463
551
  /**
464
- * All terminated facets since the last face declaration will be mapped to a single new FacetFaceData object
465
- * using facetToFaceData[]. FacetFaceData holds the 2D range of the face. Returns true if successful, false otherwise.
552
+ * Set new FacetFaceData.
553
+ * * All terminated facets since the last face declaration will be mapped to a single new FacetFaceData object using
554
+ * facetToFaceData[]. FacetFaceData holds the 2D range of the face. Returns `true` if successful, `false` otherwise.
466
555
  */
467
556
  setNewFaceData(endFacetIndex = 0) {
468
557
  const facetStart = this._facetToFaceData.length;
469
558
  if (facetStart >= this._facetStart.length)
470
559
  return false;
471
- if (0 === endFacetIndex) // The default for endFacetIndex is really the last facet
472
- endFacetIndex = this._facetStart.length; // Last facetStart index corresponds to the next facet if we were to create one
560
+ if (0 === endFacetIndex) // the default for endFacetIndex is really the last facet
561
+ endFacetIndex = this._facetStart.length; // last facet index corresponds to the future facet
473
562
  const faceData = FacetFaceData_1.FacetFaceData.createNull();
474
563
  const visitor = IndexedPolyfaceVisitor_1.IndexedPolyfaceVisitor.create(this, 0);
475
- if (!visitor.moveToReadIndex(facetStart)) { // Move visitor to first facet of new face
564
+ if (!visitor.moveToReadIndex(facetStart)) { // move visitor to first facet of new face
476
565
  return false;
477
566
  }
478
- // If parameter range is provided (by the polyface planeSet clipper) then use it
567
+ // if parameter range is provided (by the polyface planeSet clipper) then use it
479
568
  const paramDefined = this.data.param !== undefined;
480
569
  const setParamRange = faceData.paramRange.isNull && paramDefined;
481
570
  do {
@@ -490,7 +579,7 @@ class IndexedPolyface extends Polyface {
490
579
  this._facetToFaceData.push(0 === this._facetStart[i] ? 0 : faceDataIndex);
491
580
  return true;
492
581
  }
493
- /** Second step of double dispatch: call `handler.handleIndexedPolyface(this)` */
582
+ /** Second step of double dispatch: call `handler.handleIndexedPolyface(this)`. */
494
583
  dispatchToGeometryHandler(handler) {
495
584
  return handler.handleIndexedPolyface(this);
496
585
  }