@itwin/core-geometry 3.3.0-dev.8 → 3.3.0-dev.80

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 (172) hide show
  1. package/CHANGELOG.md +26 -1
  2. package/lib/cjs/curve/Arc3d.d.ts +13 -2
  3. package/lib/cjs/curve/Arc3d.d.ts.map +1 -1
  4. package/lib/cjs/curve/Arc3d.js +21 -3
  5. package/lib/cjs/curve/Arc3d.js.map +1 -1
  6. package/lib/cjs/curve/CurveChainWithDistanceIndex.d.ts +36 -2
  7. package/lib/cjs/curve/CurveChainWithDistanceIndex.d.ts.map +1 -1
  8. package/lib/cjs/curve/CurveChainWithDistanceIndex.js +157 -7
  9. package/lib/cjs/curve/CurveChainWithDistanceIndex.js.map +1 -1
  10. package/lib/cjs/curve/CurveCollection.d.ts +2 -0
  11. package/lib/cjs/curve/CurveCollection.d.ts.map +1 -1
  12. package/lib/cjs/curve/CurveCollection.js +8 -0
  13. package/lib/cjs/curve/CurveCollection.js.map +1 -1
  14. package/lib/cjs/curve/CurvePrimitive.d.ts +23 -0
  15. package/lib/cjs/curve/CurvePrimitive.d.ts.map +1 -1
  16. package/lib/cjs/curve/CurvePrimitive.js +65 -0
  17. package/lib/cjs/curve/CurvePrimitive.js.map +1 -1
  18. package/lib/cjs/curve/LineSegment3d.d.ts +5 -0
  19. package/lib/cjs/curve/LineSegment3d.d.ts.map +1 -1
  20. package/lib/cjs/curve/LineSegment3d.js +21 -0
  21. package/lib/cjs/curve/LineSegment3d.js.map +1 -1
  22. package/lib/cjs/curve/LineString3d.d.ts +2 -0
  23. package/lib/cjs/curve/LineString3d.d.ts.map +1 -1
  24. package/lib/cjs/curve/LineString3d.js +28 -0
  25. package/lib/cjs/curve/LineString3d.js.map +1 -1
  26. package/lib/cjs/curve/spiral/DirectSpiral3d.d.ts +2 -5
  27. package/lib/cjs/curve/spiral/DirectSpiral3d.d.ts.map +1 -1
  28. package/lib/cjs/curve/spiral/DirectSpiral3d.js +6 -8
  29. package/lib/cjs/curve/spiral/DirectSpiral3d.js.map +1 -1
  30. package/lib/cjs/curve/spiral/IntegratedSpiral3d.d.ts +0 -3
  31. package/lib/cjs/curve/spiral/IntegratedSpiral3d.d.ts.map +1 -1
  32. package/lib/cjs/curve/spiral/IntegratedSpiral3d.js +0 -4
  33. package/lib/cjs/curve/spiral/IntegratedSpiral3d.js.map +1 -1
  34. package/lib/cjs/curve/spiral/TransitionSpiral3d.d.ts +7 -0
  35. package/lib/cjs/curve/spiral/TransitionSpiral3d.d.ts.map +1 -1
  36. package/lib/cjs/curve/spiral/TransitionSpiral3d.js +17 -0
  37. package/lib/cjs/curve/spiral/TransitionSpiral3d.js.map +1 -1
  38. package/lib/cjs/geometry3d/GrowableBlockedArray.d.ts +32 -3
  39. package/lib/cjs/geometry3d/GrowableBlockedArray.d.ts.map +1 -1
  40. package/lib/cjs/geometry3d/GrowableBlockedArray.js +63 -14
  41. package/lib/cjs/geometry3d/GrowableBlockedArray.js.map +1 -1
  42. package/lib/cjs/geometry3d/GrowableFloat64Array.d.ts +24 -8
  43. package/lib/cjs/geometry3d/GrowableFloat64Array.d.ts.map +1 -1
  44. package/lib/cjs/geometry3d/GrowableFloat64Array.js +72 -54
  45. package/lib/cjs/geometry3d/GrowableFloat64Array.js.map +1 -1
  46. package/lib/cjs/geometry3d/GrowableXYArray.d.ts +51 -26
  47. package/lib/cjs/geometry3d/GrowableXYArray.d.ts.map +1 -1
  48. package/lib/cjs/geometry3d/GrowableXYArray.js +136 -116
  49. package/lib/cjs/geometry3d/GrowableXYArray.js.map +1 -1
  50. package/lib/cjs/geometry3d/GrowableXYZArray.d.ts +35 -21
  51. package/lib/cjs/geometry3d/GrowableXYZArray.d.ts.map +1 -1
  52. package/lib/cjs/geometry3d/GrowableXYZArray.js +124 -137
  53. package/lib/cjs/geometry3d/GrowableXYZArray.js.map +1 -1
  54. package/lib/cjs/geometry3d/Point3dVector3d.d.ts +1 -1
  55. package/lib/cjs/geometry3d/Point3dVector3d.d.ts.map +1 -1
  56. package/lib/cjs/geometry3d/Point3dVector3d.js +2 -3
  57. package/lib/cjs/geometry3d/Point3dVector3d.js.map +1 -1
  58. package/lib/cjs/geometry3d/PolygonOps.d.ts +8 -2
  59. package/lib/cjs/geometry3d/PolygonOps.d.ts.map +1 -1
  60. package/lib/cjs/geometry3d/PolygonOps.js +40 -3
  61. package/lib/cjs/geometry3d/PolygonOps.js.map +1 -1
  62. package/lib/cjs/geometry3d/Range.d.ts +12 -0
  63. package/lib/cjs/geometry3d/Range.d.ts.map +1 -1
  64. package/lib/cjs/geometry3d/Range.js +32 -0
  65. package/lib/cjs/geometry3d/Range.js.map +1 -1
  66. package/lib/cjs/geometry3d/Transform.d.ts +1 -1
  67. package/lib/cjs/geometry3d/Transform.d.ts.map +1 -1
  68. package/lib/cjs/geometry3d/Transform.js +1 -1
  69. package/lib/cjs/geometry3d/Transform.js.map +1 -1
  70. package/lib/cjs/geometry3d/XYZProps.d.ts +10 -3
  71. package/lib/cjs/geometry3d/XYZProps.d.ts.map +1 -1
  72. package/lib/cjs/geometry3d/XYZProps.js +21 -0
  73. package/lib/cjs/geometry3d/XYZProps.js.map +1 -1
  74. package/lib/cjs/polyface/PolyfaceClip.d.ts.map +1 -1
  75. package/lib/cjs/polyface/PolyfaceClip.js +1 -1
  76. package/lib/cjs/polyface/PolyfaceClip.js.map +1 -1
  77. package/lib/cjs/polyface/PolyfaceQuery.d.ts +4 -2
  78. package/lib/cjs/polyface/PolyfaceQuery.d.ts.map +1 -1
  79. package/lib/cjs/polyface/PolyfaceQuery.js +10 -6
  80. package/lib/cjs/polyface/PolyfaceQuery.js.map +1 -1
  81. package/lib/cjs/topology/Merging.js +3 -3
  82. package/lib/cjs/topology/Merging.js.map +1 -1
  83. package/lib/cjs/topology/Triangulation.d.ts +1 -3
  84. package/lib/cjs/topology/Triangulation.d.ts.map +1 -1
  85. package/lib/cjs/topology/Triangulation.js +31 -21
  86. package/lib/cjs/topology/Triangulation.js.map +1 -1
  87. package/lib/esm/curve/Arc3d.d.ts +13 -2
  88. package/lib/esm/curve/Arc3d.d.ts.map +1 -1
  89. package/lib/esm/curve/Arc3d.js +22 -4
  90. package/lib/esm/curve/Arc3d.js.map +1 -1
  91. package/lib/esm/curve/CurveChainWithDistanceIndex.d.ts +36 -2
  92. package/lib/esm/curve/CurveChainWithDistanceIndex.d.ts.map +1 -1
  93. package/lib/esm/curve/CurveChainWithDistanceIndex.js +157 -7
  94. package/lib/esm/curve/CurveChainWithDistanceIndex.js.map +1 -1
  95. package/lib/esm/curve/CurveCollection.d.ts +2 -0
  96. package/lib/esm/curve/CurveCollection.d.ts.map +1 -1
  97. package/lib/esm/curve/CurveCollection.js +8 -0
  98. package/lib/esm/curve/CurveCollection.js.map +1 -1
  99. package/lib/esm/curve/CurvePrimitive.d.ts +23 -0
  100. package/lib/esm/curve/CurvePrimitive.d.ts.map +1 -1
  101. package/lib/esm/curve/CurvePrimitive.js +65 -0
  102. package/lib/esm/curve/CurvePrimitive.js.map +1 -1
  103. package/lib/esm/curve/LineSegment3d.d.ts +5 -0
  104. package/lib/esm/curve/LineSegment3d.d.ts.map +1 -1
  105. package/lib/esm/curve/LineSegment3d.js +21 -0
  106. package/lib/esm/curve/LineSegment3d.js.map +1 -1
  107. package/lib/esm/curve/LineString3d.d.ts +2 -0
  108. package/lib/esm/curve/LineString3d.d.ts.map +1 -1
  109. package/lib/esm/curve/LineString3d.js +28 -0
  110. package/lib/esm/curve/LineString3d.js.map +1 -1
  111. package/lib/esm/curve/spiral/DirectSpiral3d.d.ts +2 -5
  112. package/lib/esm/curve/spiral/DirectSpiral3d.d.ts.map +1 -1
  113. package/lib/esm/curve/spiral/DirectSpiral3d.js +6 -8
  114. package/lib/esm/curve/spiral/DirectSpiral3d.js.map +1 -1
  115. package/lib/esm/curve/spiral/IntegratedSpiral3d.d.ts +0 -3
  116. package/lib/esm/curve/spiral/IntegratedSpiral3d.d.ts.map +1 -1
  117. package/lib/esm/curve/spiral/IntegratedSpiral3d.js +0 -4
  118. package/lib/esm/curve/spiral/IntegratedSpiral3d.js.map +1 -1
  119. package/lib/esm/curve/spiral/TransitionSpiral3d.d.ts +7 -0
  120. package/lib/esm/curve/spiral/TransitionSpiral3d.d.ts.map +1 -1
  121. package/lib/esm/curve/spiral/TransitionSpiral3d.js +17 -0
  122. package/lib/esm/curve/spiral/TransitionSpiral3d.js.map +1 -1
  123. package/lib/esm/geometry3d/GrowableBlockedArray.d.ts +32 -3
  124. package/lib/esm/geometry3d/GrowableBlockedArray.d.ts.map +1 -1
  125. package/lib/esm/geometry3d/GrowableBlockedArray.js +63 -14
  126. package/lib/esm/geometry3d/GrowableBlockedArray.js.map +1 -1
  127. package/lib/esm/geometry3d/GrowableFloat64Array.d.ts +24 -8
  128. package/lib/esm/geometry3d/GrowableFloat64Array.d.ts.map +1 -1
  129. package/lib/esm/geometry3d/GrowableFloat64Array.js +72 -54
  130. package/lib/esm/geometry3d/GrowableFloat64Array.js.map +1 -1
  131. package/lib/esm/geometry3d/GrowableXYArray.d.ts +51 -26
  132. package/lib/esm/geometry3d/GrowableXYArray.d.ts.map +1 -1
  133. package/lib/esm/geometry3d/GrowableXYArray.js +136 -116
  134. package/lib/esm/geometry3d/GrowableXYArray.js.map +1 -1
  135. package/lib/esm/geometry3d/GrowableXYZArray.d.ts +35 -21
  136. package/lib/esm/geometry3d/GrowableXYZArray.d.ts.map +1 -1
  137. package/lib/esm/geometry3d/GrowableXYZArray.js +124 -137
  138. package/lib/esm/geometry3d/GrowableXYZArray.js.map +1 -1
  139. package/lib/esm/geometry3d/Point3dVector3d.d.ts +1 -1
  140. package/lib/esm/geometry3d/Point3dVector3d.d.ts.map +1 -1
  141. package/lib/esm/geometry3d/Point3dVector3d.js +2 -3
  142. package/lib/esm/geometry3d/Point3dVector3d.js.map +1 -1
  143. package/lib/esm/geometry3d/PolygonOps.d.ts +8 -2
  144. package/lib/esm/geometry3d/PolygonOps.d.ts.map +1 -1
  145. package/lib/esm/geometry3d/PolygonOps.js +40 -3
  146. package/lib/esm/geometry3d/PolygonOps.js.map +1 -1
  147. package/lib/esm/geometry3d/Range.d.ts +12 -0
  148. package/lib/esm/geometry3d/Range.d.ts.map +1 -1
  149. package/lib/esm/geometry3d/Range.js +32 -0
  150. package/lib/esm/geometry3d/Range.js.map +1 -1
  151. package/lib/esm/geometry3d/Transform.d.ts +1 -1
  152. package/lib/esm/geometry3d/Transform.d.ts.map +1 -1
  153. package/lib/esm/geometry3d/Transform.js +1 -1
  154. package/lib/esm/geometry3d/Transform.js.map +1 -1
  155. package/lib/esm/geometry3d/XYZProps.d.ts +10 -3
  156. package/lib/esm/geometry3d/XYZProps.d.ts.map +1 -1
  157. package/lib/esm/geometry3d/XYZProps.js +20 -1
  158. package/lib/esm/geometry3d/XYZProps.js.map +1 -1
  159. package/lib/esm/polyface/PolyfaceClip.d.ts.map +1 -1
  160. package/lib/esm/polyface/PolyfaceClip.js +1 -1
  161. package/lib/esm/polyface/PolyfaceClip.js.map +1 -1
  162. package/lib/esm/polyface/PolyfaceQuery.d.ts +4 -2
  163. package/lib/esm/polyface/PolyfaceQuery.d.ts.map +1 -1
  164. package/lib/esm/polyface/PolyfaceQuery.js +10 -6
  165. package/lib/esm/polyface/PolyfaceQuery.js.map +1 -1
  166. package/lib/esm/topology/Merging.js +3 -3
  167. package/lib/esm/topology/Merging.js.map +1 -1
  168. package/lib/esm/topology/Triangulation.d.ts +1 -3
  169. package/lib/esm/topology/Triangulation.d.ts.map +1 -1
  170. package/lib/esm/topology/Triangulation.js +31 -21
  171. package/lib/esm/topology/Triangulation.js.map +1 -1
  172. package/package.json +7 -7
