@itwin/core-geometry 4.3.0-dev.9 → 4.3.1

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 (336) hide show
  1. package/CHANGELOG.md +62 -1
  2. package/lib/cjs/Geometry.d.ts +14 -2
  3. package/lib/cjs/Geometry.d.ts.map +1 -1
  4. package/lib/cjs/Geometry.js +20 -9
  5. package/lib/cjs/Geometry.js.map +1 -1
  6. package/lib/cjs/bspline/BSpline1dNd.d.ts +12 -2
  7. package/lib/cjs/bspline/BSpline1dNd.d.ts.map +1 -1
  8. package/lib/cjs/bspline/BSpline1dNd.js +27 -17
  9. package/lib/cjs/bspline/BSpline1dNd.js.map +1 -1
  10. package/lib/cjs/bspline/BSplineCurve.d.ts +30 -16
  11. package/lib/cjs/bspline/BSplineCurve.d.ts.map +1 -1
  12. package/lib/cjs/bspline/BSplineCurve.js +68 -44
  13. package/lib/cjs/bspline/BSplineCurve.js.map +1 -1
  14. package/lib/cjs/bspline/BSplineCurve3dH.d.ts +27 -20
  15. package/lib/cjs/bspline/BSplineCurve3dH.d.ts.map +1 -1
  16. package/lib/cjs/bspline/BSplineCurve3dH.js +136 -87
  17. package/lib/cjs/bspline/BSplineCurve3dH.js.map +1 -1
  18. package/lib/cjs/bspline/BSplineSurface.d.ts +138 -74
  19. package/lib/cjs/bspline/BSplineSurface.d.ts.map +1 -1
  20. package/lib/cjs/bspline/BSplineSurface.js +242 -119
  21. package/lib/cjs/bspline/BSplineSurface.js.map +1 -1
  22. package/lib/cjs/bspline/Bezier1dNd.d.ts +18 -4
  23. package/lib/cjs/bspline/Bezier1dNd.d.ts.map +1 -1
  24. package/lib/cjs/bspline/Bezier1dNd.js +19 -5
  25. package/lib/cjs/bspline/Bezier1dNd.js.map +1 -1
  26. package/lib/cjs/bspline/BezierCurve3dH.d.ts.map +1 -1
  27. package/lib/cjs/bspline/BezierCurve3dH.js +2 -1
  28. package/lib/cjs/bspline/BezierCurve3dH.js.map +1 -1
  29. package/lib/cjs/bspline/KnotVector.d.ts +30 -33
  30. package/lib/cjs/bspline/KnotVector.d.ts.map +1 -1
  31. package/lib/cjs/bspline/KnotVector.js +76 -69
  32. package/lib/cjs/bspline/KnotVector.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/core-geometry.d.ts +0 -2
  38. package/lib/cjs/core-geometry.d.ts.map +1 -1
  39. package/lib/cjs/core-geometry.js +0 -2
  40. package/lib/cjs/core-geometry.js.map +1 -1
  41. package/lib/cjs/curve/Arc3d.d.ts.map +1 -1
  42. package/lib/cjs/curve/Arc3d.js +5 -5
  43. package/lib/cjs/curve/Arc3d.js.map +1 -1
  44. package/lib/cjs/curve/CurveLocationDetail.d.ts +1 -4
  45. package/lib/cjs/curve/CurveLocationDetail.d.ts.map +1 -1
  46. package/lib/cjs/curve/CurveLocationDetail.js +4 -10
  47. package/lib/cjs/curve/CurveLocationDetail.js.map +1 -1
  48. package/lib/cjs/curve/CurveOps.d.ts +4 -5
  49. package/lib/cjs/curve/CurveOps.d.ts.map +1 -1
  50. package/lib/cjs/curve/CurveOps.js +1 -1
  51. package/lib/cjs/curve/CurveOps.js.map +1 -1
  52. package/lib/cjs/curve/CurveTypes.d.ts +14 -2
  53. package/lib/cjs/curve/CurveTypes.d.ts.map +1 -1
  54. package/lib/cjs/curve/CurveTypes.js.map +1 -1
  55. package/lib/cjs/curve/LineString3d.d.ts +3 -2
  56. package/lib/cjs/curve/LineString3d.d.ts.map +1 -1
  57. package/lib/cjs/curve/LineString3d.js +1 -0
  58. package/lib/cjs/curve/LineString3d.js.map +1 -1
  59. package/lib/cjs/curve/PointString3d.d.ts +2 -1
  60. package/lib/cjs/curve/PointString3d.d.ts.map +1 -1
  61. package/lib/cjs/curve/PointString3d.js.map +1 -1
  62. package/lib/cjs/curve/RegionOps.d.ts +5 -11
  63. package/lib/cjs/curve/RegionOps.d.ts.map +1 -1
  64. package/lib/cjs/curve/RegionOps.js.map +1 -1
  65. package/lib/cjs/curve/internalContexts/CurveCurveCloseApproachXY.d.ts +15 -9
  66. package/lib/cjs/curve/internalContexts/CurveCurveCloseApproachXY.d.ts.map +1 -1
  67. package/lib/cjs/curve/internalContexts/CurveCurveCloseApproachXY.js +68 -56
  68. package/lib/cjs/curve/internalContexts/CurveCurveCloseApproachXY.js.map +1 -1
  69. package/lib/cjs/curve/internalContexts/CurveCurveIntersectXY.d.ts +14 -16
  70. package/lib/cjs/curve/internalContexts/CurveCurveIntersectXY.d.ts.map +1 -1
  71. package/lib/cjs/curve/internalContexts/CurveCurveIntersectXY.js +51 -69
  72. package/lib/cjs/curve/internalContexts/CurveCurveIntersectXY.js.map +1 -1
  73. package/lib/cjs/curve/internalContexts/CurveCurveIntersectXYZ.d.ts.map +1 -1
  74. package/lib/cjs/curve/internalContexts/CurveCurveIntersectXYZ.js +3 -2
  75. package/lib/cjs/curve/internalContexts/CurveCurveIntersectXYZ.js.map +1 -1
  76. package/lib/cjs/curve/internalContexts/MultiChainCollector.d.ts +2 -3
  77. package/lib/cjs/curve/internalContexts/MultiChainCollector.d.ts.map +1 -1
  78. package/lib/cjs/curve/internalContexts/MultiChainCollector.js.map +1 -1
  79. package/lib/cjs/curve/internalContexts/PolygonOffsetContext.d.ts +4 -4
  80. package/lib/cjs/curve/internalContexts/PolygonOffsetContext.d.ts.map +1 -1
  81. package/lib/cjs/curve/internalContexts/PolygonOffsetContext.js +38 -36
  82. package/lib/cjs/curve/internalContexts/PolygonOffsetContext.js.map +1 -1
  83. package/lib/cjs/geometry3d/Angle.d.ts +0 -1
  84. package/lib/cjs/geometry3d/Angle.d.ts.map +1 -1
  85. package/lib/cjs/geometry3d/Angle.js +0 -1
  86. package/lib/cjs/geometry3d/Angle.js.map +1 -1
  87. package/lib/cjs/geometry3d/CoincidentGeometryOps.d.ts +21 -5
  88. package/lib/cjs/geometry3d/CoincidentGeometryOps.d.ts.map +1 -1
  89. package/lib/cjs/geometry3d/CoincidentGeometryOps.js +71 -45
  90. package/lib/cjs/geometry3d/CoincidentGeometryOps.js.map +1 -1
  91. package/lib/cjs/geometry3d/Matrix3d.d.ts +20 -13
  92. package/lib/cjs/geometry3d/Matrix3d.d.ts.map +1 -1
  93. package/lib/cjs/geometry3d/Matrix3d.js +28 -21
  94. package/lib/cjs/geometry3d/Matrix3d.js.map +1 -1
  95. package/lib/cjs/geometry3d/Point3dVector3d.d.ts +11 -2
  96. package/lib/cjs/geometry3d/Point3dVector3d.d.ts.map +1 -1
  97. package/lib/cjs/geometry3d/Point3dVector3d.js +16 -5
  98. package/lib/cjs/geometry3d/Point3dVector3d.js.map +1 -1
  99. package/lib/cjs/geometry3d/PointHelpers.d.ts +58 -20
  100. package/lib/cjs/geometry3d/PointHelpers.d.ts.map +1 -1
  101. package/lib/cjs/geometry3d/PointHelpers.js +213 -62
  102. package/lib/cjs/geometry3d/PointHelpers.js.map +1 -1
  103. package/lib/cjs/geometry3d/Segment1d.d.ts +5 -1
  104. package/lib/cjs/geometry3d/Segment1d.d.ts.map +1 -1
  105. package/lib/cjs/geometry3d/Segment1d.js +11 -7
  106. package/lib/cjs/geometry3d/Segment1d.js.map +1 -1
  107. package/lib/cjs/geometry3d/Transform.d.ts +4 -5
  108. package/lib/cjs/geometry3d/Transform.d.ts.map +1 -1
  109. package/lib/cjs/geometry3d/Transform.js +4 -5
  110. package/lib/cjs/geometry3d/Transform.js.map +1 -1
  111. package/lib/cjs/geometry4d/Point4d.d.ts +13 -0
  112. package/lib/cjs/geometry4d/Point4d.d.ts.map +1 -1
  113. package/lib/cjs/geometry4d/Point4d.js +21 -0
  114. package/lib/cjs/geometry4d/Point4d.js.map +1 -1
  115. package/lib/cjs/numerics/BezierPolynomials.d.ts +88 -64
  116. package/lib/cjs/numerics/BezierPolynomials.d.ts.map +1 -1
  117. package/lib/cjs/numerics/BezierPolynomials.js +92 -73
  118. package/lib/cjs/numerics/BezierPolynomials.js.map +1 -1
  119. package/lib/cjs/numerics/Newton.d.ts +143 -61
  120. package/lib/cjs/numerics/Newton.d.ts.map +1 -1
  121. package/lib/cjs/numerics/Newton.js +233 -66
  122. package/lib/cjs/numerics/Newton.js.map +1 -1
  123. package/lib/cjs/numerics/PascalCoefficients.d.ts +8 -12
  124. package/lib/cjs/numerics/PascalCoefficients.d.ts.map +1 -1
  125. package/lib/cjs/numerics/PascalCoefficients.js +10 -12
  126. package/lib/cjs/numerics/PascalCoefficients.js.map +1 -1
  127. package/lib/cjs/numerics/Polynomials.d.ts +6 -10
  128. package/lib/cjs/numerics/Polynomials.d.ts.map +1 -1
  129. package/lib/cjs/numerics/Polynomials.js +6 -10
  130. package/lib/cjs/numerics/Polynomials.js.map +1 -1
  131. package/lib/cjs/polyface/PolyfaceBuilder.d.ts +3 -0
  132. package/lib/cjs/polyface/PolyfaceBuilder.d.ts.map +1 -1
  133. package/lib/cjs/polyface/PolyfaceBuilder.js +13 -2
  134. package/lib/cjs/polyface/PolyfaceBuilder.js.map +1 -1
  135. package/lib/cjs/polyface/PolyfaceData.d.ts +1 -1
  136. package/lib/cjs/polyface/PolyfaceData.js +1 -1
  137. package/lib/cjs/polyface/PolyfaceData.js.map +1 -1
  138. package/lib/cjs/polyface/PolyfaceQuery.d.ts +38 -11
  139. package/lib/cjs/polyface/PolyfaceQuery.d.ts.map +1 -1
  140. package/lib/cjs/polyface/PolyfaceQuery.js +93 -16
  141. package/lib/cjs/polyface/PolyfaceQuery.js.map +1 -1
  142. package/lib/cjs/serialization/BGFBReader.d.ts +10 -10
  143. package/lib/cjs/serialization/BGFBReader.d.ts.map +1 -1
  144. package/lib/cjs/serialization/BGFBReader.js +69 -42
  145. package/lib/cjs/serialization/BGFBReader.js.map +1 -1
  146. package/lib/cjs/serialization/BGFBWriter.d.ts +8 -8
  147. package/lib/cjs/serialization/BGFBWriter.d.ts.map +1 -1
  148. package/lib/cjs/serialization/BGFBWriter.js +80 -55
  149. package/lib/cjs/serialization/BGFBWriter.js.map +1 -1
  150. package/lib/cjs/serialization/GeometrySamples.d.ts.map +1 -1
  151. package/lib/cjs/serialization/GeometrySamples.js +6 -8
  152. package/lib/cjs/serialization/GeometrySamples.js.map +1 -1
  153. package/lib/cjs/serialization/IModelJsonSchema.d.ts +8 -14
  154. package/lib/cjs/serialization/IModelJsonSchema.d.ts.map +1 -1
  155. package/lib/cjs/serialization/IModelJsonSchema.js +85 -259
  156. package/lib/cjs/serialization/IModelJsonSchema.js.map +1 -1
  157. package/lib/cjs/serialization/SerializationHelpers.d.ts +109 -0
  158. package/lib/cjs/serialization/SerializationHelpers.d.ts.map +1 -0
  159. package/lib/cjs/serialization/SerializationHelpers.js +591 -0
  160. package/lib/cjs/serialization/SerializationHelpers.js.map +1 -0
  161. package/lib/cjs/topology/Graph.d.ts +399 -366
  162. package/lib/cjs/topology/Graph.d.ts.map +1 -1
  163. package/lib/cjs/topology/Graph.js +531 -464
  164. package/lib/cjs/topology/Graph.js.map +1 -1
  165. package/lib/cjs/topology/MaskManager.d.ts +8 -9
  166. package/lib/cjs/topology/MaskManager.d.ts.map +1 -1
  167. package/lib/cjs/topology/MaskManager.js +11 -12
  168. package/lib/cjs/topology/MaskManager.js.map +1 -1
  169. package/lib/esm/Geometry.d.ts +14 -2
  170. package/lib/esm/Geometry.d.ts.map +1 -1
  171. package/lib/esm/Geometry.js +20 -9
  172. package/lib/esm/Geometry.js.map +1 -1
  173. package/lib/esm/bspline/BSpline1dNd.d.ts +12 -2
  174. package/lib/esm/bspline/BSpline1dNd.d.ts.map +1 -1
  175. package/lib/esm/bspline/BSpline1dNd.js +27 -17
  176. package/lib/esm/bspline/BSpline1dNd.js.map +1 -1
  177. package/lib/esm/bspline/BSplineCurve.d.ts +30 -16
  178. package/lib/esm/bspline/BSplineCurve.d.ts.map +1 -1
  179. package/lib/esm/bspline/BSplineCurve.js +68 -44
  180. package/lib/esm/bspline/BSplineCurve.js.map +1 -1
  181. package/lib/esm/bspline/BSplineCurve3dH.d.ts +27 -20
  182. package/lib/esm/bspline/BSplineCurve3dH.d.ts.map +1 -1
  183. package/lib/esm/bspline/BSplineCurve3dH.js +137 -88
  184. package/lib/esm/bspline/BSplineCurve3dH.js.map +1 -1
  185. package/lib/esm/bspline/BSplineSurface.d.ts +138 -74
  186. package/lib/esm/bspline/BSplineSurface.d.ts.map +1 -1
  187. package/lib/esm/bspline/BSplineSurface.js +242 -119
  188. package/lib/esm/bspline/BSplineSurface.js.map +1 -1
  189. package/lib/esm/bspline/Bezier1dNd.d.ts +18 -4
  190. package/lib/esm/bspline/Bezier1dNd.d.ts.map +1 -1
  191. package/lib/esm/bspline/Bezier1dNd.js +19 -5
  192. package/lib/esm/bspline/Bezier1dNd.js.map +1 -1
  193. package/lib/esm/bspline/BezierCurve3dH.d.ts.map +1 -1
  194. package/lib/esm/bspline/BezierCurve3dH.js +2 -1
  195. package/lib/esm/bspline/BezierCurve3dH.js.map +1 -1
  196. package/lib/esm/bspline/KnotVector.d.ts +30 -33
  197. package/lib/esm/bspline/KnotVector.d.ts.map +1 -1
  198. package/lib/esm/bspline/KnotVector.js +76 -69
  199. package/lib/esm/bspline/KnotVector.js.map +1 -1
  200. package/lib/esm/clipping/ClipUtils.d.ts +32 -5
  201. package/lib/esm/clipping/ClipUtils.d.ts.map +1 -1
  202. package/lib/esm/clipping/ClipUtils.js +92 -11
  203. package/lib/esm/clipping/ClipUtils.js.map +1 -1
  204. package/lib/esm/core-geometry.d.ts +0 -2
  205. package/lib/esm/core-geometry.d.ts.map +1 -1
  206. package/lib/esm/core-geometry.js +0 -2
  207. package/lib/esm/core-geometry.js.map +1 -1
  208. package/lib/esm/curve/Arc3d.d.ts.map +1 -1
  209. package/lib/esm/curve/Arc3d.js +5 -5
  210. package/lib/esm/curve/Arc3d.js.map +1 -1
  211. package/lib/esm/curve/CurveLocationDetail.d.ts +1 -4
  212. package/lib/esm/curve/CurveLocationDetail.d.ts.map +1 -1
  213. package/lib/esm/curve/CurveLocationDetail.js +4 -10
  214. package/lib/esm/curve/CurveLocationDetail.js.map +1 -1
  215. package/lib/esm/curve/CurveOps.d.ts +4 -5
  216. package/lib/esm/curve/CurveOps.d.ts.map +1 -1
  217. package/lib/esm/curve/CurveOps.js +1 -1
  218. package/lib/esm/curve/CurveOps.js.map +1 -1
  219. package/lib/esm/curve/CurveTypes.d.ts +14 -2
  220. package/lib/esm/curve/CurveTypes.d.ts.map +1 -1
  221. package/lib/esm/curve/CurveTypes.js.map +1 -1
  222. package/lib/esm/curve/LineString3d.d.ts +3 -2
  223. package/lib/esm/curve/LineString3d.d.ts.map +1 -1
  224. package/lib/esm/curve/LineString3d.js +1 -0
  225. package/lib/esm/curve/LineString3d.js.map +1 -1
  226. package/lib/esm/curve/PointString3d.d.ts +2 -1
  227. package/lib/esm/curve/PointString3d.d.ts.map +1 -1
  228. package/lib/esm/curve/PointString3d.js.map +1 -1
  229. package/lib/esm/curve/RegionOps.d.ts +5 -11
  230. package/lib/esm/curve/RegionOps.d.ts.map +1 -1
  231. package/lib/esm/curve/RegionOps.js.map +1 -1
  232. package/lib/esm/curve/internalContexts/CurveCurveCloseApproachXY.d.ts +15 -9
  233. package/lib/esm/curve/internalContexts/CurveCurveCloseApproachXY.d.ts.map +1 -1
  234. package/lib/esm/curve/internalContexts/CurveCurveCloseApproachXY.js +69 -57
  235. package/lib/esm/curve/internalContexts/CurveCurveCloseApproachXY.js.map +1 -1
  236. package/lib/esm/curve/internalContexts/CurveCurveIntersectXY.d.ts +14 -16
  237. package/lib/esm/curve/internalContexts/CurveCurveIntersectXY.d.ts.map +1 -1
  238. package/lib/esm/curve/internalContexts/CurveCurveIntersectXY.js +51 -68
  239. package/lib/esm/curve/internalContexts/CurveCurveIntersectXY.js.map +1 -1
  240. package/lib/esm/curve/internalContexts/CurveCurveIntersectXYZ.d.ts.map +1 -1
  241. package/lib/esm/curve/internalContexts/CurveCurveIntersectXYZ.js +3 -2
  242. package/lib/esm/curve/internalContexts/CurveCurveIntersectXYZ.js.map +1 -1
  243. package/lib/esm/curve/internalContexts/MultiChainCollector.d.ts +2 -3
  244. package/lib/esm/curve/internalContexts/MultiChainCollector.d.ts.map +1 -1
  245. package/lib/esm/curve/internalContexts/MultiChainCollector.js.map +1 -1
  246. package/lib/esm/curve/internalContexts/PolygonOffsetContext.d.ts +4 -4
  247. package/lib/esm/curve/internalContexts/PolygonOffsetContext.d.ts.map +1 -1
  248. package/lib/esm/curve/internalContexts/PolygonOffsetContext.js +38 -36
  249. package/lib/esm/curve/internalContexts/PolygonOffsetContext.js.map +1 -1
  250. package/lib/esm/geometry3d/Angle.d.ts +0 -1
  251. package/lib/esm/geometry3d/Angle.d.ts.map +1 -1
  252. package/lib/esm/geometry3d/Angle.js +0 -1
  253. package/lib/esm/geometry3d/Angle.js.map +1 -1
  254. package/lib/esm/geometry3d/CoincidentGeometryOps.d.ts +21 -5
  255. package/lib/esm/geometry3d/CoincidentGeometryOps.d.ts.map +1 -1
  256. package/lib/esm/geometry3d/CoincidentGeometryOps.js +71 -45
  257. package/lib/esm/geometry3d/CoincidentGeometryOps.js.map +1 -1
  258. package/lib/esm/geometry3d/Matrix3d.d.ts +20 -13
  259. package/lib/esm/geometry3d/Matrix3d.d.ts.map +1 -1
  260. package/lib/esm/geometry3d/Matrix3d.js +28 -21
  261. package/lib/esm/geometry3d/Matrix3d.js.map +1 -1
  262. package/lib/esm/geometry3d/Point3dVector3d.d.ts +11 -2
  263. package/lib/esm/geometry3d/Point3dVector3d.d.ts.map +1 -1
  264. package/lib/esm/geometry3d/Point3dVector3d.js +16 -5
  265. package/lib/esm/geometry3d/Point3dVector3d.js.map +1 -1
  266. package/lib/esm/geometry3d/PointHelpers.d.ts +58 -20
  267. package/lib/esm/geometry3d/PointHelpers.d.ts.map +1 -1
  268. package/lib/esm/geometry3d/PointHelpers.js +213 -62
  269. package/lib/esm/geometry3d/PointHelpers.js.map +1 -1
  270. package/lib/esm/geometry3d/Segment1d.d.ts +5 -1
  271. package/lib/esm/geometry3d/Segment1d.d.ts.map +1 -1
  272. package/lib/esm/geometry3d/Segment1d.js +11 -7
  273. package/lib/esm/geometry3d/Segment1d.js.map +1 -1
  274. package/lib/esm/geometry3d/Transform.d.ts +4 -5
  275. package/lib/esm/geometry3d/Transform.d.ts.map +1 -1
  276. package/lib/esm/geometry3d/Transform.js +4 -5
  277. package/lib/esm/geometry3d/Transform.js.map +1 -1
  278. package/lib/esm/geometry4d/Point4d.d.ts +13 -0
  279. package/lib/esm/geometry4d/Point4d.d.ts.map +1 -1
  280. package/lib/esm/geometry4d/Point4d.js +21 -0
  281. package/lib/esm/geometry4d/Point4d.js.map +1 -1
  282. package/lib/esm/numerics/BezierPolynomials.d.ts +88 -64
  283. package/lib/esm/numerics/BezierPolynomials.d.ts.map +1 -1
  284. package/lib/esm/numerics/BezierPolynomials.js +92 -73
  285. package/lib/esm/numerics/BezierPolynomials.js.map +1 -1
  286. package/lib/esm/numerics/Newton.d.ts +143 -61
  287. package/lib/esm/numerics/Newton.d.ts.map +1 -1
  288. package/lib/esm/numerics/Newton.js +229 -65
  289. package/lib/esm/numerics/Newton.js.map +1 -1
  290. package/lib/esm/numerics/PascalCoefficients.d.ts +8 -12
  291. package/lib/esm/numerics/PascalCoefficients.d.ts.map +1 -1
  292. package/lib/esm/numerics/PascalCoefficients.js +10 -12
  293. package/lib/esm/numerics/PascalCoefficients.js.map +1 -1
  294. package/lib/esm/numerics/Polynomials.d.ts +6 -10
  295. package/lib/esm/numerics/Polynomials.d.ts.map +1 -1
  296. package/lib/esm/numerics/Polynomials.js +6 -10
  297. package/lib/esm/numerics/Polynomials.js.map +1 -1
  298. package/lib/esm/polyface/PolyfaceBuilder.d.ts +3 -0
  299. package/lib/esm/polyface/PolyfaceBuilder.d.ts.map +1 -1
  300. package/lib/esm/polyface/PolyfaceBuilder.js +13 -2
  301. package/lib/esm/polyface/PolyfaceBuilder.js.map +1 -1
  302. package/lib/esm/polyface/PolyfaceData.d.ts +1 -1
  303. package/lib/esm/polyface/PolyfaceData.js +1 -1
  304. package/lib/esm/polyface/PolyfaceData.js.map +1 -1
  305. package/lib/esm/polyface/PolyfaceQuery.d.ts +38 -11
  306. package/lib/esm/polyface/PolyfaceQuery.d.ts.map +1 -1
  307. package/lib/esm/polyface/PolyfaceQuery.js +93 -16
  308. package/lib/esm/polyface/PolyfaceQuery.js.map +1 -1
  309. package/lib/esm/serialization/BGFBReader.d.ts +10 -10
  310. package/lib/esm/serialization/BGFBReader.d.ts.map +1 -1
  311. package/lib/esm/serialization/BGFBReader.js +69 -42
  312. package/lib/esm/serialization/BGFBReader.js.map +1 -1
  313. package/lib/esm/serialization/BGFBWriter.d.ts +8 -8
  314. package/lib/esm/serialization/BGFBWriter.d.ts.map +1 -1
  315. package/lib/esm/serialization/BGFBWriter.js +80 -55
  316. package/lib/esm/serialization/BGFBWriter.js.map +1 -1
  317. package/lib/esm/serialization/GeometrySamples.d.ts.map +1 -1
  318. package/lib/esm/serialization/GeometrySamples.js +7 -9
  319. package/lib/esm/serialization/GeometrySamples.js.map +1 -1
  320. package/lib/esm/serialization/IModelJsonSchema.d.ts +8 -14
  321. package/lib/esm/serialization/IModelJsonSchema.d.ts.map +1 -1
  322. package/lib/esm/serialization/IModelJsonSchema.js +86 -260
  323. package/lib/esm/serialization/IModelJsonSchema.js.map +1 -1
  324. package/lib/esm/serialization/SerializationHelpers.d.ts +109 -0
  325. package/lib/esm/serialization/SerializationHelpers.d.ts.map +1 -0
  326. package/lib/esm/serialization/SerializationHelpers.js +588 -0
  327. package/lib/esm/serialization/SerializationHelpers.js.map +1 -0
  328. package/lib/esm/topology/Graph.d.ts +399 -366
  329. package/lib/esm/topology/Graph.d.ts.map +1 -1
  330. package/lib/esm/topology/Graph.js +531 -464
  331. package/lib/esm/topology/Graph.js.map +1 -1
  332. package/lib/esm/topology/MaskManager.d.ts +8 -9
  333. package/lib/esm/topology/MaskManager.d.ts.map +1 -1
  334. package/lib/esm/topology/MaskManager.js +11 -12
  335. package/lib/esm/topology/MaskManager.js.map +1 -1
  336. package/package.json +3 -4
