Skip to content
Snippets Groups Projects
Commit 16e1708d authored by Ian Prins's avatar Ian Prins
Browse files

add method for distance between two points

parent d2cd17b5
No related branches found
No related tags found
No related merge requests found
#include "include/coord.h"
#include <string>
#include <cmath>
#include <algorithm>
Coord::Coord(int x, int y)
: x(x)
......@@ -72,4 +73,8 @@ bool Coord::operator!=(const Coord& other) {
std::string Coord::toString() const{
return std::to_string(x) + ", " + std::to_string(y);
}
\ No newline at end of file
}
int Coord::distanceTo(const Coord& other) const {
return std::max(std::abs(x - other.x), std::abs(y - other.y));
}
......@@ -25,6 +25,8 @@ class Coord {
Coord asScreen();
Coord copy();
std::string toString() const;
// maximum distance in either dimension
int distanceTo(const Coord&) const;
private:
int x, y;
static const int MAPX = 0, MAPY = 2;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment