Illuminated.js Docs (v0.1)

A 2D lights and shadows rendering engine for your HTML5 web applications and games.
Show:

illuminated.Vec2 Class

Defined in: src/illuminated.js:32
Module: illuminated

Vec2 represents a 2d position or a 2d vector. It is used everywhere in Illuminated.js.

Vec2 is based on Box2d’s Vec2 except that in Illuminated.js a Vec2 vector is immutable. It means every method creates a new Vec2 instance and you can safely use a same Vec2 instance everywhere because the immutability guarantees that properties will not be modified.

Constructor

illuminated.Vec2

(
  • [x=0]
  • [y=0]
)

Parameters:

  • [x=0] Number optional

    X coordinate for the vector.

  • [y=0] Number optional

    Y coordinate for the vector.

Item Index

Properties

Methods

add

(
  • v
)
illuminated.Vec2

Adds the given vector to this vector.

Parameters:

Returns:

illuminated.Vec2: A new vector that is the result of the addition.

copy

() illuminated.Vec2

Returns a copy of this vector.

Returns:

illuminated.Vec2: A new vector that is a copy of this vector.

dist2

(
  • v
)
Number

Calculates the squared distance between this vector and the given vector.

Parameters:

Returns:

Number: The squared distance.

dot

(
  • v
)
Number

Calculates the dot product of this vector and the given vector.

Parameters:

Returns:

Number: The result of the dot product.

inBound

(
  • topleft
  • bottomright
)
Boolean

Determines if this vector is within the bounds defined by the given vectors.

Parameters:

Returns:

Boolean: True if this vector is within the given bounds.

inv

() illuminated.Vec2

Returns the inverse of this vector.

Returns:

illuminated.Vec2: A new vector that is the inverse of this vector.

length2

() Number

Calculates the squared length of this vector.

Returns:

Number: The squared length.

mul

(
  • v
)
illuminated.Vec2

Multiplies the given vector with this vector.

Parameters:

Returns:

illuminated.Vec2: A new vector that is the result of the multiplication.

normalize

() illuminated.Vec2

Calculates the normalized form of this vector.

Returns:

illuminated.Vec2: A new vector in normalized form.

sub

(
  • v
)
illuminated.Vec2

Subtracts the given vector from this vector.

Parameters:

Returns:

illuminated.Vec2: A new vector that is the result of the subtraction.

toString

() String

Returns a string representing this vector.

Returns:

String: A string representing this vector.

Properties

x

Number

X coordinate for the vector.

Default: 0

y

Number

Y coordinate for the vector.

Default: 0