type Vector2Tuple = [number, number]; /** * Represents a 2D vector with x and y components. */ declare class Vector2 { x: number; y: number; /** * Creates a new Vector2 with optional initial values for x and y. */ constructor(x?: number, y?: number); /** * Sets the x and y components of the vector. * @example * const v = new Vector2(); * v.set(new Vector2(1, 2)); // sets x = 1 and y = 2 * v.set([1, 2]); // sets x = 1 and y = 2 * v.set(1, 2); // sets x = 1 and y = 2 * v.set(1); // same as v.set(1, 1) * @returns this */ set(x: Vector2 | Vector2Tuple | number, y?: number): this; /** * Sets the x component of the vector. * @example * const v = new Vector2(); * v.setX(1); // sets x = 1 * @returns this */ setX(x: number): this; /** * Sets the y component of the vector. * @example * const v = new Vector2(); * v.setY(1); // sets y = 1 * @returns this */ setY(y: number): this; /** * Returns a new Vector2 with the same x and y components. * @example * const v1 = new Vector2(1, 2); * const v2 = v.clone(); // same as v1 * @returns A new Vector2 with the same x and y components. */ clone(): Vector2; /** * Copies the x and y components of another vector. * @example * const v1 = new Vector2(1, 2); * const v2 = new Vector2(3, 4); * v1.copy(v2); // v1 is now equal to v2 * @returns this */ copy(v: Vector2): this; /** * Returns an array with the x and y components of the vector. * @example * const v = new Vector2(1, 2); * v.toArray(); // returns [1, 2] * @returns An array with the x and y components of the vector. */ toArray(): Vector2Tuple; /** * Returns a string representation of the vector. * @example * const v = new Vector2(1, 2); * v.toString(); // returns 'x: 1, y: 2' * @returns A string representation of the vector. */ toString(): string; /** * Adds to the current vector. * @example * const a = new Vector2(1, 2); * a.add(new Vector2(1, 2)); // a is now equal to (2, 4) * a.add([1, 2]) // a is now equal to (3, 6) * a.add(1, 2) // a is now equal to (4, 8) * a.add(1) // same as a.add(1, 1) * @returns this */ add(x: Vector2 | Vector2Tuple | number, y?: number): this; /** * Subtracts from the current vector. * @example * const a = new Vector2(1, 2); * a.sub(new Vector2(1, 2)); // a is now equal to (0, 0) * a.sub([1, 2]) // a is now equal to (-1, -2) * a.sub(1, 2) // a is now equal to (-2, -4) * a.sub(1) // same as a.sub(1, 1) * @returns this */ sub(x: Vector2 | Vector2Tuple | number, y?: number): this; /** * Multplies with the current vector * @example * const a = new Vector2(1, 2); * a.mult(new Vector2(1, 2)); // a is now equal to (1, 4) * a.mult([1, 2]) // a is now equal to (1, 8) * a.mult(1, 2) // a is now equal to (1, 16) * a.mult(1) // same as a.mult(1, 1) * @returns this */ mult(x: Vector2 | Vector2Tuple | number, y?: number): this; /** * Divides with the current vector * @example * const a = new Vector2(1, 2); * a.div(new Vector2(1, 2)); // a is now equal to (1, 1) * a.div([1, 2]) // a is now equal to (1, 0.5) * a.div(1, 2) // a is now equal to (1, 0.25) * a.div(1) // same as a.div(1, 1) * @returns this */ div(x: Vector2 | Vector2Tuple | number, y?: number): this; /** * Inverts the x and y components of the vector. * @example * const v = new Vector2(1, 2); * v.invert(); // v is now equal to (-1, -2) * @returns this */ invert(): this; /** * Normalizes the vector. * @example * const v = new Vector2(1, 2); * v.normalize(); // v is now equal to (0.447, 0.894) * @returns this */ normalize(): this; /** * Rotates the vector around a pivot by a given angle. * @param center vector/point to rotate around * @param angle Angle in radians * @example * const v = new Vector2(4, 3); * const p = new Vector2(0, 0); * v.rotateAround(p, Math.PI / 6); // v is now equal to (1.964, 4.598) * @returns this */ rotateAround(center: Vector2, angle: number): this; /** * Rotates the vector by a given angle around the origin. * @param angle Angle in radians * @example * const v = new Vector2(4, 3); * v.rotate(Math.PI / 6); // v is now equal to (1.964, 4.598) * @returns this */ rotate(angle: number): this; /** * Randomizes the vector * @example * const v = new Vector2(1, 2); * v.randomize(); // v is anything between (0, 0) and (1, 1) * v.randomize(new Vector2(2, 3), new Vector2(4, 5)); // v is anything between (2, 3) and (4, 5) * @returns this */ randomize(min?: Vector2, max?: Vector2): this; /** * Clamps the vector between two vectors. * @example * const v = new Vector2(1, 2); * v.clamp(new Vector2(2, 3), new Vector2(4, 5)); // v is now equal to (2, 3) * @returns this */ clamp(min: Vector2 | number, max: Vector2 | number): this; /** * Limits the vector to a maximum length. * @example * const v = new Vector2(1, 2); * v.limit(1); // sets the length of v to maximum of 1 * @returns this */ limit(max: number): this; /** * Rounds the vector to the nearest integer. * @example * const v = new Vector2(1.2, 2.8); * v.round(); // v is now equal to (1, 3) * @returns this */ round(): this; /** * Rounds the vector to the nearest integer towards zero. * @example * const v = new Vector2(1.2, 2.8); * v.roundToZero(); // v is now equal to (1, 2) * @returns this */ roundToZero(): this; /** * Checks if the vector is equal to another vector. * @example * const a = new Vector2(1, 2); * const b = new Vector2(1, 2); * a.equals(b); // returns true * @returns Whether the vector is equal to another vector. */ equals(v: Vector2): boolean; /** * Calculates the minimum components of the current vector and another vector. * @example * const a = new Vector2(1, 3); * const b = new Vector2(4, 2); * a.min(b); // a is now equal to (1, 2) * @returns this */ min(v: Vector2): this; /** * Calculates the maximum components of the current vector and another vector. * @example * const a = new Vector2(1, 3); * const b = new Vector2(4, 2); * a.max(b); // a is now equal to (4, 3) * @returns this */ max(v: Vector2): this; /** * Computes the dot product of the vector with another vector. * @example * const a = new Vector2(1, 2); * const b = new Vector2(3, 4); * a.dot(b); // returns 11 * @returns dot product */ dot(v: Vector2): number; /** * Computes the cross product of the vector with another vector. * @example * const a = new Vector2(1, 2); * const b = new Vector2(3, 4); * a.cross(b); // returns -2 * @returns cross product */ cross(v: Vector2): number; /** * Computes the length of the vector squared. * @example * const v = new Vector2(1, 2); * v.lengthSq(); // returns 5 * @returns squared length of the vector */ lengthSq(): number; /** * Computes the length of the vector. * @example * const v = new Vector2(1, 2); * v.length(); // returns 2.236 * @returns length of the vector */ length(): number; /** * Computes the Manhattan length of the vector. * @example * const v = new Vector2(1, 2); * v.manhattanLength(); // returns 3 * @returns manhattan length of the vector */ manhattanLength(): number; /** * Sets the length of the vector. * @example * const v = new Vector2(1, 2); * v.setLength(1); // sets the length of the vector to 1 * @returns this */ setLength(length: number): this; /** * Returns the X distance between current vector and another vector. * @example * const a = new Vector2(1, 2); * const b = new Vector2(3, 4); * a.xDistTo(b); // returns -2 * @returns distance between x components */ xDistTo(v: Vector2): number; /** * Returns the Y distance between current vector and another vector. * @example * const a = new Vector2(1, 2); * const b = new Vector2(3, 4); * a.yDistTo(b); // returns -2 * @returns distance between y components */ yDistTo(v: Vector2): number; /** * Returns the squared distance between current vector and another vector. * @example * const a = new Vector2(1, 2); * const b = new Vector2(3, 4); * a.distToSqrd(b); // returns 8 * @returns distance squared between vectors */ distToSqrd(v: Vector2): number; /** * Returns the distance between current vector and another vector. * @example * const a = new Vector2(1, 2); * const b = new Vector2(3, 4); * a.distTo(b); // returns 2.828 * @returns distance between vectors */ distTo(v: Vector2): number; /** * Returns the Manhattan distance between current vector and another vector. * @example * const a = new Vector2(1, 2); * const b = new Vector2(3, 4); * a.manhattanDistTo(b); // returns 4 * @returns manhattan distance between vectors */ manhattanDistTo(v: Vector2): number; /** * Returns the angle in radians with respect to the positive x-axis. * @example * const v = new Vector2(1, 2); * v.horizontalAngle(); // returns 1.107 * @returns the calculated angle in radians */ hAngle(): number; /** * Returns the angle in radians with respect to the positive y-axis. * @example * const v = new Vector2(1, 2); * v.verticalAngle(); // returns 1.107 * @returns the calculated angle in radians */ vAngle(): number; /** * @alias horizontalAngle */ angle(): number; /** * Returns the angle in radians between the current vector and another vector. * @example * const a = new Vector2(1, 2); * const b = new Vector2(3, 4); * a.angleTo(b); // returns 0.179 * @returns the calculated angle in radians */ angleTo(v: Vector2): number; /** * Interpolates x component towards x component of another vector. * @example * const a = new Vector2(1, 2); * const b = new Vector2(3, 4); * a.lerpX(b, 0.5); // a is now equal to (2, 2) * @returns this */ lerpX(v: Vector2, alpha: number): this; /** * Interpolates y component towards y component of another vector. * @example * const a = new Vector2(1, 2); * const b = new Vector2(3, 4); * a.lerpY(b, 0.5); // a is now equal to (1, 3) * @returns this */ lerpY(v: Vector2, alpha: number): this; /** * Interpolates the vector towards another vector. * @example * const a = new Vector2(1, 2); * const b = new Vector2(3, 4); * a.lerp(b, 0.5); // a is now equal to (2, 3) * @returns this */ lerp(v: Vector2, alpha: number): this; /** * Adds two vectors. * @returns The added vector. */ static add(a: Vector2, b: Vector2): Vector2; /** * Subtracts two vectors. * @returns The subtracted vector. */ static sub(a: Vector2, b: Vector2): Vector2; /** * Multiplies two vectors. * @returns The multiplied vector. */ static mult(a: Vector2, b: Vector2): Vector2; /** * Divides two vectors. * @returns The divided vector. */ static div(a: Vector2, b: Vector2): Vector2; /** * Checks if two vectors are equal. * @returns Whether the two vectors are equal. */ static equals(a: Vector2, b: Vector2): boolean; /** * Returns the minimum components of two vectors. * @returns The minimum vector. */ static min(a: Vector2, b: Vector2): Vector2; /** * Returns the maximum components of two vectors. * @returns The maximum vector. */ static max(a: Vector2, b: Vector2): Vector2; /** * Inverts the vector. * @returns The inverted vector. */ static invert(v: Vector2): Vector2; /** * Returns the dot product of two vectors. * @returns The dot product of the two vectors. */ static dot(a: Vector2, b: Vector2): number; /** * Calculates the cross product of two vectors. * @returns The cross product of the two vectors. */ static cross(a: Vector2, b: Vector2): number; /** * Normalizes the vector. * @returns The normalized vector. */ static normalize(v: Vector2): Vector2; /** * Calculates the distance between two vectors. * @returns A vector with the distance between the two vectors. */ static distBetween(a: Vector2, b: Vector2): number; /** * Calculates the angle in radians between two vectors. * @returns The angle in radians. */ static angleBetween(a: Vector2, b: Vector2): number; /** * Interpolates the vector towards another vector. * @returns The interpolated vector. */ static lerp(a: Vector2, b: Vector2, alpha: number): Vector2; [Symbol.iterator](): Generator; } export { Vector2, type Vector2Tuple, Vector2 as default };