import { XYPoint } from "../utils/types.ts"; /** * a generic 2D Vector Object * @category Math */ export declare class Vector2d { x: number; y: number; /** * @param [x] - x value of the vector * @param [y] - y value of the vector */ constructor(x?: number | undefined, y?: number | undefined); /** * @param [x] - x value of the vector * @param [y] - y value of the vector * @ignore */ onResetEvent(x?: number, y?: number): void; /** * set the Vector x and y properties to the given values * @param x - x component of the vector * @param y - y component of the vector * @returns Reference to this object for method chaining */ set(x: number, y: number): this; /** * set the Vector x and y properties to 0 * @returns Reference to this object for method chaining */ setZero(): this; /** * set the Vector x and y properties using the passed vector * @param v other vector * @returns Reference to this object for method chaining */ setV(v: Vector2d): this; /** * Add the passed vector to this vector * @param v other vector * @returns Reference to this object for method chaining */ add(v: Vector2d): this; /** * Subtract the passed vector from this vector * @param v other vector * @returns Reference to this object for method chaining */ sub(v: Vector2d): this; /** * Multiply this vector values by the given scalar * @param x x scale value * @param [y] y scale value, if not passed, it uses the x value * @returns Reference to this object for method chaining */ scale(x: number, y?: number): this; /** * Convert this vector into isometric coordinate space * @returns Reference to this object for method chaining */ toIso(): this; /** * Convert this vector into 2d coordinate space * @returns Reference to this object for method chaining */ to2d(): this; /** * Multiply this vector values by the passed vector * @param v other vector * @returns Reference to this object for method chaining */ scaleV(v: Vector2d): this; /** * Divide this vector values by the passed value * @param n - the value to divide the vector by * @returns Reference to this object for method chaining */ div(n: number): this; /** * Update this vector values to absolute values * @returns Reference to this object for method chaining */ abs(): this; /** * Clamp the vector value within the specified value range * @param low minimum component value * @param high maximum component value * @returns new me.Vector2d */ clamp(low: number, high: number): Vector2d; /** * Clamp this vector value within the specified value range * @param low minimum component value * @param high maximum component value * @returns Reference to this object for method chaining */ clampSelf(low: number, high: number): this; /** * Update this vector with the minimum value between this and the passed vector * @param v other vector * @returns Reference to this object for method chaining */ minV(v: Vector2d): this; /** * Update this vector with the maximum value between this and the passed vector * @param v other vector * @returns Reference to this object for method chaining */ maxV(v: Vector2d): this; /** * Floor the vector values * @returns new Vector2d */ floor(): Vector2d; /** * Floor this vector values * @returns Reference to this object for method chaining */ floorSelf(): this; /** * Ceil the vector values * @returns new Vector2d */ ceil(): Vector2d; /** * Ceil this vector values * @returns Reference to this object for method chaining */ ceilSelf(): this; /** * Negate the vector values * @returns new Vector2d */ negate(): Vector2d; /** * Negate this vector values * @returns Reference to this object for method chaining */ negateSelf(): this; /** * Copy the x,y values of the passed vector to this one * @param v other vector * @returns Reference to this object for method chaining */ copy(v: Vector2d): this; /** * Checks if this vector is equal to another vector or a pair of coordinates. * @param args - Either two numbers representing x and y coordinates or a single Vector2d object. * @returns True if the coordinates are equal, false otherwise. * @example * let v1 = new Vector2d(3, 4); * let v2 = new Vector2d(3, 4); * v1.equals(v2); // returns true * @example * let v = new Vector2d(3, 4); * v.equals(3, 4); // returns true */ equals(...args: [number, number] | [Vector2d | XYPoint]): boolean; /** * normalize this vector (scale the vector so that its magnitude is 1) * @returns Reference to this object for method chaining */ normalize(): this; /** * change this vector to be perpendicular to what it was before.
* (Effectively rotates it 90 degrees in a clockwise direction) * @returns Reference to this object for method chaining */ perp(): this; /** * Rotate this vector (counter-clockwise) by the specified angle (in radians). * @param angle - The angle to rotate (in radians) * @param [v] - an optional point to rotate around * @returns Reference to this object for method chaining */ rotate(angle: number, v?: XYPoint): this; /** * return the dot product of this vector and the passed one * @param v other vector * @returns The dot product. */ dot(v: Vector2d): number; /** * return the cross product of this vector and the passed one * @param v other vector * @returns The cross product. */ cross(v: Vector2d): number; /** * return the square length of this vector * @returns The length^2 of this vector. */ length2(): number; /** * return the length (magnitude) of this vector * @returns the length of this vector */ length(): number; /** * Linearly interpolate between this vector and the given one. * @param v other vector * @param alpha - distance along the line (alpha = 0 will be this vector, and alpha = 1 will be the given one). * @returns Reference to this object for method chaining */ lerp(v: Vector2d, alpha: number): this; /** * interpolate the position of this vector towards the given one by the given maximum step. * @param target vector to rotate towards * @param step - the maximum step per iteration (Negative values will push the vector away from the target) * @returns Reference to this object for method chaining */ moveTowards(target: Vector2d, step: number): Vector2d; /** * Calculates the Euclidean distance between this vector and another vector. * @param v - The vector to which the distance is calculated. * @returns The Euclidean distance between this vector and the given vector. * @example * let v1 = new Vector2d(3, 4); * let v2 = new Vector2d(6, 8); * v1.distance(v2); // returns 5 */ distance(v: Vector2d): number; /** * return the angle between this vector and the passed one * @param v other vector * @returns angle in radians */ angle(v: Vector2d): number; /** * project this vector on to another vector. * @param v - The vector to project onto. * @returns Reference to this object for method chaining */ project(v: Vector2d): this; /** * Project this vector onto a vector of unit length.
* This is slightly more efficient than `project` when dealing with unit vectors. * @param v - The unit vector to project onto. * @returns Reference to this object for method chaining */ projectN(v: Vector2d): this; /** * return a clone copy of this vector * @returns new Vector2d */ clone(): Vector2d; /** * convert the object to a string representation * @returns stringified representation of this vector */ toString(): `x:${number},y:${number}`; } export declare const vector2dPool: import("../system/pool.ts").Pool; //# sourceMappingURL=vector2d.d.ts.map