@itwin/core-geometry 4.3.0-dev.9 → 4.4.0-dev.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.
- package/CHANGELOG.md +38 -1
- package/lib/cjs/Geometry.d.ts +14 -2
- package/lib/cjs/Geometry.d.ts.map +1 -1
- package/lib/cjs/Geometry.js +20 -9
- 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/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/core-geometry.d.ts +0 -2
- package/lib/cjs/core-geometry.d.ts.map +1 -1
- package/lib/cjs/core-geometry.js +0 -2
- package/lib/cjs/core-geometry.js.map +1 -1
- package/lib/cjs/curve/Arc3d.d.ts.map +1 -1
- package/lib/cjs/curve/Arc3d.js +5 -5
- package/lib/cjs/curve/Arc3d.js.map +1 -1
- package/lib/cjs/curve/CurveLocationDetail.d.ts +1 -4
- package/lib/cjs/curve/CurveLocationDetail.d.ts.map +1 -1
- package/lib/cjs/curve/CurveLocationDetail.js +4 -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/LineString3d.d.ts +3 -2
- package/lib/cjs/curve/LineString3d.d.ts.map +1 -1
- package/lib/cjs/curve/LineString3d.js +1 -0
- 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 +5 -11
- package/lib/cjs/curve/RegionOps.d.ts.map +1 -1
- package/lib/cjs/curve/RegionOps.js.map +1 -1
- package/lib/cjs/curve/internalContexts/CurveCurveCloseApproachXY.d.ts +15 -9
- package/lib/cjs/curve/internalContexts/CurveCurveCloseApproachXY.d.ts.map +1 -1
- package/lib/cjs/curve/internalContexts/CurveCurveCloseApproachXY.js +68 -56
- package/lib/cjs/curve/internalContexts/CurveCurveCloseApproachXY.js.map +1 -1
- package/lib/cjs/curve/internalContexts/CurveCurveIntersectXY.d.ts +14 -16
- package/lib/cjs/curve/internalContexts/CurveCurveIntersectXY.d.ts.map +1 -1
- package/lib/cjs/curve/internalContexts/CurveCurveIntersectXY.js +51 -69
- package/lib/cjs/curve/internalContexts/CurveCurveIntersectXY.js.map +1 -1
- package/lib/cjs/curve/internalContexts/CurveCurveIntersectXYZ.d.ts.map +1 -1
- package/lib/cjs/curve/internalContexts/CurveCurveIntersectXYZ.js +3 -2
- 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.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/Angle.d.ts +0 -1
- package/lib/cjs/geometry3d/Angle.d.ts.map +1 -1
- package/lib/cjs/geometry3d/Angle.js +0 -1
- package/lib/cjs/geometry3d/Angle.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 +4 -5
- package/lib/cjs/geometry3d/Transform.d.ts.map +1 -1
- package/lib/cjs/geometry3d/Transform.js +4 -5
- package/lib/cjs/geometry3d/Transform.js.map +1 -1
- package/lib/cjs/geometry4d/Point4d.d.ts +13 -0
- package/lib/cjs/geometry4d/Point4d.d.ts.map +1 -1
- package/lib/cjs/geometry4d/Point4d.js +21 -0
- package/lib/cjs/geometry4d/Point4d.js.map +1 -1
- package/lib/cjs/numerics/BezierPolynomials.d.ts +88 -64
- package/lib/cjs/numerics/BezierPolynomials.d.ts.map +1 -1
- package/lib/cjs/numerics/BezierPolynomials.js +92 -73
- package/lib/cjs/numerics/BezierPolynomials.js.map +1 -1
- package/lib/cjs/numerics/Newton.d.ts +143 -61
- package/lib/cjs/numerics/Newton.d.ts.map +1 -1
- package/lib/cjs/numerics/Newton.js +233 -66
- 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 +6 -10
- package/lib/cjs/numerics/Polynomials.d.ts.map +1 -1
- package/lib/cjs/numerics/Polynomials.js +6 -10
- 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/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 +38 -11
- package/lib/cjs/polyface/PolyfaceQuery.d.ts.map +1 -1
- package/lib/cjs/polyface/PolyfaceQuery.js +93 -16
- 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/topology/Graph.d.ts +399 -366
- package/lib/cjs/topology/Graph.d.ts.map +1 -1
- package/lib/cjs/topology/Graph.js +531 -464
- package/lib/cjs/topology/Graph.js.map +1 -1
- package/lib/cjs/topology/MaskManager.d.ts +8 -9
- package/lib/cjs/topology/MaskManager.d.ts.map +1 -1
- package/lib/cjs/topology/MaskManager.js +11 -12
- package/lib/cjs/topology/MaskManager.js.map +1 -1
- package/lib/esm/Geometry.d.ts +14 -2
- package/lib/esm/Geometry.d.ts.map +1 -1
- package/lib/esm/Geometry.js +20 -9
- 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/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/core-geometry.d.ts +0 -2
- package/lib/esm/core-geometry.d.ts.map +1 -1
- package/lib/esm/core-geometry.js +0 -2
- package/lib/esm/core-geometry.js.map +1 -1
- package/lib/esm/curve/Arc3d.d.ts.map +1 -1
- package/lib/esm/curve/Arc3d.js +5 -5
- package/lib/esm/curve/Arc3d.js.map +1 -1
- package/lib/esm/curve/CurveLocationDetail.d.ts +1 -4
- package/lib/esm/curve/CurveLocationDetail.d.ts.map +1 -1
- package/lib/esm/curve/CurveLocationDetail.js +4 -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/LineString3d.d.ts +3 -2
- package/lib/esm/curve/LineString3d.d.ts.map +1 -1
- package/lib/esm/curve/LineString3d.js +1 -0
- 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 +5 -11
- package/lib/esm/curve/RegionOps.d.ts.map +1 -1
- package/lib/esm/curve/RegionOps.js.map +1 -1
- package/lib/esm/curve/internalContexts/CurveCurveCloseApproachXY.d.ts +15 -9
- package/lib/esm/curve/internalContexts/CurveCurveCloseApproachXY.d.ts.map +1 -1
- package/lib/esm/curve/internalContexts/CurveCurveCloseApproachXY.js +69 -57
- package/lib/esm/curve/internalContexts/CurveCurveCloseApproachXY.js.map +1 -1
- package/lib/esm/curve/internalContexts/CurveCurveIntersectXY.d.ts +14 -16
- package/lib/esm/curve/internalContexts/CurveCurveIntersectXY.d.ts.map +1 -1
- package/lib/esm/curve/internalContexts/CurveCurveIntersectXY.js +51 -68
- package/lib/esm/curve/internalContexts/CurveCurveIntersectXY.js.map +1 -1
- package/lib/esm/curve/internalContexts/CurveCurveIntersectXYZ.d.ts.map +1 -1
- package/lib/esm/curve/internalContexts/CurveCurveIntersectXYZ.js +3 -2
- 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.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/Angle.d.ts +0 -1
- package/lib/esm/geometry3d/Angle.d.ts.map +1 -1
- package/lib/esm/geometry3d/Angle.js +0 -1
- package/lib/esm/geometry3d/Angle.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 +4 -5
- package/lib/esm/geometry3d/Transform.d.ts.map +1 -1
- package/lib/esm/geometry3d/Transform.js +4 -5
- package/lib/esm/geometry3d/Transform.js.map +1 -1
- package/lib/esm/geometry4d/Point4d.d.ts +13 -0
- package/lib/esm/geometry4d/Point4d.d.ts.map +1 -1
- package/lib/esm/geometry4d/Point4d.js +21 -0
- package/lib/esm/geometry4d/Point4d.js.map +1 -1
- package/lib/esm/numerics/BezierPolynomials.d.ts +88 -64
- package/lib/esm/numerics/BezierPolynomials.d.ts.map +1 -1
- package/lib/esm/numerics/BezierPolynomials.js +92 -73
- package/lib/esm/numerics/BezierPolynomials.js.map +1 -1
- package/lib/esm/numerics/Newton.d.ts +143 -61
- package/lib/esm/numerics/Newton.d.ts.map +1 -1
- package/lib/esm/numerics/Newton.js +229 -65
- 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 +6 -10
- package/lib/esm/numerics/Polynomials.d.ts.map +1 -1
- package/lib/esm/numerics/Polynomials.js +6 -10
- 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/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 +38 -11
- package/lib/esm/polyface/PolyfaceQuery.d.ts.map +1 -1
- package/lib/esm/polyface/PolyfaceQuery.js +93 -16
- 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/topology/Graph.d.ts +399 -366
- package/lib/esm/topology/Graph.d.ts.map +1 -1
- package/lib/esm/topology/Graph.js +531 -464
- package/lib/esm/topology/Graph.js.map +1 -1
- package/lib/esm/topology/MaskManager.d.ts +8 -9
- package/lib/esm/topology/MaskManager.d.ts.map +1 -1
- package/lib/esm/topology/MaskManager.js +11 -12
- package/lib/esm/topology/MaskManager.js.map +1 -1
- 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
|
-
/**
|
|
17
|
-
*
|
|
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.
|
|
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.
|
|
27
|
-
* 20 to 28.
|
|
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.
|
|
31
|
-
*
|
|
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
|
-
/**
|
|
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)
|
|
45
|
-
*
|
|
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
|
-
|
|
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
|
-
/**
|
|
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
|
|
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) {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
|
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
|
|
142
|
-
setX(x) {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
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
|
-
/**
|
|
198
|
+
/**
|
|
199
|
+
* Object to evaluate a 2-parameter newton function with derivatives.
|
|
169
200
|
* @internal
|
|
170
201
|
*/
|
|
171
202
|
class NewtonEvaluatorRRtoRRD {
|
|
172
203
|
/**
|
|
173
|
-
*
|
|
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
|
-
|
|
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
|
|
193
|
-
setUV(
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
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 (
|
|
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
|
|
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
|
|
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
|
-
/**
|
|
225
|
-
*
|
|
226
|
-
* *
|
|
227
|
-
*
|
|
228
|
-
*
|
|
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,YA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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,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,CAAC,OAAO,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
|
-
/**
|
|
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"}
|