CellAndIndex Structure

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

Represents a cell with an additional index field that can be used to store other data such as the LOD of the cell or World Grouping of the cell. You can use this, for example, in per World dictionary where you need to store values for multiple World Groupings. Since each World Grouping will contain World Cell's the same Endless Grid Cell indexes, it's not possible to save the values using just the Endless Grid Cell index as key. With this struct, you can store the World Grouping of where the value is coming from as well. This is just one example, you can really use it any time you need to store something using the Endless Grid Cell index + 1 other int value as key.

Fields

Name Type Default Value Description
Cell readonly Cell

The actual Cell this struct details.

Index readonly int

The index of the CellAndIndex.

Constructors

CellAndIndex(Cell, int)

public CellAndIndex(Cell cell, int index)

Initializes a new instance of the CellAndIndex structure.

Parameters

Name Type Description
cell Cell

The cell of the CellAndIndex.

index int

The index of the CellAndIndex.

Methods

operator !=(CellAndIndex, CellAndIndex)

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

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

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

Parameters

Name Type Description
left CellAndIndex

The first CellAndIndex.

right CellAndIndex

The second CellAndIndex.

Returns

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


operator <(CellAndIndex, CellAndIndex)

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

< operater implementation that allows you check if the left CellAndIndex is less than the right CellAndIndex.

Parameters

Name Type Description
left CellAndIndex

The left CellAndIndex.

right CellAndIndex

The right CellAndIndex.

Returns

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


operator <=(CellAndIndex, CellAndIndex)

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

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

Parameters

Name Type Description
left CellAndIndex

The left CellAndIndex.

right CellAndIndex

The right CellAndIndex.

Returns

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


operator ==(CellAndIndex, CellAndIndex)

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

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

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

Parameters

Name Type Description
left CellAndIndex

The first CellAndIndex.

right CellAndIndex

The second CellAndIndex.

Returns

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


operator >(CellAndIndex, CellAndIndex)

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

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

Parameters

Name Type Description
left CellAndIndex

The left CellAndIndex.

right CellAndIndex

The right CellAndIndex.

Returns

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


operator >=(CellAndIndex, CellAndIndex)

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

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

Parameters

Name Type Description
left CellAndIndex

The left CellAndIndex.

right CellAndIndex

The right CellAndIndex.

Returns

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


CompareTo(CellAndIndex)

public int CompareTo(CellAndIndex other)

Compares the input CellAndIndex against this CellAndIndex to determine whether this CellAndIndex procedes, follows, or is at the same position of the input CellAndIndex. Please take a look at the return value summar to understand how the ordering is determined. The method utilizes the Index, 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 CellAndIndex to compare this CellAndIndex against.

Returns

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

The following logic is used to determine the order. First, the Index of the two CellAndIndex's is compared. If this cell's Index value is less than the Index value of the input cell, -1 is returned. If it is greater, +1 is returned. If they are the same, then the Layer value is compared in the same manner. If this CellAndIndex's layer is less than the input CellAndIndex's layer, -1 is returned. If this CellAndIndex's layer is greater than the input CellAndIndex'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 CellAndIndex's are equal and have the same placement in the order.


Equals(CellAndIndex)

public bool Equals(CellAndIndex other)

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

This method compares the Index, 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 CellAndIndex EqualityComparer that ignores the layer

Parameters

Name Type Description
other object

The other CellAndIndex to compare this CellAndIndex against.

Returns

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

Parameters

Name Type Description
obj object

The object to check this CellAndIndex against.

Returns

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


GetHashCode()

public override int GetHashCode()

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

Returns

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