summaryrefslogtreecommitdiff
path: root/public/assets/javascripts/rectangles/models/vec2.js
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2016-10-28 18:07:56 -0400
committerJules Laplace <jules@okfoc.us>2016-10-28 18:07:56 -0400
commita9c9d6adf470d0966e6c6bef0803e298fd2d4117 (patch)
tree6ccec2a448992a5f43226532051a6df09afbc203 /public/assets/javascripts/rectangles/models/vec2.js
parent343b0b3dc5bb7dbe762182a486e63a4aff6ef8fc (diff)
parent9e7bacd46c1e5d0e1c24433690d421ab3f3a11f2 (diff)
merge
Diffstat (limited to 'public/assets/javascripts/rectangles/models/vec2.js')
-rw-r--r--public/assets/javascripts/rectangles/models/vec2.js18
1 files changed, 16 insertions, 2 deletions
diff --git a/public/assets/javascripts/rectangles/models/vec2.js b/public/assets/javascripts/rectangles/models/vec2.js
index 14d0e6b..8942d92 100644
--- a/public/assets/javascripts/rectangles/models/vec2.js
+++ b/public/assets/javascripts/rectangles/models/vec2.js
@@ -43,6 +43,9 @@
vec2.prototype.eq = function(v){
return this.a == v.a && this.b == v.b
}
+ vec2.prototype.isPoint = function(){
+ return this.a == this.b
+ }
vec2.prototype.add = function(n){
this.a += n
this.b += n
@@ -80,6 +83,11 @@
this.a = Math.round(this.a)
this.b = Math.round(this.b)
}
+ vec2.prototype.distanceTo = function(v){
+ var va = (this.a - v.a)
+ var vb = (this.b - v.b)
+ return Math.sqrt( va*va + vb*vb )
+ }
vec2.prototype.setPosition = function(n){
var len = this.length()
this.a = n
@@ -103,6 +111,12 @@
vec2.prototype.containsDisc = function(n,r){
return this.a <= n-r && n+r <= this.b
}
+ vec2.prototype.containsVec = function(v){
+ return this.a <= v.a && v.b <= this.b
+ }
+ vec2.prototype.containsCenterVec = function(v){
+ return this.a < v.a && v.b < this.b
+ }
vec2.prototype.clamp = function(n){
return clamp(n, this.a, this.b)
}
@@ -200,13 +214,13 @@
}
vec2.prototype.toString = function(){
- return "[" + round(this.a) + " " + round(this.b) + "]"
+ return "[" + Math.round(this.a) + " " + Math.round(this.b) + "]"
}
vec2.prototype.exactString = function(){
return "[" + this.a + " " + this.b + "]"
}
vec2.prototype.serialize = function(){
- return [ round(this.a), round(this.b) ]
+ return [ Math.round(this.a), Math.round(this.b) ]
}
vec2.prototype.deserialize = function(data){
this.a = data[0]