@@ -4,36 +4,38 @@
4
4
  * See LICENSE.md in the project root for license terms and full copyright notice.
5
5
  *--------------------------------------------------------------------------------------------*/
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.SimpleNewton = exports.Newton2dUnboundedWithDerivative = exports.NewtonEvaluatorRRtoRRD = exports.Newton1dUnboundedApproximateDerivative = exports.NewtonEvaluatorRtoR = exports.Newton1dUnbounded = exports.NewtonEvaluatorRtoRD = exports.AbstractNewtonIterator = void 0;
7
+ exports.CurveCurveCloseApproachXYRRtoRRD = exports.CurvePointCloseApproachXYRtoRD = exports.CurveCurveIntersectionXYRRToRRD = exports.SimpleNewton = exports.Newton2dUnboundedWithDerivative = exports.NewtonEvaluatorRRtoRRD = exports.Newton1dUnboundedApproximateDerivative = exports.NewtonEvaluatorRtoR = exports.Newton1dUnbounded = exports.NewtonEvaluatorRtoRD = exports.AbstractNewtonIterator = void 0;
8
8
  /** @packageDocumentation
9
9
  * @module Numerics
10
10
  */
11
11
  const Geometry_1 = require("../Geometry");
12
12
  const Plane3dByOriginAndVectors_1 = require("../geometry3d/Plane3dByOriginAndVectors");
