< Summary

Class:GDX.Collections.Generic.Array3D[T]
Assembly:GDX
File(s):./Packages/com.dotbunny.gdx/GDX/Collections/Generic/Array3D.cs
Covered lines:18
Uncovered lines:6
Coverable lines:24
Total lines:119
Line coverage:75% (18 of 24)
Covered branches:0
Total branches:0
Covered methods:6
Total methods:8
Method coverage:75% (6 of 8)

Coverage History

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Array3D(...)0%110100%
Dispose()0%2100%
GetFromIndex(...)0%110100%
GetFromIndex(...)0%2100%

File(s)

./Packages/com.dotbunny.gdx/GDX/Collections/Generic/Array3D.cs

#LineLine coverage
 1// Copyright (c) 2020-2024 dotBunny Inc.
 2// dotBunny licenses this file to you under the BSL-1.0 license.
 3// See the LICENSE file in the project root for more information.
 4
 5using System;
 6using System.Runtime.CompilerServices;
 7using Unity.Mathematics;
 8
 9namespace GDX.Collections.Generic
 10{
 11    /// <summary>
 12    ///     A three-dimensional array backed a flat array.
 13    /// </summary>
 14    /// <typeparam name="T">Type of objects.</typeparam>
 15    public struct Array3D<T> : IDisposable
 16    {
 17        /// <summary>
 18        ///     The backing flat array.
 19        /// </summary>
 20        public T[] Array;
 21
 22        /// <summary>
 23        ///     The stride of the z-axis segment in <see cref="Array" />.
 24        /// </summary>
 25        public readonly int Depth;
 26
 27        /// <summary>
 28        ///     The total length of a single <see cref="Depth" />.
 29        /// </summary>
 30        public readonly int DepthLength;
 31
 32        /// <summary>
 33        ///     The stride of the y-axis segment in <see cref="Array" />.
 34        /// </summary>
 35        public readonly int Height;
 36
 37        /// <summary>
 38        ///     The length of <see cref="Array" />.
 39        /// </summary>
 40        public readonly int Length;
 41
 42        /// <summary>
 43        ///     The stride of the x-axis segment in <see cref="Array" />.
 44        /// </summary>
 45        public readonly int Width;
 46
 47        /// <summary>
 48        ///     Create a <see cref="Array3D{T}" /> with a uniform dimensional length.
 49        /// </summary>
 50        /// <remarks></remarks>
 51        /// <param name="width">X-axis length.</param>
 52        /// <param name="height">Y-axis length.</param>
 53        /// <param name="depth">Z-axis length.</param>
 54        public Array3D(int width, int height, int depth)
 1055        {
 1056            Width = width;
 1057            Height = height;
 1058            DepthLength = width * height;
 1059            Depth = depth;
 1060            Length = width * height * depth;
 1061            Array = new T[Length];
 1062        }
 63
 64        /// <summary>
 65        ///     Access a specific location in the voxel.
 66        /// </summary>
 67        /// <param name="x">X location index.</param>
 68        /// <param name="y">Y location index.</param>
 69        /// <param name="z">Z location index.</param>
 70        public T this[int x, int y, int z]
 71        {
 72            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 173            get => Array[x + Width * (y + Height * z)];
 74
 75            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 176            set => Array[x + Width * (y + Height * z)] = value;
 77        }
 78
 79        /// <summary>
 80        ///     Access a specific location in the voxel.
 81        /// </summary>
 82        /// <param name="index">A three-dimensional index.</param>
 83        public T this[int3 index]
 84        {
 85            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 186            get => Array[index.x + Width * (index.y + Height * index.z)];
 87
 88            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 189            set => Array[index.x + Width * (index.y + Height * index.z)] = value;
 90        }
 91
 92        /// <summary>
 93        ///     Properly dispose of the <see cref="Array3D{T}" />.
 94        /// </summary>
 95        public void Dispose()
 096        {
 097            Array = default;
 098        }
 99
 100        /// <summary>
 101        ///     Get the three-dimensional index of a flat array index.
 102        /// </summary>
 103        /// <param name="index">A flat array index.</param>
 104        /// <returns>A three-dimensional voxel index.</returns>
 105        public int3 GetFromIndex(int index)
 5106        {
 5107            int x = index % Width;
 5108            int y = (index - x) / Width % Height;
 5109            int z = index / DepthLength;
 110
 5111            return new int3(x, y, z);
 5112        }
 113
 114        public int GetFromIndex(int3 index)
 0115        {
 0116            return index.x + Width * (index.y + Height * index.z);
 0117        }
 118    }
 119}

Coverage by test methods












Methods/Properties

Array3D(System.Int32, System.Int32, System.Int32)
Item(System.Int32, System.Int32, System.Int32)
Item(System.Int32, System.Int32, System.Int32, T)
Item(Unity.Mathematics.int3)
Item(Unity.Mathematics.int3, T)
Dispose()
GetFromIndex(System.Int32)
GetFromIndex(Unity.Mathematics.int3)