From 99a820a73f5948586742404820f06fb6dfa847da Mon Sep 17 00:00:00 2001 From: Yehor Kharchenko Date: Sat, 24 Oct 2026 19:05:39 +0200 Subject: [PATCH] Access vector components through their backing fields --- packages/typegpu/src/data/vectorImpl.ts | 72 ++++++++++++------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/packages/typegpu/src/data/vectorImpl.ts b/packages/typegpu/src/data/vectorImpl.ts index abb714d267..e993648d56 100644 --- a/packages/typegpu/src/data/vectorImpl.ts +++ b/packages/typegpu/src/data/vectorImpl.ts @@ -142,35 +142,35 @@ abstract class Vec2 extends VecBase implements Tuple2 { } get x() { - return this[0]; + return this.e0; } get y() { - return this[1]; + return this.e1; } set x(value: S) { - this[0] = this.castElement()(value); + this.e0 = this.castElement()(value); } set y(value: S) { - this[1] = this.castElement()(value); + this.e1 = this.castElement()(value); } get r() { - return this[0]; + return this.e0; } get g() { - return this[1]; + return this.e1; } set r(value: S) { - this[0] = this.castElement()(value); + this.e0 = this.castElement()(value); } set g(value: S) { - this[1] = this.castElement()(value); + this.e1 = this.castElement()(value); } } @@ -213,51 +213,51 @@ abstract class Vec3 extends VecBase implements Tuple3 { } get x() { - return this[0]; + return this.e0; } get y() { - return this[1]; + return this.e1; } get z() { - return this[2]; + return this.e2; } set x(value: S) { - this[0] = this.castElement()(value); + this.e0 = this.castElement()(value); } set y(value: S) { - this[1] = this.castElement()(value); + this.e1 = this.castElement()(value); } set z(value: S) { - this[2] = this.castElement()(value); + this.e2 = this.castElement()(value); } get r() { - return this[0]; + return this.e0; } get g() { - return this[1]; + return this.e1; } get b() { - return this[2]; + return this.e2; } set r(value: S) { - this[0] = this.castElement()(value); + this.e0 = this.castElement()(value); } set g(value: S) { - this[1] = this.castElement()(value); + this.e1 = this.castElement()(value); } set b(value: S) { - this[2] = this.castElement()(value); + this.e2 = this.castElement()(value); } } @@ -310,67 +310,67 @@ abstract class Vec4 extends VecBase implements Tuple4 { } get x() { - return this[0]; + return this.e0; } get y() { - return this[1]; + return this.e1; } get z() { - return this[2]; + return this.e2; } get w() { - return this[3]; + return this.e3; } set x(value: S) { - this[0] = value; + this.e0 = this.castElement()(value); } set y(value: S) { - this[1] = value; + this.e1 = this.castElement()(value); } set z(value: S) { - this[2] = value; + this.e2 = this.castElement()(value); } set w(value: S) { - this[3] = value; + this.e3 = this.castElement()(value); } get r() { - return this[0]; + return this.e0; } get g() { - return this[1]; + return this.e1; } get b() { - return this[2]; + return this.e2; } get a() { - return this[3]; + return this.e3; } set r(value: S) { - this[0] = value; + this.e0 = this.castElement()(value); } set g(value: S) { - this[1] = value; + this.e1 = this.castElement()(value); } set b(value: S) { - this[2] = value; + this.e2 = this.castElement()(value); } set a(value: S) { - this[3] = value; + this.e3 = this.castElement()(value); } }