Interface IReadOnlyArea
Read-only interface for an arbitrary 2D area.
Inherited Members
Namespace: SadRogue.Primitives
Assembly: TheSadRogue.Primitives.dll
Syntax
public interface IReadOnlyArea : IMatchable<IReadOnlyArea>, IEnumerable<Point>, IEnumerable
Properties
Bounds
Smallest possible rectangle that encompasses every position in the area.
Declaration
Rectangle Bounds { get; }
Property Value
Type | Description |
---|---|
Rectangle |
Count
Number of (unique) positions in the current area.
Declaration
int Count { get; }
Property Value
Type | Description |
---|---|
Int32 |
Item[Int32]
Returns positions from the area in the same fashion you would via a list.
Declaration
Point this[int index] { get; }
Parameters
Type | Name | Description |
---|---|---|
Int32 | index | Index of list to retrieve. |
Property Value
Type | Description |
---|---|
Point |
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
virtual bool UseIndexEnumeration { get; }
Property Value
Type | Description |
---|---|
Boolean |
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
Contains(IReadOnlyArea)
Returns whether or not the given area is completely contained within the current one.
Declaration
bool Contains(IReadOnlyArea area)
Parameters
Type | Name | Description |
---|---|---|
IReadOnlyArea | area | Area to check. |
Returns
Type | Description |
---|---|
Boolean | True if the given area is completely contained within the current one, false otherwise. |
Contains(Point)
Determines whether or not the given position is considered within the area or not.
Declaration
bool Contains(Point position)
Parameters
Type | Name | Description |
---|---|---|
Point | position | The position to check. |
Returns
Type | Description |
---|---|
Boolean | True if the specified position is within the area, false otherwise. |
Contains(Int32, Int32)
Determines whether or not the given position is considered within the area or not.
Declaration
bool Contains(int positionX, int positionY)
Parameters
Type | Name | Description |
---|---|---|
Int32 | positionX | X-value of the position to check. |
Int32 | positionY | X-value of the position to check. |
Returns
Type | Description |
---|---|
Boolean | True if the specified position is within the area, false otherwise. |
GetEnumerator()
Returns an enumerator which can be used to iterate over the positions in this area in the most efficient manner possible via a generic interface.
Declaration
virtual ReadOnlyAreaPositionsEnumerator GetEnumerator()
Returns
Type | Description |
---|---|
ReadOnlyAreaPositionsEnumerator | A custom enumerator that iterates over the positions in the area in the most efficient manner possible via a generic interface. |
Remarks
The enumerator returned will use the area's indexer to iterate over the positions (like you might a list), if the area's UseIndexEnumeration is true. Otherwise, it uses the typical IEnumerator implementation for that area.
This may be significantly faster than the typical IEnumerable/IEnumerator usage for implementations which have UseIndexEnumeration set to true; however it won't have much benefit otherwise.
If you have a value of a concrete type rather than an interface, and the GetEnumerator implementation for that given type is particularly fast or a non-boxed type (like Area, you will probably get faster performance out of that than by using this; however this will provide better performance if you are working with an interface and thus don't know the type of area. Use cases for this function are generally for iteration via IReadOnlyArea.
Intersects(IReadOnlyArea)
Returns whether or not the given map area intersects the current one. 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
bool Intersects(IReadOnlyArea area)
Parameters
Type | Name | Description |
---|---|---|
IReadOnlyArea | area | The area to check. |
Returns
Type | Description |
---|---|
Boolean | True if the given area intersects the current one, false otherwise. |