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 Log2OfPowerOf2() { Assert.AreEqual(0u, BitTwiddle.Log2OfPowerOf2(1)); Assert.AreEqual(1u, BitTwiddle.Log2OfPowerOf2(2)); Assert.AreEqual(2u, BitTwiddle.Log2OfPowerOf2(4)); Assert.AreEqual(3u, BitTwiddle.Log2OfPowerOf2(8)); Assert.AreEqual(4u, BitTwiddle.Log2OfPowerOf2(16)); Assert.AreEqual(5u, BitTwiddle.Log2OfPowerOf2(32)); Assert.AreEqual(6u, BitTwiddle.Log2OfPowerOf2(64)); Assert.AreEqual(7u, BitTwiddle.Log2OfPowerOf2(128)); Assert.AreEqual(8u, BitTwiddle.Log2OfPowerOf2(256)); Assert.AreEqual(9u, BitTwiddle.Log2OfPowerOf2(512)); Assert.AreEqual(31u, BitTwiddle.Log2OfPowerOf2(1u << 31)); }