summaryrefslogtreecommitdiff
path: root/public/assets/javascripts/rectangles/models/vec2.js
diff options
context:
space:
mode:
Diffstat (limited to 'public/assets/javascripts/rectangles/models/vec2.js')
-rw-r--r--public/assets/javascripts/rectangles/models/vec2.js19
1 files changed, 12 insertions, 7 deletions
diff --git a/public/assets/javascripts/rectangles/models/vec2.js b/public/assets/javascripts/rectangles/models/vec2.js
index 9233aec..9c6fd99 100644
--- a/public/assets/javascripts/rectangles/models/vec2.js
+++ b/public/assets/javascripts/rectangles/models/vec2.js
@@ -80,16 +80,22 @@
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)
- }
- else if (this.a == v.a) {
+ if (this.a == v.a) { // || this.b == v.b || this.a == v.b || this.b == v.a) {
return true
}
+ else 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 (this.a < v.b && v.b <= this.b) || (v.a < this.b && this.b <= v.b)
}
}
+ vec2.prototype.adjacent = function(v){
+ if (this.a == v.a || this.b == v.b || this.a == v.b || this.b == v.a) {
+ return true
+ }
+ return false
+ }
vec2.prototype.union = function(v){
if (this.intersects(v)) {
return new vec2( min(this.a,v.a), max(this.b, v.b) )
@@ -115,8 +121,7 @@
if ('window' in this) {
window.vec2 = vec2
}
- else if ('module' in this) {
+ else {
module.exports = vec2
}
-
-})() \ No newline at end of file
+})()