<commit_before>"""Physical attributes of things.

"""

import pygame

from hypatia import constants


class Velocity(object):
    """Eight-directional velocity."""

    def __init__(self, x=0, y=0):
        """Speed in pixels per second per axis. Values may be negative.

        Args:
          x (int|None): --
          y (int|None): --

        """

        self.x = x
        self.y = y

    def get_direction(self):
        """Return a direction which corresponds to the current 2D
        velocity.

        See Also:
            :class:`constants.Direction`

        Returns:
            :class:`constants.Direction`: --

        """

        directions = []

        if x > 0:
            directions.append(constants.Direction.east)
        elif x == 0:
            pass
        else:
            directions.append(constants.Direction.west)

        if y > 0:
            directions.append(constants.Direction.south)
        elif y == 0:
            pass
        else:
            directions.append(constants.Direction.north)

        return sum(directions)


class Position(object):
    """The absolute position of an object."""

    def __init__(self, x, y, size):
        """Extrapolate position info from supplied info.

        Args:
          x (int|float): how many pixels from the left of the scene.
          y (int|float): how many pixels from the top of the scene.
          size (tuple): (x, y) pixel dimensions of object being
            represented.

        """

        self.rect = pygame.Rect((x, y), size)
        self.float = (float(x), float(y))
        self.int = (x, y)


# NOTE: this module will definitely be heavy on the tests in the future
if __name__ == "__main__":
    import doctest
    doctest.testmod()
<commit_msg>Updated physics to not use duplicate code.<commit_after>"""Physical attributes of things.

"""

import pygame

from hypatia import constants


class Velocity(object):
    """Eight-directional velocity."""

    def __init__(self, x=0, y=0):
        """Speed in pixels per second per axis. Values may be negative.

        Args:
          x (int|None): --
          y (int|None): --

        """

        self.x = x
        self.y = y

    def get_direction(self):
        """Return a direction which corresponds to the current 2D
        velocity.

        See Also:
            :class:`constants.Direction`

        Returns:
            :class:`constants.Direction`: --

        """

        x_directions = ('x', constants.Direction.east,
                        constants.Direction.west)
        y_directions = ('y', constants.Direction.south,
                        constants.Direction.north)

        collected_directions = []

        for direction_info in [x_directions, y_directions]:
            axis, plus_direction, nevative_direction = direction_info
            axis_value = getattr(self, axis)

            if axis_value > 0:
                collected_directions.append(plus_direction)
            elif axis_value == 0:
                pass
            else:
                collected_directions.append(negative_direction)

        return sum(collected_directinos)


class Position(object):
    """The absolute position of an object."""

    def __init__(self, x, y, size):
        """Extrapolate position info from supplied info.

        Args:
          x (int|float): how many pixels from the left of the scene.
          y (int|float): how many pixels from the top of the scene.
          size (tuple): (x, y) pixel dimensions of object being
            represented.

        """

        self.rect = pygame.Rect((x, y), size)
        self.float = (float(x), float(y))
        self.int = (x, y)


# NOTE: this module will definitely be heavy on the tests in the future
if __name__ == "__main__":
    import doctest
    doctest.testmod()

{'fraction_non_alphanumeric': 0.10286014169509315, 'fraction_numerical': 0.003148779847808974, 'mean_word_length': 1.890068233510235, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 6, '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': '5066776', 'n_tokens_mistral': 1076, 'n_tokens_neox': 1027, 'n_words': 334}