Class MultiArea
A class implementing the IReadOnlyMultiArea interface, that derives its area from multiple "sub-areas".
Implements
Inherited Members
Namespace: GoRogue.MapGeneration
Assembly: GoRogue.dll
Syntax
public class MultiArea : IReadOnlyMultiArea, IReadOnlyArea, IMatchable<IReadOnlyArea>, IEnumerable<Point>, IEnumerable
Constructors
View SourceMultiArea()
Creates an area with no points/subareas.
Declaration
public MultiArea()
MultiArea(IReadOnlyArea)
Creates a MultiArea that has only the given sub-area.
Declaration
public MultiArea(IReadOnlyArea area)
Parameters
Type | Name | Description |
---|---|---|
IReadOnlyArea | area | Sub-area to add. |
MultiArea(IEnumerable<IReadOnlyArea>)
Creates a multi-area that is comprised of the given sub-areas.
Declaration
public MultiArea(IEnumerable<IReadOnlyArea> areas)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<IReadOnlyArea> | areas | Sub-areas to add. |
Properties
View SourceBounds
Smallest possible rectangle that encompasses every position in every sub-area.
Declaration
public Rectangle Bounds { get; }
Property Value
Type | Description |
---|---|
Rectangle |
Count
Number of positions in all of this area's sub-areas combined.
Declaration
public int Count { get; }
Property Value
Type | Description |
---|---|
int |
this[int]
Returns positions from the area (via its sub-areas) in the same fashion you would via a list.
Declaration
public Point this[int index] { get; }
Parameters
Type | Name | Description |
---|---|---|
int | index | Index of position to retrieve. |
Property Value
Type | Description |
---|---|
Point |
Remarks
The indexing scheme considers index 0 to be index 0 in the first sub-area in SubAreas. The indices proceed in increasing order across all points in that sub-area, then roll over into the next one. Eg. index [SubAreas[0].Count] is actually index 0 in the second sub-area, ie. SubAreas[1][0].
SubAreas
List of all sub-areas in the MultiArea.
Declaration
public IReadOnlyList<IReadOnlyArea> SubAreas { get; }
Property Value
Type | Description |
---|---|
IReadOnlyList<IReadOnlyArea> |
UseIndexEnumeration
Whether or not it is more efficient for this implementation to use enumeration by index, rather than generic IEnumerable, when iterating over positions using ReadOnlyAreaPositionsEnumerator.
Declaration
public bool UseIndexEnumeration { get; }
Property Value
Type | Description |
---|---|
bool |
Remarks
Set this to true if your indexer implementation scales well (constant time), and is relatively fast. Implementations with more complex indexers should set this to false.
The default interface implementation returns false, in order to preserve backwards compatibility with previous versions.
If you set this to false, your IEnumerable.GetEnumerator() implementations must NOT call return a ReadOnlyAreaPositionsEnumerator, as this will create an infinite loop.
Methods
View SourceAdd(IReadOnlyArea)
Adds the given sub-area to the MultiArea.
Declaration
public void Add(IReadOnlyArea subArea)
Parameters
Type | Name | Description |
---|---|---|
IReadOnlyArea | subArea | The sub-area to add. |
AddRange(IEnumerable<IReadOnlyArea>)
Adds the given sub-areas to the MultiArea.
Declaration
public void AddRange(IEnumerable<IReadOnlyArea> subAreas)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<IReadOnlyArea> | subAreas | The sub-areas to add. |
Clear()
Clears all sub-areas from the MultiArea.
Declaration
public void Clear()
Contains(IReadOnlyArea)
Returns whether or not the given area is completely contained within the summation of this area's subareas.
Declaration
public bool Contains(IReadOnlyArea area)
Parameters
Type | Name | Description |
---|---|---|
IReadOnlyArea | area | Area to check. |
Returns
Type | Description |
---|---|
bool | True if the all of the given area's points are contained within one or more subareas, false otherwise. |
Contains(Point)
Determines whether or not the given position is considered within one of this area's subareas or not.
Declaration
public bool Contains(Point position)
Parameters
Type | Name | Description |
---|---|---|
Point | position | The position to check. |
Returns
Type | Description |
---|---|
bool | True if the specified position is within one of the subareas, false otherwise. |
Contains(int, int)
Determines whether or not the given position is considered within one of this area's subareas or not.
Declaration
public bool Contains(int positionX, int positionY)
Parameters
Type | Name | Description |
---|---|---|
int | positionX | X-value of the position to check. |
int | positionY | X-value of the position to check. |
Returns
Type | Description |
---|---|
bool | True if the specified position is within one of the subareas, false otherwise. |
GetEnumerator()
Returns an enumerator that iterates through all positions in all sub-areas.
Declaration
public IEnumerator<Point> GetEnumerator()
Returns
Type | Description |
---|---|
IEnumerator<Point> | An enumerator that iterates through all positions in all sub-areas. |
Intersects(IReadOnlyArea)
Returns whether or not the given map area intersects any of this area's subareas. If you intend to determine/use the exact intersection based on this return value, it is best to instead call GetIntersection(IReadOnlyArea, IReadOnlyArea, IEqualityComparer<Point>), and check the number of positions in the result (0 if no intersection).
Declaration
public bool Intersects(IReadOnlyArea area)
Parameters
Type | Name | Description |
---|---|---|
IReadOnlyArea | area | The area to check. |
Returns
Type | Description |
---|---|
bool | True if the given area intersects one of the current one's subareas, false otherwise. |
Matches(IReadOnlyArea?)
Compares for equality. Returns true if the two areas contain exactly the same points.
Declaration
public bool Matches(IReadOnlyArea? other)
Parameters
Type | Name | Description |
---|---|---|
IReadOnlyArea | other |
Returns
Type | Description |
---|---|
bool | True if the areas contain exactly the same points, false otherwise. |
Remove(IReadOnlyArea)
Removes the given sub-area from the MultiArea.
Declaration
public void Remove(IReadOnlyArea subArea)
Parameters
Type | Name | Description |
---|---|---|
IReadOnlyArea | subArea | The sub-area to remove. |