@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
@@ -16,27 +16,51 @@ import { PointStreamGrowableXYZArrayCollector, VariantPointDataStream } from "./
16
16
  */
17
17
  export class GrowableXYArray extends IndexedXYCollection {
18
18
  /** Construct a new GrowablePoint2d array.
19
- * @param numPoints [in] initial capacity.
19
+ * @param numPoints initial capacity in xy tuples (default 8)
20
+ * @param growthFactor used by ensureCapacity to expand requested reallocation size (default 1.5)
20
21
  */
21
- constructor(numPoints = 8) {
22
+ constructor(numPoints = 8, growthFactor) {
22
23
  super();
23
- this._data = new Float64Array(numPoints * 2); // 8 Points to start (2 values each)
24
+ this._data = new Float64Array(numPoints * 2); // 2 values per point
24
25
  this._xyInUse = 0;
25
- this._xyzCapacity = numPoints;
26
+ this._xyCapacity = numPoints;
27
+ this._growthFactor = (undefined !== growthFactor && growthFactor >= 1.0) ? growthFactor : 1.5;
28
+ }
29
+ /** Copy xy points from source array. Does not reallocate or change active point count.
30
+ * @param source array to copy from
31
+ * @param sourceCount copy the first sourceCount points; all points if undefined
32
+ * @param destOffset copy to instance array starting at this point index; zero if undefined
33
+ * @return count and offset of points copied
34
+ */
35
+ copyData(source, sourceCount, destOffset) {
36
+ // validate inputs and convert from points to entries
37
+ let myOffset = (undefined !== destOffset) ? destOffset * 2 : 0;
38
+ if (myOffset < 0)
39
+ myOffset = 0;
40
+ if (myOffset >= this._data.length)
41
+ return { count: 0, offset: 0 };
42
+ let myCount = (undefined !== sourceCount) ? sourceCount * 2 : source.length;
43
+ if (myCount > 0) {
44
+ if (myCount > source.length)
45
+ myCount = source.length;
46
+ if (myOffset + myCount > this._data.length)
47
+ myCount = this._data.length - myOffset;
48
+ if (myCount % 2 !== 0)
49
+ myCount -= myCount % 2;
50
+ }
51
+ if (myCount <= 0)
52
+ return { count: 0, offset: 0 };
53
+ if (myCount === source.length)
54
+ this._data.set(source, myOffset);
55
+ else if (source instanceof Float64Array)
56
+ this._data.set(source.subarray(0, myCount), myOffset);
57
+ else
58
+ this._data.set(source.slice(0, myCount), myOffset);
59
+ return { count: myCount / 2, offset: myOffset / 2 };
26
60
  }
27
61
  /** The number of points in use. When the length is increased, the array is padded with zeroes. */
28
62
  get length() { return this._xyInUse; }
29
- set length(newLength) {
30
- let oldLength = this.length;
31
- if (newLength < oldLength) {
32
- this._xyInUse = newLength;
33
- }
34
- else if (newLength > oldLength) {
35
- this.ensureCapacity(newLength);
36
- while (oldLength++ < newLength)
37
- this.pushXY(0, 0);
38
- }
39
- }
63
+ set length(newLength) { this.resize(newLength, true); }
40
64
  /** Return the number of float64 in use. */
41
65
  get float64Length() { return this._xyInUse * 2; }
42
66
  /** Return the raw packed data.
@@ -44,31 +68,29 @@ export class GrowableXYArray extends IndexedXYCollection {
44
68
  */
45
69
  float64Data() { return this._data; }
46
70
  /** If necessary, increase the capacity to a new pointCount. Current coordinates and point count (length) are unchanged. */
47
- ensureCapacity(pointCapacity) {
48
- if (pointCapacity > this._xyzCapacity) {
49
- const newData = new Float64Array(pointCapacity * 2);
50
- const numCopy = this.length * 2;
51
- for (let i = 0; i < numCopy; i++)
52
- newData[i] = this._data[i];
53
- this._data = newData;
54
- this._xyzCapacity = pointCapacity;
55
- }
56
- }
57
- /** Resize the actual point count, preserving excess capacity. */
58
- resize(pointCount) {
59
- if (pointCount < this.length) {
60
- this._xyInUse = pointCount >= 0 ? pointCount : 0;
61
- }
62
- else if (pointCount > this._xyzCapacity) {
63
- const newArray = new Float64Array(pointCount * 2);
64
- // Copy contents
65
- for (let i = 0; i < this._data.length; i += 2) {
66
- newArray[i] = this._data[i];
67
- newArray[i + 1] = this._data[i + 1];
68
- newArray[i + 2] = this._data[i + 2];
69
- }
70
- this._data = newArray;
71
- this._xyzCapacity = pointCount;
71
+ ensureCapacity(pointCapacity, applyGrowthFactor = true) {
72
+ if (pointCapacity > this._xyCapacity) {
73
+ if (applyGrowthFactor)
74
+ pointCapacity *= this._growthFactor;
75
+ const prevData = this._data;
76
+ this._data = new Float64Array(pointCapacity * 2);
77
+ this.copyData(prevData, this._xyInUse);
78
+ this._xyCapacity = pointCapacity;
79
+ }
80
+ }
81
+ /**
82
+ * * If pointCount is less than current length, just reset current length to pointCount, effectively trimming active points but preserving original capacity.
83
+ * * If pointCount is greater than current length, reallocate to exactly pointCount, copy existing points, and optionally pad excess with zero.
84
+ * @param pointCount new number of active points in array
85
+ * @param padWithZero when increasing point count, whether to zero out new points (default false)
86
+ */
87
+ resize(pointCount, padWithZero) {
88
+ if (pointCount >= 0 && pointCount < this._xyInUse)
89
+ this._xyInUse = pointCount;
90
+ else if (pointCount > this._xyInUse) {
91
+ this.ensureCapacity(pointCount, false);
92
+ if (padWithZero !== null && padWithZero !== void 0 ? padWithZero : false)
93
+ this._data.fill(0, this._xyInUse * 2);
72
94
  this._xyInUse = pointCount;
73
95
  }
74
96
  }
@@ -78,11 +100,7 @@ export class GrowableXYArray extends IndexedXYCollection {
78
100
  */
79
101
  clone() {
80
102
  const newPoints = new GrowableXYArray(this.length);
81
- const numValue = this.length * 2;
82
- const newData = newPoints._data;
83
- const data = this._data;
84
- for (let i = 0; i < numValue; i++)
85
- newData[i] = data[i];
103
+ newPoints.copyData(this._data, this.length);
86
104
  newPoints._xyInUse = this.length;
87
105
  return newPoints;
88
106
  }
@@ -114,17 +132,18 @@ export class GrowableXYArray extends IndexedXYCollection {
114
132
  }
115
133
  /** push all points of an array */
116
134
  pushAll(points) {
135
+ this.ensureCapacity(this._xyInUse + points.length, false);
117
136
  for (const p of points)
118
137
  this.push(p);
119
138
  }
120
139
  /** push all points of an array */
121
140
  pushAllXYAndZ(points) {
141
+ this.ensureCapacity(this._xyInUse + points.length, false);
122
142
  if (points instanceof GrowableXYZArray) {
123
143
  const xyzBuffer = points.float64Data();
124
144
  const n = points.length * 3;
125
- for (let i = 0; i + 2 < n; i += 3) {
145
+ for (let i = 0; i + 2 < n; i += 3)
126
146
  this.pushXY(xyzBuffer[i], xyzBuffer[i + 1]);
127
- }
128
147
  }
129
148
  else {
130
149
  for (const p of points)
@@ -132,38 +151,37 @@ export class GrowableXYArray extends IndexedXYCollection {
132
151
  }
133
152
  }
134
153
  /**
135
- * Replicate numWrap xyz values from the front of the array as new values at the end.
136
- * @param numWrap number of xyz values to replicate
154
+ * Replicate numWrap xy values from the front of the array as new values at the end.
155
+ * @param numWrap number of xy values to replicate
137
156
  */
138
157
  pushWrap(numWrap) {
139
- if (this._xyInUse > 0) {
140
- let k;
158
+ if (this._xyInUse >= numWrap) {
159
+ this.ensureCapacity(this._xyInUse + numWrap, false);
141
160
  for (let i = 0; i < numWrap; i++) {
142
- k = 2 * i;
161
+ const k = 2 * i;
143
162
  this.pushXY(this._data[k], this._data[k + 1]);
144
163
  }
145
164
  }
146
165
  }
147
166
  /** push a point given by x,y coordinates */
148
167
  pushXY(x, y) {
168
+ this.ensureCapacity(this._xyInUse + 1);
149
169
  const index = this._xyInUse * 2;
150
- if (index >= this._data.length)
151
- this.ensureCapacity(this.length === 0 ? 4 : this.length * 2);
152
170
  this._data[index] = x;
153
171
  this._data[index + 1] = y;
154
172
  this._xyInUse++;
155
173
  }
156
174
  /** Remove one point from the back.
157
175
  * * NOTE that (in the manner of std::vector native) this is "just" removing the point -- no point is NOT returned.
158
- * * Use `back ()` to get the last x,y,z assembled into a `Point3d `
176
+ * * Use `back ()` to get the last x,y assembled into a `Point2d `
159
177
  */
160
178
  pop() {
161
179
  if (this._xyInUse > 0)
162
180
  this._xyInUse--;
163
181
  }
164
182
  /**
165
- * Test if index is valid for an xyz (point or vector) within this array
166
- * @param index xyz index to test.
183
+ * Test if index is valid for an xy (point or vector) within this array
184
+ * @param index xy index to test.
167
185
  */
168
186
  isIndexValid(index) {
169
187
  if (index >= this._xyInUse || index < 0)
@@ -171,7 +189,7 @@ export class GrowableXYArray extends IndexedXYCollection {
171
189
  return true;
172
190
  }
173
191
  /**
174
- * Clear all xyz data, but leave capacity unchanged.
192
+ * Clear all xy data, but leave capacity unchanged.
175
193
  */
176
194
  clear() {
177
195
  this._xyInUse = 0;
@@ -210,18 +228,18 @@ export class GrowableXYArray extends IndexedXYCollection {
210
228
  result.push(Point2d.create(data[i], data[i + 1]));
211
229
  return result;
212
230
  }
213
- /** copy xyz into strongly typed Point2d */
231
+ /** copy xy into strongly typed Point2d */
214
232
  getPoint2dAtCheckedPointIndex(pointIndex, result) {
215
- const index = 2 * pointIndex;
216
233
  if (this.isIndexValid(pointIndex)) {
234
+ const index = 2 * pointIndex;
217
235
  return Point2d.create(this._data[index], this._data[index + 1], result);
218
236
  }
219
237
  return undefined;
220
238
  }
221
- /** copy xyz into strongly typed Vector2d */
239
+ /** copy xy into strongly typed Vector2d */
222
240
  getVector2dAtCheckedVectorIndex(vectorIndex, result) {
223
- const index = 2 * vectorIndex;
224
241
  if (this.isIndexValid(vectorIndex)) {
242
+ const index = 2 * vectorIndex;
225
243
  return Vector2d.create(this._data[index], this._data[index + 1], result);
226
244
  }
227
245
  return undefined;
@@ -239,7 +257,6 @@ export class GrowableXYArray extends IndexedXYCollection {
239
257
  const j = sourceIndex * 2;
240
258
  this._data[i] = source._data[j];
241
259
  this._data[i + 1] = source._data[j + 1];
242
- this._data[i + 2] = source._data[j + 2];
243
260
  return true;
244
261
  }
245
262
  return false;
@@ -247,21 +264,19 @@ export class GrowableXYArray extends IndexedXYCollection {
247
264
  /**
248
265
  * push coordinates from the source array to the end of this array.
249
266
  * @param source source array
250
- * @param sourceIndex xyz index within the source. If undefined, push entire contents of source
251
- * @returns true if sourceIndex is valid.
267
+ * @param sourceIndex xy index within the source. If undefined, push entire contents of source
268
+ * @returns number of points pushed.
252
269
  */
253
270
  pushFromGrowableXYArray(source, sourceIndex) {
271
+ // full array push . . .
254
272
  if (sourceIndex === undefined) {
255
- const numPresent = this.length;
256
- const numPush = source.length;
257
- this.ensureCapacity(numPresent + numPush);
258
- const numFloatPresent = 2 * numPresent;
259
- const numFloatAdd = 2 * numPush;
260
- for (let i = 0; i < numFloatAdd; i++)
261
- this._data[numFloatPresent + i] = source._data[i];
262
- this._xyInUse += numPush;
263
- return numPush;
273
+ const numXYAdd = source.length;
274
+ this.ensureCapacity(this.length + numXYAdd, false);
275
+ this.copyData(source._data, numXYAdd, this.length);
276
+ this._xyInUse += numXYAdd;
277
+ return numXYAdd;
264
278
  }
279
+ // single point push . . .
265
280
  if (source.isIndexValid(sourceIndex)) {
266
281
  const j = sourceIndex * 2;
267
282
  this.pushXY(source._data[j], source._data[j + 1]);
@@ -275,29 +290,31 @@ export class GrowableXYArray extends IndexedXYCollection {
275
290
  */
276
291
  pushInterpolatedFromGrowableXYArray(source, i, fraction, j) {
277
292
  if (source.isIndexValid(i) && source.isIndexValid(j)) {
293
+ const fraction0 = 1.0 - fraction;
278
294
  const data = source._data;
279
- i = 3 * i;
280
- j = 3 * j;
281
- this.pushXY(Geometry.interpolate(data[i], fraction, data[j]), Geometry.interpolate(data[i + 1], fraction, data[j + 1]));
295
+ i = 2 * i;
296
+ j = 2 * j;
297
+ this.pushXY(fraction0 * data[i] + fraction * data[j], fraction0 * data[i + 1] + fraction * data[j + 1]);
282
298
  }
283
299
  }
284
300
  /**
285
- * push coordinates from the source array to the end of this array.
286
- * @param source source array
287
- * @param transform optional transform to apply to points.
301
+ * Create an array of xy points from source xyz points.
302
+ * @param source source array of xyz
303
+ * @param transform optional transform to apply to xyz points.
288
304
  * @param dest optional result.
289
305
  */
290
306
  static createFromGrowableXYZArray(source, transform, dest) {
291
- const packedXYZ = source.float64Data();
292
- const numXYZ = source.length; // this is in xyz points
293
- const nDouble = 3 * numXYZ;
307
+ const numPoints = source.length;
294
308
  if (!dest)
295
- dest = new GrowableXYArray(numXYZ);
296
- dest.clear();
297
- let x;
298
- let y;
299
- let z;
309
+ dest = new GrowableXYArray(numPoints);
310
+ else {
311
+ dest.ensureCapacity(numPoints, false);
312
+ dest.clear();
313
+ }
300
314
  if (transform) {
315
+ const packedXYZ = source.float64Data();
316
+ const nDouble = 3 * numPoints;
317
+ let x, y, z;
301
318
  for (let i = 0; i < nDouble; i += 3) {
302
319
  x = packedXYZ[i];
303
320
  y = packedXYZ[i + 1];
@@ -306,11 +323,7 @@ export class GrowableXYArray extends IndexedXYCollection {
306
323
  }
307
324
  }
308
325
  else {
309
- for (let i = 0; i < nDouble; i += 3) {
310
- x = packedXYZ[i];
311
- y = packedXYZ[i + 1];
312
- dest.pushXY(x, y);
313
- }
326
+ dest.pushAllXYAndZ(source);
314
327
  }
315
328
  return dest;
316
329
  }
@@ -349,7 +362,7 @@ export class GrowableXYArray extends IndexedXYCollection {
349
362
  * @param x x coordinate
350
363
  * @param y y coordinate
351
364
  */
352
- setXYZAtCheckedPointIndex(pointIndex, x, y) {
365
+ setXYAtCheckedPointIndex(pointIndex, x, y) {
353
366
  if (!this.isIndexValid(pointIndex))
354
367
  return false;
355
368
  const index = pointIndex * 2;
@@ -358,15 +371,21 @@ export class GrowableXYArray extends IndexedXYCollection {
358
371
  return true;
359
372
  }
360
373
  /**
361
- * Copy all points into a simple array of Point3D with given z.
374
+ * Set the coordinates of a single point given as coordinates.
375
+ * @deprecated Use setXYAtCheckedPointIndex instead
376
+ */
377
+ setXYZAtCheckedPointIndex(pointIndex, x, y) {
378
+ return this.setXYAtCheckedPointIndex(pointIndex, x, y);
379
+ }
380
+ /**
381
+ * Copy all points into a simple array of Point3d with given z.
362
382
  */
363
383
  getPoint3dArray(z = 0) {
384
+ const n = 2 * this._xyInUse;
364
385
  const result = [];
365
386
  const data = this._data;
366
- const n = this.length;
367
- for (let i = 0; i < n; i++) {
368
- result.push(Point3d.create(data[i * 2], data[i * 2 + 1], z));
369
- }
387
+ for (let i = 0; i < n; i += 2)
388
+ result.push(Point3d.create(data[i], data[i + 1], z));
370
389
  return result;
371
390
  }
372
391
  /** reverse the order of points. */
@@ -398,21 +417,21 @@ export class GrowableXYArray extends IndexedXYCollection {
398
417
  const y0 = origin.y;
399
418
  let x = 0;
400
419
  let y = 0;
401
- for (let i = 0; i + 2 <= nDouble; i += 2) {
420
+ for (let i = 0; i + 1 < nDouble; i += 2) {
402
421
  x = data[i];
403
422
  y = data[i + 1];
404
423
  data[i] = coffs[0] * x + coffs[1] * y + x0;
405
424
  data[i + 1] = coffs[3] * x + coffs[4] * y + y0;
406
425
  }
407
426
  }
408
- /** multiply each xyz (as a vector) by matrix, replace values. */
427
+ /** multiply each xy (as a vector) by matrix, replace values. */
409
428
  multiplyMatrix3dInPlace(matrix) {
410
429
  const data = this._data;
411
430
  const nDouble = this.float64Length;
412
431
  const coffs = matrix.coffs;
413
432
  let x = 0;
414
433
  let y = 0;
415
- for (let i = 0; i + 2 <= nDouble; i += 2) {
434
+ for (let i = 0; i + 1 < nDouble; i += 2) {
416
435
  x = data[i];
417
436
  y = data[i + 1];
418
437
  data[i] = coffs[0] * x + coffs[1] * y;
@@ -433,12 +452,11 @@ export class GrowableXYArray extends IndexedXYCollection {
433
452
  const y0 = origin.y;
434
453
  let x = 0;
435
454
  let y = 0;
436
- for (let i = 0; i + 2 <= nDouble; i += 2) {
455
+ for (let i = 0; i + 1 < nDouble; i += 2) {
437
456
  x = data[i] - x0;
438
457
  y = data[i + 1] - y0;
439
458
  data[i] = coffs[0] * x + coffs[1] * y;
440
459
  data[i + 1] = coffs[3] * x + coffs[4] * y;
441
- data[i + 2] = coffs[6] * x + coffs[7] * y;
442
460
  }
443
461
  return true;
444
462
  }
@@ -447,11 +465,11 @@ export class GrowableXYArray extends IndexedXYCollection {
447
465
  const numDouble = this.float64Length;
448
466
  const data = this._data;
449
467
  if (transform) {
450
- for (let i = 0; i + 2 <= numDouble; i += 2)
468
+ for (let i = 0; i + 1 < numDouble; i += 2)
451
469
  rangeToExtend.extendTransformedXY(transform, data[i], data[i + 1]);
452
470
  }
453
471
  else {
454
- for (let i = 0; i + 2 <= numDouble; i += 2)
472
+ for (let i = 0; i + 1 < numDouble; i += 2)
455
473
  rangeToExtend.extendXY(data[i], data[i + 1]);
456
474
  }
457
475
  }
@@ -465,7 +483,7 @@ export class GrowableXYArray extends IndexedXYCollection {
465
483
  return sum;
466
484
  }
467
485
  /**
468
- * Multiply each x,y,z by the scale factor.
486
+ * Multiply each x,y by the scale factor.
469
487
  * @param factor
470
488
  */
471
489
  scaleInPlace(factor) {
@@ -525,21 +543,23 @@ export class GrowableXYArray extends IndexedXYCollection {
525
543
  }
526
544
  /** Compute the cross product of vectors from from indexed origin to indexed targets i and j */
527
545
  crossProductIndexIndexIndex(originIndex, targetAIndex, targetBIndex) {
528
- const i = originIndex * 2;
529
- const j = targetAIndex * 2;
530
- const k = targetBIndex * 2;
531
- const data = this._data;
532
- if (this.isIndexValid(originIndex) && this.isIndexValid(targetAIndex) && this.isIndexValid(targetBIndex))
546
+ if (this.isIndexValid(originIndex) && this.isIndexValid(targetAIndex) && this.isIndexValid(targetBIndex)) {
547
+ const i = originIndex * 2;
548
+ const j = targetAIndex * 2;
549
+ const k = targetBIndex * 2;
550
+ const data = this._data;
533
551
  return Geometry.crossProductXYXY(data[j] - data[i], data[j + 1] - data[i + 1], data[k] - data[i], data[k + 1] - data[i + 1]);
552
+ }
534
553
  return undefined;
535
554
  }
536
555
  /** Compute the cross product of vectors from from origin to indexed targets i and j */
537
556
  crossProductXAndYIndexIndex(origin, targetAIndex, targetBIndex) {
538
- const j = targetAIndex * 2;
539
- const k = targetBIndex * 2;
540
- const data = this._data;
541
- if (this.isIndexValid(targetAIndex) && this.isIndexValid(targetBIndex))
557
+ if (this.isIndexValid(targetAIndex) && this.isIndexValid(targetBIndex)) {
558
+ const j = targetAIndex * 2;
559
+ const k = targetBIndex * 2;
560
+ const data = this._data;
542
561
  return Geometry.crossProductXYXY(data[j] - origin.x, data[j + 1] - origin.y, data[k] - origin.x, data[k + 1] - origin.y);
562
+ }
543
563
  return undefined;
544
564
  }
545
565
  /** Return the distance between two points in the array. */