Options
All
• Public
• Public/Protected
• All

# Class Vector

• Vector

## Constructors

### constructor

• new Vector(x: any, y: any): Vector

## Methods

### abs

• Computes the component wise absolute

#### Returns Vector

• Adds a vector and return a new vector

#### Returns this

• Adds a scalar to both components and return a new vector

#### Returns Vector

• addScalars(x: any, y: any): Vector
• Adds two scalars and return a new vector

### angle

• angle(): number
• Returns the angle

0 .. 2 PI

### centerPoint

• Computes and returns the center between both points

### copy

• return a copy of the vector

### direction

• Returns the unnormalized direction to the other point

### distance

• distance(v: any): number
• Computes the distance to a given vector

### distanceSquare

• distanceSquare(v: any): number
• Computes the square distance to a given vectort

### divideScalar

• divideScalar(f: any): Vector
• Divides both components by a scalar and return a new vector

### divideScalarInplace

• divideScalarInplace(f: any): this
• Divides both components by a scalar

### divideScalars

• divideScalars(a: any, b: any): Vector
• Divides both components by the given scalars and return a new vector

### dot

• dot(v: any): number
• Computes the scalar product

### equals

• equals(v: any): boolean
• Compares both vectors for exact equality. Does not do an epsilon compare

### equalsEpsilon

• equalsEpsilon(v: any, epsilon?: number): boolean
• Compares both vectors for epsilon equality

### findPerpendicular

• Returns a perpendicular vector

### floor

• Computes componentwise floor and return a new vector

### length

• length(): number
• Returns the euclidian length

### lengthSquare

• lengthSquare(): number
• Returns the square length

### max

• Computes the component wise maximum and return a new vector

### maxScalar

• For both components, compute the maximum of each component and the given scalar, and return a new vector. For example:

• new Vector(-1, 5).maxScalar(0) -> Vector(0, 5)

### min

• Computes the component wise minimum and return a new vector

### mul

• Multiplies with a vector and return a new vector

### multiplyScalar

• multiplyScalar(f: any): Vector
• Multiplies both components with a scalar and return a new vector

### multiplyScalars

• multiplyScalars(a: any, b: any): Vector
• Multiplies both components with two scalars and returns a new vector

### normalize

• Normalizes the vector, dividing by the length(), and return a new vector

### normalizeIfGreaterOne

• normalizeIfGreaterOne(): Vector
• Normalizes the vector, dividing by the length(), and return a new vector

### normalizedDirection

• normalizedDirection(v: any): Vector
• Returns the normalized vector to the other point

### rotated

• Rotates this vector

new vector

### round

• Computes componentwise round and return a new vector

### serializeSimple

• serializeSimple(): object
• Creates a simple representation of the vector

### serializeTile

• serializeTile(): string
• Serializes the vector to a string

### serializeTileToInt

• serializeTileToInt(): any

### snapWorldToTile

• Converts the top left tile position of this vector

### sub

• Substracts a vector and return a new vector

### subScalar

• Substracts a scalar and return a new vector

### subScalars

• subScalars(x: any, y: any): Vector
• Substracts two scalars and return a new vector

### toStreetSpace

• Converts this vector from world to street space and return a new vector

### toString

• toString(): string
• Returns a string representation of the vector

### toTileSpace

• Converts this vector from world to tile space and return a new vector

### toWorldSpace

• Converts this vector to world space and return a new vector

### toWorldSpaceCenterOfTile

• toWorldSpaceCenterOfTile(): Vector
• Converts this vector to world space and return a new vector

### Static deserializeTile

• deserializeTile(s: any): Vector
• Deserializes a vector from a string

### Static deserializeTileFromInt

• deserializeTileFromInt(i: any): Vector

### Static fromSerializedObject

• fromSerializedObject(obj: any): Vector
• Deserializes a vector from a serialized json object