Table of Contents

Class SwiftBoolArray2D

Namespace
SwiftCollections.Dimensions
Assembly
SwiftCollections.dll

Represents a 2D array specifically designed to handle boolean values.

[JsonConverter(typeof(StateJsonConverterFactory))]
[MemoryPackable(GenerateType.Object)]
public class SwiftBoolArray2D : SwiftArray2D<bool>, IEnumerable<bool>, IEnumerable, IMemoryPackable<SwiftArray2D<bool>>, IStateBacked<Array2DState<bool>>, IMemoryPackable<SwiftBoolArray2D>, IMemoryPackFormatterRegister
Inheritance
SwiftBoolArray2D
Implements
IMemoryPackable<SwiftArray2D<bool>>
IStateBacked<Array2DState<bool>>
IMemoryPackable<SwiftBoolArray2D>
IMemoryPackFormatterRegister
Inherited Members
Extension Methods

Remarks

MemoryPack GenerateType: Object

SwiftCollections.Array2DState<bool> State

Constructors

SwiftBoolArray2D()

Initializes a new instance of the SwiftBoolArray2D class.

public SwiftBoolArray2D()

SwiftBoolArray2D(Array2DState<bool>)

Initializes a new instance of the SwiftBoolArray2D class using the specified array state.

[MemoryPackConstructor]
public SwiftBoolArray2D(Array2DState<bool> state)

Parameters

state Array2DState<bool>

The state to restore. Dimensions must be non-negative and their exact product must equal the non-null data array's length. Data is copied into independently owned storage.

Remarks

A zero dimension requires empty data. Unlike dimensional construction, restoration rejects negative dimensions instead of clamping them. Validation and copying complete before the restored state is installed.

Exceptions

ArgumentNullException

The state data array is null.

ArgumentOutOfRangeException

A state dimension is negative.

OverflowException

The exact dimension product exceeds Int32.MaxValue.

ArgumentException

The data length differs from the dimension product.

SwiftBoolArray2D(bool[,])

Initializes a new instance of the SwiftBoolArray2D class using the specified two-dimensional Boolean array as the source data.

public SwiftBoolArray2D(bool[,] source)

Parameters

source bool[,]

The source rectangular array. Elements are shallow-copied; the source storage is not retained.

Exceptions

NullReferenceException

source is null; this constructor does not use the AddRange null guard.

SwiftBoolArray2D(int, int)

Initializes a new instance of the SwiftBoolArray2D class with the specified dimensions.

public SwiftBoolArray2D(int width, int height)

Parameters

width int

The requested width in cells; negative values are clamped to zero.

height int

The requested height in cells; negative values are clamped to zero.

Remarks

Negative dimensions are clamped before checking the exact dimension product. A zero dimension creates empty storage.

Exceptions

OverflowException

The exact product of the clamped dimensions exceeds Int32.MaxValue.

SwiftBoolArray2D(int, int, bool)

Initializes a new instance of the SwiftBoolArray2D class with the specified dimensions and default value.

public SwiftBoolArray2D(int width, int height, bool defaultValue)

Parameters

width int

The requested width in cells; negative values are clamped to zero.

height int

The requested height in cells; negative values are clamped to zero.

defaultValue bool

The value assigned to every selected cell; reference-type values are shared, not cloned.

Remarks

Negative dimensions are clamped before checking the exact dimension product. A zero dimension creates empty storage.

Exceptions

OverflowException

The exact product of the clamped dimensions exceeds Int32.MaxValue.

Methods

CountTrue()

Counts the number of true values in the array.

public int CountTrue()

Returns

int

The number of true cells in the entire backing array; zero for empty storage.

SetRegion(int, int, int, int, bool)

Sets all values within a rectangular region to the specified value.

public void SetRegion(int xStart, int yStart, int width, int height, bool value)

Parameters

xStart int

The inclusive starting X coordinate in cells; out-of-bounds cells are skipped.

yStart int

The inclusive starting Y coordinate in cells; out-of-bounds cells are skipped.

width int

The number of X cells to visit; non-positive widths visit no cells.

height int

The number of Y cells to visit; non-positive heights visit no cells.

value bool

The value assigned to every selected cell; reference-type values are shared, not cloned.

Remarks

Only coordinates inside the array are written. Region endpoints use unchecked Int32 addition; keep start plus extent representable. This is a clipped overwrite, not a resize.

Toggle(int, int)

Toggles the value at the specified position in the array.

public void Toggle(int x, int y)

Parameters

x int

The zero-based X coordinate; valid from zero through the corresponding dimension minus one.

y int

The zero-based Y coordinate; valid from zero through the corresponding dimension minus one.

Exceptions

IndexOutOfRangeException

The cell coordinate is outside the shape.