Vector

Vector

A Vector class.

Constructor

new Vector(left, top)

Parameters:
Name Type Description
left Number

The position of the vector's x-axis.

top Number

The position of the vector's y-axis.

Methods

add(other) → {Number}

Add other to this.

Parameters:
Name Type Description
other Vector
Returns:
Type:
Number

clone() → {Vector}

Clone the current vector to a new object.

Returns:
Type:
Vector

A clone of this instance

distance(other) → {Number}

Returns the distance between this and other.

Parameters:
Name Type Description
other Vector
Returns:
Type:
Number

distanceSquared(other) → {Number}

Returns the squared distance between this and other.

Parameters:
Name Type Description
other Vector
Returns:
Type:
Number

getBoundingBox() → {BoundingBox}

Returns a BoundingBox instance version of this vector similar to:

new BoundingBox(Vector.left, Vector.top, Vector.left, Vector.top)
Returns:
Type:
BoundingBox

getCollisionMesh() → {CollisionMesh}

Returns a CollisionMesh instance version of this vector similar to:

new CollisionMesh(Vector.getBoundingBox())
Returns:
Type:
CollisionMesh

getVector() → {Vector}

Resolve this object down to a Vector instance. Since this instance is already a vector, it returns itself.

Returns:
Type:
Vector

self

isNaN() → {Boolean}

Checks if any property on this is NaN.

Returns:
Type:
Boolean

moveBy(deltaLeftopt, deltaTopopt) → {Vector}

Move this relatively to position by deltaLeft and/or deltaTop.

Parameters:
Name Type Attributes Default Description
deltaLeft Number <optional>
null
deltaTop Number <optional>
null
Returns:
Type:
Vector

self

moveTo(leftopt, topopt) → {Vector}

Move this to position at left and/or top.

Parameters:
Name Type Attributes Default Description
left Number <optional>
null
top Number <optional>
null
Returns:
Type:
Vector

self

set(other) → {Vector}

Sets this.left to other.left, and sets this.top to other.top.

Parameters:
Name Type Description
other Vector
Returns:
Type:
Vector

self

setMax(other) → {Number}

Sets this's properties if other's is larger.

Parameters:
Name Type Description
other Vector
Returns:
Type:
Number

setMin(other) → {Number}

Sets this's properties if other's is smaller.

Parameters:
Name Type Description
other Vector
Returns:
Type:
Number

subtract(other) → {Number}

Subtract other from this.

Parameters:
Name Type Description
other Vector
Returns:
Type:
Number