Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Lift Cell.Set to a namespace-level class
- Loading branch information
Showing
4 changed files
with
60 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
|
||
namespace Kethane.GeodesicGrid | ||
{ | ||
public class Set : IEnumerable<Cell> | ||
{ | ||
private readonly BitArray set; | ||
|
||
public Set(int level) | ||
{ | ||
this.set = new BitArray((int)Cell.CountAtLevel(level)); | ||
} | ||
|
||
public Set(int level, byte[] array) | ||
{ | ||
this.set = new BitArray(array); | ||
this.set.Length = (int)Cell.CountAtLevel(level); | ||
} | ||
|
||
public bool this[Cell cell] | ||
{ | ||
get | ||
{ | ||
if (cell.Index >= set.Count) { throw new ArgumentException(); } | ||
return set[(int)cell.Index]; | ||
} | ||
set | ||
{ | ||
if (cell.Index >= set.Count) { throw new ArgumentException(); } | ||
set[(int)cell.Index] = value; | ||
} | ||
} | ||
|
||
public IEnumerator<Cell> GetEnumerator() | ||
{ | ||
for (var i = 0; i < set.Count; i++) | ||
{ | ||
if (set[i]) | ||
{ | ||
yield return new Cell((uint)i); | ||
} | ||
} | ||
} | ||
|
||
IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } | ||
|
||
public byte[] ToByteArray() | ||
{ | ||
return set.ToByteArray(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters