@itwin/core-geometry 4.3.0-dev.2 → 4.3.0-dev.20

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 (350) hide show
  1. package/CHANGELOG.md +41 -1
  2. package/lib/cjs/Geometry.d.ts.map +1 -1
  3. package/lib/cjs/Geometry.js +2 -4
  4. package/lib/cjs/Geometry.js.map +1 -1
  5. package/lib/cjs/bspline/BSpline1dNd.d.ts +12 -2
  6. package/lib/cjs/bspline/BSpline1dNd.d.ts.map +1 -1
  7. package/lib/cjs/bspline/BSpline1dNd.js +27 -17
  8. package/lib/cjs/bspline/BSpline1dNd.js.map +1 -1
  9. package/lib/cjs/bspline/BSplineCurve.d.ts +30 -16
  10. package/lib/cjs/bspline/BSplineCurve.d.ts.map +1 -1
  11. package/lib/cjs/bspline/BSplineCurve.js +68 -44
  12. package/lib/cjs/bspline/BSplineCurve.js.map +1 -1
  13. package/lib/cjs/bspline/BSplineCurve3dH.d.ts +27 -20
  14. package/lib/cjs/bspline/BSplineCurve3dH.d.ts.map +1 -1
  15. package/lib/cjs/bspline/BSplineCurve3dH.js +136 -87
  16. package/lib/cjs/bspline/BSplineCurve3dH.js.map +1 -1
  17. package/lib/cjs/bspline/BSplineSurface.d.ts +138 -74
  18. package/lib/cjs/bspline/BSplineSurface.d.ts.map +1 -1
  19. package/lib/cjs/bspline/BSplineSurface.js +242 -119
  20. package/lib/cjs/bspline/BSplineSurface.js.map +1 -1
  21. package/lib/cjs/bspline/Bezier1dNd.d.ts +18 -4
  22. package/lib/cjs/bspline/Bezier1dNd.d.ts.map +1 -1
  23. package/lib/cjs/bspline/Bezier1dNd.js +19 -5
  24. package/lib/cjs/bspline/Bezier1dNd.js.map +1 -1
  25. package/lib/cjs/bspline/BezierCurve3dH.d.ts.map +1 -1
  26. package/lib/cjs/bspline/BezierCurve3dH.js +2 -1
  27. package/lib/cjs/bspline/BezierCurve3dH.js.map +1 -1
  28. package/lib/cjs/bspline/KnotVector.d.ts +30 -33
  29. package/lib/cjs/bspline/KnotVector.d.ts.map +1 -1
  30. package/lib/cjs/bspline/KnotVector.js +76 -69
  31. package/lib/cjs/bspline/KnotVector.js.map +1 -1
  32. package/lib/cjs/clipping/AlternatingConvexClipTree.js.map +1 -1
  33. package/lib/cjs/clipping/ClipUtils.d.ts +32 -5
  34. package/lib/cjs/clipping/ClipUtils.d.ts.map +1 -1
  35. package/lib/cjs/clipping/ClipUtils.js +92 -11
  36. package/lib/cjs/clipping/ClipUtils.js.map +1 -1
  37. package/lib/cjs/curve/CurveChainWithDistanceIndex.d.ts +18 -1
  38. package/lib/cjs/curve/CurveChainWithDistanceIndex.d.ts.map +1 -1
  39. package/lib/cjs/curve/CurveChainWithDistanceIndex.js +47 -0
  40. package/lib/cjs/curve/CurveChainWithDistanceIndex.js.map +1 -1
  41. package/lib/cjs/curve/CurveCollection.d.ts +9 -9
  42. package/lib/cjs/curve/CurveCollection.d.ts.map +1 -1
  43. package/lib/cjs/curve/CurveCollection.js +7 -10
  44. package/lib/cjs/curve/CurveCollection.js.map +1 -1
  45. package/lib/cjs/curve/CurveCurve.d.ts +2 -2
  46. package/lib/cjs/curve/CurveCurve.d.ts.map +1 -1
  47. package/lib/cjs/curve/CurveCurve.js +3 -16
  48. package/lib/cjs/curve/CurveCurve.js.map +1 -1
  49. package/lib/cjs/curve/CurveLocationDetail.d.ts +17 -4
  50. package/lib/cjs/curve/CurveLocationDetail.d.ts.map +1 -1
  51. package/lib/cjs/curve/CurveLocationDetail.js +32 -10
  52. package/lib/cjs/curve/CurveLocationDetail.js.map +1 -1
  53. package/lib/cjs/curve/CurveOps.d.ts +4 -5
  54. package/lib/cjs/curve/CurveOps.d.ts.map +1 -1
  55. package/lib/cjs/curve/CurveOps.js +1 -1
  56. package/lib/cjs/curve/CurveOps.js.map +1 -1
  57. package/lib/cjs/curve/CurveTypes.d.ts +14 -2
  58. package/lib/cjs/curve/CurveTypes.d.ts.map +1 -1
  59. package/lib/cjs/curve/CurveTypes.js.map +1 -1
  60. package/lib/cjs/curve/CurveWireMomentsXYZ.d.ts.map +1 -1
  61. package/lib/cjs/curve/CurveWireMomentsXYZ.js +2 -4
  62. package/lib/cjs/curve/CurveWireMomentsXYZ.js.map +1 -1
  63. package/lib/cjs/curve/LineString3d.d.ts +3 -6
  64. package/lib/cjs/curve/LineString3d.d.ts.map +1 -1
  65. package/lib/cjs/curve/LineString3d.js +1 -4
  66. package/lib/cjs/curve/LineString3d.js.map +1 -1
  67. package/lib/cjs/curve/PointString3d.d.ts +2 -1
  68. package/lib/cjs/curve/PointString3d.d.ts.map +1 -1
  69. package/lib/cjs/curve/PointString3d.js.map +1 -1
  70. package/lib/cjs/curve/RegionOps.d.ts +7 -12
  71. package/lib/cjs/curve/RegionOps.d.ts.map +1 -1
  72. package/lib/cjs/curve/RegionOps.js +2 -1
  73. package/lib/cjs/curve/RegionOps.js.map +1 -1
  74. package/lib/cjs/curve/internalContexts/CurveCurveCloseApproachXY.d.ts +0 -9
  75. package/lib/cjs/curve/internalContexts/CurveCurveCloseApproachXY.d.ts.map +1 -1
  76. package/lib/cjs/curve/internalContexts/CurveCurveCloseApproachXY.js +16 -35
  77. package/lib/cjs/curve/internalContexts/CurveCurveCloseApproachXY.js.map +1 -1
  78. package/lib/cjs/curve/internalContexts/CurveCurveIntersectXY.d.ts +12 -6
  79. package/lib/cjs/curve/internalContexts/CurveCurveIntersectXY.d.ts.map +1 -1
  80. package/lib/cjs/curve/internalContexts/CurveCurveIntersectXY.js +80 -18
  81. package/lib/cjs/curve/internalContexts/CurveCurveIntersectXY.js.map +1 -1
  82. package/lib/cjs/curve/internalContexts/CurveCurveIntersectXYZ.d.ts +11 -5
  83. package/lib/cjs/curve/internalContexts/CurveCurveIntersectXYZ.d.ts.map +1 -1
  84. package/lib/cjs/curve/internalContexts/CurveCurveIntersectXYZ.js +73 -8
  85. package/lib/cjs/curve/internalContexts/CurveCurveIntersectXYZ.js.map +1 -1
  86. package/lib/cjs/curve/internalContexts/MultiChainCollector.d.ts +2 -3
  87. package/lib/cjs/curve/internalContexts/MultiChainCollector.d.ts.map +1 -1
  88. package/lib/cjs/curve/internalContexts/MultiChainCollector.js +2 -3
  89. package/lib/cjs/curve/internalContexts/MultiChainCollector.js.map +1 -1
  90. package/lib/cjs/curve/internalContexts/PolygonOffsetContext.d.ts +4 -4
  91. package/lib/cjs/curve/internalContexts/PolygonOffsetContext.d.ts.map +1 -1
  92. package/lib/cjs/curve/internalContexts/PolygonOffsetContext.js +38 -36
  93. package/lib/cjs/curve/internalContexts/PolygonOffsetContext.js.map +1 -1
  94. package/lib/cjs/geometry3d/CoincidentGeometryOps.d.ts +21 -5
  95. package/lib/cjs/geometry3d/CoincidentGeometryOps.d.ts.map +1 -1
  96. package/lib/cjs/geometry3d/CoincidentGeometryOps.js +71 -45
  97. package/lib/cjs/geometry3d/CoincidentGeometryOps.js.map +1 -1
  98. package/lib/cjs/geometry3d/Matrix3d.d.ts +20 -13
  99. package/lib/cjs/geometry3d/Matrix3d.d.ts.map +1 -1
  100. package/lib/cjs/geometry3d/Matrix3d.js +28 -21
  101. package/lib/cjs/geometry3d/Matrix3d.js.map +1 -1
  102. package/lib/cjs/geometry3d/Point3dVector3d.d.ts +11 -2
  103. package/lib/cjs/geometry3d/Point3dVector3d.d.ts.map +1 -1
  104. package/lib/cjs/geometry3d/Point3dVector3d.js +16 -5
  105. package/lib/cjs/geometry3d/Point3dVector3d.js.map +1 -1
  106. package/lib/cjs/geometry3d/PointHelpers.d.ts +58 -20
  107. package/lib/cjs/geometry3d/PointHelpers.d.ts.map +1 -1
  108. package/lib/cjs/geometry3d/PointHelpers.js +213 -62
  109. package/lib/cjs/geometry3d/PointHelpers.js.map +1 -1
  110. package/lib/cjs/geometry3d/Segment1d.d.ts +5 -1
  111. package/lib/cjs/geometry3d/Segment1d.d.ts.map +1 -1
  112. package/lib/cjs/geometry3d/Segment1d.js +11 -7
  113. package/lib/cjs/geometry3d/Segment1d.js.map +1 -1
  114. package/lib/cjs/geometry3d/Transform.d.ts +2 -3
  115. package/lib/cjs/geometry3d/Transform.d.ts.map +1 -1
  116. package/lib/cjs/geometry3d/Transform.js +2 -3
  117. package/lib/cjs/geometry3d/Transform.js.map +1 -1
  118. package/lib/cjs/geometry4d/Point4d.d.ts +14 -1
  119. package/lib/cjs/geometry4d/Point4d.d.ts.map +1 -1
  120. package/lib/cjs/geometry4d/Point4d.js +22 -1
  121. package/lib/cjs/geometry4d/Point4d.js.map +1 -1
  122. package/lib/cjs/numerics/BezierPolynomials.d.ts +91 -68
  123. package/lib/cjs/numerics/BezierPolynomials.d.ts.map +1 -1
  124. package/lib/cjs/numerics/BezierPolynomials.js +100 -79
  125. package/lib/cjs/numerics/BezierPolynomials.js.map +1 -1
  126. package/lib/cjs/numerics/Newton.d.ts +115 -60
  127. package/lib/cjs/numerics/Newton.d.ts.map +1 -1
  128. package/lib/cjs/numerics/Newton.js +120 -62
  129. package/lib/cjs/numerics/Newton.js.map +1 -1
  130. package/lib/cjs/numerics/PascalCoefficients.d.ts +8 -12
  131. package/lib/cjs/numerics/PascalCoefficients.d.ts.map +1 -1
  132. package/lib/cjs/numerics/PascalCoefficients.js +10 -12
  133. package/lib/cjs/numerics/PascalCoefficients.js.map +1 -1
  134. package/lib/cjs/numerics/Polynomials.d.ts +2 -2
  135. package/lib/cjs/numerics/Polynomials.d.ts.map +1 -1
  136. package/lib/cjs/numerics/Polynomials.js +2 -2
  137. package/lib/cjs/numerics/Polynomials.js.map +1 -1
  138. package/lib/cjs/polyface/PolyfaceBuilder.d.ts +3 -0
  139. package/lib/cjs/polyface/PolyfaceBuilder.d.ts.map +1 -1
  140. package/lib/cjs/polyface/PolyfaceBuilder.js +13 -2
  141. package/lib/cjs/polyface/PolyfaceBuilder.js.map +1 -1
  142. package/lib/cjs/polyface/PolyfaceClip.d.ts +1 -1
  143. package/lib/cjs/polyface/PolyfaceClip.d.ts.map +1 -1
  144. package/lib/cjs/polyface/PolyfaceClip.js +6 -3
  145. package/lib/cjs/polyface/PolyfaceClip.js.map +1 -1
  146. package/lib/cjs/polyface/PolyfaceData.d.ts +1 -1
  147. package/lib/cjs/polyface/PolyfaceData.js +1 -1
  148. package/lib/cjs/polyface/PolyfaceData.js.map +1 -1
  149. package/lib/cjs/polyface/PolyfaceQuery.d.ts +39 -12
  150. package/lib/cjs/polyface/PolyfaceQuery.d.ts.map +1 -1
  151. package/lib/cjs/polyface/PolyfaceQuery.js +94 -17
  152. package/lib/cjs/polyface/PolyfaceQuery.js.map +1 -1
  153. package/lib/cjs/serialization/BGFBReader.d.ts +10 -10
  154. package/lib/cjs/serialization/BGFBReader.d.ts.map +1 -1
  155. package/lib/cjs/serialization/BGFBReader.js +69 -42
  156. package/lib/cjs/serialization/BGFBReader.js.map +1 -1
  157. package/lib/cjs/serialization/BGFBWriter.d.ts +8 -8
  158. package/lib/cjs/serialization/BGFBWriter.d.ts.map +1 -1
  159. package/lib/cjs/serialization/BGFBWriter.js +80 -55
  160. package/lib/cjs/serialization/BGFBWriter.js.map +1 -1
  161. package/lib/cjs/serialization/GeometrySamples.d.ts.map +1 -1
  162. package/lib/cjs/serialization/GeometrySamples.js +6 -8
  163. package/lib/cjs/serialization/GeometrySamples.js.map +1 -1
  164. package/lib/cjs/serialization/IModelJsonSchema.d.ts +8 -14
  165. package/lib/cjs/serialization/IModelJsonSchema.d.ts.map +1 -1
  166. package/lib/cjs/serialization/IModelJsonSchema.js +85 -259
  167. package/lib/cjs/serialization/IModelJsonSchema.js.map +1 -1
  168. package/lib/cjs/serialization/SerializationHelpers.d.ts +109 -0
  169. package/lib/cjs/serialization/SerializationHelpers.d.ts.map +1 -0
  170. package/lib/cjs/serialization/SerializationHelpers.js +591 -0
  171. package/lib/cjs/serialization/SerializationHelpers.js.map +1 -0
  172. package/lib/cjs/solid/SweepContour.d.ts +4 -2
  173. package/lib/cjs/solid/SweepContour.d.ts.map +1 -1
  174. package/lib/cjs/solid/SweepContour.js +4 -2
  175. package/lib/cjs/solid/SweepContour.js.map +1 -1
  176. package/lib/esm/Geometry.d.ts.map +1 -1
  177. package/lib/esm/Geometry.js +2 -4
  178. package/lib/esm/Geometry.js.map +1 -1
  179. package/lib/esm/bspline/BSpline1dNd.d.ts +12 -2
  180. package/lib/esm/bspline/BSpline1dNd.d.ts.map +1 -1
  181. package/lib/esm/bspline/BSpline1dNd.js +27 -17
  182. package/lib/esm/bspline/BSpline1dNd.js.map +1 -1
  183. package/lib/esm/bspline/BSplineCurve.d.ts +30 -16
  184. package/lib/esm/bspline/BSplineCurve.d.ts.map +1 -1
  185. package/lib/esm/bspline/BSplineCurve.js +68 -44
  186. package/lib/esm/bspline/BSplineCurve.js.map +1 -1
  187. package/lib/esm/bspline/BSplineCurve3dH.d.ts +27 -20
  188. package/lib/esm/bspline/BSplineCurve3dH.d.ts.map +1 -1
  189. package/lib/esm/bspline/BSplineCurve3dH.js +137 -88
  190. package/lib/esm/bspline/BSplineCurve3dH.js.map +1 -1
  191. package/lib/esm/bspline/BSplineSurface.d.ts +138 -74
  192. package/lib/esm/bspline/BSplineSurface.d.ts.map +1 -1
  193. package/lib/esm/bspline/BSplineSurface.js +242 -119
  194. package/lib/esm/bspline/BSplineSurface.js.map +1 -1
  195. package/lib/esm/bspline/Bezier1dNd.d.ts +18 -4
  196. package/lib/esm/bspline/Bezier1dNd.d.ts.map +1 -1
  197. package/lib/esm/bspline/Bezier1dNd.js +19 -5
  198. package/lib/esm/bspline/Bezier1dNd.js.map +1 -1
  199. package/lib/esm/bspline/BezierCurve3dH.d.ts.map +1 -1
  200. package/lib/esm/bspline/BezierCurve3dH.js +2 -1
  201. package/lib/esm/bspline/BezierCurve3dH.js.map +1 -1
  202. package/lib/esm/bspline/KnotVector.d.ts +30 -33
  203. package/lib/esm/bspline/KnotVector.d.ts.map +1 -1
  204. package/lib/esm/bspline/KnotVector.js +76 -69
  205. package/lib/esm/bspline/KnotVector.js.map +1 -1
  206. package/lib/esm/clipping/AlternatingConvexClipTree.js.map +1 -1
  207. package/lib/esm/clipping/ClipUtils.d.ts +32 -5
  208. package/lib/esm/clipping/ClipUtils.d.ts.map +1 -1
  209. package/lib/esm/clipping/ClipUtils.js +92 -11
  210. package/lib/esm/clipping/ClipUtils.js.map +1 -1
  211. package/lib/esm/curve/CurveChainWithDistanceIndex.d.ts +18 -1
  212. package/lib/esm/curve/CurveChainWithDistanceIndex.d.ts.map +1 -1
  213. package/lib/esm/curve/CurveChainWithDistanceIndex.js +48 -1
  214. package/lib/esm/curve/CurveChainWithDistanceIndex.js.map +1 -1
  215. package/lib/esm/curve/CurveCollection.d.ts +9 -9
  216. package/lib/esm/curve/CurveCollection.d.ts.map +1 -1
  217. package/lib/esm/curve/CurveCollection.js +7 -10
  218. package/lib/esm/curve/CurveCollection.js.map +1 -1
  219. package/lib/esm/curve/CurveCurve.d.ts +2 -2
  220. package/lib/esm/curve/CurveCurve.d.ts.map +1 -1
  221. package/lib/esm/curve/CurveCurve.js +3 -16
  222. package/lib/esm/curve/CurveCurve.js.map +1 -1
  223. package/lib/esm/curve/CurveLocationDetail.d.ts +17 -4
  224. package/lib/esm/curve/CurveLocationDetail.d.ts.map +1 -1
  225. package/lib/esm/curve/CurveLocationDetail.js +32 -10
  226. package/lib/esm/curve/CurveLocationDetail.js.map +1 -1
  227. package/lib/esm/curve/CurveOps.d.ts +4 -5
  228. package/lib/esm/curve/CurveOps.d.ts.map +1 -1
  229. package/lib/esm/curve/CurveOps.js +1 -1
  230. package/lib/esm/curve/CurveOps.js.map +1 -1
  231. package/lib/esm/curve/CurveTypes.d.ts +14 -2
  232. package/lib/esm/curve/CurveTypes.d.ts.map +1 -1
  233. package/lib/esm/curve/CurveTypes.js.map +1 -1
  234. package/lib/esm/curve/CurveWireMomentsXYZ.d.ts.map +1 -1
  235. package/lib/esm/curve/CurveWireMomentsXYZ.js +2 -4
  236. package/lib/esm/curve/CurveWireMomentsXYZ.js.map +1 -1
  237. package/lib/esm/curve/LineString3d.d.ts +3 -6
  238. package/lib/esm/curve/LineString3d.d.ts.map +1 -1
  239. package/lib/esm/curve/LineString3d.js +1 -4
  240. package/lib/esm/curve/LineString3d.js.map +1 -1
  241. package/lib/esm/curve/PointString3d.d.ts +2 -1
  242. package/lib/esm/curve/PointString3d.d.ts.map +1 -1
  243. package/lib/esm/curve/PointString3d.js.map +1 -1
  244. package/lib/esm/curve/RegionOps.d.ts +7 -12
  245. package/lib/esm/curve/RegionOps.d.ts.map +1 -1
  246. package/lib/esm/curve/RegionOps.js +2 -1
  247. package/lib/esm/curve/RegionOps.js.map +1 -1
  248. package/lib/esm/curve/internalContexts/CurveCurveCloseApproachXY.d.ts +0 -9
  249. package/lib/esm/curve/internalContexts/CurveCurveCloseApproachXY.d.ts.map +1 -1
  250. package/lib/esm/curve/internalContexts/CurveCurveCloseApproachXY.js +16 -35
  251. package/lib/esm/curve/internalContexts/CurveCurveCloseApproachXY.js.map +1 -1
  252. package/lib/esm/curve/internalContexts/CurveCurveIntersectXY.d.ts +12 -6
  253. package/lib/esm/curve/internalContexts/CurveCurveIntersectXY.d.ts.map +1 -1
  254. package/lib/esm/curve/internalContexts/CurveCurveIntersectXY.js +81 -19
  255. package/lib/esm/curve/internalContexts/CurveCurveIntersectXY.js.map +1 -1
  256. package/lib/esm/curve/internalContexts/CurveCurveIntersectXYZ.d.ts +11 -5
  257. package/lib/esm/curve/internalContexts/CurveCurveIntersectXYZ.d.ts.map +1 -1
  258. package/lib/esm/curve/internalContexts/CurveCurveIntersectXYZ.js +74 -9
  259. package/lib/esm/curve/internalContexts/CurveCurveIntersectXYZ.js.map +1 -1
  260. package/lib/esm/curve/internalContexts/MultiChainCollector.d.ts +2 -3
  261. package/lib/esm/curve/internalContexts/MultiChainCollector.d.ts.map +1 -1
  262. package/lib/esm/curve/internalContexts/MultiChainCollector.js +2 -3
  263. package/lib/esm/curve/internalContexts/MultiChainCollector.js.map +1 -1
  264. package/lib/esm/curve/internalContexts/PolygonOffsetContext.d.ts +4 -4
  265. package/lib/esm/curve/internalContexts/PolygonOffsetContext.d.ts.map +1 -1
  266. package/lib/esm/curve/internalContexts/PolygonOffsetContext.js +38 -36
  267. package/lib/esm/curve/internalContexts/PolygonOffsetContext.js.map +1 -1
  268. package/lib/esm/geometry3d/CoincidentGeometryOps.d.ts +21 -5
  269. package/lib/esm/geometry3d/CoincidentGeometryOps.d.ts.map +1 -1
  270. package/lib/esm/geometry3d/CoincidentGeometryOps.js +71 -45
  271. package/lib/esm/geometry3d/CoincidentGeometryOps.js.map +1 -1
  272. package/lib/esm/geometry3d/Matrix3d.d.ts +20 -13
  273. package/lib/esm/geometry3d/Matrix3d.d.ts.map +1 -1
  274. package/lib/esm/geometry3d/Matrix3d.js +28 -21
  275. package/lib/esm/geometry3d/Matrix3d.js.map +1 -1
  276. package/lib/esm/geometry3d/Point3dVector3d.d.ts +11 -2
  277. package/lib/esm/geometry3d/Point3dVector3d.d.ts.map +1 -1
  278. package/lib/esm/geometry3d/Point3dVector3d.js +16 -5
  279. package/lib/esm/geometry3d/Point3dVector3d.js.map +1 -1
  280. package/lib/esm/geometry3d/PointHelpers.d.ts +58 -20
  281. package/lib/esm/geometry3d/PointHelpers.d.ts.map +1 -1
  282. package/lib/esm/geometry3d/PointHelpers.js +213 -62
  283. package/lib/esm/geometry3d/PointHelpers.js.map +1 -1
  284. package/lib/esm/geometry3d/Segment1d.d.ts +5 -1
  285. package/lib/esm/geometry3d/Segment1d.d.ts.map +1 -1
  286. package/lib/esm/geometry3d/Segment1d.js +11 -7
  287. package/lib/esm/geometry3d/Segment1d.js.map +1 -1
  288. package/lib/esm/geometry3d/Transform.d.ts +2 -3
  289. package/lib/esm/geometry3d/Transform.d.ts.map +1 -1
  290. package/lib/esm/geometry3d/Transform.js +2 -3
  291. package/lib/esm/geometry3d/Transform.js.map +1 -1
  292. package/lib/esm/geometry4d/Point4d.d.ts +14 -1
  293. package/lib/esm/geometry4d/Point4d.d.ts.map +1 -1
  294. package/lib/esm/geometry4d/Point4d.js +22 -1
  295. package/lib/esm/geometry4d/Point4d.js.map +1 -1
  296. package/lib/esm/numerics/BezierPolynomials.d.ts +91 -68
  297. package/lib/esm/numerics/BezierPolynomials.d.ts.map +1 -1
  298. package/lib/esm/numerics/BezierPolynomials.js +100 -79
  299. package/lib/esm/numerics/BezierPolynomials.js.map +1 -1
  300. package/lib/esm/numerics/Newton.d.ts +115 -60
  301. package/lib/esm/numerics/Newton.d.ts.map +1 -1
  302. package/lib/esm/numerics/Newton.js +120 -62
  303. package/lib/esm/numerics/Newton.js.map +1 -1
  304. package/lib/esm/numerics/PascalCoefficients.d.ts +8 -12
  305. package/lib/esm/numerics/PascalCoefficients.d.ts.map +1 -1
  306. package/lib/esm/numerics/PascalCoefficients.js +10 -12
  307. package/lib/esm/numerics/PascalCoefficients.js.map +1 -1
  308. package/lib/esm/numerics/Polynomials.d.ts +2 -2
  309. package/lib/esm/numerics/Polynomials.d.ts.map +1 -1
  310. package/lib/esm/numerics/Polynomials.js +2 -2
  311. package/lib/esm/numerics/Polynomials.js.map +1 -1
  312. package/lib/esm/polyface/PolyfaceBuilder.d.ts +3 -0
  313. package/lib/esm/polyface/PolyfaceBuilder.d.ts.map +1 -1
  314. package/lib/esm/polyface/PolyfaceBuilder.js +13 -2
  315. package/lib/esm/polyface/PolyfaceBuilder.js.map +1 -1
  316. package/lib/esm/polyface/PolyfaceClip.d.ts +1 -1
  317. package/lib/esm/polyface/PolyfaceClip.d.ts.map +1 -1
  318. package/lib/esm/polyface/PolyfaceClip.js +6 -3
  319. package/lib/esm/polyface/PolyfaceClip.js.map +1 -1
  320. package/lib/esm/polyface/PolyfaceData.d.ts +1 -1
  321. package/lib/esm/polyface/PolyfaceData.js +1 -1
  322. package/lib/esm/polyface/PolyfaceData.js.map +1 -1
  323. package/lib/esm/polyface/PolyfaceQuery.d.ts +39 -12
  324. package/lib/esm/polyface/PolyfaceQuery.d.ts.map +1 -1
  325. package/lib/esm/polyface/PolyfaceQuery.js +94 -17
  326. package/lib/esm/polyface/PolyfaceQuery.js.map +1 -1
  327. package/lib/esm/serialization/BGFBReader.d.ts +10 -10
  328. package/lib/esm/serialization/BGFBReader.d.ts.map +1 -1
  329. package/lib/esm/serialization/BGFBReader.js +69 -42
  330. package/lib/esm/serialization/BGFBReader.js.map +1 -1
  331. package/lib/esm/serialization/BGFBWriter.d.ts +8 -8
  332. package/lib/esm/serialization/BGFBWriter.d.ts.map +1 -1
  333. package/lib/esm/serialization/BGFBWriter.js +80 -55
  334. package/lib/esm/serialization/BGFBWriter.js.map +1 -1
  335. package/lib/esm/serialization/GeometrySamples.d.ts.map +1 -1
  336. package/lib/esm/serialization/GeometrySamples.js +7 -9
  337. package/lib/esm/serialization/GeometrySamples.js.map +1 -1
  338. package/lib/esm/serialization/IModelJsonSchema.d.ts +8 -14
  339. package/lib/esm/serialization/IModelJsonSchema.d.ts.map +1 -1
  340. package/lib/esm/serialization/IModelJsonSchema.js +86 -260
  341. package/lib/esm/serialization/IModelJsonSchema.js.map +1 -1
  342. package/lib/esm/serialization/SerializationHelpers.d.ts +109 -0
  343. package/lib/esm/serialization/SerializationHelpers.d.ts.map +1 -0
  344. package/lib/esm/serialization/SerializationHelpers.js +588 -0
  345. package/lib/esm/serialization/SerializationHelpers.js.map +1 -0
  346. package/lib/esm/solid/SweepContour.d.ts +4 -2
  347. package/lib/esm/solid/SweepContour.d.ts.map +1 -1
  348. package/lib/esm/solid/SweepContour.js +4 -2
  349. package/lib/esm/solid/SweepContour.js.map +1 -1
  350. package/package.json +3 -3
