asciiflow2/js-lib/common.js

34 lines
746 B
JavaScript
Raw Normal View History

2014-01-08 23:06:08 +00:00
/**
* Common classes.
*/
goog.provide('ascii.Vector');
2014-01-08 23:06:08 +00:00
/**
* @constructor
*/
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
/** @return {boolean} */
ascii.Vector.prototype.equals = function(other) {
return (this.x == other.x)
&& (this.y == other.y);
2014-01-09 20:18:46 +00:00
};
/** @return {ascii.Vector} */
ascii.Vector.prototype.subtract = function(other) {
return new ascii.Vector(this.x - other.x, this.y - other.y);
};
/** @return {ascii.Vector} */
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);
};