Permalink
Browse files

always return self. added - limit

  • Loading branch information...
1 parent 4106829 commit 164535b1d3afcaec4b4ea85893c4589abbdc870a @swannodette committed Nov 4, 2009
Showing with 14 additions and 6 deletions.
  1. +4 −3 Vector2D.h
  2. +10 −3 Vector2D.m
View
@@ -49,9 +49,10 @@
- (BOOL) isEqual:(Vector2D*)other;
- (BOOL) isZero;
-- (void) clean;
-- (void) zero;
-- (void) normalize;
+- (Vector2D*) clean;
+- (Vector2D*) zero;
+- (Vector2D*) normalize;
+- (Vector2D*) limit:(float)limit;
- (Vector2D*) add:(Vector2D*)other;
- (Vector2D*) sub:(Vector2D*)other;
View
@@ -174,19 +174,20 @@ - (BOOL) isZero
return isZero(x*x + y*y);
}
-- (void) clean
+- (Vector2D*) clean
{
if(isZero(x)) x = 0.0f;
if(isZero(y)) y = 0.0f;
}
-- (void) zero
+- (Vector2D*) zero
{
x = 0.0f;
y = 0.0f;
+ return self;
}
-- (void) normalize
+- (Vector2D*) normalize
{
float lengthsq = x*x + y*y;
if (isZero(lengthsq))
@@ -200,6 +201,12 @@ - (void) normalize
x *= factor;
y *= factor;
}
+ return self;
+}
+
+- (Vector2D*) limit:(float)limit
+{
+ return [[self normalize] mult:limit];
}
- (Vector2D*) add:(Vector2D*)other

0 comments on commit 164535b

Please sign in to comment.