77from math import sqrt
88from functools import total_ordering
99
10- @total_ordering
10+
11+ @total_ordering
1112class Vector2D :
1213 """Vector2D class to perform simple vector operations.
1314 """
15+
1416 def __init__ (self , x : SupportsFloat = 0 , y : SupportsFloat = 0 ):
1517 """Creates a vector instance with the given x and y values.
16-
18+
1719 Parameters
1820 ----------
1921 x : number
2022 x-Coordinate, by default 0
2123 y : number
2224 y-Coordinate, by default 0
23-
25+
2426 Raises
2527 ------
2628 TypeError
@@ -34,7 +36,7 @@ def __init__(self, x: SupportsFloat = 0, y: SupportsFloat = 0):
3436
3537 def __call__ (self ) -> str :
3638 """Callable for the vector instance to return its representation.
37-
39+
3840 Returns
3941 -------
4042 str
@@ -45,7 +47,7 @@ def __call__(self) -> str:
4547
4648 def __repr__ (self ) -> str :
4749 """The vector instance representation.
48-
50+
4951 Returns
5052 -------
5153 str
@@ -55,7 +57,7 @@ def __repr__(self) -> str:
5557
5658 def __str__ (self ) -> str :
5759 """The vector instance as a string.
58-
60+
5961 Returns
6062 -------
6163 str
@@ -65,7 +67,7 @@ def __str__(self) -> str:
6567
6668 def __bool__ (self ) -> bool :
6769 """Returns the truth value of the vector instance.
68-
70+
6971 Returns
7072 -------
7173 bool
@@ -76,7 +78,7 @@ def __bool__(self) -> bool:
7678
7779 def __abs__ (self ) -> float :
7880 """Returns the length (magnitude) of the vector instance
79-
81+
8082 Returns
8183 -------
8284 float
@@ -86,28 +88,29 @@ def __abs__(self) -> float:
8688
8789 def check_vector_types (self , vector2 : Vector2D ):
8890 """Checks if the self and vector2 are an instance of the Vector2D class.
89-
91+
9092 Parameters
9193 ----------
9294 vector2 : Vector2D
9395 Other vector (right of the operator).
94-
96+
9597 Raises
9698 ------
9799 TypeError
98100 If self, or vector2 are not an instance of the Vector2D class.
99101 """
100102 if not isinstance (self , Vector2D ) or not isinstance (vector2 , Vector2D ):
101- raise TypeError ('You have to pass in two instances of the vector class!' )
103+ raise TypeError (
104+ 'You have to pass in two instances of the vector class!' )
102105
103106 def __eq__ (self , other_vector : Any ) -> bool :
104107 """Check if the vector instances have the same values.
105-
108+
106109 Parameters
107110 ----------
108111 other_vector : Vector2D
109112 Other vector instance (right-hand-side of the operator)
110-
113+
111114 Returns
112115 -------
113116 bool
@@ -122,12 +125,12 @@ def __eq__(self, other_vector: Any) -> bool:
122125
123126 def __lt__ (self , other_vector : Vector2D ) -> bool :
124127 """Check if the self instance is less than the other vector instance.
125-
128+
126129 Parameters
127130 ----------
128131 other_vector : Vector2D
129132 Other vector instance (right-hand-side of the operator)
130-
133+
131134 Returns
132135 -------
133136 bool
@@ -142,12 +145,12 @@ def __lt__(self, other_vector: Vector2D) -> bool:
142145
143146 def __add__ (self , other_vector : Vector2D ) -> Vector2D :
144147 """Returns the additon vector of the self and the other vector instance.
145-
148+
146149 Parameters
147150 ----------
148151 other_vector : Vector2D
149152 Other vector instance (right-hand-side of the operator)
150-
153+
151154 Returns
152155 -------
153156 Vector2D
@@ -160,12 +163,12 @@ def __add__(self, other_vector: Vector2D) -> Vector2D:
160163
161164 def __sub__ (self , other_vector : Vector2D ) -> Vector2D :
162165 """Returns the subtraction vector of the self and the other vector instance.
163-
166+
164167 Parameters
165168 ----------
166169 other_vector : Vector2D
167170 Other vector instance (right-hand-side of the operator)
168-
171+
169172 Returns
170173 -------
171174 Vector2D
@@ -178,12 +181,12 @@ def __sub__(self, other_vector: Vector2D) -> Vector2D:
178181
179182 def __mul__ (self , other : Union [Vector2D , SupportsFloat ]) -> Union [Vector2D , SupportsFloat ]:
180183 """Returns the multiplication of the self vector and the other vector(or number) instance.
181-
184+
182185 Parameters
183186 ----------
184187 other : Vector2D or number
185188 Other vector instance or scaler value (right-hand-side of the operator)
186-
189+
187190 Returns
188191 -------
189192 Vector2D
@@ -194,16 +197,17 @@ def __mul__(self, other: Union[Vector2D, SupportsFloat]) -> Union[Vector2D, Supp
194197 elif isinstance (other , numbers .Real ):
195198 return Vector2D (self .x * other , self .y * other )
196199 else :
197- raise TypeError ('You must pass in a vector instance or an int/float number!' )
200+ raise TypeError (
201+ 'You must pass in a vector instance or an int/float number!' )
198202
199203 def __truediv__ (self , other : SupportsFloat ) -> Vector2D :
200204 """Returns the multiplication of the self vector and the other vector(or number) instance.
201-
205+
202206 Parameters
203207 ----------
204208 other : Vector2D or number
205209 Other vector instance or scaler value (right-hand-side of the operator)
206-
210+
207211 Returns
208212 -------
209213 Vector2D
0 commit comments