@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
395 lines • 8.95 kB
TypeScript
/**
* Class representing a 2D vector. A 2D vector is an ordered pair of numbers (labeled x and y), which can be used to represent a number of things, such as:
*
* A point in 2D space (i.e. a position on a plane).
* A direction and length across a plane. The length will always be the Euclidean distance (straight-line distance) from `(0, 0)` to `(x, y)` and the direction is also measured from `(0, 0)` towards `(x, y)`.
* Any arbitrary ordered pair of numbers.
* There are other things a 2D vector can be used to represent, such as momentum vectors, complex numbers and so on, however these are the most common uses.
*
* Iterating through a Vector2 instance will yield its components `(x, y)` in the corresponding order.
*
* @implements Iterable<number>
*
* @author Alex Goldring
* @copyright Company Named Limited (c) 2025
*/
export class Vector2 implements Iterable<number> {
/**
*
* @param {number} [x=0]
* @param {number} [y=0]
*/
constructor(x?: number, y?: number);
/**
*
* @type {number}
*/
x: number;
/**
*
* @type {number}
*/
y: number;
/**
* @readonly
* @type {Signal<number,number,number,number>}
*/
readonly onChanged: Signal<number, number, number, number>;
/**
*
* @param {number[]|Float32Array} array
* @param {number} [offset]
* @returns {this}
*/
fromArray(array: number[] | Float32Array, offset?: number): this;
/**
*
* @param {number[]|Float32Array} array
* @param {number} [offset]
*/
toArray(array: number[] | Float32Array, offset?: number): void;
asArray(): any[];
/**
*
* @param {number} x
* @param {number} y
* @returns {this}
*/
set(x: number, y: number): this;
/**
*
* @param {number} x
* @param {number} y
* @returns {this}
*/
setSilent(x: number, y: number): this;
/**
*
* @param {number} x
* @returns {this}
*/
setX(x: number): this;
/**
*
* @param {number} y
* @returns {this}
*/
setY(y: number): this;
/**
*
* @param {number} x
* @param {number} y
* @returns {this}
*/
_sub(x: number, y: number): this;
/**
*
* @param {Vector2} other
* @returns {this}
*/
sub(other: Vector2): this;
/**
*
* @param {Vector2} a
* @param {Vector2} b
* @returns {this}
*/
subVectors(a: Vector2, b: Vector2): this;
/**
* performs Math.floor operation on x and y
* @returns {this}
*/
floor(): this;
/**
* performs Math.ceil operation on x and y
* @returns {this}
*/
ceil(): this;
/**
* Round both components to the nearest integer
* @returns {this}
*/
round(): this;
/**
* performs Math.abs operation on x and y
* @returns {this}
*/
abs(): this;
/**
*
* @param {number} x
* @param {number} y
* @returns {this}
*/
_mod(x: number, y: number): this;
/**
*
* @param {Vector2} other
* @returns {this}
*/
mod(other: Vector2): this;
/**
*
* @param {Vector2} other
* @returns {this}
*/
divide(other: Vector2): this;
/**
*
* @param {Vector2} other
* @returns {this}
*/
multiply(other: Vector2): this;
/**
*
* @param {number} x
* @param {number} y
* @returns {this}
*/
_multiply(x: number, y: number): this;
/**
* Component-size MAX operator
* @param {Vector2} other
* @returns {this}
*/
max(other: Vector2): this;
/**
*
* @param {Vector2} other
* @returns {number}
*/
dot(other: Vector2): number;
/**
*
* @param {Vector2} other
* @returns {this}
*/
copy(other: Vector2): this;
/**
*
* @returns {Vector2}
*/
clone(): Vector2;
/**
*
* @returns {this}
*/
negate(): this;
/**
*
* @param {number} x
* @param {number} y
* @returns {this}
*/
_add(x: number, y: number): this;
/**
*
* @param {Vector2} other
* @returns {this}
*/
add(other: Vector2): this;
/**
*
* @param {number} val
* @returns {this}
*/
addScalar(val: number): this;
/**
*
* @param {number} val
* @returns {this}
*/
setScalar(val: number): this;
/**
*
* @param {number} val
* @returns {this}
*/
divideScalar(val: number): this;
/**
*
* @param {number} val
* @returns {this}
*/
multiplyScalar(val: number): this;
toJSON(): {
x: number;
y: number;
};
fromJSON(json: any): void;
/**
*
* @param {BinaryBuffer} buffer
*/
toBinaryBuffer(buffer: BinaryBuffer): void;
/**
*
* @param {BinaryBuffer} buffer
*/
fromBinaryBuffer(buffer: BinaryBuffer): void;
/**
*
* @param {BinaryBuffer} buffer
*/
toBinaryBufferFloat32(buffer: BinaryBuffer): void;
/**
*
* @param {BinaryBuffer} buffer
*/
fromBinaryBufferFloat32(buffer: BinaryBuffer): void;
/**
*
* @returns {boolean}
*/
isZero(): boolean;
/**
*
* @param {number} minX
* @param {number} minY
* @param {number} maxX
* @param {number} maxY
* @returns {this}
*/
clamp(minX: number, minY: number, maxX: number, maxY: number): this;
/**
*
* @param {number} lowX
* @param {number} lowY
* @returns {this}
*/
clampLow(lowX: number, lowY: number): this;
/**
*
* @param {number} highX
* @param {number} highY
* @returns {this}
*/
clampHigh(highX: number, highY: number): this;
/**
*
* @param {Vector2} other
* @returns {number}
*/
distanceSqrTo(other: Vector2): number;
/**
*
* @param {number} x
* @param {number} y
* @returns {number}
*/
_distanceSqrTo(x: number, y: number): number;
/**
*
* @param {Vector2} a
* @param {Vector2} b
* @param {number} fraction
* @returns {this}
*/
lerpVectors(a: Vector2, b: Vector2, fraction: number): this;
/**
*
* @param {number[]} matrix3
* @returns {this}
*/
applyMatrix3(matrix3: number[]): this;
/**
*
* @param {Vector2} other
* @returns {number}
*/
distanceTo(other: Vector2): number;
/**
*
* @param {number} x
* @param {number} y
* @returns {number}
*/
_distanceTo(x: number, y: number): number;
/**
*
* @param {Vector2} other
* @returns {number}
*/
manhattanDistanceTo(other: Vector2): number;
/**
* @returns {number}
*/
length(): number;
/**
* Normalizes the vector, preserving its direction, but making magnitude equal to 1
* @returns {this}
*/
normalize(): this;
/**
*
* @returns {number}
*/
hash(): number;
/**
* Rotation is counter-clockwise
* @param {number} angle in radians
* @returns {this}
*/
rotate(angle: number): this;
/**
*
* @param {function} processor
* @param {*} [thisArg]
* @returns {this}
*/
process(processor: Function, thisArg?: any): this;
toString(): string;
/**
*
* @param {Vector2} other
* @returns {boolean}
*/
equals(other: Vector2): boolean;
/**
*
* @param {Vector2} other
* @param {number} [tolerance]
* @return {boolean}
*/
roughlyEquals(other: Vector2, tolerance?: number): boolean;
/**
*
* @param {number} x
* @param {number} y
* @param {number} [tolerance] acceptable deviation
* @return {boolean}
*/
_roughlyEquals(x: number, y: number, tolerance?: number): boolean;
set 0(arg: number);
get 0(): number;
set 1(arg: number);
get 1(): number;
/**
* @deprecated use {@link Vector2#toArray} instead
*/
writeToArray: (array: number[] | Float32Array, offset?: number) => void;
/**
* @deprecated use {@link Vector2#fromArray} instead
*/
readFromArray: (array: number[] | Float32Array, offset?: number) => this;
/**
* @readonly
* @type {boolean}
*/
readonly isVector2: boolean;
[Symbol.iterator](): Generator<number, void, unknown>;
}
export namespace Vector2 {
export let up: Vector2;
export let down: Vector2;
export let left: Vector2;
export let right: Vector2;
export let zero: Vector2;
export let one: Vector2;
export { v2_distance as _distance };
export let typeName: string;
}
export default Vector2;
import Signal from "../events/signal/Signal.js";
import { v2_distance } from "./vec2/v2_distance.js";
//# sourceMappingURL=Vector2.d.ts.map