< Summary

Information
Class: SwiftCollections.Dimensions.SwiftShortArray2D
Assembly: SwiftCollections
File(s): /home/runner/work/SwiftCollections/SwiftCollections/src/SwiftCollections/Dimension/Default/SwiftShortArray2D.cs
Line coverage
93%
Covered lines: 15
Uncovered lines: 1
Coverable lines: 16
Total lines: 86
Line coverage: 93.7%
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%11100%
.ctor(...)100%11100%
Scale(...)100%22100%
Normalize(...)100%88100%

File(s)

/home/runner/work/SwiftCollections/SwiftCollections/src/SwiftCollections/Dimension/Default/SwiftShortArray2D.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 short integer values.
 10/// </summary>
 11[Serializable]
 12[JsonConverter(typeof(StateJsonConverterFactory))]
 13[MemoryPackable]
 14public partial class SwiftShortArray2D : SwiftArray2D<short>, IStateBacked<Array2DState<short>>
 15{
 16    #region Constructors
 17
 18    /// <summary>
 19    /// Initializes a new instance of the SwiftShortArray2D class.
 20    /// </summary>
 021    public SwiftShortArray2D() { }
 22
 23    /// <summary>
 24    /// Initializes a new instance of the SwiftShortArray2D 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>
 228    public SwiftShortArray2D(int width, int height) : base(width, height) { }
 29
 30    /// <summary>
 31    /// Initializes a new instance of the SwiftShortArray2D 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 value to assign to each element in the array upon initialization.</param>
 836    public SwiftShortArray2D(int width, int height, short defaultValue) : base(width, height, defaultValue) { }
 37
 38    /// <summary>
 39    /// Initializes a new instance of the SwiftShortArray2D class using the specified two-dimensional array of short
 40    /// values.
 41    /// </summary>
 42    /// <param name="source">A two-dimensional array of short values that provides the initial data for the array.</para
 443    public SwiftShortArray2D(short[,] source) : base(source) { }
 44
 45    /// <summary>
 46    /// Initializes a new instance of the SwiftShortArray2D class using the specified array state.
 47    /// </summary>
 48    /// <param name="state">The state object that provides the initial data and configuration for the two-dimensional sh
 49    [MemoryPackConstructor]
 450    public SwiftShortArray2D(Array2DState<short> state) : base(state) { }
 51
 52    #endregion
 53
 54    #region Collection Management
 55
 56    /// <summary>
 57    /// Scales all elements in the array by the specified factor.
 58    /// </summary>
 59    public void Scale(short factor)
 60    {
 3061        for (int i = 0; i < InnerArray.Length; i++)
 1362            InnerArray[i] = (short)(InnerArray[i] * factor);
 263    }
 64
 65    /// <summary>
 66    /// Normalizes all elements in the array to a specified range.
 67    /// </summary>
 68    public void Normalize(short min, short max)
 69    {
 370        short currentMin = short.MaxValue;
 371        short currentMax = short.MinValue;
 72
 73        // Find current min and max
 4074        foreach (var value in InnerArray)
 75        {
 2076            if (value < currentMin) currentMin = value;
 2677            if (value > currentMax) currentMax = value;
 78        }
 79
 80        // Normalize values
 4081        for (int i = 0; i < InnerArray.Length; i++)
 1782            InnerArray[i] = (short)(((InnerArray[i] - currentMin) / (float)(currentMax - currentMin)) * (max - min) + mi
 383    }
 84
 85    #endregion
 86}