Show / Hide Table of Contents

Class ArrayMap2D<T>

Implementation of the ISettableMapView<T> interface that uses a 2D array to store data.

Inheritance
System.Object
ArrayMap2D<T>
Implements
ISettableMapView<T>
IMapView<T>
System.ICloneable
System.IEquatable<ArrayMap2D<T>>
Inherited Members
System.Object.Equals(System.Object, System.Object)
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
Namespace: GoRogue.MapViews
Assembly: GoRogue.dll
Syntax
[Serializable]
public sealed class ArrayMap2D<T> : ISettableMapView<T>, IMapView<T>, ICloneable, IEquatable<ArrayMap2D<T>>
Type Parameters
Name Description
T

The type of value being stored.

Remarks

An ArrayMap2D<T> can be implicitly converted to its underlying 2D array, which allows exposing that array to code that works with 2D arrays. Modifications in the array appear in the map view as well.

If you need a 1D array instead of 2D, then you should use ArrayMap<T> instead.

Constructors

| Improve this Doc View Source

ArrayMap2D(T[,])

Constructor. Takes an existing 2D array to use as the underlying data structure.

Declaration
public ArrayMap2D(T[, ] existingArray)
Parameters
Type Name Description
T[,] existingArray

An existing 2D array to use as the data structure.

| Improve this Doc View Source

ArrayMap2D(Int32, Int32)

Constructor. Takes width and height of array.

Declaration
public ArrayMap2D(int width, int height)
Parameters
Type Name Description
System.Int32 width

Width of array.

System.Int32 height

Height of array.

Properties

| Improve this Doc View Source

Height

The height of the map.

Declaration
public int Height { get; }
Property Value
Type Description
System.Int32
| Improve this Doc View Source

Item[Coord]

Given a position, returns/sets the "value" associated with that location.

Declaration
public T this[Coord pos] { get; set; }
Parameters
Type Name Description
Coord pos

Location to get/set the value for.

Property Value
Type Description
T

The "value" associated with the provided location.

| Improve this Doc View Source

Item[Int32]

Given an 1-dimensional index, returns/sets the value associated with the corresponding position in the underlying 2D array.

Declaration
public T this[int index1D] { get; set; }
Parameters
Type Name Description
System.Int32 index1D

1D index of location to retrieve the "value" for.

Property Value
Type Description
T

The "value" associated with the given location.

| Improve this Doc View Source

Item[Int32, Int32]

Given an X and Y value, returns/sets the "value" associated with that location.

Declaration
public T this[int x, int y] { get; set; }
Parameters
Type Name Description
System.Int32 x

X-value of location.

System.Int32 y

Y-value of location.

Property Value
Type Description
T

The "value" associated with that location.

| Improve this Doc View Source

Width

The width of the map.

Declaration
public int Width { get; }
Property Value
Type Description
System.Int32

Methods

| Improve this Doc View Source

Clone()

Performs deep copy of array map.

Declaration
public object Clone()
Returns
Type Description
System.Object

The cloned ArrayMap2D.

| Improve this Doc View Source

Equals(ArrayMap2D<T>)

Compares the current ArrayMap2D to the one given.

Declaration
public bool Equals(ArrayMap2D<T> other)
Parameters
Type Name Description
ArrayMap2D<T> other
Returns
Type Description
System.Boolean

True if the given ArrayMap2D<T> with a reference to the same underlying array, false otherwise.

| Improve this Doc View Source

Equals(Object)

Compares the current ArrayMap2D to the object given.

Declaration
public override bool Equals(object obj)
Parameters
Type Name Description
System.Object obj
Returns
Type Description
System.Boolean

True if the given object is an ArrayMap2D<T> with a reference to the same underlying array, false otherwise.

Overrides
System.Object.Equals(System.Object)
| Improve this Doc View Source

GetHashCode()

Returns a hash-value for this object.

Declaration
public override int GetHashCode()
Returns
Type Description
System.Int32
Overrides
System.Object.GetHashCode()
| Improve this Doc View Source

SetToDefault()

Sets each element in the ArrayMap to the default for type T.

Declaration
public void SetToDefault()
| Improve this Doc View Source

ToString()

Returns a string representation of the 2D array.

Declaration
public override string ToString()
Returns
Type Description
System.String

A string representation of the 2D array.

Overrides
System.Object.ToString()
| Improve this Doc View Source

