< Summary

Information
Class: SwiftCollections.Dimensions.SwiftBoolArray2D
Assembly: SwiftCollections
File(s): /home/runner/work/SwiftCollections/SwiftCollections/src/SwiftCollections/Dimension/Default/SwiftBoolArray2D.cs
Line coverage
87%
Covered lines: 14
Uncovered lines: 2
Coverable lines: 16
Total lines: 96
Line coverage: 87.5%
Branch coverage
100%
Covered branches: 10
Total branches: 10
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor()100%210%
.ctor(...)100%11100%
.ctor(...)100%11100%
.ctor(...)100%210%
.ctor(...)100%11100%
Toggle(...)100%11100%
SetRegion(...)100%66100%
CountTrue()100%44100%

File(s)

/home/runner/work/SwiftCollections/SwiftCollections/src/SwiftCollections/Dimension/Default/SwiftBoolArray2D.cs

#LineLine coverage
 1using Chronicler;
 2using MemoryPack;
 3using System;
 4using System.Text.Json.Serialization;
 5
 6namespace SwiftCollections.Dimensions;
 7
 8/// <summary>
 9/// Represents a 2D array specifically designed to handle boolean values.
 10/// </summary>
 11[Serializable]
 12[JsonConverter(typeof(StateJsonConverterFactory))]
 13[MemoryPackable]
 14public partial class SwiftBoolArray2D : SwiftArray2D<bool>, IStateBacked<Array2DState<bool>>
 15{
 16    #region Constructors
 17
 18    /// <summary>
 19    /// Initializes a new instance of the SwiftBoolArray2D class.
 20    /// </summary>
 021    public SwiftBoolArray2D() { }
 22
 23    /// <summary>
 24    /// Initializes a new instance of the SwiftBoolArray2D class with the specified dimensions.
 25    /// </summary>
 26    /// <param name="width">The number of columns in the two-dimensional array. Must be greater than zero.</param>
 27    /// <param name="height">The number of rows in the two-dimensional array. Must be greater than zero.</param>
 428    public SwiftBoolArray2D(int width, int height) : base(width, height) { }
 29
 30    /// <summary>
 31    /// Initializes a new instance of the SwiftBoolArray2D class with the specified dimensions and default value.
 32    /// </summary>
 33    /// <param name="width">The number of columns in the two-dimensional array. Must be greater than zero.</param>
 34    /// <param name="height">The number of rows in the two-dimensional array. Must be greater than zero.</param>
 35    /// <param name="defaultValue">The initial boolean value assigned to each element in the array.</param>
 1236    public SwiftBoolArray2D(int width, int height, bool defaultValue) : base(width, height, defaultValue) { }
 37
 38    /// <summary>
 39    /// Initializes a new instance of the SwiftBoolArray2D class using the specified two-dimensional Boolean array as th
 40    /// </summary>
 41    /// <param name="source">A two-dimensional array of Boolean values to initialize the array with. Cannot be null.</pa
 042    public SwiftBoolArray2D(bool[,] source) : base(source) { }
 43
 44    /// <summary>
 45    /// Initializes a new instance of the SwiftBoolArray2D class using the specified array state.
 46    /// </summary>
 47    /// <param name="state">The state object containing the two-dimensional array data and configuration to initialize t
 48    [MemoryPackConstructor]
 449    public SwiftBoolArray2D(Array2DState<bool> state) : base(state) { }
 50
 51    #endregion
 52
 53    #region Collection Management
 54
 55    /// <summary>
 56    /// Toggles the value at the specified position in the array.
 57    /// </summary>
 58    public void Toggle(int x, int y)
 59    {
 100000260        this[x, y] = !this[x, y];
 100000261    }
 62
 63    /// <summary>
 64    /// Sets all values within a rectangular region to the specified value.
 65    /// </summary>
 66    public void SetRegion(int xStart, int yStart, int width, int height, bool value)
 67    {
 2868        for (int x = xStart; x < xStart + width; x++)
 69        {
 10870            for (int y = yStart; y < yStart + height; y++)
 71            {
 4372                if (IsValidIndex(x, y))
 2273                    this[x, y] = value;
 74            }
 75        }
 376    }
 77
 78    #endregion
 79
 80    #region Utility Methods
 81
 82    /// <summary>
 83    /// Counts the number of true values in the array.
 84    /// </summary>
 85    public int CountTrue()
 86    {
 587        int count = 0;
 200019288        foreach (var cell in InnerArray)
 89        {
 200011590            if (cell) count++;
 91        }
 592        return count;
 93    }
 94
 95    #endregion
 96}