首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >这是一个8路的Flood Fill程序吗?

这是一个8路的Flood Fill程序吗?
EN

Stack Overflow用户
提问于 2013-03-21 03:47:28
回答 1查看 464关注 0票数 0

嘿,这是正确的,但在与4-way进行比较后,我找不到任何差异……如果我上交这篇文章,它会被认为是实现8向泛洪算法的正确方法吗?一个是/否的答案就足够了,但我想在继续之前我应该先请教专家

代码语言:javascript
复制
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 );            
        }
    }
}

感谢您的阅读

EN

回答 1

Stack Overflow用户

发布于 2013-03-21 06:10:56

将几条评论转换为答案,将其从“未回答”队列中提取出来。社区维基,所以请随意添加。

这会被认为是实施8向泛洪算法的正确方法吗?

可能不会,原因如下:

  • 你调用flood4,而正确的递归应该再次调用flood8
  • 你会对对角线邻域进行边界检查,但(可能)递归调用只会更改一个坐标。
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15533287

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档