@itwin/core-geometry 3.3.0-dev.9 → 3.4.0-dev.10

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 (202) hide show
  1. package/CHANGELOG.md +43 -1
  2. package/lib/cjs/bspline/BSplineCurve.js +3 -3
  3. package/lib/cjs/bspline/BSplineCurve.js.map +1 -1
  4. package/lib/cjs/bspline/BezierCurve3dH.d.ts +2 -1
  5. package/lib/cjs/bspline/BezierCurve3dH.d.ts.map +1 -1
  6. package/lib/cjs/bspline/BezierCurve3dH.js +10 -1
  7. package/lib/cjs/bspline/BezierCurve3dH.js.map +1 -1
  8. package/lib/cjs/curve/Arc3d.d.ts +13 -2
  9. package/lib/cjs/curve/Arc3d.d.ts.map +1 -1
  10. package/lib/cjs/curve/Arc3d.js +21 -3
  11. package/lib/cjs/curve/Arc3d.js.map +1 -1
  12. package/lib/cjs/curve/CurveChainWithDistanceIndex.d.ts +36 -2
  13. package/lib/cjs/curve/CurveChainWithDistanceIndex.d.ts.map +1 -1
  14. package/lib/cjs/curve/CurveChainWithDistanceIndex.js +158 -7
  15. package/lib/cjs/curve/CurveChainWithDistanceIndex.js.map +1 -1
  16. package/lib/cjs/curve/CurveCollection.d.ts +2 -0
  17. package/lib/cjs/curve/CurveCollection.d.ts.map +1 -1
  18. package/lib/cjs/curve/CurveCollection.js +8 -0
  19. package/lib/cjs/curve/CurveCollection.js.map +1 -1
  20. package/lib/cjs/curve/CurvePrimitive.d.ts +23 -0
  21. package/lib/cjs/curve/CurvePrimitive.d.ts.map +1 -1
  22. package/lib/cjs/curve/CurvePrimitive.js +65 -0
  23. package/lib/cjs/curve/CurvePrimitive.js.map +1 -1
  24. package/lib/cjs/curve/LineSegment3d.d.ts +5 -0
  25. package/lib/cjs/curve/LineSegment3d.d.ts.map +1 -1
  26. package/lib/cjs/curve/LineSegment3d.js +21 -0
  27. package/lib/cjs/curve/LineSegment3d.js.map +1 -1
  28. package/lib/cjs/curve/LineString3d.d.ts +2 -0
  29. package/lib/cjs/curve/LineString3d.d.ts.map +1 -1
  30. package/lib/cjs/curve/LineString3d.js +28 -0
  31. package/lib/cjs/curve/LineString3d.js.map +1 -1
  32. package/lib/cjs/curve/spiral/DirectSpiral3d.d.ts +2 -5
  33. package/lib/cjs/curve/spiral/DirectSpiral3d.d.ts.map +1 -1
  34. package/lib/cjs/curve/spiral/DirectSpiral3d.js +6 -8
  35. package/lib/cjs/curve/spiral/DirectSpiral3d.js.map +1 -1
  36. package/lib/cjs/curve/spiral/IntegratedSpiral3d.d.ts +0 -3
  37. package/lib/cjs/curve/spiral/IntegratedSpiral3d.d.ts.map +1 -1
  38. package/lib/cjs/curve/spiral/IntegratedSpiral3d.js +0 -4
  39. package/lib/cjs/curve/spiral/IntegratedSpiral3d.js.map +1 -1
  40. package/lib/cjs/curve/spiral/TransitionSpiral3d.d.ts +7 -0
  41. package/lib/cjs/curve/spiral/TransitionSpiral3d.d.ts.map +1 -1
  42. package/lib/cjs/curve/spiral/TransitionSpiral3d.js +17 -0
  43. package/lib/cjs/curve/spiral/TransitionSpiral3d.js.map +1 -1
  44. package/lib/cjs/geometry3d/GrowableBlockedArray.d.ts +32 -3
  45. package/lib/cjs/geometry3d/GrowableBlockedArray.d.ts.map +1 -1
  46. package/lib/cjs/geometry3d/GrowableBlockedArray.js +63 -14
  47. package/lib/cjs/geometry3d/GrowableBlockedArray.js.map +1 -1
  48. package/lib/cjs/geometry3d/GrowableFloat64Array.d.ts +24 -8
  49. package/lib/cjs/geometry3d/GrowableFloat64Array.d.ts.map +1 -1
  50. package/lib/cjs/geometry3d/GrowableFloat64Array.js +72 -54
  51. package/lib/cjs/geometry3d/GrowableFloat64Array.js.map +1 -1
  52. package/lib/cjs/geometry3d/GrowableXYArray.d.ts +51 -26
  53. package/lib/cjs/geometry3d/GrowableXYArray.d.ts.map +1 -1
  54. package/lib/cjs/geometry3d/GrowableXYArray.js +136 -116
  55. package/lib/cjs/geometry3d/GrowableXYArray.js.map +1 -1
  56. package/lib/cjs/geometry3d/GrowableXYZArray.d.ts +35 -21
  57. package/lib/cjs/geometry3d/GrowableXYZArray.d.ts.map +1 -1
  58. package/lib/cjs/geometry3d/GrowableXYZArray.js +124 -137
  59. package/lib/cjs/geometry3d/GrowableXYZArray.js.map +1 -1
  60. package/lib/cjs/geometry3d/Point3dVector3d.d.ts +1 -1
  61. package/lib/cjs/geometry3d/Point3dVector3d.d.ts.map +1 -1
  62. package/lib/cjs/geometry3d/Point3dVector3d.js +2 -3
  63. package/lib/cjs/geometry3d/Point3dVector3d.js.map +1 -1
  64. package/lib/cjs/geometry3d/PolygonOps.d.ts +8 -2
  65. package/lib/cjs/geometry3d/PolygonOps.d.ts.map +1 -1
  66. package/lib/cjs/geometry3d/PolygonOps.js +40 -3
  67. package/lib/cjs/geometry3d/PolygonOps.js.map +1 -1
  68. package/lib/cjs/geometry3d/Range.d.ts +12 -0
  69. package/lib/cjs/geometry3d/Range.d.ts.map +1 -1
  70. package/lib/cjs/geometry3d/Range.js +32 -0
  71. package/lib/cjs/geometry3d/Range.js.map +1 -1
  72. package/lib/cjs/geometry3d/Ray3d.js +1 -1
  73. package/lib/cjs/geometry3d/Ray3d.js.map +1 -1
  74. package/lib/cjs/geometry3d/Transform.d.ts +1 -1
  75. package/lib/cjs/geometry3d/Transform.d.ts.map +1 -1
  76. package/lib/cjs/geometry3d/Transform.js +1 -1
  77. package/lib/cjs/geometry3d/Transform.js.map +1 -1
  78. package/lib/cjs/geometry3d/XYZProps.d.ts +10 -3
  79. package/lib/cjs/geometry3d/XYZProps.d.ts.map +1 -1
  80. package/lib/cjs/geometry3d/XYZProps.js +21 -0
  81. package/lib/cjs/geometry3d/XYZProps.js.map +1 -1
  82. package/lib/cjs/polyface/PolyfaceBuilder.d.ts +1 -1
  83. package/lib/cjs/polyface/PolyfaceBuilder.js +2 -2
  84. package/lib/cjs/polyface/PolyfaceBuilder.js.map +1 -1
  85. package/lib/cjs/polyface/PolyfaceClip.d.ts.map +1 -1
  86. package/lib/cjs/polyface/PolyfaceClip.js +1 -1
  87. package/lib/cjs/polyface/PolyfaceClip.js.map +1 -1
  88. package/lib/cjs/polyface/PolyfaceQuery.d.ts +4 -2
  89. package/lib/cjs/polyface/PolyfaceQuery.d.ts.map +1 -1
  90. package/lib/cjs/polyface/PolyfaceQuery.js +10 -6
  91. package/lib/cjs/polyface/PolyfaceQuery.js.map +1 -1
  92. package/lib/cjs/serialization/GeometrySamples.d.ts +2 -0
  93. package/lib/cjs/serialization/GeometrySamples.d.ts.map +1 -1
  94. package/lib/cjs/serialization/GeometrySamples.js +20 -0
  95. package/lib/cjs/serialization/GeometrySamples.js.map +1 -1
  96. package/lib/cjs/topology/Merging.js +3 -3
  97. package/lib/cjs/topology/Merging.js.map +1 -1
  98. package/lib/cjs/topology/Triangulation.d.ts +1 -3
  99. package/lib/cjs/topology/Triangulation.d.ts.map +1 -1
  100. package/lib/cjs/topology/Triangulation.js +31 -21
  101. package/lib/cjs/topology/Triangulation.js.map +1 -1
  102. package/lib/esm/bspline/BSplineCurve.js +3 -3
  103. package/lib/esm/bspline/BSplineCurve.js.map +1 -1
  104. package/lib/esm/bspline/BezierCurve3dH.d.ts +2 -1
  105. package/lib/esm/bspline/BezierCurve3dH.d.ts.map +1 -1
  106. package/lib/esm/bspline/BezierCurve3dH.js +10 -1
  107. package/lib/esm/bspline/BezierCurve3dH.js.map +1 -1
  108. package/lib/esm/curve/Arc3d.d.ts +13 -2
  109. package/lib/esm/curve/Arc3d.d.ts.map +1 -1
  110. package/lib/esm/curve/Arc3d.js +22 -4
  111. package/lib/esm/curve/Arc3d.js.map +1 -1
  112. package/lib/esm/curve/CurveChainWithDistanceIndex.d.ts +36 -2
  113. package/lib/esm/curve/CurveChainWithDistanceIndex.d.ts.map +1 -1
  114. package/lib/esm/curve/CurveChainWithDistanceIndex.js +158 -7
  115. package/lib/esm/curve/CurveChainWithDistanceIndex.js.map +1 -1
  116. package/lib/esm/curve/CurveCollection.d.ts +2 -0
  117. package/lib/esm/curve/CurveCollection.d.ts.map +1 -1
  118. package/lib/esm/curve/CurveCollection.js +8 -0
  119. package/lib/esm/curve/CurveCollection.js.map +1 -1
  120. package/lib/esm/curve/CurvePrimitive.d.ts +23 -0
  121. package/lib/esm/curve/CurvePrimitive.d.ts.map +1 -1
  122. package/lib/esm/curve/CurvePrimitive.js +65 -0
  123. package/lib/esm/curve/CurvePrimitive.js.map +1 -1
  124. package/lib/esm/curve/LineSegment3d.d.ts +5 -0
  125. package/lib/esm/curve/LineSegment3d.d.ts.map +1 -1
  126. package/lib/esm/curve/LineSegment3d.js +21 -0
  127. package/lib/esm/curve/LineSegment3d.js.map +1 -1
  128. package/lib/esm/curve/LineString3d.d.ts +2 -0
  129. package/lib/esm/curve/LineString3d.d.ts.map +1 -1
  130. package/lib/esm/curve/LineString3d.js +28 -0
  131. package/lib/esm/curve/LineString3d.js.map +1 -1
  132. package/lib/esm/curve/spiral/DirectSpiral3d.d.ts +2 -5
  133. package/lib/esm/curve/spiral/DirectSpiral3d.d.ts.map +1 -1
  134. package/lib/esm/curve/spiral/DirectSpiral3d.js +6 -8
  135. package/lib/esm/curve/spiral/DirectSpiral3d.js.map +1 -1
  136. package/lib/esm/curve/spiral/IntegratedSpiral3d.d.ts +0 -3
  137. package/lib/esm/curve/spiral/IntegratedSpiral3d.d.ts.map +1 -1
  138. package/lib/esm/curve/spiral/IntegratedSpiral3d.js +0 -4
  139. package/lib/esm/curve/spiral/IntegratedSpiral3d.js.map +1 -1
  140. package/lib/esm/curve/spiral/TransitionSpiral3d.d.ts +7 -0
  141. package/lib/esm/curve/spiral/TransitionSpiral3d.d.ts.map +1 -1
  142. package/lib/esm/curve/spiral/TransitionSpiral3d.js +17 -0
  143. package/lib/esm/curve/spiral/TransitionSpiral3d.js.map +1 -1
  144. package/lib/esm/geometry3d/GrowableBlockedArray.d.ts +32 -3
  145. package/lib/esm/geometry3d/GrowableBlockedArray.d.ts.map +1 -1
  146. package/lib/esm/geometry3d/GrowableBlockedArray.js +63 -14
  147. package/lib/esm/geometry3d/GrowableBlockedArray.js.map +1 -1
  148. package/lib/esm/geometry3d/GrowableFloat64Array.d.ts +24 -8
  149. package/lib/esm/geometry3d/GrowableFloat64Array.d.ts.map +1 -1
  150. package/lib/esm/geometry3d/GrowableFloat64Array.js +72 -54
  151. package/lib/esm/geometry3d/GrowableFloat64Array.js.map +1 -1
  152. package/lib/esm/geometry3d/GrowableXYArray.d.ts +51 -26
  153. package/lib/esm/geometry3d/GrowableXYArray.d.ts.map +1 -1
  154. package/lib/esm/geometry3d/GrowableXYArray.js +136 -116
  155. package/lib/esm/geometry3d/GrowableXYArray.js.map +1 -1
  156. package/lib/esm/geometry3d/GrowableXYZArray.d.ts +35 -21
  157. package/lib/esm/geometry3d/GrowableXYZArray.d.ts.map +1 -1
  158. package/lib/esm/geometry3d/GrowableXYZArray.js +124 -137
  159. package/lib/esm/geometry3d/GrowableXYZArray.js.map +1 -1
  160. package/lib/esm/geometry3d/Point3dVector3d.d.ts +1 -1
  161. package/lib/esm/geometry3d/Point3dVector3d.d.ts.map +1 -1
  162. package/lib/esm/geometry3d/Point3dVector3d.js +2 -3
  163. package/lib/esm/geometry3d/Point3dVector3d.js.map +1 -1
  164. package/lib/esm/geometry3d/PolygonOps.d.ts +8 -2
  165. package/lib/esm/geometry3d/PolygonOps.d.ts.map +1 -1
  166. package/lib/esm/geometry3d/PolygonOps.js +40 -3
  167. package/lib/esm/geometry3d/PolygonOps.js.map +1 -1
  168. package/lib/esm/geometry3d/Range.d.ts +12 -0
  169. package/lib/esm/geometry3d/Range.d.ts.map +1 -1
  170. package/lib/esm/geometry3d/Range.js +32 -0
  171. package/lib/esm/geometry3d/Range.js.map +1 -1
  172. package/lib/esm/geometry3d/Ray3d.js +1 -1
  173. package/lib/esm/geometry3d/Ray3d.js.map +1 -1
  174. package/lib/esm/geometry3d/Transform.d.ts +1 -1
  175. package/lib/esm/geometry3d/Transform.d.ts.map +1 -1
  176. package/lib/esm/geometry3d/Transform.js +1 -1
  177. package/lib/esm/geometry3d/Transform.js.map +1 -1
  178. package/lib/esm/geometry3d/XYZProps.d.ts +10 -3
  179. package/lib/esm/geometry3d/XYZProps.d.ts.map +1 -1
  180. package/lib/esm/geometry3d/XYZProps.js +20 -1
  181. package/lib/esm/geometry3d/XYZProps.js.map +1 -1
  182. package/lib/esm/polyface/PolyfaceBuilder.d.ts +1 -1
  183. package/lib/esm/polyface/PolyfaceBuilder.js +2 -2
  184. package/lib/esm/polyface/PolyfaceBuilder.js.map +1 -1
  185. package/lib/esm/polyface/PolyfaceClip.d.ts.map +1 -1
  186. package/lib/esm/polyface/PolyfaceClip.js +1 -1
  187. package/lib/esm/polyface/PolyfaceClip.js.map +1 -1
  188. package/lib/esm/polyface/PolyfaceQuery.d.ts +4 -2
  189. package/lib/esm/polyface/PolyfaceQuery.d.ts.map +1 -1
  190. package/lib/esm/polyface/PolyfaceQuery.js +10 -6
  191. package/lib/esm/polyface/PolyfaceQuery.js.map +1 -1
  192. package/lib/esm/serialization/GeometrySamples.d.ts +2 -0
  193. package/lib/esm/serialization/GeometrySamples.d.ts.map +1 -1
  194. package/lib/esm/serialization/GeometrySamples.js +20 -0
  195. package/lib/esm/serialization/GeometrySamples.js.map +1 -1
  196. package/lib/esm/topology/Merging.js +3 -3
  197. package/lib/esm/topology/Merging.js.map +1 -1
  198. package/lib/esm/topology/Triangulation.d.ts +1 -3
  199. package/lib/esm/topology/Triangulation.d.ts.map +1 -1
  200. package/lib/esm/topology/Triangulation.js +31 -21
  201. package/lib/esm/topology/Triangulation.js.map +1 -1
  202. package/package.json +7 -7
