thi-ng / umbrella

⛱ Broadly scoped ecosystem & mono-repository of 198 TypeScript projects (and ~175 examples) for general purpose, functional, data driven development
https://thi.ng
Apache License 2.0
3.31k stars 144 forks source link

[vectors] Vec2 missing x and y coordinate #432

Closed dennemark closed 7 months ago

dennemark commented 7 months ago

I did not upgrade @thi.ng/vectors for a while. Was on version 7.5.14 and now upgraded to 7.8.9 I can´t really imagine it, but it seems like the x and y coordinates on a Vec2 class are missing.

console.log(new vec.Vec2([0, 1]))
//Vec2 {
//  buf: [ 0, 1 ],
//  offset: 0,
//  stride: 1,
//  x: undefined,
//  y: undefined
//}

Tried to trace it back to: https://github.com/thi-ng/umbrella/blob/develop/packages/vectors/src/compile/accessors.ts#L2 Or it is just the missing assignment in constructor of Vec2. Used yarn patch to solve it, by adding the following lines

@@ -62,6 +62,8 @@ class Vec2 extends AVec {
   y;
   constructor(buf, offset = 0, stride = 1) {
     super(buf || [0, 0], offset, stride);
+    this.x = buf ? buf[0] : 0
+    this.y = buf ? buf[1] : 0
   }
   [Symbol.iterator]() {
     return stridedValues(this.buf, 2, this.offset, this.stride);
@@ -69,6 +71,18 @@ class Vec2 extends AVec {
   get length() {
     return 2;
   }
+  get x() {
+    return this.buf[this.offset]
+  }
+  get y() {
+    return this.buf[this.offset + 1 * this.stride]
+  }
+  set x(value) {
+    this.buf[this.offset] = value
+  }
+  set y(value) {
+    this.buf[this.offset + 1 * this.stride] = value
+  }

Is this reproducable?

postspectacular commented 7 months ago

Hi @dennemark - THANK you for spotting this. The issue is that this declareIndices() approach does not work anymore with the new class syntax & semantics of ES2022 (which I switched all packages to recently). I will push a new release in the next few mins...

dennemark commented 7 months ago

Thanks so much! Super fast :D I was already wondering if maybe vite cache was messed up... Going to try out later :)

postspectacular commented 7 months ago

Customer sevice! :) It's uploading now, but maybe give it another 5 mins... it will be v7.8.10!