<commit_before>from math import sqrt, ceil

from .shapes import Point


class Grid(object):

    def __init__(self, start, size, iterations_wide, iterations_tall):
        self.start = start
        self.size = float(size)
        self.iterations_wide = iterations_wide + (1 if iterations_wide % size == 0 else 0)
        self.iterations_tall = iterations_tall + (1 if iterations_tall % size == 0 else 0)

        self.points = self._generate_points()

    def _generate_points(self):
        pass

    def _offsets(self, x, y):
        return (x, y)

    def _mirrored_points(self, x, y, x_idx, y_idx):
        mirror = set()
        x_offset, y_offset = self._offsets(x_idx, y_idx)
        mirror.add(Point(self.start.x + (x + x_offset), self.start.y + (y + y_offset)))
        mirror.add(Point(self.start.x + (x + x_offset), self.start.y - (y + y_offset)))
        mirror.add(Point(self.start.x - (x + x_offset), self.start.y + (y + y_offset)))
        mirror.add(Point(self.start.x - (x + x_offset), self.start.y - (y + y_offset)))

        return mirror


class SquareGrid(Grid):
    """ A grid of points arranged in squares.

    >>> square_grid = SquareGrid(Point(5.0, 5.0), 1, 1, 1)<commit_msg>Add method to provide for finding closest grid point to another point<commit_after>from math import sqrt, ceil

from .shapes import Point


class Grid(object):

    def __init__(self, start, size, iterations_wide, iterations_tall):
        self.start = start
        self.size = float(size)
        self.iterations_wide = iterations_wide + (1 if iterations_wide % size == 0 else 0)
        self.iterations_tall = iterations_tall + (1 if iterations_tall % size == 0 else 0)

        self.points = self._generate_points()

    def _generate_points(self):
        pass

    def _offsets(self, x, y):
        return (x, y)

    def _mirrored_points(self, x, y, x_idx, y_idx):
        mirror = set()
        x_offset, y_offset = self._offsets(x_idx, y_idx)
        mirror.add(Point(self.start.x + (x + x_offset), self.start.y + (y + y_offset)))
        mirror.add(Point(self.start.x + (x + x_offset), self.start.y - (y + y_offset)))
        mirror.add(Point(self.start.x - (x + x_offset), self.start.y + (y + y_offset)))
        mirror.add(Point(self.start.x - (x + x_offset), self.start.y - (y + y_offset)))

        return mirror

    def closest_point_to(self, other_point):
        distance, point = min([(x.distance_to(other_point), x) for x in self.points])
        return point


class SquareGrid(Grid):
    """ A grid of points arranged in squares.

    >>> square_grid = SquareGrid(Point(5.0, 5.0), 1, 1, 1)
{'fraction_non_alphanumeric': 0.13050133945656334, 'fraction_numerical': 0.009950248756218905, 'mean_word_length': 2.816058394160584, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '269358', 'n_tokens_mistral': 924, 'n_tokens_neox': 877, 'n_words': 231}