ChunkCell Structure

public struct ChunkCell : IEquatable<ChunkCell>, IComparable<ChunkCell>

Represents a cell with an additional chunk index. Useful for dictionaries and other such collections that need to store something per chunk rather than per cell.

Fields

Name Type Default Value Description
Cell readonly Cell

The actual Cell this struct details.

ChunkIndex readonly int

The chunk index of the ChunkCell.

Constructors

ChunkCell(Cell, int)

public ChunkCell(Cell cell, int chunkIndex)

Initializes a new instance of the ChunkCell structure.

Parameters

Name Type Description
cell Cell

The cell of the ChunkCell.

chunkIndex int

The chunk index of the ChunkCell.

Methods

operator !=(ChunkCell, ChunkCell)

public static bool operator !=(ChunkCell left, ChunkCell right)

!= operater implementation that allows you check if two ChunkCells are not equal

The two ChunkCells will not be equal if the ChunkIndex, rows, columns, or layers do not match each other from one ChunkCell to the other (row != row, etc.)

Parameters

Name Type Description
left ChunkCell

The first ChunkCell.

right ChunkCell

The second ChunkCell.

Returns

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


operator <(ChunkCell, ChunkCell)

public static bool operator <(ChunkCell left, ChunkCell right)

< operater implementation that allows you check if the left ChunkCell is less than the right ChunkCell. to determine

Parameters

Name Type Description
left ChunkCell

The left ChunkCell.

right ChunkCell

The right ChunkCell.

Returns

bool
The Cell value takes priority, that is if the Cell value of left is less than the Cell value of right, true is returned. If the cell value of left is greater than the Cell value of right, false is returned. If the Cell values are equal, ChunkIndex is used. If ChunkIndex of left is less than ChunkIndex of right, true is returned. Otherwise false is returned.


operator <=(ChunkCell, ChunkCell)

public static bool operator <=(ChunkCell left, ChunkCell right)

<= operater implementation that allows you check if the left ChunkCell is less than or equal to the right ChunkCell.

Parameters

Name Type Description
left ChunkCell

The left ChunkCell.

right ChunkCell

The right ChunkCell.

Returns

bool
The Cell value takes priority, that is if the Cell value of left is less than the Cell value of right, true is returned. If the cell value of left is greater than the Cell value of right, false is returned. If the Cell values are equal, ChunkIndex is used. If ChunkIndex of left is less than or equal to ChunkIndex of right, true is returned. Otherwise false is returned.


operator ==(ChunkCell, ChunkCell)

public static bool operator ==(ChunkCell left, ChunkCell right)

!= operater implementation that allows you check if two ChunkCells are equal

The two ChunkCells will be equal if the ChunkIndex, rows, columns, or layers all match each other from one ChunkCell to the other (row == row, etc.)

Parameters

Name Type Description
left ChunkCell

The first ChunkCell.

right ChunkCell

The second ChunkCell.

Returns

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


operator >(ChunkCell, ChunkCell)

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

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

Parameters

Name Type Description
left ChunkCell

The left ChunkCell.

right ChunkCell

The right ChunkCell.

Returns

bool
The Cell value takes priority, that is if the Cell value of left is greater than the Cell value of right, true is returned. If the cell value of left is less than the Cell value of right, false is returned. If the Cell values are equal, ChunkIndex is used. If ChunkIndex of left is greater than ChunkIndex of right, true is returned. Otherwise false is returned.


operator >=(ChunkCell, ChunkCell)

public static bool operator >=(ChunkCell left, ChunkCell right)

>= operater implementation that allows you check if the left ChunkCell is greater than or equal to the right ChunkCell.

Parameters

Name Type Description
left ChunkCell

The left ChunkCell.

right ChunkCell

The right ChunkCell.

Returns

bool
The Cell value takes priority, that is if the Cell value of left is greater than the Cell value of right, true is returned. If the cell value of left is less than the Cell value of right, false is returned. If the Cell values are equal, ChunkIndex is used. If ChunkIndex of left is greater than or equal to ChunkIndex of right, true is returned. Otherwise false is returned.


CompareTo(ChunkCell)

public int CompareTo(ChunkCell other)

Compares the input ChunkCell against this ChunkCell to determine whether this ChunkCell procedes, follows, or is at the same position of the input ChunkCell. This can be used to order a collection of ChunkCells. The method utilizes the ChunkIndex, 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 ChunkCell to compare this ChunkCell against.

Returns

int
-1 if this ChunkCell precedes (is less than) the input "other" ChunkCell, +1 if this ChunkCell follows (is greater than) the input "other" ChunkCell, and 0 if the ChunkCells are at the same position (are equal).

The following logic is used to determine the order. First, the Cell value of the two ChunkCell's is compared. If this cell's Cell value is less than the Cell value of the input cell, -1 is returned. If it is greater, +1 is returned. If they are the same, then the ChunkIndex value is copared in the same manner. If this ChunkCell's ChunkIndex is less than the input ChunkCell's ChunkIndex, -1 is returned. If this ChunkCell's ChunkIndex is greater than the input ChunkCell's ChunkIndex, +1 is returned. If the two have the same ChunkIndex value, 0 is returned.


Equals(ChunkCell)

public bool Equals(ChunkCell other)

Implementation of IEquatable<ChunkCell>.Equals method. Use this, as it does not box input struct.

This method compares the ChunkIndex, 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 custom ChunkCell EqualityComparer that ignores the layer.

Parameters

Name Type Description
other object

The other ChunkCell to compare this ChunkCell against.

Returns

bool
false if the row, column, and/or layer value on the other ChunkCell is not equal to this ChunkCell's ChunkIndex, 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 ChunkCell to be boxed.

Parameters

Name Type Description
obj object

The object to check this ChunkCell against.

Returns

bool
false if the object is not a ChunkCell or it is but the ChunkIndex, row, column, and/or layer value on the obj is not equal to this ChunkCell's ChunkIndex, row, column, and/or layer value.


GetHashCode()

public override int GetHashCode()

Returns a hash code for this ChunkCell. Uses all three indexes (row, column and layer) + the ChunkIndex to compute it, so the ChunkCell is treated as a 3D ChunkCell. You could also create a custom EqualityComparer that only utilizes the row, column, and ChunkIndex, if you know that you do not need the layer value.

Returns

int
The hash code of the ChunkCell, calculated using all four fields (ChunkIndex, row, column, and layer).