Skip to content

Commit

Permalink
feat(vector): remove createVector fn
Browse files Browse the repository at this point in the history
directly calling own constructor
  • Loading branch information
MrTelanie committed Sep 2, 2018
1 parent d21741c commit de3720a
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class AVector {

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

norm() {
Expand All @@ -47,7 +47,7 @@ class AVector {
}

cross(v) {
return this.createVector(
return new this.constructor(
this.y * v.z - this.z * v.y,
this.z * v.x - this.x * v.z,
this.x * v.y - this.y * v.x
Expand Down Expand Up @@ -86,13 +86,12 @@ class AVector {
x: qx, y: qy, z: qz, w: qw
} = quat;

// q*v
const ix = qw * x + qy * z - qz * y;
const iy = qw * y + qz * x - qx * z;
const iz = qw * z + qx * y - qy * x;
const iw = -qx * x - qy * y - qz * z;

return this.createVector(
return new this.constructor(
ix * qw + iw * -qx + iy * -qz - iz * -qy,
iy * qw + iw * -qy + iz * -qx - ix * -qz,
iz * qw + iw * -qz + ix * -qy - iy * -qx
Expand Down Expand Up @@ -180,10 +179,6 @@ export class Vector extends AVector {
clone() {
return new Vector(this.x, this.y, this.z);
}

createVector(x, y, z) {
return new Vector(x, y, z);
}
}

export class Victor extends AVector {
Expand Down Expand Up @@ -214,10 +209,6 @@ export class Victor extends AVector {
toVector() {
return new Vector(this.x, this.y, this.z);
}

createVector(x, y, z) {
return new Victor(x, y, z);
}
}

export function calc(alg) {
Expand Down

0 comments on commit de3720a

Please sign in to comment.