Ejemplo n.º 1
0
 private void UpdateRanges(CubeKey key)
 {
     for (var i = 0; i < Dim; ++i)
     {
         UpdateRange(key.Dims[i], Bounds[i]);
     }
 }
        public static List <CubeKey> GenerateKeysToCheck(Cube input, CubeKey dims)
        {
            var keysToCheck = new List <CubeKey>();

            Check(new List <long>(), ref keysToCheck, 0, dims);
            keysToCheck = keysToCheck.Where(x => !dims.Dims.SequenceEqual(x.Dims)).ToList();
            var result = new List <CubeKey>();

            foreach (var k in keysToCheck)
            {
                var flag = true;
                for (var i = 0; i < dims.Dims.Count; ++i)
                {
                    if (k.Dims[i] > input.Bounds[i].Max || k.Dims[i] < input.Bounds[i].Min)
                    {
                        flag = false;
                        break;
                    }
                }
                if (flag)
                {
                    result.Add(k);
                }
            }

            return(result);
        }
Ejemplo n.º 3
0
        public CellState?GetValue(CubeKey key)
        {
            var str = key.ToString();

            if (Cells.ContainsKey(key.ToString()))
            {
                return(Cells[str]);
            }

            return(CellState.Inactive);
        }
Ejemplo n.º 4
0
        public long Check(Cube input, CubeKey dims)
        {
            var result = 0;

            var keysToCheck = CubeAnalyzer.GenerateKeysToCheck(input, dims);

            foreach (var key in keysToCheck)
            {
                var value = input.GetValue(key);
                if (value == CellState.Active)
                {
                    result++;
                }
            }

            return(result);
        }
Ejemplo n.º 5
0
 public void SetCell(CellState value, CubeKey dims)
 {
     Cells[dims.ToString()] = value;
     UpdateRanges(dims);
 }
 private static void Check(List <long> input, ref List <CubeKey> output, int idx, CubeKey dims)
 {
     if (idx == dims.Dims.Count)
     {
         output.Add(new CubeKey(input.ToArray()));
         return;
     }
     for (var i = -1; i <= 1; ++i)
     {
         var copy = new List <long>(input)
         {
             dims.Dims[idx] + i
         };
         Check(copy, ref output, idx + 1, dims);
     }
 }