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<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
stateArray2DState<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
sourcebool[,]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
widthintThe requested width in cells; negative values are clamped to zero.
heightintThe 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
widthintThe requested width in cells; negative values are clamped to zero.
heightintThe requested height in cells; negative values are clamped to zero.
defaultValueboolThe 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
xStartintThe inclusive starting X coordinate in cells; out-of-bounds cells are skipped.
yStartintThe inclusive starting Y coordinate in cells; out-of-bounds cells are skipped.
widthintThe number of X cells to visit; non-positive widths visit no cells.
heightintThe number of Y cells to visit; non-positive heights visit no cells.
valueboolThe 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
xintThe zero-based X coordinate; valid from zero through the corresponding dimension minus one.
yintThe zero-based Y coordinate; valid from zero through the corresponding dimension minus one.
Exceptions
- IndexOutOfRangeException
The cell coordinate is outside the shape.