From ff2b74d8d151b10383e6a3bee04766bfca5305e4 Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Wed, 8 May 2024 13:15:45 +0530 Subject: Added vector operations to Point --- src/main.cpp | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/main.cpp b/src/main.cpp index fe2c2ae..b8ea10f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -45,11 +45,31 @@ struct Point { int x, y; - bool operator==(const struct Point &p) const + bool operator==(const Point &p) const { return x == p.x && y == p.y; } + Point operator+(const Point &p) const + { + return {x + p.x, y + p.y}; + } + + Point operator-(const Point &p) const + { + return {x - p.x, y - p.y}; + } + + Point operator*(const Point &p) const + { + return {x * p.x, y * p.y}; + } + + Point operator*(int m) const + { + return {x * m, y * m}; + } + Point() : x{0}, y{0} {} -- cgit v1.2.3-13-gbd6f