< Summary

Class:GDX.Collections.Generic.NativeArray3D[T]
Assembly:GDX
File(s):D:/BuildAgent/work/GDX-Documentation/Projects/GDX_Development/Packages/com.dotbunny.gdx/GDX/Collections/Generic/NativeArray3D.cs
Covered lines:23
Uncovered lines:5
Coverable lines:28
Total lines:129
Line coverage:82.1% (23 of 28)
Covered branches:0
Total branches:0
Covered methods:7
Total methods:8
Method coverage:87.5% (7 of 8)

Coverage History

Metrics

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

File(s)

D:/BuildAgent/work/GDX-Documentation/Projects/GDX_Development/Packages/com.dotbunny.gdx/GDX/Collections/Generic/NativeArray3D.cs

#LineLine coverage
 1// Copyright (c) 2020-2022 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.Collections;
 8using Unity.Mathematics;
 9
 10namespace GDX.Collections.Generic
 11{
 12    /// <summary>
 13    ///     A three-dimensional <see cref="NativeArray{T}" /> backed array.
 14    /// </summary>
 15    /// <typeparam name="T">Type of objects.</typeparam>
 16    public struct NativeArray3D<T> : IDisposable where T : struct
 17    {
 18        /// <summary>
 19        ///     The backing <see cref="NativeArray{T}" />.
 20        /// </summary>
 21        public NativeArray<T> Array;
 22
 23        /// <summary>
 24        ///     The stride of the z-axis segment in <see cref="Array" />.
 25        /// </summary>
 26        public readonly int Depth;
 27
 28        /// <summary>
 29        ///     The total length of a single <see cref="Depth"/>.
 30        /// </summary>
 31        public readonly int DepthLength;
 32
 33        /// <summary>
 34        ///     The stride of the y-axis segment in <see cref="Array" />.
 35        /// </summary>
 36        public readonly int Height;
 37
 38        /// <summary>
 39        ///     The length of <see cref="Array" />.
 40        /// </summary>
 41        public readonly int Length;
 42
 43        /// <summary>
 44        ///     The stride of the x-axis segment in <see cref="Array" />.
 45        /// </summary>
 46        public readonly int Width;
 47
 48        /// <summary>
 49        ///     Create a <see cref="NativeArray3D{T}" /> with a uniform dimensional length.
 50        /// </summary>
 51        /// <remarks></remarks>
 52        /// <param name="width">X-axis length.</param>
 53        /// <param name="height">Y-axis length.</param>
 54        /// <param name="depth">Z-axis length.</param>
 55        /// <param name="allocator">The <see cref="Unity.Collections.Allocator" /> type to use.</param>
 56        /// <param name="nativeArrayOptions">Should the memory be cleared on allocation?</param>
 57        public NativeArray3D(int width, int height, int depth, Allocator allocator, NativeArrayOptions nativeArrayOption
 1058        {
 1059            Width = width;
 1060            Height = height;
 1061            DepthLength = width * height;
 1062            Depth = depth;
 1063            Length = width * height * depth;
 1064            Array = new NativeArray<T>(Length, allocator, nativeArrayOptions);
 1065        }
 66
 67        /// <summary>
 68        ///     Access a specific location in the voxel.
 69        /// </summary>
 70        /// <param name="x">X location index.</param>
 71        /// <param name="y">Y location index.</param>
 72        /// <param name="z">Z location index.</param>
 73        public T this[int x, int y, int z]
 74        {
 75            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 176            get => Array[x + Width * (y + Height * z)];
 77
 78            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 179            set => Array[x + Width * (y + Height * z)] = value;
 80        }
 81
 82        /// <summary>
 83        ///     Access a specific location in the voxel.
 84        /// </summary>
 85        /// <param name="index">A three-dimensional index.</param>
 86        public T this[int3 index]
 87        {
 88            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 189            get => Array[index.x + Width * (index.y + Height * index.z)];
 90
 91            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 192            set => Array[index.x + Width * (index.y + Height * index.z)] = value;
 93        }
 94
 95
 96        /// <summary>
 97        ///     Properly dispose of the <see cref="NativeUniformArray3D{T}" />.
 98        /// </summary>
 99        public void Dispose()
 10100        {
 10101            if (!Array.IsCreated)
 0102            {
 0103                return;
 104            }
 105
 10106            Array.Dispose();
 10107            Array = default;
 10108        }
 109
 110        /// <summary>
 111        ///     Get the three-dimensional index of a flat array index.
 112        /// </summary>
 113        /// <param name="index">A flat array index.</param>
 114        /// <returns>A three-dimensional voxel index.</returns>
 115        public int3 GetFromIndex(int index)
 5116        {
 5117            int x = index % Width;
 5118            int y =  (index - x) / Width % Height;
 5119            int z = index / (DepthLength);
 120
 5121            return new int3(x, y, z);
 5122        }
 123
 124        public int GetFromIndex(int3 index)
 0125        {
 0126            return index.x + Width * (index.y + Height * index.z);
 0127        }
 128    }
 129}