thrungames

Vector

Simple vector class.

THRUNIUM.Vector(x, y)

x Number
y Number
return Object

Contructor function for THRUNIUM Vector class.

var vector = new THRUNIUM.Vector(10, 20);

clone()

return THRUNIUM.Vector

This clones the vector and returns it.

var vector = new THRUNIUM.Vector(10, 20);
var clonedVector = vector.clone();
console.log(clonedVector);
// outputs the cloned vector

normalize()

This normalizes the vector so the length of it is one.

var vector = new THRUNIUM.Vector(10, 20);
vector.normalize();
console.log(vector);
// outputs the normalized vector

limit(vector)

vector THRUNIUM.Vector

This limits the vector for exceeding a certain vector

var vector = new THRUNIUM.Vector(10, 20);
var limitVector = new THRUNIUM.Vector(10, 10);
vector.limit(limitVector);
console.log(vector);
// outputs the vector but with values (10, 10)

Scale

scale(scale)

scale Number

This scales the vector with 'scale' amount

var vector = new THRUNIUM.Vector(10, 20);
vector.scale(2);
console.log(vector);
// outputs the vector with values (20, 40)

scaleX(scale)

scale Number

This scales the vectors x value with 'scale' amount

var vector = new THRUNIUM.Vector(10, 20);
vector.scaleX(2);
console.log(vector);
// outputs the vector with values (20, 20)

scaleY(scale)

scale Number

This scales the vectors y value with 'scale' amount

var vector = new THRUNIUM.Vector(10, 20);
vector.scaleY(2);
console.log(vector);
// outputs the vector with values (10, 40)

Add

add(vector)

vector THRUNIUM.Vector

This adds a vector to the vector

var vector = new THRUNIUM.Vector(10, 20);
var addVector = new THRUNIUM.Vector(5, 2);
vector.add(addVector);
console.log(vector);
// outputs the vector with values (15, 22)

addX(vector)

vector THRUNIUM.Vector

This adds a vectors x value to the vectors x value

var vector = new THRUNIUM.Vector(10, 20);
var addVector = new THRUNIUM.Vector(5, 2);
vector.addX(addVector);
console.log(vector);
// outputs the vector with values (15, 20)

addY(vector)

vector THRUNIUM.Vector

This adds a vectors y value to the vectors y value

var vector = new THRUNIUM.Vector(10, 20);
var addVector = new THRUNIUM.Vector(5, 2);
vector.addY(addVector);
console.log(vector);
// outputs the vector with values (10, 22)

Subtract

subtract(vector)

vector THRUNIUM.Vector

This subtracts a vector from the vector

var vector = new THRUNIUM.Vector(10, 20);
var subtractVector = new THRUNIUM.Vector(2, 10);
vector.subtract(subtractVector);
console.log(vector);
// outputs the vector with values (8, 10)

subtractX(vector)

vector THRUNIUM.Vector

This subtracts a vectors x value from the vectors x value

var vector = new THRUNIUM.Vector(10, 20);
var subtractVector = new THRUNIUM.Vector(2, 10);
vector.subtractX(subtractVector);
console.log(vector);
// outputs the vector with values (8, 20)

subtractY(vector)

vector THRUNIUM.Vector

This subtracts a vectors y value from the vectors y value

var vector = new THRUNIUM.Vector(10, 20);
var subtractVector = new THRUNIUM.Vector(2, 10);
vector.subtractY(subtractVector);
console.log(vector);
// outputs the vector with values (10, 10)

Divide

divide(vector)

vector THRUNIUM.Vector

This divides a vector with the vector

var vector = new THRUNIUM.Vector(10, 20);
var divideVector = new THRUNIUM.Vector(2, 4);
vector.divide(divideVector);
console.log(vector);
// outputs the vector with values (5, 5)

divideX(vector)

vector THRUNIUM.Vector

This divides a vectors x value with the vectors x value

var vector = new THRUNIUM.Vector(10, 20);
var divideVector = new THRUNIUM.Vector(2, 4);
vector.divideX(divideVector);
console.log(vector);
// outputs the vector with values (5, 20)

divideY(vector)

vector THRUNIUM.Vector

This divides a vectors y value with the vectors y value

var vector = new THRUNIUM.Vector(10, 20);
var divideVector = new THRUNIUM.Vector(2, 4);
vector.divideY(divideVector);
console.log(vector);
// outputs the vector with values (10, 5)

Multiply

multiply(vector)

vector THRUNIUM.Vector

This multiplies a vector with the vector

var vector = new THRUNIUM.Vector(10, 20);
var multiplyVector = new THRUNIUM.Vector(4, 2);
vector.multiply(multiplyVector);
console.log(vector);
// outputs the vector with values (40, 40)

multiplyX(vector)

vector THRUNIUM.Vector

This multiplies a vectors x value with the vectors x value

var vector = new THRUNIUM.Vector(10, 20);
var multiplyVector = new THRUNIUM.Vector(4, 2);
vector.multiplyX(multiplyVector);
console.log(vector);
// outputs the vector with values (40, 20)

multiplyY(vector)

vector THRUNIUM.Vector

This multiplies a vectors y value with the vectors y value

var vector = new THRUNIUM.Vector(10, 20);
var multiplyVector = new THRUNIUM.Vector(4, 2);
vector.multiplyY(multiplyVector);
console.log(vector);
// outputs the vector with values (10, 40)

Invert

invert()

This inverts the vector

var vector = new THRUNIUM.Vector(10, 20);
vector.invert();
console.log(vector);
// outputs the vector with values (-10, -20)

invertX()

This inverts the vectors x value

var vector = new THRUNIUM.Vector(10, 20);
vector.invertX();
console.log(vector);
// outputs the vector with values (-10, 20)

invertY()

This inverts the vectors y value

var vector = new THRUNIUM.Vector(10, 20);
vector.invertY();
console.log(vector);
// outputs the vector with values (10, -20)