@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
@@ -14,6 +14,7 @@ const Transform_1 = require("../../geometry3d/Transform");
14
14
  const Geometry_1 = require("../../Geometry");
15
15
  const CurveOffsetXYHandler_1 = require("../internalContexts/CurveOffsetXYHandler");
16
16
  const PolygonOffsetContext_1 = require("../internalContexts/PolygonOffsetContext");
17
+ const Range_1 = require("../../geometry3d/Range");
17
18
  /**
18
19
  * TransitionSpiral3d is a base class for multiple variants of spirals.
19
20
  * * The menagerie of spiral types have 2 broad categories:
@@ -134,6 +135,22 @@ class TransitionSpiral3d extends CurvePrimitive_1.CurvePrimitive {
134
135
  this.emitStrokableParts(handler, options.strokeOptions);
135
136
  return handler.claimResult();
136
137
  }
138
+ /** extend the range by the strokes of the spiral */
139
+ extendRange(rangeToExtend, transform) {
140
+ const myRange = this.rangeBetweenFractions(0.0, 1.0, transform);
141
+ rangeToExtend.extendRange(myRange);
142
+ }
143
+ /** return the range of spiral between fractions of the activeStrokes.
144
+ * * Use activeStrokes point count times interval factor for initial evaluation count, but do at least 5
145
+ */
146
+ rangeBetweenFractions(fractionA, fractionB, transform) {
147
+ const strokes = this.activeStrokes;
148
+ if (undefined === strokes)
149
+ return Range_1.Range3d.createNull();
150
+ let count = Math.ceil(strokes.numPoints() * Math.abs(fractionB - fractionA));
151
+ count = Geometry_1.Geometry.clamp(5, count, 30);
152
+ return this.rangeBetweenFractionsByCount(fractionA, fractionB, count, transform, 0.5);
153
+ }
137
154
  }
138
155
  exports.TransitionSpiral3d = TransitionSpiral3d;
