Class SwiftArray3D<T>
- Namespace
- SwiftCollections.Dimensions
- Assembly
- SwiftCollections.dll
Represents a generic, flattened 3D array with efficient indexing and resizing capabilities. Optimized for use in performance-critical applications like game grids.
[JsonConverter(typeof(StateJsonConverterFactory))]
[MemoryPackable(GenerateType.Object)]
public class SwiftArray3D<T> : IStateBacked<Array3DState<T>>, IEnumerable<T>, IEnumerable, IMemoryPackable<SwiftArray3D<T>>, IMemoryPackFormatterRegister
Type Parameters
TThe type of elements in the 3D array.
- Inheritance
-
SwiftArray3D<T>
- Implements
-
IStateBacked<Array3DState<T>>IEnumerable<T>IMemoryPackable<SwiftArray3D<T>>IMemoryPackFormatterRegister
- Inherited Members
- Extension Methods
Remarks
MemoryPack GenerateType: Object
SwiftCollections.Array3DState<T> State
Constructors
SwiftArray3D()
Initializes a new instance of the SwiftArray3D class with zero dimensions.
public SwiftArray3D()
Remarks
This constructor creates an empty three-dimensional array. Use this overload when you intend to set the dimensions later or create an empty array.
SwiftArray3D(Array3DState<T>)
Initializes a new instance of the SwiftArray3D class with the specified array state.
[MemoryPackConstructor]
public SwiftArray3D(Array3DState<T> state)
Parameters
stateArray3DState<T>The state object that encapsulates the underlying data and configuration for the three-dimensional array. Cannot be null.
SwiftArray3D(int, int, int)
Initializes a new instance of the SwiftArray3D class with the specified dimensions.
public SwiftArray3D(int width, int height, int depth)
Parameters
widthintThe number of elements in the first dimension. Must be greater than zero.
heightintThe number of elements in the second dimension. Must be greater than zero.
depthintThe number of elements in the third dimension. Must be greater than zero.
SwiftArray3D(int, int, int, T)
Initializes a new instance of the SwiftArray3D class with the specified dimensions and fills all elements with the provided default value.
public SwiftArray3D(int width, int height, int depth, T defaultValue)
Parameters
widthintThe number of elements in the first dimension. Must be greater than zero.
heightintThe number of elements in the second dimension. Must be greater than zero.
depthintThe number of elements in the third dimension. Must be greater than zero.
defaultValueTThe value to assign to each element in the array upon initialization.
Properties
Depth
Gets the current depth value for this instance.
[JsonIgnore]
[MemoryPackIgnore]
public int Depth { get; }
Property Value
Height
Gets the height value associated with the current instance.
[JsonIgnore]
[MemoryPackIgnore]
public int Height { get; }
Property Value
this[int, int, int]
Gets or sets the element at the specified three-dimensional indices.
[JsonIgnore]
[MemoryPackIgnore]
public T this[int x, int y, int z] { get; set; }
Parameters
xintThe zero-based index along the first dimension.
yintThe zero-based index along the second dimension.
zintThe zero-based index along the third dimension.
Property Value
- T
The element located at the specified indices.
Remarks
An exception is thrown if any index is outside the valid range for its dimension.
Length
[JsonIgnore]
[MemoryPackIgnore]
public int Length { get; }
Property Value
Size
Total size of the array.
[JsonIgnore]
[MemoryPackIgnore]
public int Size { get; }
Property Value
State
Gets or sets the complete state of the 3D array, including its dimensions and data contents.
[JsonInclude]
[MemoryPackInclude]
public Array3DState<T> State { get; }
Property Value
- Array3DState<T>
Remarks
Setting this property replaces the current array's dimensions and data with those from the specified state. Getting this property returns a snapshot of the current array state. This property is intended for serialization and deserialization scenarios.
Width
Gets the width of the object.
[JsonIgnore]
[MemoryPackIgnore]
public int Width { get; }
Property Value
Methods
Clear()
Clears all elements in the array.
public void Clear()
Fill(T)
Fills the entire array with the specified value.
public void Fill(T value)
Parameters
valueT
GetEnumerator()
Returns an enumerator that iterates through all elements in the 3D array.
public IEnumerator<T> GetEnumerator()
Returns
- IEnumerator<T>
An enumerator for the 3D array.
GetIndex(int, int, int)
Calculates the one-dimensional array index corresponding to the specified three-dimensional coordinates.
public virtual int GetIndex(int x, int y, int z)
Parameters
xintThe zero-based X coordinate to convert.
yintThe zero-based Y coordinate to convert.
zintThe zero-based Z coordinate to convert.
Returns
- int
The zero-based index in the underlying one-dimensional array that corresponds to the specified (x, y, z) coordinates.
Remarks
Use this method to map three-dimensional coordinates to a linear array index when working with flattened 3D data structures. The valid ranges for x, y, and z depend on the dimensions of the underlying data structure.
IsValidIndex(int, int, int)
Checks if the specified indices are within bounds.
public virtual bool IsValidIndex(int x, int y, int z)
Parameters
Returns
Resize(int, int, int)
Resizes the 3D array to the specified dimensions. Retains existing data where possible.
public void Resize(int newWidth, int newHeight, int newDepth)
Parameters
Shift(int, int, int, bool)
Shifts the elements in the array by the specified offsets along each axis.
public void Shift(int xOffset, int yOffset, int zOffset, bool wrap = true)
Parameters
xOffsetintThe offset to apply along the X-axis.
yOffsetintThe offset to apply along the Y-axis.
zOffsetintThe offset to apply along the Z-axis.
wrapboolSpecifies whether to wrap elements that exceed the array's boundaries. If
true, values wrap around to the other side of the array. Iffalse, values that exceed boundaries are discarded.
Remarks
- Wrapping behavior ensures that no data is lost during shifts.
- Non-wrapping behavior discards elements that move out of bounds.
ValidateIndex(int, int, int)
Validates the specified indices. Throws an exception if the indices are out of bounds.
public virtual void ValidateIndex(int x, int y, int z)