public struct Cell : IEquatable<Cell>, IComparable<Cell>
Represents a 2D or 3D cell. Set the layer to 1 if the cell is meant to be 2D
Name | Type | Default Value | Description |
---|---|---|---|
One | Cell |
A cell set to row/column/layer = 1. Provided for ease of use. |
|
Zero | Cell |
A cell set to row/column/layer = 0. Provided for ease of use. |
Name | Type | Description |
---|---|---|
Column | int |
Gets the column index of the cell. |
Item(System.Int32) | int |
Indexer which Gets the row, column, or layer component of the cell by using an index
(0 = row, 1 = columns, 2 = layer).
|
Layer | int |
Gets the layer index of the cell. |
Row | int |
Gets the row index of the cell. |
public Cell(int row, int column, int layer)
Initializes a new instance of the Cell structure.
Name | Type | Description |
---|---|---|
row | int |
The row index of the cell. |
column | int |
The column index of the cell. |
layer | int |
The layer index of the cell. Only needed when the cell is associated with a three dimensional entity, otherwise just pass in 1. |
public static Cell operator *(Cell left, Cell right)
* operater implementation that allows you to multiple one cell by another.
The row from the second cell is multiplied by the row from the first. The column by
the column. The layer by the layer.
Name | Type | Description |
---|---|---|
left | Cell |
The first cell. |
right | Cell |
The second cell. |
Cell
The cell representing the multiplication of the second cell by the first
public static Cell operator +(Cell left, Cell right)
+ operater implementation that allows you to add two cells together. Row is added to row, column to column, and layer to layer from each cell.
Name | Type | Description |
---|---|---|
left | Cell |
The first cell. |
right | Cell |
The second cell. |
Cell
The cell representing the addition of the two input cells.
public static Cell operator -(Cell left, Cell right)
- operater implementation that allows you to subtract one cell from another.
The row from the second cell is subtracted from the row of the first. The column from
the column. The layer from the layer.
Name | Type | Description |
---|---|---|
left | Cell |
The first cell. |
right | Cell |
The second cell. |
Cell
The cell representing the subtraction of the second cell from the first
public static bool operator !=(Cell left, Cell right)
!= operater implementation that allows you check if two cells are not equal
The two cells will not be equal if the rows, columns, or layers do not match each
other from one cell to
the other (row != row, etc.)
Name | Type | Description |
---|---|---|
left | Cell |
The first cell. |
right | Cell |
The second cell. |
bool
Returns true if the cells are not equal, false if they are equal.
public static Cell operator /(Cell numerator, Cell denominator)
/ operater implementation that allows you to divide one cell by another.
The row from the numerator cell is divided by the row from the denominator cell (numerator/denominator).
The column by the column. The layer by the layer.
Name | Type | Description |
---|---|---|
numerator | Cell |
The numerator cell. |
denominator | Cell |
The denominator cell. |
Cell
The cell representing the division of the numerator cell by the denominator cell.
Uses integer division for each component of the Cell.
public static bool operator <(Cell left, Cell right)
< operater implementation that allows you check if the left cell is less than the right cell.
Name | Type | Description |
---|---|---|
left | Cell |
The left cell. |
right | Cell |
The right cell. |
bool
Please refer to the CompareTo method documentation to understand
how cell comparison works.
public static bool operator <=(Cell left, Cell right)
<= operater implementation that allows you check if the left cell is less than or equal to the right cell.
Name | Type | Description |
---|---|---|
left | Cell |
The left cell. |
right | Cell |
The right cell. |
bool
Please refer to the CompareTo method documentation to understand
how cell comparison works.
public static bool operator ==(Cell left, Cell right)
!= operater implementation that allows you check if two cells are equal
The two cells will be equal if the rows, columns, or layers all match each other from
one cell to
the other (row == row, etc.)
Name | Type | Description |
---|---|---|
left | Cell |
The first cell. |
right | Cell |
The second cell. |
bool
Returns true if the cells are equal, false if they are not equal.
public static bool operator >(Cell left, Cell right)
> operater implementation that allows you check if the left cell is greater than the right cell.
Name | Type | Description |
---|---|---|
left | Cell |
The left cell. |
right | Cell |
The right cell. |
bool
Please refer to the CompareTo method documentation to understand
how cell comparison works.
public static bool operator >=(Cell left, Cell right)
>= operater implementation that allows you check if the left cell is greater than or equal to the right cell.
Name | Type | Description |
---|---|---|
left | Cell |
The left cell. |
right | Cell |
The right cell. |
bool
Please refer to the CompareTo method documentation to understand
how cell comparison works.
public int CompareTo(Cell other)
Compares the input cell against this cell to determine whether this cell procedes, follows, or is at the same position of the input cell. This can be used to order a collection of cells in the same manner as they would appear in the scene (if they were associated with World Cells, that is). The method utilizes the row, column, and layer values. If you know the layer value is not used (such as in a 2D world), you may choose to use a different method rather than this one.
Name | Type | Description |
---|---|---|
other | object |
The other cell to compare this cell against. |
int
-1 if this cell precedes (is less than) the input "other" cell, +1 if this cell follows
(is greater than)
the input "other" cell, and 0 if the cells are at the same position (are equal).
The following logic is used to determine the order. First, the layer of the two cells
is compared. If this cell's
layer is less than the input cell's layer, -1 is returned. If this cell's layer is
greater than the input cell's layer,
+1 is returned. If the two have the same layer value, the row is compared in the same
manner. If the rows are the same,
the columns are compared. If the columns are compared, 0 is returned as the two cell's
are equal and have the same placement
in the order.
public bool Equals(Cell other)
Implementation of IEquatable<Cell>.Equals method. Use this, as it does not box input
struct.
This method compares the row, column, and layer. In some instances where you know
the layer does not
matter (on 2D worlds for instance), it may be slightly more performant to use a
TwoDimensionalCellComparer
for comparison, which will ignore the layer for comparison and hash code generation.
Name | Type | Description |
---|---|---|
other | object |
The other cell to compare this cell against. |
bool
false if the row, column, and/or layer value on
the other Cell is not equal to this cell's row, column, and/or layer value.
public override bool Equals(object obj)
Override of Equals method. You shouldn't need to use this, and you should not use it since it will cause the input Cell to be boxed.
Name | Type | Description |
---|---|---|
obj | object |
The object to check this cell against. |
bool
false if the object is not a Cell or it is but the row, column, and/or layer value
on
the obj is not equal to this cell's row, column, and/or layer value.
public override int GetHashCode()
Returns a hash code for this cell. Uses all three indexes (row, column and layer) to compute it, so the cell is treated as a 3D cell. Generally, it is better to use one of the Cell Equality Comparers (TwoDimensionalCellComparer or ThreeDimensionalCellComparer), as you determine if the cells are 2D or 3D at runtime and configure the correct type of comparer.
int
The hash code of the cell, calculated using all three fields (row, column, and layer).
public string ToShortenedString()
Returns a shortened formated string in the format of L layer# | R row# | C column#
A string representation of the Cell's Indexes.
public override string ToString()
Returns a nicely formatted string representation of the Cell's Indexes in the form of Layer layer# | Row row# | Column column#
A string representation of the Cell's Indexes.
public Cell WithColumnAdjusted(int layerAdjustment)
Returns a copy of the Cell structure with all values the same except for the Column. The new column value is equal to old column value + columnAdjustment
Name | Type | Description |
---|---|---|
columnAdjustment | int |
The adjustment to the column (added to current column value) |
Cell
The copy of this Cell structure with the new adjusted column value
public Cell WithLayerAdjusted(int layerAdjustment)
Returns a copy of the Cell structure with all values the same except for the Layer. The new layer value is equal to old layer value + layerAdjustment
Name | Type | Description |
---|---|---|
layerAdjustment | int |
The adjustment to the layer (added to current layer value) |
Cell
The copy of this Cell structure with the new adjusted layer value
public Cell WithNewColumn(int newColumn)
Returns a copy of the Cell structure with all values the same except for the Column, which is replaced by the input newColumn value.
Name | Type | Description |
---|---|---|
newColumn | int |
The new column value to use. |
Cell
The copy of this Cell structure with the new column value.
public Cell WithNewLayer(int newLayer)
Returns a copy of the Cell structure with all values the same except for the Layer, which is replaced by the input newLayer value.
Name | Type | Description |
---|---|---|
newLayer | int |
The new layer value to use. |
Cell
The copy of this Cell structure with the new layer value.
public Cell WithNewRow(int newRow)
Returns a copy of the Cell structure with all values the same except for the Row, which is replaced by the input newRow value.
Name | Type | Description |
---|---|---|
newRow | int |
The new row value to use. |
Cell
The copy of this Cell structure with the new row value.
public Cell WithRowAdjusted(int rowAdjustment)
Returns a copy of the Cell structure with all values the same except for the Row. The new row value is equal to old row value + rowAdjustment
Name | Type | Description |
---|---|---|
rowAdjustment | int |
The adjustment to the row (added to current row value) |
Cell
The copy of this Cell structure with the new adjusted row value