Files

38 lines
1.4 KiB
C#

using System.Collections.Generic;
namespace EscapeRoomEngine.Engine.Runtime.Utilities
{
public enum Orientation
{
North = 0, East = 90, South = 180, West = 270
}
public static class OrientationExtensions
{
public static HashSet<Orientation> EveryOrientation() => new(new[]
{
Orientation.North, Orientation.East, Orientation.South, Orientation.West
});
/// <summary>
/// Return the orientation corresponding to an angle, starting at 0 degrees North and going clockwise around the compass.
/// </summary>
public static Orientation FromAngle(int angle) => (Orientation)angle;
/// <summary>
/// Turn an orientation into its corresponding angle.
/// </summary>
public static float Angle(this Orientation orientation) => (float)orientation;
/// <summary>
/// Turn an orientation into its corresponding angle.
/// </summary>
public static int AngleInt(this Orientation orientation) => (int)orientation;
/// <summary>
/// Rotate an orientation by a specific amount of quarter rotations. Rotating <c>East</c> thrice would return <c>North</c>.
/// </summary>
public static Orientation Rotated(this Orientation orientation, int quarterRotations) =>
orientation + quarterRotations * 90;
}
}