< Summary

Class:GDX.Collections.Generic.NativeUniformArray3D[T]
Assembly:GDX
File(s):./Packages/com.dotbunny.gdx/GDX/Collections/Generic/NativeUniformArray3D.cs
Covered lines:12
Uncovered lines:11
Coverable lines:23
Total lines:111
Line coverage:52.1% (12 of 23)
Covered branches:0
Total branches:0
Covered methods:3
Total methods:7
Method coverage:42.8% (3 of 7)

Coverage History

Metrics

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

File(s)

./Packages/com.dotbunny.gdx/GDX/Collections/Generic/NativeUniformArray3D.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 NativeUniformArray3D<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 length of <see cref="Array" />.
 25        /// </summary>
 26        public readonly int Length;
 27
 28        /// <summary>
 29        ///     The stride of each dimensional segment in <see cref="Array" />.
 30        /// </summary>
 31        public readonly int Stride;
 32
 33        /// <summary>
 34        ///     Stores a cached copy of the stride squared.
 35        /// </summary>
 36        public readonly int StrideSquared;
 37
 38        /// <summary>
 39        ///     Create a <see cref="NativeUniformArray3D{T}" /> with a uniform dimensional length.
 40        /// </summary>
 41        /// <remarks></remarks>
 42        /// <param name="stride">X length, Y length and Z length will all be set to this value.</param>
 43        /// <param name="allocator">The <see cref="Unity.Collections.Allocator" /> type to use.</param>
 44        /// <param name="nativeArrayOptions">Should the memory be cleared on allocation?</param>
 45        public NativeUniformArray3D(int stride, Allocator allocator, NativeArrayOptions nativeArrayOptions)
 246        {
 247            Stride = stride;
 248            StrideSquared = stride * stride;
 249            Length = StrideSquared * stride;
 50
 251            Array = new NativeArray<T>(Length, allocator, nativeArrayOptions);
 252        }
 53
 54        /// <summary>
 55        ///     Access a specific location in the voxel.
 56        /// </summary>
 57        /// <param name="x">X location index.</param>
 58        /// <param name="y">Y location index.</param>
 59        /// <param name="z">Z location index.</param>
 60        public T this[int x, int y, int z]
 61        {
 62            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 163            get => Array[z * StrideSquared + y * Stride + x];
 64
 65            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 066            set => Array[z * StrideSquared + y * Stride + x] = value;
 67        }
 68
 69
 70        /// <summary>
 71        ///     Access a specific location in the voxel.
 72        /// </summary>
 73        /// <param name="index">A 3-Dimensional index.</param>
 74        public T this[int3 index]
 75        {
 76            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 077            get => Array[index.z * StrideSquared + index.y * Stride + index.x];
 78
 79            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 080            set => Array[index.z * StrideSquared + index.y * Stride + index.x] = value;
 81        }
 82
 83
 84        /// <summary>
 85        ///     Properly dispose of the <see cref="NativeUniformArray3D{T}" />.
 86        /// </summary>
 87        public void Dispose()
 288        {
 289            if (!Array.IsCreated)
 090            {
 091                return;
 92            }
 93
 294            Array.Dispose();
 295            Array = default;
 296        }
 97
 98        /// <summary>
 99        ///     Get the three-dimensional index of a flat array index.
 100        /// </summary>
 101        /// <param name="index">A flat array index.</param>
 102        /// <returns>A three-dimensional voxel index.</returns>
 103        public int3 GetFromIndex(int index)
 0104        {
 0105            int x = index % Stride;
 0106            int y = (index - x) / Stride % Stride;
 0107            int z = (index - x - Stride * y) / StrideSquared;
 0108            return new int3(x, y, z);
 0109        }
 110    }
 111}

Coverage by test methods




Methods/Properties

NativeUniformArray3D(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)