<commit_before>import numpy as np
import _transformations as trans
from abc import ABCMeta, abstractmethod
from .observers import IterObservable


class Coordinates(IterObservable):

    def __init__(self, *args, **kwargs):
        super(Coordinates, self).__init__(**kwargs)
        self._array = np.array(args, dtype=np.float32)

    def __repr__(self):
        arg_str = ', '.join(['{}={}'.format(*el) for el in zip('xyz', self._array)])
        return "{cls}({coords})".format(cls=self.__class__.__name__, coords=arg_str)

    def __getitem__(self, item):
        if type(item) == slice:
            return tuple(self._array[item])
        else:
            return self._array[item]

    def __setitem__(self, idx, value):
        super(Coordinates, self).__setitem__(idx, value)
        self._array[idx] = value

    # Note: Index counts backwards from end of array to increase compatibility with Quaternions.
    @property
    def x(self):
        return self[-3]

    @x.setter
    def x(self, value):
        self[-3] = value

    @property
    def y(self):
        return self[-2]

    @y.setter
    def y(self, value):
        self[-2] = value

    @property
    def z(self):
        return self[-1]

    @z.setter
    def z(self, value):
        self[-1] = value

    @property
    def xyz(self):
        return self[-3:]

    @xyz.setter
    def xyz(self, value):
        self[-3:] = value


class RotationBase(object):
    __metaclass__ = ABCMeta

    @abstractmethod
    def to_quaternion(self): pass

    @abstractmethod
    def to_euler(self, units='rad'): pass

    @abstractmethod
    def to_matrix(self): pass

    @classmethod
    def from_matrix(cls, matrix): pass


class RotationEuler(RotationBase, Coordinates):

    axes = 'rxyz'

    def __init__(self, x, y, z, **kwargs):
        super(RotationEuler, self).__init__(x, y, z, **kwargs)


class RotationEulerRadians(RotationEuler):

    def to_radians(self):
        return self

    def to_degrees(self):
        return RotationEulerDegrees(*np.degrees(self._array))

    def to_quaternion(self):
        return RotationQuaternion(*trans.quaternion_from_euler(*self._array, axes=self.axes))

    def to_matrix(self):
        return trans.euler_matrix(*self._array, axes=self.axes)

    def to_euler(self, units='rad'):<commit_msg>Added Rotation.rotate() method, which returns a rotated version of a 3-coordinate vector.  This will be useful for calculating orientation.<commit_after>import numpy as np
import _transformations as trans
from abc import ABCMeta, abstractmethod
from .observers import IterObservable


class Coordinates(IterObservable):

    def __init__(self, *args, **kwargs):
        super(Coordinates, self).__init__(**kwargs)
        self._array = np.array(args, dtype=np.float32)

    def __repr__(self):
        arg_str = ', '.join(['{}={}'.format(*el) for el in zip('xyz', self._array)])
        return "{cls}({coords})".format(cls=self.__class__.__name__, coords=arg_str)

    def __getitem__(self, item):
        if type(item) == slice:
            return tuple(self._array[item])
        else:
            return self._array[item]

    def __setitem__(self, idx, value):
        super(Coordinates, self).__setitem__(idx, value)
        self._array[idx] = value

    # Note: Index counts backwards from end of array to increase compatibility with Quaternions.
    @property
    def x(self):
        return self[-3]

    @x.setter
    def x(self, value):
        self[-3] = value

    @property
    def y(self):
        return self[-2]

    @y.setter
    def y(self, value):
        self[-2] = value

    @property
    def z(self):
        return self[-1]

    @z.setter
    def z(self, value):
        self[-1] = value

    @property
    def xyz(self):
        return self[-3:]

    @xyz.setter
    def xyz(self, value):
        self[-3:] = value


class RotationBase(object):
    __metaclass__ = ABCMeta

    @abstractmethod
    def to_quaternion(self): pass

    @abstractmethod
    def to_euler(self, units='rad'): pass

    @abstractmethod
    def to_matrix(self): pass

    @classmethod
    def from_matrix(cls, matrix): pass

    def rotate(self, vector):
        """Takes a vector and returns it rotated by self."""
        return np.dot(self.to_matrix()[:3, :3], vector).flatten()


class RotationEuler(RotationBase, Coordinates):

    axes = 'rxyz'

    def __init__(self, x, y, z, **kwargs):
        super(RotationEuler, self).__init__(x, y, z, **kwargs)


class RotationEulerRadians(RotationEuler):

    def to_radians(self):
        return self

    def to_degrees(self):
        return RotationEulerDegrees(*np.degrees(self._array))

    def to_quaternion(self):
        return RotationQuaternion(*trans.quaternion_from_euler(*self._array, axes=self.axes))

    def to_matrix(self):
        return trans.euler_matrix(*self._array, axes=self.axes)

    def to_euler(self, units='rad'):
{'fraction_non_alphanumeric': 0.1227532679738562, 'fraction_numerical': 0.004697712418300653, 'mean_word_length': 2.8895949166004766, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1049694', 'n_tokens_mistral': 1620, 'n_tokens_neox': 1532, 'n_words': 389}