Show / Hide Table of Contents

Interface IReadOnlySpatialMap<T>

Implements the read-only interface of ISpatialMap<T>.

Inherited Members
IEnumerable<ItemPositionPair<T>>.GetEnumerator()
Namespace: SadRogue.Primitives.SpatialMaps
Assembly: TheSadRogue.Primitives.dll
Syntax
public interface IReadOnlySpatialMap<T> : IEnumerable<ItemPositionPair<T>>, IEnumerable where T : notnull
Type Parameters
Name Description
T
Remarks

Simply exposes only those functions of ISpatialMap<T> that do not allow direct modification of the data (eg. adding/moving/removing items). This can allow for direct exposure of an ISpatialMap as a property of type IReadOnlySpatialMap, without allowing such an exposure to break data encapsulation principles of something like a game map.

Properties

View Source

Count

The number of items in the spatial map.

Declaration
int Count { get; }
Property Value
Type Description
int
View Source

Items

Enumerable of the items stored in the spatial map: for use to iterate over all items with a foreach loop.

Declaration
IEnumerable<T> Items { get; }
Property Value
Type Description
IEnumerable<T>
View Source

Positions

Enumerable of all positions that contain items.

Declaration
IEnumerable<Point> Positions { get; }
Property Value
Type Description
IEnumerable<Point>

Methods

View Source

AsReadOnly()

Returns a read-only reference to the spatial map. Convenient for "safely" exposing the spatial as a property, without allowing direct modification.

Declaration
IReadOnlySpatialMap<T> AsReadOnly()
Returns
Type Description
IReadOnlySpatialMap<T>

The current spatial map, as a "read-only" reference.

View Source

CanAdd(T, Point)

Returns true if the given item can be added at the given position; false otherwise.

Declaration
bool CanAdd(T newItem, Point position)
Parameters
Type Name Description
T newItem

Item to add.

Point position

Position to add item to.

Returns
Type Description
bool

True if the item can be successfully added at the position given; false otherwise.

View Source

CanAdd(T, int, int)

Returns true if the given item can be added at the given position; false otherwise.

Declaration
bool CanAdd(T newItem, int x, int y)
Parameters
Type Name Description
T newItem

Item to add.

int x

X-value of the position to add item to.

int y

Y-value of the position to add item to.

Returns
Type Description
bool

True if the item can be successfully added at the position given; false otherwise.

View Source

CanMove(T, Point)

Returns true if the given item can be moved from its current location to the specified one; false otherwise.

Declaration
bool CanMove(T item, Point target)
Parameters
Type Name Description
T item

Item to move.

Point target

Location to move item to.

Returns
Type Description
bool

true if the given item can be moved to the given position; false otherwise.

View Source

CanMove(T, int, int)

Returns true if the given item can be moved from its current location to the specified one; false otherwise.

Declaration
bool CanMove(T item, int targetX, int targetY)
Parameters
Type Name Description
T item

Item to move.

int targetX

X-value of the location to move item to.

int targetY

Y-value of the location to move item to.

Returns
Type Description
bool

true if the given item can be moved to the given position; false otherwise.

View Source

CanMoveAll(Point, Point)

Returns true if there are items at current and all items at that position can be moved to target; false otherwise.

Declaration
bool CanMoveAll(Point current, Point target)
Parameters
Type Name Description
Point current

Location to move items from.

Point target

Location to move items to.

Returns
Type Description
bool

true if all items at the position current can be moved to the position target; false if one or more items cannot be moved or there are no items to move.

View Source

CanMoveAll(int, int, int, int)

Returns true if there are items at the current position specified, and all items at that position can be moved to the target position; false otherwise.

Declaration
bool CanMoveAll(int currentX, int currentY, int targetX, int targetY)
Parameters
Type Name Description
int currentX

X-value of the location to move items from.

int currentY

Y-value of the location to move items from.

int targetX

X-value of the location to move items to.

int targetY

Y-value of the location to move items to.

Returns
Type Description
bool

true if all items at the position current can be moved to the position target; false if one or more items cannot be moved or there are no items to move.

View Source

Contains(Point)

Returns if there is an item in the spatial map at the given position or not.

Declaration
bool Contains(Point position)
Parameters
Type Name Description
Point position

The position to check for.

Returns
Type Description
bool

True if there is some item at the given position, false if not.

