diff options
Diffstat (limited to 'vec2.js')
| -rw-r--r-- | vec2.js | 14 |
1 files changed, 12 insertions, 2 deletions
@@ -22,6 +22,9 @@ vec2.prototype.abs = function(){ vec2.prototype.midpoint = function(){ return lerp(0.5, this.a, this.b) } +vec2.prototype.eq = function(v){ + return this.a == v.a && this.b == v.b +} vec2.prototype.add = function(n){ this.a += n this.b += n @@ -41,9 +44,16 @@ vec2.prototype.div = function(n){ vec2.prototype.contains = function(n){ return this.a <= n && n <= this.b } -// assumes (vec2)v falls to the right of (vec2)this vec2.prototype.intersects = function(v){ - return (this.b > v.a && this.b < v.b) || (v.b > this.a && v.b < this.b) + if (this.a < v.a) { + return (v.a < this.b && this.b <= v.b) || (this.a < v.b && v.b <= this.b) + } + else if (this.a == v.a) { + return true + } + else if (this.a > v.a) { + return (this.a < v.b && v.b <= this.b) || (v.a < this.b && this.b <= v.b) + } } vec2.prototype.union = function(v){ if (this.intersects(v)) { |
