/** @packageDocumentation * @module Numerics */ import { CurvePrimitive } from "../curve/CurvePrimitive"; import { Plane3dByOriginAndVectors } from "../geometry3d/Plane3dByOriginAndVectors"; import { Point3d } from "../geometry3d/Point3dVector3d"; /** * Base class for Newton iterations in various dimensions. * Dimension-specific classes carry all dimension-related data and answer generalized queries from this base class. * @internal */ export declare abstract class AbstractNewtonIterator { /** Compute a step. The current x and function values must be retained for use in later method calls. */ abstract computeStep(): boolean; /** * Return the current step size, scaled for use in tolerance tests. * * This is a single number, typically the max of various per-dimension `dx/(1+x)` for the x and dx of that dimension. */ abstract currentStepSize(): number; /** * Apply the current step (in all dimensions). * @param isFinalStep true if this is a final step. */ abstract applyCurrentStep(isFinalStep: boolean): void; /** * The constructor. * @param stepSizeTolerance tolerance to consider a single step converged. * This number should be "moderately" strict. Because 2 successive convergences are required, * it is expected that a first "accept" for (say) 10 to 14 digit step will be followed by another * iteration. A well behaved newton would then hypothetically double the number of digits to * 20 to 28. Since the IEEE double only carries 16 digits, this second-convergence step will * typically achieve full precision. Default [[Geometry.smallNewtonStep]]. * @param successiveConvergenceTarget number of successive convergences required for acceptance. Default 2. * @param maxIterations max number of iterations. A typical newton step converges in 3 to 6 iterations. * Allow 15 to 20 to catch difficult cases. Default 15. */ protected constructor(stepSizeTolerance?: number, successiveConvergenceTarget?: number, maxIterations?: number); /** Number of consecutive steps which passed convergence condition. */ protected _numAccepted: number; /** Target number of successive convergences. */ protected _successiveConvergenceTarget: number; /** Convergence target (the implementation-specific currentStepSize is compared to this). */ protected _stepSizeTolerance: number; /** Max iterations allowed. */ protected _maxIterations: number; /** Number of iterations (incremented at each step). */ numIterations: number; /** Get the relative tolerance for comparing iterations in [[testConvergence]]. */ get stepSizeTolerance(): number; /** Smallest iterate size difference in later iterations. */ private _leastDelta; /** * The current late iterate has the least delta encountered. Remember it. * * Implement this method along with [[restoreCandidate]]. */ protected cacheCandidate?(): void; /** * Set Newton result to the cached candidate. * * This is the best approximation to the root found during Newton iteration and may be useful to the caller * even when Newton fails to converge. * * Implement this method along with [[cacheCandidate]]. */ protected restoreCandidate?(): void; /** * Test if a step is converged. * * Convergence is accepted with enough (_successiveConvergenceTarget) small steps (according to _stepSizeTolerance) * occur in succession. * @param delta step size as reported by currentStepSize. */ testConvergence(delta: number): boolean; /** * Run iterations, calling various methods from base and derived classes: * * computeStep -- typically evaluate derivatives and solve linear system. * * currentStepSize -- return numeric measure of the step just computed by computeStep. * * testConvergence -- test if the step from currentStepSize (along with recent steps) is converged. * * applyCurrentStep -- apply the step to the independent variables. */ runIterations(): boolean; } /** * Object to evaluate a newton function. The object must retain most-recent function and derivative * values for immediate query. * @internal */ export declare abstract class NewtonEvaluatorRtoRD { /** Evaluate the function and its derivative at x. */ abstract evaluate(x: number): boolean; /** Most recent function value, i.e., f(x_n). */ currentF: number; /** Most recent evaluated derivative, i.e., f'(x_n). */ currentdFdX: number; } /** * Newton iterator for use when both function and derivative can be evaluated. * To solve `f(x) = 0`, the Newton iteration is `x_{n+1} = x_n - dx = x_n - f(x_n)/f'(x_n)`. * To solve `f(x) = target` which is equivalent to solving `g(x) = f(x) - target = 0`, the Newton iteration is * `x_{n+1} = x_n - dx = x_n - g(x_n)/g'(x_n) = x_n - (f(x_n)-target)/f'(x_n)`. * @internal */ export declare class Newton1dUnbounded extends AbstractNewtonIterator { private _func; /** Current step is dx. */ private _currentStep; /** Current X is x_n. */ private _currentX; /** The target */ private _target; /** * Constructor for 1D newton iteration with derivatives. * @param func function that returns both function value and derivative. */ constructor(func: NewtonEvaluatorRtoRD, maxIterations?: number); /** Set the independent variable, i.e., x_n. */ setX(x: number): void; /** Get the independent variable, i.e., x_n. */ getX(): number; /** Set the target function value. */ setTarget(y: number): void; /** Move the current X by the just-computed step, i.e., `x_n - dx`. */ applyCurrentStep(): void; /** Compute the univariate newton step dx. */ computeStep(): boolean; /** Return the current step size as a relative number, i.e., `|dx / (1 + |x_n|)|`. */ currentStepSize(): number; } /** * Object to evaluate a newton function (without derivative). The object must retain most-recent function value. * @internal */ export declare abstract class NewtonEvaluatorRtoR { /** Evaluate function value into member currentF */ abstract evaluate(x: number): boolean; /** Most recent function evaluation, i.e., f(x_n). */ currentF: number; } /** * Intermediate class for managing the parentCurve announcements from an IStrokeHandler. * @internal */ export declare abstract class NewtonRtoRStrokeHandler extends NewtonEvaluatorRtoR { protected _parentCurvePrimitive: CurvePrimitive | undefined; constructor(); /** * Retain the parentCurvePrimitive. * * Calling this method tells the handler that the parent curve is to be used for detail searches. * * Example: Transition spiral search is based on linestring first, then the exact spiral. * * Example: CurveChainWithDistanceIndex does NOT do this announcement; the constituents act independently. */ startParentCurvePrimitive(curve: CurvePrimitive | undefined): void; /** Forget the parentCurvePrimitive */ endParentCurvePrimitive(_curve: CurvePrimitive | undefined): void; } /** * Newton iteration for a univariate function, using approximate derivatives. * To approximate the derivatives we use a small step `h`, i.e., `f'(x_n) = (f(x_n + h) - f(x_n)) / h`. * Therefore, to solve `f(x) = 0`, the iteration is * `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))`. * @internal */ export declare class Newton1dUnboundedApproximateDerivative extends AbstractNewtonIterator { private _func; /** Current step is dx. */ private _currentStep; /** Current X is x_n. */ private _currentX; /** * Step size for approximate derivative for the iteration. * * Initialized to 1e-8, which is appropriate for iteration in fraction space. * * Should be larger for iteration with real distance as x. */ derivativeH: number; /** * Constructor for 1D newton iteration with approximate derivatives. * @param func function that only returns function value (and not derivative). */ constructor(func: NewtonEvaluatorRtoR, maxIterations?: number); /** Set the independent variable, i.e., x_n. */ setX(x: number): void; /** Get the independent variable, i.e., x_n. */ getX(): number; /** Move the current X by the just-computed step, i.e., `x_n - dx`. */ applyCurrentStep(): void; /** Univariate newton step dx, computed with approximate derivative. */ computeStep(): boolean; /** Return the current step size as a relative number, i.e., `|dx / (1 + |x_n|)|`. */ currentStepSize(): number; } /** * Object to evaluate a 2-parameter newton function with derivatives. * @internal */ export declare abstract class NewtonEvaluatorRRtoRRD { /** * Iteration controller calls this to ask for evaluation of the function and its two partial derivatives. * * The implementation returns true, it must set the currentF object. */ abstract evaluate(x: number, y: number): boolean; /** * Most recent function evaluation as parts of the plane. * * See doc of [[Newton2dUnboundedWithDerivative]] class for info on 2d newton method. * * For `F(u,v) := (x(u,v), y(u,v))` the returned plane stores the following evaluations at current value `X := (u,v)`: * * `origin` = F(X) = (x(X), y(X)) * * `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 * * `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 */ currentF: Plane3dByOriginAndVectors; /** * Constructor. * * This creates a currentF object to (repeatedly) receive function and derivatives. */ constructor(); } /** * Implement evaluation steps for newton iteration in 2 dimensions, using caller supplied NewtonEvaluatorRRtoRRD object. * * 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, * the 2D Newton's iteration to find a root of `F` is given by: * `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 * defined by the partial derivatives of the component functions of F: * * `[dx/du dx/dv]` * * `[dy/du dy/dv]` * @internal */ export declare class Newton2dUnboundedWithDerivative extends AbstractNewtonIterator { private _func; /** Current step, or dX = (du, dv). */ private _currentStep; /** Current uv parameters, or X_n = (u_n, v_n). */ private _currentUV; /** * Constructor for 2D newton iteration with derivatives. * @param func function that returns both function value and derivative. * @param maxIterations max number of iterations. Default 15. * @param stepSizeTolerance tolerance to consider a single step converged. Default [[Geometry.smallNewtonStep]]. */ constructor(func: NewtonEvaluatorRRtoRRD, maxIterations?: number, stepSizeTolerance?: number); /** Set the current uv parameters, i.e., `X_n = (u_n, v_n)`. */ setUV(u: number, v: number): void; /** Get the current u parameter of X_n, i.e., u_n. */ getU(): number; /** Get the current v parameter of X_n, i.e., v_n. */ getV(): number; /** Update the current uv parameter by currentStep, i.e., compute `X_{n+1} := X_n - dX = (u_n - du, v_n - dv)`. */ applyCurrentStep(): void; /** * Evaluate the functions and derivatives at `X_n = (u_n, v_n)`, and solve the Jacobian matrix equation to * compute `dX = (du, dv)`. */ computeStep(): boolean; /** * Return the current relative step size, i.e., the larger absolute component of `dX / (1 + |X_n|)` */ currentStepSize(): number; /** Candidate solution cache. */ private _cachedUV; /** The current late iterate has the least delta encountered. Remember it. */ protected cacheCandidate(): void; /** Set Newton result to the cached candidate. */ protected restoreCandidate(): void; } /** * SimpleNewton has static methods for newton methods with evaluated functions presented as immediate arguments * (not function object). * @internal */ export declare class SimpleNewton { /** * Run a one-dimensional newton iteration with separate functions for function and derivative. * * Completion is at 2 (TWO) successive passes at `absoluteTolerance + relTol * abs(x)`, where relTol is * chosen internally. * * `absoluteTolerance` is usually aggressively tight -- should come into play only for x near zero. * * The `relTol` is fluffy (for instance around 1e-11) but in properly converging cases the extra pass after * first success normally moves to full machine precision. * * This is an open-loop newton -- it just runs, and returns undefined if anything bad happens. */ static runNewton1D(x: number, func: (x: number) => number | undefined, derivative: (x: number) => number | undefined, absoluteTolerance?: number): number | undefined; } /** * Class to evaluate XY intersection between 2 curve primitives using the Newton method. * @internal */ export declare class CurveCurveIntersectionXYRRToRRD extends NewtonEvaluatorRRtoRRD { private _curveP; private _curveQ; private _rayP; private _rayQ; constructor(curveP: CurvePrimitive, curveQ: CurvePrimitive); evaluate(fractionU: number, fractionV: number): boolean; } /** * Class to evaluate XY close approach between a curve primitive and a point using the Newton method. * @internal */ export declare class CurvePointCloseApproachXYRtoRD extends NewtonEvaluatorRtoRD { private _curveP; private _pointQ; private _planeP; constructor(curveP: CurvePrimitive, pointQ: Point3d); evaluate(fractionU: number): boolean; } /** * Class to evaluate XY close approach between 2 curve primitives using the Newton method. * @internal */ export declare class CurveCurveCloseApproachXYRRtoRRD extends NewtonEvaluatorRRtoRRD { private _curveP; private _curveQ; private _planeP; private _planeQ; constructor(curveP: CurvePrimitive, curveQ: CurvePrimitive); evaluate(fractionU: number, fractionV: number): boolean; } //# sourceMappingURL=Newton.d.ts.map