View Source

Contains(int, int)

Returns if there is an item in the spatial map at the given position or not.

Declaration
bool Contains(int x, int y)
Parameters
Type Name Description
int x

The x-value of the position to check for.

int y

The y-value of the position to check for.

Returns
Type Description
bool

True if there is some item at the given position, false if not.

View Source

Contains(T)

Returns whether or not the spatial map contains the given item.

Declaration
bool Contains(T item)
Parameters
Type Name Description
T item

The item to check for.

Returns
Type Description
bool

True if the given item is contained in the spatial map, false if not.

View Source

GetItemsAt(Point)

Gets the item(s) at the given position if there are any items, or returns nothing if there is nothing at that position.

Declaration
IEnumerable<T> GetItemsAt(Point position)
Parameters
Type Name Description
Point position

The position to return the item(s) for.

Returns
Type Description
IEnumerable<T>

The item(s) at the given position if there are any items, or nothing if there is nothing at that position.

View Source

GetItemsAt(int, int)

Gets the item(s) at the given position if there are any items, or returns nothing if there is nothing at that position.

Declaration
IEnumerable<T> GetItemsAt(int x, int y)
Parameters
Type Name Description
int x

The x-value of the position to return the item(s) for.

int y

The y-value of the position to return the item(s) for.

Returns
Type Description
IEnumerable<T>

The item(s) at the given position if there are any items, or nothing if there is nothing at that position.

View Source

GetPositionOf(T)

Gets the position associated with the given item in the spatial map. If the item does not exist in the spatial map, throws ArgumentException.

Declaration
Point GetPositionOf(T item)
Parameters
Type Name Description
T item

The item to get the position for.

Returns
Type Description
Point

The position associated with the given item.

View Source

GetPositionOfOrNull(T)

Gets the position associated with the given item in the spatial map, or null if that item is not found.

Declaration
Point? GetPositionOfOrNull(T item)
Parameters
Type Name Description
T item

The item to get the position for.

Returns
Type Description
Point?

The position associated with the given item, if it exists in the spatial map, or null if the item does not exist.

View Source

ToString(Func<T, string>)

Returns a string representation of the IReadOnlySpatialMap, allowing display of the spatial map's items in a specified way.

Declaration
string ToString(Func<T, string> itemStringifier)
Parameters
Type Name Description
Func<T, string> itemStringifier

Function that turns an item into a string.

Returns
Type Description
string

A string representation of the spatial map.

View Source

TryGetPositionOf(T, out Point)

Attempts to get the position of the given item in the spatial map. If successful, the function will return true and the position will be stored in the position parameter. If the item was not found, position will have the default value for Point, and the function will return false.

Declaration
bool TryGetPositionOf(T item, out Point position)
Parameters
Type Name Description
T item

Item to retrieve the position of.

Point position

The position of the item if found, or default(Point) if not.

Returns
Type Description
bool

True if the item was found in the spatial map, false otherwise.

Events

View Source

ItemAdded

Event that is fired directly after an item has been added to the spatial map.

Declaration
event EventHandler<ItemEventArgs<T>> ItemAdded
Event Type
Type Description
EventHandler<ItemEventArgs<T>>
View Source

ItemMoved

Event that is fired directly after an item in the spatial map has been moved.

Declaration
event EventHandler<ItemMovedEventArgs<T>> ItemMoved
Event Type
Type Description
EventHandler<ItemMovedEventArgs<T>>
View Source

ItemRemoved

Event that is fired directly after an item has been removed from the spatial map.

Declaration
event EventHandler<ItemEventArgs<T>> ItemRemoved
Event Type
Type Description
EventHandler<ItemEventArgs<T>>

Extension Methods

PropertyChangedEventHelpers.SafelySetProperty<TObject, TProperty>(TObject, ref TProperty, TProperty, EventHandler<ValueChangedEventArgs<TProperty>>?)
PropertyChangedEventHelpers.SafelySetProperty<TObject, TProperty>(TObject, ref TProperty, TProperty, EventHandler<ValueChangedEventArgs<TProperty>>?, EventHandler<ValueChangedEventArgs<TProperty>>?)
ToStringExtensions.ExtendToString<T>(IEnumerable<T>, string, Func<T, string>?, string, string)
  • View Source
In this article
Back to top Generated by DocFX