From 0e4bc72fe453797743d63f57db47ef3e0468fc65 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Thu, 24 Apr 2014 16:36:49 -0400 Subject: collide based on a radius --- assets/javascripts/rectangles/models/vec2.js | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'assets/javascripts/rectangles/models/vec2.js') diff --git a/assets/javascripts/rectangles/models/vec2.js b/assets/javascripts/rectangles/models/vec2.js index 3105fec..7307fca 100644 --- a/assets/javascripts/rectangles/models/vec2.js +++ b/assets/javascripts/rectangles/models/vec2.js @@ -54,6 +54,15 @@ vec2.normalize = function(){ vec2.prototype.contains = function(n){ return this.a <= n && n <= this.b } +vec2.prototype.containsDisc = function(n,r){ + return this.a <= n-r && n+r <= this.b +} +vec2.prototype.clamp = function(n){ + return clamp(n, this.a, this.b) +} +vec2.prototype.clampDisc = function(n,r){ + return clamp(n, this.a+r, this.b-r) +} vec2.prototype.intersects = function(v){ if (this.a < v.a) { return (v.a < this.b && this.b <= v.b) || (this.a < v.b && v.b <= this.b) -- cgit v1.2.3-70-g09d2