diff options
author | Aryadev Chavali <aryadev@aryadevchavali.com> | 2024-05-08 13:15:45 +0530 |
---|---|---|
committer | Aryadev Chavali <aryadev@aryadevchavali.com> | 2024-05-08 13:15:45 +0530 |
commit | ff2b74d8d151b10383e6a3bee04766bfca5305e4 (patch) | |
tree | f48d0de011df21a366f079d4b6fd782442863b62 /src | |
parent | a9797b80ca45cb40948ed0e682656c492c8a3639 (diff) | |
download | snek-ff2b74d8d151b10383e6a3bee04766bfca5305e4.tar.gz snek-ff2b74d8d151b10383e6a3bee04766bfca5305e4.tar.bz2 snek-ff2b74d8d151b10383e6a3bee04766bfca5305e4.zip |
Added vector operations to Point
Diffstat (limited to 'src')
-rw-r--r-- | src/main.cpp | 22 |
1 files changed, 21 insertions, 1 deletions
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} {} |