< Summary

Class:GDX.Collections.Generic.NativeArray3D[T]
Assembly:GDX
File(s):./Packages/com.dotbunny.gdx/GDX/Collections/Generic/NativeArray3D.cs
Covered lines:23
Uncovered lines:5
Coverable lines:28
Total lines:130
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)

./Packages/com.dotbunny.gdx/GDX/Collections/Generic/NativeArray3D.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.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,
 58            NativeArrayOptions nativeArrayOptions)
 1059        {
 1060            Width = width;
 1061            Height = height;
 1062            DepthLength = width * height;
 1063            Depth = depth;
 1064            Length = width * height * depth;
 1065            Array = new NativeArray<T>(Length, allocator, nativeArrayOptions);
 1066        }
 67
 68        /// <summary>
 69        ///     Access a specific location in the voxel.
 70        /// </summary>
 71        /// <param name="x">X location index.</param>
 72        /// <param name="y">Y location index.</param>
 73        /// <param name="z">Z location index.</param>
 74        public T this[int x, int y, int z]
 75        {
 76            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 177            get => Array[x + Width * (y + Height * z)];
 78
 79            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 180            set => Array[x + Width * (y + Height * z)] = value;
 81        }
 82
 83        /// <summary>
 84        ///     Access a specific location in the voxel.
 85        /// </summary>
 86        /// <param name="index">A three-dimensional index.</param>
 87        public T this[int3 index]
 88        {
 89            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 190            get => Array[index.x + Width * (index.y + Height * index.z)];
 91
 92            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 193            set => Array[index.x + Width * (index.y + Height * index.z)] = value;
 94        }
 95
 96
 97        /// <summary>
 98        ///     Properly dispose of the <see cref="NativeUniformArray3D{T}" />.
 99        /// </summary>
 100        public void Dispose()
 10101        {
 10102            if (!Array.IsCreated)
 0103            {
 0104                return;
 105            }
 106
 10107            Array.Dispose();
 10108            Array = default;
 10109        }
 110
 111        /// <summary>
 112        ///     Get the three-dimensional index of a flat array index.
 113        /// </summary>
 114        /// <param name="index">A flat array index.</param>
 115        /// <returns>A three-dimensional voxel index.</returns>
 116        public int3 GetFromIndex(int index)
 5117        {
 5118            int x = index % Width;
 5119            int y = (index - x) / Width % Height;
 5120            int z = index / DepthLength;
 121
 5122            return new int3(x, y, z);
 5123        }
 124
 125        public int GetFromIndex(int3 index)
 0126        {
 0127            return index.x + Width * (index.y + Height * index.z);
 0128        }
 129    }
 130}

Coverage by test methods












Methods/Properties

NativeArray3D(System.Int32, System.Int32, System.Int32, Unity.Collections.Allocator, Unity.Collections.NativeArrayOptions)
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)