Files
ft/Client/Assets/Scripts/EventCubeMelt/Utils/MatrixRotation.cs
2026-06-29 21:18:33 +08:00

46 lines
1.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 数组旋转
//
namespace EventCubeMelt.Utils
{
public static class MatrixRotation<T>
{
// 二维数组矩阵顺时针旋转90度
public static T[,] Rotate90Clockwise(T[,] matrix)
{
int rows = matrix.GetLength(0);
int cols = matrix.GetLength(1);
T[,] result = new T[cols, rows]; // 旋转后行列互换
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < cols; j++)
{
result[j, rows - 1 - i] = matrix[i, j];
}
}
return result;
}
// 二维数组逆时针旋转90度
public static T[,] Rotate90CounterClockwise(T[,] matrix)
{
int rows = matrix.GetLength(0);
int cols = matrix.GetLength(1);
T[,] result = new T[cols, rows];
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < cols; j++)
{
result[cols - 1 - j, i] = matrix[i, j];
}
}
return result;
}
}
}