예제 #1
0
    public static int ReduceDims(int val, int target, int dims)
    {
        int result    = 0;
        int targetDim = 0;

        for (int dim = 0; dim < dims; dim++)
        {
            if (BitHelper.Get(target, dim))
            {
                result = BitHelper.Set(result, targetDim, BitHelper.Get(val, dim));
                targetDim++;
            }
        }
        return(result);
    }
예제 #2
0
    void proc(Cell[] cells, int dimensionMap, EdgeHandler handler, int level)
    {
        foreach (Cell cell in cells)
        {
            if (!cell.signed)
            {
                return;
            }
        }

        if (cells.Length == children.Length / 2) //only edges
        {
            if (level == maxLevel)
            {
                handler(cells, dimensionMap);
            }
        }

        foreach (Cell cell in cells)
        {
            if (cell.children == null)
            {
                return;
            }
        }

        //get "block"
        Cell[] block = new Cell[children.Length];
        for (int i = 0; i < block.Length; i++)
        {
            var cellToPickFrom = i & dimensionMap;
            var cellToPick     = i ^ dimensionMap;

            int actualCellToPickFrom = BitHelper.ReduceDims(cellToPickFrom, dimensionMap, Dimensions);

            block[i] = cells[actualCellToPickFrom].children[cellToPick];
        }

        for (int dimMap = 0; dimMap < children.Length - 1; dimMap++)
        {
            if ((dimMap & dimensionMap) != dimensionMap)
            {
                continue;
            }

            int activeDimensions = 0;
            for (int i = 0; i < Dimensions; i++)
            {
                if (BitHelper.Get(dimMap, i))
                {
                    activeDimensions++;
                }
            }

            for (int i = 0; i < children.Length; i++)
            {
                if ((dimMap & i) > 0)
                {
                    continue;
                }
                Cell[] pickedCells = new Cell[(int)Math.Pow(2, activeDimensions)];
                for (int j = 0; j < children.Length; j++)
                {
                    if ((~dimMap & j) > 0)
                    {
                        continue;
                    }
                    pickedCells[BitHelper.ReduceDims(j, dimMap, Dimensions)] = block[i | j];
                }
                proc(pickedCells, dimMap, handler, level + 1);
            }
        }
    }