139
156
  //# sourceMappingURL=TransitionSpiral3d.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"TransitionSpiral3d.js","sourceRoot":"","sources":["../../../../src/curve/spiral/TransitionSpiral3d.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F;;GAEG;AAEH,sDAAmD;AAEnD,0DAAuD;AACvD,0DAAuD;AAEvD,6CAA0C;AAE1C,mFAAgF;AAChF,mFAAyE;AAkCzE;;;;;;;;;;;;GAYG;AACH,MAAsB,kBAAmB,SAAQ,+BAAc;IAmB7D,YAAsB,UAA8B,EAAE,YAAuB,EAAE,sBAA6C,EAAE,gBAA6D;QACzL,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,mBAAmB,CAAC;QACj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AClB;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;IAED;;;;;OAKG;IACa,iBAAiB,CAAC,uBAA+C;QAC/E,MAAM,OAAO,GAAG,oCAAa,CAAC,MAAM,CAAC,uBAAuB,CAAC,CAAC;QAC9D,MAAM,OAAO,GAAG,IAAI,2CAAoB,CAAC,IAAI,EAAE,OAAO,CAAC,kBAAkB,CAAC,CAAC;QAC3E,IAAI,CAAC,kBAAkB,CAAC,OAAO,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;QACxD,OAAO,OAAO,CAAC,WAAW,EAAE,CAAC;IAC/B,CAAC;CACF;AAzID,gDAyIC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n\r\n/** @packageDocumentation\r\n * @module Curve\r\n */\r\n\r\nimport { CurvePrimitive } from \"../CurvePrimitive\";\r\nimport { Matrix3d } from \"../../geometry3d/Matrix3d\";\r\nimport { Segment1d } from \"../../geometry3d/Segment1d\";\r\nimport { Transform } from \"../../geometry3d/Transform\";\r\nimport { TransitionConditionalProperties } from \"./TransitionConditionalProperties\";\r\nimport { Geometry } from \"../../Geometry\";\r\nimport { LineString3d } from \"../LineString3d\";\r\nimport { CurveOffsetXYHandler } from \"../internalContexts/CurveOffsetXYHandler\";\r\nimport { OffsetOptions } from \"../internalContexts/PolygonOffsetContext\";\r\n/**\r\n * This is the set of valid type names for \"integrated\" spirals\r\n * * Behavior is expressed by a `NormalizedTransition` snap function.\r\n * * The snap function varies smoothly from f(0)=0 to f(1)=1\r\n * * The various snap functions are:\r\n * * clothoid: linear\r\n * * biquadratic: 2 quadratics pieced together, joining with 1st derivative continuity at f(0.) = 0.5, with zero slope f'(0)=0 and f'(1)= 0\r\n * * bloss: A single cubic with zero slope at 0 and 1\r\n * * cosine: half of a cosine wave, centered around 0.5\r\n * * sine: full period of a sine wave added to the line f(u)=u\r\n * *\r\n * @public\r\n */\r\nexport type IntegratedSpiralTypeName = \"clothoid\" | \"bloss\" | \"biquadratic\" | \"cosine\" | \"sine\";\r\n\r\n/**\r\n * This is the set of valid type names for \"direct\" spirals.\r\n * \"Direct\" spirals can evaluate fractionToPoint by direct equations, i.e. not requiring the numeric integrations in \"Integrated\" spiral types.\r\n * @public\r\n */\r\nexport type DirectSpiralTypeName =\r\n \"JapaneseCubic\" // 1 term from each of the X,Y clothoid series expansions: y = x^3 / (6RL)\r\n | \"Arema\" // 2 terms from each of the X,Y clothoid series expansions. Identical to ChineseCubic!\r\n | \"ChineseCubic\" // Identical to Arema!\r\n | \"HalfCosine\" // high continuity cosine variation from quadratic.\r\n | \"AustralianRailCorp\" // cubic with high accuracy distance series\r\n | \"WesternAustralian\" // simple cubic -- 2 terms of x series, 1 term of y series.\r\n | \"Czech\" // simple cubic with two term distance approximation\r\n | \"MXCubicAlongArc\" // x obtained from fractional distance via 2-terms from series, y = x^3/ (6RL)\r\n | \"Polish\"\r\n | \"Italian\"\r\n ;\r\n\r\n/**\r\n * TransitionSpiral3d is a base class for multiple variants of spirals.\r\n * * The menagerie of spiral types have 2 broad categories:\r\n * * IntegratedSpiral3d -- a spiral whose direct function for curvature versus distance must be integrated to determine x,y\r\n * * The IntegratedSpiral3d types are enumerated in `IntegratedSpiralTypes`\r\n * * DirectSpiral3d -- a spiral implemented with direct calculation of x,y from fractional position along the spiral.\r\n * * The direct spiral types are enumerated in the `DirectSpiralType`\r\n * * The method set for CurvePrimitive support includes a `handleTransitionSpiral(g: TransitionSpiral3d)` which receives all the spiral types.\r\n * * The spiral class may impose expectations that its inflection is at the origin, with tangent along the x axis.\r\n * * This is generally necessary for direct spirals.\r\n * * This is not necessary for integrated spirals.\r\n * @public\r\n */\r\nexport abstract class TransitionSpiral3d extends CurvePrimitive {\r\n /** string name of spiral type */\r\n protected _spiralType: string;\r\n /** Original defining properties. */\r\n protected _designProperties: TransitionConditionalProperties | undefined;\r\n\r\n /** Fractional interval for the \"active\" part of a containing spiral.\r\n * (The radius, angle, and length conditions define a complete spiral, and some portion of it is \"active\")\r\n */\r\n protected _activeFractionInterval: Segment1d;\r\n /** Return (reference to) the active portion of the reference spiral. */\r\n public get activeFractionInterval(): Segment1d { return this._activeFractionInterval; }\r\n /** strokes in the active portion */\r\n public abstract get activeStrokes(): LineString3d;\r\n /** Placement transform */\r\n protected _localToWorld: Transform;\r\n /** (reference to) placement transform. */\r\n public get localToWorld(): Transform { return this._localToWorld; }\r\n\r\n protected constructor(spiralType: string | undefined, localToWorld: Transform, activeFractionInterval: Segment1d | undefined, designProperties: TransitionConditionalProperties | undefined) {\r\n super();\r\n this._spiralType = spiralType ? spiralType : \"unknownSpiralType\";\r\n this._designProperties = designProperties;\r\n this._localToWorld = localToWorld;\r\n this._activeFractionInterval = activeFractionInterval ? activeFractionInterval : Segment1d.create(0, 1);\r\n }\r\n\r\n public get spiralType(): string { return this._spiralType; }\r\n /** Return 1/r with convention that if true zero is given as radius it represents infinite radius (0 curvature, straight line) */\r\n public static radiusToCurvature(radius: number): number { return (radius === 0.0) ? 0.0 : 1.0 / radius; }\r\n\r\n /** Return 1/k with convention that if near-zero is given as curvature, its infinite radius is returned as 0 */\r\n public static curvatureToRadius(curvature: number): number {\r\n if (Math.abs(curvature) < Geometry.smallAngleRadians)\r\n return 0.0;\r\n return 1.0 / curvature;\r\n }\r\n\r\n /** Return a deep clone. */\r\n public abstract override clone(): TransitionSpiral3d;\r\n\r\n /** Recompute strokes */\r\n public abstract refreshComputedProperties(): void;\r\n\r\n /** Return (if possible) a spiral which is a portion of this curve. */\r\n public override clonePartialCurve(fractionA: number, fractionB: number): TransitionSpiral3d {\r\n const spiralB = this.clone();\r\n const globalFractionA = this._activeFractionInterval.fractionToPoint(fractionA);\r\n const globalFractionB = this._activeFractionInterval.fractionToPoint(fractionB);\r\n spiralB._activeFractionInterval.set(globalFractionA, globalFractionB);\r\n spiralB.refreshComputedProperties();\r\n return spiralB;\r\n }\r\n\r\n /** Clone with a transform applied */\r\n public override cloneTransformed(transform: Transform): TransitionSpiral3d {\r\n const result = this.clone();\r\n result.tryTransformInPlace(transform); // ok, we're confident it will always work.\r\n return result;\r\n }\r\n\r\n /** Return the average of the start and end curvatures. */\r\n public static averageCurvature(radiusLimits: Segment1d): number {\r\n return 0.5 * (TransitionSpiral3d.radiusToCurvature(radiusLimits.x0) + TransitionSpiral3d.radiusToCurvature(radiusLimits.x1));\r\n }\r\n /**\r\n * Given two radii (or zeros for 0 curvature) return the average curvature\r\n * @param r0 start radius, or 0 for line\r\n * @param r1 end radius, or 0 for line\r\n */\r\n public static averageCurvatureR0R1(r0: number, r1: number): number {\r\n return 0.5 * (TransitionSpiral3d.radiusToCurvature(r0) + TransitionSpiral3d.radiusToCurvature(r1));\r\n }\r\n /**\r\n * Given two radii (or zeros for 0 curvature) return the average curvature\r\n * @param r0 start radius, or 0 for line\r\n * @param r1 end radius, or 0 for line\r\n */\r\n public static interpolateCurvatureR0R1(r0: number, fraction: number, r1: number): number {\r\n return Geometry.interpolate(TransitionSpiral3d.radiusToCurvature(r0), fraction, TransitionSpiral3d.radiusToCurvature(r1));\r\n }\r\n\r\n /** Return the arc length of a transition spiral with given sweep and radius pair. */\r\n public static radiusRadiusSweepRadiansToArcLength(radius0: number, radius1: number, sweepRadians: number): number {\r\n return Math.abs(sweepRadians / TransitionSpiral3d.averageCurvatureR0R1(radius0, radius1));\r\n }\r\n\r\n /** Return the turn angle for spiral of given length between two radii */\r\n public static radiusRadiusLengthToSweepRadians(radius0: number, radius1: number, arcLength: number): number {\r\n return TransitionSpiral3d.averageCurvatureR0R1(radius0, radius1) * arcLength;\r\n }\r\n\r\n /** Return the end radius for spiral of given start radius, length, and turn angle. */\r\n public static radius0LengthSweepRadiansToRadius1(radius0: number, arcLength: number, sweepRadians: number) {\r\n return TransitionSpiral3d.curvatureToRadius((2.0 * sweepRadians / arcLength) - TransitionSpiral3d.radiusToCurvature(radius0));\r\n }\r\n /** Return the start radius for spiral of given end radius, length, and turn angle. */\r\n public static radius1LengthSweepRadiansToRadius0(radius1: number, arcLength: number, sweepRadians: number) {\r\n return TransitionSpiral3d.curvatureToRadius((2.0 * sweepRadians / arcLength) - TransitionSpiral3d.radiusToCurvature(radius1));\r\n }\r\n /** Return the original defining properties (if any) saved by the constructor. */\r\n public get designProperties(): TransitionConditionalProperties | undefined { return this._designProperties; }\r\n /**\r\n * * If transformA is rigid with uniform scale, apply the rigid part of transformA to the localToWorld transform and return the scale and rigid separation.\r\n * * If not rigid, do nothing and return undefined.\r\n * * Also apply the scale factor to the designProperties.\r\n * @param transformA\r\n */\r\n protected applyRigidPartOfTransform(transformA: Transform): { rigidAxes: Matrix3d, scale: number } | undefined {\r\n const rigidData = transformA.matrix.factorRigidWithSignedScale();\r\n if (rigidData !== undefined) {\r\n // [sQ a][R b] = [sQ*R sQb+a]\r\n // but we save it as [Q*R sQb+a] with spiral data scaled by s.\r\n const transformC0 = transformA.multiplyTransformTransform(this.localToWorld);\r\n // BUT pull the scale part out of the matrix ...\r\n const matrixC = rigidData.rigidAxes.multiplyMatrixMatrix(this.localToWorld.matrix);\r\n this._localToWorld = Transform.createOriginAndMatrix(transformC0.origin, matrixC);\r\n if (this.designProperties)\r\n this.designProperties.applyScaleFactor(rigidData.scale);\r\n\r\n return rigidData;\r\n }\r\n return undefined;\r\n }\r\n\r\n /**\r\n * Construct an offset of the instance curve as viewed in the xy-plane (ignoring z).\r\n * * No attempt is made to join the offsets of smaller constituent primitives. To construct a fully joined offset\r\n * for an aggregate instance (e.g., LineString3d, CurveChainWithDistanceIndex), use RegionOps.constructCurveXYOffset() instead.\r\n * @param offsetDistanceOrOptions offset distance (positive to left of the instance curve), or options object\r\n */\r\n public override constructOffsetXY(offsetDistanceOrOptions: number | OffsetOptions): CurvePrimitive | CurvePrimitive[] | undefined {\r\n const options = OffsetOptions.create(offsetDistanceOrOptions);\r\n const handler = new CurveOffsetXYHandler(this, options.leftOffsetDistance);\r\n this.emitStrokableParts(handler, options.strokeOptions);\r\n return handler.claimResult();\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"TransitionSpiral3d.js","sourceRoot":"","sources":["../../../../src/curve/spiral/TransitionSpiral3d.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F;;GAEG;AAEH,sDAAmD;AAEnD,0DAAuD;AACvD,0DAAuD;AAEvD,6CAA0C;AAE1C,mFAAgF;AAChF,mFAAyE;AACzE,kDAAiD;AAkCjD;;;;;;;;;;;;GAYG;AACH,MAAsB,kBAAmB,SAAQ,+BAAc;IAmB7D,YAAsB,UAA8B,EAAE,YAAuB,EAAE,sBAA6C,EAAE,gBAA6D;QACzL,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,mBAAmB,CAAC;QACjE,IAAI,CAAC,iBAAiB,GAAG,gBAAgB,CAAC;QAC1C,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC;QAClC,IAAI,CAAC,uBAAuB,GAAG,sBAAsB,CAAC,CAAC,CAAC,sBAAsB,CAAC,CAAC,CAAC,qBAAS,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAC1G,CAAC;IAfD,wEAAwE;IACxE,IAAW,sBAAsB,KAAgB,OAAO,IAAI,CAAC,uBAAuB,CAAC,CAAC,CAAC;IAKvF,0CAA0C;IAC1C,IAAW,YAAY,KAAgB,OAAO,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC;IAUnE,IAAW,UAAU,KAAa,OAAO,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC;IAC5D,iIAAiI;IAC1H,MAAM,CAAC,iBAAiB,CAAC,MAAc,IAAY,OAAO,CAAC,MAAM,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,MAAM,CAAC,CAAC,CAAC;IAEzG,+GAA+G;IACxG,MAAM,CAAC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CAAC;QACnC,IAAI,SAAS,KAAK,OAAO;YACvB,OAAO,eAAO,CAAC,UAAU,EAAG,CAAC;QAC/B,IAAI,KAAK,GAAG,IAAI,CAAC,IAAI,CAAE,OAAO,CAAC,SAAS,EAAE,GAAG,IAAI,CAAC,GAAG,CAAE,SAAS,GAAG,SAAS,CAAC,CAAC,CAAC;QAC/E,KAAK,GAAG,mBAAQ,CAAC,KAAK,CAAE,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC;QACtC,OAAO,IAAI,CAAC,4BAA4B,CAAE,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,CAAC,CAAC;IACzF,CAAC;CACF;AA1JD,gDA0JC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n\r\n/** @packageDocumentation\r\n * @module Curve\r\n */\r\n\r\nimport { CurvePrimitive } from \"../CurvePrimitive\";\r\nimport { Matrix3d } from \"../../geometry3d/Matrix3d\";\r\nimport { Segment1d } from \"../../geometry3d/Segment1d\";\r\nimport { Transform } from \"../../geometry3d/Transform\";\r\nimport { TransitionConditionalProperties } from \"./TransitionConditionalProperties\";\r\nimport { Geometry } from \"../../Geometry\";\r\nimport { LineString3d } from \"../LineString3d\";\r\nimport { CurveOffsetXYHandler } from \"../internalContexts/CurveOffsetXYHandler\";\r\nimport { OffsetOptions } from \"../internalContexts/PolygonOffsetContext\";\r\nimport { Range3d } from \"../../geometry3d/Range\";\r\n/**\r\n * This is the set of valid type names for \"integrated\" spirals\r\n * * Behavior is expressed by a `NormalizedTransition` snap function.\r\n * * The snap function varies smoothly from f(0)=0 to f(1)=1\r\n * * The various snap functions are:\r\n * * clothoid: linear\r\n * * biquadratic: 2 quadratics pieced together, joining with 1st derivative continuity at f(0.) = 0.5, with zero slope f'(0)=0 and f'(1)= 0\r\n * * bloss: A single cubic with zero slope at 0 and 1\r\n * * cosine: half of a cosine wave, centered around 0.5\r\n * * sine: full period of a sine wave added to the line f(u)=u\r\n * *\r\n * @public\r\n */\r\nexport type IntegratedSpiralTypeName = \"clothoid\" | \"bloss\" | \"biquadratic\" | \"cosine\" | \"sine\";\r\n\r\n/**\r\n * This is the set of valid type names for \"direct\" spirals.\r\n * \"Direct\" spirals can evaluate fractionToPoint by direct equations, i.e. not requiring the numeric integrations in \"Integrated\" spiral types.\r\n * @public\r\n */\r\nexport type DirectSpiralTypeName =\r\n \"JapaneseCubic\" // 1 term from each of the X,Y clothoid series expansions: y = x^3 / (6RL)\r\n | \"Arema\" // 2 terms from each of the X,Y clothoid series expansions. Identical to ChineseCubic!\r\n | \"ChineseCubic\" // Identical to Arema!\r\n | \"HalfCosine\" // high continuity cosine variation from quadratic.\r\n | \"AustralianRailCorp\" // cubic with high accuracy distance series\r\n | \"WesternAustralian\" // simple cubic -- 2 terms of x series, 1 term of y series.\r\n | \"Czech\" // simple cubic with two term distance approximation\r\n | \"MXCubicAlongArc\" // x obtained from fractional distance via 2-terms from series, y = x^3/ (6RL)\r\n | \"Polish\"\r\n | \"Italian\"\r\n ;\r\n\r\n/**\r\n * TransitionSpiral3d is a base class for multiple variants of spirals.\r\n * * The menagerie of spiral types have 2 broad categories:\r\n * * IntegratedSpiral3d -- a spiral whose direct function for curvature versus distance must be integrated to determine x,y\r\n * * The IntegratedSpiral3d types are enumerated in `IntegratedSpiralTypes`\r\n * * DirectSpiral3d -- a spiral implemented with direct calculation of x,y from fractional position along the spiral.\r\n * * The direct spiral types are enumerated in the `DirectSpiralType`\r\n * * The method set for CurvePrimitive support includes a `handleTransitionSpiral(g: TransitionSpiral3d)` which receives all the spiral types.\r\n * * The spiral class may impose expectations that its inflection is at the origin, with tangent along the x axis.\r\n * * This is generally necessary for direct spirals.\r\n * * This is not necessary for integrated spirals.\r\n * @public\r\n */\r\nexport abstract class TransitionSpiral3d extends CurvePrimitive {\r\n /** string name of spiral type */\r\n protected _spiralType: string;\r\n /** Original defining properties. */\r\n protected _designProperties: TransitionConditionalProperties | undefined;\r\n\r\n /** Fractional interval for the \"active\" part of a containing spiral.\r\n * (The radius, angle, and length conditions define a complete spiral, and some portion of it is \"active\")\r\n */\r\n protected _activeFractionInterval: Segment1d;\r\n /** Return (reference to) the active portion of the reference spiral. */\r\n public get activeFractionInterval(): Segment1d { return this._activeFractionInterval; }\r\n /** strokes in the active portion */\r\n public abstract get activeStrokes(): LineString3d;\r\n /** Placement transform */\r\n protected _localToWorld: Transform;\r\n /** (reference to) placement transform. */\r\n public get localToWorld(): Transform { return this._localToWorld; }\r\n\r\n protected constructor(spiralType: string | undefined, localToWorld: Transform, activeFractionInterval: Segment1d | undefined, designProperties: TransitionConditionalProperties | undefined) {\r\n super();\r\n this._spiralType = spiralType ? spiralType : \"unknownSpiralType\";\r\n this._designProperties = designProperties;\r\n this._localToWorld = localToWorld;\r\n this._activeFractionInterval = activeFractionInterval ? activeFractionInterval : Segment1d.create(0, 1);\r\n }\r\n\r\n public get spiralType(): string { return this._spiralType; }\r\n /** Return 1/r with convention that if true zero is given as radius it represents infinite radius (0 curvature, straight line) */\r\n public static radiusToCurvature(radius: number): number { return (radius === 0.0) ? 0.0 : 1.0 / radius; }\r\n\r\n /** Return 1/k with convention that if near-zero is given as curvature, its infinite radius is returned as 0 */\r\n public static curvatureToRadius(curvature: number): number {\r\n if (Math.abs(curvature) < Geometry.smallAngleRadians)\r\n return 0.0;\r\n return 1.0 / curvature;\r\n }\r\n\r\n /** Return a deep clone. */\r\n public abstract override clone(): TransitionSpiral3d;\r\n\r\n /** Recompute strokes */\r\n public abstract refreshComputedProperties(): void;\r\n\r\n /** Return (if possible) a spiral which is a portion of this curve. */\r\n public override clonePartialCurve(fractionA: number, fractionB: number): TransitionSpiral3d {\r\n const spiralB = this.clone();\r\n const globalFractionA = this._activeFractionInterval.fractionToPoint(fractionA);\r\n const globalFractionB = this._activeFractionInterval.fractionToPoint(fractionB);\r\n spiralB._activeFractionInterval.set(globalFractionA, globalFractionB);\r\n spiralB.refreshComputedProperties();\r\n return spiralB;\r\n }\r\n\r\n /** Clone with a transform applied */\r\n public override cloneTransformed(transform: Transform): TransitionSpiral3d {\r\n const result = this.clone();\r\n result.tryTransformInPlace(transform); // ok, we're confident it will always work.\r\n return result;\r\n }\r\n\r\n /** Return the average of the start and end curvatures. */\r\n public static averageCurvature(radiusLimits: Segment1d): number {\r\n return 0.5 * (TransitionSpiral3d.radiusToCurvature(radiusLimits.x0) + TransitionSpiral3d.radiusToCurvature(radiusLimits.x1));\r\n }\r\n /**\r\n * Given two radii (or zeros for 0 curvature) return the average curvature\r\n * @param r0 start radius, or 0 for line\r\n * @param r1 end radius, or 0 for line\r\n */\r\n public static averageCurvatureR0R1(r0: number, r1: number): number {\r\n return 0.5 * (TransitionSpiral3d.radiusToCurvature(r0) + TransitionSpiral3d.radiusToCurvature(r1));\r\n }\r\n /**\r\n * Given two radii (or zeros for 0 curvature) return the average curvature\r\n * @param r0 start radius, or 0 for line\r\n * @param r1 end radius, or 0 for line\r\n */\r\n public static interpolateCurvatureR0R1(r0: number, fraction: number, r1: number): number {\r\n return Geometry.interpolate(TransitionSpiral3d.radiusToCurvature(r0), fraction, TransitionSpiral3d.radiusToCurvature(r1));\r\n }\r\n\r\n /** Return the arc length of a transition spiral with given sweep and radius pair. */\r\n public static radiusRadiusSweepRadiansToArcLength(radius0: number, radius1: number, sweepRadians: number): number {\r\n return Math.abs(sweepRadians / TransitionSpiral3d.averageCurvatureR0R1(radius0, radius1));\r\n }\r\n\r\n /** Return the turn angle for spiral of given length between two radii */\r\n public static radiusRadiusLengthToSweepRadians(radius0: number, radius1: number, arcLength: number): number {\r\n return TransitionSpiral3d.averageCurvatureR0R1(radius0, radius1) * arcLength;\r\n }\r\n\r\n /** Return the end radius for spiral of given start radius, length, and turn angle. */\r\n public static radius0LengthSweepRadiansToRadius1(radius0: number, arcLength: number, sweepRadians: number) {\r\n return TransitionSpiral3d.curvatureToRadius((2.0 * sweepRadians / arcLength) - TransitionSpiral3d.radiusToCurvature(radius0));\r\n }\r\n /** Return the start radius for spiral of given end radius, length, and turn angle. */\r\n public static radius1LengthSweepRadiansToRadius0(radius1: number, arcLength: number, sweepRadians: number) {\r\n return TransitionSpiral3d.curvatureToRadius((2.0 * sweepRadians / arcLength) - TransitionSpiral3d.radiusToCurvature(radius1));\r\n }\r\n /** Return the original defining properties (if any) saved by the constructor. */\r\n public get designProperties(): TransitionConditionalProperties | undefined { return this._designProperties; }\r\n /**\r\n * * If transformA is rigid with uniform scale, apply the rigid part of transformA to the localToWorld transform and return the scale and rigid separation.\r\n * * If not rigid, do nothing and return undefined.\r\n * * Also apply the scale factor to the designProperties.\r\n * @param transformA\r\n */\r\n protected applyRigidPartOfTransform(transformA: Transform): { rigidAxes: Matrix3d, scale: number } | undefined {\r\n const rigidData = transformA.matrix.factorRigidWithSignedScale();\r\n if (rigidData !== undefined) {\r\n // [sQ a][R b] = [sQ*R sQb+a]\r\n // but we save it as [Q*R sQb+a] with spiral data scaled by s.\r\n const transformC0 = transformA.multiplyTransformTransform(this.localToWorld);\r\n // BUT pull the scale part out of the matrix ...\r\n const matrixC = rigidData.rigidAxes.multiplyMatrixMatrix(this.localToWorld.matrix);\r\n this._localToWorld = Transform.createOriginAndMatrix(transformC0.origin, matrixC);\r\n if (this.designProperties)\r\n this.designProperties.applyScaleFactor(rigidData.scale);\r\n\r\n return rigidData;\r\n }\r\n return undefined;\r\n }\r\n\r\n /**\r\n * Construct an offset of the instance curve as viewed in the xy-plane (ignoring z).\r\n * * No attempt is made to join the offsets of smaller constituent primitives. To construct a fully joined offset\r\n * for an aggregate instance (e.g., LineString3d, CurveChainWithDistanceIndex), use RegionOps.constructCurveXYOffset() instead.\r\n * @param offsetDistanceOrOptions offset distance (positive to left of the instance curve), or options object\r\n */\r\n public override constructOffsetXY(offsetDistanceOrOptions: number | OffsetOptions): CurvePrimitive | CurvePrimitive[] | undefined {\r\n const options = OffsetOptions.create(offsetDistanceOrOptions);\r\n const handler = new CurveOffsetXYHandler(this, options.leftOffsetDistance);\r\n this.emitStrokableParts(handler, options.strokeOptions);\r\n return handler.claimResult();\r\n }\r\n /** extend the range by the strokes of the spiral */\r\n public override extendRange(rangeToExtend: Range3d, transform?: Transform): void {\r\n const myRange = this.rangeBetweenFractions (0.0, 1.0, transform);\r\n rangeToExtend.extendRange (myRange);\r\n }\r\n\r\n /** return the range of spiral between fractions of the activeStrokes.\r\n * * Use activeStrokes point count times interval factor for initial evaluation count, but do at least 5\r\n */\r\n public override rangeBetweenFractions(fractionA: number, fractionB: number, transform?: Transform): Range3d {\r\n const strokes = this.activeStrokes;\r\n if (undefined === strokes)\r\n return Range3d.createNull ();\r\n let count = Math.ceil (strokes.numPoints() * Math.abs (fractionB - fractionA));\r\n count = Geometry.clamp (5, count, 30);\r\n return this.rangeBetweenFractionsByCount (fractionA, fractionB, count, transform, 0.5);\r\n }\r\n}\r\n"]}
