@itwin/core-geometry 5.4.0-dev.6 → 5.4.0
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 +43 -1
- package/lib/cjs/bspline/SurfaceLocationDetail.d.ts +1 -1
- package/lib/cjs/bspline/SurfaceLocationDetail.js +1 -1
- package/lib/cjs/bspline/SurfaceLocationDetail.js.map +1 -1
- package/lib/cjs/curve/CurveChainWithDistanceIndex.d.ts.map +1 -1
- package/lib/cjs/curve/CurveChainWithDistanceIndex.js.map +1 -1
- package/lib/cjs/curve/internalContexts/CurveCurveIntersectXY.d.ts +13 -0
- package/lib/cjs/curve/internalContexts/CurveCurveIntersectXY.d.ts.map +1 -1
- package/lib/cjs/curve/internalContexts/CurveCurveIntersectXY.js +78 -3
- package/lib/cjs/curve/internalContexts/CurveCurveIntersectXY.js.map +1 -1
- package/lib/cjs/curve/spiral/AustralianRailCorpXYEvaluator.d.ts +1 -1
- package/lib/cjs/curve/spiral/AustralianRailCorpXYEvaluator.js +1 -1
- package/lib/cjs/curve/spiral/AustralianRailCorpXYEvaluator.js.map +1 -1
- package/lib/cjs/curve/spiral/ClothoidSeries.d.ts +3 -3
- package/lib/cjs/curve/spiral/ClothoidSeries.d.ts.map +1 -1
- package/lib/cjs/curve/spiral/ClothoidSeries.js +15 -11
- package/lib/cjs/curve/spiral/ClothoidSeries.js.map +1 -1
- package/lib/cjs/curve/spiral/CzechSpiralEvaluator.d.ts +2 -5
- package/lib/cjs/curve/spiral/CzechSpiralEvaluator.d.ts.map +1 -1
- package/lib/cjs/curve/spiral/CzechSpiralEvaluator.js +4 -12
- package/lib/cjs/curve/spiral/CzechSpiralEvaluator.js.map +1 -1
- package/lib/cjs/curve/spiral/DirectSpiral3d.d.ts +7 -6
- package/lib/cjs/curve/spiral/DirectSpiral3d.d.ts.map +1 -1
- package/lib/cjs/curve/spiral/DirectSpiral3d.js +8 -6
- package/lib/cjs/curve/spiral/DirectSpiral3d.js.map +1 -1
- package/lib/cjs/curve/spiral/IntegratedSpiral3d.d.ts +2 -2
- package/lib/cjs/curve/spiral/IntegratedSpiral3d.d.ts.map +1 -1
- package/lib/cjs/curve/spiral/IntegratedSpiral3d.js +9 -5
- package/lib/cjs/curve/spiral/IntegratedSpiral3d.js.map +1 -1
- package/lib/cjs/curve/spiral/NormalizedTransition.d.ts +8 -7
- package/lib/cjs/curve/spiral/NormalizedTransition.d.ts.map +1 -1
- package/lib/cjs/curve/spiral/NormalizedTransition.js +32 -16
- package/lib/cjs/curve/spiral/NormalizedTransition.js.map +1 -1
- package/lib/cjs/curve/spiral/TransitionConditionalProperties.d.ts.map +1 -1
- package/lib/cjs/curve/spiral/TransitionConditionalProperties.js +1 -0
- package/lib/cjs/curve/spiral/TransitionConditionalProperties.js.map +1 -1
- package/lib/cjs/curve/spiral/TransitionSpiral3d.d.ts +1 -1
- package/lib/cjs/curve/spiral/TransitionSpiral3d.d.ts.map +1 -1
- package/lib/cjs/curve/spiral/TransitionSpiral3d.js +1 -0
- package/lib/cjs/curve/spiral/TransitionSpiral3d.js.map +1 -1
- package/lib/cjs/geometry3d/Ray3d.d.ts +1 -2
- package/lib/cjs/geometry3d/Ray3d.d.ts.map +1 -1
- package/lib/cjs/geometry3d/Ray3d.js +1 -2
- package/lib/cjs/geometry3d/Ray3d.js.map +1 -1
- package/lib/cjs/numerics/Newton.d.ts +1 -1
- package/lib/cjs/numerics/Newton.js +1 -1
- package/lib/cjs/numerics/Newton.js.map +1 -1
- package/lib/esm/bspline/SurfaceLocationDetail.d.ts +1 -1
- package/lib/esm/bspline/SurfaceLocationDetail.js +1 -1
- package/lib/esm/bspline/SurfaceLocationDetail.js.map +1 -1
- package/lib/esm/curve/CurveChainWithDistanceIndex.d.ts.map +1 -1
- package/lib/esm/curve/CurveChainWithDistanceIndex.js.map +1 -1
- package/lib/esm/curve/internalContexts/CurveCurveIntersectXY.d.ts +13 -0
- package/lib/esm/curve/internalContexts/CurveCurveIntersectXY.d.ts.map +1 -1
- package/lib/esm/curve/internalContexts/CurveCurveIntersectXY.js +78 -3
- package/lib/esm/curve/internalContexts/CurveCurveIntersectXY.js.map +1 -1
- package/lib/esm/curve/spiral/AustralianRailCorpXYEvaluator.d.ts +1 -1
- package/lib/esm/curve/spiral/AustralianRailCorpXYEvaluator.js +1 -1
- package/lib/esm/curve/spiral/AustralianRailCorpXYEvaluator.js.map +1 -1
- package/lib/esm/curve/spiral/ClothoidSeries.d.ts +3 -3
- package/lib/esm/curve/spiral/ClothoidSeries.d.ts.map +1 -1
- package/lib/esm/curve/spiral/ClothoidSeries.js +15 -11
- package/lib/esm/curve/spiral/ClothoidSeries.js.map +1 -1
- package/lib/esm/curve/spiral/CzechSpiralEvaluator.d.ts +2 -5
- package/lib/esm/curve/spiral/CzechSpiralEvaluator.d.ts.map +1 -1
- package/lib/esm/curve/spiral/CzechSpiralEvaluator.js +4 -12
- package/lib/esm/curve/spiral/CzechSpiralEvaluator.js.map +1 -1
- package/lib/esm/curve/spiral/DirectSpiral3d.d.ts +7 -6
- package/lib/esm/curve/spiral/DirectSpiral3d.d.ts.map +1 -1
- package/lib/esm/curve/spiral/DirectSpiral3d.js +8 -6
- package/lib/esm/curve/spiral/DirectSpiral3d.js.map +1 -1
- package/lib/esm/curve/spiral/IntegratedSpiral3d.d.ts +2 -2
- package/lib/esm/curve/spiral/IntegratedSpiral3d.d.ts.map +1 -1
- package/lib/esm/curve/spiral/IntegratedSpiral3d.js +9 -5
- package/lib/esm/curve/spiral/IntegratedSpiral3d.js.map +1 -1
- package/lib/esm/curve/spiral/NormalizedTransition.d.ts +8 -7
- package/lib/esm/curve/spiral/NormalizedTransition.d.ts.map +1 -1
- package/lib/esm/curve/spiral/NormalizedTransition.js +32 -16
- package/lib/esm/curve/spiral/NormalizedTransition.js.map +1 -1
- package/lib/esm/curve/spiral/TransitionConditionalProperties.d.ts.map +1 -1
- package/lib/esm/curve/spiral/TransitionConditionalProperties.js +1 -0
- package/lib/esm/curve/spiral/TransitionConditionalProperties.js.map +1 -1
- package/lib/esm/curve/spiral/TransitionSpiral3d.d.ts +1 -1
- package/lib/esm/curve/spiral/TransitionSpiral3d.d.ts.map +1 -1
- package/lib/esm/curve/spiral/TransitionSpiral3d.js +1 -0
- package/lib/esm/curve/spiral/TransitionSpiral3d.js.map +1 -1
- package/lib/esm/geometry3d/Ray3d.d.ts +1 -2
- package/lib/esm/geometry3d/Ray3d.d.ts.map +1 -1
- package/lib/esm/geometry3d/Ray3d.js +1 -2
- package/lib/esm/geometry3d/Ray3d.js.map +1 -1
- package/lib/esm/numerics/Newton.d.ts +1 -1
- package/lib/esm/numerics/Newton.js +1 -1
- package/lib/esm/numerics/Newton.js.map +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Ray3d.js","sourceRoot":"","sources":["../../../src/geometry3d/Ray3d.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F;;GAEG;AACH,OAAO,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AACpH,OAAO,EAAE,SAAS,EAAmB,QAAQ,EAAuB,MAAM,aAAa,CAAC;AACxF,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,OAAO,EAAW,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAGxC,qBAAqB;AACrB;;;;;;GAMG;AACH,MAAM,OAAO,KAAK;IAChB,qBAAqB;IACd,MAAM,CAAU;IACvB,0EAA0E;IACnE,SAAS,CAAW;IAC3B,0BAA0B;IACnB,CAAC,CAAU,CAAC,yBAAyB;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EAAE,EAAE,GAAG,CAAC,CAAC,GAAG,QAAQ,GAAG,EAAE,CAAC,CAAC;aACpF,CAAC;YACJ,MAAM,CAAC,GAAW,QAAQ,GAAG,GAAG,CAAC;YACjC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC;QACpE,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,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 CartesianGeometry\r\n */\r\nimport { CurveCurveApproachType, CurveLocationDetail, CurveLocationDetailPair } from \"../curve/CurveLocationDetail\";\r\nimport { AxisOrder, BeJSONFunctions, Geometry, PerpParallelOptions } from \"../Geometry\";\r\nimport { SmallSystem } from \"../numerics/SmallSystem\";\r\nimport { Matrix3d } from \"./Matrix3d\";\r\nimport { Plane3dByOriginAndUnitNormal } from \"./Plane3dByOriginAndUnitNormal\";\r\nimport { Vector2d } from \"./Point2dVector2d\";\r\nimport { Point3d, Vector3d } from \"./Point3dVector3d\";\r\nimport { Range1d, Range3d } from \"./Range\";\r\nimport { Transform } from \"./Transform\";\r\nimport { XYAndZ } from \"./XYZProps\";\r\n\r\n// cspell:word Cramer\r\n/**\r\n * A Ray3d contains\r\n * * an `origin` point.\r\n * * a `direction` vector (The vector is not required to be normalized).\r\n * * an optional weight (number).\r\n * @public\r\n */\r\nexport class Ray3d implements BeJSONFunctions {\r\n /** The ray origin */\r\n public origin: Point3d;\r\n /** The ray direction. This is commonly (but not always) a unit vector. */\r\n public direction: Vector3d;\r\n /** Numeric annotation. */\r\n public a?: number; // optional (e.g. weight)\r\n private static _workVector0?: Vector3d;\r\n private static _workVector1?: Vector3d;\r\n private static _workVector2?: Vector3d;\r\n private static _workVector3?: Vector3d;\r\n private static _workVector4?: Vector3d;\r\n private static _workMatrix?: Matrix3d;\r\n // constructor (captures references)\r\n private constructor(origin: Point3d, direction: Vector3d) {\r\n this.origin = origin;\r\n this.direction = direction;\r\n this.a = undefined;\r\n }\r\n private static _create(x: number, y: number, z: number, u: number, v: number, w: number) {\r\n return new Ray3d(Point3d.create(x, y, z), Vector3d.create(u, v, w));\r\n }\r\n /** Create a ray on the x axis. */\r\n public static createXAxis(): Ray3d {\r\n return Ray3d._create(0, 0, 0, 1, 0, 0);\r\n }\r\n /** Create a ray on the y axis. */\r\n public static createYAxis(): Ray3d {\r\n return Ray3d._create(0, 0, 0, 0, 1, 0);\r\n }\r\n /** Create a ray on the z axis. */\r\n public static createZAxis(): Ray3d {\r\n return Ray3d._create(0, 0, 0, 0, 0, 1);\r\n }\r\n /** Create a ray with all zeros. */\r\n public static createZero(result?: Ray3d): Ray3d {\r\n if (result) {\r\n result.origin.setZero();\r\n result.direction.setZero();\r\n return result;\r\n }\r\n return new Ray3d(Point3d.createZero(), Vector3d.createZero());\r\n }\r\n /**\r\n * Test for nearly equal Ray3d objects by comparing their origin and direction members.\r\n * @see [[isAlmostEqualPointSet]] to test for rays on the same infinite line.\r\n */\r\n public isAlmostEqual(other: Ray3d, tolerance: number = Geometry.smallMetricDistance): boolean {\r\n return this.origin.isAlmostEqual(other.origin, tolerance) && this.direction.isAlmostEqual(other.direction, tolerance);\r\n }\r\n /**\r\n * Return the dot product of the ray's direction vector with a vector from the ray origin\r\n * to the `spacePoint`.\r\n * * If the instance is the unit normal of a plane, then this method returns the (signed) altitude\r\n * of `spacePoint` with respect to the plane.\r\n * * Visualization can be found at https://www.itwinjs.org/sandbox/SaeedTorabi/ProjectVectorOnPlane\r\n */\r\n public dotProductToPoint(spacePoint: Point3d): number {\r\n return this.direction.dotProductStartEnd(this.origin, spacePoint);\r\n }\r\n /** Return the fractional coordinate (along the direction vector) of the `spacePoint` projected to the ray. */\r\n public pointToFraction(spacePoint: Point3d): number {\r\n return Geometry.safeDivideFraction(\r\n this.dotProductToPoint(spacePoint),\r\n this.direction.magnitudeSquared(),\r\n 0,\r\n );\r\n }\r\n /** Return the `spacePoint` projected onto the ray. */\r\n public projectPointToRay(spacePoint: Point3d): Point3d {\r\n /**\r\n * To project a point to the ray, we can create a vector called \"v\" from ray origin to the spacePoint and project\r\n * that vector to the ray direction vector \"r\". The projection is \"((v.r)/||r||^2) r\" where \"v.r\" is the dot\r\n * product. Note that pointToFraction returns \"(v.r)/||r||^2\".\r\n * Note: If r is the normal of a plane, then projection length \"(v.r)/||r||\" is the signed altitude of the\r\n * spacePoint with respect to the plane.\r\n */\r\n return this.origin.plusScaled(this.direction, this.pointToFraction(spacePoint));\r\n }\r\n /**\r\n * Test for rays that describe the same infinite line.\r\n * @see [[isAlmostEqual]] for member-by-member comparison.\r\n */\r\n public isAlmostEqualPointSet(other: Ray3d, options?: PerpParallelOptions): boolean {\r\n if (!this.direction.isParallelTo(other.direction, true, false, options))\r\n return false;\r\n const tol2 = options?.distanceSquaredTol ?? Geometry.smallMetricDistanceSquared;\r\n // theoretically, one test below is sufficient, but perform both in case the first passes because of round-off\r\n let workPoint = this.projectPointToRay(other.origin);\r\n if (other.origin.distanceSquared(workPoint) > tol2)\r\n return false;\r\n workPoint = other.projectPointToRay(this.origin);\r\n if (this.origin.distanceSquared(workPoint) > tol2)\r\n return false;\r\n return true;\r\n }\r\n /** Create a ray from origin and direction. */\r\n public static create(origin: Point3d, direction: Vector3d, result?: Ray3d): Ray3d {\r\n if (result) {\r\n result.set(origin, direction);\r\n return result;\r\n }\r\n return new Ray3d(origin.clone(), direction.clone());\r\n }\r\n /**\r\n * Given a homogeneous point and its derivative components, construct a Ray3d with cartesian\r\n * coordinates and derivatives.\r\n * @param weightedPoint `[x,y,z,w]` parts of weighted point.\r\n * @param weightedDerivative `[x,y,z,w]` derivatives\r\n * @param result\r\n */\r\n public static createWeightedDerivative(\r\n weightedPoint: Float64Array, weightedDerivative: Float64Array, result?: Ray3d,\r\n ): Ray3d | undefined {\r\n const w = weightedPoint[3];\r\n const dw = weightedDerivative[3];\r\n const x = weightedPoint[0];\r\n const y = weightedPoint[1];\r\n const z = weightedPoint[2];\r\n const dx = weightedDerivative[0] * w - weightedPoint[0] * dw;\r\n const dy = weightedDerivative[1] * w - weightedPoint[1] * dw;\r\n const dz = weightedDerivative[2] * w - weightedPoint[2] * dw;\r\n if (Geometry.isSmallMetricDistance(w))\r\n return undefined;\r\n const divW = 1.0 / w;\r\n const divWW = divW * divW;\r\n return Ray3d.createXYZUVW(\r\n x * divW, y * divW, z * divW,\r\n dx * divWW, dy * divWW, dz * divWW,\r\n result,\r\n );\r\n }\r\n /** Create from coordinates of the origin and direction. */\r\n public static createXYZUVW(\r\n originX: number, originY: number, originZ: number,\r\n directionX: number, directionY: number, directionZ: number,\r\n result?: Ray3d,\r\n ): Ray3d {\r\n if (result) {\r\n result.getOriginRef().set(originX, originY, originZ);\r\n result.getDirectionRef().set(directionX, directionY, directionZ);\r\n return result;\r\n }\r\n return new Ray3d(Point3d.create(originX, originY, originZ), Vector3d.create(directionX, directionY, directionZ));\r\n }\r\n /** Capture origin and direction in a new Ray3d. */\r\n public static createCapture(origin: Point3d, direction: Vector3d): Ray3d {\r\n return new Ray3d(origin, direction);\r\n }\r\n /** Create from (clones of) origin, direction, and numeric weight. */\r\n public static createPointVectorNumber(origin: Point3d, direction: Vector3d, a: number, result?: Ray3d): Ray3d {\r\n if (result) {\r\n result.origin.setFrom(origin);\r\n result.direction.setFrom(direction);\r\n result.a = a;\r\n return result;\r\n }\r\n result = new Ray3d(origin.clone(), direction.clone());\r\n result.a = a;\r\n return result;\r\n }\r\n /** Create from origin and target. The direction vector is the full length (non-unit) vector from origin to target. */\r\n public static createStartEnd(origin: Point3d, target: Point3d, result?: Ray3d): Ray3d {\r\n if (result) {\r\n result.origin.setFrom(origin);\r\n result.direction.setStartEnd(origin, target);\r\n return result;\r\n }\r\n return new Ray3d(origin.clone(), Vector3d.createStartEnd(origin, target));\r\n }\r\n /** Return a reference to the ray's origin. */\r\n public getOriginRef(): Point3d {\r\n return this.origin;\r\n }\r\n /** Return a reference to the ray's direction vector. */\r\n public getDirectionRef(): Vector3d {\r\n return this.direction;\r\n }\r\n /** Copy coordinates from origin and direction. */\r\n public set(origin: Point3d, direction: Vector3d): void {\r\n this.origin.setFrom(origin);\r\n this.direction.setFrom(direction);\r\n }\r\n /** Clone the ray. */\r\n public clone(result?: Ray3d): Ray3d {\r\n if (result) {\r\n result.set(this.origin.clone(), this.direction.clone());\r\n return result;\r\n }\r\n return new Ray3d(this.origin.clone(), this.direction.clone());\r\n }\r\n /** Return a clone of the transformed instance */\r\n public cloneTransformed(transform: Transform, result?: Ray3d): Ray3d {\r\n return Ray3d.create(\r\n transform.multiplyPoint3d(this.origin, result?.origin),\r\n transform.multiplyVector(this.direction, result?.direction),\r\n result,\r\n );\r\n }\r\n /** Create a clone and return the inverse transform of the clone. */\r\n public cloneInverseTransformed(transform: Transform, result?: Ray3d): Ray3d | undefined {\r\n if (!transform.computeCachedInverse(true))\r\n return undefined;\r\n return Ray3d.create(\r\n transform.multiplyInversePoint3d(this.origin, result?.origin)!,\r\n transform.matrix.multiplyInverseXYZAsVector3d(\r\n this.direction.x, this.direction.y, this.direction.z, result?.direction,\r\n )!,\r\n result,\r\n );\r\n }\r\n /** Apply a transform in place. */\r\n public transformInPlace(transform: Transform) {\r\n transform.multiplyPoint3d(this.origin, this.origin);\r\n transform.multiplyVector(this.direction, this.direction);\r\n }\r\n /** Copy data from another ray. */\r\n public setFrom(source: Ray3d): void {\r\n this.set(source.origin, source.direction);\r\n }\r\n /**\r\n * Return a point at fractional position along the ray.\r\n * * fraction 0 is the ray origin.\r\n * * fraction 1 is at the end of the direction vector when placed at the origin.\r\n */\r\n public fractionToPoint(fraction: number, result?: Point3d): Point3d {\r\n return this.origin.plusScaled(this.direction, fraction, result);\r\n }\r\n /**\r\n * Return a transform for rigid axes at ray origin with z in ray direction.\r\n * * If the direction vector is zero, axes default to identity (from [[Matrix3d.createRigidHeadsUp]])\r\n */\r\n public toRigidZFrame(result?: Transform): Transform {\r\n const axes = Ray3d._workMatrix = Matrix3d.createRigidHeadsUp(this.direction, AxisOrder.ZXY, Ray3d._workMatrix);\r\n return Transform.createOriginAndMatrix(this.origin, axes, result);\r\n }\r\n /** Convert {origin:[x,y,z], direction:[u,v,w]} to a Ray3d. */\r\n public setFromJSON(json?: any) {\r\n if (!json) {\r\n this.origin.set(0, 0, 0);\r\n this.direction.set(0, 0, 1);\r\n return;\r\n }\r\n this.origin.setFromJSON(json.origin);\r\n this.direction.setFromJSON(json.direction);\r\n }\r\n /**\r\n * Construct a JSON object from this Ray3d.\r\n * @return {*} [origin,normal]\r\n */\r\n public toJSON(): any {\r\n return { origin: this.origin.toJSON(), direction: this.direction.toJSON() };\r\n }\r\n /** Create a new ray from json object. See `setFromJSON` for json structure; */\r\n public static fromJSON(json?: any) {\r\n const result = Ray3d.createXAxis();\r\n result.setFromJSON(json);\r\n return result;\r\n }\r\n /**\r\n * Try to scale the direction vector to a given `magnitude`.\r\n * * Returns `false` if the ray direction is a zero vector.\r\n */\r\n public trySetDirectionMagnitudeInPlace(magnitude: number = 1.0): boolean {\r\n if (this.direction.tryNormalizeInPlace()) {\r\n this.direction.scaleInPlace(magnitude);\r\n return true;\r\n }\r\n this.direction.setZero();\r\n this.a = 0.0;\r\n return false;\r\n }\r\n /**\r\n * Normalize the ray direction in place.\r\n * * If parameter `a` is clearly nonzero and the direction vector can be normalized,\r\n * * Save the parameter `a` as the optional `a` member of the ray.\r\n * * Normalize the ray's direction vector.\r\n * * If parameter `a` is nearly zero,\r\n * * Set the `a` member to zero.\r\n * * Set the ray's direction vector to zero.\r\n * @param a value to be saved (e.g,. area).\r\n * @returns `true` if `a` is nonzero and normalization was successful. Otherwise, return `false`.\r\n */\r\n public tryNormalizeInPlaceWithAreaWeight(a: number): boolean {\r\n const tolerance = Geometry.smallMetricDistanceSquared;\r\n this.a = a;\r\n if (Math.abs(a) > tolerance && this.direction.tryNormalizeInPlace(tolerance))\r\n return true;\r\n this.direction.setZero();\r\n this.a = 0.0;\r\n return false;\r\n }\r\n /** Return distance from the ray to point in space. */\r\n public distance(spacePoint: Point3d): number {\r\n const uu = this.direction.magnitudeSquared();\r\n const uv = this.dotProductToPoint(spacePoint);\r\n const aa = Geometry.inverseMetricDistanceSquared(uu);\r\n if (aa)\r\n return Math.sqrt(this.origin.distanceSquared(spacePoint) - uv * uv * aa);\r\n else\r\n return Math.sqrt(this.origin.distanceSquared(spacePoint));\r\n }\r\n /**\r\n * Return the intersection parameter of the line defined by the ray with a `plane`.\r\n * * Stores the point of intersection in the `result` point (if passed as a parameter) and returns the parameter\r\n * along the ray where the intersection occurs. If we call the parameter 'f' then the point of intersection would\r\n * be `ray.origin + f * ray.direction`. Therefore:\r\n * * if ray intersects the plane at its origin, the function returns f = 0.\r\n * * if intersects at `ray.origin + ray.direction`, the function returns f = 1.\r\n * * if intersects behind the ray origin, the function returns f < 0.\r\n * * if intersects after `ray.origin + ray.direction`, the function returns f > 1.\r\n * * Returns `undefined` if the ray and plane are parallel or coplanar.\r\n */\r\n public intersectionWithPlane(plane: Plane3dByOriginAndUnitNormal, result?: Point3d): number | undefined {\r\n const vectorA = Vector3d.createStartEnd(plane.getOriginRef(), this.origin);\r\n const uDotN = this.direction.dotProduct(plane.getNormalRef());\r\n const nDotN = this.direction.magnitudeSquared();\r\n const aDotN = vectorA.dotProduct(plane.getNormalRef());\r\n const division = Geometry.conditionalDivideFraction(-aDotN, uDotN);\r\n if (undefined === division)\r\n return undefined;\r\n const division1 = Geometry.conditionalDivideFraction(nDotN, uDotN);\r\n if (undefined === division1)\r\n return undefined;\r\n if (result) {\r\n this.origin.plusScaled(this.direction, division, result);\r\n }\r\n return division;\r\n }\r\n /**\r\n * Find the intersection of the line defined by the ray with a Range3d.\r\n * * Return the range of parameters (on the ray) which are \"inside\" the range.\r\n * * Note that a range is always returned; if there is no intersection it is indicated by the test `result.isNull`.\r\n */\r\n public intersectionWithRange3d(range: Range3d, result?: Range1d): Range1d {\r\n if (range.isNull)\r\n return Range1d.createNull(result);\r\n const interval = Range1d.createXX(-Geometry.largeCoordinateResult, Geometry.largeCoordinateResult, result);\r\n interval.clipLinearMapToInterval(this.origin.x, this.direction.x, range.low.x, range.high.x);\r\n interval.clipLinearMapToInterval(this.origin.y, this.direction.y, range.low.y, range.high.y);\r\n interval.clipLinearMapToInterval(this.origin.z, this.direction.z, range.low.z, range.high.z);\r\n return interval;\r\n }\r\n /**\r\n * Compute the intersection of the ray with a triangle.\r\n * * This method is faster than `BarycentricTriangle.intersectRay3d`.\r\n * @param vertex0 first vertex of the triangle\r\n * @param vertex1 second vertex of the triangle\r\n * @param vertex2 third vertex of the triangle\r\n * @param distanceTol optional tolerance used to check if ray is parallel to the triangle or if we have line\r\n * intersection but not ray intersection (if tolerance is not provided, Geometry.smallMetricDistance is used)\r\n * @param parameterTol optional tolerance used to allow intersections just beyond an edge/vertex in barycentric\r\n * coordinate space (if tolerance is not provided, Geometry.smallFloatingPoint is used)\r\n * @param result optional pre-allocated object to fill and return\r\n * @returns the intersection point if ray intersects the triangle. Otherwise, return undefined.\r\n */\r\n public intersectionWithTriangle(\r\n vertex0: Point3d, vertex1: Point3d, vertex2: Point3d, distanceTol?: number, parameterTol?: number, result?: Point3d,\r\n ): Point3d | undefined {\r\n /**\r\n * Let (w,u,v) be the barycentric coordinates of point P wrt the triangle (v0,v1,v2), such that\r\n * P = w*v0 + u*v1 + v*v2 = (1-u-v)*v0 + u*v1 + v*v2 = v0 + u*(v1-v0) + v*(v2-v0)\r\n *\r\n * Then if the ray given by rayOrigin + t*rayVector intersects the triangle at P, we have\r\n * v0 + u*(v1-v0) + v*(v2-v0) = rayOrigin + t*rayVector\r\n *\r\n * This equation can be reformulated as the following linear system:\r\n *\r\n * [ | | | ] [t] [ | ]\r\n * [-rayVector v1-v0 v2-v0] [u] = [rayOrigin - v0]\r\n * [ | | | ] [v] [ | ]\r\n *\r\n * Then to find t, u, and v, use Cramer's Rule, the formulation of matrix determinant as column triple product,\r\n * and the fact that swapping any 2 vectors in the triple product negates it:\r\n *\r\n * t = (v2-v0).(rayOrigin - v0) x (v1-v0) / (v1-v0).rayVector x (v2-v0)\r\n * u = (rayOrigin - v0).rayVector x (v2-v0) / (v1-v0).rayVector x (v2-v0)\r\n * v = -rayVector.(rayOrigin - v0) x (v1-v0) / (v1-v0).rayVector x (v2-v0)\r\n *\r\n * Note that we verify 0 <= u,v,w <= 1. To do so we only need to check 0 <= u <= 1, 0 <= v, and u+v <= 1:\r\n * these 4 checks guarantee that v <= 1 and 0 <= u+v, and so with w = 1-(u+v), we have 0 <= w <= 1.\r\n *\r\n * More info be found at https://en.wikipedia.org/wiki/Moller-Trumbore_intersection_algorithm.\r\n */\r\n if (distanceTol === undefined || distanceTol < 0) // we explicitly allow zero tolerance\r\n distanceTol = Geometry.smallMetricDistance;\r\n if (parameterTol === undefined || parameterTol < 0) // we explicitly allow zero tolerance\r\n parameterTol = Geometry.smallFloatingPoint;\r\n const edge1 = Ray3d._workVector0 = Vector3d.createStartEnd(vertex0, vertex1, Ray3d._workVector0);\r\n const edge2 = Ray3d._workVector1 = Vector3d.createStartEnd(vertex0, vertex2, Ray3d._workVector1);\r\n const h = Ray3d._workVector2 = this.direction.crossProduct(edge2, Ray3d._workVector2);\r\n const a = edge1.dotProduct(h);\r\n if (a >= -distanceTol && a <= distanceTol)\r\n return undefined; // ray is parallel to the triangle (includes coplanar case)\r\n const f = 1.0 / a;\r\n const s = Ray3d._workVector3 = Vector3d.createStartEnd(vertex0, this.origin, Ray3d._workVector3);\r\n let u = f * s.dotProduct(h);\r\n if (u < 0.0) {\r\n if (u >= -parameterTol)\r\n u = 0.0;\r\n else\r\n return undefined; // ray does not intersect the triangle\r\n } else if (u > 1.0) {\r\n if (u <= 1.0 + parameterTol)\r\n u = 1.0;\r\n else\r\n return undefined; // ray does not intersect the triangle\r\n }\r\n const q = Ray3d._workVector4 = s.crossProduct(edge1, Ray3d._workVector4);\r\n let v = f * this.direction.dotProduct(q);\r\n if (v < 0.0) {\r\n if (v >= -parameterTol)\r\n v = 0.0;\r\n else\r\n return undefined; // ray does not intersect the triangle\r\n } else if (u + v > 1.0 + parameterTol) {\r\n return undefined; // ray does not intersect the triangle\r\n }\r\n // at this stage, we know the line (parameterized as the ray) intersects the triangle\r\n const t = f * edge2.dotProduct(q);\r\n if (t < -distanceTol) // line intersection but not ray intersection\r\n return undefined;\r\n return this.origin.plusScaled(this.direction, t, result); // ray intersection\r\n }\r\n /**\r\n * Return the shortest vector `v` to `targetPoint` from the line defined by this ray.\r\n * * If the projection of `targetPoint` onto the line defined by this ray is q, then `v = targetPoint - q`.\r\n */\r\n public perpendicularPartOfVectorToTarget(targetPoint: XYAndZ, result?: Vector3d): Vector3d {\r\n const vectorV = Vector3d.createStartEnd(this.origin, targetPoint);\r\n const uu = this.direction.magnitudeSquared();\r\n const uv = this.direction.dotProductStartEnd(this.origin, targetPoint);\r\n const fraction = Geometry.safeDivideFraction(uv, uu, 0.0);\r\n return vectorV.plusScaled(this.direction, -fraction, result);\r\n }\r\n /**\r\n * Determine if two rays intersect, or are fully overlapped, or parallel but not coincident, or skew.\r\n * * Return a CurveLocationDetailPair which contains fraction and point on each ray and has\r\n * annotation (in member `approachType`) indicating one of these relationships:\r\n * * CurveCurveApproachType.Intersection -- the rays have a simple intersection, at fractions indicated\r\n * in detailA and detailB\r\n * * CurveCurveApproachType.PerpendicularChord -- there is pair of where the rays have closest approach.\r\n * The rays are skew in space.\r\n * * CurveCurveApproachType.CoincidentGeometry -- the rays are the same unbounded line in space. The\r\n * fractions and points are a representative single common point.\r\n * * CurveCurveApproachType.Parallel -- the rays are parallel (and not coincident). The two points are\r\n * at the minimum distance\r\n */\r\n public static closestApproachRay3dRay3d(rayA: Ray3d, rayB: Ray3d): CurveLocationDetailPair {\r\n const intersectionFractions = Vector2d.create();\r\n let fractionA, fractionB;\r\n let pointA, pointB;\r\n let pairType;\r\n if (\r\n SmallSystem.ray3dXYZUVWClosestApproachUnbounded(\r\n rayA.origin.x, rayA.origin.y, rayA.origin.z, rayA.direction.x, rayA.direction.y, rayA.direction.z,\r\n rayB.origin.x, rayB.origin.y, rayB.origin.z, rayB.direction.x, rayB.direction.y, rayB.direction.z,\r\n intersectionFractions,\r\n )\r\n ) {\r\n fractionA = intersectionFractions.x;\r\n fractionB = intersectionFractions.y;\r\n pointA = rayA.fractionToPoint(fractionA);\r\n pointB = rayB.fractionToPoint(fractionB);\r\n pairType = pointA.isAlmostEqualMetric(pointB) ?\r\n CurveCurveApproachType.Intersection : CurveCurveApproachType.PerpendicularChord;\r\n } else {\r\n fractionB = 0.0;\r\n fractionA = rayA.pointToFraction(rayB.origin);\r\n pointA = rayA.fractionToPoint(fractionA);\r\n pointB = rayB.fractionToPoint(fractionB);\r\n pairType = pointA.isAlmostEqualMetric(pointB) ?\r\n CurveCurveApproachType.CoincidentGeometry : CurveCurveApproachType.ParallelGeometry;\r\n }\r\n const pair = CurveLocationDetailPair.createCapture(\r\n CurveLocationDetail.createRayFractionPoint(rayA, fractionA, rayA.fractionToPoint(fractionA)),\r\n CurveLocationDetail.createRayFractionPoint(rayB, fractionB, rayB.fractionToPoint(fractionB)));\r\n pair.approachType = pairType;\r\n return pair;\r\n }\r\n /**\r\n * Return a ray with `ray.origin` interpolated between `pt1` and `pt2` at the given `fraction`\r\n * and `ray.direction` set to the vector from `pt1` to `pt2` multiplied by the given `tangentScale`.\r\n * @param pt1 start point of the interpolation.\r\n * @param fraction fractional position between points.\r\n * @param pt2 end point of the interpolation.\r\n * @param tangentScale scale factor to apply to the startToEnd vector.\r\n * @param result optional receiver.\r\n */\r\n public static interpolatePointAndTangent(\r\n pt1: XYAndZ, fraction: number, pt2: XYAndZ, tangentScale: number, result?: Ray3d,\r\n ): Ray3d {\r\n result = result ?? Ray3d.createZero();\r\n const dx = pt2.x - pt1.x;\r\n const dy = pt2.y - pt1.y;\r\n const dz = pt2.z - pt1.z;\r\n result.direction.set(tangentScale * dx, tangentScale * dy, tangentScale * dz);\r\n if (fraction <= 0.5)\r\n result.origin.set(pt1.x + fraction * dx, pt1.y + fraction * dy, pt1.z + fraction * dz);\r\n else {\r\n const t: number = fraction - 1.0;\r\n result.origin.set(pt2.x + t * dx, pt2.y + t * dy, pt2.z + t * dz);\r\n }\r\n return result;\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"Ray3d.js","sourceRoot":"","sources":["../../../src/geometry3d/Ray3d.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F;;GAEG;AACH,OAAO,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AACpH,OAAO,EAAE,SAAS,EAAmB,QAAQ,EAAuB,MAAM,aAAa,CAAC;AACxF,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,OAAO,EAAW,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAGxC,qBAAqB;AACrB;;;;;;GAMG;AACH,MAAM,OAAO,KAAK;IAChB,qBAAqB;IACd,MAAM,CAAU;IACvB,0EAA0E;IACnE,SAAS,CAAW;IAC3B,0BAA0B;IACnB,CAAC,CAAU,CAAC,yBAAyB;IACpC,MAAM,CAAC,YAAY,CAAY;IAC/B,MAAM,CAAC,YAAY,CAAY;IAC/B,MAAM,CAAC,YAAY,CAAY;IAC/B,MAAM,CAAC,YAAY,CAAY;IAC/B,MA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MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC;QACpE,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,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 CartesianGeometry\r\n */\r\nimport { CurveCurveApproachType, CurveLocationDetail, CurveLocationDetailPair } from \"../curve/CurveLocationDetail\";\r\nimport { AxisOrder, BeJSONFunctions, Geometry, PerpParallelOptions } from \"../Geometry\";\r\nimport { SmallSystem } from \"../numerics/SmallSystem\";\r\nimport { Matrix3d } from \"./Matrix3d\";\r\nimport { Plane3dByOriginAndUnitNormal } from \"./Plane3dByOriginAndUnitNormal\";\r\nimport { Vector2d } from \"./Point2dVector2d\";\r\nimport { Point3d, Vector3d } from \"./Point3dVector3d\";\r\nimport { Range1d, Range3d } from \"./Range\";\r\nimport { Transform } from \"./Transform\";\r\nimport { XYAndZ } from \"./XYZProps\";\r\n\r\n// cspell:word Cramer\r\n/**\r\n * A Ray3d contains\r\n * * an `origin` point.\r\n * * a `direction` vector (The vector is not required to be normalized).\r\n * * an optional weight (number).\r\n * @public\r\n */\r\nexport class Ray3d implements BeJSONFunctions {\r\n /** The ray origin */\r\n public origin: Point3d;\r\n /** The ray direction. This is commonly (but not always) a unit vector. */\r\n public direction: Vector3d;\r\n /** Numeric annotation. */\r\n public a?: number; // optional (e.g. weight)\r\n private static _workVector0?: Vector3d;\r\n private static _workVector1?: Vector3d;\r\n private static _workVector2?: Vector3d;\r\n private static _workVector3?: Vector3d;\r\n private static _workVector4?: Vector3d;\r\n private static _workMatrix?: Matrix3d;\r\n // constructor (captures references)\r\n private constructor(origin: Point3d, direction: Vector3d) {\r\n this.origin = origin;\r\n this.direction = direction;\r\n this.a = undefined;\r\n }\r\n private static _create(x: number, y: number, z: number, u: number, v: number, w: number) {\r\n return new Ray3d(Point3d.create(x, y, z), Vector3d.create(u, v, w));\r\n }\r\n /** Create a ray on the x axis. */\r\n public static createXAxis(): Ray3d {\r\n return Ray3d._create(0, 0, 0, 1, 0, 0);\r\n }\r\n /** Create a ray on the y axis. */\r\n public static createYAxis(): Ray3d {\r\n return Ray3d._create(0, 0, 0, 0, 1, 0);\r\n }\r\n /** Create a ray on the z axis. */\r\n public static createZAxis(): Ray3d {\r\n return Ray3d._create(0, 0, 0, 0, 0, 1);\r\n }\r\n /** Create a ray with all zeros. */\r\n public static createZero(result?: Ray3d): Ray3d {\r\n if (result) {\r\n result.origin.setZero();\r\n result.direction.setZero();\r\n return result;\r\n }\r\n return new Ray3d(Point3d.createZero(), Vector3d.createZero());\r\n }\r\n /**\r\n * Test for nearly equal Ray3d objects by comparing their origin and direction members.\r\n * @see [[isAlmostEqualPointSet]] to test for rays on the same infinite line.\r\n */\r\n public isAlmostEqual(other: Ray3d, tolerance: number = Geometry.smallMetricDistance): boolean {\r\n return this.origin.isAlmostEqual(other.origin, tolerance) && this.direction.isAlmostEqual(other.direction, tolerance);\r\n }\r\n /**\r\n * Return the dot product of the ray's direction vector with a vector from the ray origin to the `spacePoint`.\r\n * * If the instance is the unit normal of a plane, then this method returns the (signed) altitude\r\n * of `spacePoint` with respect to the plane.\r\n * * Visualization can be found at https://www.itwinjs.org/sandbox/SaeedTorabi/ProjectVectorOnPlane\r\n */\r\n public dotProductToPoint(spacePoint: Point3d): number {\r\n return this.direction.dotProductStartEnd(this.origin, spacePoint);\r\n }\r\n /** Return the fractional coordinate (along the direction vector) of the `spacePoint` projected to the ray. */\r\n public pointToFraction(spacePoint: Point3d): number {\r\n return Geometry.safeDivideFraction(\r\n this.dotProductToPoint(spacePoint),\r\n this.direction.magnitudeSquared(),\r\n 0,\r\n );\r\n }\r\n /** Return the `spacePoint` projected onto the ray. */\r\n public projectPointToRay(spacePoint: Point3d): Point3d {\r\n /**\r\n * To project a point to the ray, we can create a vector called \"v\" from ray origin to the spacePoint and project\r\n * that vector to the ray direction vector \"r\". The projection is \"((v.r)/||r||^2) r\" where \"v.r\" is the dot\r\n * product. Note that pointToFraction returns \"(v.r)/||r||^2\".\r\n * Note: If r is the normal of a plane, then projection length \"(v.r)/||r||\" is the signed altitude of the\r\n * spacePoint with respect to the plane.\r\n */\r\n return this.origin.plusScaled(this.direction, this.pointToFraction(spacePoint));\r\n }\r\n /**\r\n * Test for rays that describe the same infinite line.\r\n * @see [[isAlmostEqual]] for member-by-member comparison.\r\n */\r\n public isAlmostEqualPointSet(other: Ray3d, options?: PerpParallelOptions): boolean {\r\n if (!this.direction.isParallelTo(other.direction, true, false, options))\r\n return false;\r\n const tol2 = options?.distanceSquaredTol ?? Geometry.smallMetricDistanceSquared;\r\n // theoretically, one test below is sufficient, but perform both in case the first passes because of round-off\r\n let workPoint = this.projectPointToRay(other.origin);\r\n if (other.origin.distanceSquared(workPoint) > tol2)\r\n return false;\r\n workPoint = other.projectPointToRay(this.origin);\r\n if (this.origin.distanceSquared(workPoint) > tol2)\r\n return false;\r\n return true;\r\n }\r\n /** Create a ray from origin and direction. */\r\n public static create(origin: Point3d, direction: Vector3d, result?: Ray3d): Ray3d {\r\n if (result) {\r\n result.set(origin, direction);\r\n return result;\r\n }\r\n return new Ray3d(origin.clone(), direction.clone());\r\n }\r\n /**\r\n * Given a homogeneous point and its derivative components, construct a Ray3d with cartesian\r\n * coordinates and derivatives.\r\n * @param weightedPoint `[x,y,z,w]` parts of weighted point.\r\n * @param weightedDerivative `[x,y,z,w]` derivatives\r\n * @param result\r\n */\r\n public static createWeightedDerivative(\r\n weightedPoint: Float64Array, weightedDerivative: Float64Array, result?: Ray3d,\r\n ): Ray3d | undefined {\r\n const w = weightedPoint[3];\r\n const dw = weightedDerivative[3];\r\n const x = weightedPoint[0];\r\n const y = weightedPoint[1];\r\n const z = weightedPoint[2];\r\n const dx = weightedDerivative[0] * w - weightedPoint[0] * dw;\r\n const dy = weightedDerivative[1] * w - weightedPoint[1] * dw;\r\n const dz = weightedDerivative[2] * w - weightedPoint[2] * dw;\r\n if (Geometry.isSmallMetricDistance(w))\r\n return undefined;\r\n const divW = 1.0 / w;\r\n const divWW = divW * divW;\r\n return Ray3d.createXYZUVW(\r\n x * divW, y * divW, z * divW,\r\n dx * divWW, dy * divWW, dz * divWW,\r\n result,\r\n );\r\n }\r\n /** Create from coordinates of the origin and direction. */\r\n public static createXYZUVW(\r\n originX: number, originY: number, originZ: number,\r\n directionX: number, directionY: number, directionZ: number,\r\n result?: Ray3d,\r\n ): Ray3d {\r\n if (result) {\r\n result.getOriginRef().set(originX, originY, originZ);\r\n result.getDirectionRef().set(directionX, directionY, directionZ);\r\n return result;\r\n }\r\n return new Ray3d(Point3d.create(originX, originY, originZ), Vector3d.create(directionX, directionY, directionZ));\r\n }\r\n /** Capture origin and direction in a new Ray3d. */\r\n public static createCapture(origin: Point3d, direction: Vector3d): Ray3d {\r\n return new Ray3d(origin, direction);\r\n }\r\n /** Create from (clones of) origin, direction, and numeric weight. */\r\n public static createPointVectorNumber(origin: Point3d, direction: Vector3d, a: number, result?: Ray3d): Ray3d {\r\n if (result) {\r\n result.origin.setFrom(origin);\r\n result.direction.setFrom(direction);\r\n result.a = a;\r\n return result;\r\n }\r\n result = new Ray3d(origin.clone(), direction.clone());\r\n result.a = a;\r\n return result;\r\n }\r\n /** Create from origin and target. The direction vector is the full length (non-unit) vector from origin to target. */\r\n public static createStartEnd(origin: Point3d, target: Point3d, result?: Ray3d): Ray3d {\r\n if (result) {\r\n result.origin.setFrom(origin);\r\n result.direction.setStartEnd(origin, target);\r\n return result;\r\n }\r\n return new Ray3d(origin.clone(), Vector3d.createStartEnd(origin, target));\r\n }\r\n /** Return a reference to the ray's origin. */\r\n public getOriginRef(): Point3d {\r\n return this.origin;\r\n }\r\n /** Return a reference to the ray's direction vector. */\r\n public getDirectionRef(): Vector3d {\r\n return this.direction;\r\n }\r\n /** Copy coordinates from origin and direction. */\r\n public set(origin: Point3d, direction: Vector3d): void {\r\n this.origin.setFrom(origin);\r\n this.direction.setFrom(direction);\r\n }\r\n /** Clone the ray. */\r\n public clone(result?: Ray3d): Ray3d {\r\n if (result) {\r\n result.set(this.origin.clone(), this.direction.clone());\r\n return result;\r\n }\r\n return new Ray3d(this.origin.clone(), this.direction.clone());\r\n }\r\n /** Return a clone of the transformed instance */\r\n public cloneTransformed(transform: Transform, result?: Ray3d): Ray3d {\r\n return Ray3d.create(\r\n transform.multiplyPoint3d(this.origin, result?.origin),\r\n transform.multiplyVector(this.direction, result?.direction),\r\n result,\r\n );\r\n }\r\n /** Create a clone and return the inverse transform of the clone. */\r\n public cloneInverseTransformed(transform: Transform, result?: Ray3d): Ray3d | undefined {\r\n if (!transform.computeCachedInverse(true))\r\n return undefined;\r\n return Ray3d.create(\r\n transform.multiplyInversePoint3d(this.origin, result?.origin)!,\r\n transform.matrix.multiplyInverseXYZAsVector3d(\r\n this.direction.x, this.direction.y, this.direction.z, result?.direction,\r\n )!,\r\n result,\r\n );\r\n }\r\n /** Apply a transform in place. */\r\n public transformInPlace(transform: Transform) {\r\n transform.multiplyPoint3d(this.origin, this.origin);\r\n transform.multiplyVector(this.direction, this.direction);\r\n }\r\n /** Copy data from another ray. */\r\n public setFrom(source: Ray3d): void {\r\n this.set(source.origin, source.direction);\r\n }\r\n /**\r\n * Return a point at fractional position along the ray.\r\n * * fraction 0 is the ray origin.\r\n * * fraction 1 is at the end of the direction vector when placed at the origin.\r\n */\r\n public fractionToPoint(fraction: number, result?: Point3d): Point3d {\r\n return this.origin.plusScaled(this.direction, fraction, result);\r\n }\r\n /**\r\n * Return a transform for rigid axes at ray origin with z in ray direction.\r\n * * If the direction vector is zero, axes default to identity (from [[Matrix3d.createRigidHeadsUp]])\r\n */\r\n public toRigidZFrame(result?: Transform): Transform {\r\n const axes = Ray3d._workMatrix = Matrix3d.createRigidHeadsUp(this.direction, AxisOrder.ZXY, Ray3d._workMatrix);\r\n return Transform.createOriginAndMatrix(this.origin, axes, result);\r\n }\r\n /** Convert {origin:[x,y,z], direction:[u,v,w]} to a Ray3d. */\r\n public setFromJSON(json?: any) {\r\n if (!json) {\r\n this.origin.set(0, 0, 0);\r\n this.direction.set(0, 0, 1);\r\n return;\r\n }\r\n this.origin.setFromJSON(json.origin);\r\n this.direction.setFromJSON(json.direction);\r\n }\r\n /**\r\n * Construct a JSON object from this Ray3d.\r\n * @return {*} [origin,normal]\r\n */\r\n public toJSON(): any {\r\n return { origin: this.origin.toJSON(), direction: this.direction.toJSON() };\r\n }\r\n /** Create a new ray from json object. See `setFromJSON` for json structure; */\r\n public static fromJSON(json?: any) {\r\n const result = Ray3d.createXAxis();\r\n result.setFromJSON(json);\r\n return result;\r\n }\r\n /**\r\n * Try to scale the direction vector to a given `magnitude`.\r\n * * Returns `false` if the ray direction is a zero vector.\r\n */\r\n public trySetDirectionMagnitudeInPlace(magnitude: number = 1.0): boolean {\r\n if (this.direction.tryNormalizeInPlace()) {\r\n this.direction.scaleInPlace(magnitude);\r\n return true;\r\n }\r\n this.direction.setZero();\r\n this.a = 0.0;\r\n return false;\r\n }\r\n /**\r\n * Normalize the ray direction in place.\r\n * * If parameter `a` is clearly nonzero and the direction vector can be normalized,\r\n * * Save the parameter `a` as the optional `a` member of the ray.\r\n * * Normalize the ray's direction vector.\r\n * * If parameter `a` is nearly zero,\r\n * * Set the `a` member to zero.\r\n * * Set the ray's direction vector to zero.\r\n * @param a value to be saved (e.g,. area).\r\n * @returns `true` if `a` is nonzero and normalization was successful. Otherwise, return `false`.\r\n */\r\n public tryNormalizeInPlaceWithAreaWeight(a: number): boolean {\r\n const tolerance = Geometry.smallMetricDistanceSquared;\r\n this.a = a;\r\n if (Math.abs(a) > tolerance && this.direction.tryNormalizeInPlace(tolerance))\r\n return true;\r\n this.direction.setZero();\r\n this.a = 0.0;\r\n return false;\r\n }\r\n /** Return distance from the ray to point in space. */\r\n public distance(spacePoint: Point3d): number {\r\n const uu = this.direction.magnitudeSquared();\r\n const uv = this.dotProductToPoint(spacePoint);\r\n const aa = Geometry.inverseMetricDistanceSquared(uu);\r\n if (aa)\r\n return Math.sqrt(this.origin.distanceSquared(spacePoint) - uv * uv * aa);\r\n else\r\n return Math.sqrt(this.origin.distanceSquared(spacePoint));\r\n }\r\n /**\r\n * Return the intersection parameter of the line defined by the ray with a `plane`.\r\n * * Stores the point of intersection in the `result` point (if passed as a parameter) and returns the parameter\r\n * along the ray where the intersection occurs. If we call the parameter 'f' then the point of intersection would\r\n * be `ray.origin + f * ray.direction`. Therefore:\r\n * * if ray intersects the plane at its origin, the function returns f = 0.\r\n * * if intersects at `ray.origin + ray.direction`, the function returns f = 1.\r\n * * if intersects behind the ray origin, the function returns f < 0.\r\n * * if intersects after `ray.origin + ray.direction`, the function returns f > 1.\r\n * * Returns `undefined` if the ray and plane are parallel or coplanar.\r\n */\r\n public intersectionWithPlane(plane: Plane3dByOriginAndUnitNormal, result?: Point3d): number | undefined {\r\n const vectorA = Vector3d.createStartEnd(plane.getOriginRef(), this.origin);\r\n const uDotN = this.direction.dotProduct(plane.getNormalRef());\r\n const nDotN = this.direction.magnitudeSquared();\r\n const aDotN = vectorA.dotProduct(plane.getNormalRef());\r\n const division = Geometry.conditionalDivideFraction(-aDotN, uDotN);\r\n if (undefined === division)\r\n return undefined;\r\n const division1 = Geometry.conditionalDivideFraction(nDotN, uDotN);\r\n if (undefined === division1)\r\n return undefined;\r\n if (result) {\r\n this.origin.plusScaled(this.direction, division, result);\r\n }\r\n return division;\r\n }\r\n /**\r\n * Find the intersection of the line defined by the ray with a Range3d.\r\n * * Return the range of parameters (on the ray) which are \"inside\" the range.\r\n * * Note that a range is always returned; if there is no intersection it is indicated by the test `result.isNull`.\r\n */\r\n public intersectionWithRange3d(range: Range3d, result?: Range1d): Range1d {\r\n if (range.isNull)\r\n return Range1d.createNull(result);\r\n const interval = Range1d.createXX(-Geometry.largeCoordinateResult, Geometry.largeCoordinateResult, result);\r\n interval.clipLinearMapToInterval(this.origin.x, this.direction.x, range.low.x, range.high.x);\r\n interval.clipLinearMapToInterval(this.origin.y, this.direction.y, range.low.y, range.high.y);\r\n interval.clipLinearMapToInterval(this.origin.z, this.direction.z, range.low.z, range.high.z);\r\n return interval;\r\n }\r\n /**\r\n * Compute the intersection of the ray with a triangle.\r\n * * This method is faster than `BarycentricTriangle.intersectRay3d`.\r\n * @param vertex0 first vertex of the triangle\r\n * @param vertex1 second vertex of the triangle\r\n * @param vertex2 third vertex of the triangle\r\n * @param distanceTol optional tolerance used to check if ray is parallel to the triangle or if we have line\r\n * intersection but not ray intersection (if tolerance is not provided, Geometry.smallMetricDistance is used)\r\n * @param parameterTol optional tolerance used to allow intersections just beyond an edge/vertex in barycentric\r\n * coordinate space (if tolerance is not provided, Geometry.smallFloatingPoint is used)\r\n * @param result optional pre-allocated object to fill and return\r\n * @returns the intersection point if ray intersects the triangle. Otherwise, return undefined.\r\n */\r\n public intersectionWithTriangle(\r\n vertex0: Point3d, vertex1: Point3d, vertex2: Point3d, distanceTol?: number, parameterTol?: number, result?: Point3d,\r\n ): Point3d | undefined {\r\n /**\r\n * Let (w,u,v) be the barycentric coordinates of point P wrt the triangle (v0,v1,v2), such that\r\n * P = w*v0 + u*v1 + v*v2 = (1-u-v)*v0 + u*v1 + v*v2 = v0 + u*(v1-v0) + v*(v2-v0)\r\n *\r\n * Then if the ray given by rayOrigin + t*rayVector intersects the triangle at P, we have\r\n * v0 + u*(v1-v0) + v*(v2-v0) = rayOrigin + t*rayVector\r\n *\r\n * This equation can be reformulated as the following linear system:\r\n *\r\n * [ | | | ] [t] [ | ]\r\n * [-rayVector v1-v0 v2-v0] [u] = [rayOrigin - v0]\r\n * [ | | | ] [v] [ | ]\r\n *\r\n * Then to find t, u, and v, use Cramer's Rule, the formulation of matrix determinant as column triple product,\r\n * and the fact that swapping any 2 vectors in the triple product negates it:\r\n *\r\n * t = (v2-v0).(rayOrigin - v0) x (v1-v0) / (v1-v0).rayVector x (v2-v0)\r\n * u = (rayOrigin - v0).rayVector x (v2-v0) / (v1-v0).rayVector x (v2-v0)\r\n * v = -rayVector.(rayOrigin - v0) x (v1-v0) / (v1-v0).rayVector x (v2-v0)\r\n *\r\n * Note that we verify 0 <= u,v,w <= 1. To do so we only need to check 0 <= u <= 1, 0 <= v, and u+v <= 1:\r\n * these 4 checks guarantee that v <= 1 and 0 <= u+v, and so with w = 1-(u+v), we have 0 <= w <= 1.\r\n *\r\n * More info be found at https://en.wikipedia.org/wiki/Moller-Trumbore_intersection_algorithm.\r\n */\r\n if (distanceTol === undefined || distanceTol < 0) // we explicitly allow zero tolerance\r\n distanceTol = Geometry.smallMetricDistance;\r\n if (parameterTol === undefined || parameterTol < 0) // we explicitly allow zero tolerance\r\n parameterTol = Geometry.smallFloatingPoint;\r\n const edge1 = Ray3d._workVector0 = Vector3d.createStartEnd(vertex0, vertex1, Ray3d._workVector0);\r\n const edge2 = Ray3d._workVector1 = Vector3d.createStartEnd(vertex0, vertex2, Ray3d._workVector1);\r\n const h = Ray3d._workVector2 = this.direction.crossProduct(edge2, Ray3d._workVector2);\r\n const a = edge1.dotProduct(h);\r\n if (a >= -distanceTol && a <= distanceTol)\r\n return undefined; // ray is parallel to the triangle (includes coplanar case)\r\n const f = 1.0 / a;\r\n const s = Ray3d._workVector3 = Vector3d.createStartEnd(vertex0, this.origin, Ray3d._workVector3);\r\n let u = f * s.dotProduct(h);\r\n if (u < 0.0) {\r\n if (u >= -parameterTol)\r\n u = 0.0;\r\n else\r\n return undefined; // ray does not intersect the triangle\r\n } else if (u > 1.0) {\r\n if (u <= 1.0 + parameterTol)\r\n u = 1.0;\r\n else\r\n return undefined; // ray does not intersect the triangle\r\n }\r\n const q = Ray3d._workVector4 = s.crossProduct(edge1, Ray3d._workVector4);\r\n let v = f * this.direction.dotProduct(q);\r\n if (v < 0.0) {\r\n if (v >= -parameterTol)\r\n v = 0.0;\r\n else\r\n return undefined; // ray does not intersect the triangle\r\n } else if (u + v > 1.0 + parameterTol) {\r\n return undefined; // ray does not intersect the triangle\r\n }\r\n // at this stage, we know the line (parameterized as the ray) intersects the triangle\r\n const t = f * edge2.dotProduct(q);\r\n if (t < -distanceTol) // line intersection but not ray intersection\r\n return undefined;\r\n return this.origin.plusScaled(this.direction, t, result); // ray intersection\r\n }\r\n /**\r\n * Return the shortest vector `v` to `targetPoint` from the line defined by this ray.\r\n * * If the projection of `targetPoint` onto the line defined by this ray is q, then `v = targetPoint - q`.\r\n */\r\n public perpendicularPartOfVectorToTarget(targetPoint: XYAndZ, result?: Vector3d): Vector3d {\r\n const vectorV = Vector3d.createStartEnd(this.origin, targetPoint);\r\n const uu = this.direction.magnitudeSquared();\r\n const uv = this.direction.dotProductStartEnd(this.origin, targetPoint);\r\n const fraction = Geometry.safeDivideFraction(uv, uu, 0.0);\r\n return vectorV.plusScaled(this.direction, -fraction, result);\r\n }\r\n /**\r\n * Determine if two rays intersect, or are fully overlapped, or parallel but not coincident, or skew.\r\n * * Return a CurveLocationDetailPair which contains fraction and point on each ray and has\r\n * annotation (in member `approachType`) indicating one of these relationships:\r\n * * CurveCurveApproachType.Intersection -- the rays have a simple intersection, at fractions indicated\r\n * in detailA and detailB\r\n * * CurveCurveApproachType.PerpendicularChord -- there is pair of where the rays have closest approach.\r\n * The rays are skew in space.\r\n * * CurveCurveApproachType.CoincidentGeometry -- the rays are the same unbounded line in space. The\r\n * fractions and points are a representative single common point.\r\n * * CurveCurveApproachType.Parallel -- the rays are parallel (and not coincident). The two points are\r\n * at the minimum distance\r\n */\r\n public static closestApproachRay3dRay3d(rayA: Ray3d, rayB: Ray3d): CurveLocationDetailPair {\r\n const intersectionFractions = Vector2d.create();\r\n let fractionA, fractionB;\r\n let pointA, pointB;\r\n let pairType;\r\n if (\r\n SmallSystem.ray3dXYZUVWClosestApproachUnbounded(\r\n rayA.origin.x, rayA.origin.y, rayA.origin.z, rayA.direction.x, rayA.direction.y, rayA.direction.z,\r\n rayB.origin.x, rayB.origin.y, rayB.origin.z, rayB.direction.x, rayB.direction.y, rayB.direction.z,\r\n intersectionFractions,\r\n )\r\n ) {\r\n fractionA = intersectionFractions.x;\r\n fractionB = intersectionFractions.y;\r\n pointA = rayA.fractionToPoint(fractionA);\r\n pointB = rayB.fractionToPoint(fractionB);\r\n pairType = pointA.isAlmostEqualMetric(pointB) ?\r\n CurveCurveApproachType.Intersection : CurveCurveApproachType.PerpendicularChord;\r\n } else {\r\n fractionB = 0.0;\r\n fractionA = rayA.pointToFraction(rayB.origin);\r\n pointA = rayA.fractionToPoint(fractionA);\r\n pointB = rayB.fractionToPoint(fractionB);\r\n pairType = pointA.isAlmostEqualMetric(pointB) ?\r\n CurveCurveApproachType.CoincidentGeometry : CurveCurveApproachType.ParallelGeometry;\r\n }\r\n const pair = CurveLocationDetailPair.createCapture(\r\n CurveLocationDetail.createRayFractionPoint(rayA, fractionA, rayA.fractionToPoint(fractionA)),\r\n CurveLocationDetail.createRayFractionPoint(rayB, fractionB, rayB.fractionToPoint(fractionB)));\r\n pair.approachType = pairType;\r\n return pair;\r\n }\r\n /**\r\n * Return a ray with `ray.origin` interpolated between `pt1` and `pt2` at the given `fraction`\r\n * and `ray.direction` set to the vector from `pt1` to `pt2` multiplied by the given `tangentScale`.\r\n * @param pt1 start point of the interpolation.\r\n * @param fraction fractional position between points.\r\n * @param pt2 end point of the interpolation.\r\n * @param tangentScale scale factor to apply to the startToEnd vector.\r\n * @param result optional receiver.\r\n */\r\n public static interpolatePointAndTangent(\r\n pt1: XYAndZ, fraction: number, pt2: XYAndZ, tangentScale: number, result?: Ray3d,\r\n ): Ray3d {\r\n result = result ?? Ray3d.createZero();\r\n const dx = pt2.x - pt1.x;\r\n const dy = pt2.y - pt1.y;\r\n const dz = pt2.z - pt1.z;\r\n result.direction.set(tangentScale * dx, tangentScale * dy, tangentScale * dz);\r\n if (fraction <= 0.5)\r\n result.origin.set(pt1.x + fraction * dx, pt1.y + fraction * dy, pt1.z + fraction * dz);\r\n else {\r\n const t: number = fraction - 1.0;\r\n result.origin.set(pt2.x + t * dx, pt2.y + t * dy, pt2.z + t * dz);\r\n }\r\n return result;\r\n }\r\n}\r\n"]}
|
|
@@ -77,7 +77,7 @@ export declare abstract class NewtonEvaluatorRtoRD {
|
|
|
77
77
|
/**
|
|
78
78
|
* Newton iterator for use when both function and derivative can be evaluated.
|
|
79
79
|
* To solve `f(x) = 0`, the Newton iteration is `x_{n+1} = x_n - dx = x_n - f(x_n)/f'(x_n)`.
|
|
80
|
-
* To solve `f(x) = target` which is equivalent to solving
|
|
80
|
+
* To solve `f(x) = target` which is equivalent to solving `g(x) = f(x) - target = 0`, the Newton iteration is
|
|
81
81
|
* `x_{n+1} = x_n - dx = x_n - g(x_n)/g'(x_n) = x_n - (f(x_n)-target)/f'(x_n)`.
|
|
82
82
|
* @internal
|
|
83
83
|
*/
|
|
@@ -89,7 +89,7 @@ export class NewtonEvaluatorRtoRD {
|
|
|
89
89
|
/**
|
|
90
90
|
* Newton iterator for use when both function and derivative can be evaluated.
|
|
91
91
|
* To solve `f(x) = 0`, the Newton iteration is `x_{n+1} = x_n - dx = x_n - f(x_n)/f'(x_n)`.
|
|
92
|
-
* To solve `f(x) = target` which is equivalent to solving
|
|
92
|
+
* To solve `f(x) = target` which is equivalent to solving `g(x) = f(x) - target = 0`, the Newton iteration is
|
|
93
93
|
* `x_{n+1} = x_n - dx = x_n - g(x_n)/g'(x_n) = x_n - (f(x_n)-target)/f'(x_n)`.
|
|
94
94
|
* @internal
|
|
95
95
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Newton.js","sourceRoot":"","sources":["../../../src/numerics/Newton.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAO/F,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAA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GAAG,OAAO,GAAG,OAAO,EACzE,GAAG,CACJ,CAAC;QACF,OAAO,IAAI,CAAC;IACd,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 { CurvePrimitive } from \"../curve/CurvePrimitive\";\r\nimport { Geometry } from \"../Geometry\";\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 \"./SmallSystem\";\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, maxIterations?: number) {\r\n super(undefined, undefined, maxIterations);\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, maxIterations?: number) {\r\n super(undefined, undefined, maxIterations);\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, maxIterations?: number) {\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 // 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 return false;\r\n const fA = this._func.currentF;\r\n const jCol0 = fA.vectorU;\r\n const jCol1 = fA.vectorV;\r\n const fX = fA.origin;\r\n // 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 if (SmallSystem.linearSystem2d(jCol0.x, jCol1.x, jCol0.y, jCol1.y, fX.x, fX.y, this._currentStep))\r\n return true;\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"]}
|
|
1
|
+
{"version":3,"file":"Newton.js","sourceRoot":"","sources":["../../../src/numerics/Newton.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAO/F,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;AAElE,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,+BAA+B;AAE/B;;;;GAIG;AACH,MAAM,OAAgB,sBAAsB;IAa1C;;;;;;;;;;;OAWG;IACH,YACE,oBAA4B,OAAO,EACnC,8BAAsC,CAAC,EACvC,gBAAwB,EAAE;QAE1B,IAAI,CAAC,kBAAkB,GAAG,iBAAiB,CAAC;QAC5C,IAAI,CAAC,4BAA4B,GAAG,2BAA2B,CAAC;QAChE,IAAI,CAAC,cAAc,GAAG,aAAa,CAAC;IACtC,CAAC;IACD,sEAAsE;IAC5D,YAAY,GAAW,CAAC,CAAC;IACnC,gDAAgD;IACtC,4BAA4B,CAAS;IAC/C,4FAA4F;IAClF,kBAAkB,CAAS;IACrC,8BAA8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AC,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","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 { CurvePrimitive } from \"../curve/CurvePrimitive\";\r\nimport { Geometry } from \"../Geometry\";\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 \"./SmallSystem\";\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, maxIterations?: number) {\r\n super(undefined, undefined, maxIterations);\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, maxIterations?: number) {\r\n super(undefined, undefined, maxIterations);\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, maxIterations?: number) {\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 // 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 return false;\r\n const fA = this._func.currentF;\r\n const jCol0 = fA.vectorU;\r\n const jCol1 = fA.vectorV;\r\n const fX = fA.origin;\r\n // 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 if (SmallSystem.linearSystem2d(jCol0.x, jCol1.x, jCol0.y, jCol1.y, fX.x, fX.y, this._currentStep))\r\n return true;\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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itwin/core-geometry",
|
|
3
|
-
"version": "5.4.0
|
|
3
|
+
"version": "5.4.0",
|
|
4
4
|
"description": "iTwin.js Core Geometry library",
|
|
5
5
|
"main": "lib/cjs/core-geometry.js",
|
|
6
6
|
"module": "lib/esm/core-geometry.js",
|
|
@@ -31,11 +31,11 @@
|
|
|
31
31
|
"rimraf": "^6.0.1",
|
|
32
32
|
"typescript": "~5.6.2",
|
|
33
33
|
"vitest": "^3.0.6",
|
|
34
|
-
"@itwin/build-tools": "5.4.0
|
|
34
|
+
"@itwin/build-tools": "5.4.0"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"flatbuffers": "~1.12.0",
|
|
38
|
-
"@itwin/core-bentley": "5.4.0
|
|
38
|
+
"@itwin/core-bentley": "5.4.0"
|
|
39
39
|
},
|
|
40
40
|
"scripts": {
|
|
41
41
|
"build": "npm run -s build:cjs && npm run -s build:esm",
|