Class AdvancedLayeredSpatialMap<T>
A more complex version of LayeredSpatialMap<T> that does not require the items in it to implement IHasID, instead requiring the specification of a custom IEqualityComparer<T> to use for hashing and comparison of items.
Implements
Namespace: SadRogue.Primitives.SpatialMaps
Assembly: TheSadRogue.Primitives.dll
Syntax
public class AdvancedLayeredSpatialMap<T> : Object, ISpatialMap<T>, IReadOnlyLayeredSpatialMap<T>, IReadOnlySpatialMap<T>, IEnumerable<ItemPositionPair<T>>, IEnumerable where T : IHasLayer
Type Parameters
Name | Description |
---|---|
T | Type of items in the layers. Type T must implement IHasLayer, and its Layer value MUST NOT change while the item is in the AdvancedLayeredSpatialMap. |
Remarks
This class is useful for cases where you do not want to implement IHasID. For simple cases, it is recommended to use LayeredSpatialMap<T> instead. Be mindful of the efficiency of your hashing function specified in the IEqualityComparer<T> -- it will in large part determine the performance of AdvancedLayeredSpatialMap!
Constructors
AdvancedLayeredSpatialMap(IEqualityComparer<T>, Int32, Func<Int32, IListPool<T>>, IEqualityComparer<Point>, Int32, UInt32)
Constructor.
Declaration
public AdvancedLayeredSpatialMap(IEqualityComparer<T> itemComparer, int numberOfLayers, Func<int, IListPool<T>> customListPoolCreator = null, IEqualityComparer<Point> pointComparer = null, int startingLayer = 0, uint layersSupportingMultipleItems = 0U)
Parameters
Type | Name | Description |
---|---|---|
IEqualityComparer<T> | itemComparer | Equality comparer to use for comparison and hashing of type T. Be especially mindful of the efficiency of its GetHashCode function, as it will determine the efficiency of many AdvancedLayeredSpatialMap functions. |
Int32 | numberOfLayers | Number of layers to include. |
Func<Int32, IListPool<T>> | customListPoolCreator | A function used to determine the list pool implementation used for the spatial maps which support multiple items in a location (if any). The function takes the layer it is creating the pool for as a parameter. If no custom creator is specified, a ListPool is used. |
IEqualityComparer<Point> | pointComparer | Equality comparer to use for comparison and hashing of points, as object are added to/removed from/moved around the spatial map. Be especially mindful of the efficiency of its GetHashCode function, as it will determine the efficiency of many AdvancedLayeredSpatialMap functions. Defaults to the default equality comparer for Point, which uses a fairly efficient generalized hashing algorithm. |
Int32 | startingLayer | Index to use for the first layer. |
UInt32 | layersSupportingMultipleItems | A layer mask indicating which layers should support multiple items residing at the same location on that layer. Defaults to no layers. |
Properties
Count
The number of items in the spatial map.
Declaration
public int Count { get; }
Property Value
Type | Description |
---|---|
Int32 |
Items
Enumerable of the items stored in the spatial map: for use to iterate over all items with a foreach loop.
Declaration
public IEnumerable<T> Items { get; }
Property Value
Type | Description |
---|---|
IEnumerable<T> |
LayerMasker
Object used to get layer masks as they pertain to this spatial map.
Declaration
public LayerMasker LayerMasker { get; }
Property Value
Type | Description |
---|---|
LayerMasker |
Layers
Gets read-only spatial maps representing each layer. To access a specific layer, instead use GetLayer(Int32).
Declaration
public IEnumerable<IReadOnlySpatialMap<T>> Layers { get; }
Property Value
Type | Description |
---|---|
IEnumerable<IReadOnlySpatialMap<T>> |
NumberOfLayers
Gets the number of layers contained in the spatial map.
Declaration
public int NumberOfLayers { get; }
Property Value
Type | Description |
---|---|
Int32 |
Positions
Enumerable of all positions that contain items.
Declaration
public IEnumerable<Point> Positions { get; }
Property Value
Type | Description |
---|---|
IEnumerable<Point> |
StartingLayer
Starting index for layers contained in this spatial map.
Declaration
public int StartingLayer { get; }
Property Value
Type | Description |
---|---|
Int32 |
Methods
Add(T, Point)
Adds the given item at the given position on the correct layer. ArgumentException is thrown if the layer is invalid or the item otherwise cannot be added to its layer.
Declaration
public void Add(T item, Point position)
Parameters
Type | Name | Description |
---|---|---|
T | item | Item to add. |
Point | position | Position to add item at. |
Add(T, Int32, Int32)
Adds the given item at the given position on the correct layer. ArgumentException is thrown if the layer is invalid or the item otherwise cannot be added to its layer.
Declaration
public void Add(T item, int x, int y)
Parameters
Type | Name | Description |
---|---|---|
T | item | Item to add. |
Int32 | x | X-value of position to add item at. |
Int32 | y | Y-value of position to add item at. |
AsReadOnly()
Returns a read-only reference to the spatial map. Convenient for "safely" exposing the spatial map as a property.
Declaration
public IReadOnlyLayeredSpatialMap<T> AsReadOnly()
Returns
Type | Description |
---|---|
IReadOnlyLayeredSpatialMap<T> | The current spatial map, as a "read-only" reference. |
CanAdd(T, Point)
Returns true if the given item can be added at the given position, eg. it is on a layer in the spatial map and its layer will accept it; false otherwise.
Declaration
public 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 |
---|---|
Boolean | True if the item can be successfully added at the position given; false otherwise. |
CanAdd(T, Int32, Int32)
Returns true if the given item can be added at the given position, eg. it is on a layer in the spatial map and its layer will accept it; false otherwise.
Declaration
public bool CanAdd(T newItem, int x, int y)
Parameters
Type | Name | Description |
---|---|---|
T | newItem | Item to add. |
Int32 | x | X-value of the position to add item to. |
Int32 | y | Y-value of the position to add item to. |
Returns
Type | Description |
---|---|
Boolean | True if the item can be successfully added at the position given; false otherwise. |
CanMove(T, Point)
Returns true if the given item can be moved from its current location to the specified one, eg. it is in the spatial map and its layer will accept it at the new position; false otherwise.
Declaration
public 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 |
---|---|
Boolean | true if the given item can be moved to the given position; false otherwise. |
CanMove(T, Int32, Int32)
Returns true if the given item can be moved from its current location to the specified one, eg. it is in the spatial map and its layer will accept it at the new position; false otherwise.
Declaration
public bool CanMove(T item, int targetX, int targetY)
Parameters
Type | Name | Description |
---|---|---|
T | item | Item to move. |
Int32 | targetX | X-value of the location to move item to. |
Int32 | targetY | Y-value of the location to move item to. |
Returns
Type | Description |
---|---|
Boolean | true if the given item can be moved to the given position; false otherwise. |
CanMoveAll(Point, Point, UInt32)
Returns true if there are items at current
on one or more of the layers specified by the layer
mask,
and all items on those layers at that position can be moved to target
; false otherwise.
Declaration
public bool CanMoveAll(Point current, Point target, uint layerMask = 4294967295U)
Parameters
Type | Name | Description |
---|---|---|
Point | current | Location to move items from. |
Point | target | Location to move items to. |
UInt32 | layerMask | Layer mask indicating which layers to check items on. |
Returns
Type | Description |
---|---|
Boolean | 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. |
CanMoveAll(Int32, Int32, Int32, Int32, UInt32)
Returns true if there are items at the current position on one or more of the layers specified by the layer mask, and all items on those layers at that position can be moved to the target position; false otherwise.
Declaration
public bool CanMoveAll(int currentX, int currentY, int targetX, int targetY, uint layerMask = 4294967295U)
Parameters
Type | Name | Description |
---|---|---|
Int32 | currentX | X-value of the location to move items from. |
Int32 | currentY | Y-value of the location to move items from. |
Int32 | targetX | X-value of the location to move items to. |
Int32 | targetY | Y-value of the location to move items to. |
UInt32 | layerMask | Layer mask indicating which layers to check items on. |
Returns
Type | Description |
---|---|
Boolean | 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. |
Clear()
Clears all items out of the spatial map.
Declaration
public void Clear()
Contains(T)
Returns whether or not the spatial map contains the given item.
Declaration
public bool Contains(T item)
Parameters
Type | Name | Description |
---|---|---|
T | item | The item to check for. |
Returns
Type | Description |
---|---|
Boolean | True if the given item is contained in the spatial map, false if not. |
Contains(Point, UInt32)
Returns whether or not there is an item in the spatial map at the given position that is on a layer included in the given layer mask. Defaults to searching on all layers.
Declaration
public bool Contains(Point position, uint layerMask = 4294967295U)
Parameters
Type | Name | Description |
---|---|---|
Point | position | The position to check for. |
UInt32 | layerMask | Layer mask that indicates which layers to check. Defaults to all layers. |
Returns
Type | Description |
---|---|
Boolean | True if there is some item at the given position on a layer included in the given layer mask, false if not. |
Contains(Int32, Int32, UInt32)
Returns whether or not there is an item in the data structure at the given position, that is on a layer included in the given layer mask.
Declaration
public bool Contains(int x, int y, uint layerMask = 4294967295U)
Parameters
Type | Name | Description |
---|---|---|
Int32 | x | X-value of the position to check for. |
Int32 | y | Y-value of the position to check for. |
UInt32 | layerMask | Layer mask that indicates which layers to check. Defaults to all layers. |
Returns
Type | Description |
---|---|
Boolean | True if there is some item at the given position on a layer included in the given layer mask, false if not. |
GetEnumerator()
Used by foreach loop, so that the class will give ISpatialTuple objects when used in a foreach loop. Generally should never be called explicitly.
Declaration
public IEnumerator<ItemPositionPair<T>> GetEnumerator()
Returns
Type | Description |
---|---|
IEnumerator<ItemPositionPair<T>> | An enumerator for the spatial map |
GetItemsAt(Point, UInt32)
Gets the item(s) associated with the given position that reside on any layer included in the given layer mask. Returns nothing if there is nothing at that position on a layer included in the given layer mask.
Declaration
public IEnumerable<T> GetItemsAt(Point position, uint layerMask = 4294967295U)
Parameters
Type | Name | Description |
---|---|---|
Point | position | The position to return the item(s) for. |
UInt32 | layerMask | Layer mask that indicates which layers to check. Defaults to all layers. |
Returns
Type | Description |
---|---|
IEnumerable<T> | The item(s) at the given position that reside on a layer included in the layer mask if there are any items, or nothing if there is nothing at that position. |
GetItemsAt(Int32, Int32, UInt32)
Gets the item(s) associated with the given position that reside on any layer included in the given layer mask. Returns nothing if there is nothing at that position on a layer included in the given layer mask.
Declaration
public IEnumerable<T> GetItemsAt(int x, int y, uint layerMask = 4294967295U)
Parameters
Type | Name | Description |
---|---|---|
Int32 | x | X-value of the position to return the item(s) for. |
Int32 | y | Y-value of the position to return the item(s) for. |
UInt32 | layerMask | Layer mask that indicates which layers to check. Defaults to all layers. |
Returns
Type | Description |
---|---|
IEnumerable<T> | The item(s) at the given position that reside on a layer included in the layer mask if there are any items, or nothing if there is nothing at that position. |
GetLayer(Int32)
Gets a read-only spatial map representing the layer specified.
Declaration
public IReadOnlySpatialMap<T> GetLayer(int layer)
Parameters
Type | Name | Description |
---|---|---|
Int32 | layer | The layer to retrieve. |
Returns
Type | Description |
---|---|
IReadOnlySpatialMap<T> | The IReadOnlySpatialMap that represents the given layer. |
GetLayersInMask(UInt32)
Returns read-only spatial maps that represent each layer included in the given layer mask. Defaults to all layers.
Declaration
public IEnumerable<IReadOnlySpatialMap<T>> GetLayersInMask(uint layerMask = 4294967295U)
Parameters
Type | Name | Description |
---|---|---|
UInt32 | layerMask | Layer mask indicating which layers to return. Defaults to all layers. |
Returns
Type | Description |
---|---|
IEnumerable<IReadOnlySpatialMap<T>> | Read-only spatial maps representing each layer in the given layer mask. |
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
public 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. |
GetPositionOfOrNull(T)
Gets the position associated with the given item in the spatial map, or null if that item is not found.
Declaration
public Nullable<Point> GetPositionOfOrNull(T item)
Parameters
Type | Name | Description |
---|---|---|
T | item | The item to get the position for. |
Returns
Type | Description |
---|---|
Nullable<Point> | The position associated with the given item, if it exists in the spatial map, or null if the item does not exist. |
Move(T, Point)
Moves the given item to the given position. Throws ArgumentException if either the item given
isn't in the spatial map, or if the layer that the item resides on is configured to allow only one item per
location at any given time and there is already an item at target
.
Declaration
public void Move(T item, Point target)
Parameters
Type | Name | Description |
---|---|---|
T | item | Item to move. |
Point | target | Position to move the given item to. |
Move(T, Int32, Int32)
Moves the given item to the given position. Throws ArgumentException if either the item given isn't in the spatial map, or if the layer that the item resides on is configured to allow only one item per location at any given time and there is already an item at the target position.
Declaration
public void Move(T item, int targetX, int targetY)
Parameters
Type | Name | Description |
---|---|---|
T | item | Item to move. |
Int32 | targetX | X-value of position to move the given item to. |
Int32 | targetY | Y-value of position to move the given item to. |
MoveAll(Point, Point, UInt32)
Moves all items that are on layers in layerMask
at the specified source location to the target
location. Throws ArgumentException if one or more items cannot be moved or there are
no items to be moved.
Declaration
public void MoveAll(Point current, Point target, uint layerMask = 4294967295U)
Parameters
Type | Name | Description |
---|---|---|
Point | current | Location to move items from. |
Point | target | Location to move items to. |
UInt32 | layerMask | The layer mask to use to find items. |
MoveAll(Int32, Int32, Int32, Int32, UInt32)
Moves all items that are on layers in layerMask
at the specified source location to the target
location. Throws ArgumentException if one or more items cannot be moved or there are
no items to be moved.
Declaration
public void MoveAll(int currentX, int currentY, int targetX, int targetY, uint layerMask = 4294967295U)
Parameters
Type | Name | Description |
---|---|---|
Int32 | currentX | X-value of the location to move items from. |
Int32 | currentY | Y-value of the location to move items from. |
Int32 | targetX | X-value of the location to move items to. |
Int32 | targetY | Y-value of the location to move items to. |
UInt32 | layerMask | The layer mask to use to find items. |
MoveValid(Point, Point, List<T>, UInt32)
Moves all items that can be moved, that are at the given position and on any layer specified by the given layer mask, to the new position. If no layer mask is specified, defaults to all layers.
Declaration
public void MoveValid(Point current, Point target, List<T> itemsMovedOutput, uint layerMask = 4294967295U)
Parameters
Type | Name | Description |
---|---|---|
Point | current | Position to move items from. |
Point | target | Position to move items to. |
List<T> | itemsMovedOutput | List in which to place all moved items. |
UInt32 | layerMask | Layer mask specifying which layers to search for items on. Defaults to all layers. |
MoveValid(Point, Point, UInt32)
Moves all items that can be moved, that are at the given position and on any layer specified by the given layer mask, to the new position. If no layer mask is specified, defaults to all layers.
Declaration
public List<T> MoveValid(Point current, Point target, uint layerMask = 4294967295U)
Parameters
Type | Name | Description |
---|---|---|
Point | current | Position to move all items from. |
Point | target | Position to move all items to. |
UInt32 | layerMask | Layer mask specifying which layers to search for items on. Defaults to all layers. |
Returns
Type | Description |
---|---|
List<T> | All items moved. |
MoveValid(Int32, Int32, Int32, Int32, List<T>, UInt32)
Moves all items that can be moved, that are at the given position and on any layer specified by the given layer mask, to the new position. If no layer mask is specified, defaults to all layers.
Declaration
public void MoveValid(int currentX, int currentY, int targetX, int targetY, List<T> itemsMovedOutput, uint layerMask = 4294967295U)
Parameters
Type | Name | Description |
---|---|---|
Int32 | currentX | X-value of the position to move items from. |
Int32 | currentY | Y-value of the position to move items from. |
Int32 | targetX | X-value of the position to move items to. |
Int32 | targetY | Y-value of the position to move items from. |
List<T> | itemsMovedOutput | List in which to place all moved items. |
UInt32 | layerMask | Layer mask specifying which layers to search for items on. Defaults to all layers. |
MoveValid(Int32, Int32, Int32, Int32, UInt32)
Moves all items that can be moved, that are at the given position and on any layer specified by the given layer mask, to the new position. If no layer mask is specified, defaults to all layers.
Declaration
public List<T> MoveValid(int currentX, int currentY, int targetX, int targetY, uint layerMask = 4294967295U)
Parameters
Type | Name | Description |
---|---|---|
Int32 | currentX | X-value of the position to move items from. |
Int32 | currentY | Y-value of the position to move items from. |
Int32 | targetX | X-value of the position to move items to. |
Int32 | targetY | Y-value of the position to move items from. |
UInt32 | layerMask | Layer mask specifying which layers to search for items on. Defaults to all layers. |
Returns
Type | Description |
---|---|
List<T> | All items moved. |
Remove(T)
Removes the given item from the spatial map. Throws ArgumentException if the item cannot be removed.
Declaration
public void Remove(T item)
Parameters
Type | Name | Description |
---|---|---|
T | item | The item to remove. |
Remove(Point, UInt32)
Removes all items at the specified location that are on any layer included in the given layer mask from the spatial map. Returns any items that were removed. Defaults to searching for items on all layers.
Declaration
public List<T> Remove(Point position, uint layerMask = 4294967295U)
Parameters
Type | Name | Description |
---|---|---|
Point | position | Position to remove items from. |
UInt32 | layerMask | The layer mask indicating which layers to search for items. Defaults to all layers. |
Returns
Type | Description |
---|---|
List<T> | Any items that were removed, or nothing if no items were removed. |
Remove(Int32, Int32, UInt32)
Removes all items at the specified location that are on any layer included in the given layer mask from the spatial map. Returns any items that were removed. Defaults to searching for items on all layers.
Declaration
public List<T> Remove(int x, int y, uint layerMask = 4294967295U)
Parameters
Type | Name | Description |
---|---|---|
Int32 | x | X-value of the position to remove items from. |
Int32 | y | Y-value of the position to remove items from. |
UInt32 | layerMask | The layer mask indicating which layers to search for items. Defaults to all layers. |
Returns
Type | Description |
---|---|
List<T> | Any items that were removed, or nothing if no items were removed. |
ToString()
Returns a string representation of each layer in the spatial map.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
String | A string representing each layer of the LayeredSpatialMap |
ToString(Func<T, String>)
Returns a string representation of each item in the spatial map, with elements displayed in the specified way.
Declaration
public string ToString(Func<T, string> elementStringifier)
Parameters
Type | Name | Description |
---|---|---|
Func<T, String> | elementStringifier | A function that takes an element of type T and produces the string that should represent it in the output. |
Returns
Type | Description |
---|---|
String | A string representing each layer in the spatial map, with each element displayed in the specified way. |
TryAdd(T, Point)
Adds the given item at the given position on the correct layer. If the layer is invalid or the item otherwise cannot be added to its layer, does nothing and returns false.
Declaration
public bool TryAdd(T item, Point position)
Parameters
Type | Name | Description |
---|---|---|
T | item | Item to add. |
Point | position | Position to add item at. |
Returns
Type | Description |
---|---|
Boolean | True if the item was added, false otherwise. |
TryAdd(T, Int32, Int32)
Adds the given item at the given position on the correct layer. If the layer is invalid or the item otherwise cannot be added to its layer, does nothing and returns false.
Declaration
public bool TryAdd(T item, int x, int y)
Parameters
Type | Name | Description |
---|---|---|
T | item | Item to add. |
Int32 | x | X-value of position to add item at. |
Int32 | y | Y-value of position to add item at. |
Returns
Type | Description |
---|---|
Boolean | True if the item was added, false otherwise. |
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
public 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 |
---|---|
Boolean | True if the item was found in the spatial map, false otherwise. |
TryMove(T, Point)
Attempts to move the given item from its current location to the specified one. Does nothing and returns false if the item cannot be moved to the given location.
Declaration
public bool TryMove(T item, Point target)
Parameters
Type | Name | Description |
---|---|---|
T | item | Item to move. |
Point | target | Location to move item to. |
Returns
Type | Description |
---|---|
Boolean | True if the item was moved; false if not. |
TryMove(T, Int32, Int32)
Attempts to move the given item from its current location to the specified one. Does nothing and returns false if the item cannot be moved to the given location.
Declaration
public bool TryMove(T item, int targetX, int targetY)
Parameters
Type | Name | Description |
---|---|---|
T | item | Item to move. |
Int32 | targetX | X-value of the location to move item to. |
Int32 | targetY | Y-value of the location to move item to. |
Returns
Type | Description |
---|---|
Boolean | True if the item was moved; false if not. |
TryMoveAll(Point, Point, UInt32)
Moves all items that are on layers in layerMask
at the specified source location to the
target location. Returns false if one or more items cannot be moved or there are no items to be moved.
Declaration
public bool TryMoveAll(Point current, Point target, uint layerMask = 4294967295U)
Parameters
Type | Name | Description |
---|---|---|
Point | current | Location to move items from. |
Point | target | Location to move items to. |
UInt32 | layerMask | The layer mask to use to find items. |
Returns
Type | Description |
---|---|
Boolean | True if all items at |
TryMoveAll(Int32, Int32, Int32, Int32, UInt32)
Moves all items that are on layers in layerMask
at the specified source location to the
target location. Returns false if one or more items cannot be moved or there are no items to be moved.
Declaration
public bool TryMoveAll(int currentX, int currentY, int targetX, int targetY, uint layerMask = 4294967295U)
Parameters
Type | Name | Description |
---|---|---|
Int32 | currentX | X-value of the location to move items from. |
Int32 | currentY | Y-value of the location to move items from. |
Int32 | targetX | X-value of the location to move items to. |
Int32 | targetY | Y-value of the location to move items to. |
UInt32 | layerMask | The layer mask to use to find items. |
Returns
Type | Description |
---|---|
Boolean | True if all items at the current position on layers within the mask given were moved to the target position; false otherwise. |
TryRemove(T)
Attempts to remove the given item from the spatial map. Does nothing and return false if the item cannot be removed.
Declaration
public bool TryRemove(T item)
Parameters
Type | Name | Description |
---|---|---|
T | item | The item to remove. |
Returns
Type | Description |
---|---|
Boolean | True if the item was successfully removed; false otherwise. |
TryRemove(Point, UInt32)
Attempts to remove all items at the specified location that are on any layer included in the given layer mask from the spatial map. Returns true if the items were successfully removed; false if one or more failed.
Declaration
public bool TryRemove(Point position, uint layerMask = 4294967295U)
Parameters
Type | Name | Description |
---|---|---|
Point | position | Position to remove items from. |
UInt32 | layerMask | The layer mask indicating which layers to search for items. Defaults to all layers. |
Returns
Type | Description |
---|---|
Boolean | True if the items were successfully removed; false otherwise |
TryRemove(Int32, Int32, UInt32)
Attempts to remove all items at the specified location that are on any layer included in the given layer mask from the spatial map. Returns true if the items were successfully removed; false if one or more failed.
Declaration
public bool TryRemove(int x, int y, uint layerMask = 4294967295U)
Parameters
Type | Name | Description |
---|---|---|
Int32 | x | X-value of the position to remove items from. |
Int32 | y | Y-value of the position to remove items from. |
UInt32 | layerMask | The layer mask indicating which layers to search for items. Defaults to all layers. |
Returns
Type | Description |
---|---|
Boolean | True if the items were successfully removed; false otherwise |
Events
ItemAdded
Event that is fired directly after an item has been added to the spatial map.
Declaration
public event EventHandler<ItemEventArgs<T>> ItemAdded
Event Type
Type | Description |
---|---|
EventHandler<ItemEventArgs<T>> |
ItemMoved
Event that is fired directly after an item in the spatial map has been moved.
Declaration
public event EventHandler<ItemMovedEventArgs<T>> ItemMoved
Event Type
Type | Description |
---|---|
EventHandler<ItemMovedEventArgs<T>> |
ItemRemoved
Event that is fired directly after an item has been removed from the spatial map.
Declaration
public event EventHandler<ItemEventArgs<T>> ItemRemoved
Event Type
Type | Description |
---|---|
EventHandler<ItemEventArgs<T>> |
Explicit Interface Implementations
IReadOnlySpatialMap<T>.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> IReadOnlySpatialMap<T>.AsReadOnly()
Returns
Type | Description |
---|---|
IReadOnlySpatialMap<T> | The current spatial map, as a "read-only" reference. |
IReadOnlySpatialMap<T>.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 IReadOnlySpatialMap<T>.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 |
---|---|
Boolean | 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. |
IReadOnlySpatialMap<T>.CanMoveAll(Int32, Int32, Int32, Int32)
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 IReadOnlySpatialMap<T>.CanMoveAll(int currentX, int currentY, int targetX, int targetY)
Parameters
Type | Name | Description |
---|---|---|
Int32 | currentX | X-value of the location to move items from. |
Int32 | currentY | Y-value of the location to move items from. |
Int32 | targetX | X-value of the location to move items to. |
Int32 | targetY | Y-value of the location to move items to. |
Returns
Type | Description |
---|---|
Boolean | 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. |
IReadOnlySpatialMap<T>.Contains(Point)
Returns if there is an item in the spatial map at the given position or not.
Declaration
bool IReadOnlySpatialMap<T>.Contains(Point position)
Parameters
Type | Name | Description |
---|---|---|
Point | position | The position to check for. |
Returns
Type | Description |
---|---|
Boolean | True if there is some item at the given position, false if not. |
IReadOnlySpatialMap<T>.Contains(Int32, Int32)
Returns if there is an item in the spatial map at the given position or not.
Declaration
bool IReadOnlySpatialMap<T>.Contains(int x, int y)
Parameters
Type | Name | Description |
---|---|---|
Int32 | x | The x-value of the position to check for. |
Int32 | y | The y-value of the position to check for. |
Returns
Type | Description |
---|---|
Boolean | True if there is some item at the given position, false if not. |
IReadOnlySpatialMap<T>.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> IReadOnlySpatialMap<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. |
IReadOnlySpatialMap<T>.GetItemsAt(Int32, Int32)
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> IReadOnlySpatialMap<T>.GetItemsAt(int x, int y)
Parameters
Type | Name | Description |
---|---|---|
Int32 | x | The x-value of the position to return the item(s) for. |
Int32 | 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. |
ISpatialMap<T>.MoveAll(Point, Point)
Moves all items at the specified source location to the target location. Throws ArgumentException if one or more items cannot be moved or there are no items to be moved.
Declaration
void ISpatialMap<T>.MoveAll(Point current, Point target)
Parameters
Type | Name | Description |
---|---|---|
Point | current | Location to move items from. |
Point | target | Location to move items to. |
ISpatialMap<T>.MoveAll(Int32, Int32, Int32, Int32)
Moves all items at the specified source location to the target location. Throws ArgumentException if one or more items cannot be moved or there are no items to be moved.
Declaration
void ISpatialMap<T>.MoveAll(int currentX, int currentY, int targetX, int targetY)
Parameters
Type | Name | Description |
---|---|---|
Int32 | currentX | X-value of the location to move items from. |
Int32 | currentY | Y-value of the location to move items from. |
Int32 | targetX | X-value of the location to move items to. |
Int32 | targetY | Y-value of the location to move items to. |
ISpatialMap<T>.MoveValid(Point, Point)
Moves all items at the specified source location that can be moved to the target location. Returns all items that were moved.
Declaration
List<T> ISpatialMap<T>.MoveValid(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 |
---|---|
List<T> | All items that were moved, or an empty list if no items were moved. |
ISpatialMap<T>.MoveValid(Point, Point, List<T>)
Moves all items at the specified source location that can be moved to the target location. Adds all items that were moved to the given list.
Declaration
void ISpatialMap<T>.MoveValid(Point current, Point target, List<T> itemsMovedOutput)
Parameters
Type | Name | Description |
---|---|---|
Point | current | Location to move items from. |
Point | target | Location to move items to. |
List<T> | itemsMovedOutput | A list to which all items successfully moved are added. |
ISpatialMap<T>.MoveValid(Int32, Int32, Int32, Int32)
Moves all items at the specified location that can be moved to the target one. Returns all items that were moved.
Declaration
List<T> ISpatialMap<T>.MoveValid(int currentX, int currentY, int targetX, int targetY)
Parameters
Type | Name | Description |
---|---|---|
Int32 | currentX | X-value of the location to move items from. |
Int32 | currentY | Y-value of the location to move items from. |
Int32 | targetX | X-value of the location to move items to. |
Int32 | targetY | Y-value of the location to move items to. |
Returns
Type | Description |
---|---|
List<T> | All items that were moved, or nothing if no items were moved. |
ISpatialMap<T>.MoveValid(Int32, Int32, Int32, Int32, List<T>)
Moves all items at the specified source location that can be moved to the target location. Adds all items that were moved to the given list.
Declaration
void ISpatialMap<T>.MoveValid(int currentX, int currentY, int targetX, int targetY, List<T> itemsMovedOutput)
Parameters
Type | Name | Description |
---|---|---|
Int32 | currentX | X-value of the location to move items from. |
Int32 | currentY | Y-value of the location to move items from. |
Int32 | targetX | X-value of the location to move items to. |
Int32 | targetY | Y-value of the location to move items to. |
List<T> | itemsMovedOutput | A list to which all items successfully moved are added. |
ISpatialMap<T>.Remove(Point)
Removes all items at the specified location from the spatial map. Returns all items that were removed.
Declaration
List<T> ISpatialMap<T>.Remove(Point position)
Parameters
Type | Name | Description |
---|---|---|
Point | position | Position to remove items from. |
Returns
Type | Description |
---|---|
List<T> | All items that were removed, or an empty list if no items were removed. |
ISpatialMap<T>.Remove(Int32, Int32)
Removes all items at the specified location from the spatial map. Returns all items that were removed.
Declaration
List<T> ISpatialMap<T>.Remove(int x, int y)
Parameters
Type | Name | Description |
---|---|---|
Int32 | x | X-value of the position to remove items from. |
Int32 | y | Y-value of the position to remove items from. |
Returns
Type | Description |
---|---|
List<T> | All items that were removed, or nothing if no items were removed. |
ISpatialMap<T>.TryMoveAll(Point, Point)
Moves all items at the specified source location to the target location. Returns false if one or more items cannot be moved or there are no items to be moved.
Declaration
bool ISpatialMap<T>.TryMoveAll(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 |
---|---|
Boolean | True if all items at |
ISpatialMap<T>.TryMoveAll(Int32, Int32, Int32, Int32)
Moves all items at the specified source location to the target location. Returns false if one or more items cannot be moved or there are no items to be moved.
Declaration
bool ISpatialMap<T>.TryMoveAll(int currentX, int currentY, int targetX, int targetY)
Parameters
Type | Name | Description |
---|---|---|
Int32 | currentX | X-value of the location to move items from. |
Int32 | currentY | Y-value of the location to move items from. |
Int32 | targetX | X-value of the location to move items to. |
Int32 | targetY | Y-value of the location to move items to. |
Returns
Type | Description |
---|---|
Boolean | True if all items at (currentX, currentY) were moved to (targetX, targetY); false otherwise. |
ISpatialMap<T>.TryRemove(Point)
Attempts to remove all items at the specified location from the spatial map. Returns true if the items were successfully removed; false if one or more failed.
Declaration
bool ISpatialMap<T>.TryRemove(Point position)
Parameters
Type | Name | Description |
---|---|---|
Point | position | Position to remove items from. |
Returns
Type | Description |
---|---|
Boolean | True if the items were successfully removed; false otherwise |
ISpatialMap<T>.TryRemove(Int32, Int32)
Attempts to remove all items at the specified location from the spatial map. Returns true if the items were successfully removed; false if one or more failed.
Declaration
bool ISpatialMap<T>.TryRemove(int x, int y)
Parameters
Type | Name | Description |
---|---|---|
Int32 | x | X-value of the position to remove items from. |
Int32 | y | Y-value of the position to remove items from. |
Returns
Type | Description |
---|---|
Boolean | True if the items were successfully removed; false otherwise |