From 00c3532ccb70db5e0f6e995d2913285dc60730f7 Mon Sep 17 00:00:00 2001 From: CL-CodingStuff <121184311+CL-CodingStuff@users.noreply.github.com> Date: Wed, 15 Feb 2023 16:23:45 +0000 Subject: [PATCH 1/3] Wrote init, repr, str, and abs functions --- main.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 104be10..ebceb89 100644 --- a/main.py +++ b/main.py @@ -1,2 +1,16 @@ +import math class Vector2d: - pass \ No newline at end of file + def __init__(self, x, y): + self.x = x + self.y = y + + def __repr__(self): + return f"Vector2d(x={self.x},y={self.y})" + + + def __str__(self): + return f"{self.x}i + {self.y}j" + + def __abs__(self): + c = (self.x**2)+(self.y**2) + return math.sqrt(c) \ No newline at end of file From bd4f00ef1a4656c38773c7762fa474357f99e7fc Mon Sep 17 00:00:00 2001 From: CL-CodingStuff <121184311+CL-CodingStuff@users.noreply.github.com> Date: Thu, 16 Feb 2023 17:13:41 +0000 Subject: [PATCH 2/3] Added __add__ and __neg__ functions. --- main.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index ebceb89..badc964 100644 --- a/main.py +++ b/main.py @@ -13,4 +13,21 @@ def __str__(self): def __abs__(self): c = (self.x**2)+(self.y**2) - return math.sqrt(c) \ No newline at end of file + return math.sqrt(c) + + def __neg__(self): + return Vector2d(-self.x, -self.y) + + def __add__(self, other): + return Vector2d(self.x + other.x,self.y + other.y) + + def __eq__(self, other): + return bool((self.x, self.y) == (other.x, other.y)) + + def __sub__(self, other): + return Vector2d(self.x - other.x,self.y - other.y) + + def angle(self): + return math.degrees(math.atan2(self.x, self.y)) + + \ No newline at end of file From b50a76bde3acbb0500bae407145957e4aa5a5031 Mon Sep 17 00:00:00 2001 From: CL-CodingStuff <121184311+CL-CodingStuff@users.noreply.github.com> Date: Thu, 23 Feb 2023 15:34:38 +0000 Subject: [PATCH 3/3] Added more dunder methods