// Copyright (c) 2014 Robert Rouhani and other contributors (see CONTRIBUTORS file). // Licensed under the MIT License - https://raw.github.com/Robmaister/SharpNav/master/LICENSE using System; namespace SharpNav { /// /// An enum similar to , but with the ability to store multiple directions. /// [Flags] public enum EdgeFlags : byte { /// No edges are selected. None = 0x0, /// The west edge is selected. West = 0x1, /// The north edge is selected. North = 0x2, /// The east edge is selected. East = 0x4, /// The south edge is selected. South = 0x8, /// All of the edges are selected. All = West | North | East | South } /// /// A static class with helper functions to modify instances of the enum. /// public static class EdgeFlagsHelper { /// /// Adds an edge in a specified direction to an instance of . /// /// An existing set of edges. /// The direction to add. public static void AddEdge(ref EdgeFlags edges, Direction dir) { edges |= (EdgeFlags)(1 << (int)dir); } /// /// Flips the set of edges in an instance of . /// /// An existing set of edges. public static void FlipEdges(ref EdgeFlags edges) { edges ^= EdgeFlags.All; } /// /// Determines whether an instance of includes an edge in a specified direction. /// /// A set of edges. /// The direction to check for an edge. /// A value indicating whether the set of edges contains an edge in the specified direction. public static bool IsConnected(ref EdgeFlags edges, Direction dir) { return (edges & (EdgeFlags)(1 << (int)dir)) != EdgeFlags.None; } /// /// Removes an edge from an instance of . /// /// A set of edges. /// The direction to remove. public static void RemoveEdge(ref EdgeFlags edges, Direction dir) { edges &= (EdgeFlags)(~(1 << (int)dir)); } } }