@lucania/vectorics
Version:
A linear algebra library.
59 lines (58 loc) • 2.63 kB
TypeScript
import { Tuple2, Tuple3, Tuple4, Vector, Vector2, Vector3, Vector4 } from "./Vector";
export type Tuple2x2 = [...Tuple2, ...Tuple2];
export type Tuple3x3 = [...Tuple3, ...Tuple3, ...Tuple3];
export type Tuple4x4 = [...Tuple4, ...Tuple4, ...Tuple4, ...Tuple4];
export type TupleNxN = Tuple2x2 | Tuple3x3 | Tuple4x4 | number[];
export type MatrixSource<Tuple extends TupleNxN> = number | Tuple | Matrix<Tuple>;
export declare class Matrix<Tuple extends TupleNxN> {
private _data;
readonly size: number;
readonly length: Tuple["length"];
constructor(...data: Tuple);
get(row: number, column: number): number;
add(scalar: number): this;
add(matrix: Matrix<Tuple>): this;
add(tuple: Tuple): this;
subtract(scalar: number): this;
subtract(matrix: Matrix<Tuple>): this;
subtract(tuple: Tuple): this;
multiply(scalar: number): this;
multiply(matrix: Matrix<Tuple>): this;
multiply(tuple: Tuple): this;
multiplyVector(vector: Vector<number[]>): Vector<number[]>;
divide(scalar: number): this;
divide(matrix: Matrix<Tuple>): this;
divide(tuple: Tuple): this;
inverse(): this;
transpose(): this;
clone(): Matrix<Tuple>;
private _tuple;
get data(): Tuple;
toString(fractionDigits?: number): string;
static tuple<Tuple extends TupleNxN>(length: Tuple["length"], source: MatrixSource<Tuple>): Tuple;
static fromSource<Tuple extends Tuple2x2>(size: 4, source: MatrixSource<Tuple>): Matrix2;
static fromSource<Tuple extends Tuple3x3>(size: 9, source: MatrixSource<Tuple>): Matrix3;
static fromSource<Tuple extends Tuple4x4>(size: 16, source: MatrixSource<Tuple>): Matrix4;
}
export declare class Matrix2 extends Matrix<Tuple2x2> {
static readonly SIZE: number;
static identity(): Matrix2;
multiplyVector(vector: Vector2): Vector2;
clone(): Matrix2;
}
export declare class Matrix3 extends Matrix<Tuple3x3> {
static readonly SIZE: number;
static identity(): Matrix3;
multiplyVector(vector: Vector3): Vector3;
clone(): Matrix3;
}
export declare class Matrix4 extends Matrix<Tuple4x4> {
static readonly SIZE: number;
static identity(): Matrix4;
multiplyVector(vector: Vector4): Vector4;
static orthographic(left: number, right: number, bottom: number, top: number, near: number, far: number): Matrix4;
static translate(translationX: number, translationY: number, translationZ: number): Matrix4;
static rotate(angleInDegrees: number, axisX: number, axisY: number, axisZ: number): Matrix4;
static scale(scaleX: number, scaleY: number, scaleZ: number): Matrix4;
clone(): Matrix4;
}