@numericelements/knot-sequence
Version:
A library for generating and manipulating knot sequences for b-spline curves and surfaces
280 lines • 15 kB
TypeScript
import { Knot } from "./Knot";
import { IncreasingOpenKnotSequence, IncreasingOpenKnotSequenceCCurve, IncreasingOpenKnotSequenceCCurve_allKnots, IncreasingOpenKnotSequenceUpToC0Discontinuity, IncreasingOpenKnotSequenceUpToC0DiscontinuityCCurve_allKnots, IncreasingPeriodicKnotSequence, StrictIncreasingPeriodicKnotSequence, StrictlyIncreasingOpenKnotSequence, StrictlyIncreasingOpenKnotSequenceCCurve, StrictlyIncreasingOpenKnotSequenceCCurvee_allKnots, StrictlyIncreasingOpenKnotSequenceUpToC0Discontinuity, StrictlyIncreasingOpenKnotSequenceUpToC0DiscontinuityCCurvee_allKnots, Uniform_OpenKnotSequence, Uniform_PeriodicKnotSequence, UniformlySpreadInterKnots_OpenKnotSequence } from "./KnotSequenceConstructorInterface";
import { KnotIndexStrictlyIncreasingSequence } from "./KnotIndexStrictlyIncreasingSequence";
/**
* Abstract base class for knot sequences used in B-spline entities (curves or surfaces).
*
* @description
* Provides common functionality for managing and validating knot sequences
* with different knot multiplicity orders and spacing characteristics.
* This base class covers increasing and strictly increasing knot sequences, open and periodic knot sequences.
* All these categories enable the description of open and closed curves and surfaces.
* Derived classes from this class are responsible for implementing all categories of open knot sequences, on the one hand, and periodic knot sequences, on the other hand.
* The internal representation of the knot sequence is an array of Knot objects describing the sequence as a strictly increasing sequence of knots.
*
* @abstract
*/
export declare abstract class AbstractKnotSequence {
protected abstract knotSequence: Array<Knot>;
protected abstract _indexKnotOrigin: KnotIndexStrictlyIncreasingSequence;
protected _maxMultiplicityOrder: number;
protected _isKnotSpacingUniform: boolean;
protected _isKnotMultiplicityUniform: boolean;
/**
* Creates a new knot sequence with specified maximum multiplicity order.
*
* @param maxMultiplicityOrder - Maximum allowed multiplicity for any knot
*
*/
constructor(maxMultiplicityOrder: number);
/**
* Gets the maximum allowed multiplicity order for knots in the sequence.
*
* @returns {number} Maximum multiplicity order
*/
get maxMultiplicityOrder(): number;
/**
* Indicates if knot spacing is uniform across the sequence.
*
* @returns {boolean} True if knot spacing is uniform
*/
get isKnotSpacingUniform(): boolean;
/**
* Indicates if knot multiplicity is uniform across the sequence.
*
* @returns {boolean} True if knot multiplicity is uniform
*/
get isKnotMultiplicityUniform(): boolean;
abstract checkNonUniformKnotMultiplicityOrder(): void;
protected abstract decrementKnotMultiplicityMutSeq(index: KnotIndexStrictlyIncreasingSequence): void;
/**
* Generates and throws a RangeError with formatted error message.
*
* @param functionName - Name of the function where error occurred
* @param message - Error message to include
* @throws {RangeError} With formatted error message
*
* @example
* this.throwRangeErrorMessage("constructor", "Invalid multiplicity order");
*/
protected throwRangeErrorMessage(functionName: string, message: string): void;
/**
* Validates that the maximum multiplicity order of a knot sequence is greater than or equal to the minimum allowed value.
*
* @param minValue - Minimum allowed value for maximum multiplicity order
* @throws {RangeError} If maxMultiplicityOrder is less than minValue
*
* @example
* this.constructorInputMultOrderAssessment(3);
*/
protected constructorInputMultOrderAssessment(minValue: number): void;
/**
* Validates that a knot multiplicity does not exceed the maximum multiplicity order assigned to a knot sequence.
*
* @param multiplicity - The knot multiplicity value to validate
* @param methodName - Name of the calling method for error reporting
* @throws {RangeError} If multiplicity exceeds maxMultiplicityOrder
*
* @example
* const multiplicity = 3;
* const methodName = "checkMaxMultiplicityOrderConsistency";
* this.maxMultiplicityOrderInputParamAssessment(multiplicity, methodName);
*/
protected maxMultiplicityOrderInputParamAssessment(multiplicity: number, methodName: string): void;
/**
* Assesses the input array parameters for the constructor of the `AbstractKnotSequence` class hierarchy.
*
* @param knotParameters - An object containing the knot sequence parameters.
* @throws {RangeError} If the input parameters are invalid.
*
* @description
* This method checks the validity of the `knotParameters` object, which can be of type `IncreasingOpenKnotSequence`,
* `IncreasingOpenKnotSequenceCCurve_allKnots`, or `IncreasingOpenKnotSequenceUpToC0Discontinuity`...., i.e. all knot sequences that use knot abscissae as input parameters.
* It ensures that the knot sequence and multiplicity arrays have the correct lengthes.
*
* @example
* const knotParams = {
* type: INCREASINGOPENKNOTSEQUENCE,
* knots: [0, 0, 0, 1, 2, 3, 3, 3]
* };
* this.constructorInputArrayAssessment(knotParams);
*/
protected constructorInputArrayAssessment(knotParameters: IncreasingOpenKnotSequence | IncreasingOpenKnotSequenceCCurve_allKnots | IncreasingOpenKnotSequenceUpToC0Discontinuity | IncreasingOpenKnotSequenceCCurve | IncreasingOpenKnotSequenceUpToC0DiscontinuityCCurve_allKnots | StrictlyIncreasingOpenKnotSequence | StrictlyIncreasingOpenKnotSequenceCCurve | StrictlyIncreasingOpenKnotSequenceCCurvee_allKnots | StrictlyIncreasingOpenKnotSequenceUpToC0Discontinuity | StrictlyIncreasingOpenKnotSequenceUpToC0DiscontinuityCCurvee_allKnots | IncreasingPeriodicKnotSequence | StrictIncreasingPeriodicKnotSequence): void;
/**
* Validates B-spline basis size requirements for uniform knot sequences to ensure that a normalized basis exists given the maxMultiplicityOrder assigned to the knot sequence.
* For open sequences: basis size must be >= maxMultiplicityOrder
* For periodic sequences: basis size must be >= (maxMultiplicityOrder + 1)
*
* @param knotParameters - Parameters containing B-spline basis size
* @throws {RangeError} If basis size requirements are not met
*
* @example
* const params = {
* type: UNIFORM_OPENKNOTSEQUENCE,
* BsplBasisSize: 4
* };
* this.constructorInputBspBasisSizeAssessment(params);
*/
protected constructorInputBspBasisSizeAssessment(knotParameters: Uniform_OpenKnotSequence | UniformlySpreadInterKnots_OpenKnotSequence | Uniform_PeriodicKnotSequence): void;
/**
* Validates that a knot index is within valid bounds of the sequence.
*
* @param index - Index to validate in the strictly increasing representation of the knot sequence
* @param methodName - Name of calling method for error reporting
* @throws {RangeError} If index is out of valid range
*
* @example
* const index = new KnotIndexStrictlyIncreasingSequence(1);
* this.strictlyIncKnotIndexInputParamAssessment(index, "knotMultiplicity");
*/
protected strictlyIncKnotIndexInputParamAssessment(index: KnotIndexStrictlyIncreasingSequence, methodName: string): void;
/**
* Finds a span in an increasing knot sequence where the abscissa is distinct from knots.
*
* @description
* Locates a span between two consecutive distinct knots where the given abscissa lies,
* accounting for knots with multiplicity greater than 1.
* The method does not ensure the abscissa is not coincident with any knot in the sequence.
* This method is called by the findSpan method. The findSpan checks the validity of the asbcissa
* as well as the coincidence of the abscissa with knots.
* Performs a binary search to find the knot index characterizing the span.
*
* @param abscissa - The abscissa value to locate in the sequence
* @param warningLog - Index of the knot defining the right bound of normalized basis interval. Defaults to the last knot index.
* The index value is defined from the strictly increasing representation of the knot sequence.
* @returns The index of the knot defining the span containing the abscissa within the increasing knot sequence.
*
* @example
* // For sequence [0,0,0,1,2,3,3,3], maxMultiplicityOrder = 3 and abscissa 1.5
* const span = knotSequence.findSpanWithAbscissaDistinctFromKnotIncreasingKnotSequence(1.5);
* // Returns 3 (span between knots at indices 3 and 4)
*
* @example
* // For sequence [-2,-1,0,1,2,3,4,4,5,6,7], maxMultiplicityOrder = 3 and abscissa 4.999. targetIndex = 8.
* const span = knotSequence.findSpanWithAbscissaDistinctFromKnotIncreasingKnotSequence(4.999);
* // Returns 7 (span between knots at indices 7 and 8)
*/
protected findSpanWithAbscissaDistinctFromKnotIncreasingKnotSequence(u: number, targetIndex?: number): number;
/**
* Finds a span in a strictly increasing knot sequence where the abscissa is distinct from knots.
*
* @description
* Locates a span between two consecutive knots where the given abscissa lies.
* The method does not ensure the abscissa is not coincident with any knot in the sequence.
* This method is called by the findSpan method. The findSpan checks the validity of the asbcissa
* as well as the coincidence of the abscissa with knots.
* Performs a binary search to find the knot index characterizing the span.
*
* @param abscissa - The abscissa value to locate in the sequence
* @param targetIndex - Index of the knot defining the right bound of normalized basis interval. Defaults to the last knot index.
* @returns The index of the knot defining the span containing the abscissa within the strictly increasing knot sequence.
*
* @example
* // For a strictly increasing sequence [0.0, 0.5, 0.6, 0.7, 1] with multiplicities [4, 1, 1, 2, 4], maxMultiplicityOrder = 4 and abscissa 0.55
* const span = knotSequence.findSpanWithAbscissaDistinctFromKnotStrictlyIncreasingKnotSequence(0.55);
* // Returns 1 (span between knots at indices 1 and 2)
*
* @example
* // For a strictly increasing sequence [-2,-1,0,1,2,3,4,5] with multiplicities [1,1,1,1,1,1,1,1], maxMultiplicityOrder = 3 and abscissa 2.999
* const span = knotSequence.findSpanWithAbscissaDistinctFromKnotStrictlyIncreasingKnotSequence(2.999, 5);
* // Returns 4 (span between knots at indices 4 and 5)
*/
protected findSpanWithAbscissaDistinctFromKnotStrictlyIncreasingKnotSequence(u: number, targetIndex?: number): number;
/**
* Returns an array containing the distinct abscissa values of all knots in the knot sequence.
*
* @returns {number[]} Array of distinct knot abscissa values
*
* @example
* const abscissae = knotSequence.distinctAbscissae(); // [0, 1, 2, 3]
*/
distinctAbscissae(): number[];
/**
* Returns an array containing the multiplicities of all knots in the knot sequence.
*
* @returns {number[]} Array of knot multiplicities
*
* @example
* const multiplicities = knotSequence.multiplicities(); // [3, 1, 1, 3]
*/
multiplicities(): number[];
/**
* Verifies that no knot multiplicity exceeds the maximum multiplicity order
* assigned to the knot sequence.
*
* @throws {RangeError} If any knot multiplicity exceeds maxMultiplicityOrder
*
* @example
* knotSequence.checkMaxMultiplicityOrderConsistency(); // Validates all knot multiplicities
*/
checkMaxMultiplicityOrderConsistency(): void;
/**
* Checks uniformity of knot spacing in the sequence.
* Updates isKnotSpacingUniform property.
*/
checkUniformityOfKnotSpacing(): void;
/**
* Checks uniformity of knot multiplicity in the sequence.
* Updates isKnotMultiplicityUniform property.
*/
checkUniformityOfKnotMultiplicity(): void;
/**
* Verifies that intermediate knots don't exceed maximum multiplicity order assigned to the knot sequence.
*
* @throws {RangeError} If any intermediate knot exceeds max multiplicity
*/
checkMaxKnotMultiplicityAtIntermediateKnots(): void;
/**
* Verifies that knot values of the iterated knot sequence are in increasing order.
*
* @param knots - Array of knot values to check
* @throws {RangeError} If knots are not in increasing order
*/
checkKnotIncreasingValues(knots: number[]): void;
/**
* Verifies that knot values of the iterated knot sequence are in strictly increasing order.
*
* @param knots - Array of knot values to check
* @throws {RangeError} If knots are not in strictly increasing order
*/
checkKnotStrictlyIncreasingValues(knots: number[]): void;
/**
* Checks if a given abscissa value coincides with any knot in the sequence within the KNOT_COINCIDENCE_TOLERANCE tolerance.
*
* @param abscissa - Knot abscissa value to check for coincidence with knots of the sequence
* @returns {boolean} True if abscissa coincides with a knot
*
* @example
* const coincides = knotSequence.isAbscissaCoincidingWithKnot(1.0);
*/
isAbscissaCoincidingWithKnot(abscissa: number): boolean;
/**
* Checks if a given knot abscissa has zero multiplicity (no coincident knot).
*
* @param abscissa - Value to check for zero multiplicity
* @returns {boolean} True if abscissa has zero multiplicity
*
* @example
* const isZero = knotSequence.isKnotlMultiplicityZero(1.5);
*/
isKnotlMultiplicityZero(abscissa: number): boolean;
/**
* Gets the multiplicity of knot at specified index.
*
* @param index - Index of knot into a strictly increasing representation of the knot sequence
* @returns {number} Multiplicity of knot at index
*
* @example
* const mult = knotSequence.knotMultiplicity(new KnotIndexStrictlyIncreasingSequence(1));
*/
knotMultiplicity(index: KnotIndexStrictlyIncreasingSequence): number;
/**
* Reverses the knot spacing distribution in the sequence while preserving multiplicities and the origin of the knot sequence.
*
* @example
* knotSequence.revertKnotSpacing(); // [0,0,1,3,3] becomes [0,0,2,3,3] for an increasing open knot sequence describing an open curve
* knotSequence.revertKnotSpacing(); // [0,1,1.5,3] becomes [0,1.5,2,3] for an increasing periodic knot sequence describing a closed curve
*/
protected revertKnotSpacing(): void;
}
//# sourceMappingURL=AbstractKnotSequence.d.ts.map