Skip to content

Commit

Permalink
fix: maintainability things
Browse files Browse the repository at this point in the history
  • Loading branch information
SilasPeters committed Apr 22, 2024
1 parent 0ec3098 commit c728115
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions aplib.net-demo/Assets/Scripts/Tiles/Direction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ public static Direction Opposite(this Direction direction)
=> (Direction)(((int)direction + 2) % 4);

/// <summary>
/// Calculates how much degrees to the right the given direction is rotated from the north.
/// Calculates how many degrees clockwise the given direction is rotated from the north.
/// </summary>
/// <param name="direction"></param>
/// <returns>The right handed rotation in degrees, [0..360)</returns>
/// <returns>The clockwise rotation in degrees, [0..360)</returns>
public static int RotationDegrees(this Direction direction) => (int)direction * 90;
}
}
10 changes: 5 additions & 5 deletions aplib.net-demo/Assets/Scripts/WFC/Grid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public void PlaceRoom(int x, int y, Room room)
/// <returns>All neighbouring cells, excluding diagonal neighbours.</returns>
/// <remarks>This does not check if the tiles in the cells are connected.</remarks>
/// <seealso cref="GetConnectedNeighbours"/>
public ICollection<Cell> Get4NeighbouringCells(Cell cell)
public IEnumerable<Cell> Get4NeighbouringCells(Cell cell)
{
ICollection<Cell> neighbours = new Collection<Cell>();
if (cell.X > 0) neighbours.Add(this[cell.X - 1, cell.Y]);
Expand Down Expand Up @@ -162,10 +162,10 @@ public ICollection<Cell> Get8NeighbouringCells(Cell cell)
/// <param name="cell">The cell whose connected tiles are to be determined.</param>
/// <returns>The cells directly connected through their tiles</returns>
/// <remarks>Assumes that the cells are assigned a tile.</remarks>
public ICollection<Cell> GetConnectedNeighbours(Cell cell)
public IEnumerable<Cell> GetConnectedNeighbours(Cell cell)
{
ICollection<Cell> connectedNeighbours = new Collection<Cell>();
ICollection<Cell> neighbours = Get4NeighbouringCells(cell); // Note: no diagonal neighbours
IEnumerable<Cell> neighbours = Get4NeighbouringCells(cell); // Note: no diagonal neighbours
foreach (Cell neighbour in neighbours)
{
if (cell.Tile.CanConnectInDirection(East) && neighbour.X > cell.X && neighbour.Tile.CanConnectInDirection(West)
Expand All @@ -182,7 +182,7 @@ public ICollection<Cell> GetConnectedNeighbours(Cell cell)
/// This method goes through all cells in this grid, to determine all connected components.
/// </summary>
/// <returns>A collection of sets of cells, where the sets of cells represent the connected components.</returns>
public IList<ISet<Cell>> DetermineConnectedComponents()
public IEnumerable<ISet<Cell>> DetermineConnectedComponents()
{
ISet<Cell> unvisitedCells = new HashSet<Cell>(_cells.Where(cell => cell.Tile is not Empty)); // Deep copy
IList<ISet<Cell>> connectedComponents = new List<ISet<Cell>>();
Expand Down Expand Up @@ -211,7 +211,7 @@ public void DetermineSingleConnectedComponent(in ISet<Cell> searchSpace, in ISet
connectedComponent.Add(cell);
searchSpace.Remove(cell);

ICollection<Cell> connectedNeighbours = GetConnectedNeighbours(cell);
IEnumerable<Cell> connectedNeighbours = GetConnectedNeighbours(cell);
foreach (Cell connectedNeighbour in connectedNeighbours)
{
if (!searchSpace.Contains(connectedNeighbour)) continue; // Already visited
Expand Down
2 changes: 1 addition & 1 deletion aplib.net-demo/Assets/Scripts/WFC/GridPlacer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public void PlaceTile(int x, int y, Tile tile)
/// </summary>
private void JoinConnectedComponentsWithTeleporters()
{
IList<ISet<Cell>> connectedComponents = _grid.DetermineConnectedComponents();
IEnumerable<ISet<Cell>> connectedComponents = _grid.DetermineConnectedComponents();

// We draw all the connected components individually
foreach (ISet<Cell> connectedComponent in connectedComponents)
Expand Down

0 comments on commit c728115

Please sign in to comment.