![]() |
Common
A library of common classes.
|
A 2D array that can be serialized. More...
Public Member Functions | |
Array2D () | |
Initializes an empty array. More... | |
Array2D (Array2D< T > other) | |
Initializes a copy of an array. More... | |
Array2D (int rows, int columns) | |
Initializes an array by size. More... | |
Array2D (T[,] array) | |
Initializes an array from a built-in 2D array. More... | |
void | Clear () |
Sets the contents of the array to the default value. More... | |
Array2D< T > | Copy () |
Returns a shallow copy of the array. More... | |
void | Fill (T value) |
Sets all elements of the array to the value. More... | |
Array2D< int > | FindDistances (int row, int column, Func< T, bool > predicate=null) |
Returns an array of distances from the specified index to each cell. Values of -1 indicate that the index does not exist. More... | |
Vector2DInt | FindIndex (Func< T, bool > predicate) |
Returns the first 2D index where the specified predicate is true. Returns a -1 vector if no index is found. More... | |
List< Vector2DInt > | FindIndexes (Func< T, bool > predicate) |
Returns a list of indexes where the specified predicate is true. More... | |
T | GetOrDefault (int row, int column, T fallback=default) |
Returns the value at the specified index if it exists. If not, returns the fallback value. More... | |
T | GetOrDefault (Vector2DInt index, T fallback=default) |
Returns the value at the specified index if it exists. If not, returns the fallback value. More... | |
bool | IndexExists (int row, int column) |
Returns true if the index exists. More... | |
Vector2DInt | IndexMirroredHorizontally (int row, int column) |
Returns the index corresponding to when the array is mirrored horizontally. More... | |
Vector2DInt | IndexMirroredHorizontally (Vector2DInt index) |
Returns the index corresponding to when the array is mirrored horizontally. More... | |
Vector2DInt | IndexMirroredVertically (int row, int column) |
Returns the index corresponding to when the array is mirrored vertically. More... | |
Vector2DInt | IndexMirroredVertically (Vector2DInt index) |
Returns the index corresponding to when the array is mirrored vertically. More... | |
Vector2DInt | IndexRotated180 (int row, int column) |
Returns the index corresponding to when the array is rotated 180 degrees. More... | |
Vector2DInt | IndexRotated180 (Vector2DInt index) |
Returns the index corresponding to when the array is rotated 180 degrees. More... | |
Vector2DInt | IndexRotated270 (int row, int column) |
Returns the index corresponding to when the array is rotated clockwise 270 degrees. More... | |
Vector2DInt | IndexRotated270 (Vector2DInt index) |
Returns the index corresponding to when the array is rotated clockwise 270 degrees. More... | |
Vector2DInt | IndexRotated90 (int row, int column) |
Returns the index corresponding to when the array is rotated clockwise 90 degrees. More... | |
Vector2DInt | IndexRotated90 (Vector2DInt index) |
Returns the index corresponding to when the array is rotated clockwise 90 degrees. More... | |
Vector2DInt | InverseIndex (int index) |
Returns the 2D index corresponding to the specified flat index. More... | |
Array2D< T > | MirroredHorizontally () |
Returns a new array mirrored horizontally, i.e. about the vertical axis. More... | |
Array2D< T > | MirroredVertically () |
Returns a new array mirrored vertically, i.e. about the horizontal axis. More... | |
Array2D< T > | Rotated180 () |
Returns a new array rotated 180 degrees. More... | |
Array2D< T > | Rotated270 () |
Returns a new array rotated clockwise 270 degrees. More... | |
Array2D< T > | Rotated90 () |
Returns a new array rotated clockwise 90 degrees. More... | |
string | ToArrayString () |
Returns a string of all array elements. More... | |
override string | ToString () |
bool | ValuesAreEqual (Array2D< T > other) |
Returns true if the values in the arrays are equal based on the default comparer. More... | |
bool | ValuesAreEqual (Array2D< T > other, Func< T, T, bool > comparer) |
Returns true if the values in the arrays are equal. More... | |
Static Public Member Functions | |
static T[] | FlattenArray (T[,] array) |
Returns a new flattened array from a built-in 2D array. More... | |
static implicit | operator Array2D< T > (T[,] array) |
Implicitly casts a built-in 2D array to an Array2D. More... | |
static bool | ValuesAreEqual (Array2D< T > x, Array2D< T > y) |
Returns true if the values in the arrays of equal based on the default comparer. More... | |
static bool | ValuesAreEqual (Array2D< T > x, Array2D< T > y, Func< T, T, bool > comparer) |
Returns true if the values in the arrays are equal. More... | |
Properties | |
T[] | Array = System.Array.Empty<T>() [getprivate set] |
The underlying flat array. More... | |
int | Columns [getprivate set] |
The number of columns in the array. More... | |
int | Rows [getprivate set] |
The number of rows in the array. More... | |
T | this[int row, int column] [getset] |
Accesses the array by 2D index. More... | |
T | this[Vector2DInt index] [getset] |
Accesses the array by 2D index. More... | |
Private Member Functions | |
int | Index (int row, int column) |
Returns the flat array index corresponding to the specified 2D index. More... | |
void | SearchDistances (int row, int column, int distance, Array2D< int > distances, Func< T, bool > predicate) |
Performs a recursive crawl of the array cells to determine the distance to an index. More... | |
A 2D array that can be serialized.
Definition at line 14 of file Array2D.cs.
Array2D | ( | ) |
Initializes an empty array.
Definition at line 37 of file Array2D.cs.
Array2D | ( | int | rows, |
int | columns | ||
) |
Initializes an array by size.
rows | The number of rows in the array. |
columns | The number of columns in the array. |
ArgumentException | Raised if either the input rows or columns are negative. |
Definition at line 48 of file Array2D.cs.
Initializes a copy of an array.
other | The original array. |
Definition at line 67 of file Array2D.cs.
Array2D | ( | T | array[,] | ) |
Initializes an array from a built-in 2D array.
array | The built-in 2D array. |
Definition at line 82 of file Array2D.cs.
void Clear | ( | ) |
Sets the contents of the array to the default value.
Definition at line 178 of file Array2D.cs.
Array2D< T > Copy | ( | ) |
Returns a shallow copy of the array.
Definition at line 139 of file Array2D.cs.
void Fill | ( | T | value | ) |
Sets all elements of the array to the value.
value | The fill value. |
Definition at line 187 of file Array2D.cs.
Array2D< int > FindDistances | ( | int | row, |
int | column, | ||
Func< T, bool > | predicate = null |
||
) |
Returns an array of distances from the specified index to each cell. Values of -1 indicate that the index does not exist.
row | The row. |
column | The column. |
predicate | A predicate that returns true when the cell at an index does not exist. If null, the default value for the array type will be considered an empty cell. |
Definition at line 566 of file Array2D.cs.
Vector2DInt FindIndex | ( | Func< T, bool > | predicate | ) |
Returns the first 2D index where the specified predicate is true. Returns a -1 vector if no index is found.
predicate | The predicate, taking each element. |
Definition at line 294 of file Array2D.cs.
List< Vector2DInt > FindIndexes | ( | Func< T, bool > | predicate | ) |
Returns a list of indexes where the specified predicate is true.
predicate | The predicate, taking each element. |
Definition at line 312 of file Array2D.cs.
|
static |
Returns a new flattened array from a built-in 2D array.
array | The built-in 2D array. |
Definition at line 332 of file Array2D.cs.
T GetOrDefault | ( | int | row, |
int | column, | ||
T | fallback = default |
||
) |
Returns the value at the specified index if it exists. If not, returns the fallback value.
row | The row index. |
column | The column index. |
fallback | The fallback value. |
Definition at line 355 of file Array2D.cs.
T GetOrDefault | ( | Vector2DInt | index, |
T | fallback = default |
||
) |
Returns the value at the specified index if it exists. If not, returns the fallback value.
index | The index. |
fallback | The fallback value. |
Definition at line 368 of file Array2D.cs.
|
private |
Returns the flat array index corresponding to the specified 2D index.
row | The row index. |
column | The column index. |
Definition at line 267 of file Array2D.cs.
bool IndexExists | ( | int | row, |
int | column | ||
) |
Returns true if the index exists.
row | The row index. |
column | The column index. |
Definition at line 256 of file Array2D.cs.
Vector2DInt IndexMirroredHorizontally | ( | int | row, |
int | column | ||
) |
Returns the index corresponding to when the array is mirrored horizontally.
row | The row. |
column | The column. |
Definition at line 498 of file Array2D.cs.
Vector2DInt IndexMirroredHorizontally | ( | Vector2DInt | index | ) |
Returns the index corresponding to when the array is mirrored horizontally.
index | The index vector. |
Definition at line 488 of file Array2D.cs.
Vector2DInt IndexMirroredVertically | ( | int | row, |
int | column | ||
) |
Returns the index corresponding to when the array is mirrored vertically.
row | The row. |
column | The column. |
Definition at line 535 of file Array2D.cs.
Vector2DInt IndexMirroredVertically | ( | Vector2DInt | index | ) |
Returns the index corresponding to when the array is mirrored vertically.
index | The index vector. |
Definition at line 525 of file Array2D.cs.
Vector2DInt IndexRotated180 | ( | int | row, |
int | column | ||
) |
Returns the index corresponding to when the array is rotated 180 degrees.
row | The row. |
column | The column. |
Definition at line 424 of file Array2D.cs.
Vector2DInt IndexRotated180 | ( | Vector2DInt | index | ) |
Returns the index corresponding to when the array is rotated 180 degrees.
index | The index vector. |
Definition at line 414 of file Array2D.cs.
Vector2DInt IndexRotated270 | ( | int | row, |
int | column | ||
) |
Returns the index corresponding to when the array is rotated clockwise 270 degrees.
row | The row. |
column | The column. |
Definition at line 461 of file Array2D.cs.
Vector2DInt IndexRotated270 | ( | Vector2DInt | index | ) |
Returns the index corresponding to when the array is rotated clockwise 270 degrees.
index | The index vector. |
Definition at line 451 of file Array2D.cs.
Vector2DInt IndexRotated90 | ( | int | row, |
int | column | ||
) |
Returns the index corresponding to when the array is rotated clockwise 90 degrees.
row | The row. |
column | The column. |
Definition at line 387 of file Array2D.cs.
Vector2DInt IndexRotated90 | ( | Vector2DInt | index | ) |
Returns the index corresponding to when the array is rotated clockwise 90 degrees.
index | The index vector. |
Definition at line 377 of file Array2D.cs.
Vector2DInt InverseIndex | ( | int | index | ) |
Returns the 2D index corresponding to the specified flat index.
index | The flat index. |
IndexOutOfRangeException | Raised if the index is outside the bounds of the array. |
Definition at line 277 of file Array2D.cs.
Array2D< T > MirroredHorizontally | ( | ) |
Returns a new array mirrored horizontally, i.e. about the vertical axis.
Definition at line 506 of file Array2D.cs.
Array2D< T > MirroredVertically | ( | ) |
Returns a new array mirrored vertically, i.e. about the horizontal axis.
Definition at line 543 of file Array2D.cs.
|
static |
Implicitly casts a built-in 2D array to an Array2D.
array | The built-in 2D array. |
Array2D< T > Rotated180 | ( | ) |
Returns a new array rotated 180 degrees.
Definition at line 432 of file Array2D.cs.
Array2D< T > Rotated270 | ( | ) |
Returns a new array rotated clockwise 270 degrees.
Definition at line 469 of file Array2D.cs.
Array2D< T > Rotated90 | ( | ) |
Returns a new array rotated clockwise 90 degrees.
Definition at line 395 of file Array2D.cs.
|
private |
Performs a recursive crawl of the array cells to determine the distance to an index.
row | The row. |
column | The column. |
distance | The current distance crawled. |
distances | The results array of distances. |
predicate | A predicate that returns true when the cell at an index does not exist. |
Definition at line 585 of file Array2D.cs.
string ToArrayString | ( | ) |
Returns a string of all array elements.
Definition at line 147 of file Array2D.cs.
override string ToString | ( | ) |
Definition at line 131 of file Array2D.cs.
bool ValuesAreEqual | ( | Array2D< T > | other | ) |
Returns true if the values in the arrays are equal based on the default comparer.
other | The other array. |
Definition at line 226 of file Array2D.cs.
bool ValuesAreEqual | ( | Array2D< T > | other, |
Func< T, T, bool > | comparer | ||
) |
Returns true if the values in the arrays are equal.
other | The other array. |
comparer | The element equality comparer. |
Definition at line 236 of file Array2D.cs.
Returns true if the values in the arrays of equal based on the default comparer.
x | The first array. |
y | The second array. |
Definition at line 200 of file Array2D.cs.
Returns true if the values in the arrays are equal.
x | The first array. |
y | The second array. |
comparer | The equality comparer. |
Definition at line 211 of file Array2D.cs.
|
getprivate set |
The underlying flat array.
Definition at line 32 of file Array2D.cs.
|
getprivate set |
The number of columns in the array.
Definition at line 26 of file Array2D.cs.
|
getprivate set |
The number of rows in the array.
Definition at line 20 of file Array2D.cs.
|
getset |
Accesses the array by 2D index.
row | The row index. |
column | The column index. |
IndexOutOfRangeException | Raised if the index is out of range. |
Definition at line 98 of file Array2D.cs.
|
getset |
Accesses the array by 2D index.
index | The index vector, where X is the row and Y is the column. |
Definition at line 118 of file Array2D.cs.