Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Vector

Hierarchy

  • Vector

Index

Constructors

constructor

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

    • x: any
    • y: any

    Returns Vector

Methods

abs

  • Computes the component wise absolute

    Returns Vector

add

  • Adds a vector and return a new vector

    Parameters

    • other: any

    Returns Vector

addInplace

  • addInplace(other: any): this
  • Adds a vector

    Parameters

    • other: any

    Returns this

addScalar

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

    Parameters

    • f: any

    Returns Vector

addScalars

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

    Parameters

    • x: any
    • y: any

    Returns Vector

angle

  • angle(): number
  • Returns the angle

    Returns number

    0 .. 2 PI

centerPoint

  • Computes and returns the center between both points

    Parameters

    • v: any

    Returns Vector

copy

  • return a copy of the vector

    Returns Vector

direction

  • Returns the unnormalized direction to the other point

    Parameters

    • v: any

    Returns Vector

distance

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

    Parameters

    • v: any

    Returns number

distanceSquare

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

    Parameters

    • v: any

    Returns number

divideScalar

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

    Parameters

    • f: any

    Returns Vector

divideScalarInplace

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

    Parameters

    • f: any

    Returns this

divideScalars

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

    Parameters

    • a: any
    • b: any

    Returns Vector

dot

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

    Parameters

    • v: any

    Returns number

equals

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

    Parameters

    • v: any

    Returns boolean

equalsEpsilon

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

    Parameters

    • v: any
    • Default value epsilon: number = 0.00001

    Returns boolean

findPerpendicular

  • Returns a perpendicular vector

    Returns Vector

floor

  • Computes componentwise floor and return a new vector

    Returns Vector

length

  • length(): number
  • Returns the euclidian length

    Returns number

lengthSquare

  • lengthSquare(): number
  • Returns the square length

    Returns number

max

  • Computes the component wise maximum and return a new vector

    Parameters

    • v: any

    Returns 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)

    Parameters

    • f: any

    Returns Vector

min

  • Computes the component wise minimum and return a new vector

    Parameters

    • v: any

    Returns Vector

mul

  • Multiplies with a vector and return a new vector

    Parameters

    • other: any

    Returns Vector

multiplyScalar

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

    Parameters

    • f: any

    Returns Vector

multiplyScalars

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

    Parameters

    • a: any
    • b: any

    Returns Vector

normalize

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

    Returns Vector

normalizeIfGreaterOne

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

    Returns Vector

normalizedDirection

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

    Parameters

    • v: any

    Returns Vector

rotated

  • Rotates this vector

    Parameters

    • angle: any

    Returns Vector

    new vector

round

  • Computes componentwise round and return a new vector

    Returns Vector

serializeSimple

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

    Returns object

    • x: any
    • y: any

serializeTile

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

    Returns string

serializeTileToInt

  • serializeTileToInt(): any
  • Returns any

snapWorldToTile

  • Converts the top left tile position of this vector

    Returns Vector

sub

  • Substracts a vector and return a new vector

    Parameters

    • other: any

    Returns Vector

subScalar

  • Substracts a scalar and return a new vector

    Parameters

    • f: any

    Returns Vector

subScalars

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

    Parameters

    • x: any
    • y: any

    Returns Vector

toStreetSpace

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

    Returns Vector

toString

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

    Returns string

toTileSpace

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

    Returns Vector

toWorldSpace

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

    Returns Vector

toWorldSpaceCenterOfTile

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

    Returns Vector

Static deserializeTile

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

    Parameters

    • s: any

    Returns Vector

Static deserializeTileFromInt

  • deserializeTileFromInt(i: any): Vector
  • Parameters

    • i: any

    Returns Vector

Static fromSerializedObject

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

    Parameters

    • obj: any

    Returns Vector