0

嘿,这可以正常工作,但是在将其与 4-way 进行比较后,我找不到任何差异...如果我将其交出,它会被认为是实现 8-way flood 算法的正确方法吗?一个是/否的答案就足够了,但我想在继续之前我会问专家

private void flood8(int col, int row, Color startColour) {

    if (startColour.equals(getPixel(col, row))) {
        setPixel(col, row);

        // this bit makes the animation work by
        // drawing intermediate results, and slowing the updates down
        synchronized (this) {
            draw();
       }

        try {
            Thread.sleep(10);
        } catch (InterruptedException e) {
        }

        // now we call the routine recursively for each neighbour
        // the "guard" surrounding each call ensures that we do
        // not try to keep going past the edge of the raster
        if (col + 1 < COLS) {
            flood4(col + 1, row, startColour);
            System.out.println("Position1 " + col + ", " + row );
        }
        if (col - 1 >= 0) {
            flood4(col - 1, row, startColour);
            System.out.println("Position2 " + col + ", " + row );
        }
        if (row + 1 < ROWS) {
            flood4(col, row + 1, startColour);
            System.out.println("Position3 " + col + ", " + row );
        }
        if (row - 1 <= 0) {
            flood4(col, row - 1, startColour);
            System.out.println("Position4 " + col + ", " + row );
        }
        if (col + 1 < COLS && row + 1 < ROWS) {
            flood4(col + 1, row, startColour);
            System.out.println("Position1 " + col + ", " + row );
        }
        if (col + 1 < COLS && row - 1 >= 0) {
            flood4(col - 1, row, startColour);
            System.out.println("Position2 " + col + ", " + row );
        }
        if (row - 1 >= 0 && row + 1 < ROWS) {
            flood4(col, row + 1, startColour);
            System.out.println("Position3 " + col + ", " + row );
        }
        if (row - 1 >= 0 && row - 1 >= 0) {
            flood4(col, row - 1, startColour);
            System.out.println("Position4 " + col + ", " + row );            
        }
    }
}

谢谢阅读

4

1 回答 1

0

将几条评论变成一个答案,以将其从“未答复”队列中取出。社区 wiki,因此请随时添加。

它会被认为是实现 8 路洪水算法的正确方法吗?

可能不会,原因如下:

  • 您调用flood4,而适当的递归应该flood8再次调用。
  • 您对对角线邻居进行边界检查,但(可能)递归调用仅更改一个坐标。
于 2013-03-20T22:10:55.963 回答