Skip to content

Commit

Permalink
if vec.length is 0 return 0 for normalized
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeMyst committed Jun 21, 2020
1 parent 4f73690 commit e414e2d
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions source/cosmomyst/math/vector.d
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,17 @@ struct vec(ulong n) if (n >= 1) {
+ normalizes the vectors. changes the current struct!
+/
@nogc void normalize() pure nothrow {
this = this / length();
this = normalized();
}

/++
+ returns the normalized vector. doesn't change the current struct!
+/
@nogc vec!n normalized() pure nothrow const {
auto res = this / length();
return res;
if (length() == 0) {
return vec!n(0f);
}
return this / length();
}

string toString() const {
Expand Down

0 comments on commit e414e2d

Please sign in to comment.