public HexTile TileAtPoint(Vector2 point) { // Return null if the point is not within the grid at all if (!m_GridArea.Contains(point)) { return(null); } point -= TopLeft; int x = (int)(point.X / TileWidth); int y = (int)(point.Y / (TileHeight * 0.75f)); if (x >= ArrayWidth || y >= ArrayHeight) { return(null); } return(TileArray[x, y]); }
/// <summary> /// Works. /// </summary> /// <param name="point"></param> /// <returns>The node with the highest depth that contains the point or null if the point is outside the QuadTree.</returns> public QuadTreeNode <T> GetSmallestNode(ref Vector2 point) { if (AABB.Contains(point)) // Check if this node contains the point at all { if (!IsLeaf) // If it is divided then check if there is a sub { QuadTreeNode <T> result = null; result = TopLeft.GetSmallestNode(ref point); if (result == null) { result = TopRight.GetSmallestNode(ref point); if (result == null) { result = BottomRight.GetSmallestNode(ref point); if (result == null) { result = BottomLeft.GetSmallestNode(ref point); if (result == null) { throw new Exception("Is not possible. If the node has the point then at least one of the 4 childnodes MUST have the point too."); } } } } return(result); } else { return(this); } } else { return(null); } }
public bool Collide(FRect rectangle) { return(Overlaps(rectangle) || rectangle.Contains(Center)); }