From 81920ef73d41f44e834b624ae4dddc65f1490165 Mon Sep 17 00:00:00 2001 From: Justin Aquadro Date: Sun, 9 Sep 2012 14:36:38 -0400 Subject: [PATCH] Fixed index calculation bug in Anvil composite arrays. --- SubstrateCS/Source/Core/CompositeByteArray.cs | 3 ++- SubstrateCS/Source/Core/CompositeNibbleArray.cs | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/SubstrateCS/Source/Core/CompositeByteArray.cs b/SubstrateCS/Source/Core/CompositeByteArray.cs index 3a82b1b..1399ed3 100644 --- a/SubstrateCS/Source/Core/CompositeByteArray.cs +++ b/SubstrateCS/Source/Core/CompositeByteArray.cs @@ -63,7 +63,7 @@ namespace Substrate.Core { int ydiv = y / _sections[0].YDim; int yrem = y - (ydiv * _sections[0].YDim); - return ydiv * _sections[ydiv].GetIndex(x, yrem, z); + return (ydiv * _sections[0].Length) + _sections[ydiv].GetIndex(x, yrem, z); } public void GetMultiIndex (int index, out int x, out int y, out int z) @@ -71,6 +71,7 @@ namespace Substrate.Core int idiv = index / _sections[0].Length; int irem = index - (idiv * _sections[0].Length); _sections[idiv].GetMultiIndex(irem, out x, out y, out z); + y += idiv * _sections[0].YDim; } #endregion diff --git a/SubstrateCS/Source/Core/CompositeNibbleArray.cs b/SubstrateCS/Source/Core/CompositeNibbleArray.cs index 09bc6ea..ca160bb 100644 --- a/SubstrateCS/Source/Core/CompositeNibbleArray.cs +++ b/SubstrateCS/Source/Core/CompositeNibbleArray.cs @@ -63,7 +63,7 @@ namespace Substrate.Core { int ydiv = y / _sections[0].YDim; int yrem = y - (ydiv * _sections[0].YDim); - return ydiv * _sections[ydiv].GetIndex(x, yrem, z); + return (ydiv * _sections[0].Length) + _sections[ydiv].GetIndex(x, yrem, z); } public void GetMultiIndex (int index, out int x, out int y, out int z) @@ -71,6 +71,7 @@ namespace Substrate.Core int idiv = index / _sections[0].Length; int irem = index - (idiv * _sections[0].Length); _sections[idiv].GetMultiIndex(irem, out x, out y, out z); + y += idiv * _sections[0].YDim; } #endregion