<commit_before>#!/usr/bin/env python
# -*- coding:utf-8 -*-
#
# written by <NAME>


from growing_string import Main
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.tri as tri
from matplotlib.patches import Polygon
from matplotlib.collections import PatchCollection


class FillBucket(object):
    def __init__(self, main, plot_type='fill'):
        self.lattice = main.lattice
        self.lattice_X = main.lattice_X
        self.lattice_Y = main.lattice_Y
        self.doubled_lattice = np.zeros((self.lattice.Lx * 2, self.lattice.Ly),
                                        dtype=np.bool)
        self.string = main.strings[0]

        self.plot_type = plot_type

        doubled_lattice = self.create_doubled_lattice()
        self.doubled_lattice = self.fill_inside(doubled_lattice)
        self.convert_to_realspace(self.doubled_lattice)
        self.plot_all()

    def create_doubled_lattice(self):
        str_pos = self.string.pos.tolist()
        check_index = [(i, j)
                       for i in range(self.lattice.Lx)
                       for j in range(self.lattice.Ly)
                       if [i, j] in str_pos]

        for i, j in check_index:
            k = str_pos.index([i, j])
            vec = self.string.vec[k]
            if vec in [0, 3]:
                continue

            if vec == 1:
                x = 2 * i
                y = j
            elif vec == 2:
                x = 2 * i - 1
                y = j
            elif vec == 4:
                x = 2 * i
                y = j - 1
            elif vec == 5:
                x = 2 * i + 1
                y =  j - 1

            self.doubled_lattice[x, y] = True
        return self.doubled_lattice

    def fill_inside(self, arr):
        """Fill inside

        arr: (m x n: boolean ndarray)
        """
        size_x, size_y = arr.shape
        ret_arr = np.zeros((size_x, size_y), dtype=np.bool)
        for j in range(size_y):
            flag = False
            for i in range(size_x):
                tf = arr[i, j]
                if flag ^ tf:
                    ret_arr[i, j] = True

                if tf:
                    flag = not flag
        return ret_arr

    def convert_to_realspace(self, arr):
        size_x, size_y = self.lattice.Lx, self.lattice.Ly
        index = np.array(np.where(arr)).T.tolist()
        self.X_even, self.Y_even = [], []
        self.X_odd, self.Y_odd = [], []
        for (i, j) in index:
            if i % 2 == 0:
                self.X_even.append(self.lattice_X[i / 2, j])
                self.Y_even.append(self.lattice_Y[i / 2, j])
            elif i % 2 == 1:
                self.X_odd.append(self.lattice_X[(i / 2 + 1) % size_x, j])
                self.Y_odd.append(self.lattice_Y[(i / 2 + 1) % size_x, j])

    def plot_all(self, plot_type=None):
        if plot_type is None:
            plot_type = self.plot_type

        self.fig, self.ax = plt.subplots(figsize=(8, 8))

        lattice_X = self.lattice.coordinates_x
        lattice_Y = self.lattice.coordinates_y
        X_min, X_max = min(lattice_X) - 0.1, max(lattice_X) + 0.1
        Y_min, Y_max = min(lattice_Y) - 0.1, max(lattice_Y) + 0.1
        self.ax.set_xlim([X_min, X_max])
        self.ax.set_ylim([Y_min, Y_max])
        self.ax.set_xticklabels([])
        self.ax.set_yticklabels([])
        self.ax.set_aspect('equal')

        triang = tri.Triangulation(lattice_X, lattice_Y)
        self.ax.triplot(triang, color='#d5d5d5', marker='.', markersize=1)<commit_msg>fill_bucket: Remove unused method 'convert_to_realspace'<commit_after>#!/usr/bin/env python
# -*- coding:utf-8 -*-
#
# written by <NAME>


from growing_string import Main
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.tri as tri
from matplotlib.patches import Polygon
from matplotlib.collections import PatchCollection


class FillBucket(object):
    def __init__(self, main, plot_type='fill'):
        self.lattice = main.lattice
        self.lattice_X = main.lattice_X
        self.lattice_Y = main.lattice_Y
        self.doubled_lattice = np.zeros((self.lattice.Lx * 2, self.lattice.Ly),
                                        dtype=np.bool)
        self.string = main.strings[0]

        self.plot_type = plot_type

        doubled_lattice = self.create_doubled_lattice()
        self.doubled_lattice = self.fill_inside(doubled_lattice)

    def create_doubled_lattice(self):
        str_pos = self.string.pos.tolist()
        check_index = [(i, j)
                       for i in range(self.lattice.Lx)
                       for j in range(self.lattice.Ly)
                       if [i, j] in str_pos]

        for i, j in check_index:
            k = str_pos.index([i, j])
            vec = self.string.vec[k]
            if vec in [0, 3]:
                continue

            if vec == 1:
                x = 2 * i
                y = j
            elif vec == 2:
                x = 2 * i - 1
                y = j
            elif vec == 4:
                x = 2 * i
                y = j - 1
            elif vec == 5:
                x = 2 * i + 1
                y =  j - 1

            self.doubled_lattice[x, y] = True
        return self.doubled_lattice

    def fill_inside(self, arr):
        """Fill inside

        arr: (m x n: boolean ndarray)
        """
        size_x, size_y = arr.shape
        ret_arr = np.zeros((size_x, size_y), dtype=np.bool)
        for j in range(size_y):
            flag = False
            for i in range(size_x):
                tf = arr[i, j]
                if flag ^ tf:
                    ret_arr[i, j] = True

                if tf:
                    flag = not flag
        return ret_arr

        size_x, size_y = self.lattice.Lx, self.lattice.Ly

    def plot_all(self, plot_type=None):
        if plot_type is None:
            plot_type = self.plot_type

        self.fig, self.ax = plt.subplots(figsize=(8, 8))

        lattice_X = self.lattice.coordinates_x
        lattice_Y = self.lattice.coordinates_y
        X_min, X_max = min(lattice_X) - 0.1, max(lattice_X) + 0.1
        Y_min, Y_max = min(lattice_Y) - 0.1, max(lattice_Y) + 0.1
        self.ax.set_xlim([X_min, X_max])
        self.ax.set_ylim([Y_min, Y_max])
        self.ax.set_xticklabels([])
        self.ax.set_yticklabels([])
        self.ax.set_aspect('equal')

        triang = tri.Triangulation(lattice_X, lattice_Y)
        self.ax.triplot(triang, color='#d5d5d5', marker='.', markersize=1)
{'fraction_non_alphanumeric': 0.11054421768707483, 'fraction_numerical': 0.011131725417439703, 'mean_word_length': 1.5886354541816727, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4871875', 'n_tokens_mistral': 2283, 'n_tokens_neox': 2139, 'n_words': 489}