@@ -19,27 +19,51 @@ const PointStreaming_1 = require("./PointStreaming");
19
19
  */
20
20
  class GrowableXYArray extends IndexedXYCollection_1.IndexedXYCollection {
21
21
  /** Construct a new GrowablePoint2d array.
22
- * @param numPoints [in] initial capacity.
22
+ * @param numPoints initial capacity in xy tuples (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 * 2); // 8 Points to start (2 values each)
27
+ this._data = new Float64Array(numPoints * 2); // 2 values per point
27
28
  this._xyInUse = 0;
28
- this._xyzCapacity = numPoints;
29
+ this._xyCapacity = numPoints;
30
+ this._growthFactor = (undefined !== growthFactor && growthFactor >= 1.0) ? growthFactor : 1.5;
31
+ }
32
+ /** Copy xy 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 * 2 : 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 * 2 : 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 % 2 !== 0)
52
+ myCount -= myCount % 2;
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 / 2, offset: myOffset / 2 };
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._xyInUse; }
32
- set length(newLength) {
33
- let oldLength = this.length;
34
- if (newLength < oldLength) {
35
- this._xyInUse = newLength;
36
- }
37
- else if (newLength > oldLength) {
38
- this.ensureCapacity(newLength);
39
- while (oldLength++ < newLength)
40
- this.pushXY(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._xyInUse * 2; }
45
69
  /** Return the raw packed data.
@@ -47,31 +71,29 @@ class GrowableXYArray extends IndexedXYCollection_1.IndexedXYCollection {
47
71
  */
48
72
  float64Data() { return this._data; }
49
73
  /** If necessary, increase the capacity to a new pointCount. Current coordinates and point count (length) are unchanged. */
50
- ensureCapacity(pointCapacity) {
51
- if (pointCapacity > this._xyzCapacity) {
52
- const newData = new Float64Array(pointCapacity * 2);
53
- const numCopy = this.length * 2;
54
- for (let i = 0; i < numCopy; i++)
55
- newData[i] = this._data[i];
56
- this._data = newData;
57
- this._xyzCapacity = pointCapacity;
58
- }
59
- }
60
- /** Resize the actual point count, preserving excess capacity. */
61
- resize(pointCount) {
62
- if (pointCount < this.length) {
63
- this._xyInUse = pointCount >= 0 ? pointCount : 0;
64
- }
65
- else if (pointCount > this._xyzCapacity) {
66
- const newArray = new Float64Array(pointCount * 2);
67
- // Copy contents
68
- for (let i = 0; i < this._data.length; i += 2) {
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;
74
+ ensureCapacity(pointCapacity, applyGrowthFactor = true) {
75
+ if (pointCapacity > this._xyCapacity) {
76
+ if (applyGrowthFactor)
77
+ pointCapacity *= this._growthFactor;
78
+ const prevData = this._data;
79
+ this._data = new Float64Array(pointCapacity * 2);
80
+ this.copyData(prevData, this._xyInUse);
81
+ this._xyCapacity = pointCapacity;
82
+ }
83
+ }
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._xyInUse)
92
+ this._xyInUse = pointCount;
93
+ else if (pointCount > this._xyInUse) {
94
+ this.ensureCapacity(pointCount, false);
95
+ if (padWithZero !== null && padWithZero !== void 0 ? padWithZero : false)
96
+ this._data.fill(0, this._xyInUse * 2);
75
97
  this._xyInUse = pointCount;
76
98
  }
77
99
  }
@@ -81,11 +103,7 @@ class GrowableXYArray extends IndexedXYCollection_1.IndexedXYCollection {
81
103
  */
82
104
  clone() {
83
105
  const newPoints = new GrowableXYArray(this.length);
84
- const numValue = this.length * 2;
85
- const newData = newPoints._data;
86
- const data = this._data;
87
- for (let i = 0; i < numValue; i++)
88
- newData[i] = data[i];
106
+ newPoints.copyData(this._data, this.length);
89
107
  newPoints._xyInUse = this.length;
90
108
  return newPoints;
91
109
  }
@@ -117,17 +135,18 @@ class GrowableXYArray extends IndexedXYCollection_1.IndexedXYCollection {
117
135
  }
118
136
  /** push all points of an array */
119
137
  pushAll(points) {
138
+ this.ensureCapacity(this._xyInUse + points.length, false);
120
139
  for (const p of points)
121
140
  this.push(p);
122
141
  }
123
142
  /** push all points of an array */
124
143
  pushAllXYAndZ(points) {
144
+ this.ensureCapacity(this._xyInUse + points.length, false);
125
145
  if (points instanceof GrowableXYZArray_1.GrowableXYZArray) {
126
146
  const xyzBuffer = points.float64Data();
127
147
  const n = points.length * 3;
128
- for (let i = 0; i + 2 < n; i += 3) {
148
+ for (let i = 0; i + 2 < n; i += 3)
129
149
  this.pushXY(xyzBuffer[i], xyzBuffer[i + 1]);
130
- }
131
150
  }
132
151
  else {
133
152
  for (const p of points)
@@ -135,38 +154,37 @@ class GrowableXYArray extends IndexedXYCollection_1.IndexedXYCollection {
135
154
  }
136
155
  }
137
156
  /**
138
- * Replicate numWrap xyz values from the front of the array as new values at the end.
139
- * @param numWrap number of xyz values to replicate
157
+ * Replicate numWrap xy values from the front of the array as new values at the end.
158
+ * @param numWrap number of xy values to replicate
140
159
  */
141
160
  pushWrap(numWrap) {
142
- if (this._xyInUse > 0) {
143
- let k;
161
+ if (this._xyInUse >= numWrap) {
162
+ this.ensureCapacity(this._xyInUse + numWrap, false);
144
163
  for (let i = 0; i < numWrap; i++) {
145
- k = 2 * i;
164
+ const k = 2 * i;
146
165
  this.pushXY(this._data[k], this._data[k + 1]);
147
166
  }
148
167
  }
149
168
  }
150
169
  /** push a point given by x,y coordinates */
151
170
  pushXY(x, y) {
171
+ this.ensureCapacity(this._xyInUse + 1);
152
172
  const index = this._xyInUse * 2;
153
- if (index >= this._data.length)
154
- this.ensureCapacity(this.length === 0 ? 4 : this.length * 2);
155
173
  this._data[index] = x;
156
174
  this._data[index + 1] = y;
157
175
  this._xyInUse++;
158
176
  }
159
177
  /** Remove one point from the back.
160
178
  * * NOTE that (in the manner of std::vector native) this is "just" removing the point -- no point is NOT returned.
161
- * * Use `back ()` to get the last x,y,z assembled into a `Point3d `
179
+ * * Use `back ()` to get the last x,y assembled into a `Point2d `
162
180
  */
163
181
  pop() {
164
182
  if (this._xyInUse > 0)
165
183
  this._xyInUse--;
166
184
  }
167
185
  /**
168
- * Test if index is valid for an xyz (point or vector) within this array
169
- * @param index xyz index to test.
186
+ * Test if index is valid for an xy (point or vector) within this array
187
+ * @param index xy index to test.
170
188
  */
171
189
  isIndexValid(index) {
172
190
  if (index >= this._xyInUse || index < 0)
@@ -174,7 +192,7 @@ class GrowableXYArray extends IndexedXYCollection_1.IndexedXYCollection {
174
192
  return true;
175
193
  }
176
194
  /**
177
- * Clear all xyz data, but leave capacity unchanged.
195
+ * Clear all xy data, but leave capacity unchanged.
178
196
  */
179
197
  clear() {
180
198
  this._xyInUse = 0;
@@ -213,18 +231,18 @@ class GrowableXYArray extends IndexedXYCollection_1.IndexedXYCollection {
213
231
  result.push(Point2dVector2d_1.Point2d.create(data[i], data[i + 1]));
214
232
  return result;
215
233
  }
216
- /** copy xyz into strongly typed Point2d */
234
+ /** copy xy into strongly typed Point2d */
217
235
  getPoint2dAtCheckedPointIndex(pointIndex, result) {
218
- const index = 2 * pointIndex;
219
236
  if (this.isIndexValid(pointIndex)) {
237
+ const index = 2 * pointIndex;
220
238
  return Point2dVector2d_1.Point2d.create(this._data[index], this._data[index + 1], result);
221
239
  }
222
240
  return undefined;
223
241
  }
224
- /** copy xyz into strongly typed Vector2d */
242
+ /** copy xy into strongly typed Vector2d */
225
243
  getVector2dAtCheckedVectorIndex(vectorIndex, result) {
226
- const index = 2 * vectorIndex;
227
244
  if (this.isIndexValid(vectorIndex)) {
245
+ const index = 2 * vectorIndex;
228
246
  return Point2dVector2d_1.Vector2d.create(this._data[index], this._data[index + 1], result);
229
247
  }
230
248
  return undefined;
@@ -242,7 +260,6 @@ class GrowableXYArray extends IndexedXYCollection_1.IndexedXYCollection {
242
260
  const j = sourceIndex * 2;
243
261
  this._data[i] = source._data[j];
244
262
  this._data[i + 1] = source._data[j + 1];
245
- this._data[i + 2] = source._data[j + 2];
246
263
  return true;
247
264
  }
248
265
  return false;
@@ -250,21 +267,19 @@ class GrowableXYArray extends IndexedXYCollection_1.IndexedXYCollection {
250
267
  /**
251
268
  * push coordinates from the source array to the end of this array.
252
269
  * @param source source array
253
- * @param sourceIndex xyz index within the source. If undefined, push entire contents of source
254
- * @returns true if sourceIndex is valid.
270
+ * @param sourceIndex xy index within the source. If undefined, push entire contents of source
271
+ * @returns number of points pushed.
255
272
  */
256
273
  pushFromGrowableXYArray(source, sourceIndex) {
274
+ // full array push . . .
257
275
  if (sourceIndex === undefined) {
258
- const numPresent = this.length;
259
- const numPush = source.length;
260
- this.ensureCapacity(numPresent + numPush);
261
- const numFloatPresent = 2 * numPresent;
262
- const numFloatAdd = 2 * numPush;
263
- for (let i = 0; i < numFloatAdd; i++)
264
- this._data[numFloatPresent + i] = source._data[i];
265
- this._xyInUse += numPush;
266
- return numPush;
276
+ const numXYAdd = source.length;
277
+ this.ensureCapacity(this.length + numXYAdd, false);
278
+ this.copyData(source._data, numXYAdd, this.length);
279
+ this._xyInUse += numXYAdd;
280
+ return numXYAdd;
267
281
  }
282
+ // single point push . . .
268
283
  if (source.isIndexValid(sourceIndex)) {
269
284
  const j = sourceIndex * 2;
270
285
  this.pushXY(source._data[j], source._data[j + 1]);
@@ -278,29 +293,31 @@ class GrowableXYArray extends IndexedXYCollection_1.IndexedXYCollection {
278
293
  */
279
294
  pushInterpolatedFromGrowableXYArray(source, i, fraction, j) {
280
295
  if (source.isIndexValid(i) && source.isIndexValid(j)) {
296
+ const fraction0 = 1.0 - fraction;
281
297
  const data = source._data;
282
- i = 3 * i;
283
- j = 3 * j;
284
- this.pushXY(Geometry_1.Geometry.interpolate(data[i], fraction, data[j]), Geometry_1.Geometry.interpolate(data[i + 1], fraction, data[j + 1]));
298
+ i = 2 * i;
299
+ j = 2 * j;
300
+ this.pushXY(fraction0 * data[i] + fraction * data[j], fraction0 * data[i + 1] + fraction * data[j + 1]);
285
301
  }
286
302
  }
287
303
  /**
288
- * push coordinates from the source array to the end of this array.
289
- * @param source source array
290
- * @param transform optional transform to apply to points.
304
+ * Create an array of xy points from source xyz points.
305
+ * @param source source array of xyz
306
+ * @param transform optional transform to apply to xyz points.
291
307
  * @param dest optional result.
292
308
  */
293
309
  static createFromGrowableXYZArray(source, transform, dest) {
294
- const packedXYZ = source.float64Data();
295
- const numXYZ = source.length; // this is in xyz points
296
- const nDouble = 3 * numXYZ;
310
+ const numPoints = source.length;
297
311
  if (!dest)
298
- dest = new GrowableXYArray(numXYZ);
299
- dest.clear();
300
- let x;
301
- let y;
302
- let z;
312
+ dest = new GrowableXYArray(numPoints);
313
+ else {
314
+ dest.ensureCapacity(numPoints, false);
315
+ dest.clear();
316
+ }
303
317
  if (transform) {
318
+ const packedXYZ = source.float64Data();
319
+ const nDouble = 3 * numPoints;
320
+ let x, y, z;
304
321
  for (let i = 0; i < nDouble; i += 3) {
305
322
  x = packedXYZ[i];
306
323
  y = packedXYZ[i + 1];
@@ -309,11 +326,7 @@ class GrowableXYArray extends IndexedXYCollection_1.IndexedXYCollection {
309
326
  }
310
327
  }
311
328
  else {
312
- for (let i = 0; i < nDouble; i += 3) {
313
- x = packedXYZ[i];
314
- y = packedXYZ[i + 1];
315
- dest.pushXY(x, y);
316
- }
329
+ dest.pushAllXYAndZ(source);
317
330
  }
318
331
  return dest;
319
332
  }
@@ -352,7 +365,7 @@ class GrowableXYArray extends IndexedXYCollection_1.IndexedXYCollection {
352
365
  * @param x x coordinate
353
366
  * @param y y coordinate
354
367
  */
355
- setXYZAtCheckedPointIndex(pointIndex, x, y) {
368
+ setXYAtCheckedPointIndex(pointIndex, x, y) {
356
369
  if (!this.isIndexValid(pointIndex))
357
370
  return false;
358
371
  const index = pointIndex * 2;
@@ -361,15 +374,21 @@ class GrowableXYArray extends IndexedXYCollection_1.IndexedXYCollection {
361
374
  return true;
362
375
  }
363
376
  /**
364
- * Copy all points into a simple array of Point3D with given z.
377
+ * Set the coordinates of a single point given as coordinates.
378
+ * @deprecated Use setXYAtCheckedPointIndex instead
379
+ */
380
+ setXYZAtCheckedPointIndex(pointIndex, x, y) {
381
+ return this.setXYAtCheckedPointIndex(pointIndex, x, y);
382
+ }
383
+ /**
384
+ * Copy all points into a simple array of Point3d with given z.
365
385
  */
366
386
  getPoint3dArray(z = 0) {
387
+ const n = 2 * this._xyInUse;
367
388
  const result = [];
368
389
  const data = this._data;
369
- const n = this.length;
370
- for (let i = 0; i < n; i++) {
371
- result.push(Point3dVector3d_1.Point3d.create(data[i * 2], data[i * 2 + 1], z));
372
- }
390
+ for (let i = 0; i < n; i += 2)
391
+ result.push(Point3dVector3d_1.Point3d.create(data[i], data[i + 1], z));
373
392
  return result;
374
393
  }
375
394
  /** reverse the order of points. */
@@ -401,21 +420,21 @@ class GrowableXYArray extends IndexedXYCollection_1.IndexedXYCollection {
401
420
  const y0 = origin.y;
402
421
  let x = 0;
403
422
  let y = 0;
404
- for (let i = 0; i + 2 <= nDouble; i += 2) {
423
+ for (let i = 0; i + 1 < nDouble; i += 2) {
405
424
  x = data[i];
406
425
  y = data[i + 1];
407
426
  data[i] = coffs[0] * x + coffs[1] * y + x0;
408
427
  data[i + 1] = coffs[3] * x + coffs[4] * y + y0;
409
428
  }
410
429
  }
411
- /** multiply each xyz (as a vector) by matrix, replace values. */
430
+ /** multiply each xy (as a vector) by matrix, replace values. */
412
431
  multiplyMatrix3dInPlace(matrix) {
413
432
  const data = this._data;
414
433
  const nDouble = this.float64Length;
415
434
  const coffs = matrix.coffs;
416
435
  let x = 0;
417
436
  let y = 0;
418
- for (let i = 0; i + 2 <= nDouble; i += 2) {
437
+ for (let i = 0; i + 1 < nDouble; i += 2) {
419
438
  x = data[i];
420
439
  y = data[i + 1];
421
440
  data[i] = coffs[0] * x + coffs[1] * y;
@@ -436,12 +455,11 @@ class GrowableXYArray extends IndexedXYCollection_1.IndexedXYCollection {
436
455
  const y0 = origin.y;
437
456
  let x = 0;
438
457
  let y = 0;
439
- for (let i = 0; i + 2 <= nDouble; i += 2) {
458
+ for (let i = 0; i + 1 < nDouble; i += 2) {
440
459
  x = data[i] - x0;
441
460
  y = data[i + 1] - y0;
442
461
  data[i] = coffs[0] * x + coffs[1] * y;
443
462
  data[i + 1] = coffs[3] * x + coffs[4] * y;
444
- data[i + 2] = coffs[6] * x + coffs[7] * y;
445
463
  }
446
464
  return true;
447
465
  }
@@ -450,11 +468,11 @@ class GrowableXYArray extends IndexedXYCollection_1.IndexedXYCollection {
450
468
  const numDouble = this.float64Length;
451
469
  const data = this._data;
452
470
  if (transform) {
453
- for (let i = 0; i + 2 <= numDouble; i += 2)
471
+ for (let i = 0; i + 1 < numDouble; i += 2)
454
472
  rangeToExtend.extendTransformedXY(transform, data[i], data[i + 1]);
455
473
  }
456
474
  else {
457
- for (let i = 0; i + 2 <= numDouble; i += 2)
475
+ for (let i = 0; i + 1 < numDouble; i += 2)
458
476
  rangeToExtend.extendXY(data[i], data[i + 1]);
459
477
  }
460
478
  }
@@ -468,7 +486,7 @@ class GrowableXYArray extends IndexedXYCollection_1.IndexedXYCollection {
468
486
  return sum;
469
487
  }
470
488
  /**
471
- * Multiply each x,y,z by the scale factor.
489
+ * Multiply each x,y by the scale factor.
472
490
  * @param factor
473
491
  */
474
492
  scaleInPlace(factor) {
@@ -528,21 +546,23 @@ class GrowableXYArray extends IndexedXYCollection_1.IndexedXYCollection {
528
546
  }
529
547
  /** Compute the cross product of vectors from from indexed origin to indexed targets i and j */
530
548
  crossProductIndexIndexIndex(originIndex, targetAIndex, targetBIndex) {
531
- const i = originIndex * 2;
532
- const j = targetAIndex * 2;
533
- const k = targetBIndex * 2;
534
- const data = this._data;
535
- if (this.isIndexValid(originIndex) && this.isIndexValid(targetAIndex) && this.isIndexValid(targetBIndex))
549
+ if (this.isIndexValid(originIndex) && this.isIndexValid(targetAIndex) && this.isIndexValid(targetBIndex)) {
550
+ const i = originIndex * 2;
551
+ const j = targetAIndex * 2;
552
+ const k = targetBIndex * 2;
553
+ const data = this._data;
536
554
  return Geometry_1.Geometry.crossProductXYXY(data[j] - data[i], data[j + 1] - data[i + 1], data[k] - data[i], data[k + 1] - data[i + 1]);
555
+ }
537
556
  return undefined;
538
557
  }
539
558
  /** Compute the cross product of vectors from from origin to indexed targets i and j */
540
559
  crossProductXAndYIndexIndex(origin, targetAIndex, targetBIndex) {
541
- const j = targetAIndex * 2;
542
- const k = targetBIndex * 2;
543
- const data = this._data;
544
- if (this.isIndexValid(targetAIndex) && this.isIndexValid(targetBIndex))
560
+ if (this.isIndexValid(targetAIndex) && this.isIndexValid(targetBIndex)) {
561
+ const j = targetAIndex * 2;
562
+ const k = targetBIndex * 2;
563
+ const data = this._data;
545
564
  return Geometry_1.Geometry.crossProductXYXY(data[j] - origin.x, data[j + 1] - origin.y, data[k] - origin.x, data[k + 1] - origin.y);
565
+ }
546
566
  return undefined;
547
567
  }
548
568
  /** Return the distance between two points in the array. */