Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from numbers import Real
- import math
- class Vector2D:
- _abscissa: float
- _ordinate: float
- def __init__(self, abscissa = 0.0, ordinate = 0.0):
- self._abscissa = abscissa
- self._ordinate = ordinate
- @property
- def abscissa(self):
- return self._abscissa
- @property
- def ordinate(self):
- return self._ordinate
- def __str__(self):
- return f"Vector2D(abscissa={self._abscissa}, ordinate={self._ordinate})"
- def __eq__(self, other):
- return self._abscissa == other.abscissa and self._ordinate == other.ordinate
- def __lt__(self, other):
- return self._abscissa < other.abscissa or self._abscissa == other.abscissa and self.ordinate < other.ordinate
- def __le__(self, other):
- return self._abscissa <= other.abscissa or self._abscissa == other.abscissa and self.ordinate <= other.ordinate
- def __abs__(self):
- return math.sqrt(self._abscissa**2 + self._ordinate**2)
- def __bool__(self):
- return abs(self) > 0
- def __mul__(self, k):
- res = Vector2D(self._abscissa, self._ordinate)
- res.abscissa *= k
- res.ordinate *= k
- def __rmul__(self, k):
- res = Vector2D(self._abscissa, self._ordinate)
- res.abscissa *= k
- res.ordinate *= k
- def __truediv__(self, k):
- res = Vector2D(self._abscissa, self._ordinate)
- res.abscissa /= k
- res.ordinate /= k
- a = Vector2D(1, 2)
- b = Vector2D(2, 2)
- print(a >= b)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement