< Summary

Information
Class: SwiftCollections.Array2DState<T>
Assembly: SwiftCollections
File(s): /home/runner/work/SwiftCollections/SwiftCollections/src/SwiftCollections/Serialization/State/Array2DState.cs
Line coverage
100%
Covered lines: 4
Uncovered lines: 0
Coverable lines: 4
Total lines: 65
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%

File(s)

/home/runner/work/SwiftCollections/SwiftCollections/src/SwiftCollections/Serialization/State/Array2DState.cs

#LineLine coverage
 1//=======================================================================
 2// Array2DState.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 MemoryPack;
 9using System;
 10using System.Text.Json.Serialization;
 11
 12namespace SwiftCollections;
 13
 14/// <summary>
 15/// Represents the immutable state of a two-dimensional array, including its dimensions and underlying data.
 16/// </summary>
 17/// <remarks>
 18/// This struct is intended for scenarios where a snapshot of a 2D array's state is needed, such as
 19/// serialization or state management. The data is stored in a one-dimensional array in row-major order. The struct is
 20/// serializable and compatible with supported serialization frameworks.
 21/// </remarks>
 22/// <typeparam name="T">The type of elements stored in the array.</typeparam>
 23[Serializable]
 24[MemoryPackable]
 25public readonly partial struct Array2DState<T>
 26{
 27    /// <summary>
 28    /// Gets the width value represented by this field.
 29    /// </summary>
 30    [JsonInclude]
 31    [MemoryPackInclude]
 32    public readonly int Width;
 33
 34    /// <summary>
 35    /// Gets the height value represented by this field.
 36    /// </summary>
 37    [JsonInclude]
 38    [MemoryPackInclude]
 39    public readonly int Height;
 40
 41    /// <summary>
 42    /// Gets the underlying array of data elements contained in the collection.
 43    /// </summary>
 44    [JsonInclude]
 45    [MemoryPackInclude]
 46    public readonly T[] Data;
 47
 48    /// <summary>
 49    /// Initializes a new instance of the Array2DState class with the specified dimensions and data array.
 50    /// </summary>
 51    /// <param name="width">The number of columns in the two-dimensional array. Must be greater than zero.</param>
 52    /// <param name="height">The number of rows in the two-dimensional array. Must be greater than zero.</param>
 53    /// <param name="data">
 54    /// The one-dimensional array containing the elements of the two-dimensional array, stored in row-major order.
 55    /// The length must be equal to width multiplied by height.
 56    /// </param>
 57    [JsonConstructor]
 58    [MemoryPackConstructor]
 59    public Array2DState(int width, int height, T[] data)
 60    {
 1461        Width = width;
 1462        Height = height;
 1463        Data = data;
 1464    }
 65}