class Vector(Point): """This class defines a vector in 2 space""" origin = Point(0, 0) def __init__(self, x, y): """Post: returns a vector centered at the origin with coordinates (x,y)""" super().__init__(x, y) def __add__(self, v): """Post: adds the given vector to this vector component-wise""" return Vector(self.x + v.x, self.y + v.y) def __neg__(self, v): """Post: subtracts the given vector to this vector component-wise""" return Vector(self.x - v.x, self.y - v.y) def __mul__(self, n): """Post: multiplies this vector by the given number component-wise""" return Vector(self.x * n, self.y * n) def __len__(self): """Post: returns the length of the vector from the origin rounded""" return int(Vector.distance(Vector.origin, self)) def __eq__(self, v): """Post: returns whether the given vector is equal to this vector""" return self.x == v.x and self.y == v.y def isDiagonalInPointSet(self, points): """Post: returns whether this vector is on the diagonal and exists in the collection of points given""" for p in points: if (self == p and self.__isDiagonal()): return True return False def __isDiagonal(self): """Post: returns whether the vector is on the diagonal""" return self.x == self.y @staticmethod def dot(p1, p2): """Post: returns the dot product of the the given vector with this vector""" return p1.x * p2.x + p1.y * p2.y