@itwin/core-geometry 4.3.0-dev.2 → 4.3.0-dev.21
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.
- package/CHANGELOG.md +41 -1
- package/lib/cjs/Geometry.d.ts.map +1 -1
- package/lib/cjs/Geometry.js +2 -4
- package/lib/cjs/Geometry.js.map +1 -1
- package/lib/cjs/bspline/BSpline1dNd.d.ts +12 -2
- package/lib/cjs/bspline/BSpline1dNd.d.ts.map +1 -1
- package/lib/cjs/bspline/BSpline1dNd.js +27 -17
- package/lib/cjs/bspline/BSpline1dNd.js.map +1 -1
- package/lib/cjs/bspline/BSplineCurve.d.ts +30 -16
- package/lib/cjs/bspline/BSplineCurve.d.ts.map +1 -1
- package/lib/cjs/bspline/BSplineCurve.js +68 -44
- package/lib/cjs/bspline/BSplineCurve.js.map +1 -1
- package/lib/cjs/bspline/BSplineCurve3dH.d.ts +27 -20
- package/lib/cjs/bspline/BSplineCurve3dH.d.ts.map +1 -1
- package/lib/cjs/bspline/BSplineCurve3dH.js +136 -87
- package/lib/cjs/bspline/BSplineCurve3dH.js.map +1 -1
- package/lib/cjs/bspline/BSplineSurface.d.ts +138 -74
- package/lib/cjs/bspline/BSplineSurface.d.ts.map +1 -1
- package/lib/cjs/bspline/BSplineSurface.js +242 -119
- package/lib/cjs/bspline/BSplineSurface.js.map +1 -1
- package/lib/cjs/bspline/Bezier1dNd.d.ts +18 -4
- package/lib/cjs/bspline/Bezier1dNd.d.ts.map +1 -1
- package/lib/cjs/bspline/Bezier1dNd.js +19 -5
- package/lib/cjs/bspline/Bezier1dNd.js.map +1 -1
- package/lib/cjs/bspline/BezierCurve3dH.d.ts.map +1 -1
- package/lib/cjs/bspline/BezierCurve3dH.js +2 -1
- package/lib/cjs/bspline/BezierCurve3dH.js.map +1 -1
- package/lib/cjs/bspline/KnotVector.d.ts +30 -33
- package/lib/cjs/bspline/KnotVector.d.ts.map +1 -1
- package/lib/cjs/bspline/KnotVector.js +76 -69
- package/lib/cjs/bspline/KnotVector.js.map +1 -1
- package/lib/cjs/clipping/AlternatingConvexClipTree.js.map +1 -1
- package/lib/cjs/clipping/ClipUtils.d.ts +32 -5
- package/lib/cjs/clipping/ClipUtils.d.ts.map +1 -1
- package/lib/cjs/clipping/ClipUtils.js +92 -11
- package/lib/cjs/clipping/ClipUtils.js.map +1 -1
- package/lib/cjs/curve/CurveChainWithDistanceIndex.d.ts +18 -1
- package/lib/cjs/curve/CurveChainWithDistanceIndex.d.ts.map +1 -1
- package/lib/cjs/curve/CurveChainWithDistanceIndex.js +47 -0
- package/lib/cjs/curve/CurveChainWithDistanceIndex.js.map +1 -1
- package/lib/cjs/curve/CurveCollection.d.ts +9 -9
- package/lib/cjs/curve/CurveCollection.d.ts.map +1 -1
- package/lib/cjs/curve/CurveCollection.js +7 -10
- package/lib/cjs/curve/CurveCollection.js.map +1 -1
- package/lib/cjs/curve/CurveCurve.d.ts +2 -2
- package/lib/cjs/curve/CurveCurve.d.ts.map +1 -1
- package/lib/cjs/curve/CurveCurve.js +3 -16
- package/lib/cjs/curve/CurveCurve.js.map +1 -1
- package/lib/cjs/curve/CurveLocationDetail.d.ts +17 -4
- package/lib/cjs/curve/CurveLocationDetail.d.ts.map +1 -1
- package/lib/cjs/curve/CurveLocationDetail.js +32 -10
- package/lib/cjs/curve/CurveLocationDetail.js.map +1 -1
- package/lib/cjs/curve/CurveOps.d.ts +4 -5
- package/lib/cjs/curve/CurveOps.d.ts.map +1 -1
- package/lib/cjs/curve/CurveOps.js +1 -1
- package/lib/cjs/curve/CurveOps.js.map +1 -1
- package/lib/cjs/curve/CurveTypes.d.ts +14 -2
- package/lib/cjs/curve/CurveTypes.d.ts.map +1 -1
- package/lib/cjs/curve/CurveTypes.js.map +1 -1
- package/lib/cjs/curve/CurveWireMomentsXYZ.d.ts.map +1 -1
- package/lib/cjs/curve/CurveWireMomentsXYZ.js +2 -4
- package/lib/cjs/curve/CurveWireMomentsXYZ.js.map +1 -1
- package/lib/cjs/curve/LineString3d.d.ts +3 -6
- package/lib/cjs/curve/LineString3d.d.ts.map +1 -1
- package/lib/cjs/curve/LineString3d.js +1 -4
- package/lib/cjs/curve/LineString3d.js.map +1 -1
- package/lib/cjs/curve/PointString3d.d.ts +2 -1
- package/lib/cjs/curve/PointString3d.d.ts.map +1 -1
- package/lib/cjs/curve/PointString3d.js.map +1 -1
- package/lib/cjs/curve/RegionOps.d.ts +7 -12
- package/lib/cjs/curve/RegionOps.d.ts.map +1 -1
- package/lib/cjs/curve/RegionOps.js +2 -1
- package/lib/cjs/curve/RegionOps.js.map +1 -1
- package/lib/cjs/curve/internalContexts/CurveCurveCloseApproachXY.d.ts +0 -9
- package/lib/cjs/curve/internalContexts/CurveCurveCloseApproachXY.d.ts.map +1 -1
- package/lib/cjs/curve/internalContexts/CurveCurveCloseApproachXY.js +16 -35
- package/lib/cjs/curve/internalContexts/CurveCurveCloseApproachXY.js.map +1 -1
- package/lib/cjs/curve/internalContexts/CurveCurveIntersectXY.d.ts +12 -6
- package/lib/cjs/curve/internalContexts/CurveCurveIntersectXY.d.ts.map +1 -1
- package/lib/cjs/curve/internalContexts/CurveCurveIntersectXY.js +80 -18
- package/lib/cjs/curve/internalContexts/CurveCurveIntersectXY.js.map +1 -1
- package/lib/cjs/curve/internalContexts/CurveCurveIntersectXYZ.d.ts +11 -5
- package/lib/cjs/curve/internalContexts/CurveCurveIntersectXYZ.d.ts.map +1 -1
- package/lib/cjs/curve/internalContexts/CurveCurveIntersectXYZ.js +73 -8
- package/lib/cjs/curve/internalContexts/CurveCurveIntersectXYZ.js.map +1 -1
- package/lib/cjs/curve/internalContexts/MultiChainCollector.d.ts +2 -3
- package/lib/cjs/curve/internalContexts/MultiChainCollector.d.ts.map +1 -1
- package/lib/cjs/curve/internalContexts/MultiChainCollector.js +2 -3
- package/lib/cjs/curve/internalContexts/MultiChainCollector.js.map +1 -1
- package/lib/cjs/curve/internalContexts/PolygonOffsetContext.d.ts +4 -4
- package/lib/cjs/curve/internalContexts/PolygonOffsetContext.d.ts.map +1 -1
- package/lib/cjs/curve/internalContexts/PolygonOffsetContext.js +38 -36
- package/lib/cjs/curve/internalContexts/PolygonOffsetContext.js.map +1 -1
- package/lib/cjs/geometry3d/CoincidentGeometryOps.d.ts +21 -5
- package/lib/cjs/geometry3d/CoincidentGeometryOps.d.ts.map +1 -1
- package/lib/cjs/geometry3d/CoincidentGeometryOps.js +71 -45
- package/lib/cjs/geometry3d/CoincidentGeometryOps.js.map +1 -1
- package/lib/cjs/geometry3d/Matrix3d.d.ts +20 -13
- package/lib/cjs/geometry3d/Matrix3d.d.ts.map +1 -1
- package/lib/cjs/geometry3d/Matrix3d.js +28 -21
- package/lib/cjs/geometry3d/Matrix3d.js.map +1 -1
- package/lib/cjs/geometry3d/Point3dVector3d.d.ts +11 -2
- package/lib/cjs/geometry3d/Point3dVector3d.d.ts.map +1 -1
- package/lib/cjs/geometry3d/Point3dVector3d.js +16 -5
- package/lib/cjs/geometry3d/Point3dVector3d.js.map +1 -1
- package/lib/cjs/geometry3d/PointHelpers.d.ts +58 -20
- package/lib/cjs/geometry3d/PointHelpers.d.ts.map +1 -1
- package/lib/cjs/geometry3d/PointHelpers.js +213 -62
- package/lib/cjs/geometry3d/PointHelpers.js.map +1 -1
- package/lib/cjs/geometry3d/Segment1d.d.ts +5 -1
- package/lib/cjs/geometry3d/Segment1d.d.ts.map +1 -1
- package/lib/cjs/geometry3d/Segment1d.js +11 -7
- package/lib/cjs/geometry3d/Segment1d.js.map +1 -1
- package/lib/cjs/geometry3d/Transform.d.ts +2 -3
- package/lib/cjs/geometry3d/Transform.d.ts.map +1 -1
- package/lib/cjs/geometry3d/Transform.js +2 -3
- package/lib/cjs/geometry3d/Transform.js.map +1 -1
- package/lib/cjs/geometry4d/Point4d.d.ts +14 -1
- package/lib/cjs/geometry4d/Point4d.d.ts.map +1 -1
- package/lib/cjs/geometry4d/Point4d.js +22 -1
- package/lib/cjs/geometry4d/Point4d.js.map +1 -1
- package/lib/cjs/numerics/BezierPolynomials.d.ts +91 -68
- package/lib/cjs/numerics/BezierPolynomials.d.ts.map +1 -1
- package/lib/cjs/numerics/BezierPolynomials.js +100 -79
- package/lib/cjs/numerics/BezierPolynomials.js.map +1 -1
- package/lib/cjs/numerics/Newton.d.ts +115 -60
- package/lib/cjs/numerics/Newton.d.ts.map +1 -1
- package/lib/cjs/numerics/Newton.js +120 -62
- package/lib/cjs/numerics/Newton.js.map +1 -1
- package/lib/cjs/numerics/PascalCoefficients.d.ts +8 -12
- package/lib/cjs/numerics/PascalCoefficients.d.ts.map +1 -1
- package/lib/cjs/numerics/PascalCoefficients.js +10 -12
- package/lib/cjs/numerics/PascalCoefficients.js.map +1 -1
- package/lib/cjs/numerics/Polynomials.d.ts +2 -2
- package/lib/cjs/numerics/Polynomials.d.ts.map +1 -1
- package/lib/cjs/numerics/Polynomials.js +2 -2
- package/lib/cjs/numerics/Polynomials.js.map +1 -1
- package/lib/cjs/polyface/PolyfaceBuilder.d.ts +3 -0
- package/lib/cjs/polyface/PolyfaceBuilder.d.ts.map +1 -1
- package/lib/cjs/polyface/PolyfaceBuilder.js +13 -2
- package/lib/cjs/polyface/PolyfaceBuilder.js.map +1 -1
- package/lib/cjs/polyface/PolyfaceClip.d.ts +1 -1
- package/lib/cjs/polyface/PolyfaceClip.d.ts.map +1 -1
- package/lib/cjs/polyface/PolyfaceClip.js +6 -3
- package/lib/cjs/polyface/PolyfaceClip.js.map +1 -1
- package/lib/cjs/polyface/PolyfaceData.d.ts +1 -1
- package/lib/cjs/polyface/PolyfaceData.js +1 -1
- package/lib/cjs/polyface/PolyfaceData.js.map +1 -1
- package/lib/cjs/polyface/PolyfaceQuery.d.ts +39 -12
- package/lib/cjs/polyface/PolyfaceQuery.d.ts.map +1 -1
- package/lib/cjs/polyface/PolyfaceQuery.js +94 -17
- package/lib/cjs/polyface/PolyfaceQuery.js.map +1 -1
- package/lib/cjs/serialization/BGFBReader.d.ts +10 -10
- package/lib/cjs/serialization/BGFBReader.d.ts.map +1 -1
- package/lib/cjs/serialization/BGFBReader.js +69 -42
- package/lib/cjs/serialization/BGFBReader.js.map +1 -1
- package/lib/cjs/serialization/BGFBWriter.d.ts +8 -8
- package/lib/cjs/serialization/BGFBWriter.d.ts.map +1 -1
- package/lib/cjs/serialization/BGFBWriter.js +80 -55
- package/lib/cjs/serialization/BGFBWriter.js.map +1 -1
- package/lib/cjs/serialization/GeometrySamples.d.ts.map +1 -1
- package/lib/cjs/serialization/GeometrySamples.js +6 -8
- package/lib/cjs/serialization/GeometrySamples.js.map +1 -1
- package/lib/cjs/serialization/IModelJsonSchema.d.ts +8 -14
- package/lib/cjs/serialization/IModelJsonSchema.d.ts.map +1 -1
- package/lib/cjs/serialization/IModelJsonSchema.js +85 -259
- package/lib/cjs/serialization/IModelJsonSchema.js.map +1 -1
- package/lib/cjs/serialization/SerializationHelpers.d.ts +109 -0
- package/lib/cjs/serialization/SerializationHelpers.d.ts.map +1 -0
- package/lib/cjs/serialization/SerializationHelpers.js +591 -0
- package/lib/cjs/serialization/SerializationHelpers.js.map +1 -0
- package/lib/cjs/solid/SweepContour.d.ts +4 -2
- package/lib/cjs/solid/SweepContour.d.ts.map +1 -1
- package/lib/cjs/solid/SweepContour.js +4 -2
- package/lib/cjs/solid/SweepContour.js.map +1 -1
- package/lib/esm/Geometry.d.ts.map +1 -1
- package/lib/esm/Geometry.js +2 -4
- package/lib/esm/Geometry.js.map +1 -1
- package/lib/esm/bspline/BSpline1dNd.d.ts +12 -2
- package/lib/esm/bspline/BSpline1dNd.d.ts.map +1 -1
- package/lib/esm/bspline/BSpline1dNd.js +27 -17
- package/lib/esm/bspline/BSpline1dNd.js.map +1 -1
- package/lib/esm/bspline/BSplineCurve.d.ts +30 -16
- package/lib/esm/bspline/BSplineCurve.d.ts.map +1 -1
- package/lib/esm/bspline/BSplineCurve.js +68 -44
- package/lib/esm/bspline/BSplineCurve.js.map +1 -1
- package/lib/esm/bspline/BSplineCurve3dH.d.ts +27 -20
- package/lib/esm/bspline/BSplineCurve3dH.d.ts.map +1 -1
- package/lib/esm/bspline/BSplineCurve3dH.js +137 -88
- package/lib/esm/bspline/BSplineCurve3dH.js.map +1 -1
- package/lib/esm/bspline/BSplineSurface.d.ts +138 -74
- package/lib/esm/bspline/BSplineSurface.d.ts.map +1 -1
- package/lib/esm/bspline/BSplineSurface.js +242 -119
- package/lib/esm/bspline/BSplineSurface.js.map +1 -1
- package/lib/esm/bspline/Bezier1dNd.d.ts +18 -4
- package/lib/esm/bspline/Bezier1dNd.d.ts.map +1 -1
- package/lib/esm/bspline/Bezier1dNd.js +19 -5
- package/lib/esm/bspline/Bezier1dNd.js.map +1 -1
- package/lib/esm/bspline/BezierCurve3dH.d.ts.map +1 -1
- package/lib/esm/bspline/BezierCurve3dH.js +2 -1
- package/lib/esm/bspline/BezierCurve3dH.js.map +1 -1
- package/lib/esm/bspline/KnotVector.d.ts +30 -33
- package/lib/esm/bspline/KnotVector.d.ts.map +1 -1
- package/lib/esm/bspline/KnotVector.js +76 -69
- package/lib/esm/bspline/KnotVector.js.map +1 -1
- package/lib/esm/clipping/AlternatingConvexClipTree.js.map +1 -1
- package/lib/esm/clipping/ClipUtils.d.ts +32 -5
- package/lib/esm/clipping/ClipUtils.d.ts.map +1 -1
- package/lib/esm/clipping/ClipUtils.js +92 -11
- package/lib/esm/clipping/ClipUtils.js.map +1 -1
- package/lib/esm/curve/CurveChainWithDistanceIndex.d.ts +18 -1
- package/lib/esm/curve/CurveChainWithDistanceIndex.d.ts.map +1 -1
- package/lib/esm/curve/CurveChainWithDistanceIndex.js +48 -1
- package/lib/esm/curve/CurveChainWithDistanceIndex.js.map +1 -1
- package/lib/esm/curve/CurveCollection.d.ts +9 -9
- package/lib/esm/curve/CurveCollection.d.ts.map +1 -1
- package/lib/esm/curve/CurveCollection.js +7 -10
- package/lib/esm/curve/CurveCollection.js.map +1 -1
- package/lib/esm/curve/CurveCurve.d.ts +2 -2
- package/lib/esm/curve/CurveCurve.d.ts.map +1 -1
- package/lib/esm/curve/CurveCurve.js +3 -16
- package/lib/esm/curve/CurveCurve.js.map +1 -1
- package/lib/esm/curve/CurveLocationDetail.d.ts +17 -4
- package/lib/esm/curve/CurveLocationDetail.d.ts.map +1 -1
- package/lib/esm/curve/CurveLocationDetail.js +32 -10
- package/lib/esm/curve/CurveLocationDetail.js.map +1 -1
- package/lib/esm/curve/CurveOps.d.ts +4 -5
- package/lib/esm/curve/CurveOps.d.ts.map +1 -1
- package/lib/esm/curve/CurveOps.js +1 -1
- package/lib/esm/curve/CurveOps.js.map +1 -1
- package/lib/esm/curve/CurveTypes.d.ts +14 -2
- package/lib/esm/curve/CurveTypes.d.ts.map +1 -1
- package/lib/esm/curve/CurveTypes.js.map +1 -1
- package/lib/esm/curve/CurveWireMomentsXYZ.d.ts.map +1 -1
- package/lib/esm/curve/CurveWireMomentsXYZ.js +2 -4
- package/lib/esm/curve/CurveWireMomentsXYZ.js.map +1 -1
- package/lib/esm/curve/LineString3d.d.ts +3 -6
- package/lib/esm/curve/LineString3d.d.ts.map +1 -1
- package/lib/esm/curve/LineString3d.js +1 -4
- package/lib/esm/curve/LineString3d.js.map +1 -1
- package/lib/esm/curve/PointString3d.d.ts +2 -1
- package/lib/esm/curve/PointString3d.d.ts.map +1 -1
- package/lib/esm/curve/PointString3d.js.map +1 -1
- package/lib/esm/curve/RegionOps.d.ts +7 -12
- package/lib/esm/curve/RegionOps.d.ts.map +1 -1
- package/lib/esm/curve/RegionOps.js +2 -1
- package/lib/esm/curve/RegionOps.js.map +1 -1
- package/lib/esm/curve/internalContexts/CurveCurveCloseApproachXY.d.ts +0 -9
- package/lib/esm/curve/internalContexts/CurveCurveCloseApproachXY.d.ts.map +1 -1
- package/lib/esm/curve/internalContexts/CurveCurveCloseApproachXY.js +16 -35
- package/lib/esm/curve/internalContexts/CurveCurveCloseApproachXY.js.map +1 -1
- package/lib/esm/curve/internalContexts/CurveCurveIntersectXY.d.ts +12 -6
- package/lib/esm/curve/internalContexts/CurveCurveIntersectXY.d.ts.map +1 -1
- package/lib/esm/curve/internalContexts/CurveCurveIntersectXY.js +81 -19
- package/lib/esm/curve/internalContexts/CurveCurveIntersectXY.js.map +1 -1
- package/lib/esm/curve/internalContexts/CurveCurveIntersectXYZ.d.ts +11 -5
- package/lib/esm/curve/internalContexts/CurveCurveIntersectXYZ.d.ts.map +1 -1
- package/lib/esm/curve/internalContexts/CurveCurveIntersectXYZ.js +74 -9
- package/lib/esm/curve/internalContexts/CurveCurveIntersectXYZ.js.map +1 -1
- package/lib/esm/curve/internalContexts/MultiChainCollector.d.ts +2 -3
- package/lib/esm/curve/internalContexts/MultiChainCollector.d.ts.map +1 -1
- package/lib/esm/curve/internalContexts/MultiChainCollector.js +2 -3
- package/lib/esm/curve/internalContexts/MultiChainCollector.js.map +1 -1
- package/lib/esm/curve/internalContexts/PolygonOffsetContext.d.ts +4 -4
- package/lib/esm/curve/internalContexts/PolygonOffsetContext.d.ts.map +1 -1
- package/lib/esm/curve/internalContexts/PolygonOffsetContext.js +38 -36
- package/lib/esm/curve/internalContexts/PolygonOffsetContext.js.map +1 -1
- package/lib/esm/geometry3d/CoincidentGeometryOps.d.ts +21 -5
- package/lib/esm/geometry3d/CoincidentGeometryOps.d.ts.map +1 -1
- package/lib/esm/geometry3d/CoincidentGeometryOps.js +71 -45
- package/lib/esm/geometry3d/CoincidentGeometryOps.js.map +1 -1
- package/lib/esm/geometry3d/Matrix3d.d.ts +20 -13
- package/lib/esm/geometry3d/Matrix3d.d.ts.map +1 -1
- package/lib/esm/geometry3d/Matrix3d.js +28 -21
- package/lib/esm/geometry3d/Matrix3d.js.map +1 -1
- package/lib/esm/geometry3d/Point3dVector3d.d.ts +11 -2
- package/lib/esm/geometry3d/Point3dVector3d.d.ts.map +1 -1
- package/lib/esm/geometry3d/Point3dVector3d.js +16 -5
- package/lib/esm/geometry3d/Point3dVector3d.js.map +1 -1
- package/lib/esm/geometry3d/PointHelpers.d.ts +58 -20
- package/lib/esm/geometry3d/PointHelpers.d.ts.map +1 -1
- package/lib/esm/geometry3d/PointHelpers.js +213 -62
- package/lib/esm/geometry3d/PointHelpers.js.map +1 -1
- package/lib/esm/geometry3d/Segment1d.d.ts +5 -1
- package/lib/esm/geometry3d/Segment1d.d.ts.map +1 -1
- package/lib/esm/geometry3d/Segment1d.js +11 -7
- package/lib/esm/geometry3d/Segment1d.js.map +1 -1
- package/lib/esm/geometry3d/Transform.d.ts +2 -3
- package/lib/esm/geometry3d/Transform.d.ts.map +1 -1
- package/lib/esm/geometry3d/Transform.js +2 -3
- package/lib/esm/geometry3d/Transform.js.map +1 -1
- package/lib/esm/geometry4d/Point4d.d.ts +14 -1
- package/lib/esm/geometry4d/Point4d.d.ts.map +1 -1
- package/lib/esm/geometry4d/Point4d.js +22 -1
- package/lib/esm/geometry4d/Point4d.js.map +1 -1
- package/lib/esm/numerics/BezierPolynomials.d.ts +91 -68
- package/lib/esm/numerics/BezierPolynomials.d.ts.map +1 -1
- package/lib/esm/numerics/BezierPolynomials.js +100 -79
- package/lib/esm/numerics/BezierPolynomials.js.map +1 -1
- package/lib/esm/numerics/Newton.d.ts +115 -60
- package/lib/esm/numerics/Newton.d.ts.map +1 -1
- package/lib/esm/numerics/Newton.js +120 -62
- package/lib/esm/numerics/Newton.js.map +1 -1
- package/lib/esm/numerics/PascalCoefficients.d.ts +8 -12
- package/lib/esm/numerics/PascalCoefficients.d.ts.map +1 -1
- package/lib/esm/numerics/PascalCoefficients.js +10 -12
- package/lib/esm/numerics/PascalCoefficients.js.map +1 -1
- package/lib/esm/numerics/Polynomials.d.ts +2 -2
- package/lib/esm/numerics/Polynomials.d.ts.map +1 -1
- package/lib/esm/numerics/Polynomials.js +2 -2
- package/lib/esm/numerics/Polynomials.js.map +1 -1
- package/lib/esm/polyface/PolyfaceBuilder.d.ts +3 -0
- package/lib/esm/polyface/PolyfaceBuilder.d.ts.map +1 -1
- package/lib/esm/polyface/PolyfaceBuilder.js +13 -2
- package/lib/esm/polyface/PolyfaceBuilder.js.map +1 -1
- package/lib/esm/polyface/PolyfaceClip.d.ts +1 -1
- package/lib/esm/polyface/PolyfaceClip.d.ts.map +1 -1
- package/lib/esm/polyface/PolyfaceClip.js +6 -3
- package/lib/esm/polyface/PolyfaceClip.js.map +1 -1
- package/lib/esm/polyface/PolyfaceData.d.ts +1 -1
- package/lib/esm/polyface/PolyfaceData.js +1 -1
- package/lib/esm/polyface/PolyfaceData.js.map +1 -1
- package/lib/esm/polyface/PolyfaceQuery.d.ts +39 -12
- package/lib/esm/polyface/PolyfaceQuery.d.ts.map +1 -1
- package/lib/esm/polyface/PolyfaceQuery.js +94 -17
- package/lib/esm/polyface/PolyfaceQuery.js.map +1 -1
- package/lib/esm/serialization/BGFBReader.d.ts +10 -10
- package/lib/esm/serialization/BGFBReader.d.ts.map +1 -1
- package/lib/esm/serialization/BGFBReader.js +69 -42
- package/lib/esm/serialization/BGFBReader.js.map +1 -1
- package/lib/esm/serialization/BGFBWriter.d.ts +8 -8
- package/lib/esm/serialization/BGFBWriter.d.ts.map +1 -1
- package/lib/esm/serialization/BGFBWriter.js +80 -55
- package/lib/esm/serialization/BGFBWriter.js.map +1 -1
- package/lib/esm/serialization/GeometrySamples.d.ts.map +1 -1
- package/lib/esm/serialization/GeometrySamples.js +7 -9
- package/lib/esm/serialization/GeometrySamples.js.map +1 -1
- package/lib/esm/serialization/IModelJsonSchema.d.ts +8 -14
- package/lib/esm/serialization/IModelJsonSchema.d.ts.map +1 -1
- package/lib/esm/serialization/IModelJsonSchema.js +86 -260
- package/lib/esm/serialization/IModelJsonSchema.js.map +1 -1
- package/lib/esm/serialization/SerializationHelpers.d.ts +109 -0
- package/lib/esm/serialization/SerializationHelpers.d.ts.map +1 -0
- package/lib/esm/serialization/SerializationHelpers.js +588 -0
- package/lib/esm/serialization/SerializationHelpers.js.map +1 -0
- package/lib/esm/solid/SweepContour.d.ts +4 -2
- package/lib/esm/solid/SweepContour.d.ts.map +1 -1
- package/lib/esm/solid/SweepContour.js +4 -2
- package/lib/esm/solid/SweepContour.js.map +1 -1
- package/package.json +3 -3
|
@@ -10,27 +10,28 @@ import { Plane3dByOriginAndVectors } from "../geometry3d/Plane3dByOriginAndVecto
|
|
|
10
10
|
import { Point2d, Vector2d } from "../geometry3d/Point2dVector2d";
|
|
11
11
|
import { SmallSystem } from "./Polynomials";
|
|
12
12
|
// cspell:word currentdFdX
|
|
13
|
-
/**
|
|
14
|
-
*
|
|
15
|
-
* from this base class.
|
|
13
|
+
/**
|
|
14
|
+
* Base class for Newton iterations in various dimensions.
|
|
15
|
+
* Dimension-specific classes carry all dimension-related data and answer generalized queries from this base class.
|
|
16
16
|
* @internal
|
|
17
17
|
*/
|
|
18
18
|
export class AbstractNewtonIterator {
|
|
19
19
|
/**
|
|
20
|
+
* The constructor.
|
|
20
21
|
* @param stepSizeTarget tolerance to consider a single step converged.
|
|
21
|
-
* This number should be "moderately" strict.
|
|
22
|
+
* This number should be "moderately" strict. Because 2 successive convergences are required,
|
|
22
23
|
* it is expected that a first "accept" for (say) 10 to 14 digit step will be followed by another
|
|
23
|
-
* iteration.
|
|
24
|
-
* 20 to 28.
|
|
24
|
+
* iteration. A well behaved newton would then hypothetically double the number of digits to
|
|
25
|
+
* 20 to 28. Since the IEEE double only carries 16 digits, this second-convergence step will
|
|
25
26
|
* typically achieve full precision.
|
|
26
27
|
* @param successiveConvergenceTarget number of successive convergences required for acceptance.
|
|
27
|
-
* @param maxIterations max number of iterations.
|
|
28
|
-
*
|
|
28
|
+
* @param maxIterations max number of iterations. A typical newton step converges in 3 to 6 iterations.
|
|
29
|
+
* Allow 15 to 20 to catch difficult cases.
|
|
29
30
|
*/
|
|
30
31
|
constructor(stepSizeTolerance = 1.0e-11, successiveConvergenceTarget = 2, maxIterations = 15) {
|
|
31
|
-
/** Number of consecutive steps which passed convergence condition */
|
|
32
|
+
/** Number of consecutive steps which passed convergence condition. */
|
|
32
33
|
this._numAccepted = 0;
|
|
33
|
-
/**
|
|
34
|
+
/** Number of iterations (incremented at each step). */
|
|
34
35
|
this.numIterations = 0;
|
|
35
36
|
this._stepSizeTolerance = stepSizeTolerance;
|
|
36
37
|
this._successiveConvergenceTarget = successiveConvergenceTarget;
|
|
@@ -38,8 +39,9 @@ export class AbstractNewtonIterator {
|
|
|
38
39
|
}
|
|
39
40
|
/**
|
|
40
41
|
* Test if a step is converged.
|
|
41
|
-
* * Convergence is accepted with enough (_successiveConvergenceTarget) small steps (according to _stepSizeTolerance)
|
|
42
|
-
*
|
|
42
|
+
* * Convergence is accepted with enough (_successiveConvergenceTarget) small steps (according to _stepSizeTolerance)
|
|
43
|
+
* occur in succession.
|
|
44
|
+
* @param delta step size as reported by currentStepSize.
|
|
43
45
|
*/
|
|
44
46
|
testConvergence(delta) {
|
|
45
47
|
if (Math.abs(delta) < this._stepSizeTolerance) {
|
|
@@ -52,16 +54,15 @@ export class AbstractNewtonIterator {
|
|
|
52
54
|
/**
|
|
53
55
|
* Run iterations, calling various methods from base and derived classes:
|
|
54
56
|
* * computeStep -- typically evaluate derivatives and solve linear system.
|
|
55
|
-
* * currentStepSize -- return numeric measure of the step just computed by computeStep
|
|
57
|
+
* * currentStepSize -- return numeric measure of the step just computed by computeStep.
|
|
56
58
|
* * testConvergence -- test if the step from currentStepSize (along with recent steps) is converged.
|
|
57
|
-
* * applyCurrentStep -- apply the step to the independent variables
|
|
59
|
+
* * applyCurrentStep -- apply the step to the independent variables.
|
|
58
60
|
*/
|
|
59
61
|
runIterations() {
|
|
60
62
|
this._numAccepted = 0;
|
|
61
63
|
this.numIterations = 0;
|
|
62
64
|
while (this.numIterations++ < this._maxIterations && this.computeStep()) {
|
|
63
|
-
if (this.testConvergence(this.currentStepSize())
|
|
64
|
-
&& this.applyCurrentStep(true)) {
|
|
65
|
+
if (this.testConvergence(this.currentStepSize()) && this.applyCurrentStep(true)) {
|
|
65
66
|
return true;
|
|
66
67
|
}
|
|
67
68
|
this.applyCurrentStep(false);
|
|
@@ -69,7 +70,8 @@ export class AbstractNewtonIterator {
|
|
|
69
70
|
return false;
|
|
70
71
|
}
|
|
71
72
|
}
|
|
72
|
-
/**
|
|
73
|
+
/**
|
|
74
|
+
* Object to evaluate a newton function. The object must retain most-recent function and derivative
|
|
73
75
|
* values for immediate query.
|
|
74
76
|
* @internal
|
|
75
77
|
*/
|
|
@@ -77,26 +79,39 @@ export class NewtonEvaluatorRtoRD {
|
|
|
77
79
|
}
|
|
78
80
|
/**
|
|
79
81
|
* Newton iterator for use when both function and derivative can be evaluated.
|
|
82
|
+
* To solve `f(x) = 0`, the Newton iteration is `x_{n+1} = x_n - dx = x_n - f(x_n)/f'(x_n)`.
|
|
83
|
+
* To solve `f(x) = target` which is equivalent to solving `g(x) = f(x) - target = 0`, the Newton iteration is
|
|
84
|
+
* `x_{n+1} = x_n - dx = x_n - g(x_n)/g'(x_n) = x_n - (f(x_n)-target)/f'(x_n)`.
|
|
80
85
|
* @internal
|
|
81
86
|
*/
|
|
82
87
|
export class Newton1dUnbounded extends AbstractNewtonIterator {
|
|
83
88
|
/**
|
|
84
|
-
* Constructor for 1D newton iteration with
|
|
85
|
-
* @param func function that returns both function and derivative.
|
|
89
|
+
* Constructor for 1D newton iteration with derivatives.
|
|
90
|
+
* @param func function that returns both function value and derivative.
|
|
86
91
|
*/
|
|
87
92
|
constructor(func) {
|
|
88
93
|
super();
|
|
89
94
|
this._func = func;
|
|
90
95
|
this.setTarget(0);
|
|
91
96
|
}
|
|
92
|
-
/** Set the independent variable */
|
|
93
|
-
setX(x) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
97
|
+
/** Set the independent variable, i.e., x_n. */
|
|
98
|
+
setX(x) {
|
|
99
|
+
this._currentX = x;
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
/** Get the independent variable, i.e., x_n. */
|
|
103
|
+
getX() {
|
|
104
|
+
return this._currentX;
|
|
105
|
+
}
|
|
106
|
+
/** Set the target function value. */
|
|
107
|
+
setTarget(y) {
|
|
108
|
+
this._target = y;
|
|
109
|
+
}
|
|
110
|
+
/** Move the current X by the just-computed step, i.e., `x_n - dx`. */
|
|
111
|
+
applyCurrentStep() {
|
|
112
|
+
// console.log(this._currentX - this._currentStep); // print approximations for debug
|
|
113
|
+
return this.setX(this._currentX - this._currentStep);
|
|
114
|
+
}
|
|
100
115
|
/** Compute the univariate newton step. */
|
|
101
116
|
computeStep() {
|
|
102
117
|
if (this._func.evaluate(this._currentX)) {
|
|
@@ -108,41 +123,54 @@ export class Newton1dUnbounded extends AbstractNewtonIterator {
|
|
|
108
123
|
}
|
|
109
124
|
return false;
|
|
110
125
|
}
|
|
111
|
-
/** Return the current step size as a relative number. */
|
|
126
|
+
/** Return the current step size as a relative number, i.e., `|dx / (1 + |x_n|)|`. */
|
|
112
127
|
currentStepSize() {
|
|
113
128
|
return Math.abs(this._currentStep / (1.0 + Math.abs(this._currentX)));
|
|
114
129
|
}
|
|
115
130
|
}
|
|
116
|
-
/**
|
|
131
|
+
/**
|
|
132
|
+
* Object to evaluate a newton function (without derivative). The object must retain most-recent function value.
|
|
117
133
|
* @internal
|
|
118
134
|
*/
|
|
119
135
|
export class NewtonEvaluatorRtoR {
|
|
120
136
|
}
|
|
121
|
-
/**
|
|
137
|
+
/**
|
|
138
|
+
* Newton iteration for a univariate function, using approximate derivatives.
|
|
139
|
+
* To approximate the derivatives we use a small step `h`, i.e., `f'(x_n) = (f(x_n + h) - f(x_n)) / h`.
|
|
140
|
+
* Therefore, to solve `f(x) = 0`, the iteration is
|
|
141
|
+
* `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))`.
|
|
122
142
|
* @internal
|
|
123
143
|
*/
|
|
124
144
|
export class Newton1dUnboundedApproximateDerivative extends AbstractNewtonIterator {
|
|
125
145
|
/**
|
|
126
146
|
* Constructor for 1D newton iteration with approximate derivatives.
|
|
127
|
-
* @param func function that returns
|
|
147
|
+
* @param func function that only returns function value (and not derivative).
|
|
128
148
|
*/
|
|
129
149
|
constructor(func) {
|
|
130
150
|
super();
|
|
131
151
|
this._func = func;
|
|
132
152
|
this.derivativeH = 1.0e-8;
|
|
133
153
|
}
|
|
134
|
-
/** Set the
|
|
135
|
-
setX(x) {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
154
|
+
/** Set the independent variable, i.e., x_n. */
|
|
155
|
+
setX(x) {
|
|
156
|
+
this._currentX = x;
|
|
157
|
+
return true;
|
|
158
|
+
}
|
|
159
|
+
/** Get the independent variable, i.e., x_n. */
|
|
160
|
+
getX() {
|
|
161
|
+
return this._currentX;
|
|
162
|
+
}
|
|
163
|
+
/** Move the current X by the just-computed step, i.e., `x_n - dx`. */
|
|
164
|
+
applyCurrentStep() {
|
|
165
|
+
// console.log(this._currentX - this._currentStep); // print approximations for debug
|
|
166
|
+
return this.setX(this._currentX - this._currentStep);
|
|
167
|
+
}
|
|
168
|
+
/** Univariate newton step computed with approximate derivative. */
|
|
141
169
|
computeStep() {
|
|
142
170
|
if (this._func.evaluate(this._currentX)) {
|
|
143
|
-
const fA = this._func.currentF;
|
|
171
|
+
const fA = this._func.currentF; // f(x_n)
|
|
144
172
|
if (this._func.evaluate(this._currentX + this.derivativeH)) {
|
|
145
|
-
const fB = this._func.currentF;
|
|
173
|
+
const fB = this._func.currentF; // f(x_n + h)
|
|
146
174
|
const dx = Geometry.conditionalDivideFraction(fA, (fB - fA) / this.derivativeH);
|
|
147
175
|
if (dx !== undefined) {
|
|
148
176
|
this._currentStep = dx;
|
|
@@ -152,17 +180,18 @@ export class Newton1dUnboundedApproximateDerivative extends AbstractNewtonIterat
|
|
|
152
180
|
}
|
|
153
181
|
return false;
|
|
154
182
|
}
|
|
155
|
-
/** Return the current step size as a relative number. */
|
|
183
|
+
/** Return the current step size as a relative number, i.e., `|dx / (1 + |x_n|)|`. */
|
|
156
184
|
currentStepSize() {
|
|
157
185
|
return Math.abs(this._currentStep / (1.0 + Math.abs(this._currentX)));
|
|
158
186
|
}
|
|
159
187
|
}
|
|
160
|
-
/**
|
|
188
|
+
/**
|
|
189
|
+
* Object to evaluate a 2-parameter newton function with derivatives.
|
|
161
190
|
* @internal
|
|
162
191
|
*/
|
|
163
192
|
export class NewtonEvaluatorRRtoRRD {
|
|
164
193
|
/**
|
|
165
|
-
*
|
|
194
|
+
* Constructor.
|
|
166
195
|
* * This creates a currentF object to (repeatedly) receive function and derivatives.
|
|
167
196
|
*/
|
|
168
197
|
constructor() {
|
|
@@ -171,51 +200,79 @@ export class NewtonEvaluatorRRtoRRD {
|
|
|
171
200
|
}
|
|
172
201
|
/**
|
|
173
202
|
* Implement evaluation steps for newton iteration in 2 dimensions, using caller supplied NewtonEvaluatorRRtoRRD object.
|
|
203
|
+
* * 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,
|
|
204
|
+
* the 2D Newton's iteration to find a root of `F` is given by:
|
|
205
|
+
* `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
|
|
206
|
+
* defined as:
|
|
207
|
+
*
|
|
208
|
+
* `[dx/du dx/dv]`
|
|
209
|
+
*
|
|
210
|
+
* `[dy/du dy/dv]`
|
|
174
211
|
* @internal
|
|
175
212
|
*/
|
|
176
213
|
export class Newton2dUnboundedWithDerivative extends AbstractNewtonIterator {
|
|
214
|
+
/**
|
|
215
|
+
* Constructor for 2D newton iteration with derivatives.
|
|
216
|
+
* @param func function that returns both function value and derivative.
|
|
217
|
+
*/
|
|
177
218
|
constructor(func) {
|
|
178
219
|
super();
|
|
179
220
|
this._func = func;
|
|
180
221
|
this._currentStep = Vector2d.createZero();
|
|
181
222
|
this._currentUV = Point2d.createZero();
|
|
182
223
|
}
|
|
183
|
-
/** Set the current uv
|
|
184
|
-
setUV(
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
224
|
+
/** Set the current uv parameters, i.e., `X_n = (u_n, v_n)`. */
|
|
225
|
+
setUV(u, v) {
|
|
226
|
+
this._currentUV.set(u, v);
|
|
227
|
+
return true;
|
|
228
|
+
}
|
|
229
|
+
/** Get the current u parameter of X_n, i.e., u_n. */
|
|
230
|
+
getU() {
|
|
231
|
+
return this._currentUV.x;
|
|
232
|
+
}
|
|
233
|
+
/** Get the current v parameter of X_n, i.e., v_n. */
|
|
234
|
+
getV() {
|
|
235
|
+
return this._currentUV.y;
|
|
236
|
+
}
|
|
237
|
+
/** Update the current uv parameter by currentStep, i.e., compute `X_{n+1} := X_n - dX = (u_n - du, v_n - dv)`. */
|
|
238
|
+
applyCurrentStep() {
|
|
239
|
+
// print approximations for debug
|
|
240
|
+
// console.log("(" + (this._currentUV.x - this._currentStep.x) + "," + (this._currentUV.y - this._currentStep.y) + ")");
|
|
241
|
+
return this.setUV(this._currentUV.x - this._currentStep.x, this._currentUV.y - this._currentStep.y);
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Evaluate the functions and derivatives at `X_n = (u_n, v_n)`, and solve the Jacobian matrix equation to
|
|
245
|
+
* compute `dX = (du, dv)`.
|
|
193
246
|
*/
|
|
194
247
|
computeStep() {
|
|
195
248
|
if (this._func.evaluate(this._currentUV.x, this._currentUV.y)) {
|
|
196
249
|
const fA = this._func.currentF;
|
|
197
|
-
if (
|
|
250
|
+
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:
|
|
251
|
+
SmallSystem.linearSystem2d(fA.vectorU.x, fA.vectorV.x, fA.vectorU.y, fA.vectorV.y, fA.origin.x, fA.origin.y, this._currentStep))
|
|
198
252
|
return true;
|
|
199
253
|
}
|
|
200
254
|
return false;
|
|
201
255
|
}
|
|
202
256
|
/**
|
|
203
|
-
* Return the
|
|
257
|
+
* Return the current relative step size, i.e., the larger absolute component of `dX / (1 + |X_n|)`
|
|
204
258
|
*/
|
|
205
259
|
currentStepSize() {
|
|
206
260
|
return Geometry.maxAbsXY(this._currentStep.x / (1.0 + Math.abs(this._currentUV.x)), this._currentStep.y / (1.0 + Math.abs(this._currentUV.y)));
|
|
207
261
|
}
|
|
208
262
|
}
|
|
209
263
|
/**
|
|
210
|
-
* SimpleNewton has static methods for newton methods with evaluated functions presented as immediate arguments
|
|
264
|
+
* SimpleNewton has static methods for newton methods with evaluated functions presented as immediate arguments
|
|
265
|
+
* (not function object).
|
|
211
266
|
* @internal
|
|
212
267
|
*/
|
|
213
268
|
export class SimpleNewton {
|
|
214
|
-
/**
|
|
215
|
-
*
|
|
216
|
-
* *
|
|
217
|
-
*
|
|
218
|
-
*
|
|
269
|
+
/**
|
|
270
|
+
* Run a one-dimensional newton iteration with separate functions for function and derivative.
|
|
271
|
+
* * Completion is at 2 (TWO) successive passes at `absoluteTolerance + relTol * abs(x)`, where relTol is
|
|
272
|
+
* chosen internally.
|
|
273
|
+
* * `absoluteTolerance` is usually aggressively tight -- should come into play only for x near zero.
|
|
274
|
+
* * The `relTol` is fluffy (for instance around 1e-11) but in properly converging cases the extra pass after
|
|
275
|
+
* first success normally moves to full machine precision.
|
|
219
276
|
* * This is an open-loop newton -- it just runs, and returns undefined if anything bad happens.
|
|
220
277
|
*/
|
|
221
278
|
static runNewton1D(x, func, derivative, absoluteTolerance = Geometry.smallFloatingPoint) {
|
|
@@ -230,10 +287,11 @@ export class SimpleNewton {
|
|
|
230
287
|
if (dx === undefined)
|
|
231
288
|
return undefined;
|
|
232
289
|
x -= dx;
|
|
290
|
+
// console.log(x); // print approximations for debug
|
|
233
291
|
tolerance = absoluteTolerance + Math.abs(x) * relTol;
|
|
234
292
|
if (Math.abs(dx) < tolerance) {
|
|
235
293
|
numConverged++;
|
|
236
|
-
if (dx === 0.0 || numConverged > 1) // bypass convergence count on true 0 dx
|
|
294
|
+
if (dx === 0.0 || numConverged > 1) // bypass convergence count on true 0 dx
|
|
237
295
|
return x;
|
|
238
296
|
}
|
|
239
297
|
else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Newton.js","sourceRoot":"","sources":["../../../src/numerics/Newton.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F;;GAEG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,yBAAyB,EAAE,MAAM,yCAAyC,CAAC;AACpF,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,0BAA0B;AAC1B;;;;GAIG;AACH,MAAM,OAAgB,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,CAA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AACH,MAAM,OAAO,YAAY;IACvB;;;;;;OAMG;IACI,MAAM,CAAC,WAAW,CACvB,CAAS,EACT,IAAuC,EACvC,UAA6C,EAC7C,oBAA4B,QAAQ,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,QAAQ,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","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,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,yBAAyB,EAAE,MAAM,yCAAyC,CAAC;AACpF,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,0BAA0B;AAE1B;;;;GAIG;AACH,MAAM,OAAgB,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,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G,CAAC,EAAI,wCAAwC;wBAC5E,OAAO,CAAC,CAAC;iBACZ;qBAAM;oBACL,YAAY,GAAG,CAAC,CAAC;iBAClB;aACF;SACF;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;CACF","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
|
-
/**
|
|
15
|
-
*
|
|
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
|
-
/**
|
|
24
|
-
*
|
|
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
|
|
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"}
|
|
@@ -38,13 +38,11 @@ class PascalCoefficients {
|
|
|
38
38
|
}
|
|
39
39
|
return allRows[row];
|
|
40
40
|
}
|
|
41
|
-
/**
|
|
42
|
-
*
|
|
41
|
+
/**
|
|
42
|
+
* Return an array with Bezier weighted pascal coefficients
|
|
43
|
+
* @param order output size. The index of the row of the Pascal triangle supplying weights is `order - 1`.
|
|
43
44
|
* @param u parameter value
|
|
44
|
-
* @param result optional destination array.
|
|
45
|
-
* @note if the destination array is undefined or too small, a new Float64Array is allocated.
|
|
46
|
-
* @note if the destination array is larger than needed, its leading `row+1` values are filled,
|
|
47
|
-
* and the array is returned.
|
|
45
|
+
* @param result optional destination array of length `order`. If the destination array is too small, a new Float64Array is allocated.
|
|
48
46
|
*/
|
|
49
47
|
static getBezierBasisValues(order, u, result) {
|
|
50
48
|
const row = order - 1;
|
|
@@ -66,15 +64,15 @@ class PascalCoefficients {
|
|
|
66
64
|
}
|
|
67
65
|
return result;
|
|
68
66
|
}
|
|
69
|
-
/**
|
|
70
|
-
*
|
|
67
|
+
/**
|
|
68
|
+
* Return an array with derivatives of Bezier weighted pascal coefficients
|
|
69
|
+
* @param order output size. The index of the row of the Pascal triangle supplying weights is `order - 2`.
|
|
71
70
|
* @param u parameter value
|
|
72
|
-
* @param result optional destination array.
|
|
73
|
-
* @note if the destination array is undefined or too small, a new Float64Array is allocated.
|
|
74
|
-
* @note if the destination array is larger than needed, its leading `row+1` values are filled,
|
|
75
|
-
* and the array is returned.
|
|
71
|
+
* @param result optional destination array of length `order`. If the destination array is too small, a new Float64Array is allocated.
|
|
76
72
|
*/
|
|
77
73
|
static getBezierBasisDerivatives(order, u, result) {
|
|
74
|
+
if (result === undefined || result.length < order)
|
|
75
|
+
result = new Float64Array(order);
|
|
78
76
|
result = this.getBezierBasisValues(order - 1, u, result);
|
|
79
77
|
// derivative is df/du = (order-1 ) * sum ( q[i+1] - q[i]) summed on 0 <= i < order - 1.\
|
|
80
78
|
// 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,E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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;;AA/Ec,2BAAQ,GAAmB,EAAE,CAAC;SADlC,kBAAkB","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
|
|
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
|
|
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
|