UNPKG

@moderrkowo/jsgl

Version:

Client-side JavaScript library for creating web 2D games. Focusing at objective game.

199 lines (198 loc) 6.01 kB
/** @group Important Classes */ export declare class Vector2 { /** * X component of vector. * @property */ x: number; /** * Y component of vector. * @property */ y: number; /** * Constructs a new Vector2 with the given components. * @param x - X component * @param y - Y component * @constructor */ constructor(x?: number, y?: number); /** * Performs Linear Interpolation on Vectors2 with given decimal midpoint * @method * @param a - The first Vector2 * @param b - The second Vector2 * @param c - The decimal midpoint * @returns Vector2 after Linear Interpolation. * @example * const a = new JSGL.Vector2(3, 9); * const b = new JSGL.Vector2(5, 2); * JSGL.Vector2.Lerp(a, b, 0); // (3, 9) * JSGL.Vector2.Lerp(a, b, 0.5); // (4, 5.5) * JSGL.Vector2.Lerp(a, b, 1); // (5, 2) */ static Lerp(a: Vector2, b: Vector2, c?: number): Vector2; /** * Returns the new Vector2 with maximum X and Y coordinates from first and second Vector2 * @method * @param a - The first Vector2 * @param b - The second Vector2 * @returns The new Vector2 with maximum X and Y * @example * const a = new JSGL.Vector2(3, 9); * const b = new JSGL.Vector2(5, 2); * const max = JSGL.Vector2.Max(a, b); // (5, 9) */ static Max(a: Vector2, b: Vector2): Vector2; /** * Returns the new Vector2 with minimum X and Y coordinates from first and second Vector2 * @method * @param a - The first Vector2 * @param b - The second Vector2 * @returns The new Vector2 with minimum X and Y * @example * const a = new JSGL.Vector2(3, 9); * const b = new JSGL.Vector2(5, 2); * const min = JSGL.Vector2.Min(a, b); // (3, 2) */ static Min(a: Vector2, b: Vector2): Vector2; /** * Returns is `point` between given 2D range. * @method * @param min - The minimal range * @param max - The maximum range * @param point - The point * @returns is `point` between range. * @example * const min = new JSGL.Vector2(5, 5); * const max = new JSGL.Vector2(7, 7); * JSGL.Vector2.IsPointIn(min, max, new JSGL.Vector2(6, 5)); */ static IsPointIn(min: Vector2, max: Vector2, point: Vector2): boolean; /** * Returns true if two vectors are equal. * @method * @param v - The first Vector2 * @param v2 - The second Vector2 * @returns are vectors equal * @example * const vector1 = new JSGL.Vector2(2, 4); * const vector2 = new JSGL.Vector2(2, 4); * JSGL.Vector2.Equal(vector1, vector2); */ static Equal(v?: Vector2, v2?: Vector2): boolean; /** * @returns (0, 0) */ static get zero(): Vector2; /** * @returns (1, 1) */ static get one(): Vector2; /** * @returns (0, 1) */ static get up(): Vector2; /** * @returns (0, -1) */ static get down(): Vector2; /** * @returns (1, 0) */ static get right(): Vector2; /** * @returns (-1, 0) */ static get left(): Vector2; get magnitude(): number; /** * Sets components to given Vector2 or X, Y. * @method * @param x - The Vector2 or X-coordinate * @param y - The Y-coordinate (if `x` isn't Vector2) * @returns This reference * @example * vector2.set(exampleVector); * vector2.set(x, y); */ set(x: number | Vector2, y?: number): Vector2; /** * Adds given Vector2 or X, Y to this Vector2 components. * @method * @param x - The Vector2 or X-coordinate * @param y - The Y-coordinate (if `x` isn't Vector2) * @returns This reference * @example * vector2.add(exampleVector); * vector2.add(x, y); */ add(x: number | Vector2, y?: number): Vector2; /** * Substracts given Vector2 or X, Y to this Vector2 components. * @method * @param x - The Vector2 or X-coordinate * @param y - The Y-coordinate (if `x` isn't Vector2) * @returns This reference * @example * vector2.subtract(exampleVector); * vector2.subtract(x, y); */ subtract(x: number | Vector2, y?: number): Vector2; /** * Multiplies component by scalar or Vector2. * @method * @param x - The Vector2 or scalar * @returns This reference * @example * vector2.multiply(exampleVector); * vector2.multiply(scalar); */ multiply(x: number | Vector2): Vector2; /** * Divides component by scalar or Vector2. * @method * @param x - The Vector2 or scalar * @returns This reference * @example * vector2.divide(exampleVector); * vector2.divide(scalar); */ divide(x: number | Vector2): Vector2; /** * Returns distance between Vector2 or X, Y coordinate. * @method * @param x - The Vector2 or X-coordinate * @param y - The Y-coordinate (if `x` isn't Vector2) * @returns The distance between vectors * @example * vector2.distance(exampleVector); * vector2.distance(0, 0); */ distance(x: number | Vector2, y?: number): number; /** * Floors the X, Y components. * @method * @returns The reference * @example * vector2.floor(); */ floor(): Vector2; /** * Returns true if two vectors are equal. * @method * @param v - The second Vector2 * @returns are vectors equal * @example * const vector1 = new JSGL.Vector2(2, 4); * const vector2 = new JSGL.Vector2(2, 4); * vector1.equal(vector2); */ equal(v?: Vector2): boolean; /** * Clones the Vector2. * @method * @returns The clone */ clone(): Vector2; }