import type { Closed, Interval } from '../interval/interval.ts'; import type { Pipeable } from '../utils.ts'; import type * as Solution from '../solution/solution.ts'; import type { Vector2 } from '../vector/vector2.ts'; import type { LinearPolynomialTypeId } from './linear.internal.ts'; import type { GuaranteedMonotonicity } from '../monotonicity/monotonicity.ts'; import type { QuadraticPolynomial } from './quadratic.ts'; import type { Decreasing, Increasing, Monotonic, PolynomialTraits } from './traits.ts'; export type { Monotonic, Increasing, Decreasing } from './traits.ts'; /** * A linear polynomial. * * All fields are readonly and immutable, and all operations create new instances. * * The `Traits` type parameter is a phantom marker that accumulates trait * brands as the polynomial is refined via `isMonotonic` / `asMonotonic` and * friends. The runtime value carries no trait data — `Traits` only flows * through the type system to enable tighter return types on operations like * `solveInverse`. * * @since 1.0.0 */ export interface LinearPolynomial extends Pipeable { readonly [LinearPolynomialTypeId]: LinearPolynomialTypeId; readonly [PolynomialTraits]: Traits; /** * The coefficient of the x^0 term. */ readonly c0: number; /** * The coefficient of the x^1 term. */ readonly c1: number; } /** * Checks if a value is a `LinearPolynomial`. * * @param v - The value to check. * @returns `true` if the value is a `LinearPolynomial`, `false` otherwise. * @since 1.0.0 */ export declare const isLinearPolynomial: (v: unknown) => v is LinearPolynomial; export declare const equals: { /** * Checks if two `LinearPolynomial` instances are approximately equal within * the default absolute tolerance ({@link EPSILON}). * * @param a - The first polynomial. * @param b - The second polynomial. * @returns `true` when each pair of coefficients is within tolerance. * @since 1.1.0 */ (a: LinearPolynomial, b: LinearPolynomial): boolean; /** * Checks if two `LinearPolynomial` instances are approximately equal within * the default absolute tolerance ({@link EPSILON}). * * @param b - The second polynomial. * @returns A function that takes the first polynomial and returns the comparison result. * @since 1.1.0 */ (b: LinearPolynomial): (a: LinearPolynomial) => boolean; }; /** * Creates a new `LinearPolynomial` instance. * * @param c0 - The coefficient of the x^0 term. Defaults to 0. * @param c1 - The coefficient of the x^1 term. Defaults to 0. * @returns A new `LinearPolynomial` instance. * @since 1.0.0 */ export declare const make: (c0?: number, c1?: number) => LinearPolynomial; /** * Creates a new `LinearPolynomial` instance from a vector. * * @param v - The vector to create the polynomial from. * @returns A new `LinearPolynomial` instance. * @since 1.0.0 */ export declare const fromVector: (v: Vector2) => LinearPolynomial; /** * Creates a new `LinearPolynomial` instance from a point and slope. * * @param p - The point on the line. * @param slope - The slope of the line. * @returns A new `LinearPolynomial` instance. * @since 1.0.0 */ export declare const fromPointSlope: (p: Vector2, slope: number) => LinearPolynomial; /** * Creates a new `LinearPolynomial` instance from two points. * * @param p1 - The first point. * @param p2 - The second point. * @returns A new `LinearPolynomial` instance. * @since 1.0.0 */ export declare const fromPoints: (p1: Vector2, p2: Vector2) => LinearPolynomial; export declare const solve: { /** * Solves a linear polynomial for a given value of x. * * @param p - The linear polynomial to solve. * @param x - The value of x to solve for. * @returns The result of the polynomial evaluated at x. * @since 1.0.0 */ (p: LinearPolynomial, x: number): number; /** * Solves a linear polynomial for a given value of x. * * @param x - The value of x to solve for. * @returns A function that takes a `LinearPolynomial` and returns the result of the polynomial evaluated at x. * @since 1.0.0 */ (x: number): (p: LinearPolynomial) => number; }; /** * Converts a linear polynomial to a solver function. * * @param p - The linear polynomial to convert. * @returns A function that takes a value of x and returns the result of the polynomial evaluated at x. * @since 1.0.0 */ export declare const toSolver: (p: LinearPolynomial) => (x: number) => number; export declare const solveInverse: { /** * Solves a monotonic linear polynomial for a given value of y. Because the * polynomial is strictly monotonic, the inverse always has exactly one * solution — wrapped in `Solution.One`. * * @param p - The monotonic linear polynomial to solve. * @param y - The value of y to solve for. * @since 2.0.0 */ (p: LinearPolynomial, y: number): Solution.One; /** * Solves a linear polynomial for a given value of y. Returns `Solution.none` * for constant polynomials (no inverse). * * @param p - The linear polynomial to solve. * @param y - The value of y to solve for. * @since 1.0.0 */ (p: LinearPolynomial, y: number): Solution.AtMostOne; /** @since 1.0.0 */ (y: number): { (p: LinearPolynomial): Solution.One; (p: LinearPolynomial): Solution.AtMostOne; }; }; /** * Converts a linear polynomial to an inverse solver function. * * @param p - The linear polynomial to convert. * @since 1.0.0 */ export declare const toInverseSolver: (p: LinearPolynomial) => (y: number) => Solution.AtMostOne; /** * Finds the roots of a linear polynomial. * * @param p - The linear polynomial to find the roots of. * @since 1.0.0 */ export declare const root: (p: LinearPolynomial) => Solution.AtMostOne; /** * Calculates the monotonicity of a linear polynomial. * * @param p - The linear polynomial to check. * @returns The guaranteed monotonicity of the polynomial. * @since 1.0.0 */ export declare const monotonicity: (p: LinearPolynomial) => GuaranteedMonotonicity; /** * Type-narrowing predicate: refines a `LinearPolynomial` to * `LinearPolynomial` when the polynomial is strictly monotonic. * * @param p - The linear polynomial to check. * @returns `true` when `monotonicity(p)` is `Increasing` or `Decreasing`. * @since 2.0.0 */ export declare const isMonotonic: (p: LinearPolynomial) => p is LinearPolynomial; /** * Type-narrowing predicate: refines to `LinearPolynomial`. * * @param p - The linear polynomial to check. * @returns `true` when `monotonicity(p)` is `Increasing`. * @since 2.0.0 */ export declare const isIncreasing: (p: LinearPolynomial) => p is LinearPolynomial; /** * Type-narrowing predicate: refines to `LinearPolynomial`. * * @param p - The linear polynomial to check. * @returns `true` when `monotonicity(p)` is `Decreasing`. * @since 2.0.0 */ export declare const isDecreasing: (p: LinearPolynomial) => p is LinearPolynomial; /** * Asserts that the linear polynomial is monotonic, throwing on failure. * * @param p - The linear polynomial to assert against. * @returns The same polynomial, typed with the `Monotonic` brand. * @throws When `monotonicity(p)` is `Constant`. * @since 2.0.0 */ export declare const asMonotonic: (p: LinearPolynomial) => LinearPolynomial; /** * Asserts that the linear polynomial is increasing, throwing on failure. * * @param p - The linear polynomial to assert against. * @returns The same polynomial, typed with the `Increasing` brand. * @throws When `monotonicity(p)` is not `Increasing`. * @since 2.0.0 */ export declare const asIncreasing: (p: LinearPolynomial) => LinearPolynomial; /** * Asserts that the linear polynomial is decreasing, throwing on failure. * * @param p - The linear polynomial to assert against. * @returns The same polynomial, typed with the `Decreasing` brand. * @throws When `monotonicity(p)` is not `Decreasing`. * @since 2.0.0 */ export declare const asDecreasing: (p: LinearPolynomial) => LinearPolynomial; /** * Returns the polynomial's coefficients as a tuple `[c0, c1]`. * * @param p - The linear polynomial. * @returns The coefficients in monomial order. * @since 2.0.0 */ export declare const coefficients: (p: LinearPolynomial) => readonly [number, number]; /** * Calculates the derivative of a linear polynomial. * * @param p - The linear polynomial to differentiate. * @returns The derivative of the linear polynomial. * @since 1.0.0 */ export declare const derivative: (p: LinearPolynomial) => number; export declare const antiderivative: { /** * Calculates the antiderivative of a linear polynomial. * * @param p - The linear polynomial to integrate. * @param constant - The constant of integration. Defaults to 0. * @returns The antiderivative of the linear polynomial. * @since 1.0.0 */ (p: LinearPolynomial, constant?: number): QuadraticPolynomial; /** * Calculates the antiderivative of a linear polynomial. * * @param constant - The constant of integration. Defaults to 0. * @returns A function that takes a `LinearPolynomial` and returns the antiderivative of the polynomial. * @since 1.0.0 */ (constant: number): (p: LinearPolynomial) => QuadraticPolynomial; }; export declare const domain: { /** * Calculates the domain of a linear polynomial. * * @param p - The linear polynomial to check. * @param range - The range to check against. * @returns The domain of the polynomial within the given range. * @since 1.0.0 */ (p: LinearPolynomial, range: Interval): Solution.AtMostOne; /** * Calculates the domain of a linear polynomial. * * @param range - The range to check against. * @returns A function that takes a `LinearPolynomial` and returns the domain of the polynomial within the given range. * @since 1.0.0 */ (range: Interval): (p: LinearPolynomial) => Solution.AtMostOne; }; export declare const range: { /** * Calculates the range of a linear polynomial. * * @param p - The linear polynomial to check. * @param domain - The domain to check against. * @returns The range of the polynomial within the given domain. * @since 1.0.0 */ (p: LinearPolynomial, domain: Interval): Closed; /** * Calculates the range of a linear polynomial. * * @param domain - The domain to check against. * @returns A function that takes a `LinearPolynomial` and returns the range of the polynomial within the given domain. * @since 1.0.0 */ (domain: Interval): (p: LinearPolynomial) => Closed; }; /** * Calculates the range of a linear polynomial over the unit interval `[0, 1]`. * Equivalent to `range(p, Interval.unit)` but without the import and call * overhead — directly evaluates the endpoints. * * @param p - The linear polynomial. * @returns The closed range of the polynomial over `[0, 1]`. * @since 2.0.0 */ export declare const unitRange: (p: LinearPolynomial) => Closed; export declare const length: { /** * Calculates the length of a linear polynomial within a particular domain `Interval`. * * @param p - The linear polynomial to analyze. * @param domain - The domain to restrict the analysis to. * @returns The length of the linear polynomial in the specified domain. * @since 1.0.0 */ (p: LinearPolynomial, domain: Interval): number; /** * Calculates the length of a linear polynomial within a particular domain `Interval`. * * @param domain - The domain to restrict the analysis to. * @returns A function that takes a `LinearPolynomial` and returns the length of the polynomial in the specified domain. * @since 1.0.0 */ (domain: Interval): (p: LinearPolynomial) => number; };