13
13
  const Point2dVector2d_1 = require("../geometry3d/Point2dVector2d");
14
+ const Ray3d_1 = require("../geometry3d/Ray3d");
14
15
  const Polynomials_1 = require("./Polynomials");
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
+ // cspell:word currentdFdX XYRR
17
+ /**
18
+ * Base class for Newton iterations in various dimensions.
19
+ * Dimension-specific classes carry all dimension-related data and answer generalized queries from this base class.
19
20
  * @internal
20
21
  */
21
22
  class AbstractNewtonIterator {
22
23
  /**
24
+ * The constructor.
23
25
  * @param stepSizeTarget tolerance to consider a single step converged.
24
- * This number should be "moderately" strict. Because 2 successive convergences are required,
26
+ * This number should be "moderately" strict. Because 2 successive convergences are required,
25
27
  * 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
28
+ * iteration. A well behaved newton would then hypothetically double the number of digits to
29
+ * 20 to 28. Since the IEEE double only carries 16 digits, this second-convergence step will
28
30
  * typically achieve full precision.
29
31
  * @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.
32
+ * @param maxIterations max number of iterations. A typical newton step converges in 3 to 6 iterations.
33
+ * Allow 15 to 20 to catch difficult cases.
32
34
  */
33
35
  constructor(stepSizeTolerance = 1.0e-11, successiveConvergenceTarget = 2, maxIterations = 15) {
34
- /** Number of consecutive steps which passed convergence condition */
36
+ /** Number of consecutive steps which passed convergence condition. */
35
37
  this._numAccepted = 0;
36
- /** number of iterations (incremented at each step) */
38
+ /** Number of iterations (incremented at each step). */
37
39
  this.numIterations = 0;
38
40
  this._stepSizeTolerance = stepSizeTolerance;
39
41
  this._successiveConvergenceTarget = successiveConvergenceTarget;
@@ -41,8 +43,9 @@ class AbstractNewtonIterator {
41
43
  }
42
44
  /**
43
45
  * 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
46
+ * * Convergence is accepted with enough (_successiveConvergenceTarget) small steps (according to _stepSizeTolerance)
47
+ * occur in succession.
48
+ * @param delta step size as reported by currentStepSize.
46
49
  */
47
50
  testConvergence(delta) {
48
51
  if (Math.abs(delta) < this._stepSizeTolerance) {
@@ -55,16 +58,16 @@ class AbstractNewtonIterator {
55
58
  /**
56
59
  * Run iterations, calling various methods from base and derived classes:
57
60
  * * computeStep -- typically evaluate derivatives and solve linear system.
58
- * * currentStepSize -- return numeric measure of the step just computed by computeStep
61
+ * * currentStepSize -- return numeric measure of the step just computed by computeStep.
59
62
  * * testConvergence -- test if the step from currentStepSize (along with recent steps) is converged.
60
- * * applyCurrentStep -- apply the step to the independent variables
63
+ * * applyCurrentStep -- apply the step to the independent variables.
61
64
  */
62
65
  runIterations() {
63
66
  this._numAccepted = 0;
64
67
  this.numIterations = 0;
65
68
  while (this.numIterations++ < this._maxIterations && this.computeStep()) {
66
- if (this.testConvergence(this.currentStepSize())
67
- && this.applyCurrentStep(true)) {
69
+ if (this.testConvergence(this.currentStepSize()) && this.applyCurrentStep(true)) {
70
+ // console.log("iter: " + this.numIterations); // print number of Newton iterations for debug
68
71
  return true;
69
72
  }
70
73
  this.applyCurrentStep(false);
@@ -73,7 +76,8 @@ class AbstractNewtonIterator {
73
76
  }
74
77
  }
75
78
  exports.AbstractNewtonIterator = AbstractNewtonIterator;
76
- /** object to evaluate a newton function. The object must retain most-recent function and derivative
79
+ /**
80
+ * Object to evaluate a newton function. The object must retain most-recent function and derivative
77
81
  * values for immediate query.
78
82
  * @internal
79
83
  */
@@ -82,27 +86,40 @@ class NewtonEvaluatorRtoRD {
82
86
  exports.NewtonEvaluatorRtoRD = NewtonEvaluatorRtoRD;
83
87
  /**
84
88
  * Newton iterator for use when both function and derivative can be evaluated.
89
+ * To solve `f(x) = 0`, the Newton iteration is `x_{n+1} = x_n - dx = x_n - f(x_n)/f'(x_n)`.
90
+ * To solve `f(x) = target` which is equivalent to solving `g(x) = f(x) - target = 0`, the Newton iteration is
91
+ * `x_{n+1} = x_n - dx = x_n - g(x_n)/g'(x_n) = x_n - (f(x_n)-target)/f'(x_n)`.
85
92
  * @internal
86
93
  */
87
94
  class Newton1dUnbounded extends AbstractNewtonIterator {
88
95
  /**
89
- * Constructor for 1D newton iteration with approximate derivatives.
90
- * @param func function that returns both function and derivative.
96
+ * Constructor for 1D newton iteration with derivatives.
97
+ * @param func function that returns both function value and derivative.
91
98
  */
92
99
  constructor(func) {
93
100
  super();
94
101
  this._func = func;
95
102
  this.setTarget(0);
96
103
  }
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); }
105
- /** Compute the univariate newton step. */
104
+ /** Set the independent variable, i.e., x_n. */
105
+ setX(x) {
106
+ this._currentX = x;
107
+ return true;
108
+ }
109
+ /** Get the independent variable, i.e., x_n. */
110
+ getX() {
111
+ return this._currentX;
112
+ }
113
+ /** Set the target function value. */
114
+ setTarget(y) {
115
+ this._target = y;
116
+ }
117
+ /** Move the current X by the just-computed step, i.e., `x_n - dx`. */
118
+ applyCurrentStep() {
119
+ // console.log(this._currentX - this._currentStep); // print approximations for debug
120
+ return this.setX(this._currentX - this._currentStep);
121
+ }
122
+ /** Compute the univariate newton step dx. */
106
123
  computeStep() {
107
124
  if (this._func.evaluate(this._currentX)) {
108
125
  const dx = Geometry_1.Geometry.conditionalDivideFraction(this._func.currentF - this._target, this._func.currentdFdX);
@@ -113,43 +130,56 @@ class Newton1dUnbounded extends AbstractNewtonIterator {
113
130
  }
114
131
  return false;
115
132
  }
116
- /** Return the current step size as a relative number. */
133
+ /** Return the current step size as a relative number, i.e., `|dx / (1 + |x_n|)|`. */
117
134
  currentStepSize() {
118
135
  return Math.abs(this._currentStep / (1.0 + Math.abs(this._currentX)));
119
136
  }
120
137
  }
121
138
  exports.Newton1dUnbounded = Newton1dUnbounded;
122
- /** object to evaluate a newton function (without derivative). The object must retain most-recent function value.
139
+ /**
140
+ * Object to evaluate a newton function (without derivative). The object must retain most-recent function value.
123
141
  * @internal
124
142
  */
125
143
  class NewtonEvaluatorRtoR {
126
144
  }
127
145
  exports.NewtonEvaluatorRtoR = NewtonEvaluatorRtoR;
128
- /** Newton iteration for a univariate function, using approximate derivatives.
146
+ /**
147
+ * Newton iteration for a univariate function, using approximate derivatives.
148
+ * To approximate the derivatives we use a small step `h`, i.e., `f'(x_n) = (f(x_n + h) - f(x_n)) / h`.
149
+ * Therefore, to solve `f(x) = 0`, the iteration is
150
+ * `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
151
  * @internal
130
152
  */
131
153
  class Newton1dUnboundedApproximateDerivative extends AbstractNewtonIterator {
132
154
  /**
133
155
  * Constructor for 1D newton iteration with approximate derivatives.
134
- * @param func function that returns both function and derivative.
156
+ * @param func function that only returns function value (and not derivative).
135
157
  */
136
158
  constructor(func) {
137
159
  super();
138
160
  this._func = func;
139
161
  this.derivativeH = 1.0e-8;
140
162
  }
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. */
163
+ /** Set the independent variable, i.e., x_n. */
164
+ setX(x) {
165
+ this._currentX = x;
166
+ return true;
167
+ }
168
+ /** Get the independent variable, i.e., x_n. */
169
+ getX() {
170
+ return this._currentX;
171
+ }
172
+ /** Move the current X by the just-computed step, i.e., `x_n - dx`. */
173
+ applyCurrentStep() {
174
+ // console.log(this._currentX - this._currentStep); // print approximations for debug
175
+ return this.setX(this._currentX - this._currentStep);
176
+ }
177
+ /** Univariate newton step dx, computed with approximate derivative. */
148
178
  computeStep() {
149
179
  if (this._func.evaluate(this._currentX)) {
150
- const fA = this._func.currentF;
180
+ const fA = this._func.currentF; // f(x_n)
151
181
  if (this._func.evaluate(this._currentX + this.derivativeH)) {
152
- const fB = this._func.currentF;
182
+ const fB = this._func.currentF; // f(x_n + h)
153
183
  const dx = Geometry_1.Geometry.conditionalDivideFraction(fA, (fB - fA) / this.derivativeH);
154
184
  if (dx !== undefined) {
155
185
  this._currentStep = dx;
@@ -159,18 +189,19 @@ class Newton1dUnboundedApproximateDerivative extends AbstractNewtonIterator {
159
189
  }
160
190
  return false;
161
191
  }
162
- /** Return the current step size as a relative number. */
192
+ /** Return the current step size as a relative number, i.e., `|dx / (1 + |x_n|)|`. */
163
193
  currentStepSize() {
164
194
  return Math.abs(this._currentStep / (1.0 + Math.abs(this._currentX)));
165
195
  }
166
196
  }
167
197
  exports.Newton1dUnboundedApproximateDerivative = Newton1dUnboundedApproximateDerivative;
168
- /** object to evaluate a 2-parameter newton function (with derivatives!!).
198
+ /**
199
+ * Object to evaluate a 2-parameter newton function with derivatives.
169
200
  * @internal
170
201
  */
171
202
  class NewtonEvaluatorRRtoRRD {
172
203
  /**
173
- * constructor.
204
+ * Constructor.
174
205
  * * This creates a currentF object to (repeatedly) receive function and derivatives.
175
206
  */
176
207
  constructor() {
@@ -180,36 +211,65 @@ class NewtonEvaluatorRRtoRRD {
180
211
  exports.NewtonEvaluatorRRtoRRD = NewtonEvaluatorRRtoRRD;
181
212
  /**
182
213
  * Implement evaluation steps for newton iteration in 2 dimensions, using caller supplied NewtonEvaluatorRRtoRRD object.
214
+ * * 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,
215
+ * the 2D Newton's iteration to find a root of `F` is given by:
216
+ * `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
217
+ * defined by the partial derivatives of the component functions of F:
218
+ *
219
+ * `[dx/du dx/dv]`
220
+ *
221
+ * `[dy/du dy/dv]`
183
222
  * @internal
184
223
  */
185
224
  class Newton2dUnboundedWithDerivative extends AbstractNewtonIterator {
225
+ /**
226
+ * Constructor for 2D newton iteration with derivatives.
227
+ * @param func function that returns both function value and derivative.
228
+ */
186
229
  constructor(func) {
187
- super();
230
+ const maxIterations = 100; // Was default (15). We observed 49 iters to achieve 1e-11 tol with tangent geometry.
231
+ super(undefined, undefined, maxIterations);
188
232
  this._func = func;
189
233
  this._currentStep = Point2dVector2d_1.Vector2d.createZero();
190
234
  this._currentUV = Point2dVector2d_1.Point2d.createZero();
191
235
  }
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.
236
+ /** Set the current uv parameters, i.e., `X_n = (u_n, v_n)`. */
237
+ setUV(u, v) {
238
+ this._currentUV.set(u, v);
239
+ return true;
240
+ }
241
+ /** Get the current u parameter of X_n, i.e., u_n. */
242
+ getU() {
243
+ return this._currentUV.x;
244
+ }
245
+ /** Get the current v parameter of X_n, i.e., v_n. */
246
+ getV() {
247
+ return this._currentUV.y;
248
+ }
249
+ /** Update the current uv parameter by currentStep, i.e., compute `X_{n+1} := X_n - dX = (u_n - du, v_n - dv)`. */
250
+ applyCurrentStep() {
251
+ // print approximations for debug
252
+ // console.log("(" + (this._currentUV.x - this._currentStep.x) + "," + (this._currentUV.y - this._currentStep.y) + ")");
253
+ return this.setUV(this._currentUV.x - this._currentStep.x, this._currentUV.y - this._currentStep.y);
254
+ }
255
+ /**
256
+ * Evaluate the functions and derivatives at `X_n = (u_n, v_n)`, and solve the Jacobian matrix equation to
257
+ * compute `dX = (du, dv)`.
202
258
  */
203
259
  computeStep() {
204
260
  if (this._func.evaluate(this._currentUV.x, this._currentUV.y)) {
205
261
  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))
262
+ 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:
263
+ Polynomials_1.SmallSystem.linearSystem2d(fA.vectorU.x, fA.vectorV.x, // x_u(X_n), x_v(X_n): 1st row of J evaluated at X_n
264
+ fA.vectorU.y, fA.vectorV.y, // y_u(X_n), y_v(X_n): 2nd row of J evaluated at X_n
265
+ fA.origin.x, fA.origin.y, // F(X_n) := (x(X_n), y(X_n))
266
+ this._currentStep))
207
267
  return true;
208
268
  }
209
269
  return false;
210
270
  }
211
271
  /**
212
- * Return the largest relative step of the x,y, components of the current step.
272
+ * Return the current relative step size, i.e., the larger absolute component of `dX / (1 + |X_n|)`
213
273
  */
214
274
  currentStepSize() {
215
275
  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 +277,18 @@ class Newton2dUnboundedWithDerivative extends AbstractNewtonIterator {
217
277
  }
218
278
  exports.Newton2dUnboundedWithDerivative = Newton2dUnboundedWithDerivative;
219
279
  /**
220
- * SimpleNewton has static methods for newton methods with evaluated functions presented as immediate arguments (not function object)
280
+ * SimpleNewton has static methods for newton methods with evaluated functions presented as immediate arguments
281
+ * (not function object).
221
282
  * @internal
222
283
  */
223
284
  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.
285
+ /**
286
+ * Run a one-dimensional newton iteration with separate functions for function and derivative.
287
+ * * Completion is at 2 (TWO) successive passes at `absoluteTolerance + relTol * abs(x)`, where relTol is
288
+ * chosen internally.
289
+ * * `absoluteTolerance` is usually aggressively tight -- should come into play only for x near zero.
290
+ * * The `relTol` is fluffy (for instance around 1e-11) but in properly converging cases the extra pass after
291
+ * first success normally moves to full machine precision.
229
292
  * * This is an open-loop newton -- it just runs, and returns undefined if anything bad happens.
230
293
  */
231
294
  static runNewton1D(x, func, derivative, absoluteTolerance = Geometry_1.Geometry.smallFloatingPoint) {
@@ -240,10 +303,11 @@ class SimpleNewton {
240
303
  if (dx === undefined)
241
304
  return undefined;
242
305
  x -= dx;
306
+ // console.log(x); // print approximations for debug
243
307
  tolerance = absoluteTolerance + Math.abs(x) * relTol;
244
308
  if (Math.abs(dx) < tolerance) {
245
309
  numConverged++;
246
- if (dx === 0.0 || numConverged > 1) // bypass convergence count on true 0 dx !
310
+ if (dx === 0.0 || numConverged > 1) // bypass convergence count on true 0 dx
247
311
  return x;
248
312
  }
249
313
  else {
@@ -255,4 +319,107 @@ class SimpleNewton {
255
319
  }
256
320
  }
257
321
  exports.SimpleNewton = SimpleNewton;
322
+ /**
323
+ * Class to evaluate XY intersection between 2 curve primitives using the Newton method.
324
+ * @internal
325
+ */
326
+ class CurveCurveIntersectionXYRRToRRD extends NewtonEvaluatorRRtoRRD {
327
+ constructor(curveP, curveQ) {
328
+ super();
329
+ this._curveP = curveP;
330
+ this._curveQ = curveQ;
331
+ this._rayP = Ray3d_1.Ray3d.createZero();
332
+ this._rayQ = Ray3d_1.Ray3d.createZero();
333
+ }
334
+ evaluate(fractionU, fractionV) {
335
+ /**
336
+ * To find an intersection between xy-curves P(u) = (x_p(u), y_p(u)) and Q(v) = (x_q(v), y_q(v)) we should solve
337
+ * F(u,v) := P(u) - Q(v) = (0,0)
338
+ * Using the Newton method we can find the fractions u and v at the intersection via
339
+ * [u_{n+1}] [u_n] [x_p'(u_n) -x_q'(v_n)] [x_p(u_n) - x_q(v_n)]
340
+ * = - Inv( )
341
+ * [v_{n+1}] [v_n] [y_p'(u_n) -y_q'(v_n)] [y_p(u_n) - y_q(v_n)]
342
+ * Note that this is xy intersection so we can ignore z.
343
+ */
344
+ this._curveP.fractionToPointAndDerivative(fractionU, this._rayP);
345
+ this._curveQ.fractionToPointAndDerivative(fractionV, this._rayQ);
346
+ this.currentF.setOriginAndVectorsXYZ(this._rayP.origin.x - this._rayQ.origin.x, this._rayP.origin.y - this._rayQ.origin.y, 0.0, this._rayP.direction.x, this._rayP.direction.y, 0.0, -this._rayQ.direction.x, -this._rayQ.direction.y, 0.0);
347
+ return true;
348
+ }
349
+ }
350
+ exports.CurveCurveIntersectionXYRRToRRD = CurveCurveIntersectionXYRRToRRD;
351
+ /**
352
+ * Class to evaluate XY close approach between a curve primitive and a point using the Newton method.
353
+ * @internal
354
+ */
355
+ class CurvePointCloseApproachXYRtoRD extends NewtonEvaluatorRtoRD {
356
+ constructor(curveP, pointQ) {
357
+ super();
358
+ this._curveP = curveP;
359
+ this._pointQ = pointQ;
360
+ this._planeP = Plane3dByOriginAndVectors_1.Plane3dByOriginAndVectors.createXYPlane();
361
+ }
362
+ evaluate(fractionU) {
363
+ /**
364
+ * To find a close approach between xy-curve P(u) and xy-point q we should solve
365
+ * F(u) := P'(u).(P(u) - q) = 0
366
+ * For a solution u, the segment S(u) := P(u) - q is perpendicular to the curve tangent P'(u), which means S(u) is a close approach.
367
+ * Using the Newton method we can find the fractions u at the close approach location via
368
+ * u_{n+1} = u_n + F(u_n)/F'(u_n) = u_n + [ P'(u_n).S(u_n) ]/[ P''(u_n).S(u_n) + P'(u_n).P'(u_n) ]
369
+ * Note that this is xy close approach so we can ignore z.
370
+ */
371
+ this._curveP.fractionToPointAnd2Derivatives(fractionU, this._planeP);
372
+ const segX = this._planeP.origin.x - this._pointQ.x;
373
+ const segY = this._planeP.origin.y - this._pointQ.y;
374
+ const pDerivX = this._planeP.vectorU.x;
375
+ const pDerivY = this._planeP.vectorU.y;
376
+ const p2DerivX = this._planeP.vectorV.x;
377
+ const p2DerivY = this._planeP.vectorV.y;
378
+ this.currentF = pDerivX * segX + pDerivY * segY;
379
+ this.currentdFdX = p2DerivX * segX + pDerivX * pDerivX + p2DerivY * segY + pDerivY * pDerivY;
380
+ return true;
381
+ }
382
+ }
383
+ exports.CurvePointCloseApproachXYRtoRD = CurvePointCloseApproachXYRtoRD;
384
+ /**
385
+ * Class to evaluate XY close approach between 2 curve primitives using the Newton method.
386
+ * @internal
387
+ */
388
+ class CurveCurveCloseApproachXYRRtoRRD extends NewtonEvaluatorRRtoRRD {
389
+ constructor(curveP, curveQ) {
390
+ super();
391
+ this._curveP = curveP;
392
+ this._curveQ = curveQ;
393
+ this._planeP = Plane3dByOriginAndVectors_1.Plane3dByOriginAndVectors.createXYPlane();
394
+ this._planeQ = Plane3dByOriginAndVectors_1.Plane3dByOriginAndVectors.createXYPlane();
395
+ }
396
+ evaluate(fractionU, fractionV) {
397
+ /**
398
+ * To find a close approach between xy-curves P(u) and Q(v) we should solve
399
+ * F(u,v) := (P'(u).(P(u) - Q(v)), Q'(v).(P(u) - Q(v))) = (0,0)
400
+ * For a solution (u,v), the segment S(u,v) := P(u) - Q(v) is perpendicular to the curve tangents P'(u) and Q'(v),
401
+ * which means S(u,v) is a close approach.
402
+ * Using the Newton method we can find the fractions u and v at the close approach location via
403
+ * [u_{n+1}] [u_n] [P''(u_n).S(u_n,v_n) + P'(u_n).P'(u_n) -P'(u_n).Q'(v_n)] [P'(u_n).S(u_n,v_n)]
404
+ * = - Inv( )
405
+ * [v_{n+1}] [v_n] [Q'(v_n).P'(u_n) Q''(v_n).S(u_n,v_n) - Q'(v_n).Q'(v_n)] [Q'(v_n).S(u_n,v_n)]
406
+ * Note that this is xy close approach so we can ignore z.
407
+ */
408
+ this._curveP.fractionToPointAnd2Derivatives(fractionU, this._planeP);
409
+ this._curveQ.fractionToPointAnd2Derivatives(fractionV, this._planeQ);
410
+ const segX = this._planeP.origin.x - this._planeQ.origin.x;
411
+ const segY = this._planeP.origin.y - this._planeQ.origin.y;
412
+ const pDerivX = this._planeP.vectorU.x;
413
+ const pDerivY = this._planeP.vectorU.y;
414
+ const qDerivX = this._planeQ.vectorU.x;
415
+ const qDerivY = this._planeQ.vectorU.y;
416
+ const p2DerivX = this._planeP.vectorV.x;
417
+ const p2DerivY = this._planeP.vectorV.y;
418
+ const q2DerivX = this._planeQ.vectorV.x;
419
+ const q2DerivY = this._planeQ.vectorV.y;
420
+ this.currentF.setOriginAndVectorsXYZ(pDerivX * segX + pDerivY * segY, qDerivX * segX + qDerivY * segY, 0.0, p2DerivX * segX + p2DerivY * segY + pDerivX * pDerivX + pDerivY * pDerivY, qDerivX * pDerivX + qDerivY * pDerivY, 0.0, -(pDerivX * qDerivX + pDerivY * qDerivY), q2DerivX * segX + q2DerivY * segY - qDerivX * qDerivX - qDerivY * qDerivY, 0.0);
421
+ return true;
422
+ }
423
+ }
424
+ exports.CurveCurveCloseApproachXYRRtoRRD = CurveCurveCloseApproachXYRRtoRRD;
258
425
  //# sourceMappingURL=Newton.js.map
@@ -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,YAA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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;AAEvC,uFAAoF;AACpF,mEAAkE;AAElE,+CAA4C;AAC5C,+CAA4C;AAE5C,+BAA+B;AAE/B;;;;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,KA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AAO,CAAC,CAAC,CAAC;QACvC,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;QACvC,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;QACvC,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;QACxC,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;QACxC,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;QACxC,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;QACxC,IAAI,CAAC,QAAQ,CAAC,sBAAsB,CAClC,OAAO,GAAG,IAAI,GAAG,OAAO,GAAG,IAAI,EAC/B,OAAO,GAAG,IAAI,GAAG,OAAO,GAAG,IAAI,EAC/B,GAAG,EACH,QAAQ,GAAG,IAAI,GAAG,QAAQ,GAAG,IAAI,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,EACzE,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,EACrC,GAAG,EACH,CAAC,CAAC,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,CAAC,EACxC,QAAQ,GAAG,IAAI,GAAG,QAAQ,GAAG,IAAI,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,EACzE,GAAG,CACJ,CAAC;QACF,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAjDD,4EAiDC","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 { CurvePrimitive } from \"../curve/CurvePrimitive\";\r\nimport { Plane3dByOriginAndVectors } from \"../geometry3d/Plane3dByOriginAndVectors\";\r\nimport { Point2d, Vector2d } from \"../geometry3d/Point2dVector2d\";\r\nimport { Point3d } from \"../geometry3d/Point3dVector3d\";\r\nimport { Ray3d } from \"../geometry3d/Ray3d\";\r\nimport { SmallSystem } from \"./Polynomials\";\r\n\r\n// cspell:word currentdFdX XYRR\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 // console.log(\"iter: \" + this.numIterations); // print number of Newton iterations for debug\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 dx. */\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 dx, 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 `F(u,v) := (x(u,v), y(u,v))` the returned plane stores the following evaluations at current value `X := (u,v)`:\r\n * * `origin` = F(X) = (x(X), y(X))\r\n * * `vectorU` = F_u(X) = partial deriv of F wrt u at X = (x_u(X), y_u(X)) = 1st col of Jacobian matrix evaluated at X\r\n * * `vectorV` = F_v(X) = partial deriv of F wrt v at X = (x_v(X), y_v(X)) = 2nd col of Jacobian matrix evaluated at X\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 by the partial derivatives of the component functions of F:\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 const maxIterations = 100; // Was default (15). We observed 49 iters to achieve 1e-11 tol with tangent geometry.\r\n super(undefined, undefined, maxIterations);\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, // x_u(X_n), x_v(X_n): 1st row of J evaluated at X_n\r\n fA.vectorU.y, fA.vectorV.y, // y_u(X_n), y_v(X_n): 2nd row of J evaluated at X_n\r\n fA.origin.x, fA.origin.y, // F(X_n) := (x(X_n), y(X_n))\r\n this._currentStep, // dX\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\r\n/**\r\n * Class to evaluate XY intersection between 2 curve primitives using the Newton method.\r\n * @internal\r\n */\r\nexport class CurveCurveIntersectionXYRRToRRD extends NewtonEvaluatorRRtoRRD {\r\n private _curveP: CurvePrimitive;\r\n private _curveQ: CurvePrimitive;\r\n private _rayP: Ray3d;\r\n private _rayQ: Ray3d;\r\n constructor(curveP: CurvePrimitive, curveQ: CurvePrimitive) {\r\n super();\r\n this._curveP = curveP;\r\n this._curveQ = curveQ;\r\n this._rayP = Ray3d.createZero();\r\n this._rayQ = Ray3d.createZero();\r\n }\r\n public evaluate(fractionU: number, fractionV: number): boolean {\r\n /**\r\n * To find an intersection between xy-curves P(u) = (x_p(u), y_p(u)) and Q(v) = (x_q(v), y_q(v)) we should solve\r\n * F(u,v) := P(u) - Q(v) = (0,0)\r\n * Using the Newton method we can find the fractions u and v at the intersection via\r\n * [u_{n+1}] [u_n] [x_p'(u_n) -x_q'(v_n)] [x_p(u_n) - x_q(v_n)]\r\n * = - Inv( )\r\n * [v_{n+1}] [v_n] [y_p'(u_n) -y_q'(v_n)] [y_p(u_n) - y_q(v_n)]\r\n * Note that this is xy intersection so we can ignore z.\r\n */\r\n this._curveP.fractionToPointAndDerivative(fractionU, this._rayP);\r\n this._curveQ.fractionToPointAndDerivative(fractionV, this._rayQ);\r\n this.currentF.setOriginAndVectorsXYZ(\r\n this._rayP.origin.x - this._rayQ.origin.x, this._rayP.origin.y - this._rayQ.origin.y, 0.0,\r\n this._rayP.direction.x, this._rayP.direction.y, 0.0,\r\n -this._rayQ.direction.x, -this._rayQ.direction.y, 0.0,\r\n );\r\n return true;\r\n }\r\n}\r\n\r\n/**\r\n * Class to evaluate XY close approach between a curve primitive and a point using the Newton method.\r\n * @internal\r\n */\r\nexport class CurvePointCloseApproachXYRtoRD extends NewtonEvaluatorRtoRD {\r\n private _curveP: CurvePrimitive;\r\n private _pointQ: Point3d;\r\n private _planeP: Plane3dByOriginAndVectors;\r\n constructor(curveP: CurvePrimitive, pointQ: Point3d) {\r\n super();\r\n this._curveP = curveP;\r\n this._pointQ = pointQ;\r\n this._planeP = Plane3dByOriginAndVectors.createXYPlane();\r\n }\r\n public evaluate(fractionU: number): boolean {\r\n /**\r\n * To find a close approach between xy-curve P(u) and xy-point q we should solve\r\n * F(u) := P'(u).(P(u) - q) = 0\r\n * For a solution u, the segment S(u) := P(u) - q is perpendicular to the curve tangent P'(u), which means S(u) is a close approach.\r\n * Using the Newton method we can find the fractions u at the close approach location via\r\n * u_{n+1} = u_n + F(u_n)/F'(u_n) = u_n + [ P'(u_n).S(u_n) ]/[ P''(u_n).S(u_n) + P'(u_n).P'(u_n) ]\r\n * Note that this is xy close approach so we can ignore z.\r\n */\r\n this._curveP.fractionToPointAnd2Derivatives(fractionU, this._planeP);\r\n const segX = this._planeP.origin.x - this._pointQ.x;\r\n const segY = this._planeP.origin.y - this._pointQ.y;\r\n const pDerivX = this._planeP.vectorU.x;\r\n const pDerivY = this._planeP.vectorU.y;\r\n const p2DerivX = this._planeP.vectorV.x;\r\n const p2DerivY = this._planeP.vectorV.y;\r\n this.currentF = pDerivX * segX + pDerivY * segY;\r\n this.currentdFdX = p2DerivX * segX + pDerivX * pDerivX + p2DerivY * segY + pDerivY * pDerivY;\r\n return true;\r\n }\r\n}\r\n\r\n/**\r\n * Class to evaluate XY close approach between 2 curve primitives using the Newton method.\r\n * @internal\r\n */\r\nexport class CurveCurveCloseApproachXYRRtoRRD extends NewtonEvaluatorRRtoRRD {\r\n private _curveP: CurvePrimitive;\r\n private _curveQ: CurvePrimitive;\r\n private _planeP: Plane3dByOriginAndVectors;\r\n private _planeQ: Plane3dByOriginAndVectors;\r\n constructor(curveP: CurvePrimitive, curveQ: CurvePrimitive) {\r\n super();\r\n this._curveP = curveP;\r\n this._curveQ = curveQ;\r\n this._planeP = Plane3dByOriginAndVectors.createXYPlane();\r\n this._planeQ = Plane3dByOriginAndVectors.createXYPlane();\r\n }\r\n public evaluate(fractionU: number, fractionV: number): boolean {\r\n /**\r\n * To find a close approach between xy-curves P(u) and Q(v) we should solve\r\n * F(u,v) := (P'(u).(P(u) - Q(v)), Q'(v).(P(u) - Q(v))) = (0,0)\r\n * For a solution (u,v), the segment S(u,v) := P(u) - Q(v) is perpendicular to the curve tangents P'(u) and Q'(v),\r\n * which means S(u,v) is a close approach.\r\n * Using the Newton method we can find the fractions u and v at the close approach location via\r\n * [u_{n+1}] [u_n] [P''(u_n).S(u_n,v_n) + P'(u_n).P'(u_n) -P'(u_n).Q'(v_n)] [P'(u_n).S(u_n,v_n)]\r\n * = - Inv( )\r\n * [v_{n+1}] [v_n] [Q'(v_n).P'(u_n) Q''(v_n).S(u_n,v_n) - Q'(v_n).Q'(v_n)] [Q'(v_n).S(u_n,v_n)]\r\n * Note that this is xy close approach so we can ignore z.\r\n */\r\n this._curveP.fractionToPointAnd2Derivatives(fractionU, this._planeP);\r\n this._curveQ.fractionToPointAnd2Derivatives(fractionV, this._planeQ);\r\n const segX = this._planeP.origin.x - this._planeQ.origin.x;\r\n const segY = this._planeP.origin.y - this._planeQ.origin.y;\r\n const pDerivX = this._planeP.vectorU.x;\r\n const pDerivY = this._planeP.vectorU.y;\r\n const qDerivX = this._planeQ.vectorU.x;\r\n const qDerivY = this._planeQ.vectorU.y;\r\n const p2DerivX = this._planeP.vectorV.x;\r\n const p2DerivY = this._planeP.vectorV.y;\r\n const q2DerivX = this._planeQ.vectorV.x;\r\n const q2DerivY = this._planeQ.vectorV.y;\r\n this.currentF.setOriginAndVectorsXYZ(\r\n pDerivX * segX + pDerivY * segY,\r\n qDerivX * segX + qDerivY * segY,\r\n 0.0,\r\n p2DerivX * segX + p2DerivY * segY + pDerivX * pDerivX + pDerivY * pDerivY,\r\n qDerivX * pDerivX + qDerivY * pDerivY,\r\n 0.0,\r\n -(pDerivX * qDerivX + pDerivY * qDerivY),\r\n q2DerivX * segX + q2DerivY * segY - qDerivX * qDerivX - qDerivY * qDerivY,\r\n 0.0,\r\n );\r\n return true;\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"}