Class MapAreaFinder
Class designed to calculate and produce a list of Areas representing each unique connected area of the map.
Inherited Members
Namespace: GoRogue.MapGeneration
Assembly: GoRogue.dll
Syntax
public class MapAreaFinder
Remarks
The class takes in an IGridView<T>, where a value of true for a given position indicates it should be part of a map area, and false indicates it should not be part of any map area. In a classic roguelike dungeon example, this might be a view of "walkability" where floors return a value of true and walls return a value of false.
Constructors
View SourceMapAreaFinder(IGridView<bool>, AdjacencyRule, IEqualityComparer<Point>?)
Constructor.
Declaration
public MapAreaFinder(IGridView<bool> areasView, AdjacencyRule adjacencyMethod, IEqualityComparer<Point>? pointHasher = null)
Parameters
Type | Name | Description |
---|---|---|
IGridView<bool> | areasView | Grid view indicating which cells should be considered part of a map area and which should not. |
AdjacencyRule | adjacencyMethod | The method used for determining connectivity of the grid. |
IEqualityComparer<Point> | pointHasher | Point hashing algorithm to use for the areas created. If set to null the default point hashing algorithm will be used. |
Fields
View SourceAreasView
Grid view indicating which cells should be considered part of a map area and which should not.
Declaration
public IGridView<bool> AreasView
Field Value
Type | Description |
---|---|
IGridView<bool> |
PointHasher
Point hashing algorithm to use for the areas created. If set to null, the default point hashing algorithm will be used.
Declaration
public IEqualityComparer<Point>? PointHasher
Field Value
Type | Description |
---|---|
IEqualityComparer<Point> |
Properties
View SourceAdjacencyMethod
The method used for determining connectivity of the grid.
Declaration
public AdjacencyRule AdjacencyMethod { get; set; }
Property Value
Type | Description |
---|---|
AdjacencyRule |
Methods
View SourceFillFrom(IGridView<bool>, AdjacencyRule, Point, IEqualityComparer<Point>?)
Convenience function that creates a MapAreaFinder and returns the result of that instance's FillFrom(Point, bool) function. Intended to be used for cases in which the area finder will never be re-used.
Declaration
public static Area? FillFrom(IGridView<bool> map, AdjacencyRule adjacencyMethod, Point position, IEqualityComparer<Point>? pointHasher = null)
Parameters
Type | Name | Description |
---|---|---|
IGridView<bool> | map | Grid view indicating which cells should be considered part of a map area and which should not. |
AdjacencyRule | adjacencyMethod | The method used for determining connectivity of the grid. |
Point | position | The position to start from. |
IEqualityComparer<Point> | pointHasher | Point hashing algorithm to use for the areas created. If set to null the default point hashing algorithm will be used. |
Returns
Type | Description |
---|---|
Area | An IEnumerable of each (unique) map area. |
FillFrom(Point, bool)
Calculates and returns an area representing every point connected to the start point given.
Declaration
public Area? FillFrom(Point position, bool clearVisited = true)
Parameters
Type | Name | Description |
---|---|---|
Point | position | Position to start from. |
bool | clearVisited | Whether or not to reset all cells to unvisited before finding areas. Visited positions cannot be included in the resulting area. |
Returns
Type | Description |
---|---|
Area | An area representing every point connected to the start point given, or null if there is no valid area starting from that point. |
MapAreas(bool)
Calculates the list of map areas, returning each unique map area.
Declaration
public IEnumerable<Area> MapAreas(bool clearVisited = true)
Parameters
Type | Name | Description |
---|---|---|
bool | clearVisited | Whether or not to reset all cells to unvisited before finding areas. Visited positions cannot be included in any of the resulting areas. |
Returns
Type | Description |
---|---|
IEnumerable<Area> | An IEnumerable of each (unique) map area. |
MapAreasFor(IGridView<bool>, AdjacencyRule, IEqualityComparer<Point>?)
Convenience function that creates a MapAreaFinder and returns the result of that instances MapAreas(bool) function. Intended to be used for cases in which the area finder will never be re-used.
Declaration
public static IEnumerable<Area> MapAreasFor(IGridView<bool> map, AdjacencyRule adjacencyMethod, IEqualityComparer<Point>? pointHasher = null)
Parameters
Type | Name | Description |
---|---|---|
IGridView<bool> | map | Grid view indicating which cells should be considered part of a map area and which should not. |
AdjacencyRule | adjacencyMethod | The method used for determining connectivity of the grid. |
IEqualityComparer<Point> | pointHasher | Point hashing algorithm to use for the areas created. If set to null the default point hashing algorithm will be used. |
Returns
Type | Description |
---|---|
IEnumerable<Area> | An IEnumerable of each (unique) map area. |
ResetVisitedPositions()
Resets all positions to "unvisited". Called automatically if area-finding algorithms have the reset flag set to true.
Declaration
public void ResetVisitedPositions()