< 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: 103
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 Chronicler;
 9using MemoryPack;
 10using System;
 11using System.Text.Json.Serialization;
 12
 13namespace SwiftCollections.Dimensions;
 14
 15/// <summary>
 16/// Represents a 2D array specifically designed to handle boolean values.
 17/// </summary>
 18[Serializable]
 19[JsonConverter(typeof(StateJsonConverterFactory))]
 20[MemoryPackable]
 21public partial class SwiftBoolArray2D : SwiftArray2D<bool>, IStateBacked<Array2DState<bool>>
 22{
 23    #region Constructors
 24
 25    /// <summary>
 26    /// Initializes a new instance of the SwiftBoolArray2D class.
 27    /// </summary>
 228    public SwiftBoolArray2D() { }
 29
 30    /// <summary>
 31    /// Initializes a new instance of the SwiftBoolArray2D class with the specified dimensions.
 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>
 435    public SwiftBoolArray2D(int width, int height) : base(width, height) { }
 36
 37    /// <summary>
 38    /// Initializes a new instance of the SwiftBoolArray2D class with the specified dimensions and default value.
 39    /// </summary>
 40    /// <param name="width">The number of columns in the two-dimensional array. Must be greater than zero.</param>
 41    /// <param name="height">The number of rows in the two-dimensional array. Must be greater than zero.</param>
 42    /// <param name="defaultValue">The initial boolean value assigned to each element in the array.</param>
 1243    public SwiftBoolArray2D(int width, int height, bool defaultValue) : base(width, height, defaultValue) { }
 44
 45    /// <summary>
 46    /// Initializes a new instance of the SwiftBoolArray2D class using the specified two-dimensional Boolean array as th
 47    /// </summary>
 48    /// <param name="source">A two-dimensional array of Boolean values to initialize the array with. Cannot be null.</pa
 249    public SwiftBoolArray2D(bool[,] source) : base(source) { }
 50
 51    /// <summary>
 52    /// Initializes a new instance of the SwiftBoolArray2D class using the specified array state.
 53    /// </summary>
 54    /// <param name="state">The state object containing the two-dimensional array data and configuration to initialize t
 55    [MemoryPackConstructor]
 456    public SwiftBoolArray2D(Array2DState<bool> state) : base(state) { }
 57
 58    #endregion
 59
 60    #region Collection Management
 61
 62    /// <summary>
 63    /// Toggles the value at the specified position in the array.
 64    /// </summary>
 65    public void Toggle(int x, int y)
 66    {
 100000267        this[x, y] = !this[x, y];
 100000268    }
 69
 70    /// <summary>
 71    /// Sets all values within a rectangular region to the specified value.
 72    /// </summary>
 73    public void SetRegion(int xStart, int yStart, int width, int height, bool value)
 74    {
 2875        for (int x = xStart; x < xStart + width; x++)
 76        {
 10877            for (int y = yStart; y < yStart + height; y++)
 78            {
 4379                if (IsValidIndex(x, y))
 2280                    this[x, y] = value;
 81            }
 82        }
 383    }
 84
 85    #endregion
 86
 87    #region Utility Methods
 88
 89    /// <summary>
 90    /// Counts the number of true values in the array.
 91    /// </summary>
 92    public int CountTrue()
 93    {
 694        int count = 0;
 200019495        foreach (var cell in InnerArray)
 96        {
 200011597            if (cell) count++;
 98        }
 699        return count;
 100    }
 101
 102    #endregion
 103}