< Summary

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

File(s)

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

#LineLine coverage
 1//=======================================================================
 2// SwiftShortArray2D.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 short integer values.
 17/// </summary>
 18[Serializable]
 19[JsonConverter(typeof(StateJsonConverterFactory))]
 20[MemoryPackable]
 21public partial class SwiftShortArray2D : SwiftArray2D<short>, IStateBacked<Array2DState<short>>
 22{
 23    #region Constructors
 24
 25    /// <summary>
 26    /// Initializes a new instance of the SwiftShortArray2D class.
 27    /// </summary>
 228    public SwiftShortArray2D() { }
 29
 30    /// <summary>
 31    /// Initializes a new instance of the SwiftShortArray2D 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>
 235    public SwiftShortArray2D(int width, int height) : base(width, height) { }
 36
 37    /// <summary>
 38    /// Initializes a new instance of the SwiftShortArray2D 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 value to assign to each element in the array upon initialization.</param>
 843    public SwiftShortArray2D(int width, int height, short defaultValue) : base(width, height, defaultValue) { }
 44
 45    /// <summary>
 46    /// Initializes a new instance of the SwiftShortArray2D class using the specified two-dimensional array of short
 47    /// values.
 48    /// </summary>
 49    /// <param name="source">A two-dimensional array of short values that provides the initial data for the array.</para
 450    public SwiftShortArray2D(short[,] source) : base(source) { }
 51
 52    /// <summary>
 53    /// Initializes a new instance of the SwiftShortArray2D class using the specified array state.
 54    /// </summary>
 55    /// <param name="state">The state object that provides the initial data and configuration for the two-dimensional sh
 56    [MemoryPackConstructor]
 457    public SwiftShortArray2D(Array2DState<short> state) : base(state) { }
 58
 59    #endregion
 60
 61    #region Collection Management
 62
 63    /// <summary>
 64    /// Scales all elements in the array by the specified factor.
 65    /// </summary>
 66    public void Scale(short factor)
 67    {
 3068        for (int i = 0; i < InnerArray.Length; i++)
 1369            InnerArray[i] = (short)(InnerArray[i] * factor);
 270    }
 71
 72    /// <summary>
 73    /// Normalizes all elements in the array to a specified range.
 74    /// </summary>
 75    public void Normalize(short min, short max)
 76    {
 377        short currentMin = short.MaxValue;
 378        short currentMax = short.MinValue;
 79
 80        // Find current min and max
 4081        foreach (var value in InnerArray)
 82        {
 2083            if (value < currentMin) currentMin = value;
 2684            if (value > currentMax) currentMax = value;
 85        }
 86
 87        // Normalize values
 4088        for (int i = 0; i < InnerArray.Length; i++)
 1789            InnerArray[i] = (short)(((InnerArray[i] - currentMin) / (float)(currentMax - currentMin)) * (max - min) + mi
 390    }
 91
 92    #endregion
 93}