Exemplo n.º 1
0
        public void FromArrayAndBack()
        {
            var testId = new VoxelTypeID(5);

            var sourceArray = new VoxelTypeID[dimensions.x * dimensions.y * dimensions.z];

            Vector3Int[] testPositions = new Vector3Int[] {
                new Vector3Int(1, 2, 3),
                new Vector3Int(4, 5, 6),
                new Vector3Int(7, 8, 9),
                new Vector3Int(10, 11, 12),
                new Vector3Int(0, 0, 0),
                new Vector3Int(15, 15, 15),
            };

            //Initialise source array
            foreach (var item in testPositions)
            {
                var flat = MultiIndexToFlat(item.x, item.y, item.z, dimensions);
                sourceArray[flat] = testId;
            }

            rle = new RLEArray <VoxelTypeID>(dimensions.ToBasic(), sourceArray);

            var resultArray = rle.ToArray();

            for (int i = 0; i < sourceArray.Length; i++)
            {
                FlatIndexToMulti(i, dimensions, out var x, out var y, out var z);
                Assert.AreEqual(sourceArray[i], resultArray[i], $"Result array did not match source for coordinates {x},{y},{z}");
            }
        }
Exemplo n.º 2
0
        public void ToArray()
        {
            var testId = new VoxelTypeID(5);

            Vector3Int[] testPositions = new Vector3Int[] {
                new Vector3Int(1, 2, 3),
                new Vector3Int(4, 5, 6),
                new Vector3Int(7, 8, 9),
                new Vector3Int(10, 11, 12),
                new Vector3Int(0, 0, 0),
                new Vector3Int(15, 15, 15),
            };

            foreach (var item in testPositions)
            {
                rle.Set(MultiIndexToFlat(item.x, item.y, item.z, dimensions), testId);
            }

            var array = rle.ToArray();

            foreach (var item in testPositions)
            {
                var flat  = MultiIndexToFlat(item.x, item.y, item.z, dimensions);
                var value = array[flat];
                Assert.AreEqual(testId, value, $"Array index {item} was not correctly translated");
            }
        }