@@ -13,27 +13,28 @@ const Plane3dByOriginAndVectors_1 = require("../geometry3d/Plane3dByOriginAndVec
13
13
  const Point2dVector2d_1 = require("../geometry3d/Point2dVector2d");
14
14
  const Polynomials_1 = require("./Polynomials");
15
15
  // cspell:word currentdFdX
16
- /** base class for Newton iterations in various dimensions.
17
- * Dimension-specific classes carry all dimension-related data and answer generalized queries
18
- * from this base class.
16
+ /**
17
+ * Base class for Newton iterations in various dimensions.
18
+ * Dimension-specific classes carry all dimension-related data and answer generalized queries from this base class.
19
19
  * @internal
20
20
  */
21
21
  class AbstractNewtonIterator {
22
22
  /**
23
+ * The constructor.
23
24
  * @param stepSizeTarget tolerance to consider a single step converged.
24
- * This number should be "moderately" strict. Because 2 successive convergences are required,
25
+ * This number should be "moderately" strict. Because 2 successive convergences are required,
25
26
  * it is expected that a first "accept" for (say) 10 to 14 digit step will be followed by another
26
- * iteration. A well behaved newton would then hypothetically double the number of digits to
27
- * 20 to 28. Since the IEEE double only carries 16 digits, this second-convergence step will
27
+ * iteration. A well behaved newton would then hypothetically double the number of digits to
28
+ * 20 to 28. Since the IEEE double only carries 16 digits, this second-convergence step will
28
29
  * typically achieve full precision.
29
30
  * @param successiveConvergenceTarget number of successive convergences required for acceptance.
30
- * @param maxIterations max number of iterations. A typical newton step converges in 3 to 6 iterations.
31
- * Allow 15 to 20 to catch difficult cases.
31
+ * @param maxIterations max number of iterations. A typical newton step converges in 3 to 6 iterations.
32
+ * Allow 15 to 20 to catch difficult cases.
32
33
  */
33
34
  constructor(stepSizeTolerance = 1.0e-11, successiveConvergenceTarget = 2, maxIterations = 15) {
34
- /** Number of consecutive steps which passed convergence condition */
35
+ /** Number of consecutive steps which passed convergence condition. */
35
36
  this._numAccepted = 0;
36
- /** number of iterations (incremented at each step) */
37
+ /** Number of iterations (incremented at each step). */
37
38
  this.numIterations = 0;
38
39
  this._stepSizeTolerance = stepSizeTolerance;
39
40
  this._successiveConvergenceTarget = successiveConvergenceTarget;
@@ -41,8 +42,9 @@ class AbstractNewtonIterator {
41
42
  }
42
43
  /**
43
44
  * Test if a step is converged.
44
- * * Convergence is accepted with enough (_successiveConvergenceTarget) small steps (according to _stepSizeTolerance) occur in succession.
45
- * @param delta step size as reported by currentStepSize
45
+ * * Convergence is accepted with enough (_successiveConvergenceTarget) small steps (according to _stepSizeTolerance)
46
+ * occur in succession.
47
+ * @param delta step size as reported by currentStepSize.
46
48
  */
47
49
  testConvergence(delta) {
48
50
  if (Math.abs(delta) < this._stepSizeTolerance) {
@@ -55,16 +57,15 @@ class AbstractNewtonIterator {
55
57
  /**
56
58
  * Run iterations, calling various methods from base and derived classes:
57
59
  * * computeStep -- typically evaluate derivatives and solve linear system.
58
- * * currentStepSize -- return numeric measure of the step just computed by computeStep
60
+ * * currentStepSize -- return numeric measure of the step just computed by computeStep.
59
61
  * * testConvergence -- test if the step from currentStepSize (along with recent steps) is converged.
60
- * * applyCurrentStep -- apply the step to the independent variables
62
+ * * applyCurrentStep -- apply the step to the independent variables.
61
63
  */
62
64
  runIterations() {
63
65
  this._numAccepted = 0;
64
66
  this.numIterations = 0;
65
67
  while (this.numIterations++ < this._maxIterations && this.computeStep()) {
66
- if (this.testConvergence(this.currentStepSize())
67
- && this.applyCurrentStep(true)) {
68
+ if (this.testConvergence(this.currentStepSize()) && this.applyCurrentStep(true)) {
68
69
  return true;
69
70
  }
70
71
  this.applyCurrentStep(false);
@@ -73,7 +74,8 @@ class AbstractNewtonIterator {
73
74
  }
74
75
  }
75
76
  exports.AbstractNewtonIterator = AbstractNewtonIterator;
76
- /** object to evaluate a newton function. The object must retain most-recent function and derivative
77
+ /**
78
+ * Object to evaluate a newton function. The object must retain most-recent function and derivative
77
79
  * values for immediate query.
78
80
  * @internal
79
81
  */
@@ -82,26 +84,39 @@ class NewtonEvaluatorRtoRD {
82
84
  exports.NewtonEvaluatorRtoRD = NewtonEvaluatorRtoRD;
83
85
  /**
84
86
  * Newton iterator for use when both function and derivative can be evaluated.
87
+ * To solve `f(x) = 0`, the Newton iteration is `x_{n+1} = x_n - dx = x_n - f(x_n)/f'(x_n)`.
88
+ * To solve `f(x) = target` which is equivalent to solving `g(x) = f(x) - target = 0`, the Newton iteration is
89
+ * `x_{n+1} = x_n - dx = x_n - g(x_n)/g'(x_n) = x_n - (f(x_n)-target)/f'(x_n)`.
85
90
  * @internal
86
91
  */
87
92
  class Newton1dUnbounded extends AbstractNewtonIterator {
88
93
  /**
89
- * Constructor for 1D newton iteration with approximate derivatives.
90
- * @param func function that returns both function and derivative.
94
+ * Constructor for 1D newton iteration with derivatives.
95
+ * @param func function that returns both function value and derivative.
91
96
  */
92
97
  constructor(func) {
93
98
  super();
94
99
  this._func = func;
95
100
  this.setTarget(0);
96
101
  }
97
- /** Set the independent variable */
98
- setX(x) { this._currentX = x; return true; }
99
- /** Get the independent variable */
100
- getX() { return this._currentX; }
101
- /** Set the target function value */
102
- setTarget(y) { this._target = y; }
103
- /** move the current X by the just-computed step */
104
- applyCurrentStep() { return this.setX(this._currentX - this._currentStep); }
102
+ /** Set the independent variable, i.e., x_n. */
103
+ setX(x) {
104
+ this._currentX = x;
105
+ return true;
106
+ }
107
+ /** Get the independent variable, i.e., x_n. */
108
+ getX() {
109
+ return this._currentX;
110
+ }
111
+ /** Set the target function value. */
112
+ setTarget(y) {
113
+ this._target = y;
114
+ }
115
+ /** Move the current X by the just-computed step, i.e., `x_n - dx`. */
116
+ applyCurrentStep() {
117
+ // console.log(this._currentX - this._currentStep); // print approximations for debug
118
+ return this.setX(this._currentX - this._currentStep);
119
+ }
105
120
  /** Compute the univariate newton step. */
106
121
  computeStep() {
107
122
  if (this._func.evaluate(this._currentX)) {
@@ -113,43 +128,56 @@ class Newton1dUnbounded extends AbstractNewtonIterator {
113
128
  }
114
129
  return false;
115
130
  }
116
- /** Return the current step size as a relative number. */
131
+ /** Return the current step size as a relative number, i.e., `|dx / (1 + |x_n|)|`. */
117
132
  currentStepSize() {
118
133
  return Math.abs(this._currentStep / (1.0 + Math.abs(this._currentX)));
119
134
  }
120
135
  }
121
136
  exports.Newton1dUnbounded = Newton1dUnbounded;
122
- /** object to evaluate a newton function (without derivative). The object must retain most-recent function value.
137
+ /**
138
+ * Object to evaluate a newton function (without derivative). The object must retain most-recent function value.
123
139
  * @internal
124
140
  */
125
141
  class NewtonEvaluatorRtoR {
126
142
  }
127
143
  exports.NewtonEvaluatorRtoR = NewtonEvaluatorRtoR;
128
- /** Newton iteration for a univariate function, using approximate derivatives.
144
+ /**
145
+ * Newton iteration for a univariate function, using approximate derivatives.
146
+ * To approximate the derivatives we use a small step `h`, i.e., `f'(x_n) = (f(x_n + h) - f(x_n)) / h`.
147
+ * Therefore, to solve `f(x) = 0`, the iteration is
148
+ * `x_{n+1} = x_n - dx = x_n - f(x_n)/f'(x_n) = x_n - f(x_n) * h / (f(x_n + h) - f(x_n))`.
129
149
  * @internal
130
150
  */
131
151
  class Newton1dUnboundedApproximateDerivative extends AbstractNewtonIterator {
132
152
  /**
133
153
  * Constructor for 1D newton iteration with approximate derivatives.
134
- * @param func function that returns both function and derivative.
154
+ * @param func function that only returns function value (and not derivative).
135
155
  */
136
156
  constructor(func) {
137
157
  super();
138
158
  this._func = func;
139
159
  this.derivativeH = 1.0e-8;
140
160
  }
141
- /** Set the x (independent, iterated) value */
142
- setX(x) { this._currentX = x; return true; }
143
- /** Get the independent variable */
144
- getX() { return this._currentX; }
145
- /** move the current X by the just-computed step */
146
- applyCurrentStep() { return this.setX(this._currentX - this._currentStep); }
147
- /** Univariate newton step computed with APPROXIMATE derivative. */
161
+ /** Set the independent variable, i.e., x_n. */
162
+ setX(x) {
163
+ this._currentX = x;
164
+ return true;
165
+ }
166
+ /** Get the independent variable, i.e., x_n. */
167
+ getX() {
168
+ return this._currentX;
169
+ }
170
+ /** Move the current X by the just-computed step, i.e., `x_n - dx`. */
171
+ applyCurrentStep() {
172
+ // console.log(this._currentX - this._currentStep); // print approximations for debug
173
+ return this.setX(this._currentX - this._currentStep);
174
+ }
175
+ /** Univariate newton step computed with approximate derivative. */
148
176
  computeStep() {
149
177
  if (this._func.evaluate(this._currentX)) {
150
- const fA = this._func.currentF;
178
+ const fA = this._func.currentF; // f(x_n)
151
179
  if (this._func.evaluate(this._currentX + this.derivativeH)) {
152
- const fB = this._func.currentF;
180
+ const fB = this._func.currentF; // f(x_n + h)
153
181
  const dx = Geometry_1.Geometry.conditionalDivideFraction(fA, (fB - fA) / this.derivativeH);
154
182
  if (dx !== undefined) {
155
183
  this._currentStep = dx;
@@ -159,18 +187,19 @@ class Newton1dUnboundedApproximateDerivative extends AbstractNewtonIterator {
159
187
  }
160
188
  return false;
161
189
  }
162
- /** Return the current step size as a relative number. */
190
+ /** Return the current step size as a relative number, i.e., `|dx / (1 + |x_n|)|`. */
163
191
  currentStepSize() {
164
192
  return Math.abs(this._currentStep / (1.0 + Math.abs(this._currentX)));
165
193
  }
166
194
  }
167
195
  exports.Newton1dUnboundedApproximateDerivative = Newton1dUnboundedApproximateDerivative;
168
- /** object to evaluate a 2-parameter newton function (with derivatives!!).
196
+ /**
197
+ * Object to evaluate a 2-parameter newton function with derivatives.
169
198
  * @internal
170
199
  */
171
200
  class NewtonEvaluatorRRtoRRD {
172
201
  /**
173
- * constructor.
202
+ * Constructor.
174
203
  * * This creates a currentF object to (repeatedly) receive function and derivatives.
175
204
  */
176
205
  constructor() {
@@ -180,36 +209,61 @@ class NewtonEvaluatorRRtoRRD {
180
209
  exports.NewtonEvaluatorRRtoRRD = NewtonEvaluatorRRtoRRD;
181
210
  /**
182
211
  * Implement evaluation steps for newton iteration in 2 dimensions, using caller supplied NewtonEvaluatorRRtoRRD object.
212
+ * * Suppose we want to find the roots of `F(u,v) := (x(u,v), y(u,v))`. Writing `X := (u,v)` and `F(X)` as column vectors,
213
+ * the 2D Newton's iteration to find a root of `F` is given by:
214
+ * `X_{n+1} = X_n - dX = X_n - JInv(X_n)F(X_n)`, where `JInv` is the inverse of the Jacobian matrix `J`, and `J` is
215
+ * defined as:
216
+ *
217
+ * `[dx/du dx/dv]`
218
+ *
219
+ * `[dy/du dy/dv]`
183
220
  * @internal
184
221
  */
185
222
  class Newton2dUnboundedWithDerivative extends AbstractNewtonIterator {
223
+ /**
224
+ * Constructor for 2D newton iteration with derivatives.
225
+ * @param func function that returns both function value and derivative.
226
+ */
186
227
  constructor(func) {
187
228
  super();
188
229
  this._func = func;
189
230
  this._currentStep = Point2dVector2d_1.Vector2d.createZero();
190
231
  this._currentUV = Point2dVector2d_1.Point2d.createZero();
191
232
  }
192
- /** Set the current uv coordinates for current iteration */
193
- setUV(x, y) { this._currentUV.set(x, y); return true; }
194
- /** Get the current u coordinate */
195
- getU() { return this._currentUV.x; }
196
- /** Get the current v coordinate */
197
- getV() { return this._currentUV.y; }
198
- /** Move the currentUV coordinate by currentStep. */
199
- applyCurrentStep() { return this.setUV(this._currentUV.x - this._currentStep.x, this._currentUV.y - this._currentStep.y); }
200
- /** Evaluate the functions and derivatives at this._currentUV
201
- * Invert the jacobian and compute the this._currentStep.
233
+ /** Set the current uv parameters, i.e., `X_n = (u_n, v_n)`. */
234
+ setUV(u, v) {
235
+ this._currentUV.set(u, v);
236
+ return true;
237
+ }
238
+ /** Get the current u parameter of X_n, i.e., u_n. */
239
+ getU() {
240
+ return this._currentUV.x;
241
+ }
242
+ /** Get the current v parameter of X_n, i.e., v_n. */
243
+ getV() {
244
+ return this._currentUV.y;
245
+ }
246
+ /** Update the current uv parameter by currentStep, i.e., compute `X_{n+1} := X_n - dX = (u_n - du, v_n - dv)`. */
247
+ applyCurrentStep() {
248
+ // print approximations for debug
249
+ // console.log("(" + (this._currentUV.x - this._currentStep.x) + "," + (this._currentUV.y - this._currentStep.y) + ")");
250
+ return this.setUV(this._currentUV.x - this._currentStep.x, this._currentUV.y - this._currentStep.y);
251
+ }
252
+ /**
253
+ * Evaluate the functions and derivatives at `X_n = (u_n, v_n)`, and solve the Jacobian matrix equation to
254
+ * compute `dX = (du, dv)`.
202
255
  */
203
256
  computeStep() {
204
257
  if (this._func.evaluate(this._currentUV.x, this._currentUV.y)) {
205
258
  const fA = this._func.currentF;
206
- if (Polynomials_1.SmallSystem.linearSystem2d(fA.vectorU.x, fA.vectorV.x, fA.vectorU.y, fA.vectorV.y, fA.origin.x, fA.origin.y, this._currentStep))
259
+ if ( // Given X_{n+1} = X_n - dX = X_n - JInv(X_n) F(X_n), we solve J(X_n) dX = F(X_n) for dX:
260
+ Polynomials_1.SmallSystem.linearSystem2d(fA.vectorU.x, fA.vectorV.x, fA.vectorU.y, fA.vectorV.y, fA.origin.x, fA.origin.y, this._currentStep))
207
261
  return true;
208
262
  }
209
263
  return false;
210
264
  }
211
265
  /**
212
- * Return the largest relative step of the x,y, components of the current step.
266
+ * Return the current relative step size, i.e., the larger absolute component of `dX / (1 + |X_n|)`
213
267
  */
214
268
  currentStepSize() {
215
269
  return Geometry_1.Geometry.maxAbsXY(this._currentStep.x / (1.0 + Math.abs(this._currentUV.x)), this._currentStep.y / (1.0 + Math.abs(this._currentUV.y)));
@@ -217,15 +271,18 @@ class Newton2dUnboundedWithDerivative extends AbstractNewtonIterator {
217
271
  }
218
272
  exports.Newton2dUnboundedWithDerivative = Newton2dUnboundedWithDerivative;
219
273
  /**
220
- * SimpleNewton has static methods for newton methods with evaluated functions presented as immediate arguments (not function object)
274
+ * SimpleNewton has static methods for newton methods with evaluated functions presented as immediate arguments
275
+ * (not function object).
221
276
  * @internal
222
277
  */
223
278
  class SimpleNewton {
224
- /** Run a one-dimensional newton iteration with separate functions for function and derivative.
225
- * * completion is at 2 (TWO) successive passes at (absoluteTolerance + relTol * abs (x)), where relTol is chosen internally.
226
- * * absoluteTolerance is usually aggressively tight -- should come into play only for x near zero.
227
- * * The relTol is fluffy (for instance around 1e-11) but in properly converging cases the extra pass after first success
228
- * normally moves to full machine precision.
279
+ /**
280
+ * Run a one-dimensional newton iteration with separate functions for function and derivative.
281
+ * * Completion is at 2 (TWO) successive passes at `absoluteTolerance + relTol * abs(x)`, where relTol is
282
+ * chosen internally.
283
+ * * `absoluteTolerance` is usually aggressively tight -- should come into play only for x near zero.
284
+ * * The `relTol` is fluffy (for instance around 1e-11) but in properly converging cases the extra pass after
285
+ * first success normally moves to full machine precision.
229
286
  * * This is an open-loop newton -- it just runs, and returns undefined if anything bad happens.
230
287
  */
231
288
  static runNewton1D(x, func, derivative, absoluteTolerance = Geometry_1.Geometry.smallFloatingPoint) {
@@ -240,10 +297,11 @@ class SimpleNewton {
240
297
  if (dx === undefined)
241
298
  return undefined;
242
299
  x -= dx;
300
+ // console.log(x); // print approximations for debug
243
301
  tolerance = absoluteTolerance + Math.abs(x) * relTol;
244
302
  if (Math.abs(dx) < tolerance) {
245
303
  numConverged++;
246
- if (dx === 0.0 || numConverged > 1) // bypass convergence count on true 0 dx !
304
+ if (dx === 0.0 || numConverged > 1) // bypass convergence count on true 0 dx
247
305
  return x;
248
306
  }
249
307
  else {
@@ -1 +1 @@
1
- {"version":3,"file":"Newton.js","sourceRoot":"","sources":["../../../src/numerics/Newton.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F;;GAEG;AAEH,0CAAuC;AACvC,uFAAoF;AACpF,mEAAkE;AAClE,+CAA4C;AAE5C,0BAA0B;AAC1B;;;;GAIG;AACH,MAAsB,sBAAsB;IAY1C;;;;;;;;;;OAUG;IACH,YACE,oBAA4B,OAAO,EACnC,8BAAsC,CAAC,EACvC,gBAAwB,EAAE;QAK5B,qEAAqE;QAC3D,iBAAY,GAAW,CAAC,CAAC;QAOnC,sDAAsD;QAC/C,kBAAa,GAAW,CAAC,CAAC;QAb/B,IAAI,CAAC,kBAAkB,GAAG,iBAAiB,CAAC;QAC5C,IAAI,CAAC,4BAA4B,GAAG,2BAA2B,CAAC;QAChE,IAAI,CAAC,cAAc,GAAG,aAAa,CAAC;IACtC,CAAC;IAWD;;;;OAIG;IACI,eAAe,CAAC,KAAa;QAClC,IAAI,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,kBAAkB,EAAE;YAC7C,IAAI,CAAC,YAAY,EAAE,CAAC;YACpB,OAAO,IAAI,CAAC,YAAY,IAAI,IAAI,CAAC,4BAA4B,CAAC;SAC/D;QACD,IAAI,CAAC,YAAY,GAAG,CAAC,CAAC;QACtB,OAAO,KAAK,CAAC;IACf,CAAC;IACD;;;;;;OAMG;IACI,aAAa;QAClB,IAAI,CAAC,YAAY,GAAG,CAAC,CAAC;QACtB,IAAI,CAAC,aAAa,GAAG,CAAC,CAAC;QACvB,OAAO,IAA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AzCD,0EAyCC;AACD;;;GAGG;AACH,MAAa,YAAY;IACvB;;;;;;OAMG;IACI,MAAM,CAAC,WAAW,CACvB,CAAS,EACT,IAAuC,EACvC,UAA6C,EAC7C,oBAA4B,mBAAQ,CAAC,kBAAkB;QAEvD,IAAI,YAAY,GAAG,CAAC,CAAC;QACrB,IAAI,SAAiB,CAAC;QACtB,MAAM,MAAM,GAAG,OAAO,CAAC;QACvB,KAAK,IAAI,SAAS,GAAG,CAAC,EAAE,SAAS,GAAG,EAAE,EAAE,SAAS,EAAE,EAAE;YACnD,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;YAClB,MAAM,EAAE,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;YACzB,IAAI,CAAC,KAAK,SAAS,IAAI,EAAE,KAAK,SAAS,EAAE;gBACvC,MAAM,EAAE,GAAG,mBAAQ,CAAC,2BAA2B,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;gBACvD,IAAI,EAAE,KAAK,SAAS;oBAClB,OAAO,SAAS,CAAC;gBACnB,CAAC,IAAI,EAAE,CAAC;gBACR,SAAS,GAAG,iBAAiB,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC;gBACrD,IAAI,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,EAAE;oBAC5B,YAAY,EAAE,CAAC;oBACf,IAAI,EAAE,KAAK,GAAG,IAAI,YAAY,GAAG,CAAC,EAAI,0CAA0C;wBAC9E,OAAO,CAAC,CAAC;iBACZ;qBAAM;oBACL,YAAY,GAAG,CAAC,CAAC;iBAClB;aACF;SACF;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;CACF;AArCD,oCAqCC","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 Numerics\r\n */\r\n\r\nimport { Geometry } from \"../Geometry\";\r\nimport { Plane3dByOriginAndVectors } from \"../geometry3d/Plane3dByOriginAndVectors\";\r\nimport { Point2d, Vector2d } from \"../geometry3d/Point2dVector2d\";\r\nimport { SmallSystem } from \"./Polynomials\";\r\n\r\n// cspell:word currentdFdX\r\n/** base class for Newton iterations in various dimensions.\r\n * Dimension-specific classes carry all dimension-related data and answer generalized queries\r\n * from this base class.\r\n * @internal\r\n */\r\nexport abstract class AbstractNewtonIterator {\r\n /** Compute a step. The current x and function values must be retained for use in later method calls */\r\n public abstract computeStep(): boolean;\r\n /** return the current step size, scaled for use in tolerance tests.\r\n * * This is a single number, typically the max of various per-dimension `dx / (1+x)` for the x and dx of that dimension.\r\n */\r\n public abstract currentStepSize(): number;\r\n /**\r\n * Apply the current step (in all dimensions)\r\n * @param isFinalStep true if this is a final step.\r\n */\r\n public abstract applyCurrentStep(isFinalStep: boolean): boolean;\r\n /**\r\n * @param stepSizeTarget tolerance to consider a single step converged.\r\n * This number should be \"moderately\" strict. Because 2 successive convergences are required,\r\n * it is expected that a first \"accept\" for (say) 10 to 14 digit step will be followed by another\r\n * iteration. A well behaved newton would then hypothetically double the number of digits to\r\n * 20 to 28. Since the IEEE double only carries 16 digits, this second-convergence step will\r\n * typically achieve full precision.\r\n * @param successiveConvergenceTarget number of successive convergences required for acceptance.\r\n * @param maxIterations max number of iterations. A typical newton step converges in 3 to 6 iterations.\r\n * Allow 15 to 20 to catch difficult cases.\r\n */\r\n protected constructor(\r\n stepSizeTolerance: number = 1.0e-11,\r\n successiveConvergenceTarget: number = 2,\r\n maxIterations: number = 15) {\r\n this._stepSizeTolerance = stepSizeTolerance;\r\n this._successiveConvergenceTarget = successiveConvergenceTarget;\r\n this._maxIterations = maxIterations;\r\n }\r\n /** Number of consecutive steps which passed convergence condition */\r\n protected _numAccepted: number = 0;\r\n /** Target number of successive convergences */\r\n protected _successiveConvergenceTarget: number;\r\n /** convergence target (the implementation-specific currentStepSize is compared to this) */\r\n protected _stepSizeTolerance: number;\r\n /** Max iterations allowed */\r\n protected _maxIterations: number;\r\n /** number of iterations (incremented at each step) */\r\n public numIterations: number = 0;\r\n /**\r\n * Test if a step is converged.\r\n * * Convergence is accepted with enough (_successiveConvergenceTarget) small steps (according to _stepSizeTolerance) occur in succession.\r\n * @param delta step size as reported by currentStepSize\r\n */\r\n public testConvergence(delta: number): boolean {\r\n if (Math.abs(delta) < this._stepSizeTolerance) {\r\n this._numAccepted++;\r\n return this._numAccepted >= this._successiveConvergenceTarget;\r\n }\r\n this._numAccepted = 0;\r\n return false;\r\n }\r\n /**\r\n * Run iterations, calling various methods from base and derived classes:\r\n * * computeStep -- typically evaluate derivatives and solve linear system.\r\n * * currentStepSize -- return numeric measure of the step just computed by computeStep\r\n * * testConvergence -- test if the step from currentStepSize (along with recent steps) is converged.\r\n * * applyCurrentStep -- apply the step to the independent variables\r\n */\r\n public runIterations(): boolean {\r\n this._numAccepted = 0;\r\n this.numIterations = 0;\r\n while (this.numIterations++ < this._maxIterations && this.computeStep()) {\r\n if (this.testConvergence(this.currentStepSize())\r\n && this.applyCurrentStep(true)) {\r\n return true;\r\n }\r\n this.applyCurrentStep(false);\r\n }\r\n return false;\r\n }\r\n}\r\n/** object to evaluate a newton function. The object must retain most-recent function and derivative\r\n * values for immediate query.\r\n * @internal\r\n */\r\nexport abstract class NewtonEvaluatorRtoRD {\r\n /** evaluate the function and its derivative at x. */\r\n public abstract evaluate(x: number): boolean;\r\n /** most recent function value */\r\n public currentF!: number;\r\n /** most recent evaluated derivative */\r\n public currentdFdX!: number;\r\n}\r\n/**\r\n * Newton iterator for use when both function and derivative can be evaluated.\r\n * @internal\r\n */\r\nexport class Newton1dUnbounded extends AbstractNewtonIterator {\r\n private _func: NewtonEvaluatorRtoRD;\r\n private _currentStep!: number;\r\n private _currentX!: number;\r\n private _target!: number;\r\n /**\r\n * Constructor for 1D newton iteration with approximate derivatives.\r\n * @param func function that returns both function and derivative.\r\n */\r\n public constructor(func: NewtonEvaluatorRtoRD) {\r\n super();\r\n this._func = func;\r\n this.setTarget(0);\r\n }\r\n /** Set the independent variable */\r\n public setX(x: number): boolean { this._currentX = x; return true; }\r\n /** Get the independent variable */\r\n public getX(): number { return this._currentX; }\r\n /** Set the target function value */\r\n public setTarget(y: number) { this._target = y; }\r\n /** move the current X by the just-computed step */\r\n public applyCurrentStep(): boolean { return this.setX(this._currentX - this._currentStep); }\r\n /** Compute the univariate newton step. */\r\n public computeStep(): boolean {\r\n if (this._func.evaluate(this._currentX)) {\r\n const dx = Geometry.conditionalDivideFraction(this._func.currentF - this._target, this._func.currentdFdX);\r\n if (dx !== undefined) {\r\n this._currentStep = dx;\r\n return true;\r\n }\r\n }\r\n return false;\r\n }\r\n /** Return the current step size as a relative number. */\r\n public currentStepSize(): number {\r\n return Math.abs(this._currentStep / (1.0 + Math.abs(this._currentX)));\r\n }\r\n}\r\n\r\n/** object to evaluate a newton function (without derivative). The object must retain most-recent function value.\r\n * @internal\r\n */\r\nexport abstract class NewtonEvaluatorRtoR {\r\n /** Evaluate function value into member currentF */\r\n public abstract evaluate(x: number): boolean;\r\n /** Most recent function evaluation. */\r\n public currentF!: number;\r\n}\r\n\r\n/** Newton iteration for a univariate function, using approximate derivatives.\r\n * @internal\r\n */\r\nexport class Newton1dUnboundedApproximateDerivative extends AbstractNewtonIterator {\r\n private _func: NewtonEvaluatorRtoR;\r\n private _currentStep!: number;\r\n private _currentX!: number;\r\n /** Step size for iteration.\r\n * * Initialized to 1e-8, which is appropriate for iteration in fraction space.\r\n * * Should be larger for iteration with real distance as x.\r\n */\r\n public derivativeH: number; // step size for approximate derivative\r\n\r\n /**\r\n * Constructor for 1D newton iteration with approximate derivatives.\r\n * @param func function that returns both function and derivative.\r\n */\r\n public constructor(func: NewtonEvaluatorRtoR) {\r\n super();\r\n this._func = func;\r\n this.derivativeH = 1.0e-8;\r\n }\r\n /** Set the x (independent, iterated) value */\r\n public setX(x: number): boolean { this._currentX = x; return true; }\r\n /** Get the independent variable */\r\n public getX(): number { return this._currentX; }\r\n /** move the current X by the just-computed step */\r\n public applyCurrentStep(): boolean { return this.setX(this._currentX - this._currentStep); }\r\n /** Univariate newton step computed with APPROXIMATE derivative. */\r\n public computeStep(): boolean {\r\n if (this._func.evaluate(this._currentX)) {\r\n const fA = this._func.currentF;\r\n if (this._func.evaluate(this._currentX + this.derivativeH)) {\r\n const fB = this._func.currentF;\r\n const dx = Geometry.conditionalDivideFraction(fA, (fB - fA) / this.derivativeH);\r\n if (dx !== undefined) {\r\n this._currentStep = dx;\r\n return true;\r\n }\r\n }\r\n }\r\n return false;\r\n }\r\n\r\n /** Return the current step size as a relative number. */\r\n public currentStepSize(): number {\r\n return Math.abs(this._currentStep / (1.0 + Math.abs(this._currentX)));\r\n }\r\n}\r\n\r\n/** object to evaluate a 2-parameter newton function (with derivatives!!).\r\n * @internal\r\n */\r\nexport abstract class NewtonEvaluatorRRtoRRD {\r\n /** Iteration controller calls this to ask for evaluation of the function and its two partial derivatives.\r\n * * The implementation returns true, it must set the currentF object.\r\n */\r\n public abstract evaluate(x: number, y: number): boolean;\r\n /** most recent function evaluation as xy parts of the plane */\r\n public currentF!: Plane3dByOriginAndVectors;\r\n /**\r\n * constructor.\r\n * * This creates a currentF object to (repeatedly) receive function and derivatives.\r\n */\r\n public constructor() {\r\n this.currentF = Plane3dByOriginAndVectors.createXYPlane();\r\n }\r\n}\r\n\r\n/**\r\n * Implement evaluation steps for newton iteration in 2 dimensions, using caller supplied NewtonEvaluatorRRtoRRD object.\r\n * @internal\r\n */\r\nexport class Newton2dUnboundedWithDerivative extends AbstractNewtonIterator {\r\n private _func: NewtonEvaluatorRRtoRRD;\r\n private _currentStep: Vector2d;\r\n private _currentUV: Point2d;\r\n\r\n public constructor(func: NewtonEvaluatorRRtoRRD) {\r\n super();\r\n this._func = func;\r\n this._currentStep = Vector2d.createZero();\r\n this._currentUV = Point2d.createZero();\r\n }\r\n /** Set the current uv coordinates for current iteration */\r\n public setUV(x: number, y: number): boolean { this._currentUV.set(x, y); return true; }\r\n /** Get the current u coordinate */\r\n public getU(): number { return this._currentUV.x; }\r\n /** Get the current v coordinate */\r\n public getV(): number { return this._currentUV.y; }\r\n /** Move the currentUV coordinate by currentStep. */\r\n public applyCurrentStep(): boolean { return this.setUV(this._currentUV.x - this._currentStep.x, this._currentUV.y - this._currentStep.y); }\r\n /** Evaluate the functions and derivatives at this._currentUV\r\n * Invert the jacobian and compute the this._currentStep.\r\n */\r\n public computeStep(): boolean {\r\n if (this._func.evaluate(this._currentUV.x, this._currentUV.y)) {\r\n const fA = this._func.currentF;\r\n if (SmallSystem.linearSystem2d(\r\n fA.vectorU.x, fA.vectorV.x,\r\n fA.vectorU.y, fA.vectorV.y,\r\n fA.origin.x, fA.origin.y, this._currentStep))\r\n return true;\r\n }\r\n return false;\r\n }\r\n /**\r\n * Return the largest relative step of the x,y, components of the current step.\r\n */\r\n public currentStepSize(): number {\r\n return Geometry.maxAbsXY(\r\n this._currentStep.x / (1.0 + Math.abs(this._currentUV.x)),\r\n this._currentStep.y / (1.0 + Math.abs(this._currentUV.y)));\r\n }\r\n}\r\n/**\r\n * SimpleNewton has static methods for newton methods with evaluated functions presented as immediate arguments (not function object)\r\n * @internal\r\n */\r\nexport class SimpleNewton {\r\n /** Run a one-dimensional newton iteration with separate functions for function and derivative.\r\n * * completion is at 2 (TWO) successive passes at (absoluteTolerance + relTol * abs (x)), where relTol is chosen internally.\r\n * * absoluteTolerance is usually aggressively tight -- should come into play only for x near zero.\r\n * * The relTol is fluffy (for instance around 1e-11) but in properly converging cases the extra pass after first success\r\n * normally moves to full machine precision.\r\n * * This is an open-loop newton -- it just runs, and returns undefined if anything bad happens.\r\n */\r\n public static runNewton1D(\r\n x: number,\r\n func: (x: number) => number | undefined,\r\n derivative: (x: number) => number | undefined,\r\n absoluteTolerance: number = Geometry.smallFloatingPoint,\r\n ): number | undefined {\r\n let numConverged = 0;\r\n let tolerance: number;\r\n const relTol = 1.0e-11;\r\n for (let iteration = 0; iteration < 20; iteration++) {\r\n const f = func(x);\r\n const df = derivative(x);\r\n if (f !== undefined && df !== undefined) {\r\n const dx = Geometry.conditionalDivideCoordinate(f, df);\r\n if (dx === undefined)\r\n return undefined;\r\n x -= dx;\r\n tolerance = absoluteTolerance + Math.abs(x) * relTol;\r\n if (Math.abs(dx) < tolerance) {\r\n numConverged++;\r\n if (dx === 0.0 || numConverged > 1) // bypass convergence count on true 0 dx !\r\n return x;\r\n } else {\r\n numConverged = 0;\r\n }\r\n }\r\n }\r\n return undefined;\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"Newton.js","sourceRoot":"","sources":["../../../src/numerics/Newton.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F;;GAEG;AAEH,0CAAuC;AACvC,uFAAoF;AACpF,mEAAkE;AAClE,+CAA4C;AAE5C,0BAA0B;AAE1B;;;;GAIG;AACH,MAAsB,sBAAsB;IAa1C;;;;;;;;;;;OAWG;IACH,YACE,oBAA4B,OAAO,EACnC,8BAAsC,CAAC,EACvC,gBAAwB,EAAE;QAM5B,sEAAsE;QAC5D,iBAAY,GAAW,CAAC,CAAC;QAOnC,uDAAuD;QAChD,kBAAa,GAAW,CAAC,CAAC;QAb/B,IAAI,CAAC,kBAAkB,GAAG,iBAAiB,CAAC;QAC5C,IAAI,CAAC,4BAA4B,GAAG,2BAA2B,CAAC;QAChE,IAAI,CAAC,cAAc,GAAG,aAAa,CAAC;IACtC,CAAC;IAWD;;;;;OAKG;IACI,eAAe,CAAC,KAAa;QAClC,IAAI,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,kBAAkB,EAAE;YAC7C,IAAI,CAAC,YAAY,EAAE,CAAC;YACpB,OAAO,IAAI,CAAC,YAAY,IAAI,IAAI,CAAC,4BAA4B,CAAC;SAC/D;QACD,IAAI,CAAC,YAAY,GAAG,CAAC,CAAC;QACtB,OAAO,KAAK,CAAC;IACf,C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BAAM;oBACL,YAAY,GAAG,CAAC,CAAC;iBAClB;aACF;SACF;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;CACF;AAxCD,oCAwCC","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 Numerics\r\n */\r\n\r\nimport { Geometry } from \"../Geometry\";\r\nimport { Plane3dByOriginAndVectors } from \"../geometry3d/Plane3dByOriginAndVectors\";\r\nimport { Point2d, Vector2d } from \"../geometry3d/Point2dVector2d\";\r\nimport { SmallSystem } from \"./Polynomials\";\r\n\r\n// cspell:word currentdFdX\r\n\r\n/**\r\n * Base class for Newton iterations in various dimensions.\r\n * Dimension-specific classes carry all dimension-related data and answer generalized queries from this base class.\r\n * @internal\r\n */\r\nexport abstract class AbstractNewtonIterator {\r\n /** Compute a step. The current x and function values must be retained for use in later method calls. */\r\n public abstract computeStep(): boolean;\r\n /**\r\n * Return the current step size, scaled for use in tolerance tests.\r\n * * This is a single number, typically the max of various per-dimension `dx/(1+x)` for the x and dx of that dimension.\r\n */\r\n public abstract currentStepSize(): number;\r\n /**\r\n * Apply the current step (in all dimensions).\r\n * @param isFinalStep true if this is a final step.\r\n */\r\n public abstract applyCurrentStep(isFinalStep: boolean): boolean;\r\n /**\r\n * The constructor.\r\n * @param stepSizeTarget tolerance to consider a single step converged.\r\n * This number should be \"moderately\" strict. Because 2 successive convergences are required,\r\n * it is expected that a first \"accept\" for (say) 10 to 14 digit step will be followed by another\r\n * iteration. A well behaved newton would then hypothetically double the number of digits to\r\n * 20 to 28. Since the IEEE double only carries 16 digits, this second-convergence step will\r\n * typically achieve full precision.\r\n * @param successiveConvergenceTarget number of successive convergences required for acceptance.\r\n * @param maxIterations max number of iterations. A typical newton step converges in 3 to 6 iterations.\r\n * Allow 15 to 20 to catch difficult cases.\r\n */\r\n protected constructor(\r\n stepSizeTolerance: number = 1.0e-11,\r\n successiveConvergenceTarget: number = 2,\r\n maxIterations: number = 15,\r\n ) {\r\n this._stepSizeTolerance = stepSizeTolerance;\r\n this._successiveConvergenceTarget = successiveConvergenceTarget;\r\n this._maxIterations = maxIterations;\r\n }\r\n /** Number of consecutive steps which passed convergence condition. */\r\n protected _numAccepted: number = 0;\r\n /** Target number of successive convergences. */\r\n protected _successiveConvergenceTarget: number;\r\n /** Convergence target (the implementation-specific currentStepSize is compared to this). */\r\n protected _stepSizeTolerance: number;\r\n /** Max iterations allowed. */\r\n protected _maxIterations: number;\r\n /** Number of iterations (incremented at each step). */\r\n public numIterations: number = 0;\r\n /**\r\n * Test if a step is converged.\r\n * * Convergence is accepted with enough (_successiveConvergenceTarget) small steps (according to _stepSizeTolerance)\r\n * occur in succession.\r\n * @param delta step size as reported by currentStepSize.\r\n */\r\n public testConvergence(delta: number): boolean {\r\n if (Math.abs(delta) < this._stepSizeTolerance) {\r\n this._numAccepted++;\r\n return this._numAccepted >= this._successiveConvergenceTarget;\r\n }\r\n this._numAccepted = 0;\r\n return false;\r\n }\r\n /**\r\n * Run iterations, calling various methods from base and derived classes:\r\n * * computeStep -- typically evaluate derivatives and solve linear system.\r\n * * currentStepSize -- return numeric measure of the step just computed by computeStep.\r\n * * testConvergence -- test if the step from currentStepSize (along with recent steps) is converged.\r\n * * applyCurrentStep -- apply the step to the independent variables.\r\n */\r\n public runIterations(): boolean {\r\n this._numAccepted = 0;\r\n this.numIterations = 0;\r\n while (this.numIterations++ < this._maxIterations && this.computeStep()) {\r\n if (this.testConvergence(this.currentStepSize()) && this.applyCurrentStep(true)) {\r\n return true;\r\n }\r\n this.applyCurrentStep(false);\r\n }\r\n return false;\r\n }\r\n}\r\n/**\r\n * Object to evaluate a newton function. The object must retain most-recent function and derivative\r\n * values for immediate query.\r\n * @internal\r\n */\r\nexport abstract class NewtonEvaluatorRtoRD {\r\n /** Evaluate the function and its derivative at x. */\r\n public abstract evaluate(x: number): boolean;\r\n /** Most recent function value, i.e., f(x_n). */\r\n public currentF!: number;\r\n /** Most recent evaluated derivative, i.e., f'(x_n). */\r\n public currentdFdX!: number;\r\n}\r\n/**\r\n * Newton iterator for use when both function and derivative can be evaluated.\r\n * To solve `f(x) = 0`, the Newton iteration is `x_{n+1} = x_n - dx = x_n - f(x_n)/f'(x_n)`.\r\n * To solve `f(x) = target` which is equivalent to solving `g(x) = f(x) - target = 0`, the Newton iteration is\r\n * `x_{n+1} = x_n - dx = x_n - g(x_n)/g'(x_n) = x_n - (f(x_n)-target)/f'(x_n)`.\r\n * @internal\r\n */\r\nexport class Newton1dUnbounded extends AbstractNewtonIterator {\r\n private _func: NewtonEvaluatorRtoRD;\r\n /** Current step is dx. */\r\n private _currentStep!: number;\r\n /** Current X is x_n. */\r\n private _currentX!: number;\r\n /** The target */\r\n private _target!: number;\r\n /**\r\n * Constructor for 1D newton iteration with derivatives.\r\n * @param func function that returns both function value and derivative.\r\n */\r\n public constructor(func: NewtonEvaluatorRtoRD) {\r\n super();\r\n this._func = func;\r\n this.setTarget(0);\r\n }\r\n /** Set the independent variable, i.e., x_n. */\r\n public setX(x: number): boolean {\r\n this._currentX = x;\r\n return true;\r\n }\r\n /** Get the independent variable, i.e., x_n. */\r\n public getX(): number {\r\n return this._currentX;\r\n }\r\n /** Set the target function value. */\r\n public setTarget(y: number): void {\r\n this._target = y;\r\n }\r\n /** Move the current X by the just-computed step, i.e., `x_n - dx`. */\r\n public applyCurrentStep(): boolean {\r\n // console.log(this._currentX - this._currentStep); // print approximations for debug\r\n return this.setX(this._currentX - this._currentStep);\r\n }\r\n /** Compute the univariate newton step. */\r\n public computeStep(): boolean {\r\n if (this._func.evaluate(this._currentX)) {\r\n const dx = Geometry.conditionalDivideFraction(this._func.currentF - this._target, this._func.currentdFdX);\r\n if (dx !== undefined) {\r\n this._currentStep = dx;\r\n return true;\r\n }\r\n }\r\n return false;\r\n }\r\n /** Return the current step size as a relative number, i.e., `|dx / (1 + |x_n|)|`. */\r\n public currentStepSize(): number {\r\n return Math.abs(this._currentStep / (1.0 + Math.abs(this._currentX)));\r\n }\r\n}\r\n\r\n/**\r\n * Object to evaluate a newton function (without derivative). The object must retain most-recent function value.\r\n * @internal\r\n */\r\nexport abstract class NewtonEvaluatorRtoR {\r\n /** Evaluate function value into member currentF */\r\n public abstract evaluate(x: number): boolean;\r\n /** Most recent function evaluation, i.e., f(x_n). */\r\n public currentF!: number;\r\n}\r\n\r\n/**\r\n * Newton iteration for a univariate function, using approximate derivatives.\r\n * To approximate the derivatives we use a small step `h`, i.e., `f'(x_n) = (f(x_n + h) - f(x_n)) / h`.\r\n * Therefore, to solve `f(x) = 0`, the iteration is\r\n * `x_{n+1} = x_n - dx = x_n - f(x_n)/f'(x_n) = x_n - f(x_n) * h / (f(x_n + h) - f(x_n))`.\r\n * @internal\r\n */\r\nexport class Newton1dUnboundedApproximateDerivative extends AbstractNewtonIterator {\r\n private _func: NewtonEvaluatorRtoR;\r\n /** Current step is dx. */\r\n private _currentStep!: number;\r\n /** Current X is x_n. */\r\n private _currentX!: number;\r\n /**\r\n * Step size for approximate derivative for the iteration.\r\n * * Initialized to 1e-8, which is appropriate for iteration in fraction space.\r\n * * Should be larger for iteration with real distance as x.\r\n */\r\n public derivativeH: number; // h\r\n\r\n /**\r\n * Constructor for 1D newton iteration with approximate derivatives.\r\n * @param func function that only returns function value (and not derivative).\r\n */\r\n public constructor(func: NewtonEvaluatorRtoR) {\r\n super();\r\n this._func = func;\r\n this.derivativeH = 1.0e-8;\r\n }\r\n /** Set the independent variable, i.e., x_n. */\r\n public setX(x: number): boolean {\r\n this._currentX = x;\r\n return true;\r\n }\r\n /** Get the independent variable, i.e., x_n. */\r\n public getX(): number {\r\n return this._currentX;\r\n }\r\n /** Move the current X by the just-computed step, i.e., `x_n - dx`. */\r\n public applyCurrentStep(): boolean {\r\n // console.log(this._currentX - this._currentStep); // print approximations for debug\r\n return this.setX(this._currentX - this._currentStep);\r\n }\r\n /** Univariate newton step computed with approximate derivative. */\r\n public computeStep(): boolean {\r\n if (this._func.evaluate(this._currentX)) {\r\n const fA = this._func.currentF; // f(x_n)\r\n if (this._func.evaluate(this._currentX + this.derivativeH)) {\r\n const fB = this._func.currentF; // f(x_n + h)\r\n const dx = Geometry.conditionalDivideFraction(fA, (fB - fA) / this.derivativeH);\r\n if (dx !== undefined) {\r\n this._currentStep = dx;\r\n return true;\r\n }\r\n }\r\n }\r\n return false;\r\n }\r\n /** Return the current step size as a relative number, i.e., `|dx / (1 + |x_n|)|`. */\r\n public currentStepSize(): number {\r\n return Math.abs(this._currentStep / (1.0 + Math.abs(this._currentX)));\r\n }\r\n}\r\n\r\n/**\r\n * Object to evaluate a 2-parameter newton function with derivatives.\r\n * @internal\r\n */\r\nexport abstract class NewtonEvaluatorRRtoRRD {\r\n /**\r\n * Iteration controller calls this to ask for evaluation of the function and its two partial derivatives.\r\n * * The implementation returns true, it must set the currentF object.\r\n */\r\n public abstract evaluate(x: number, y: number): boolean;\r\n /**\r\n * Most recent function evaluation as parts of the plane.\r\n * * See doc of [[Newton2dUnboundedWithDerivative]] class for info on 2d newton method.\r\n * * For current value (u,v) of the independent variable, and `F(u,v) := (x(u,v), y(u,v)), the returned plane has:\r\n * * `origin.x` = x(u,v)\r\n * * `origin.y` = y(u,v)\r\n * * `vectorU.x` = dx/du\r\n * * `vectorU.y` = dy/du\r\n * * `vectorV.x` = dx/dv\r\n * * `vectorV.y` = dy/dv\r\n * * In other words, the plane stores the columns of the Jacobian matrix J of F: `vectorU` stores the partials\r\n * of F with respect to u (the first column of J), and `vectorV` stores the partials of F with respect to v\r\n * (the second column of J):\r\n *\r\n * `[vectorU.x vectorV.x]`\r\n *\r\n * `[vectorU.y vectorV.y]`\r\n */\r\n public currentF!: Plane3dByOriginAndVectors;\r\n /**\r\n * Constructor.\r\n * * This creates a currentF object to (repeatedly) receive function and derivatives.\r\n */\r\n public constructor() {\r\n this.currentF = Plane3dByOriginAndVectors.createXYPlane();\r\n }\r\n}\r\n\r\n/**\r\n * Implement evaluation steps for newton iteration in 2 dimensions, using caller supplied NewtonEvaluatorRRtoRRD object.\r\n * * Suppose we want to find the roots of `F(u,v) := (x(u,v), y(u,v))`. Writing `X := (u,v)` and `F(X)` as column vectors,\r\n * the 2D Newton's iteration to find a root of `F` is given by:\r\n * `X_{n+1} = X_n - dX = X_n - JInv(X_n)F(X_n)`, where `JInv` is the inverse of the Jacobian matrix `J`, and `J` is\r\n * defined as:\r\n *\r\n * `[dx/du dx/dv]`\r\n *\r\n * `[dy/du dy/dv]`\r\n * @internal\r\n */\r\nexport class Newton2dUnboundedWithDerivative extends AbstractNewtonIterator {\r\n private _func: NewtonEvaluatorRRtoRRD;\r\n /** Current step, or dX = (du, dv). */\r\n private _currentStep: Vector2d;\r\n /** Current uv parameters, or X_n = (u_n, v_n). */\r\n private _currentUV: Point2d;\r\n /**\r\n * Constructor for 2D newton iteration with derivatives.\r\n * @param func function that returns both function value and derivative.\r\n */\r\n public constructor(func: NewtonEvaluatorRRtoRRD) {\r\n super();\r\n this._func = func;\r\n this._currentStep = Vector2d.createZero();\r\n this._currentUV = Point2d.createZero();\r\n }\r\n /** Set the current uv parameters, i.e., `X_n = (u_n, v_n)`. */\r\n public setUV(u: number, v: number): boolean {\r\n this._currentUV.set(u, v);\r\n return true;\r\n }\r\n /** Get the current u parameter of X_n, i.e., u_n. */\r\n public getU(): number {\r\n return this._currentUV.x;\r\n }\r\n /** Get the current v parameter of X_n, i.e., v_n. */\r\n public getV(): number {\r\n return this._currentUV.y;\r\n }\r\n /** Update the current uv parameter by currentStep, i.e., compute `X_{n+1} := X_n - dX = (u_n - du, v_n - dv)`. */\r\n public applyCurrentStep(): boolean {\r\n // print approximations for debug\r\n // console.log(\"(\" + (this._currentUV.x - this._currentStep.x) + \",\" + (this._currentUV.y - this._currentStep.y) + \")\");\r\n return this.setUV(this._currentUV.x - this._currentStep.x, this._currentUV.y - this._currentStep.y);\r\n }\r\n /**\r\n * Evaluate the functions and derivatives at `X_n = (u_n, v_n)`, and solve the Jacobian matrix equation to\r\n * compute `dX = (du, dv)`.\r\n */\r\n public computeStep(): boolean {\r\n if (this._func.evaluate(this._currentUV.x, this._currentUV.y)) {\r\n const fA = this._func.currentF;\r\n if ( // Given X_{n+1} = X_n - dX = X_n - JInv(X_n) F(X_n), we solve J(X_n) dX = F(X_n) for dX:\r\n SmallSystem.linearSystem2d(\r\n fA.vectorU.x, fA.vectorV.x,\r\n fA.vectorU.y, fA.vectorV.y,\r\n fA.origin.x, fA.origin.y,\r\n this._currentStep,\r\n )\r\n )\r\n return true;\r\n }\r\n return false;\r\n }\r\n /**\r\n * Return the current relative step size, i.e., the larger absolute component of `dX / (1 + |X_n|)`\r\n */\r\n public currentStepSize(): number {\r\n return Geometry.maxAbsXY(\r\n this._currentStep.x / (1.0 + Math.abs(this._currentUV.x)),\r\n this._currentStep.y / (1.0 + Math.abs(this._currentUV.y)),\r\n );\r\n }\r\n}\r\n/**\r\n * SimpleNewton has static methods for newton methods with evaluated functions presented as immediate arguments\r\n * (not function object).\r\n * @internal\r\n */\r\nexport class SimpleNewton {\r\n /**\r\n * Run a one-dimensional newton iteration with separate functions for function and derivative.\r\n * * Completion is at 2 (TWO) successive passes at `absoluteTolerance + relTol * abs(x)`, where relTol is\r\n * chosen internally.\r\n * * `absoluteTolerance` is usually aggressively tight -- should come into play only for x near zero.\r\n * * The `relTol` is fluffy (for instance around 1e-11) but in properly converging cases the extra pass after\r\n * first success normally moves to full machine precision.\r\n * * This is an open-loop newton -- it just runs, and returns undefined if anything bad happens.\r\n */\r\n public static runNewton1D(\r\n x: number,\r\n func: (x: number) => number | undefined,\r\n derivative: (x: number) => number | undefined,\r\n absoluteTolerance: number = Geometry.smallFloatingPoint,\r\n ): number | undefined {\r\n let numConverged = 0;\r\n let tolerance: number;\r\n const relTol = 1.0e-11;\r\n for (let iteration = 0; iteration < 20; iteration++) {\r\n const f = func(x);\r\n const df = derivative(x);\r\n if (f !== undefined && df !== undefined) {\r\n const dx = Geometry.conditionalDivideCoordinate(f, df);\r\n if (dx === undefined)\r\n return undefined;\r\n x -= dx;\r\n // console.log(x); // print approximations for debug\r\n tolerance = absoluteTolerance + Math.abs(x) * relTol;\r\n if (Math.abs(dx) < tolerance) {\r\n numConverged++;\r\n if (dx === 0.0 || numConverged > 1) // bypass convergence count on true 0 dx\r\n return x;\r\n } else {\r\n numConverged = 0;\r\n }\r\n }\r\n }\r\n return undefined;\r\n }\r\n}\r\n"]}
@@ -11,22 +11,18 @@ export declare class PascalCoefficients {
11
11
  * * BUT in practice, values 60 create integer entries that are too big for IEEE double.
12
12
  */
13
13
  static getRow(row: number): Float64Array;
14
- /** Return an array with Bezier weighted pascal coefficients
15
- * @param row row index in the pascal triangle. (`row+1` entries)
14
+ /**
15
+ * Return an array with Bezier weighted pascal coefficients
16
+ * @param order output size. The index of the row of the Pascal triangle supplying weights is `order - 1`.
16
17
  * @param u parameter value
17
- * @param result optional destination array.
18
- * @note if the destination array is undefined or too small, a new Float64Array is allocated.
19
- * @note if the destination array is larger than needed, its leading `row+1` values are filled,
20
- * and the array is returned.
18
+ * @param result optional destination array of length `order`. If the destination array is too small, a new Float64Array is allocated.
21
19
  */
22
20
  static getBezierBasisValues(order: number, u: number, result?: Float64Array): Float64Array;
23
- /** Return an array with derivatives of Bezier weighted pascal coefficients
24
- * @param row row index in the pascal triangle. (`row+1` entries)
21
+ /**
22
+ * Return an array with derivatives of Bezier weighted pascal coefficients
23
+ * @param order output size. The index of the row of the Pascal triangle supplying weights is `order - 2`.
25
24
  * @param u parameter value
26
- * @param result optional destination array.
27
- * @note if the destination array is undefined or too small, a new Float64Array is allocated.
28
- * @note if the destination array is larger than needed, its leading `row+1` values are filled,
29
- * and the array is returned.
25
+ * @param result optional destination array of length `order`. If the destination array is too small, a new Float64Array is allocated.
30
26
  */
31
27
  static getBezierBasisDerivatives(order: number, u: number, result?: Float64Array): Float64Array;
32
28
  }
@@ -1 +1 @@
1
- {"version":3,"file":"PascalCoefficients.d.ts","sourceRoot":"","sources":["../../../src/numerics/PascalCoefficients.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAsB;IAC7C;;;;;OAKG;WACW,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY;IA0B/C;;;;;;;OAOG;WACW,oBAAoB,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,YAAY,GAAG,YAAY;IAqBjG;;;;;;;OAOG;WACW,yBAAyB,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,YAAY,GAAG,YAAY;CAYvG"}
1
+ {"version":3,"file":"PascalCoefficients.d.ts","sourceRoot":"","sources":["../../../src/numerics/PascalCoefficients.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAsB;IAC7C;;;;;OAKG;WACW,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY;IA0B/C;;;;;OAKG;WACW,oBAAoB,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,YAAY,GAAG,YAAY;IAqBjG;;;;;OAKG;WACW,yBAAyB,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,YAAY,GAAG,YAAY;CAcvG"}
@@ -41,13 +41,11 @@ class PascalCoefficients {
41
41
  }
42
42
  return allRows[row];
43
43
  }
44
- /** Return an array with Bezier weighted pascal coefficients
45
- * @param row row index in the pascal triangle. (`row+1` entries)
44
+ /**
45
+ * Return an array with Bezier weighted pascal coefficients
46
+ * @param order output size. The index of the row of the Pascal triangle supplying weights is `order - 1`.
46
47
  * @param u parameter value
47
- * @param result optional destination array.
48
- * @note if the destination array is undefined or too small, a new Float64Array is allocated.
49
- * @note if the destination array is larger than needed, its leading `row+1` values are filled,
50
- * and the array is returned.
48
+ * @param result optional destination array of length `order`. If the destination array is too small, a new Float64Array is allocated.
51
49
  */
52
50
  static getBezierBasisValues(order, u, result) {
53
51
  const row = order - 1;
@@ -69,15 +67,15 @@ class PascalCoefficients {
69
67
  }
70
68
  return result;
71
69
  }
72
- /** Return an array with derivatives of Bezier weighted pascal coefficients
73
- * @param row row index in the pascal triangle. (`row+1` entries)
70
+ /**
71
+ * Return an array with derivatives of Bezier weighted pascal coefficients
72
+ * @param order output size. The index of the row of the Pascal triangle supplying weights is `order - 2`.
74
73
  * @param u parameter value
75
- * @param result optional destination array.
76
- * @note if the destination array is undefined or too small, a new Float64Array is allocated.
77
- * @note if the destination array is larger than needed, its leading `row+1` values are filled,
78
- * and the array is returned.
74
+ * @param result optional destination array of length `order`. If the destination array is too small, a new Float64Array is allocated.
79
75
  */
80
76
  static getBezierBasisDerivatives(order, u, result) {
77
+ if (result === undefined || result.length < order)
78
+ result = new Float64Array(order);
81
79
  result = this.getBezierBasisValues(order - 1, u, result);
82
80
  // derivative is df/du = (order-1 ) * sum ( q[i+1] - q[i]) summed on 0 <= i < order - 1.\
83
81
  // evaluate lower order basis, overwrite in place from right to left
@@ -1 +1 @@
1
- {"version":3,"file":"PascalCoefficients.js","sourceRoot":"","sources":["../../../src/numerics/PascalCoefficients.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F;;;GAGG;AACH,MAAa,kBAAkB;IAE7B;;;;;OAKG;IACI,MAAM,CAAC,MAAM,CAAC,GAAW;QAC9B,MAAM,OAAO,GAAG,kBAAkB,CAAC,QAAQ,CAAC;QAC5C,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE;YACxB,uBAAuB;YACvB,OAAO,CAAC,IAAI,CAAC,IAAI,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YACpC,OAAO,CAAC,IAAI,C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AAC,CAAC;SAChB;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;IAED;;;;;;;OAOG;IACI,MAAM,CAAC,yBAAyB,CAAC,KAAa,EAAE,CAAS,EAAE,MAAqB;QACrF,MAAM,GAAG,IAAI,CAAC,oBAAoB,CAAC,KAAK,GAAG,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC;QACzD,2FAA2F;QAC3F,oEAAoE;QACpE,MAAM,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC;QACpB,MAAM,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;QAC1C,KAAK,IAAI,CAAC,GAAG,KAAK,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE;YAClC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;SAC7C;QACD,MAAM,CAAC,CAAC,CAAC,GAAG,CAAE,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;QAC5B,OAAO,MAAM,CAAC;IAChB,CAAC;;AAjFc,2BAAQ,GAAmB,EAAE,CAAC;AADlC,gDAAkB","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 * PascalCoeffients class has static methods which return rows of the PascalTriangle.\r\n * @internal\r\n */\r\nexport class PascalCoefficients {\r\n private static _allRows: Float64Array[] = [];\r\n /**\r\n * * return a row of the pascal table.\r\n * * The contents must not be altered by the user !!!\r\n * * Hypothetically the request row can be any integer.\r\n * * BUT in practice, values 60 create integer entries that are too big for IEEE double.\r\n */\r\n public static getRow(row: number): Float64Array {\r\n const allRows = PascalCoefficients._allRows;\r\n if (allRows.length === 0) {\r\n // seed the table . . .\r\n allRows.push(new Float64Array([1]));\r\n allRows.push(new Float64Array([1, 1]));\r\n allRows.push(new Float64Array([1, 2, 1]));\r\n allRows.push(new Float64Array([1, 3, 3, 1]));\r\n allRows.push(new Float64Array([1, 4, 6, 4, 1]));\r\n allRows.push(new Float64Array([1, 5, 10, 10, 5, 1]));\r\n allRows.push(new Float64Array([1, 6, 15, 20, 15, 6, 1]));\r\n allRows.push(new Float64Array([1, 7, 21, 35, 35, 21, 7, 1]));\r\n }\r\n\r\n while (allRows.length <= row) {\r\n const k = allRows.length;\r\n const oldRow = allRows[k - 1];\r\n const newRow = new Float64Array(k + 1);\r\n newRow[0] = 1.0;\r\n for (let i = 1; i < k; i++)\r\n newRow[i] = oldRow[i - 1] + oldRow[i];\r\n newRow[k] = 1.0;\r\n allRows.push(newRow);\r\n }\r\n return allRows[row];\r\n }\r\n /** Return an array with Bezier weighted pascal coefficients\r\n * @param row row index in the pascal triangle. (`row+1` entries)\r\n * @param u parameter value\r\n * @param result optional destination array.\r\n * @note if the destination array is undefined or too small, a new Float64Array is allocated.\r\n * @note if the destination array is larger than needed, its leading `row+1` values are filled,\r\n * and the array is returned.\r\n */\r\n public static getBezierBasisValues(order: number, u: number, result?: Float64Array): Float64Array {\r\n const row = order - 1;\r\n const pascalRow = PascalCoefficients.getRow(row);\r\n if (result === undefined || result.length < order)\r\n result = new Float64Array(order);\r\n for (let i = 0; i < order; i++)\r\n result[i] = pascalRow[i];\r\n // multiply by increasing powers of u ...\r\n let p = u;\r\n for (let i = 1; i < order; i++ , p *= u) {\r\n result[i] *= p;\r\n }\r\n // multiply by powers of (1-u), working from right\r\n const v = 1.0 - u;\r\n p = v;\r\n for (let i = order - 2; i >= 0; i-- , p *= v) {\r\n result[i] *= p;\r\n }\r\n return result;\r\n }\r\n\r\n /** Return an array with derivatives of Bezier weighted pascal coefficients\r\n * @param row row index in the pascal triangle. (`row+1` entries)\r\n * @param u parameter value\r\n * @param result optional destination array.\r\n * @note if the destination array is undefined or too small, a new Float64Array is allocated.\r\n * @note if the destination array is larger than needed, its leading `row+1` values are filled,\r\n * and the array is returned.\r\n */\r\n public static getBezierBasisDerivatives(order: number, u: number, result?: Float64Array): Float64Array {\r\n result = this.getBezierBasisValues(order - 1, u, result);\r\n // derivative is df/du = (order-1 ) * sum ( q[i+1] - q[i]) summed on 0 <= i < order - 1.\\\r\n // evaluate lower order basis, overwrite in place from right to left\r\n const f = order - 1;\r\n result[order - 1] = f * result[order - 2];\r\n for (let k = order - 2; k > 0; k--) {\r\n result[k] = f * (result[k - 1] - result[k]);\r\n }\r\n result[0] = - f * result[0];\r\n return result;\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"PascalCoefficients.js","sourceRoot":"","sources":["../../../src/numerics/PascalCoefficients.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F;;;GAGG;AACH,MAAa,kBAAkB;IAE7B;;;;;OAKG;IACI,MAAM,CAAC,MAAM,CAAC,GAAW;QAC9B,MAAM,OAAO,GAAG,kBAAkB,CAAC,QAAQ,CAAC;QAC5C,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE;YACxB,uBAAuB;YACvB,OAAO,CAAC,IAAI,CAAC,IAAI,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YACpC,OAAO,CAAC,IAAI,CAAC,IAAI,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;YACvC,OAAO,CAAC,IAAI,CAAC,IAAI,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;YAC1C,OAAO,CAAC,IAAI,CAAC,IAAI,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;YAC7C,OAAO,CAAC,IAAI,CAAC,IAAI,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC,EAA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QACpE,MAAM,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC;QACpB,MAAM,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;QAC1C,KAAK,IAAI,CAAC,GAAG,KAAK,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE;YAClC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;SAC7C;QACD,MAAM,CAAC,CAAC,CAAC,GAAG,CAAE,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;QAC5B,OAAO,MAAM,CAAC;IAChB,CAAC;;AA/Ec,2BAAQ,GAAmB,EAAE,CAAC;AADlC,gDAAkB","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 * PascalCoeffients class has static methods which return rows of the PascalTriangle.\r\n * @internal\r\n */\r\nexport class PascalCoefficients {\r\n private static _allRows: Float64Array[] = [];\r\n /**\r\n * * return a row of the pascal table.\r\n * * The contents must not be altered by the user !!!\r\n * * Hypothetically the request row can be any integer.\r\n * * BUT in practice, values 60 create integer entries that are too big for IEEE double.\r\n */\r\n public static getRow(row: number): Float64Array {\r\n const allRows = PascalCoefficients._allRows;\r\n if (allRows.length === 0) {\r\n // seed the table . . .\r\n allRows.push(new Float64Array([1]));\r\n allRows.push(new Float64Array([1, 1]));\r\n allRows.push(new Float64Array([1, 2, 1]));\r\n allRows.push(new Float64Array([1, 3, 3, 1]));\r\n allRows.push(new Float64Array([1, 4, 6, 4, 1]));\r\n allRows.push(new Float64Array([1, 5, 10, 10, 5, 1]));\r\n allRows.push(new Float64Array([1, 6, 15, 20, 15, 6, 1]));\r\n allRows.push(new Float64Array([1, 7, 21, 35, 35, 21, 7, 1]));\r\n }\r\n\r\n while (allRows.length <= row) {\r\n const k = allRows.length;\r\n const oldRow = allRows[k - 1];\r\n const newRow = new Float64Array(k + 1);\r\n newRow[0] = 1.0;\r\n for (let i = 1; i < k; i++)\r\n newRow[i] = oldRow[i - 1] + oldRow[i];\r\n newRow[k] = 1.0;\r\n allRows.push(newRow);\r\n }\r\n return allRows[row];\r\n }\r\n /**\r\n * Return an array with Bezier weighted pascal coefficients\r\n * @param order output size. The index of the row of the Pascal triangle supplying weights is `order - 1`.\r\n * @param u parameter value\r\n * @param result optional destination array of length `order`. If the destination array is too small, a new Float64Array is allocated.\r\n */\r\n public static getBezierBasisValues(order: number, u: number, result?: Float64Array): Float64Array {\r\n const row = order - 1;\r\n const pascalRow = PascalCoefficients.getRow(row);\r\n if (result === undefined || result.length < order)\r\n result = new Float64Array(order);\r\n for (let i = 0; i < order; i++)\r\n result[i] = pascalRow[i];\r\n // multiply by increasing powers of u ...\r\n let p = u;\r\n for (let i = 1; i < order; i++ , p *= u) {\r\n result[i] *= p;\r\n }\r\n // multiply by powers of (1-u), working from right\r\n const v = 1.0 - u;\r\n p = v;\r\n for (let i = order - 2; i >= 0; i-- , p *= v) {\r\n result[i] *= p;\r\n }\r\n return result;\r\n }\r\n\r\n /**\r\n * Return an array with derivatives of Bezier weighted pascal coefficients\r\n * @param order output size. The index of the row of the Pascal triangle supplying weights is `order - 2`.\r\n * @param u parameter value\r\n * @param result optional destination array of length `order`. If the destination array is too small, a new Float64Array is allocated.\r\n */\r\n public static getBezierBasisDerivatives(order: number, u: number, result?: Float64Array): Float64Array {\r\n if (result === undefined || result.length < order)\r\n result = new Float64Array(order);\r\n result = this.getBezierBasisValues(order - 1, u, result);\r\n // derivative is df/du = (order-1 ) * sum ( q[i+1] - q[i]) summed on 0 <= i < order - 1.\\\r\n // evaluate lower order basis, overwrite in place from right to left\r\n const f = order - 1;\r\n result[order - 1] = f * result[order - 2];\r\n for (let k = order - 2; k > 0; k--) {\r\n result[k] = f * (result[k - 1] - result[k]);\r\n }\r\n result[0] = - f * result[0];\r\n return result;\r\n }\r\n}\r\n"]}
@@ -486,7 +486,7 @@ export declare class SmallSystem {
486
486
  static ray3dXYZUVWClosestApproachUnbounded(ax: number, ay: number, az: number, au: number, av: number, aw: number, bx: number, by: number, bz: number, bu: number, bv: number, bw: number, result: Vector2d): boolean;
487
487
  /**
488
488
  * Solve the pair of linear equations
489
- * * `ux * x + vx + y = cx`
489
+ * * `ux * x + vx * y = cx`
490
490
  * * `uy * x + vy * y = cy`
491
491
  * @param ux xx coefficient
492
492
  * @param vx xy coefficient
@@ -494,7 +494,7 @@ export declare class SmallSystem {
494
494
  * @param vy yy coefficient
495
495
  * @param cx x right hand side
496
496
  * @param cy y right hand side
497
- * @param result (x,y) solution. (MUST be preallocated by caller)
497
+ * @param result (x,y) solution (MUST be preallocated by caller)
498
498
  */
499
499
  static linearSystem2d(ux: number, vx: number, // first row of matrix
500
500
  uy: number, vy: number, // second row of matrix