summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rect.js2
-rw-r--r--rectangles.html6
-rw-r--r--vec2.js5
3 files changed, 9 insertions, 4 deletions
diff --git a/rect.js b/rect.js
index f1f19e1..94a537b 100644
--- a/rect.js
+++ b/rect.js
@@ -22,7 +22,7 @@ rect.prototype.center = function(){
rect.prototype.area = function(){
return this.x.length() * this.y.length()
}
-rect.prototype.normalize = function(){
+rect.prototype.translate = function(){
this.x.abs().add(this.translation.a)
this.y.abs().add(this.translation.b)
this.translation.a = this.translation.b = 0
diff --git a/rectangles.html b/rectangles.html
index 71f83c6..32790d7 100644
--- a/rectangles.html
+++ b/rectangles.html
@@ -131,11 +131,11 @@ canvas.addEventListener("mousemove", function(e){
document.addEventListener("mouseup", function(e){
if (creating) {
if (mouse.height() != 0 && mouse.width() != 0) {
- rects.push(mouse.normalize())
+ rects.push(mouse.translate())
}
}
if (dragging) {
- dragging.normalize()
+ dragging.translate()
}
mouse = new rect(e.pageX, e.pageY)
creating = dragging = false
@@ -258,7 +258,7 @@ function draw_mouse(){
}
else {
ctx.fillStyle = "rgba(255,255,0,0.5)"
- mouse.clone().normalize().fill()
+ mouse.clone().translate().fill()
}
}
}
diff --git a/vec2.js b/vec2.js
index 973613f..aae1c25 100644
--- a/vec2.js
+++ b/vec2.js
@@ -38,6 +38,11 @@ vec2.prototype.div = function(n){
this.a /= n
this.b /= n
}
+vec2.normalize = function(){
+ var dim = max(this.a, this.b)
+ this.a = this.a/dim
+ this.b = this.b/dim
+}
vec2.prototype.contains = function(n){
return this.a <= n && n <= this.b
}