From af825cefe94eb8a677d61bc6721451af63105988 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Tue, 15 Apr 2014 14:47:56 -0400 Subject: rect clipping works properly --- vec2.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'vec2.js') diff --git a/vec2.js b/vec2.js index 973613f..f4d6a84 100644 --- a/vec2.js +++ b/vec2.js @@ -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)) { -- cgit v1.2.3-70-g09d2