2014-01-08 23:06:08 +00:00
|
|
|
/**
|
|
|
|
* Common classes.
|
|
|
|
*/
|
2014-01-11 16:40:01 +00:00
|
|
|
goog.provide('ascii.Vector');
|
2014-01-08 23:06:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @constructor
|
2014-01-12 10:37:38 +00:00
|
|
|
* @param {number} x
|
|
|
|
* @param {number} y
|
2014-01-08 23:06:08 +00:00
|
|
|
*/
|
2014-01-11 16:40:01 +00:00
|
|
|
ascii.Vector = function(x, y) {
|
2014-01-08 23:06:08 +00:00
|
|
|
/** type {Number} */ this.x = x;
|
|
|
|
/** type {Number} */ this.y = y;
|
|
|
|
};
|
2014-01-09 20:18:46 +00:00
|
|
|
|
2014-01-12 10:37:38 +00:00
|
|
|
/**
|
|
|
|
* @param {ascii.Vector} other
|
|
|
|
* @return {boolean}
|
|
|
|
*/
|
2014-01-11 16:40:01 +00:00
|
|
|
ascii.Vector.prototype.equals = function(other) {
|
2014-01-12 10:37:38 +00:00
|
|
|
return (this.x == other.x) && (this.y == other.y);
|
2014-01-09 20:18:46 +00:00
|
|
|
};
|
2014-01-11 16:40:01 +00:00
|
|
|
|
2014-01-12 10:37:38 +00:00
|
|
|
/**
|
|
|
|
* @param {ascii.Vector} other
|
|
|
|
* @return {boolean}
|
|
|
|
*/
|
2014-01-11 16:40:01 +00:00
|
|
|
ascii.Vector.prototype.subtract = function(other) {
|
|
|
|
return new ascii.Vector(this.x - other.x, this.y - other.y);
|
|
|
|
};
|
|
|
|
|
2014-01-12 10:37:38 +00:00
|
|
|
/**
|
|
|
|
* @param {ascii.Vector} other
|
|
|
|
* @return {boolean}
|
|
|
|
*/
|
2014-01-11 16:40:01 +00:00
|
|
|
ascii.Vector.prototype.add = function(other) {
|
|
|
|
return new ascii.Vector(this.x + other.x, this.y + other.y);
|
|
|
|
};
|
|
|
|
|
|
|
|
/** @return {number} */
|
|
|
|
ascii.Vector.prototype.length = function() {
|
|
|
|
return Math.sqrt(this.x * this.x + this.y * this.y);
|
|
|
|
};
|
2014-01-11 17:41:44 +00:00
|
|
|
|
2014-01-12 10:37:38 +00:00
|
|
|
/**
|
|
|
|
* @param {number} scale
|
|
|
|
* @return {ascii.Vector}
|
|
|
|
*/
|
2014-01-11 17:41:44 +00:00
|
|
|
ascii.Vector.prototype.scale = function(scale) {
|
|
|
|
return new ascii.Vector(this.x * scale, this.y * scale);
|
|
|
|
};
|
|
|
|
|