| | | 1 | | using MemoryPack; |
| | | 2 | | using System; |
| | | 3 | | using System.Text.Json.Serialization; |
| | | 4 | | |
| | | 5 | | namespace SwiftCollections; |
| | | 6 | | |
| | | 7 | | |
| | | 8 | | /// <summary> |
| | | 9 | | /// Represents the immutable state of a three-dimensional array, including its dimensions and underlying data. |
| | | 10 | | /// </summary> |
| | | 11 | | /// <remarks> |
| | | 12 | | /// This struct is intended for scenarios where a snapshot of a 3D array's state is needed, such as |
| | | 13 | | /// serialization or state management. The data is stored in a one-dimensional array in row-major order. The struct is |
| | | 14 | | /// serializable and compatible with supported serialization frameworks. |
| | | 15 | | /// </remarks> |
| | | 16 | | /// <typeparam name="T">The type of elements stored in the array.</typeparam> |
| | | 17 | | [Serializable] |
| | | 18 | | [MemoryPackable] |
| | | 19 | | public readonly partial struct Array3DState<T> |
| | | 20 | | { |
| | | 21 | | /// <summary> |
| | | 22 | | /// Gets the width value represented by this field. |
| | | 23 | | /// </summary> |
| | | 24 | | [JsonInclude] |
| | | 25 | | [MemoryPackInclude] |
| | | 26 | | public readonly int Width; |
| | | 27 | | |
| | | 28 | | /// <summary> |
| | | 29 | | /// Gets the height value represented by this field. |
| | | 30 | | /// </summary> |
| | | 31 | | [JsonInclude] |
| | | 32 | | [MemoryPackInclude] |
| | | 33 | | public readonly int Height; |
| | | 34 | | |
| | | 35 | | /// <summary> |
| | | 36 | | /// Gets the depth value represented by this field. |
| | | 37 | | /// </summary> |
| | | 38 | | [JsonInclude] |
| | | 39 | | [MemoryPackInclude] |
| | | 40 | | public readonly int Depth; |
| | | 41 | | |
| | | 42 | | /// <summary> |
| | | 43 | | /// Gets the underlying array of data elements contained in the collection. |
| | | 44 | | /// </summary> |
| | | 45 | | [JsonInclude] |
| | | 46 | | [MemoryPackInclude] |
| | | 47 | | public readonly T[] Data; |
| | | 48 | | |
| | | 49 | | /// <summary> |
| | | 50 | | /// Initializes a new instance of the Array3DState class with the specified dimensions and data. |
| | | 51 | | /// </summary> |
| | | 52 | | /// <param name="width">The number of elements along the X-axis. Must be greater than zero.</param> |
| | | 53 | | /// <param name="height">The number of elements along the Y-axis. Must be greater than zero.</param> |
| | | 54 | | /// <param name="depth">The number of elements along the Z-axis. Must be greater than zero.</param> |
| | | 55 | | /// <param name="data"> |
| | | 56 | | /// A one-dimensional array containing the elements of the 3D array, stored in row-major order. |
| | | 57 | | /// The length must equal width × height × depth. |
| | | 58 | | /// </param> |
| | | 59 | | [JsonConstructor] |
| | | 60 | | [MemoryPackConstructor] |
| | | 61 | | public Array3DState(int width, int height, int depth, T[] data) |
| | | 62 | | { |
| | 4 | 63 | | Width = width; |
| | 4 | 64 | | Height = height; |
| | 4 | 65 | | Depth = depth; |
| | 4 | 66 | | Data = data; |
| | 4 | 67 | | } |
| | | 68 | | } |