1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2026-03-02 03:39:21 +00:00

Refactor rotation overview matrices

This commit is contained in:
tobspr
2020-08-11 18:50:43 +02:00
parent 850461df8f
commit a32c0530bb
3 changed files with 58 additions and 34 deletions

View File

@@ -632,3 +632,54 @@ export function formatItemsPerSecond(speed, double = false, separator = T.global
round2Digits(speed).toString().replace(".", separator)
) + (double ? " " + T.ingame.buildingPlacement.infoTexts.itemsPerSecondDouble : "");
}
/**
* Rotates a flat 3x3 matrix clockwise
* Entries:
* 0 lo
* 1 mo
* 2 ro
* 3 lm
* 4 mm
* 5 rm
* 6 lu
* 7 mu
* 8 ru
* @param {Array<number>} flatMatrix
*/
export function rotateFlatMatrix3x3(flatMatrix) {
return [
flatMatrix[6],
flatMatrix[3],
flatMatrix[0],
flatMatrix[7],
flatMatrix[4],
flatMatrix[1],
flatMatrix[8],
flatMatrix[5],
flatMatrix[2],
];
}
/**
* Generates rotated variants of the matrix
* @param {Array<number>} originalMatrix
* @returns {Object<number, Array<number>>}
*/
export function generateMatrixRotations(originalMatrix) {
const result = {
0: originalMatrix,
};
originalMatrix = rotateFlatMatrix3x3(originalMatrix);
result[90] = originalMatrix;
originalMatrix = rotateFlatMatrix3x3(originalMatrix);
result[180] = originalMatrix;
originalMatrix = rotateFlatMatrix3x3(originalMatrix);
result[270] = originalMatrix;
return result;
}