williamngan / pts

A library for visualization and creative-coding
https://ptsjs.org
Apache License 2.0
5.16k stars 182 forks source link

Bound's bottom right pt isn't updated after calling e.g. `add` #213

Closed suguruwataru closed 3 months ago

suguruwataru commented 4 months ago
const p = Bound.fromGroup(Group.fromArray(
  [
    [0, 0], [1, 1]
  ]
)).add(1).bottomRight

One would expect p to be Pt(2, 2), but it's actually Pt(1, 1).

I suspect that this is because unlike the top left point, the bottom right point is not initialized using the setter, but uses an direct assignment to the member variable, so it's not one of the points that are indexable using numbers (setters make the points indexable from 0 and 1). Methods such as add are inherited from Group, and they rely on integer indexing to get points.

I'm using 0.11.3, but this appears to also exist in master.

https://github.com/williamngan/pts/blob/47de4b76ce6a24892c2c7e2b155c09a18e1d5b7e/src/Pt.ts#L1021-L1022

For anyone else who is facing this issue and don't want to wait for a fix to land, there's an update method on Bound that updates the point.