botw-toolset/IO/TSCB/GridConverter.cs
Chev a1a83285f8 Migrate from .NET Framework 4.8 to .NET 5
Also compress Resources/Icons image files, and remove unused entry in App.xaml
2021-01-18 23:33:46 -08:00

28 lines
802 B
C#

namespace BOTWToolset.IO.TSCB
{
/// <summary>
/// Manages the TSCB tab's pixel map.
/// </summary>
static class GridConverter
{
/// <summary>
/// Converts a Z-Curve position to (X, Y) coordinates.
/// </summary>
/// <param name="index">Z-Curve index</param>
/// <returns>int array with X and Y coordinates.</returns>
public static int[] ZCurveToXY(int index)
{
int x = 0;
int y = 0;
// Shift bits to the right to get untangled X and Y bytes
for (int i = 0; i < 16; i++)
{
x = ((index & (1 << (i * 2))) >> i) | x;
y = ((index & (2 << (i * 2))) >> i + 1) | y;
}
return new int[] { x, y };
}
}
}