sussy-util
Version:
Util package made by me
96 lines (95 loc) • 3.84 kB
TypeScript
import Tuple from './Tuple';
export default class Vector2d {
readonly x: number;
readonly y: number;
constructor(x?: number, y?: number);
/**
* Creates a copy of the vector.
* @returns {Vector2d} - A new Vector2d object with the same x and y coordinates.
*/
clone(): Vector2d;
/**
* Adds another vector to the current vector.
* @param {Vector2d} vector - The vector to be added.
* @returns {Vector2d} - A new Vector2d object representing the sum of the two vectors.
*/
add(vector: Vector2d): Vector2d;
/**
* Subtracts another vector from the current vector.
* @param {Vector2d} vector - The vector to be subtracted.
* @returns {Vector2d} - A new Vector2d object representing the difference between the two vectors.
*/
subtract(vector: Vector2d): Vector2d;
/**
* Multiplies the vector by a scalar value.
* @param {number} scalar - The scalar value to multiply the vector by.
* @returns {Vector2d} - A new Vector2d object representing the scaled vector.
*/
multiply(scalar: number): Vector2d;
/**
* Divides the vector by a scalar value.
* @param {number} scalar - The scalar value to divide the vector by.
* @returns {Vector2d} - A new Vector2d object representing the divided vector.
* @throws {Error} - Throws an error if the scalar is zero.
*/
divide(scalar: number): Vector2d;
/**
* Calculates the magnitude (length) of the vector.
* @returns {number} - The magnitude of the vector.
*/
magnitude(): number;
/**
* Returns a normalized version of the vector.
* @returns {Vector2d} - A new Vector2d object representing the normalized vector.
* @throws {Error} - Throws an error if the vector is a zero vector.
*/
normalize(): Vector2d;
/**
* Calculates the dot product of the vector with another vector.
* @param {Vector2d} vector - The vector to calculate the dot product with.
* @returns {number} - The dot product of the two vectors.
*/
dotProduct(vector: Vector2d): number;
/**
* Calculates the distance between two vectors.
* @param {Vector2d} vector - The vector to calculate the distance to.
* @returns {number} - The distance between the two vectors.
*/
distanceTo(vector: Vector2d): number;
/**
* Calculates the angle between two vectors in radians.
* @param {Vector2d} vector - The vector to calculate the angle to.
* @returns {number} - The angle between the two vectors in radians.
*/
angleTo(vector: Vector2d): number;
/**
* Returns a vector with the absolute values of the original vector's components.
* @returns {Vector2d} - A new Vector2d object with absolute values.
*/
abs(): Vector2d;
/**
* Checks if the vector is equal to another vector.
* @param {Vector2d} vector - The vector to compare with.
* @returns {boolean} - True if the vectors are equal, false otherwise.
*/
equals(vector: Vector2d): boolean;
toString(): string;
/**
* Converts the vector to an array representation.
* @returns An array containing the x, y, and z components of the vector.
*/
toArray(): number[];
/**
* Converts the vector to an array representation.
* @returns An array containing the x, y, and z components of the vector.
*/
toTuple(): Tuple<number, number>;
/**
* Creates a new Vector2d instance from an array representation.
* @param arr - An array containing the x and y components of the vector.
* @returns A new Vector2d instance created from the array.
* @throws Throws an error if the array length is not 2.
*/
static ofArray(arr: number[]): Vector2d;
static ofTuple(tuple: Tuple<number, number>): Vector2d;
}