@@ -19,59 +19,81 @@ const Transform_1 = require("./Transform");
19
19
  */
20
20
  class GrowableXYZArray extends IndexedXYZCollection_1.IndexedReadWriteXYZCollection {
21
21
  /** Construct a new GrowablePoint3d array.
22
- * @param numPoints [in] initial capacity.
22
+ * @param numPoints initial capacity in xyz triples (default 8)
23
+ * @param growthFactor used by ensureCapacity to expand requested reallocation size (default 1.5)
23
24
  */
24
- constructor(numPoints = 8) {
25
+ constructor(numPoints = 8, growthFactor) {
25
26
  super();
26
- this._data = new Float64Array(numPoints * 3); // 8 Points to start (3 values each)
27
+ this._data = new Float64Array(numPoints * 3); // 3 values per point
27
28
  this._xyzInUse = 0;
28
29
  this._xyzCapacity = numPoints;
30
+ this._growthFactor = (undefined !== growthFactor && growthFactor >= 1.0) ? growthFactor : 1.5;
31
+ }
32
+ /** Copy xyz points from source array. Does not reallocate or change active point count.
33
+ * @param source array to copy from
34
+ * @param sourceCount copy the first sourceCount points; all points if undefined
35
+ * @param destOffset copy to instance array starting at this point index; zero if undefined
36
+ * @return count and offset of points copied
37
+ */
38
+ copyData(source, sourceCount, destOffset) {
39
+ // validate inputs and convert from points to entries
40
+ let myOffset = (undefined !== destOffset) ? destOffset * 3 : 0;
41
+ if (myOffset < 0)
42
+ myOffset = 0;
43
+ if (myOffset >= this._data.length)
44
+ return { count: 0, offset: 0 };
45
+ let myCount = (undefined !== sourceCount) ? sourceCount * 3 : source.length;
46
+ if (myCount > 0) {
47
+ if (myCount > source.length)
48
+ myCount = source.length;
49
+ if (myOffset + myCount > this._data.length)
50
+ myCount = this._data.length - myOffset;
51
+ if (myCount % 3 !== 0)
52
+ myCount -= myCount % 3;
53
+ }
54
+ if (myCount <= 0)
55
+ return { count: 0, offset: 0 };
56
+ if (myCount === source.length)
57
+ this._data.set(source, myOffset);
58
+ else if (source instanceof Float64Array)
59
+ this._data.set(source.subarray(0, myCount), myOffset);
60
+ else
61
+ this._data.set(source.slice(0, myCount), myOffset);
62
+ return { count: myCount / 3, offset: myOffset / 3 };
29
63
  }
30
64
  /** The number of points in use. When the length is increased, the array is padded with zeroes. */
31
65
  get length() { return this._xyzInUse; }
32
- set length(newLength) {
33
- let oldLength = this.length;
34
- if (newLength < oldLength) {
35
- this._xyzInUse = newLength;
36
- }
37
- else if (newLength > oldLength) {
38
- this.ensureCapacity(newLength);
39
- while (oldLength++ < newLength)
40
- this.pushXYZ(0, 0, 0);
41
- }
42
- }
66
+ set length(newLength) { this.resize(newLength, true); }
43
67
  /** Return the number of float64 in use. */
44
68
  get float64Length() { return this._xyzInUse * 3; }
45
69
  /** Return the raw packed data.
46
70
  * * Note that the length of the returned Float64Array is a count of doubles, and includes the excess capacity
47
71
  */
48
72
  float64Data() { return this._data; }
49
- /** If necessary, increase the capacity to a new pointCount. Current coordinates and point count (length) are unchanged. */
50
- ensureCapacity(pointCapacity) {
73
+ /** If necessary, increase the capacity to the new number of points. Current coordinates and point count (length) are unchanged. */
74
+ ensureCapacity(pointCapacity, applyGrowthFactor = true) {
51
75
  if (pointCapacity > this._xyzCapacity) {
52
- const newData = new Float64Array(pointCapacity * 3);
53
- const numCopy = this.length * 3;
54
- for (let i = 0; i < numCopy; i++)
55
- newData[i] = this._data[i];
56
- this._data = newData;
76
+ if (applyGrowthFactor)
77
+ pointCapacity *= this._growthFactor;
78
+ const prevData = this._data;
79
+ this._data = new Float64Array(pointCapacity * 3);
80
+ this.copyData(prevData, this._xyzInUse);
57
81
  this._xyzCapacity = pointCapacity;
58
82
  }
59
83
  }
60
- /** Resize the actual point count, preserving excess capacity. */
61
- resize(pointCount) {
62
- if (pointCount < this.length) {
63
- this._xyzInUse = pointCount >= 0 ? pointCount : 0;
64
- }
65
- else if (pointCount > this._xyzCapacity) {
66
- const newArray = new Float64Array(pointCount * 3);
67
- // Copy contents
68
- for (let i = 0; i < this._data.length; i += 3) {
69
- newArray[i] = this._data[i];
70
- newArray[i + 1] = this._data[i + 1];
71
- newArray[i + 2] = this._data[i + 2];
72
- }
73
- this._data = newArray;
74
- this._xyzCapacity = pointCount;
84
+ /**
85
+ * * If pointCount is less than current length, just reset current length to pointCount, effectively trimming active points but preserving original capacity.
86
+ * * If pointCount is greater than current length, reallocate to exactly pointCount, copy existing points, and optionally pad excess with zero.
87
+ * @param pointCount new number of active points in array
88
+ * @param padWithZero when increasing point count, whether to zero out new points (default false)
89
+ */
90
+ resize(pointCount, padWithZero) {
91
+ if (pointCount >= 0 && pointCount < this._xyzInUse)
92
+ this._xyzInUse = pointCount;
93
+ else if (pointCount > this._xyzInUse) {
94
+ this.ensureCapacity(pointCount, false);
95
+ if (padWithZero !== null && padWithZero !== void 0 ? padWithZero : false)
96
+ this._data.fill(0, this._xyzInUse * 3);
75
97
  this._xyzInUse = pointCount;
76
98
  }
77
99
  }
@@ -80,17 +102,14 @@ class GrowableXYZArray extends IndexedXYZCollection_1.IndexedReadWriteXYZCollect
80
102
  * (The clone does NOT get excess capacity)
81
103
  */
82
104
  clone(result) {
83
- const numValue = this.length * 3;
84
105
  if (!result)
85
106
  result = new GrowableXYZArray(this.length);
86
107
  else {
87
- result.clear();
88
- result.ensureCapacity(this.length);
108
+ if (result.length !== this.length)
109
+ result.clear(); // force resize to trim excess capacity
110
+ result.resize(this.length);
89
111
  }
90
- const newData = result._data;
91
- const data = this._data;
92
- for (let i = 0; i < numValue; i++)
93
- newData[i] = data[i];
112
+ result.copyData(this._data, this.length);
94
113
  result._xyzInUse = this.length;
95
114
  return result;
96
115
  }
@@ -125,6 +144,7 @@ class GrowableXYZArray extends IndexedXYZCollection_1.IndexedReadWriteXYZCollect
125
144
  }
126
145
  /** push all points of an array */
127
146
  pushAll(points) {
147
+ this.ensureCapacity(this._xyzInUse + points.length, false);
128
148
  for (const p of points)
129
149
  this.push(p);
130
150
  }
@@ -139,7 +159,6 @@ class GrowableXYZArray extends IndexedXYZCollection_1.IndexedReadWriteXYZCollect
139
159
  * * Any json object satisfying Point3d.isXAndY
140
160
  * * A Float64Array of doubles, interpreted as xyzxyz
141
161
  * * An array of any of the above
142
- * @returns the number of points added.
143
162
  */
144
163
  pushFrom(p) {
145
164
  if (p instanceof Point3dVector3d_1.Point3d)
@@ -148,10 +167,11 @@ class GrowableXYZArray extends IndexedXYZCollection_1.IndexedReadWriteXYZCollect
148
167
  this.pushFromGrowableXYZArray(p);
149
168
  else if (p instanceof Point2dVector2d_1.Point2d)
150
169
  this.pushXYZ(p.x, p.y, 0.0);
151
- else if (Geometry_1.Geometry.isNumberArray(p, 4)) {
152
- const n = p.length;
153
- for (let i = 0; i + 2 < n; i += 3)
154
- this.pushXYZ(p[i], p[i + 1], p[i + 2]);
170
+ else if (Geometry_1.Geometry.isNumberArray(p, 4) || p instanceof Float64Array) {
171
+ const xyzToAdd = Math.trunc(p.length / 3);
172
+ this.ensureCapacity(this._xyzInUse + xyzToAdd, false);
173
+ this.copyData(p, xyzToAdd, this._xyzInUse);
174
+ this._xyzInUse += xyzToAdd;
155
175
  }
156
176
  else if (Geometry_1.Geometry.isNumberArray(p, 3))
157
177
  this.pushXYZ(p[0], p[1], p[2]);
@@ -166,13 +186,10 @@ class GrowableXYZArray extends IndexedXYZCollection_1.IndexedReadWriteXYZCollect
166
186
  this.pushXYZ(p.x, p.y, p.z);
167
187
  else if (Point3dVector3d_1.Point3d.isXAndY(p))
168
188
  this.pushXYZ(p.x, p.y, 0.0);
169
- else if (p instanceof Float64Array) {
170
- const n = p.length;
171
- for (let i = 0; i + 2 < n; i += 3)
172
- this.pushXYZ(p[i], p[i + 1], p[i + 2]);
173
- }
174
189
  else if (p instanceof IndexedXYZCollection_1.IndexedXYZCollection) {
175
- for (let i = 0; i < p.length; i++)
190
+ const n = p.length;
191
+ this.ensureCapacity(this._xyzInUse + n, false);
192
+ for (let i = 0; i < n; i++)
176
193
  this.pushXYZ(p.getXAtUncheckedPointIndex(i), p.getYAtUncheckedPointIndex(i), p.getZAtUncheckedPointIndex(i));
177
194
  }
178
195
  }
@@ -181,19 +198,18 @@ class GrowableXYZArray extends IndexedXYZCollection_1.IndexedReadWriteXYZCollect
181
198
  * @param numWrap number of xyz values to replicate
182
199
  */
183
200
  pushWrap(numWrap) {
184
- if (this._xyzInUse > 0) {
185
- let k;
201
+ if (this._xyzInUse >= numWrap) {
202
+ this.ensureCapacity(this._xyzInUse + numWrap, false);
186
203
  for (let i = 0; i < numWrap; i++) {
187
- k = 3 * i;
204
+ const k = 3 * i;
188
205
  this.pushXYZ(this._data[k], this._data[k + 1], this._data[k + 2]);
189
206
  }
190
207
  }
191
208
  }
192
209
  /** append a new point with given x,y,z */
193
210
  pushXYZ(x, y, z) {
211
+ this.ensureCapacity(this._xyzInUse + 1);
194
212
  const index = this._xyzInUse * 3;
195
- if (index >= this._data.length)
196
- this.ensureCapacity(this.length === 0 ? 4 : this.length * 2);
197
213
  this._data[index] = x;
198
214
  this._data[index + 1] = y;
199
215
  this._data[index + 2] = z;
@@ -206,11 +222,7 @@ class GrowableXYZArray extends IndexedXYZCollection_1.IndexedReadWriteXYZCollect
206
222
  shiftForward(numPoints) {
207
223
  if (numPoints <= 0)
208
224
  return;
209
- let newCapacity = this.length + numPoints; // in POINTS
210
- if (newCapacity > this._xyzCapacity) {
211
- newCapacity = Math.max(4, 2 * this._xyzCapacity);
212
- this.ensureCapacity(newCapacity);
213
- }
225
+ this.ensureCapacity(this._xyzInUse + numPoints);
214
226
  const numAddedDouble = 3 * numPoints;
215
227
  const lastIndex = this._xyzInUse * 3;
216
228
  this._data.copyWithin(numAddedDouble, 0, lastIndex);
@@ -286,14 +298,9 @@ class GrowableXYZArray extends IndexedXYZCollection_1.IndexedReadWriteXYZCollect
286
298
  }
287
299
  /** copy xyz into strongly typed Point3d */
288
300
  getPoint3dAtCheckedPointIndex(pointIndex, result) {
289
- const index = 3 * pointIndex;
290
301
  if (this.isIndexValid(pointIndex)) {
291
- if (!result)
292
- result = Point3dVector3d_1.Point3d.create();
293
- result.x = this._data[index];
294
- result.y = this._data[index + 1];
295
- result.z = this._data[index + 2];
296
- return result;
302
+ const index = 3 * pointIndex;
303
+ return Point3dVector3d_1.Point3d.create(this._data[index], this._data[index + 1], this._data[index + 2], result);
297
304
  }
298
305
  return undefined;
299
306
  }
@@ -314,26 +321,17 @@ class GrowableXYZArray extends IndexedXYZCollection_1.IndexedReadWriteXYZCollect
314
321
  }
315
322
  /** copy xy into strongly typed Point2d */
316
323
  getPoint2dAtCheckedPointIndex(pointIndex, result) {
317
- const index = 3 * pointIndex;
318
324
  if (this.isIndexValid(pointIndex)) {
319
- if (!result)
320
- result = Point2dVector2d_1.Point2d.create();
321
- result.x = this._data[index];
322
- result.y = this._data[index + 1];
323
- return result;
325
+ const index = 3 * pointIndex;
326
+ return Point2dVector2d_1.Point2d.create(this._data[index], this._data[index + 1], result);
324
327
  }
325
328
  return undefined;
326
329
  }
327
330
  /** copy xyz into strongly typed Vector3d */
328
331
  getVector3dAtCheckedVectorIndex(vectorIndex, result) {
329
- const index = 3 * vectorIndex;
330
- if (vectorIndex >= 0 && vectorIndex < this._xyzInUse) {
331
- if (!result)
332
- result = Point3dVector3d_1.Vector3d.create();
333
- result.x = this._data[index];
334
- result.y = this._data[index + 1];
335
- result.z = this._data[index + 2];
336
- return result;
332
+ if (this.isIndexValid(vectorIndex)) {
333
+ const index = 3 * vectorIndex;
334
+ return Point3dVector3d_1.Vector3d.create(this._data[index], this._data[index + 1], this._data[index + 2], result);
337
335
  }
338
336
  return undefined;
339
337
  }
@@ -365,11 +363,8 @@ class GrowableXYZArray extends IndexedXYZCollection_1.IndexedReadWriteXYZCollect
365
363
  // full array push . . .
366
364
  if (sourceIndex === undefined) {
367
365
  const numXYZAdd = source.length;
368
- this.ensureCapacity(this.length + numXYZAdd);
369
- const nXAdd = source.length * 3;
370
- const i0 = this._xyzInUse * 3;
371
- for (let i = 0; i < nXAdd; i++)
372
- this._data[i0 + i] = source._data[i];
366
+ this.ensureCapacity(this.length + numXYZAdd, false);
367
+ this.copyData(source._data, numXYZAdd, this.length);
373
368
  this._xyzInUse += numXYZAdd;
374
369
  return numXYZAdd;
375
370
  }
@@ -431,12 +426,11 @@ class GrowableXYZArray extends IndexedXYZCollection_1.IndexedReadWriteXYZCollect
431
426
  * Copy all points into a simple array of Point3d
432
427
  */
433
428
  getPoint3dArray() {
429
+ const n = 3 * this._xyzInUse;
434
430
  const result = [];
435
431
  const data = this._data;
436
- const n = this.length;
437
- for (let i = 0; i < n; i++) {
438
- result.push(Point3dVector3d_1.Point3d.create(data[i * 3], data[i * 3 + 1], data[i * 3 + 2]));
439
- }
432
+ for (let i = 0; i < n; i += 3)
433
+ result.push(Point3dVector3d_1.Point3d.create(data[i], data[i + 1], data[i + 2]));
440
434
  return result;
441
435
  }
442
436
  /** multiply each point by the transform, replace values. */
@@ -589,7 +583,7 @@ class GrowableXYZArray extends IndexedXYZCollection_1.IndexedReadWriteXYZCollect
589
583
  let x = 0;
590
584
  let y = 0;
591
585
  let z = 0;
592
- for (let i = 0; i + 3 <= nDouble; i += 3) {
586
+ for (let i = 0; i + 2 < nDouble; i += 3) {
593
587
  x = data[i] - x0;
594
588
  y = data[i + 1] - y0;
595
589
  z = data[i + 2] - z0;
@@ -604,11 +598,11 @@ class GrowableXYZArray extends IndexedXYZCollection_1.IndexedReadWriteXYZCollect
604
598
  const numDouble = this.float64Length;
605
599
  const data = this._data;
606
600
  if (transform) {
607
- for (let i = 0; i + 3 <= numDouble; i += 3)
601
+ for (let i = 0; i + 2 < numDouble; i += 3)
608
602
  rangeToExtend.extendTransformedXYZ(transform, data[i], data[i + 1], data[i + 2]);
609
603
  }
610
604
  else {
611
- for (let i = 0; i + 3 <= numDouble; i += 3)
605
+ for (let i = 0; i + 2 < numDouble; i += 3)
612
606
  rangeToExtend.extendXYZ(data[i], data[i + 1], data[i + 2]);
613
607
  }
614
608
  }
@@ -719,15 +713,10 @@ class GrowableXYZArray extends IndexedXYZCollection_1.IndexedReadWriteXYZCollect
719
713
  vectorIndexIndex(i, j, result) {
720
714
  if (!this.isIndexValid(i) || !this.isIndexValid(j))
721
715
  return undefined;
722
- if (!result)
723
- result = Point3dVector3d_1.Vector3d.create();
724
716
  const data = this._data;
725
717
  i = 3 * i;
726
718
  j = 3 * j;
727
- result.x = data[j] - data[i];
728
- result.y = data[j + 1] - data[i + 1];
729
- result.z = data[j + 2] - data[i + 2];
730
- return result;
719
+ return Point3dVector3d_1.Vector3d.create(data[j] - data[i], data[j + 1] - data[i + 1], data[j + 2] - data[i + 2], result);
731
720
  }
732
721
  /** Compute a vector from origin to indexed target j */
733
722
  vectorXYAndZIndex(origin, j, result) {
@@ -740,12 +729,13 @@ class GrowableXYZArray extends IndexedXYZCollection_1.IndexedReadWriteXYZCollect
740
729
  }
741
730
  /** Compute the cross product of vectors from from indexed origin to indexed targets i and j */
742
731
  crossProductIndexIndexIndex(originIndex, targetAIndex, targetBIndex, result) {
743
- const i = originIndex * 3;
744
- const j = targetAIndex * 3;
745
- const k = targetBIndex * 3;
746
- const data = this._data;
747
- if (this.isIndexValid(originIndex) && this.isIndexValid(targetAIndex) && this.isIndexValid(targetBIndex))
732
+ if (this.isIndexValid(originIndex) && this.isIndexValid(targetAIndex) && this.isIndexValid(targetBIndex)) {
733
+ const i = originIndex * 3;
734
+ const j = targetAIndex * 3;
735
+ const k = targetBIndex * 3;
736
+ const data = this._data;
748
737
  return Geometry_1.Geometry.crossProductXYZXYZ(data[j] - data[i], data[j + 1] - data[i + 1], data[j + 2] - data[i + 2], data[k] - data[i], data[k + 1] - data[i + 1], data[k + 2] - data[i + 2], result);
738
+ }
749
739
  return undefined;
750
740
  }
751
741
  /** Compute the dot product of pointIndex with [x,y,z] */
@@ -765,22 +755,22 @@ class GrowableXYZArray extends IndexedXYZCollection_1.IndexedReadWriteXYZCollect
765
755
  * * accumulate it to the result.
766
756
  */
767
757
  accumulateCrossProductIndexIndexIndex(originIndex, targetAIndex, targetBIndex, result) {
768
- const i = originIndex * 3;
769
- const j = targetAIndex * 3;
770
- const k = targetBIndex * 3;
771
- const data = this._data;
772
- if (this.isIndexValid(originIndex) && this.isIndexValid(targetAIndex) && this.isIndexValid(targetBIndex))
758
+ if (this.isIndexValid(originIndex) && this.isIndexValid(targetAIndex) && this.isIndexValid(targetBIndex)) {
759
+ const i = originIndex * 3;
760
+ const j = targetAIndex * 3;
761
+ const k = targetBIndex * 3;
762
+ const data = this._data;
773
763
  result.addCrossProductToTargetsInPlace(data[i], data[i + 1], data[i + 2], data[j], data[j + 1], data[j + 2], data[k], data[k + 1], data[k + 2]);
774
- return undefined;
764
+ }
775
765
  }
776
766
  /**
777
767
  * * compute the cross product from indexed origin t indexed targets targetAIndex and targetB index.
778
768
  * * accumulate it to the result.
779
769
  */
780
770
  accumulateScaledXYZ(index, scale, sum) {
781
- const i = index * 3;
782
- const data = this._data;
783
771
  if (this.isIndexValid(index)) {
772
+ const i = index * 3;
773
+ const data = this._data;
784
774
  sum.x += scale * data[i];
785
775
  sum.y += scale * data[i + 1];
786
776
  sum.z += scale * data[i + 2];
@@ -788,16 +778,17 @@ class GrowableXYZArray extends IndexedXYZCollection_1.IndexedReadWriteXYZCollect
788
778
  }
789
779
  /** Compute the cross product of vectors from from origin to indexed targets i and j */
790
780
  crossProductXYAndZIndexIndex(origin, targetAIndex, targetBIndex, result) {
791
- const j = targetAIndex * 3;
792
- const k = targetBIndex * 3;
793
- const data = this._data;
794
- if (this.isIndexValid(targetAIndex) && this.isIndexValid(targetBIndex))
781
+ if (this.isIndexValid(targetAIndex) && this.isIndexValid(targetBIndex)) {
782
+ const j = targetAIndex * 3;
783
+ const k = targetBIndex * 3;
784
+ const data = this._data;
795
785
  return Geometry_1.Geometry.crossProductXYZXYZ(data[j] - origin.x, data[j + 1] - origin.y, data[j + 2] - origin.z, data[k] - origin.x, data[k + 1] - origin.y, data[k + 2] - origin.z, result);
786
+ }
796
787
  return undefined;
797
788
  }
798
789
  /** Return the distance between an array point and the input point. */
799
790
  distanceIndexToPoint(i, spacePoint) {
800
- if (i >= 0 && i < this._xyzInUse) {
791
+ if (this.isIndexValid(i)) {
801
792
  const i0 = 3 * i;
802
793
  return Geometry_1.Geometry.hypotenuseXYZ(spacePoint.x - this._data[i0], spacePoint.y - this._data[i0 + 1], spacePoint.z - this._data[i0 + 2]);
803
794
  }
@@ -805,14 +796,11 @@ class GrowableXYZArray extends IndexedXYZCollection_1.IndexedReadWriteXYZCollect
805
796
  }
806
797
  /**
807
798
  * Return distance squared between indicated points.
808
- * * Concrete classes may be able to implement this without creating a temporary.
809
- * @param index0 first point index
810
- * @param index1 second point index
811
- * @param defaultDistanceSquared distance squared to return if either point index is invalid.
812
- *
799
+ * @param i first point index
800
+ * @param j second point index
813
801
  */
814
802
  distanceSquaredIndexIndex(i, j) {
815
- if (i >= 0 && i < this._xyzInUse && j >= 0 && j <= this._xyzInUse) {
803
+ if (this.isIndexValid(i) && this.isIndexValid(j)) {
816
804
  const i0 = 3 * i;
817
805
  const j0 = 3 * j;
818
806
  return Geometry_1.Geometry.hypotenuseSquaredXYZ(this._data[j0] - this._data[i0], this._data[j0 + 1] - this._data[i0 + 1], this._data[j0 + 2] - this._data[i0 + 2]);
@@ -821,13 +809,11 @@ class GrowableXYZArray extends IndexedXYZCollection_1.IndexedReadWriteXYZCollect
821
809
  }
822
810
  /**
823
811
  * Return distance between indicated points.
824
- * * Concrete classes may be able to implement this without creating a temporary.
825
- * @param index0 first point index
826
- * @param index1 second point index
827
- * @param defaultDistanceSquared distance squared to return if either point index is invalid.
812
+ * @param i first point index
813
+ * @param j second point index
828
814
  */
829
815
  distanceIndexIndex(i, j) {
830
- if (i >= 0 && i < this._xyzInUse && j >= 0 && j <= this._xyzInUse) {
816
+ if (this.isIndexValid(i) && this.isIndexValid(j)) {
831
817
  const i0 = 3 * i;
832
818
  const j0 = 3 * j;
833
819
  return Geometry_1.Geometry.hypotenuseXYZ(this._data[j0] - this._data[i0], this._data[j0 + 1] - this._data[i0 + 1], this._data[j0 + 2] - this._data[i0 + 2]);
@@ -836,7 +822,7 @@ class GrowableXYZArray extends IndexedXYZCollection_1.IndexedReadWriteXYZCollect
836
822
  }
837
823
  /** Return the distance between points in distinct arrays. */
838
824
  static distanceBetweenPointsIn2Arrays(arrayA, i, arrayB, j) {
839
- if (i >= 0 && i < arrayA._xyzInUse && j >= 0 && j <= arrayB._xyzInUse) {
825
+ if (arrayA.isIndexValid(i) && arrayB.isIndexValid(j)) {
840
826
  const i0 = 3 * i;
841
827
  const j0 = 3 * j;
842
828
  return Geometry_1.Geometry.hypotenuseXYZ(arrayB._data[j0] - arrayA._data[i0], arrayB._data[j0 + 1] - arrayA._data[i0 + 1], arrayB._data[j0 + 2] - arrayA._data[i0 + 2]);
@@ -900,6 +886,7 @@ class GrowableXYZArray extends IndexedXYZCollection_1.IndexedReadWriteXYZCollect
900
886
  let b0 = pointIndex0 * 3;
901
887
  const nb = other.length * 3;
902
888
  let numAdded = 0;
889
+ this.ensureCapacity(this._xyzInUse + numAdd, false);
903
890
  while (b0 >= 0 && b0 + 2 < nb && numAdded < numAdd) {
904
891
  this.pushXYZ(dataB[b0], dataB[b0 + 1], dataB[b0 + 2]);
905
892
  b0 += step * 3;
@@ -935,11 +922,11 @@ class GrowableXYZArray extends IndexedXYZCollection_1.IndexedReadWriteXYZCollect
935
922
  points.pop();
936
923
  }
937
924
  /**
938
- * * Triangle for (unchecked!) for three points identified by index
925
+ * Compute frame for a triangle formed by three (unchecked!) points identified by index.
939
926
  * * z direction of frame is 001.
940
- * * Transform axes from origin to targetX and targetY
927
+ * * Transform axes from origin to targetA and targetB
941
928
  * * in local coordinates (u,v,w) the xy interior of the triangle is `u>=0, v>= 0, w>= 0, u+v+w<1`
942
- * * Return undefined if transform is invertible (i.e. points are not in a vertical plane.)
929
+ * * Return undefined if transform is not invertible, e.g. if points are in a vertical plane.
943
930
  */
944
931
  fillLocalXYTriangleFrame(originIndex, targetAIndex, targetBIndex, result) {
945
932
  if (this.isIndexValid(originIndex) && this.isIndexValid(targetAIndex) && this.isIndexValid(targetBIndex)) {
@@ -962,7 +949,7 @@ class GrowableXYZArray extends IndexedXYZCollection_1.IndexedReadWriteXYZCollect
962
949
  return undefined;
963
950
  }
964
951
  /**
965
- * Pass the (x,y,z) of each point to a function which returns a replacement for of of the 3 components.
952
+ * Pass the (x,y,z) of each point to a function which returns a replacement for one of the 3 components.
966
953
  * @param componentIndex Index (0,1,2) of component to be replaced.
967
954
  * @param func function to be called as `func(x,y,z)`, returning a replacement value for componentIndex
968
955
  */