import { rotatePixels } from '@datamoc/mw_games/two-d/render';
const pixels = new Uint8ClampedArray([255, 0, 0, 255, 0, 255, 0, 255]); // 2x1: red, green
const rotated = rotatePixels(pixels, 2, 1, 90);
console.log(rotated.width, rotated.height); // 1, 2 - the surface expanded to fit
const smooth = rotatePixels(pixels, 2, 1, 60, 'linear'); // the same, with an interpolated edge
The renderer-free core of
~ROTATE: rotates the source pixels themselves bydegrees(clockwise) around their centre and expands the surface to fit the rotated bounds, rather than turning a sprite's own transform -applyImageModifiers'ssprite.rotationleaves the art unrotated and does not grow the surface, which is wrong for terrain and anything else that has to keep tiling after the rotation. A destination pixel with no source under it is fully transparent, and a sample point up to half a pixel outside the source still reads it, so the edge of the rotated art ends where the art does.'nearest'is the default and stays exact at multiples of 90 degrees, which round-trip pixel-for-pixel;'linear'costs four reads and a premultiplied blend per destination pixel and is what keeps a non-square angle readable. Both modes are bake-time work - the rotation happens once, when the texture is built - so the choice is a load-time one, not a frame-time one, and a game can afford'linear'wherever the art is not meant to look pixel-blocky.