(function(){ var point if ('window' in this) { point = window.point } else { point = require('./point') } var vec2 = function (x0,y0, x1,y1){ if (x0 instanceof point) { this.a = x0 this.b = y0 } else if (x1 === undefined) { this.a = new point(x0,y0) this.b = new point(x0,y0) } else { this.a = new point(x0,y0) this.b = new point(x1,y1) } } vec2.prototype.clone = function(){ return new vec2( this.a.clone(), this.b.clone() ) } vec2.prototype.delta = function(){ return new point( this.width(), this.height() ) } vec2.prototype.width = function(){ return this.b.x - this.a.x } vec2.prototype.height = function(){ return this.b.y - this.a.y } vec2.prototype.toString = function(){ var s = "[" + this.a.toString() + " " + this.b.toString() + "] " return s } vec2.prototype.exactString = function(){ var s = "[" + this.a.exactString() + " " + this.b.exactString() + "] " return s } vec2.prototype.serialize = function(){ return { a: this.a.serialize(), b: this.b.serialize() } } vec2.prototype.quantize = function(n){ this.a.quantize(n) this.b.quantize(n) return this } if ('window' in this) { window.vec2 = vec2 } else { module.exports = vec2 } })()