mirror of
https://github.com/exogen/t2-mapper.git
synced 2026-01-19 12:14:47 +00:00
49 lines
850 B
TypeScript
49 lines
850 B
TypeScript
export function rotateHeightMap(
|
|
src: Uint16Array,
|
|
width: number,
|
|
height: number,
|
|
degrees: 90 | 180 | 270
|
|
) {
|
|
let outW: number;
|
|
let outH: number;
|
|
|
|
switch (degrees) {
|
|
case 90:
|
|
case 270:
|
|
outW = height;
|
|
outH = width;
|
|
break;
|
|
case 180:
|
|
outW = width;
|
|
outH = height;
|
|
break;
|
|
}
|
|
|
|
const out = new Uint16Array(outW * outH);
|
|
|
|
for (let y = 0; y < height; y++) {
|
|
for (let x = 0; x < width; x++) {
|
|
const val = src[y * width + x];
|
|
|
|
let nx, ny;
|
|
switch (degrees) {
|
|
case 90:
|
|
nx = height - 1 - y;
|
|
ny = x;
|
|
break;
|
|
case 180:
|
|
nx = width - 1 - x;
|
|
ny = height - 1 - y;
|
|
break;
|
|
case 270:
|
|
nx = y;
|
|
ny = width - 1 - x;
|
|
}
|
|
|
|
out[ny * outW + nx] = val;
|
|
}
|
|
}
|
|
|
|
return out;
|
|
}
|