Done auxiliary methods for Direction

This commit is contained in:
Roman Danilov 2024-03-05 21:49:29 +05:00
parent 91ef890bb6
commit df9443381b
3 changed files with 44 additions and 1 deletions

View file

@ -1,4 +1,6 @@
namespace MinecraftClient.Mapping
using System;
namespace MinecraftClient.Mapping
{
public static class DirectionExtensions
{
@ -35,5 +37,27 @@
}
}
public static Direction[] HORIZONTAL =
{
Direction.South,
Direction.West,
Direction.North,
Direction.East
};
public static Direction FromRotation(double rotation)
{
double floor = Math.Floor((rotation / 90.0) + 0.5);
int value = (int)floor & 3;
return FromHorizontal(value);
}
public static Direction FromHorizontal(int value)
{
return HORIZONTAL[Math.Abs(value % HORIZONTAL.Length)];
}
}
}