@@ -16,13 +16,42 @@ export declare class GrowableBlockedArray {
16
16
  * * If viewing the array as a two dimensional array, this is the row size.
17
17
  */
18
18
  protected _blockSize: number;
19
- constructor(blockSize: number, initialBlocks?: number);
19
+ /**
20
+ * multiplier used by ensureBlockCapacity to expand requested reallocation size
21
+ */
22
+ protected _growthFactor: number;
23
+ /**
24
+ * Construct an array whose contents are in blocked (row-major) order, possibly with extra capacity.
25
+ * * Total capacity is `this._data.length`
26
+ * * Actual in-use count is `this._inUse * this._blockSize`
27
+ * @param blockSize number of entries in each block, i.e., row size
28
+ * @param initialBlocks initial capacity in blocks (default 8)
29
+ * @param growthFactor used by ensureBlockCapacity to expand requested reallocation size (default 1.5)
30
+ */
31
+ constructor(blockSize: number, initialBlocks?: number, growthFactor?: number);
32
+ /** Copy data from source array. Does not reallocate or change active block count.
33
+ * @param source array to copy from
34
+ * @param sourceCount copy the first sourceCount blocks; all blocks if undefined
35
+ * @param destOffset copy to instance array starting at this block index; zero if undefined
36
+ * @return count and offset of blocks copied
37
+ */
38
+ protected copyData(source: Float64Array | number[], sourceCount?: number, destOffset?: number): {
39
+ count: number;
40
+ offset: number;
41
+ };
42
+ /**
43
+ * Make a copy of the (active) blocks in this array.
44
+ * (The clone does NOT get excess capacity)
45
+ */
46
+ clone(): GrowableBlockedArray;
47
+ /** computed property: length (in blocks, not doubles) */
48
+ get length(): number;
20
49
  /** computed property: length (in blocks, not doubles) */
21
50
  get numBlocks(): number;
22
51
  /** property: number of data values per block */
23
52
  get numPerBlock(): number;
24
53
  /**
25
- * Return a single value indexed within a block
54
+ * Return a single value indexed within a block. Indices are unchecked.
26
55
  * @param blockIndex index of block to read
27
56
  * @param indexInBlock offset within the block
28
57
  */
@@ -32,7 +61,7 @@ export declare class GrowableBlockedArray {
32
61
  /** Return the capacity in blocks (not doubles) */
33
62
  blockCapacity(): number;
34
63
  /** ensure capacity (in blocks, not doubles) */
35
- ensureBlockCapacity(blockCapacity: number): void;
64
+ ensureBlockCapacity(blockCapacity: number, applyGrowthFactor?: boolean): void;
36
65
  /** Add a new block of data.
37
66
  * * If newData has fewer than numPerBlock entries, the remaining part of the new block is zeros.
38
67
  * * If newData has more entries, only the first numPerBlock are taken.
@@ -1 +1 @@
1
- {"version":3,"file":"GrowableBlockedArray.d.ts","sourceRoot":"","sources":["../../../src/geometry3d/GrowableBlockedArray.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAEjE;;;;GAIG;AACH,qBAAa,oBAAoB;IAC/B,+CAA+C;IAC/C,SAAS,CAAC,KAAK,EAAE,YAAY,CAAC;IAC9B,6CAA6C;IAC7C,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC;IACzB;;OAEG;IACH,SAAS,CAAC,UAAU,EAAE,MAAM,CAAC;gBACV,SAAS,EAAE,MAAM,EAAE,aAAa,GAAE,MAAU;IAS/D,yDAAyD;IACzD,IAAW,SAAS,IAAI,MAAM,CAAwB;IACtD,g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wHAAwH;IACjH,gBAAgB,CAAC,UAAU,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAKvF,oFAAoF;IAC7E,SAAS,CAAC,UAAU,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,MAAM;IAGpE;;;;;OAKG;WACW,mBAAmB,CAAC,IAAI,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM;IAWxG,+EAA+E;IACxE,kBAAkB,CAAC,aAAa,GAAE,uBAAkE,GAAG,WAAW;IAezH,qFAAqF;IAC9E,qBAAqB,CAAC,WAAW,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM;IAa9E,2HAA2H;IACpH,wBAAwB,CAAC,WAAW,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM;CAYhH"}
@@ -14,21 +14,70 @@ exports.GrowableBlockedArray = void 0;
14
14
  * @public
15
15
  */
16
16
  class GrowableBlockedArray {
17
- constructor(blockSize, initialBlocks = 8) {
18
- /** array contents in blocked (row-major) order, possibly with extra capacity
19
- * Total capacity is `this._data.length`
20
- * Actual in-use count is `this._inUse * this._blockSize`
21
- */
17
+ /**
18
+ * Construct an array whose contents are in blocked (row-major) order, possibly with extra capacity.
19
+ * * Total capacity is `this._data.length`
20
+ * * Actual in-use count is `this._inUse * this._blockSize`
21
+ * @param blockSize number of entries in each block, i.e., row size
22
+ * @param initialBlocks initial capacity in blocks (default 8)
23
+ * @param growthFactor used by ensureBlockCapacity to expand requested reallocation size (default 1.5)
24
+ */
25
+ constructor(blockSize, initialBlocks = 8, growthFactor) {
22
26
  this._data = new Float64Array(initialBlocks * blockSize);
23
27
  this._inUse = 0;
24
- this._blockSize = blockSize;
28
+ this._blockSize = blockSize > 0 ? blockSize : 1;
29
+ this._growthFactor = (undefined !== growthFactor && growthFactor >= 1.0) ? growthFactor : 1.5;
30
+ }
31
+ /** Copy data from source array. Does not reallocate or change active block count.
32
+ * @param source array to copy from
33
+ * @param sourceCount copy the first sourceCount blocks; all blocks if undefined
34
+ * @param destOffset copy to instance array starting at this block index; zero if undefined
35
+ * @return count and offset of blocks copied
36
+ */
37
+ copyData(source, sourceCount, destOffset) {
38
+ // validate inputs and convert from blocks to entries
39
+ let myOffset = (undefined !== destOffset) ? destOffset * this.numPerBlock : 0;
40
+ if (myOffset < 0)
41
+ myOffset = 0;
42
+ if (myOffset >= this._data.length)
43
+ return { count: 0, offset: 0 };
44
+ let myCount = (undefined !== sourceCount) ? sourceCount * this.numPerBlock : source.length;
45
+ if (myCount > 0) {
46
+ if (myCount > source.length)
47
+ myCount = source.length;
48
+ if (myOffset + myCount > this._data.length)
49
+ myCount = this._data.length - myOffset;
50
+ if (myCount % this.numPerBlock !== 0)
51
+ myCount -= myCount % this.numPerBlock;
52
+ }
53
+ if (myCount <= 0)
54
+ return { count: 0, offset: 0 };
55
+ if (myCount === source.length)
56
+ this._data.set(source, myOffset);
57
+ else if (source instanceof Float64Array)
58
+ this._data.set(source.subarray(0, myCount), myOffset);
59
+ else
60
+ this._data.set(source.slice(0, myCount), myOffset);
61
+ return { count: myCount / this.numPerBlock, offset: myOffset / this.numPerBlock };
25
62
  }
63
+ /**
64
+ * Make a copy of the (active) blocks in this array.
65
+ * (The clone does NOT get excess capacity)
66
+ */
67
+ clone() {
68
+ const newBlocks = new GrowableBlockedArray(this.numPerBlock, this.numBlocks, this._growthFactor);
69
+ newBlocks.copyData(this._data, this.numBlocks);
70
+ newBlocks._inUse = this.numBlocks;
71
+ return newBlocks;
72
+ }
73
+ /** computed property: length (in blocks, not doubles) */
74
+ get length() { return this._inUse; }
26
75
  /** computed property: length (in blocks, not doubles) */
27
76
  get numBlocks() { return this._inUse; }
28
77
  /** property: number of data values per block */
29
78
  get numPerBlock() { return this._blockSize; }
30
79
  /**
31
- * Return a single value indexed within a block
80
+ * Return a single value indexed within a block. Indices are unchecked.
32
81
  * @param blockIndex index of block to read
33
82
  * @param indexInBlock offset within the block
34
83
  */
@@ -42,13 +91,13 @@ class GrowableBlockedArray {
42
91
  return this._data.length / this._blockSize;
43
92
  }
44
93
  /** ensure capacity (in blocks, not doubles) */
45
- ensureBlockCapacity(blockCapacity) {
94
+ ensureBlockCapacity(blockCapacity, applyGrowthFactor = true) {
46
95
  if (blockCapacity > this.blockCapacity()) {
47
- const newData = new Float64Array(blockCapacity * this._blockSize);
48
- for (let i = 0; i < this._data.length; i++) {
49
- newData[i] = this._data[i];
50
- }
51
- this._data = newData;
96
+ if (applyGrowthFactor)
97
+ blockCapacity *= this._growthFactor;
98
+ const prevData = this._data;
99
+ this._data = new Float64Array(blockCapacity * this._blockSize);
100
+ this.copyData(prevData, this._inUse);
52
101
  }
53
102
  }
54
103
  /** Add a new block of data.
@@ -73,7 +122,7 @@ class GrowableBlockedArray {
73
122
  newBlockIndex() {
74
123
  const index = this._blockSize * this._inUse;
75
124
  if ((index + 1) > this._data.length)
76
- this.ensureBlockCapacity(1 + 2 * this._inUse);
125
+ this.ensureBlockCapacity(1 + this._inUse);
77
126
  this._inUse++;
78
127
  for (let i = index; i < index + this._blockSize; i++)
79
128
  this._data[i] = 0.0;
@@ -1 +1 @@
1
- {"version":3,"file":"GrowableBlockedArray.js","sourceRoot":"","sources":["../../../src/geometry3d/GrowableBlockedArray.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAIH;;;;GAIG;AACH,MAAa,oBAAoB;IAS/B,YAAmB,SAAiB,EAAE,gBAAwB,CAAC;QAC7D;;;WAGG;QACH,IAAI,CAAC,KAAK,GAAG,IAAI,YAAY,CAAC,aAAa,GAAG,SAAS,CAAC,CAAC;QACzD,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;QAChB,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;IAC9B,CAAC;IACD,yDAAyD;IACz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ACD,OAAO,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACvB,CAAC;CACF;AAvJD,oDAuJC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module ArraysAndInterfaces\r\n */\r\n\r\nimport { BlockComparisonFunction } from \"./GrowableFloat64Array\";\r\n\r\n/**\r\n * Array of contiguous doubles, indexed by block number and index within block.\r\n * * This is essentially a rectangular matrix (two dimensional array), with each block being a row of the matrix.\r\n * @public\r\n */\r\nexport class GrowableBlockedArray {\r\n /** underlying contiguous, oversized buffer. */\r\n protected _data: Float64Array;\r\n /** Number of blocks (matrix rows) in use. */\r\n protected _inUse: number;\r\n /** number of numbers per block in the array.\r\n * * If viewing the array as a two dimensional array, this is the row size.\r\n */\r\n protected _blockSize: number; // positive integer !!!\r\n public constructor(blockSize: number, initialBlocks: number = 8) {\r\n /** array contents in blocked (row-major) order, possibly with extra capacity\r\n * Total capacity is `this._data.length`\r\n * Actual in-use count is `this._inUse * this._blockSize`\r\n */\r\n this._data = new Float64Array(initialBlocks * blockSize);\r\n this._inUse = 0;\r\n this._blockSize = blockSize;\r\n }\r\n /** computed property: length (in blocks, not doubles) */\r\n public get numBlocks(): number { return this._inUse; }\r\n /** property: number of data values per block */\r\n public get numPerBlock(): number { return this._blockSize; }\r\n /**\r\n * Return a single value indexed within a block\r\n * @param blockIndex index of block to read\r\n * @param indexInBlock offset within the block\r\n */\r\n public getWithinBlock(blockIndex: number, indexWithinBlock: number): number {\r\n return this._data[blockIndex * this._blockSize + indexWithinBlock];\r\n }\r\n /** clear the block count to zero, but maintain the allocated memory */\r\n public clear() { this._inUse = 0; }\r\n /** Return the capacity in blocks (not doubles) */\r\n public blockCapacity() {\r\n return this._data.length / this._blockSize;\r\n }\r\n /** ensure capacity (in blocks, not doubles) */\r\n public ensureBlockCapacity(blockCapacity: number) {\r\n if (blockCapacity > this.blockCapacity()) {\r\n const newData = new Float64Array(blockCapacity * this._blockSize);\r\n for (let i = 0; i < this._data.length; i++) {\r\n newData[i] = this._data[i];\r\n }\r\n this._data = newData;\r\n }\r\n }\r\n /** Add a new block of data.\r\n * * If newData has fewer than numPerBlock entries, the remaining part of the new block is zeros.\r\n * * If newData has more entries, only the first numPerBlock are taken.\r\n */\r\n public addBlock(newData: number[]) {\r\n const k0 = this.newBlockIndex();\r\n let numValue = newData.length;\r\n if (numValue > this._blockSize)\r\n numValue = this._blockSize;\r\n for (let i = 0; i < numValue; i++)\r\n this._data[k0 + i] = newData[i];\r\n }\r\n /**\r\n * Return the starting index of a block of (zero-initialized) doubles at the end.\r\n *\r\n * * this.data is reallocated if needed to include the new block.\r\n * * The inUse count is incremented to include the new block.\r\n * * The returned block is an index to the Float64Array (not a block index)\r\n */\r\n protected newBlockIndex(): number {\r\n const index = this._blockSize * this._inUse;\r\n if ((index + 1) > this._data.length)\r\n this.ensureBlockCapacity(1 + 2 * this._inUse);\r\n this._inUse++;\r\n for (let i = index; i < index + this._blockSize; i++)\r\n this._data[i] = 0.0;\r\n return index;\r\n }\r\n /** reduce the block count by one. */\r\n public popBlock() {\r\n if (this._inUse > 0)\r\n this._inUse--;\r\n }\r\n /** convert a block index to the simple index to the underlying Float64Array. */\r\n protected blockIndexToDoubleIndex(blockIndex: number) { return this._blockSize * blockIndex; }\r\n /** Access a single double at offset within a block, with index checking and return undefined if indexing is invalid. */\r\n public checkedComponent(blockIndex: number, componentIndex: number): number | undefined {\r\n if (blockIndex >= this._inUse || blockIndex < 0 || componentIndex < 0 || componentIndex >= this._blockSize)\r\n return undefined;\r\n return this._data[this._blockSize * blockIndex + componentIndex];\r\n }\r\n /** Access a single double at offset within a block. This has no index checking. */\r\n public component(blockIndex: number, componentIndex: number): number {\r\n return this._data[this._blockSize * blockIndex + componentIndex];\r\n }\r\n /** compare two blocks in simple lexical order.\r\n * @param data data array\r\n * @param blockSize number of items to compare\r\n * @param ia raw index (not block index) of first block\r\n * @param ib raw index (not block index) of second block\r\n */\r\n public static compareLexicalBlock(data: Float64Array, blockSize: number, ia: number, ib: number): number {\r\n let ax = 0;\r\n let bx = 0;\r\n for (let i = 0; i < blockSize; i++) {\r\n ax = data[ia + i];\r\n bx = data[ib + i];\r\n if (ax > bx) return 1;\r\n if (ax < bx) return -1;\r\n }\r\n return ia - ib; // so original order is maintained among duplicates !!!!\r\n }\r\n /** Return an array of block indices sorted per compareLexicalBlock function */\r\n public sortIndicesLexical(compareBlocks: BlockComparisonFunction = GrowableBlockedArray.compareLexicalBlock): Uint32Array {\r\n const n = this._inUse;\r\n // let numCompare = 0;\r\n const result = new Uint32Array(n);\r\n const data = this._data;\r\n const blockSize = this._blockSize;\r\n for (let i = 0; i < n; i++)result[i] = i;\r\n result.sort(\r\n (blockIndexA: number, blockIndexB: number) => {\r\n // numCompare++;\r\n return compareBlocks(data, blockSize, blockIndexA * blockSize, blockIndexB * blockSize);\r\n });\r\n // console.log (n, numCompare);\r\n return result;\r\n }\r\n /** Return the distance (hypotenuse=sqrt(summed squares)) between indicated blocks */\r\n public distanceBetweenBlocks(blockIndexA: number, blockIndexB: number): number {\r\n let dd = 0.0;\r\n let iA = this.blockIndexToDoubleIndex(blockIndexA);\r\n let iB = this.blockIndexToDoubleIndex(blockIndexB);\r\n let a = 0;\r\n const data = this._data;\r\n for (let i = 0; i < this._blockSize; i++) {\r\n a = data[iA++] - data[iB++];\r\n dd += a * a;\r\n }\r\n return Math.sqrt(dd);\r\n }\r\n\r\n /** Return the distance (hypotenuse=sqrt(summed squares)) between block entries `iBegin <= i < iEnd` of indicated blocks */\r\n public distanceBetweenSubBlocks(blockIndexA: number, blockIndexB: number, iBegin: number, iEnd: number): number {\r\n let dd = 0.0;\r\n const iA = this.blockIndexToDoubleIndex(blockIndexA);\r\n const iB = this.blockIndexToDoubleIndex(blockIndexB);\r\n let a = 0;\r\n const data = this._data;\r\n for (let i = iBegin; i < iEnd; i++) {\r\n a = data[iA + i] - data[iB + i];\r\n dd += a * a;\r\n }\r\n return Math.sqrt(dd);\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"GrowableBlockedArray.js","sourceRoot":"","sources":["../../../src/geometry3d/GrowableBlockedArray.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAIH;;;;GAIG;AACH,MAAa,oBAAoB;IAc/B;;;;;;;OAOG;IACH,YAAmB,SAAiB,EAAE,gBAAwB,CAAC,EAAE,YAAqB;QACpF,IAAI,CAAC,KAAK,GAAG,IAAI,YAAY,CAAC,aAAa,GAAG,SAAS,CAAC,CAAC;QACzD,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;QAChB,IAAI,CAAC,UAAU,GAAG,SAAS,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;QAChD,IAAI,CAAC,aAAa,GAAG,CAAC,SAAS,KAAK,YAAY,IAAI,YAAY,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,GAAG,CAAC;IAChG,CAAC;IAED;;;;;OAKG;IACO,QAAQ,CAAC,MAA+B,EAAE,WAAoB,EAAE,UAAmB;QAC3F,qDAAqD;QACrD,IAAI,QAAQ,GAAG,CAAC,SAAS,KAAK,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,GAAG,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;QAC9E,IAAI,QAAQ,GAAG,CAAC;YACd,QAAQ,GAAG,CAAC,CAAC;QACf,IAAI,QAAQ,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM;YAC/B,OAAO,EAAC,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAC,CAAC;QAC/B,IAAI,OAAO,GAAG,CAAC,SAAS,KAAK,WAAW,CAAC,CAAC,CAAC,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW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AC,GAAG,IAAI,EAAE,CAAC,EAAE,EAAE;YAClC,CAAC,GAAG,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;YAChC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;SACb;QACD,OAAO,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACvB,CAAC;CACF;AAhND,oDAgNC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module ArraysAndInterfaces\r\n */\r\n\r\nimport { BlockComparisonFunction } from \"./GrowableFloat64Array\";\r\n\r\n/**\r\n * Array of contiguous doubles, indexed by block number and index within block.\r\n * * This is essentially a rectangular matrix (two dimensional array), with each block being a row of the matrix.\r\n * @public\r\n */\r\nexport class GrowableBlockedArray {\r\n /** underlying contiguous, oversized buffer. */\r\n protected _data: Float64Array;\r\n /** Number of blocks (matrix rows) in use. */\r\n protected _inUse: number;\r\n /** number of numbers per block in the array.\r\n * * If viewing the array as a two dimensional array, this is the row size.\r\n */\r\n protected _blockSize: number; // positive integer !!!\r\n /**\r\n * multiplier used by ensureBlockCapacity to expand requested reallocation size\r\n */\r\n protected _growthFactor: number;\r\n\r\n /**\r\n * Construct an array whose contents are in blocked (row-major) order, possibly with extra capacity.\r\n * * Total capacity is `this._data.length`\r\n * * Actual in-use count is `this._inUse * this._blockSize`\r\n * @param blockSize number of entries in each block, i.e., row size\r\n * @param initialBlocks initial capacity in blocks (default 8)\r\n * @param growthFactor used by ensureBlockCapacity to expand requested reallocation size (default 1.5)\r\n */\r\n public constructor(blockSize: number, initialBlocks: number = 8, growthFactor?: number) {\r\n this._data = new Float64Array(initialBlocks * blockSize);\r\n this._inUse = 0;\r\n this._blockSize = blockSize > 0 ? blockSize : 1;\r\n this._growthFactor = (undefined !== growthFactor && growthFactor >= 1.0) ? growthFactor : 1.5;\r\n }\r\n\r\n /** Copy data from source array. Does not reallocate or change active block count.\r\n * @param source array to copy from\r\n * @param sourceCount copy the first sourceCount blocks; all blocks if undefined\r\n * @param destOffset copy to instance array starting at this block index; zero if undefined\r\n * @return count and offset of blocks copied\r\n */\r\n protected copyData(source: Float64Array | number[], sourceCount?: number, destOffset?: number): {count: number, offset: number} {\r\n // validate inputs and convert from blocks to entries\r\n let myOffset = (undefined !== destOffset) ? destOffset * this.numPerBlock : 0;\r\n if (myOffset < 0)\r\n myOffset = 0;\r\n if (myOffset >= this._data.length)\r\n return {count: 0, offset: 0};\r\n let myCount = (undefined !== sourceCount) ? sourceCount * this.numPerBlock : source.length;\r\n if (myCount > 0) {\r\n if (myCount > source.length)\r\n myCount = source.length;\r\n if (myOffset + myCount > this._data.length)\r\n myCount = this._data.length - myOffset;\r\n if (myCount % this.numPerBlock !== 0)\r\n myCount -= myCount % this.numPerBlock;\r\n }\r\n if (myCount <= 0)\r\n return {count: 0, offset: 0};\r\n if (myCount === source.length)\r\n this._data.set(source, myOffset);\r\n else if (source instanceof Float64Array)\r\n this._data.set(source.subarray(0, myCount), myOffset);\r\n else\r\n this._data.set(source.slice(0, myCount), myOffset);\r\n return {count: myCount / this.numPerBlock, offset: myOffset / this.numPerBlock};\r\n }\r\n\r\n /**\r\n * Make a copy of the (active) blocks in this array.\r\n * (The clone does NOT get excess capacity)\r\n */\r\n public clone(): GrowableBlockedArray {\r\n const newBlocks = new GrowableBlockedArray(this.numPerBlock, this.numBlocks, this._growthFactor);\r\n newBlocks.copyData(this._data, this.numBlocks);\r\n newBlocks._inUse = this.numBlocks;\r\n return newBlocks;\r\n }\r\n\r\n /** computed property: length (in blocks, not doubles) */\r\n public get length(): number { return this._inUse; }\r\n /** computed property: length (in blocks, not doubles) */\r\n public get numBlocks(): number { return this._inUse; }\r\n /** property: number of data values per block */\r\n public get numPerBlock(): number { return this._blockSize; }\r\n /**\r\n * Return a single value indexed within a block. Indices are unchecked.\r\n * @param blockIndex index of block to read\r\n * @param indexInBlock offset within the block\r\n */\r\n public getWithinBlock(blockIndex: number, indexWithinBlock: number): number {\r\n return this._data[blockIndex * this._blockSize + indexWithinBlock];\r\n }\r\n /** clear the block count to zero, but maintain the allocated memory */\r\n public clear() { this._inUse = 0; }\r\n /** Return the capacity in blocks (not doubles) */\r\n public blockCapacity() {\r\n return this._data.length / this._blockSize;\r\n }\r\n /** ensure capacity (in blocks, not doubles) */\r\n public ensureBlockCapacity(blockCapacity: number, applyGrowthFactor: boolean = true) {\r\n if (blockCapacity > this.blockCapacity()) {\r\n if (applyGrowthFactor)\r\n blockCapacity *= this._growthFactor;\r\n const prevData = this._data;\r\n this._data = new Float64Array(blockCapacity * this._blockSize);\r\n this.copyData(prevData, this._inUse);\r\n }\r\n }\r\n /** Add a new block of data.\r\n * * If newData has fewer than numPerBlock entries, the remaining part of the new block is zeros.\r\n * * If newData has more entries, only the first numPerBlock are taken.\r\n */\r\n public addBlock(newData: number[]) {\r\n const k0 = this.newBlockIndex();\r\n let numValue = newData.length;\r\n if (numValue > this._blockSize)\r\n numValue = this._blockSize;\r\n for (let i = 0; i < numValue; i++)\r\n this._data[k0 + i] = newData[i];\r\n }\r\n /**\r\n * Return the starting index of a block of (zero-initialized) doubles at the end.\r\n *\r\n * * this.data is reallocated if needed to include the new block.\r\n * * The inUse count is incremented to include the new block.\r\n * * The returned block is an index to the Float64Array (not a block index)\r\n */\r\n protected newBlockIndex(): number {\r\n const index = this._blockSize * this._inUse;\r\n if ((index + 1) > this._data.length)\r\n this.ensureBlockCapacity(1 + this._inUse);\r\n this._inUse++;\r\n for (let i = index; i < index + this._blockSize; i++)\r\n this._data[i] = 0.0;\r\n return index;\r\n }\r\n /** reduce the block count by one. */\r\n public popBlock() {\r\n if (this._inUse > 0)\r\n this._inUse--;\r\n }\r\n /** convert a block index to the simple index to the underlying Float64Array. */\r\n protected blockIndexToDoubleIndex(blockIndex: number) { return this._blockSize * blockIndex; }\r\n /** Access a single double at offset within a block, with index checking and return undefined if indexing is invalid. */\r\n public checkedComponent(blockIndex: number, componentIndex: number): number | undefined {\r\n if (blockIndex >= this._inUse || blockIndex < 0 || componentIndex < 0 || componentIndex >= this._blockSize)\r\n return undefined;\r\n return this._data[this._blockSize * blockIndex + componentIndex];\r\n }\r\n /** Access a single double at offset within a block. This has no index checking. */\r\n public component(blockIndex: number, componentIndex: number): number {\r\n return this._data[this._blockSize * blockIndex + componentIndex];\r\n }\r\n /** compare two blocks in simple lexical order.\r\n * @param data data array\r\n * @param blockSize number of items to compare\r\n * @param ia raw index (not block index) of first block\r\n * @param ib raw index (not block index) of second block\r\n */\r\n public static compareLexicalBlock(data: Float64Array, blockSize: number, ia: number, ib: number): number {\r\n let ax = 0;\r\n let bx = 0;\r\n for (let i = 0; i < blockSize; i++) {\r\n ax = data[ia + i];\r\n bx = data[ib + i];\r\n if (ax > bx) return 1;\r\n if (ax < bx) return -1;\r\n }\r\n return ia - ib; // so original order is maintained among duplicates !!!!\r\n }\r\n /** Return an array of block indices sorted per compareLexicalBlock function */\r\n public sortIndicesLexical(compareBlocks: BlockComparisonFunction = GrowableBlockedArray.compareLexicalBlock): Uint32Array {\r\n const n = this._inUse;\r\n // let numCompare = 0;\r\n const result = new Uint32Array(n);\r\n const data = this._data;\r\n const blockSize = this._blockSize;\r\n for (let i = 0; i < n; i++)result[i] = i;\r\n result.sort(\r\n (blockIndexA: number, blockIndexB: number) => {\r\n // numCompare++;\r\n return compareBlocks(data, blockSize, blockIndexA * blockSize, blockIndexB * blockSize);\r\n });\r\n // console.log (n, numCompare);\r\n return result;\r\n }\r\n /** Return the distance (hypotenuse=sqrt(summed squares)) between indicated blocks */\r\n public distanceBetweenBlocks(blockIndexA: number, blockIndexB: number): number {\r\n let dd = 0.0;\r\n let iA = this.blockIndexToDoubleIndex(blockIndexA);\r\n let iB = this.blockIndexToDoubleIndex(blockIndexB);\r\n let a = 0;\r\n const data = this._data;\r\n for (let i = 0; i < this._blockSize; i++) {\r\n a = data[iA++] - data[iB++];\r\n dd += a * a;\r\n }\r\n return Math.sqrt(dd);\r\n }\r\n\r\n /** Return the distance (hypotenuse=sqrt(summed squares)) between block entries `iBegin <= i < iEnd` of indicated blocks */\r\n public distanceBetweenSubBlocks(blockIndexA: number, blockIndexB: number, iBegin: number, iEnd: number): number {\r\n let dd = 0.0;\r\n const iA = this.blockIndexToDoubleIndex(blockIndexA);\r\n const iB = this.blockIndexToDoubleIndex(blockIndexB);\r\n let a = 0;\r\n const data = this._data;\r\n for (let i = iBegin; i < iEnd; i++) {\r\n a = data[iA + i] - data[iB + i];\r\n dd += a * a;\r\n }\r\n return Math.sqrt(dd);\r\n }\r\n}\r\n"]}
@@ -23,7 +23,22 @@ export declare type BlockComparisonFunction = (data: Float64Array, blockSize: nu
23
23
  export declare class GrowableFloat64Array {
24
24
  private _data;
25
25
  private _inUse;
26
- constructor(initialCapacity?: number);
26
+ private _growthFactor;
27
+ /** Construct a GrowableFloat64Array.
28
+ * @param initialCapacity initial capacity (default 8)
29
+ * @param growthFactor used by ensureCapacity to expand requested reallocation size (default 1.5)
30
+ */
31
+ constructor(initialCapacity?: number, growthFactor?: number);
32
+ /** Copy data from source array. Does not reallocate or change active entry count.
33
+ * @param source array to copy from
34
+ * @param sourceCount copy the first sourceCount entries; all entries if undefined
35
+ * @param destOffset copy to instance array starting at this index; zero if undefined
36
+ * @return count and offset of entries copied
37
+ */
38
+ protected copyData(source: Float64Array | number[], sourceCount?: number, destOffset?: number): {
39
+ count: number;
40
+ offset: number;
41
+ };
27
42
  /**
28
43
  * Create a GrowableFloat64Array with given contents.
29
44
  * @param contents data to copy into the array
@@ -74,7 +89,7 @@ export declare class GrowableFloat64Array {
74
89
  * @param data array of values to push
75
90
  */
76
91
  pushArray(data: Float64Array | number[]): void;
77
- /** Push a `numToCopy` consecutive values starting at `copyFromIndex` to the end of the array. */
92
+ /** Push `numToCopy` consecutive values starting at `copyFromIndex`. */
78
93
  pushBlockCopy(copyFromIndex: number, numToCopy: number): void;
79
94
  /** Clear the array to 0 length. The underlying memory remains allocated for reuse. */
80
95
  clear(): void;
@@ -84,14 +99,15 @@ export declare class GrowableFloat64Array {
84
99
  */
85
100
  capacity(): number;
86
101
  /**
87
- * * If the capacity (Float64Array length) is less than or equal to the requested newCapacity, do nothing
88
- * * If the requested newCapacity is larger than the existing capacity, reallocate (and copy existing values) with the larger capacity.
89
- * @param newCapacity
102
+ * * If the capacity (Float64Array length) is less than or equal to the requested newCapacity, do nothing.
103
+ * * If the requested newCapacity is larger than the existing capacity, reallocate to larger capacity, and copy existing values.
104
+ * @param newCapacity size of new array
105
+ * @param applyGrowthFactor whether to apply the growth factor to newCapacity when reallocating
90
106
  */
91
- ensureCapacity(newCapacity: number): void;
107
+ ensureCapacity(newCapacity: number, applyGrowthFactor?: boolean): void;
92
108
  /**
93
- * * If newLength is less than current (active) length, just set (active) length.
94
- * * If newLength is greater, ensureCapacity (newSize) and pad with padValue up to newSize;
109
+ * * If newLength is less than current length, just reset current length to newLength, effectively trimming active entries but preserving original capacity.
110
+ * * If newLength is greater than current length, reallocate to (exactly) newLength, copy existing entries, and pad with padValue up to newLength.
95
111
  * @param newLength new data count
96
112
  * @param padValue value to use for padding if the length increases.
97
113
  */
@@ -1 +1 @@
1
- {"version":3,"file":"GrowableFloat64Array.d.ts","sourceRoot":"","sources":["../../../src/geometry3d/GrowableFloat64Array.ts"],"names":[],"mappings":"AAKA;;GAEG;AAEH;;;GAGG;AACH,oBAAY,4BAA4B,GAAG,oBAAoB,GAAG,SAAS,CAAC;AAC5E;;;GAGG;AACH,oBAAY,uBAAuB,GAAG,CAAC,IAAI,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,MAAM,CAAC;AACxH;;;;;;;;GAQG;AACH,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,KAAK,CAAe;IAC5B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I,mBAAmB,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAIvD;;;;OAIG;IACI,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM;IAGhC;;;;OAIG;IACI,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM;IAMhC;;;OAGG;IACI,IAAI,CAAC,MAAM,EAAE,MAAM;IAK1B;;;OAGG;IACI,SAAS,CAAC,IAAI,EAAE,YAAY,GAAG,MAAM,EAAE;IAK9C,uEAAuE;IAChE,aAAa,CAAC,aAAa,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM;IAO7D,uFAAuF;IAChF,KAAK;IAGZ;;;OAGG;IACI,QAAQ;IAGf;;;;;OAKG;IACI,cAAc,CAAC,WAAW,EAAE,MAAM,EAAE,iBAAiB,GAAE,OAAc;IAS5E;;;;;OAKG;IACI,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAU;IASrD;;;;OAIG;IACI,GAAG;IAOV,4CAA4C;IACrC,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAG9C,sDAAsD;IAC/C,KAAK;IAGZ,oDAAoD;IAC7C,IAAI;IAGX,2BAA2B;IACpB,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAI5C;;;;OAIG;IACI,IAAI,CAAC,aAAa,GAAE,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,KAAK,MAAqC;IAapF;;;;;OAKG;IACI,kBAAkB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM;IAa9C;;;OAGG;IACI,0BAA0B,CAAC,SAAS,GAAE,MAAY;CAmB1D"}
@@ -15,20 +15,53 @@ exports.GrowableFloat64Array = void 0;
15
15
  * @public
16
16
  */
17
17
  class GrowableFloat64Array {
18
- constructor(initialCapacity = 8) {
18
+ /** Construct a GrowableFloat64Array.
19
+ * @param initialCapacity initial capacity (default 8)
20
+ * @param growthFactor used by ensureCapacity to expand requested reallocation size (default 1.5)
21
+ */
22
+ constructor(initialCapacity = 8, growthFactor) {
19
23
  this._data = new Float64Array(initialCapacity);
20
24
  this._inUse = 0;
25
+ this._growthFactor = (undefined !== growthFactor && growthFactor >= 1.0) ? growthFactor : 1.5;
26
+ }
27
+ /** Copy data from source array. Does not reallocate or change active entry count.
28
+ * @param source array to copy from
29
+ * @param sourceCount copy the first sourceCount entries; all entries if undefined
30
+ * @param destOffset copy to instance array starting at this index; zero if undefined
31
+ * @return count and offset of entries copied
32
+ */
33
+ copyData(source, sourceCount, destOffset) {
34
+ let myOffset = destOffset !== null && destOffset !== void 0 ? destOffset : 0;
35
+ if (myOffset < 0)
36
+ myOffset = 0;
37
+ if (myOffset >= this._data.length)
38
+ return { count: 0, offset: 0 };
39
+ let myCount = sourceCount !== null && sourceCount !== void 0 ? sourceCount : source.length;
40
+ if (myCount > 0) {
41
+ if (myCount > source.length)
42
+ myCount = source.length;
43
+ if (myOffset + myCount > this._data.length)
44
+ myCount = this._data.length - myOffset;
45
+ }
46
+ if (myCount <= 0)
47
+ return { count: 0, offset: 0 };
48
+ if (myCount === source.length)
49
+ this._data.set(source, myOffset);
50
+ else if (source instanceof Float64Array)
51
+ this._data.set(source.subarray(0, myCount), myOffset);
52
+ else
53
+ this._data.set(source.slice(0, myCount), myOffset);
54
+ return { count: myCount, offset: myOffset };
21
55
  }
22
56
  /**
23
57
  * Create a GrowableFloat64Array with given contents.
24
58
  * @param contents data to copy into the array
25
59
  */
26
60
  static create(contents) {
27
- const result = new GrowableFloat64Array(contents.length);
28
- for (const a of contents) {
29
- result.push(a);
30
- }
31
- return result;
61
+ const out = new GrowableFloat64Array(contents.length);
62
+ out.copyData(contents);
63
+ out._inUse = contents.length;
64
+ return out;
32
65
  }
33
66
  /** sort-compatible comparison.
34
67
  * * Returns `(a-b)` which is
@@ -44,11 +77,9 @@ class GrowableFloat64Array {
44
77
  * * optionally trimmed capacity to the active length or replicate the capacity and unused space.
45
78
  */
46
79
  clone(maintainExcessCapacity = false) {
47
- const n = this._inUse;
48
- const data = this._data;
49
- const out = new GrowableFloat64Array(maintainExcessCapacity ? this.capacity() : n);
50
- for (let i = 0; i < n; i++)
51
- out.push(data[i]);
80
+ const out = new GrowableFloat64Array(maintainExcessCapacity ? this.capacity() : this._inUse);
81
+ out.copyData(this._data, this._inUse);
82
+ out._inUse = this._inUse;
52
83
  return out;
53
84
  }
54
85
  /**
@@ -89,41 +120,30 @@ class GrowableFloat64Array {
89
120
  * @param toPush value to append to the active array.
90
121
  */
91
122
  push(toPush) {
92
- if (this._inUse + 1 <= this._data.length) {
93
- this._data[this._inUse] = toPush;
94
- this._inUse++;
95
- }
96
- else {
97
- // Make new array (double size), copy values, then push toPush
98
- const newData = new Float64Array(4 + this._inUse * 2);
99
- for (let i = 0; i < this._inUse; i++) {
100
- newData[i] = this._data[i];
101
- }
102
- this._data = newData;
103
- this._data[this._inUse] = toPush;
104
- this._inUse++;
105
- }
123
+ this.ensureCapacity(this._inUse + 1);
124
+ this._data[this._inUse] = toPush;
125
+ this._inUse++;
106
126
  }
107
127
  /**
108
128
  * Push each value from an array.
109
129
  * @param data array of values to push
110
130
  */
111
131
  pushArray(data) {
112
- for (const a of data)
113
- this.push(a);
132
+ this.ensureCapacity(this._inUse + data.length);
133
+ this.copyData(data, data.length, this._inUse);
134
+ this._inUse += data.length;
114
135
  }
115
- /** Push a `numToCopy` consecutive values starting at `copyFromIndex` to the end of the array. */
136
+ /** Push `numToCopy` consecutive values starting at `copyFromIndex`. */
116
137
  pushBlockCopy(copyFromIndex, numToCopy) {
117
- const newLength = this._inUse + numToCopy;
118
- this.ensureCapacity(newLength);
119
- const limit = copyFromIndex + numToCopy;
120
- for (let i = copyFromIndex; i < limit; i++)
121
- this._data[this._inUse++] = this._data[i];
138
+ if (copyFromIndex >= 0 && copyFromIndex < this._inUse && numToCopy > 0 && copyFromIndex + numToCopy <= this._inUse) {
139
+ this.ensureCapacity(this._inUse + numToCopy);
140
+ this._data.copyWithin(this._inUse, copyFromIndex, copyFromIndex + numToCopy);
141
+ this._inUse += numToCopy;
142
+ }
122
143
  }
123
144
  /** Clear the array to 0 length. The underlying memory remains allocated for reuse. */
124
145
  clear() {
125
- while (this._inUse > 0)
126
- this.pop();
146
+ this._inUse = 0;
127
147
  }
128
148
  /**
129
149
  * Returns the number of entries in the supporting Float64Array buffer.
@@ -133,36 +153,34 @@ class GrowableFloat64Array {
133
153
  return this._data.length;
134
154
  }
135
155
  /**
136
- * * If the capacity (Float64Array length) is less than or equal to the requested newCapacity, do nothing
137
- * * If the requested newCapacity is larger than the existing capacity, reallocate (and copy existing values) with the larger capacity.
138
- * @param newCapacity
156
+ * * If the capacity (Float64Array length) is less than or equal to the requested newCapacity, do nothing.
157
+ * * If the requested newCapacity is larger than the existing capacity, reallocate to larger capacity, and copy existing values.
158
+ * @param newCapacity size of new array
159
+ * @param applyGrowthFactor whether to apply the growth factor to newCapacity when reallocating
139
160
  */
140
- ensureCapacity(newCapacity) {
161
+ ensureCapacity(newCapacity, applyGrowthFactor = true) {
141
162
  if (newCapacity > this.capacity()) {
142
- const oldInUse = this._inUse;
143
- const newData = new Float64Array(newCapacity);
144
- for (let i = 0; i < oldInUse; i++)
145
- newData[i] = this._data[i];
146
- this._data = newData;
163
+ if (applyGrowthFactor)
164
+ newCapacity *= this._growthFactor;
165
+ const prevData = this._data;
166
+ this._data = new Float64Array(newCapacity);
167
+ this.copyData(prevData, this._inUse);
147
168
  }
148
169
  }
149
170
  /**
150
- * * If newLength is less than current (active) length, just set (active) length.
151
- * * If newLength is greater, ensureCapacity (newSize) and pad with padValue up to newSize;
171
+ * * If newLength is less than current length, just reset current length to newLength, effectively trimming active entries but preserving original capacity.
172
+ * * If newLength is greater than current length, reallocate to (exactly) newLength, copy existing entries, and pad with padValue up to newLength.
152
173
  * @param newLength new data count
153
174
  * @param padValue value to use for padding if the length increases.
154
175
  */
155
176
  resize(newLength, padValue = 0) {
156
- // quick out for easy case ...
157
- if (newLength <= this._inUse) {
177
+ if (newLength >= 0 && newLength < this._inUse)
178
+ this._inUse = newLength;
179
+ else if (newLength > this._inUse) {
180
+ this.ensureCapacity(newLength, false);
181
+ this._data.fill(padValue, this._inUse);
158
182
  this._inUse = newLength;
159
- return;
160
183
  }
161
- const oldLength = this._inUse;
162
- this.ensureCapacity(newLength);
163
- for (let i = oldLength; i < newLength; i++)
164
- this._data[i] = padValue;
165
- this._inUse = newLength;
166
184
  }
167
185
  /**
168
186
  * * Reduce the length by one.