< Summary

Information
Class: SwiftCollections.Dimensions.SwiftBoolArray2D
Assembly: SwiftCollections
File(s): /home/runner/work/SwiftCollections/SwiftCollections/src/SwiftCollections/Dimension/Default/SwiftBoolArray2D.cs
Line coverage
100%
Covered lines: 16
Uncovered lines: 0
Coverable lines: 16
Total lines: 104
Line coverage: 100%
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%11100%
.ctor(...)100%11100%
.ctor(...)100%11100%
.ctor(...)100%11100%
.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
 1//=======================================================================
 2// SwiftBoolArray2D.cs
 3//=======================================================================
 4// MIT License, Copyright (c) 2024-present David Oravsky (mrdav30)
 5// See LICENSE file in the project root for full license information.
 6//=======================================================================
 7
 8using System;
 9using System.Text.Json.Serialization;
 10using Chronicler;
 11using Chronicler.Serialization;
 12using MemoryPack;
 13
 14namespace SwiftCollections.Dimensions;
 15
 16/// <summary>
 17/// Represents a 2D array specifically designed to handle boolean values.
 18/// </summary>
 19[Serializable]
 20[JsonConverter(typeof(StateJsonConverterFactory))]
 21[MemoryPackable]
 22public partial class SwiftBoolArray2D : SwiftArray2D<bool>, IStateBacked<Array2DState<bool>>
 23{
 24    #region Constructors
 25
 26    /// <summary>
 27    /// Initializes a new instance of the SwiftBoolArray2D class.
 28    /// </summary>
 229    public SwiftBoolArray2D() { }
 30
 31    /// <summary>
 32    /// Initializes a new instance of the SwiftBoolArray2D class with the specified dimensions.
 33    /// </summary>
 34    /// <param name="width">The number of columns in the two-dimensional array. Must be greater than zero.</param>
 35    /// <param name="height">The number of rows in the two-dimensional array. Must be greater than zero.</param>
 436    public SwiftBoolArray2D(int width, int height) : base(width, height) { }
 37
 38    /// <summary>
 39    /// Initializes a new instance of the SwiftBoolArray2D class with the specified dimensions and default value.
 40    /// </summary>
 41    /// <param name="width">The number of columns in the two-dimensional array. Must be greater than zero.</param>
 42    /// <param name="height">The number of rows in the two-dimensional array. Must be greater than zero.</param>
 43    /// <param name="defaultValue">The initial boolean value assigned to each element in the array.</param>
 1244    public SwiftBoolArray2D(int width, int height, bool defaultValue) : base(width, height, defaultValue) { }
 45
 46    /// <summary>
 47    /// Initializes a new instance of the SwiftBoolArray2D class using the specified two-dimensional Boolean array as th
 48    /// </summary>
 49    /// <param name="source">A two-dimensional array of Boolean values to initialize the array with. Cannot be null.</pa
 250    public SwiftBoolArray2D(bool[,] source) : base(source) { }
 51
 52    /// <summary>
 53    /// Initializes a new instance of the SwiftBoolArray2D class using the specified array state.
 54    /// </summary>
 55    /// <param name="state">The state object containing the two-dimensional array data and configuration to initialize t
 56    [MemoryPackConstructor]
 457    public SwiftBoolArray2D(Array2DState<bool> state) : base(state) { }
 58
 59    #endregion
 60
 61    #region Collection Management
 62
 63    /// <summary>
 64    /// Toggles the value at the specified position in the array.
 65    /// </summary>
 66    public void Toggle(int x, int y)
 67    {
 100000268        this[x, y] = !this[x, y];
 100000269    }
 70
 71    /// <summary>
 72    /// Sets all values within a rectangular region to the specified value.
 73    /// </summary>
 74    public void SetRegion(int xStart, int yStart, int width, int height, bool value)
 75    {
 2876        for (int x = xStart; x < xStart + width; x++)
 77        {
 10878            for (int y = yStart; y < yStart + height; y++)
 79            {
 4380                if (IsValidIndex(x, y))
 2281                    this[x, y] = value;
 82            }
 83        }
 384    }
 85
 86    #endregion
 87
 88    #region Utility Methods
 89
 90    /// <summary>
 91    /// Counts the number of true values in the array.
 92    /// </summary>
 93    public int CountTrue()
 94    {
 695        int count = 0;
 200019496        foreach (var cell in InnerArray)
 97        {
 200011598            if (cell) count++;
 99        }
 6100        return count;
 101    }
 102
 103    #endregion
 104}