ToString(Func<T, String>)

Returns a string representation of the 2D array, using the elementStringifier function given to determine what string represents which value.

Declaration
public string ToString(Func<T, string> elementStringifier)
Parameters
Type Name Description
System.Func<T, System.String> elementStringifier

Function determining the string representation of each element.

Returns
Type Description
System.String

A string representation of the 2D array.

Remarks

This could be used, for example, on an ArrayMap2D of boolean values, to output '#' for false values, and '.' for true values.

| Improve this Doc View Source

ToString(Int32, Func<T, String>)

Prints the values in the ArrayMap2D, using the function specified to turn elements into strings, and using the "field length" specified.

Declaration
public string ToString(int fieldSize, Func<T, string> elementStringifier = null)
Parameters
Type Name Description
System.Int32 fieldSize

The size of the field to give each value. A positive-number right-aligns the text within the field, while a negative number left-aligns the text.

System.Func<T, System.String> elementStringifier

Function to use to convert each element to a string. null defaults to the ToString function of type T.

Returns
Type Description
System.String

A string representation of the ArrayMap2D.

Remarks

Each element of type T will have spaces added to cause it to take up exactly fieldSize characters, provided fieldSize is less than the length of the element's string represention.

Operators

| Improve this Doc View Source

Equality(ArrayMap2D<T>, ArrayMap2D<T>)

Compares the two ArrayMap2D instances.

Declaration
public static bool operator ==(ArrayMap2D<T> lhs, ArrayMap2D<T> rhs)
Parameters
Type Name Description
ArrayMap2D<T> lhs
ArrayMap2D<T> rhs
Returns
Type Description
System.Boolean

True if the two given ArrayMap2D<T> instances have a reference to the same underlying array, false otherwise.

| Improve this Doc View Source

Implicit(ArrayMap2D<T> to T[,])

Allows implicit conversion to 2D array.

Declaration
public static implicit operator T[, ](ArrayMap2D<T> arrayMap)
Parameters
Type Name Description
ArrayMap2D<T> arrayMap

The ArrayMap2D to convert.

Returns
Type Description
T[,]
| Improve this Doc View Source

Inequality(ArrayMap2D<T>, ArrayMap2D<T>)

Compares the two ArrayMap2D instances.

Declaration
public static bool operator !=(ArrayMap2D<T> lhs, ArrayMap2D<T> rhs)
Parameters
Type Name Description
ArrayMap2D<T> lhs
ArrayMap2D<T> rhs
Returns
Type Description
System.Boolean

True if the two given ArrayMap2D<T> instances do NOT have a reference to the same underlying array, false otherwise.

Implements

ISettableMapView<T>
IMapView<T>
System.ICloneable
System.IEquatable<T>

Extension Methods

Utility.Yield<T>(T)
IMapViewExtensions.ApplyOverlay<T>(ISettableMapView<T>, IMapView<T>)
IMapViewExtensions.Bounds<T>(IMapView<T>)
IMapViewExtensions.Contains<T>(IMapView<T>, Int32, Int32)
IMapViewExtensions.Contains<T>(IMapView<T>, Coord)
IMapViewExtensions.ExtendToString<T>(IMapView<T>, String, String, Func<T, String>, String, String, String, String)
IMapViewExtensions.ExtendToString<T>(IMapView<T>, Int32, String, String, Func<T, String>, String, String, String, String)
IMapViewExtensions.Positions<T>(IMapView<T>)
IMapViewExtensions.RandomItem<T>(IMapView<T>, IGenerator)
IMapViewExtensions.RandomItem<T>(IMapView<T>, Func<Coord, T, Boolean>, IGenerator)
IMapViewExtensions.RandomPosition<T>(IMapView<T>, T, IGenerator)
IMapViewExtensions.RandomPosition<T>(IMapView<T>, IEnumerable<T>, IGenerator)
IMapViewExtensions.RandomPosition<T>(IMapView<T>, HashSet<T>, IGenerator)
IMapViewExtensions.RandomPosition<T>(IMapView<T>, IGenerator, T[])
IMapViewExtensions.RandomPosition<T>(IMapView<T>, Func<Coord, T, Boolean>, IGenerator)
IMapViewExtensions.RandomPosition<T>(IMapView<T>, IGenerator)
  • Improve this Doc
  • View Source
Back to top Generated by DocFX