2024-03-05 21:49:29 +05:00
|
|
|
|
using System;
|
|
|
|
|
|
|
2026-03-24 00:34:00 +00:00
|
|
|
|
namespace MinecraftClient.Mapping;
|
|
|
|
|
|
|
|
|
|
|
|
public static class DirectionExtensions
|
2024-03-05 20:30:58 +05:00
|
|
|
|
{
|
2026-03-24 00:34:00 +00:00
|
|
|
|
public static Direction GetOpposite(this Direction direction) => direction switch
|
2024-03-05 20:30:58 +05:00
|
|
|
|
{
|
2026-03-24 00:34:00 +00:00
|
|
|
|
Direction.SouthEast => Direction.NorthEast,
|
|
|
|
|
|
Direction.SouthWest => Direction.NorthWest,
|
|
|
|
|
|
Direction.NorthEast => Direction.SouthEast,
|
|
|
|
|
|
Direction.NorthWest => Direction.SouthWest,
|
|
|
|
|
|
Direction.West => Direction.East,
|
|
|
|
|
|
Direction.East => Direction.West,
|
|
|
|
|
|
Direction.North => Direction.South,
|
|
|
|
|
|
Direction.South => Direction.North,
|
|
|
|
|
|
Direction.Down => Direction.Up,
|
|
|
|
|
|
Direction.Up => Direction.Down,
|
|
|
|
|
|
_ => Direction.Up,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
2024-03-05 21:49:29 +05:00
|
|
|
|
|
2026-03-24 00:34:00 +00:00
|
|
|
|
return FromHorizontal(value);
|
|
|
|
|
|
}
|
2024-03-05 21:49:29 +05:00
|
|
|
|
|
2026-03-24 00:34:00 +00:00
|
|
|
|
public static Direction FromHorizontal(int value)
|
|
|
|
|
|
{
|
|
|
|
|
|
return HORIZONTAL[Math.Abs(value % HORIZONTAL.Length)];
|
2024-03-05 20:30:58 +05:00
|
|
|
|
}
|
|
|
|
|
|
}
|