UNPKG

duckengine

Version:
432 lines (431 loc) 13.2 kB
import { Duck } from '../..'; /** * @class Vector2 * @classdesc Creates a Vector2 * @description The Vector2 Class. Represents a point * @since 2.0.0 */ export default class Vector2 { x: number; y: number; /** * @constructor Vector2 * @description Creates a Vector2 instance * @param {number} [x=0] X position, optional -> defaults: 0 * @param {number} [y=0] Y position, optional -> defaults: 0 * @since 2.0.0 */ constructor(x?: number, y?: number); /** * @memberof Vector2 * @description Sets the values of the Vector2 * @param {number} x X position to setValue of * @param {number} y Y position to setValue of * @returns {Vector2} * @since 2.0.0 */ setValues(x: number, y: number): this; /** * @memberof Vector2 * @description Sets the values of the Vector2 based on another Vector2 * @param {number} vector Vector2 to use to set the position * @returns {Vector2} * @since 2.0.0 */ setValuesVec(vector: Vector2): this; /** * @memberof Vector2 * @description Adds a Vector2 * @param {Vector2} vector Vector2 to be added to * @returns {Vector2} * @since 2.0.0 */ add(vector: Vector2): this; /** * @memberof Vector2 * @description Adds a number to the x and y properties * @param {number} number Number to add to x and y properties * @returns {Vector2} * @since 2.0.0 */ addNumber(number: number): this; /** * @memberof Vector2 * @description Subtracts a Vector2 * @param {Vector2} vector Vector2 to be subtracted to * @returns {Vector2} * @since 2.0.0 */ subtract(vector: Vector2): this; /** * @memberof Vector2 * @description Subtracts a number from the x and y properties * @param {number} number Number to subtract from x and y properties * @returns {Vector2} * @since 2.0.0 */ subtractNumber(number: number): this; /** * @memberof Vector2 * @description Multiplies a Vector2 * @param {Vector2} vector Vector2 to be multiplied to * @returns {Vector2} * @since 2.0.0 */ multiply(vector: Vector2): this; /** * @memberof Vector2 * @description Multiplies a number to the x and y properties * @param {number} number Number to multiply to x and y properties * @returns {Vector2} * @since 2.0.0 */ multiplyNumber(number: number): this; /** * @memberof Vector2 * @description Divides a Vector2 * @param {Vector2} vector Vector2 to be divided to * @returns {Vector2} * @since 2.0.0 */ divide(vector: Vector2): this; /** * @memberof Vector2 * @description Divides a number to the x and y properties * @param {number} number Number to divide to x and y properties * @returns {Vector2} * @since 2.0.0 */ divideNumber(number: number): this; /** * @memberof Vector2 * @description Rounds the Vector2 * @returns {Vector2} * @since 2.0.0 */ round(): this; /** * @memberof Vector2 * @description Gets the angle between two Vector2s * @param {Vector2} vector A Vector2 to get the angle between from * @returns {number} * @since 2.0.0 */ angleBetween(vector: Vector2): number; /** * @memberof Vector2 * @description Gets the angle to two Vector2s * @param {Vector2} vector A Vector2 to get the angle to from * @returns {number} * @since 2.0.0 */ angleTo(vector: Vector2): number; /** * @memberof Vector2 * @description Clones the current Vector2 * @returns {Vector2} * @since 2.0.0 */ clone(): Vector2; /** * @memberof Vector2 * @description Gets the distance from another Vector2 * @param {Vector2} vector A Vector2 to get the distance from * @returns {number} * @since 2.0.0 */ distance(vector: Vector2): number; /** * @memberof Vector2 * @description Gets the distance squared from another Vector2 * @param {Vector2} vector A Vector2 to get the distance from * @returns {number} * @since 2.0.0 */ distanceSqr(vector: Vector2): number; /** * @memberof Vector2 * @description Gets the dot product with another Vector2 * @param {Vector2} vector A Vector2 to get the dot product from * @returns {number} * @since 2.0.0 */ dot(vector: Vector2): number; /** * @memberof Vector2 * @description Gets the cross dot product with another Vector2 * @param {Vector2} vector A Vector2 to get the cross dot product from * @returns {number} * @since 2.0.0 */ crossProduct(vector: Vector2): number; /** * @memberof Vector2 * @description Checks if another Vector2 is equal on both axises * @param {Vector2} vector A Vector2 to compare with * @returns {boolean} * @since 2.0.0 */ equals(vector: Vector2): boolean; /** * @memberof Vector2 * @description Gets the perpendicular values of the Vector2 * @param {Vector2} [resultVector] The new Vector2 to save the value to, optional -> defaults: new Vector2 * @returns {Vector2} * @since 2.0.0 */ perpendicular(resultVector?: Vector2): Vector2; /** * @memberof Vector2 * @description Gradually interpolates the Vector2 towards another Vector2 by an amount * @param {Vector2} current The Current Vector * @param {Vector2} target The Target Vector2 * @param {number} maxDistanceDelta The amount to increase by * @returns {Vector2} * @since 2.0.0 */ moveTowards(current: Vector2, target: Vector2, maxDistanceDelta: number): Vector2; /** * @memberof Vector2 * @description Normalizes the Vector2 * @returns {Vector2} * @since 2.0.0 */ normalize(): this; /** * @memberof Vector2 * @description Gets the normal value of the Vector2 and another Vector2 * @param * @param {Vector2} [resultVector] The new Vector2 to save the value to, optional -> defaults: new Vector2 * @returns {Vector2} * @since 2.0.0 */ getNormal(vector: Vector2, resultVector?: Vector2): Vector2; /** * @memberof Vector2 * @description Determines if Vector2.x and Vector2.y are both equal to 0 * @returns {boolean} * @since 2.0.0 */ isZero(): boolean; /** * @memberof Vector * @description Scales the Vector2 by a scalar Vector2 * @param {Vector2} scalar A Vector2 that is used to scale the current Vector2 * @returns {Vector2} * @since 2.0.0 */ scale(scalar: Vector2): this; /** * @memberof Vector2 * @description Sets Vector2.x and Vector2.y to their negative values * @returns {Vector2} * @since 2.0.0 */ negate(): this; /** * @memberof Vector2 * @description Returns the magnitude or length of the Vector2 * @returns {number} * @since 2.0.0 */ magnitude(): number; /** * @memberof Vector2 * @description Returns the magnitude/lenth squared of the Vector2 * @returns {number} * @since 2.0.0 */ magnitudeSqr(): number; /** * @memberof Vector2 * @description Scales the Vector2 by the magnitude or length * @param magnitude The magnitude or length of the Vector2 * @returns {Vector2} * @since 2.0.0 */ scaleToMagnitude(magnitude: number): this; /** * @memberof Vector2 * @description Returns the string version of the Vector2 * @example console.log(new Vector2(0, 0).toString()) // Vector2(0, 0) * @returns {string} * @since 2.0.0 */ toString(): string; /** * @memberof Vector2 * @description Sets the values to be precise by using Number.toPrecision * @param {number} precision The precision * @returns {Vector2} * @since 2.0.0 */ toPrecision(precision: number): this; /** * @memberof Vector2 * @description Adds to the Vector2 by an amount * @param {number} dx Delta x, the amount to increase the x value by * @param {number} dy Delta y, the amount to increase the y value by * @returns {Vector2} * @since 2.0.0 */ translate(dx: number, dy: number): this; /** * @memberof Vector2 * @description Adds to the Vector2.x by an amount * @param {number} dx Delta x, the amount to increase the x value by * @returns {Vector2} * @since 2.0.0 */ translateX(dx: number): this; /** * @memberof Vector2 * @description Adds to the Vector2.y by an amount * @param {number} dy Delta y, the amount to increase the y value by * @returns {Vector2} * @since 2.0.0 */ translateY(dy: number): this; /** * @memberof Vector2 * @description Gets the dot product using three different Vector2s * @param {Vector2} a A Vector2 * @param {Vector2} b A Vector2 * @param {Vector2} c A Vector2 * @param {Vector2} [resultVector=Vector2] A Vector2 that the result is saved in, optional -> defaults: new Vector2 * @returns {Vector2} * @since 2.0.0 */ tripleProduct(a: Vector2, b: Vector2, c: Vector2, resultVector?: Vector2): Vector2; /** * @memberof Vector2 * @description Clamps the values to a min and max * @param {number} min The min value * @param {number} max The max value * @returns {Vector2} * @since 2.0.0 */ clamp(min: number, max: number): this; /** * @memberof Vector2 * @description Clamps the values to a min * @param {number} min The min value * @returns {Vector2} * @since 2.0.0 */ clampMin(min: number): this; /** * @memberof Vector2 * @description Clamps the values to a max * @param {number} max The max value * @returns {Vector2} * @since 2.0.0 */ clampMax(max: number): this; /** * @memberof Vector2 * @description Rotates the Vector2 based on degrees * @param {number} degrees The angle in degrees * @param {Vector2} [center] The center Vector relative to the Vector, optional -> defaults: Vector2.ZERO * @returns {Vector2} * @since 2.0.0 */ rotate(degrees: number, center?: Vector2): this; /** * @memberof Vector2 * @description Reflects the Vector2, returns the opposite value on a number line * * @example new Vector2(100, 50).reflect() // Vector2(-100, -50) * * @returns {Vector2} * @since 2.0.0 */ reflect(): this; /** * @memberof Vector2 * @description Gets the absolute value of the vector * @returns {Vector2} * @since 2.0.0 */ abs(): this; /** * @memberof Vector2 * @static * @description Returns a Vector2 with 0 set as x and y * @returns {Vector2} * @since 2.0.0 */ static get ZERO(): Vector2; /** * @memberof Vector2 * @static * @description Returns a Vector2 with 0 set as x and -1 set as y * @returns {Vector2} * @since 2.0.0 */ static get UP(): Vector2; /** * @memberof Vector2 * @static * @description Returns a Vector2 with 0 set as x and 1 set as y * @returns {Vector2} * @since 2.0.0 */ static get DOWN(): Vector2; /** * @memberof Vector2 * @static * @description Returns a Vector2 with -1 set as x and 0 set as y * @returns {Vector2} * @since 2.0.0 */ static get LEFT(): Vector2; /** * @memberof Vector2 * @static * @description Returns a Vector2 with 1 set as x and 0 set as y * @returns {Vector2} * @since 2.0.0 */ static get RIGHT(): Vector2; /** * @memberof Vector2 * @static * @description Returns a Vector2 with passed parameters, if no parameters are passed, a Vector2.ZERO is returned * @param {number} [x] X position, optional -> defaults: 0 * @param {number} [y] Y position, optional -> defaults: 0 * @returns {Vector2} * @since 2.0.0 */ static CREATE(x?: number, y?: number): Vector2; /** * @memberof Vector2 * @static * @description Returns a Vector2 with passed vector2Like object * @param {Duck.Types.Math.Vector2Like} vector2Like An object with x and y properties * @returns {Vector2} * @since 2.0.0 */ static fromVector2Like(vector2Like: Duck.Types.Math.Vector2Like): Vector2; /** * @memberof Vector2 * @static * @description Returns a Vector2Like object with passed Vector2 * @param {Vector2} vector2 A Vector2 to convert to Vector2Like object * @returns {Vector2} * @since 2.0.0 */ static toVector2Like(vector2: Vector2): { x: number; y: number; }; /** * @memberof Vector2 * @static * @description Returns a Vector2 with values from a passed Vector2 * @param {Vector2} vector Vector2 to create a Vector2 from * @returns {Vector2} * @since 2.0.0 */ static fromVec(vector: Vector2): Vector2; }