diff options
| author | Jules Laplace <jules@okfoc.us> | 2014-04-24 16:36:49 -0400 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2014-04-24 16:36:49 -0400 |
| commit | 0e4bc72fe453797743d63f57db47ef3e0468fc65 (patch) | |
| tree | 31c8983117d7043ff2af5bc315691900ae80a592 /assets/javascripts/rectangles/models/vec2.js | |
| parent | 796e1194d13bfa16f41676d81f7d9cdb4b9fc96f (diff) | |
collide based on a radius
Diffstat (limited to 'assets/javascripts/rectangles/models/vec2.js')
| -rw-r--r-- | assets/javascripts/rectangles/models/vec2.js | 9 |
1 files changed, 9 insertions, 0 deletions
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) |
