nodequad

Vector

function
Vector()

Option name Type Description
x String
y String
z String

Vector object to store and handle three related floating point values

function Vector(x, y, z) {
	this.x = parseFloat(x);
	this.y = parseFloat(y); 
	this.z = parseFloat(z);
}

PRECISION

property
Vector.PRECISION

Precision used in rounding during serialization/deserialization

Vector.PRECISION = 2;

toJSON

method
Vector.prototype.toJSON() ->String

Get the serailized JSON representation of the object

Vector.prototype.toJSON = function toJSON() {
	return [this.x.toFixed(Vector.PRECISION), this.y.toFixed(Vector.PRECISION), this.z.toFixed(Vector.PRECISION)];
};

deserialize

method
Vector.deserialize() ->Object

Option name Type Description
x Array

Creates a Vector object from a previously serialized JSON array

Vector.deserialize = function(val) {
	return new Vector(val[0], val[1], val[2]);
};