Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/gmath/src/vector2.ts>Vector2

🎮 A wasm accelerated game and graphics maths library for deno
Latest
class Vector2
implements Point2
import { Vector2 } from "https://deno.land/x/gmath@0.1.12/src/vector2.ts";

Constructors

new
Vector2()
new
Vector2(x: number)
new
Vector2(x: number, y: number)
new
Vector2(source: Float32Array)
new
Vector2(x?: number | Float32Array, y?: number)

Properties

x: number
y: number
[0]: number
[1]: number

Methods

add(other: number | Vector2): Vector2

Adds this Vector2 to the specified Vector2 or scalar

Returns the angle of this Vector2

clamp(length: number): Vector2

Returns a new Vector2 with the same direction, but clamped to the specified length

Creates a new Vector2 with the same values

div(other: number | Vector2): Vector2

Divides this Vector2 with the specified Vector2 or scalar

dot(other: Vector2): number

Calculates the dot product of this Vector2

eq(other: Vector2): boolean

Checks equality between two Vector2

extend3(z: number): Vector3

Create a Vector3 using this x and y and the provided z

extend4(z: number, w: number): Vector4

Create a Vector4 using this x and y and the provided z and w

isFinite(): boolean

Checks if the Vector2 is finite

lerp(other: Vector2, alpha: number): Vector2

Linearly interpolates between this and the specified Vector2

mag(): number

The magnitude of this Vector2

mag2(): number

The squared magnitude of this Vector2

Calculates the midpoint between two Vector2

mul(other: number | Vector2): Vector2

Multiplies this Vector2 with the specified Vector2 or scalar

Negates the values of this Vector2

Returns a new Vector2 with the same direction, but with a magnitude of 1

Sets the x and y of this Vector2 to the specified Vector2 x and y values

sub(other: number | Vector2): Vector2

Subtracts this Vector2 from the specified Vector2 or scalar

toArray(): [number, number]

Converts the Vector2 to a tuple of numbers

toFloat32Array(): Float32Array

Converts the Vector to a Float32Array

toString(): string

Converts the Vector2 to a string

Static Methods

Shorthand for writing Vector2(0, -1)

Shorthand for writing Vector2(-1, 0)

A Vector2 with all values set to Number.NEGATIVE_INFINITY

A Vector2 with all values set to 1

A Vector2 with all values set to Number.POSITIVE_INFINITY

Shorthand for writing Vector2(1, 0)

Shorthand for writing Vector2(0, 1)

A Vector2 with all values set to 0