From d9832544ce846de33942f4832835586800676648 Mon Sep 17 00:00:00 2001 From: Justin Aquadro Date: Tue, 21 Feb 2012 00:57:19 -0500 Subject: [PATCH] Small bit of Anvil support. --- SubstrateCS/Source/Core/NibbleArray.cs | 69 ++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/SubstrateCS/Source/Core/NibbleArray.cs b/SubstrateCS/Source/Core/NibbleArray.cs index aebc206..4f41f22 100644 --- a/SubstrateCS/Source/Core/NibbleArray.cs +++ b/SubstrateCS/Source/Core/NibbleArray.cs @@ -151,4 +151,73 @@ namespace Substrate.Core #endregion } + + public sealed class YZXNibbleArray : NibbleArray + { + private readonly int _xdim; + private readonly int _ydim; + private readonly int _zdim; + + public YZXNibbleArray (int xdim, int ydim, int zdim) + : base(xdim * ydim * zdim) + { + _xdim = xdim; + _ydim = ydim; + _zdim = zdim; + } + + public YZXNibbleArray (int xdim, int ydim, int zdim, byte[] data) + : base(data) + { + _xdim = xdim; + _ydim = ydim; + _zdim = zdim; + + if (xdim * ydim * zdim != data.Length * 2) { + throw new ArgumentException("Product of dimensions must equal half length of raw data"); + } + } + + public byte this[int x, int y, int z] + { + get + { + int index = _xdim * (y * _zdim + z) + x; + return this[index]; + } + + set + { + int index = _xdim * (y * _zdim + z) + x; + this[index] = value; + } + } + + public int XDim + { + get { return _xdim; } + } + + public int YDim + { + get { return _ydim; } + } + + public int ZDim + { + get { return _zdim; } + } + + #region ICopyable Members + + public override NibbleArray Copy () + { + byte[] data = new byte[Data.Length]; + Data.CopyTo(data, 0); + + return new YZXNibbleArray(_xdim, _ydim, _zdim, data); + } + + #endregion + } }