PAIR-code / megaplot

Apache License 2.0
19 stars 5 forks source link

Convenience setters for Scene.scale and Scene.offset #86

Open RyanMullins opened 1 year ago

RyanMullins commented 1 year ago

The SpriteView implementation provides convenient setters for the PositionWorld etc. properties as:

set PositionWorld(value: (number[] | {x?: number; y?: number;})) { /* ...some logic... */ }

I would like the same convenience setters for Scene.scale and Scene.offset as follows.

set scale(value: (number | number[] | {x?: number; y?: number;})) {
  if (typeof value === 'number') {
    this.scale.x = this.scale.y = value;
  } else if (Array.isArray(value)) {
    // setter logic similar to SpriteView
  } else if (typeof value === 'object') {
    // setter logic similar to SpriteView
  } else {
    throw new TypeError('Argument must be a number, number array, or object.');
  }
}

It seems like this isn't happening now because Scene.scale and Scene.offset are instances of DrawTriggerPoint, but it shouldn't be hard to move these to an internal private variable and convert the public interfaces to getters and setters. What might be more difficult to overcome is the philosophical desire to always be setting the x and y components of a DrawTriggerPoint directly.