private uint GetWidthInTilesLog2(uint widthInTiles) { //if (!IsPowerOf2(widthInTiles)) { if (widthInTiles != 0 && !BitTwiddle.IsPowerOf2(widthInTiles)) { throw new System.Exception("Map width in tiles must be a power of 2"); } return(BitTwiddle.Log2OfPowerOf2(widthInTiles)); }
public void IsPowerOf2() { Assert.IsTrue(BitTwiddle.IsPowerOf2(1)); Assert.IsTrue(BitTwiddle.IsPowerOf2(2)); Assert.IsTrue(BitTwiddle.IsPowerOf2(4)); Assert.IsTrue(BitTwiddle.IsPowerOf2(8)); Assert.IsTrue(BitTwiddle.IsPowerOf2(16)); Assert.IsTrue(BitTwiddle.IsPowerOf2(32)); Assert.IsTrue(BitTwiddle.IsPowerOf2(64)); Assert.IsTrue(BitTwiddle.IsPowerOf2(128)); Assert.IsTrue(BitTwiddle.IsPowerOf2(256)); Assert.IsTrue(BitTwiddle.IsPowerOf2(512)); Assert.IsTrue(BitTwiddle.IsPowerOf2(1u << 31)); Assert.IsFalse(BitTwiddle.IsPowerOf2(0)); Assert.IsFalse(BitTwiddle.IsPowerOf2(3)); Assert.IsFalse(BitTwiddle.IsPowerOf2(5)); Assert.IsFalse(BitTwiddle.IsPowerOf2(6)); Assert.IsFalse(BitTwiddle.IsPowerOf2(7)); }