adafruit / Adafruit-GFX-Library

Adafruit GFX graphics core Arduino library, this is the 'core' class that all our other graphics libraries derive from
https://learn.adafruit.com/adafruit-gfx-graphics-library
Other
2.41k stars 1.55k forks source link

Add function to rotate pixel #417

Open MarcelRobitaille opened 1 year ago

MarcelRobitaille commented 1 year ago

This code to rotate a pixel from the virtual, rotated coordinate to physical screen coordinates is repeated many times.

int16_t t;
switch (rotation) {
case 1:
  t = x;
  x = WIDTH - 1 - y;
  y = t;
  break;
case 2:
  x = WIDTH - 1 - x;
  y = HEIGHT - 1 - y;
  break;
case 3:
  t = x;
  x = y;
  y = HEIGHT - 1 - t;
  break;
}

I think there should be a function applyRotation(x, y) that goes from virtual, rotated coordinates to physical screen coordinates. I think there should also be a function that does the inverse. Something like undoRotation(x, y) that goes from physical screen coordinates to virtual, rotated coordinates. This is useful when using touch screens, so you can transform the touch event's coordinates into the virtual coordinates.

Would you accept a pull request generalizing all of the places this code is repeated into a single function and adding the inverse function?