private Hexside(int value, string name, Hexsides hexsides) { AsHexsides = hexsides; Name = name; Value = value; _reversed = (Value + 3) % 6; }
/// <summary>TODO</summary> public static Hexsides ValidBitsMask(this Hexsides @this) { const Hexsides HexsidesMask = Hexsides.North | Hexsides.Northeast | Hexsides.Southeast | Hexsides.South | Hexsides.Southwest | Hexsides.Northwest; return(@this &= HexsidesMask); }
/// <summary>Tests (without boxing) if all flags are clear.</summary> public static bool IsAnySet(this Hexsides @this, Hexsides testBits) { if (@this == 0) { throw new ArgumentOutOfRangeException("this"); //"Value must not be 0."); } return((@this & testBits) != 0); }
/// <summary>Tests (without boxing) if all flags are clear.</summary> public static bool AreAllClear(this Hexsides @this, Hexsides testBits) { if (@this == 0) { throw new ArgumentOutOfRangeException("this"); //,"Value must not be 0."); } return((@this & testBits) == 0); }
/// <summary>Performs action for all bits set in this.</summary> public static void ForEach(this Hexsides @this, Action <Hexsides> action) { if (action == null) { throw new ArgumentNullException("action"); } for (UInt32 bit = 1; bit != 0; bit <<= 1) { var flag = (Hexsides)bit; if (@this.IsAnySet(flag)) { action(flag); } } }
/// <summary>Clears the bits clearBits in this.</summary> public static Hexsides ClearBits(this Hexsides @this, Hexsides bits) { return(@this & ~bits); }
/// <summary>Returns the count of of set bit-flags in the argument.</summary> /// <param name="this"></param> public static int BitCount(this Hexsides @this) { return(LookupTable[(int)@this]); }
/// <summary>Returns set of hexes at direction(s) specified by <c>hexsides</c>, as IEnumerable.</summary> public IEnumerable <NeighbourCoords> GetNeighbours(Hexsides hexsides) { return(GetNeighbours().Where(n => hexsides.HasFlag(n.Hexside))); }
/// <summary>Returns the result of clearing all invalid bits in <c>this</c>.</summary> public static Hexsides ValidBitsMask(this Hexsides @this) { return @this &= Hexsides.All; }
/// <summary>Sets specified bits in this.</summary> public static Hexsides SetBits(this Hexsides @this, Hexsides bits) => (@this | bits).ValidBitsMask();
/// <summary>Clears specified bits in this.</summary> public static Hexsides ClearBits(this Hexsides @this, Hexsides bits) => (@this & ~bits).ValidBitsMask();
/// <summary>Tests (without boxing) if any requested bit is set.</summary> public static bool IsAnySet(this Hexsides @this, Hexsides testBits) { if (@this == 0) throw new ArgumentOutOfRangeException("this","Value must not be 0."); return (@this & testBits).ValidBitsMask() != 0; }
/// <summary>TODO</summary> public static int GetValue(this Hexsides @this) { return (int)@this.ValidBitsMask(); }
/// <summary>Returns true exactly if <c>this</c> has the the eponymous bit from <c>hexside</c> set.</summary> /// <param name="this">The Hexsides value to test.</param> /// <param name="hexside">Specification of the eponymous bit in <c>this</c> to test.</param> public static bool IsSet(this Hexsides @this, Hexside hexside) => (@this.GetValue() & ((int)hexside.AsHexsides)) != 0;
/// <summary>The <c>Hexside</c> corresponding to this <c>Hexside</c> bit, or -1 if it doesn't exist.</summary> public static Hexside IndexOf(this Hexsides @this) { return((Hexside)HexsideBits.IndexOf(@this)); }
/// <summary>Sets the bits setBits in this.</summary> public static Hexsides SetBits(this Hexsides @this, Hexsides bits) { return(@this | bits); }
/// <summary>Returns the count of of set bit-flags in the argument.</summary> /// <param name="this">The Hexsides instnace of interest.</param> public static int BitCount(this Hexsides @this) => BitCountLookup[(int)@this];
/// <summary>TODO</summary> public NeighbourHex(IHex hex, Hexsides hexside) : this(hex, hexside.IndexOf()) { }