Home Reference Source Repository
import {Vec} from 'webgame-lib/src/geom.js'
public class | source

Vec

Denotes a point in 2D space.

Constructor Summary

Public Constructor
public

Initializes a point.

Member Summary

Public Members
public get

r: number: *

Magnitude of the vector.

public

X coordinate.

public

Y coordinate.

Method Summary

Public Methods
public

add(v: Vec): Vec

Sums with another vector.

public

Calculates the manhattan distance with another vector.

public

clip(rect: Rect): *

Clips the vector to within the bounds of the supplied rectangle.

public

clone(): Vec

Returns an identical instance.

public

floor(): Vec

Floors all properties.

public

Linearly interpolates this vector with another.

public

round(): Vec

Rounds all properties.

public

Scales the vector.

public

set(x: number, y: number): Vec

Sets the properties.

public

sub(v: Vec): Vec

Difference with another vector.

Public Constructors

public constructor(x: number, y: number) source

Initializes a point.

Params:

NameTypeAttributeDescription
x number

X coordinate

y number

Y coordinate

Public Members

public get r: number: * source

Magnitude of the vector.

Return:

number

Resultant

public x: number source

X coordinate.

public y: number source

Y coordinate.

Public Methods

public add(v: Vec): Vec source

Sums with another vector.

Params:

NameTypeAttributeDescription
v Vec

Other

Return:

Vec

Self

public blockDist(v: Vec): number source

Calculates the manhattan distance with another vector.

Params:

NameTypeAttributeDescription
v Vec

Other

Return:

number

Block distance

public clip(rect: Rect): * source

Clips the vector to within the bounds of the supplied rectangle.

Params:

NameTypeAttributeDescription
rect Rect

Bounds

Return:

*

public clone(): Vec source

Returns an identical instance.

Return:

Vec

Copy of self

public floor(): Vec source

Floors all properties.

Return:

Vec

Self

public interpolate(f: number): Vec source

Linearly interpolates this vector with another.

Params:

NameTypeAttributeDescription
f number

Interpolation factor

Return:

Vec

Interpolated vector

public round(): Vec source

Rounds all properties.

Return:

Vec

Self

public scale(f: number): Vec source

Scales the vector.

Params:

NameTypeAttributeDescription
f number

Factor to scale by

Return:

Vec

Self

public set(x: number, y: number): Vec source

Sets the properties.

Params:

NameTypeAttributeDescription
x number

X coordinate

y number

Y coordinate

Return:

Vec

Self

public sub(v: Vec): Vec source

Difference with another vector.

Params:

NameTypeAttributeDescription
v Vec

Other

Return:

Vec

Self