예제 #1
0
 def __sub__(self, other):
     delta = super().__sub__(other)
     if isinstance(other, PointAny):
         if other.is_mutable():
             return mVec(delta)
         else:
             return Vec(delta)
     return delta
예제 #2
0
 def __sub__(self, other):
     delta = super().__sub__(other)
     if isinstance(other, PointAny):
         if other.is_mutable():
             return mVec(delta)
         else:
             return Vec(delta)
     return delta
예제 #3
0
    def rotate(self, theta):
        """
        Rotate vector by an angle theta around origin.
        """

        if isinstance(theta, self._rotmat):
            return theta * self

        cls = type(self)
        x, y = self
        cos_t, sin_t = self._cos(theta), self._sin(theta)

        # TODO: decent implementation of this!
        try:
            return cls(x * cos_t - y * sin_t, x * sin_t + y * cos_t)
        except InexactError:
            if isinstance(self, Mutable):
                return mVec(x * cos_t - y * sin_t, x * sin_t + y * cos_t)
            else:
                return Vec(x * cos_t - y * sin_t, x * sin_t + y * cos_t)
예제 #4
0
    def rotate(self, theta):
        """
        Rotate vector by an angle theta around origin.
        """

        if isinstance(theta, self._rotmat):
            return theta * self

        cls = type(self)
        x, y = self
        cos_t, sin_t = self._cos(theta), self._sin(theta)

        # TODO: decent implementation of this!
        try:
            return cls(x * cos_t - y * sin_t, x * sin_t + y * cos_t)
        except InexactError:
            if isinstance(self, Mutable):
                return mVec(x * cos_t - y * sin_t, x * sin_t + y * cos_t)
            else:
                return Vec(x * cos_t - y * sin_t, x * sin_t + y * cos_t)