@itwin/core-geometry 4.5.0-dev.4 → 4.5.0-dev.7

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