AStartTest.TileSystem.TileMap.GetTileFromPos C# (CSharp) Method

GetTileFromPos() public static method

Returns a tile given a Vector3 position
public static GetTileFromPos ( System.Vector3 position ) : Tile
position System.Vector3 The position to investigate
return Tile
        public static Tile GetTileFromPos(Vector3 position)
        {
            int xNum, yNum, index;
            xNum = yNum = index = 0;

            //xNum = (int)((upperLeftPos.X - position.X) / (int)tileSize.X);
            //yNum = (int)(((upperLeftPos.Z - position.Z) / (int)tileSize.Y) * numTiles.X);

            xNum = (int)Math.Round((upperLeftPos.X - position.X) / (int)tileSize.X);
            yNum = (int)(Math.Round((upperLeftPos.Z - position.Z) / (int)tileSize.Y) * numTiles.X);

            index = Math.Abs(xNum) + Math.Abs(yNum);

            if (index >= 0 && index < numTiles.X * numTiles.Y)
                return tiles[index];

            return new Tile();
        }

Usage Example

 public void GetTileFromPosTest()
 {
     Vector2 position = null; // TODO: Initialize to an appropriate value
     Vector2 numTiles = null; // TODO: Initialize to an appropriate value
     Vector2 tileSize = null; // TODO: Initialize to an appropriate value
     IList<Panel> panels = null; // TODO: Initialize to an appropriate value
     TileMap target = new TileMap(position, numTiles, tileSize, panels); // TODO: Initialize to an appropriate value
     Vector2 position1 = null; // TODO: Initialize to an appropriate value
     Tile expected = null; // TODO: Initialize to an appropriate value
     Tile actual;
     actual = target.GetTileFromPos(position1);
     Assert.AreEqual(expected, actual);
     Assert.Inconclusive("Verify the correctness of this test method.");
 }