Skip to content

Commit

Permalink
feat(vector): 2d, 3d and 4d getter
Browse files Browse the repository at this point in the history
  • Loading branch information
rickkky committed Mar 3, 2024
1 parent 2ff601e commit 198c6eb
Show file tree
Hide file tree
Showing 3 changed files with 246 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/vector2-base.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { VectorBase } from './vector-base';
import { Vector2 } from './vector2';

export abstract class Vector2Base extends VectorBase {
get 0() {
Expand Down Expand Up @@ -32,4 +33,12 @@ export abstract class Vector2Base extends VectorBase {
set y(n: number) {
this[1] = n;
}

get xy() {
return new Vector2(this.x, this.y);
}

get yx() {
return new Vector2(this.y, this.x);
}
}
42 changes: 42 additions & 0 deletions src/vector3-base.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { Vector2Base } from './vector2-base';
import { Vector2 } from './vector2';
import { Vector3 } from './vector3';

export abstract class Vector3Base extends Vector2Base {
get 2() {
Expand All @@ -16,4 +18,44 @@ export abstract class Vector3Base extends Vector2Base {
set z(n: number) {
this[2] = n;
}

get xz() {
return new Vector2(this.x, this.z);
}

get yz() {
return new Vector2(this.y, this.z);
}

get zx() {
return new Vector2(this.z, this.x);
}

get zy() {
return new Vector2(this.z, this.y);
}

get xyz() {
return new Vector3(this.x, this.y, this.z);
}

get xzy() {
return new Vector3(this.x, this.z, this.y);
}

get yxz() {
return new Vector3(this.y, this.x, this.z);
}

get yzx() {
return new Vector3(this.y, this.z, this.x);
}

get zxy() {
return new Vector3(this.z, this.x, this.y);
}

get zyx() {
return new Vector3(this.z, this.y, this.x);
}
}
195 changes: 195 additions & 0 deletions src/vector4-base.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { Vector3Base } from './vector3-base';
import { Vector2 } from './vector2';
import { Vector3 } from './vector3';
import { Vector4 } from './vector4';

export abstract class Vector4Base extends Vector3Base {
get 3() {
Expand All @@ -16,4 +19,196 @@ export abstract class Vector4Base extends Vector3Base {
set w(n: number) {
this[3] = n;
}

get xw() {
return new Vector2(this.x, this.w);
}

get yw() {
return new Vector2(this.y, this.w);
}

get zw() {
return new Vector2(this.z, this.w);
}

get wx() {
return new Vector2(this.w, this.x);
}

get wy() {
return new Vector2(this.w, this.y);
}

get wz() {
return new Vector2(this.w, this.z);
}

get xyw() {
return new Vector3(this.x, this.y, this.w);
}

get xzw() {
return new Vector3(this.x, this.z, this.w);
}

get xwy() {
return new Vector3(this.x, this.w, this.y);
}

get xwz() {
return new Vector3(this.x, this.w, this.z);
}

get yxw() {
return new Vector3(this.y, this.x, this.w);
}

get yzw() {
return new Vector3(this.y, this.z, this.w);
}

get ywx() {
return new Vector3(this.y, this.w, this.x);
}

get ywz() {
return new Vector3(this.y, this.w, this.z);
}

get zxw() {
return new Vector3(this.z, this.x, this.w);
}

get zyw() {
return new Vector3(this.z, this.y, this.w);
}

get zwx() {
return new Vector3(this.z, this.w, this.x);
}

get zwy() {
return new Vector3(this.z, this.w, this.y);
}

get wxy() {
return new Vector3(this.w, this.x, this.y);
}

get wxz() {
return new Vector3(this.w, this.x, this.z);
}

get wyx() {
return new Vector3(this.w, this.y, this.x);
}

get wyz() {
return new Vector3(this.w, this.y, this.z);
}

get wzx() {
return new Vector3(this.w, this.z, this.x);
}

get wzy() {
return new Vector3(this.w, this.z, this.y);
}

get xyzw() {
return new Vector4(this.x, this.y, this.z, this.w);
}

get xywz() {
return new Vector4(this.x, this.y, this.w, this.z);
}

get xzyw() {
return new Vector4(this.x, this.z, this.y, this.w);
}

get xzwy() {
return new Vector4(this.x, this.z, this.w, this.y);
}

get xwyz() {
return new Vector4(this.x, this.w, this.y, this.z);
}

get xwzy() {
return new Vector4(this.x, this.w, this.z, this.y);
}

get yxzw() {
return new Vector4(this.y, this.x, this.z, this.w);
}

get yxwz() {
return new Vector4(this.y, this.x, this.w, this.z);
}

get yzxw() {
return new Vector4(this.y, this.z, this.x, this.w);
}

get yzwx() {
return new Vector4(this.y, this.z, this.w, this.x);
}

get ywxz() {
return new Vector4(this.y, this.w, this.x, this.z);
}

get ywzx() {
return new Vector4(this.y, this.w, this.z, this.x);
}

get zxyw() {
return new Vector4(this.z, this.x, this.y, this.w);
}

get zxwy() {
return new Vector4(this.z, this.x, this.w, this.y);
}

get zyxw() {
return new Vector4(this.z, this.y, this.x, this.w);
}

get zywx() {
return new Vector4(this.z, this.y, this.w, this.x);
}

get zwxy() {
return new Vector4(this.z, this.w, this.x, this.y);
}

get zwyx() {
return new Vector4(this.z, this.w, this.y, this.x);
}

get wxyz() {
return new Vector4(this.w, this.x, this.y, this.z);
}

get wxzy() {
return new Vector4(this.w, this.x, this.z, this.y);
}

get wyxz() {
return new Vector4(this.w, this.y, this.x, this.z);
}

get wyzx() {
return new Vector4(this.w, this.y, this.z, this.x);
}

get wzxy() {
return new Vector4(this.w, this.z, this.x, this.y);
}

get wzyx() {
return new Vector4(this.w, this.z, this.y, this.x);
}
}

0 comments on commit 198c6eb

Please sign in to comment.