Skip to content

Commit

Permalink
feat: vector normalize function
Browse files Browse the repository at this point in the history
  • Loading branch information
MrTelanie committed Aug 12, 2018
1 parent 7bfcda9 commit f08c7be
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/vector.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

let inProgress = 'default';

const v3ValueOf = {
Expand Down Expand Up @@ -56,6 +55,15 @@ export class Vector {
return v3ValueOf[inProgress].call(this);
}

normalize() {
const { length } = this;
return new Vector(this.x / length, this.y / length, this.z / length);
}

norm() {
return this.normalize();
}

toString() {
return `[${this.x}, ${this.y}, ${this.z}]`;
}
Expand Down

0 comments on commit f08c7be

Please sign in to comment.