Cell Structure

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

Fields

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.

Properties

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).

Use it like you'd use an array, i.e., int row = cell[0];

Layer int

Gets the layer index of the cell.

Row int

Gets the row index of the cell.

Constructors

Cell(int, int, int)

public Cell(int row, int column, int layer)

Initializes a new instance of the Cell structure.

Parameters

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.

Methods

operator *(Cell, Cell)

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.

Parameters

Name Type Description
left Cell

The first cell.

right Cell

The second cell.

Returns

Cell
The cell representing the multiplication of the second cell by the first


operator +(Cell, Cell)

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.

Parameters

Name Type Description
left Cell

The first cell.

right Cell

The second cell.

Returns

Cell
The cell representing the addition of the two input cells.


operator -(Cell, Cell)

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.

Parameters

Name Type Description
left Cell

The first cell.

right Cell

The second cell.

Returns

Cell
The cell representing the subtraction of the second cell from the first


operator !=(Cell, Cell)

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.)

Parameters

Name Type Description
left Cell

The first cell.

right Cell

The second cell.

Returns

bool
Returns true if the cells are not equal, false if they are equal.


operator /(Cell, Cell)

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.

Parameters

Name Type Description
numerator Cell

The numerator cell.

denominator Cell

The denominator cell.

Returns

Cell
The cell representing the division of the numerator cell by the denominator cell. Uses integer division for each component of the Cell.


operator <(Cell, 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.

Parameters

Name Type Description
left Cell

The left cell.

right Cell

The right cell.

Returns

bool
Please refer to the CompareTo method documentation to understand how cell comparison works.


operator <=(Cell, Cell)

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.

Parameters

Name Type Description
left Cell

The left cell.

right Cell

The right cell.

Returns

bool
Please refer to the CompareTo method documentation to understand how cell comparison works.


operator ==(Cell, Cell)

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.)

Parameters

Name Type Description
left Cell

The first cell.

right Cell

The second cell.

Returns

bool
Returns true if the cells are equal, false if they are not equal.


operator >(Cell, Cell)

public static bool operator >(Cell left, Cell right)

> operater implementation that allows you check if the left cell is greater than the right cell.

Parameters

Name Type Description
left Cell

The left cell.

right Cell

The right cell.

Returns

bool
Please refer to the CompareTo method documentation to understand how cell comparison works.


operator >=(Cell, Cell)

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.

Parameters

Name Type Description
left Cell

The left cell.

right Cell

The right cell.

Returns

bool
Please refer to the CompareTo method documentation to understand how cell comparison works.


CompareTo(Cell)

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.

Parameters

Name Type Description
other object

The other cell to compare this cell against.

Returns

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.


Equals(Cell)

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.

Parameters

Name Type Description
other object

The other cell to compare this cell against.

Returns

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.


Equals(object)

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.

Parameters

Name Type Description
obj object

The object to check this cell against.

Returns

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.


GetHashCode()

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.

Returns

int
The hash code of the cell, calculated using all three fields (row, column, and layer).


ToShortenedString()

public string ToShortenedString()

Returns a shortened formated string in the format of L layer# | R row# | C column#

Returns


A string representation of the Cell's Indexes.


ToString()

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#

Returns


A string representation of the Cell's Indexes.


WithColumnAdjusted(int)

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

Parameters

Name Type Description
columnAdjustment int

The adjustment to the column (added to current column value)

Returns

Cell
The copy of this Cell structure with the new adjusted column value


WithLayerAdjusted(int)

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

Parameters

Name Type Description
layerAdjustment int

The adjustment to the layer (added to current layer value)

Returns

Cell
The copy of this Cell structure with the new adjusted layer value


WithNewColumn(int)

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.

Parameters

Name Type Description
newColumn int

The new column value to use.

Returns

Cell
The copy of this Cell structure with the new column value.


WithNewLayer(int)

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.

Parameters

Name Type Description
newLayer int

The new layer value to use.

Returns

Cell
The copy of this Cell structure with the new layer value.


WithNewRow(int)

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.

Parameters

Name Type Description
newRow int

The new row value to use.

Returns

Cell
The copy of this Cell structure with the new row value.


WithRowAdjusted(int)

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

Parameters

Name Type Description
rowAdjustment int

The adjustment to the row (added to current row value)

Returns

Cell
The copy of this Cell structure with the new adjusted row value