From 218ba4f20989d05ad24a35fafda6f0d39cfa7b89 Mon Sep 17 00:00:00 2001 From: Julie Lala Date: Thu, 10 Apr 2014 10:36:11 -0400 Subject: midpoint, center --- rectangles.html | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'rectangles.html') 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) -- cgit v1.2.3-70-g09d2