Added vector operations to Point
This commit is contained in:
22
src/main.cpp
22
src/main.cpp
@@ -45,11 +45,31 @@ struct Point
|
|||||||
{
|
{
|
||||||
int x, y;
|
int x, y;
|
||||||
|
|
||||||
bool operator==(const struct Point &p) const
|
bool operator==(const Point &p) const
|
||||||
{
|
{
|
||||||
return x == p.x && y == p.y;
|
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}
|
Point() : x{0}, y{0}
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user