@bitbybit-dev/base
Version:
Bit By Bit Developers Base CAD Library to Program Geometry
162 lines (161 loc) • 7.22 kB
TypeScript
import { Base } from "../inputs/base-inputs";
import * as Inputs from "../inputs";
import { MathBitByBit } from "./math";
import { Vector } from "./vector";
/**
* Transformations help to move, scale, rotate objects. You can combine multiple transformations
* for object to be placed exactly into position and orientation that you want.
* Contains various methods for transformations that represent 4x4 matrixes in flat 16 number arrays.
*/
export declare class Transforms {
private readonly vector;
private readonly math;
constructor(vector: Vector, math: MathBitByBit);
/**
* Creates rotation transformations around a center point and custom axis.
* Combines translation to origin, axis rotation, then translation back.
* Example: center=[5,0,0], axis=[0,1,0], angle=90° → rotates around vertical axis through point [5,0,0]
* @param inputs Rotation around center with an axis information
* @returns array of transformations
* @group rotation
* @shortname center axis
* @drawable false
*/
rotationCenterAxis(inputs: Inputs.Transforms.RotationCenterAxisDto): Base.TransformMatrixes;
/**
* Creates rotation transformations around a center point along the X axis.
* Example: center=[5,5,5], angle=90° → rotates 90° around X axis through point [5,5,5]
* @param inputs Rotation around center with an X axis information
* @returns array of transformations
* @group rotation
* @shortname center x
* @drawable false
*/
rotationCenterX(inputs: Inputs.Transforms.RotationCenterDto): Base.TransformMatrixes;
/**
* Creates rotation transformations around a center point along the Y axis.
* Example: center=[0,0,0], angle=45° → rotates 45° around Y axis through origin
* @param inputs Rotation around center with an Y axis information
* @returns array of transformations
* @group rotation
* @shortname center y
* @drawable false
*/
rotationCenterY(inputs: Inputs.Transforms.RotationCenterDto): Base.TransformMatrixes;
/**
* Creates rotation transformations around a center point along the Z axis.
* Example: center=[10,10,0], angle=180° → rotates 180° around Z axis through point [10,10,0]
* @param inputs Rotation around center with an Z axis information
* @returns array of transformations
* @group rotation
* @shortname center z
* @drawable false
*/
rotationCenterZ(inputs: Inputs.Transforms.RotationCenterDto): Base.TransformMatrixes;
/**
* Creates rotation transformations using yaw-pitch-roll (Euler angles) around a center point.
* Yaw → Y axis rotation, Pitch → X axis rotation, Roll → Z axis rotation.
* Example: center=[0,0,0], yaw=90°, pitch=0°, roll=0° → rotates 90° around Y axis
* @param inputs Yaw pitch roll rotation information
* @returns array of transformations
* @group rotation
* @shortname yaw pitch roll
* @drawable false
*/
rotationCenterYawPitchRoll(inputs: Inputs.Transforms.RotationCenterYawPitchRollDto): Base.TransformMatrixes;
/**
* Creates non-uniform scale transformation around a center point (different scale per axis).
* Example: center=[5,5,5], scaleXyz=[2,1,0.5] → doubles X, keeps Y, halves Z around point [5,5,5]
* @param inputs Scale center xyz trnansformation
* @returns array of transformations
* @group scale
* @shortname center xyz
* @drawable false
*/
scaleCenterXYZ(inputs: Inputs.Transforms.ScaleCenterXYZDto): Base.TransformMatrixes;
/**
* Creates non-uniform scale transformation from origin (different scale per axis).
* Example: scaleXyz=[2,3,1] → doubles X, triples Y, keeps Z unchanged
* @param inputs Scale XYZ number array information
* @returns transformation
* @group scale
* @shortname xyz
* @drawable false
*/
scaleXYZ(inputs: Inputs.Transforms.ScaleXYZDto): Base.TransformMatrixes;
/**
* Creates directional stretch transformation that scales along a specific direction from a center point.
* Points move only along the direction vector; perpendicular plane remains unchanged.
* Example: center=[0,0,0], direction=[1,0,0], scale=2 → stretches 2× along X axis only
* @param inputs Defines the center, direction, and scale factor for the stretch.
* @returns Array of transformations: [Translate To Origin, Stretch, Translate Back].
* @group scale
* @shortname stretch dir center
* @drawable false
*/
stretchDirFromCenter(inputs: Inputs.Transforms.StretchDirCenterDto): Base.TransformMatrixes;
/**
* Creates uniform scale transformation from origin (same scale on all axes).
* Example: scale=2 → doubles size in all directions (X, Y, Z)
* @param inputs Scale Dto
* @returns transformation
* @group scale
* @shortname uniform
* @drawable false
*/
uniformScale(inputs: Inputs.Transforms.UniformScaleDto): Base.TransformMatrixes;
/**
* Creates uniform scale transformation around a center point (same scale on all axes).
* Example: center=[5,5,5], scale=0.5 → halves size in all directions around point [5,5,5]
* @param inputs Scale Dto with center point information
* @returns array of transformations
* @group scale
* @shortname uniform from center
* @drawable false
*/
uniformScaleFromCenter(inputs: Inputs.Transforms.UniformScaleFromCenterDto): Base.TransformMatrixes;
/**
* Creates translation transformation (moves objects in space).
* Example: translation=[10,5,0] → moves object 10 units in X, 5 in Y, 0 in Z
* @param inputs Translation information
* @returns transformation
* @group translation
* @shortname xyz
* @drawable false
*/
translationXYZ(inputs: Inputs.Transforms.TranslationXYZDto): Base.TransformMatrixes;
/**
* Creates multiple translation transformations (batch move operations).
* Example: translations=[[1,0,0], [0,2,0]] → generates two transforms: move +X, move +Y
* @param inputs Translation information
* @returns transformation
* @group translations
* @shortname xyz
* @drawable false
*/
translationsXYZ(inputs: Inputs.Transforms.TranslationsXYZDto): Base.TransformMatrixes[];
/**
* Creates identity transformation matrix (no transformation - leaves objects unchanged).
* Returns 4×4 matrix: [1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1]
* @returns transformation
* @group identity
* @shortname identity
* @drawable false
*/
identity(): Base.TransformMatrix;
private translation;
private scaling;
private rotationAxis;
private rotationX;
private rotationY;
private rotationZ;
private rotationYawPitchRoll;
private rotationMatrixFromQuat;
/**
* Creates a 4x4 matrix that scales along a given direction vector.
* @param direction The direction vector (will be normalized).
* @param scale The scale factor along the direction.
* @returns A 4x4 column-major transformation matrix.
*/
private stretchDirection;
}