0

シードフィル アルゴリズムを実装しています。色については、ジェネリック変数を使用します。pattただし、整数のパターンを実装する方法がわかりません。ソースコードは次のとおりです。

public class SeedFill4In<PixelType> implements SeedFill<PixelType> {

@Override
public @NotNull RasterImage<PixelType> fill(
        final @NotNull RasterImage<PixelType> img, final int c, final int r, 
        final @NotNull PixelType areaValue,
        final @NotNull PixelType newValue) {

    int [ ][ ] patt =       {
            {0xFF0000,0x0000FF,0x0000FF,0xFF0000,0xFF0000},
            {0xFF0000,0x0000FF,0x00FF00,0xFF0000,0xFF0000},
            {0xFF0000,0x0000FF,0x0000FF,0x00FF00,0xFF0000},
            {0xFF0000,0x0000FF,0x0000FF,0xFF0000,0xFF0000},
            {0xFF0000,0x0000FF,0x0000FF,0xFF0000,0xFF0000}
        };

    int i = c % patt.length;
    int j = r % patt.length;






    return new Object() {
        @NotNull RasterImage<PixelType> fill(
                final @NotNull RasterImage<PixelType> img, final int c, final int r) {
            return img.getPixel(c, r)
                    .flatMap((final @NotNull PixelType actualValue) -> {
                        if (actualValue.equals(areaValue)) {
                            return Optional.of(
                                fill(
                                    fill(
                                        fill(
                                            fill(
                                                img.withPixel(c, r, newValue), 
                                                c, r - 1), 
                                            c + 1, r), 
                                        c, r + 1),
                                    c - 1, r)
                                );
                        }
                        return Optional.empty();
                    })
                    .orElse(img);
        }
    }.fill(img, c, r);
}

パターンなしで塗りつぶすために、newValue変数を使用しました。パターンに変更するには?

4

1 に答える 1