UNPKG

@bitbybit-dev/base

Version:

Bit By Bit Developers Base CAD Library to Program Geometry

66 lines (65 loc) 3.81 kB
import * as Inputs from "../inputs"; export declare class GeometryHelper { /** * Applies one or more 4×4 transformation matrices to a list of points sequentially. * Each transformation is applied in order (composition of transformations). * Example: points=[[0,0,0], [1,0,0]] with translation [5,0,0] → [[5,0,0], [6,0,0]] */ transformControlPoints(transformation: number[][] | number[][][], transformedControlPoints: Inputs.Base.Point3[]): Inputs.Base.Point3[]; /** * Flattens nested transformation arrays into a single-level array of transformation matrices. * Handles both 2D arrays (single transform list) and 3D arrays (nested transform lists). * Example: [[[matrix1, matrix2]], [[matrix3]]] → [matrix1, matrix2, matrix3] */ getFlatTransformations(transformation: number[][] | number[][][]): number[][]; /** * Calculates the nesting depth of an array recursively. * Example: [1,2,3] → 1, [[1,2],[3,4]]2, [[[1]]] → 3 */ getArrayDepth: (value: any) => number; /** * Applies a single 4×4 transformation matrix (as flat 16-element array) to multiple points. * Example: points=[[0,0,0], [1,0,0]] with translation matrix → transformed points */ transformPointsByMatrixArray(points: Inputs.Base.Point3[], transform: number[]): Inputs.Base.Point3[]; /** * Transforms multiple points using a transformation matrix (maps each point through the matrix). * Example: points=[[1,0,0], [0,1,0]] with 90° rotation → [[0,1,0], [-1,0,0]] */ transformPointsCoordinates(points: Inputs.Base.Point3[], transform: number[]): Inputs.Base.Point3[]; /** * Removes all duplicate vectors from a list (works with arbitrary-length numeric vectors). * Compares vectors using tolerance for floating-point equality. * Example: [[1,2], [3,4], [1,2], [5,6]] with tolerance=1e-7[[1,2], [3,4], [5,6]] */ removeAllDuplicateVectors(vectors: number[][], tolerance?: number): number[][]; /** * Removes consecutive duplicate vectors from a list (keeps only first occurrence in each sequence). * Optionally checks and removes duplicate if first and last vectors match. * Example: [[1,2], [1,2], [3,4], [3,4], [5,6]][[1,2], [3,4], [5,6]] */ removeConsecutiveVectorDuplicates(vectors: number[][], checkFirstAndLast?: boolean, tolerance?: number): number[][]; /** * Compares two vectors for approximate equality using tolerance (element-wise comparison). * Returns false if vectors have different lengths. * Example: [1.0000001, 2.0], [1.0, 2.0] with tolerance=1e-6true */ vectorsTheSame(vec1: number[], vec2: number[], tolerance: number): boolean; /** * Checks if two numbers are approximately equal within a tolerance. * Example: 1.0000001, 1.0 with tolerance=1e-6true, 1.001, 1.0 with tolerance=1e-6false */ approxEq(num1: number, num2: number, tolerance: number): boolean; /** * Removes consecutive duplicate points from a list (specialized for 3D/2D points). * Optionally checks and removes duplicate if first and last points match (for closed loops). * Example: [[0,0,0], [0,0,0], [1,0,0], [1,0,0]][[0,0,0], [1,0,0]] */ removeConsecutivePointDuplicates(points: Inputs.Base.Point3[], checkFirstAndLast?: boolean, tolerance?: number): Inputs.Base.Point3[]; /** * Checks if two points are approximately equal using tolerance (supports 2D and 3D points). * Example: [1.0000001, 2.0, 3.0], [1.0, 2.0, 3.0] with tolerance=1e-6true */ arePointsTheSame(pointA: Inputs.Base.Point3 | Inputs.Base.Point2, pointB: Inputs.Base.Point3 | Inputs.Base.Point2, tolerance: number): boolean; private transformCoordinates; }