UNPKG

vectors-co

Version:

A library for handling multi dimensional vectors

152 lines (151 loc) 4.06 kB
export declare type TPoints<Length extends number> = [number, ...number[]] & { length: Length; }; export declare class MismatchedSizeError { private message; private name; constructor(lhsWidth: number, rhsWidth: number); } /** * This is the super class. A generically lengthened vector that takes in a type argument for the length. */ export declare class Vec<Length extends number> { points: TPoints<Length>; length: Length; constructor(points: TPoints<Length>, length: Length); /** * This function creates a vector where each element is the same value * @param value The value for each element to be * @param length The length of the vector */ static fromScalar<Length extends number>(value: number, length: Length): Vec<Length>; /** * * @param rhs * @protected * @throws MismatchedSizeError */ protected _add(rhs: Vec<Length>): TPoints<Length>; /** * Adds two vectors together * @param rhs * @throws MismatchedSizeError */ add(rhs: Vec<Length>): Vec<Length>; /** * * @param rhs * @protected * @throws MismatchedSizeError */ protected _sub(rhs: Vec<Length>): TPoints<Length>; /** * Subtracts two vectors togethers * @param rhs * @throws MismatchedSizeError */ sub(rhs: Vec<Length>): Vec<Length>; /** * * @param rhs * @protected * @throws MismatchedSizeError */ protected _mul(rhs: Vec<Length>): TPoints<Length>; /** * Multiples each value of two vectors together * @param rhs * @throws MismatchedSizeError */ mul(rhs: Vec<Length>): Vec<Length>; /** * * @param rhs * @protected * @throws MismatchedSizeError */ protected _div(rhs: Vec<Length>): TPoints<Length>; protected _pow(power: number): TPoints<Length>; /** * Raises each element to the power given * @param power */ pow(power: number): Vec<Length>; /** * Divides each value of two vectors together * @param rhs * @protected * @throws MismatchedSizeError */ div(rhs: Vec<Length>): Vec<Length>; /** * Gives the dot product of two vectors * @param rhs * @throws MismatchedSizeError */ dot(rhs: Vec<Length>): number; /** * Gives the magnitude of the vector */ get size(): number; /** * Gives the values of the vector summed up */ get sum(): number; get _unit(): TPoints<Length>; /** * Returns a unit vector of the current vector */ get unit(): Vec<Length>; } export declare class Vec2 extends Vec<2> { constructor(points: TPoints<2>); add(rhs: Vec<2>): Vec2; sub(rhs: Vec<2>): Vec2; mul(rhs: Vec<2>): Vec2; div(rhs: Vec<2>): Vec2; pow(power: number): Vec2; get x(): number; set x(val: number); get y(): number; set y(val: number); get unit(): Vec2; } export declare class Vec3 extends Vec<3> { constructor(points: TPoints<3>); add(rhs: Vec<3>): Vec3; sub(rhs: Vec<3>): Vec3; mul(rhs: Vec<3>): Vec3; div(rhs: Vec<3>): Vec3; pow(power: number): Vec3; /** * Calculates a cross product * @param _rhs * @throws MismatchedSizeError */ cross(_rhs: Vec<3>): Vec3; get x(): number; set x(val: number); get y(): number; set y(val: number); get z(): number; set z(val: number); get unit(): Vec3; } export declare class Vec4 extends Vec<4> { constructor(points: TPoints<4>); add(rhs: Vec<4>): Vec4; sub(rhs: Vec<4>): Vec4; mul(rhs: Vec<4>): Vec4; div(rhs: Vec<4>): Vec4; pow(power: number): Vec4; get x(): number; set x(val: number); get y(): number; set y(val: number); get z(): number; set z(val: number); get w(): number; set w(val: number); get unit(): Vec4; }