summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rectangles.html6
1 files changed, 6 insertions, 0 deletions
diff --git a/rectangles.html b/rectangles.html
index 086ce27..8878985 100644
--- a/rectangles.html
+++ b/rectangles.html
@@ -40,6 +40,9 @@ vec2.prototype.normalize = function(){
}
return this
}
+vec2.prototype.midpoint = function(){
+ return lerp(0.5, this.a, this.b)
+}
vec2.prototype.add = function(n){
this.a += n
this.b += n
@@ -92,6 +95,9 @@ function rect (x0,y0,x1,y1){
rect.prototype.clone = function(){
return new rect( this.x.clone(), this.y.clone() )
}
+rect.prototype.center = function(){
+ return new vec2(this.x.midpoint(), this.y.midpoint())
+}
rect.prototype.normalize = function(){
this.x.normalize().add(this.translation.a)
this.y.normalize().add(this.translation.b)