Table of Contents

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

T

The type of elements in the 3D array.

Inheritance
SwiftArray3D<T>
Implements
IStateBacked<Array3DState<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

state Array3DState<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

width int

The number of elements in the first dimension. Must be greater than zero.

height int

The number of elements in the second dimension. Must be greater than zero.

depth int

The 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

width int

The number of elements in the first dimension. Must be greater than zero.

height int

The number of elements in the second dimension. Must be greater than zero.

depth int

The number of elements in the third dimension. Must be greater than zero.

defaultValue T

The 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

int

Height

Gets the height value associated with the current instance.

[JsonIgnore]
[MemoryPackIgnore]
public int Height { get; }

Property Value

int

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

x int

The zero-based index along the first dimension.

y int

The zero-based index along the second dimension.

z int

The 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

int

Size

Total size of the array.

[JsonIgnore]
[MemoryPackIgnore]
public int Size { get; }

Property Value

int

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

int

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

value T

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

x int

The zero-based X coordinate to convert.

y int

The zero-based Y coordinate to convert.

z int

The 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

x int
y int
z int

Returns

bool

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

newWidth int
newHeight int
newDepth int

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

xOffset int

The offset to apply along the X-axis.

yOffset int

The offset to apply along the Y-axis.

zOffset int

The offset to apply along the Z-axis.

wrap bool

Specifies whether to wrap elements that exceed the array's boundaries. If true, values wrap around to the other side of the array. If false, 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)

Parameters

x int
y int
z int