/// <summary> /// Expands the AABB for this grid when a new tile is added. If the tile is already inside the existing AABB, /// nothing happens. If it is outside, the AABB is expanded to fit the new tile. /// </summary> /// <param name="gridTile">The new tile to check.</param> public void UpdateAABB(Indices gridTile) { var worldPos = GridTileToLocal(gridTile).ToWorld(); if (AABBWorld.Contains(worldPos.Position)) { return; } // rect union var a = AABBWorld; var b = worldPos; var x = Math.Min(a.Left, b.X); var width = Math.Max(a.Left + a.Width, b.X); var y = Math.Min(a.Top, b.Y); var height = Math.Max(a.Top + a.Height, b.Y); AABBWorld = new Box2(x, y, width - x, height - y); }
/// <summary> /// Expands the AABB for this grid when a new tile is added. If the tile is already inside the existing AABB, /// nothing happens. If it is outside, the AABB is expanded to fit the new tile. /// </summary> /// <param name="gridTile">The new tile to check.</param> public void UpdateAABB(MapIndices gridTile) { var worldPos = GridTileToLocal(gridTile).ToWorld(); if (AABBWorld.Contains(worldPos.Position)) { return; } // rect union var a = AABBWorld; var b = worldPos; var min_x = Math.Min(a.Left, b.X); var max_x = Math.Max(a.Right, b.X); var min_y = Math.Min(a.Bottom, b.Y); var max_y = Math.Max(a.Top, b.Y); AABBWorld = Box2.FromDimensions(min_x, min_y, max_x - min_x, max_y - min_y); }