Esempio n. 1
0
    public int PositionRangeInAxis(KMapLoop loop, int[] checkBits, out int maximum, out int numCellsInAxis)
    {
        // Get the leftmost and rightmost position, or upmost and downmost position,
        // that this loop contains. Specify the bits to check against in checkBits.
        KMapLoop singleAxisLoop = new KMapLoop();

        foreach (int bit in checkBits)
        {
            singleAxisLoop.Add(loop[bit]);
        }
        IEnumerable <IEnumerable <bool> > combinations = singleAxisLoop.CrossProductCombinations();
        int minimum = BinaryHelper.PowBaseTwo(checkBits.Length);

        maximum = 0;

        foreach (IEnumerable <bool> cellBitList in combinations)
        {
            int lineIndex = BinaryHelper.GrayCode(BinaryHelper.BooleanToBinaryValue(cellBitList.ToArray()));

            if (lineIndex < minimum)
            {
                minimum = lineIndex;
            }
            if (lineIndex > maximum)
            {
                maximum = lineIndex;
            }
        }
        numCellsInAxis = combinations.Count();
        return(minimum);
    }
    public static List <int> CellsCovered(this KMapLoop loop)
    {
        List <int> neighbourCellList = new List <int>();

        foreach (IEnumerable <bool> cellBitList in loop.CrossProductCombinations())
        {
            int gridIndex = BinaryHelper.BooleanToBinaryValue(cellBitList.ToArray());
            neighbourCellList.Add(gridIndex);
        }
        return(neighbourCellList);
    }