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