<commit_before>/*
 * Copyright 2009 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package de.michaeltamm.fightinglayoutbugs;

/**
 * Marks buggy pixels in the screenshot by
 * surrounding them with thick red lines.
 *
 * @author <NAME>
 */
public class SurroundBuggyPixels implements Marker {

    private static final int[] CIRCLE = new int[] { 2, 3, 4, 5, 5, 5, 5, 5, 4, 3, 2 };
    private static final int RED = 0x00FF0000;
    private static final int TRANSPARENT = 0xFF000000;

    private final boolean[][] _buggyPixels;

    public SurroundBuggyPixels(boolean[][] buggyPixels) {
        _buggyPixels = buggyPixels;
    }

    public void mark(int[][] screenshot) {
        final int w = _buggyPixels.length;
        final int h = _buggyPixels[0].length;
        if (screenshot.length != w || screenshot[0].length != h) {
            throw new RuntimeException("Buggy pixels (" + w + " x " + h + ") have different size than screenshot (" + screenshot.length + " x " + screenshot[0].length + ").");
        }
        // 1.) Find buggy areas by drawing a circle with a radius of 5 pixels around each buggy pixel ...
        final boolean[][] buggyAreas = new boolean[w][h];
        for (int x = 0; x < w; ++x) {
            for (int y = 0; y < h; ++y) {
                if (_buggyPixels[x][y]) {
                    for (int i = -5; i <= 5; ++i) {
                        final int yy = y + i;
                        if (y >= 0 && y < h) {
                            final int n = CIRCLE[i + 5];
                            for (int j = -n; j < n; ++j) {
                                final int xx = x + j;
                                if (xx >= 0 && xx < w) {
                                    buggyAreas[xx][yy] = true;
                                }
                            }
                        }
                    }
                }
            }
        }<commit_msg>Fixed ArrayIndexOutOfBoundsException in SurroundBuggyPixels.mark(...) - thanks go to <NAME> for pointing out the bug<commit_after>/*
 * Copyright 2009 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package de.michaeltamm.fightinglayoutbugs;

/**
 * Marks buggy pixels in the screenshot by
 * surrounding them with thick red lines.
 *
 * @author <NAME>
 */
public class SurroundBuggyPixels implements Marker {

    private static final int[] CIRCLE = new int[] { 2, 3, 4, 5, 5, 5, 5, 5, 4, 3, 2 };
    private static final int RED = 0x00FF0000;
    private static final int TRANSPARENT = 0xFF000000;

    private final boolean[][] _buggyPixels;

    public SurroundBuggyPixels(boolean[][] buggyPixels) {
        _buggyPixels = buggyPixels;
    }

    public void mark(int[][] screenshot) {
        final int w = _buggyPixels.length;
        final int h = _buggyPixels[0].length;
        if (screenshot.length != w || screenshot[0].length != h) {
            throw new RuntimeException("Buggy pixels (" + w + " x " + h + ") have different size than screenshot (" + screenshot.length + " x " + screenshot[0].length + ").");
        }
        // 1.) Find buggy areas by drawing a circle with a radius of 5 pixels around each buggy pixel ...
        final boolean[][] buggyAreas = new boolean[w][h];
        for (int x = 0; x < w; ++x) {
            for (int y = 0; y < h; ++y) {
                if (_buggyPixels[x][y]) {
                    for (int i = -5; i <= 5; ++i) {
                        final int yy = y + i;
                        if (yy >= 0 && yy < h) {
                            final int n = CIRCLE[i + 5];
                            for (int j = -n; j < n; ++j) {
                                final int xx = x + j;
                                if (xx >= 0 && xx < w) {
                                    buggyAreas[xx][yy] = true;
                                }
                            }
                        }
                    }
                }
            }
        }
{'fraction_non_alphanumeric': 0.10761154855643044, 'fraction_numerical': 0.018170805572380374, 'mean_word_length': 1.7145205479452055, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3837009', 'n_tokens_mistral': 1493, 'n_tokens_neox': 1355, 'n_words': 522}