Skip to content

Commit de3720a

Browse files
committed
feat(vector): remove createVector fn
directly calling own constructor
1 parent d21741c commit de3720a

File tree

1 file changed

+3
-12
lines changed

1 file changed

+3
-12
lines changed

src/index.js

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class AVector {
3232

3333
normalize() {
3434
const { length } = this;
35-
return this.createVector(this.x / length, this.y / length, this.z / length);
35+
return new this.constructor(this.x / length, this.y / length, this.z / length);
3636
}
3737

3838
norm() {
@@ -47,7 +47,7 @@ class AVector {
4747
}
4848

4949
cross(v) {
50-
return this.createVector(
50+
return new this.constructor(
5151
this.y * v.z - this.z * v.y,
5252
this.z * v.x - this.x * v.z,
5353
this.x * v.y - this.y * v.x
@@ -86,13 +86,12 @@ class AVector {
8686
x: qx, y: qy, z: qz, w: qw
8787
} = quat;
8888

89-
// q*v
9089
const ix = qw * x + qy * z - qz * y;
9190
const iy = qw * y + qz * x - qx * z;
9291
const iz = qw * z + qx * y - qy * x;
9392
const iw = -qx * x - qy * y - qz * z;
9493

95-
return this.createVector(
94+
return new this.constructor(
9695
ix * qw + iw * -qx + iy * -qz - iz * -qy,
9796
iy * qw + iw * -qy + iz * -qx - ix * -qz,
9897
iz * qw + iw * -qz + ix * -qy - iy * -qx
@@ -180,10 +179,6 @@ export class Vector extends AVector {
180179
clone() {
181180
return new Vector(this.x, this.y, this.z);
182181
}
183-
184-
createVector(x, y, z) {
185-
return new Vector(x, y, z);
186-
}
187182
}
188183

189184
export class Victor extends AVector {
@@ -214,10 +209,6 @@ export class Victor extends AVector {
214209
toVector() {
215210
return new Vector(this.x, this.y, this.z);
216211
}
217-
218-
createVector(x, y, z) {
219-
return new Victor(x, y, z);
220-
}
221212
}
222213

223214
export function calc(alg) {

0 commit comments

Comments
 (0)