diff options
Diffstat (limited to 'Vertex.cpp')
-rw-r--r-- | Vertex.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/Vertex.cpp b/Vertex.cpp new file mode 100644 index 0000000..a2aefaf --- /dev/null +++ b/Vertex.cpp @@ -0,0 +1,33 @@ +#include "Vertex.h" +#include <math.h> + +double Vertex::distanceSq(const Vertex &v) const { + return (x - v.x)*(x - v.x) + (y - v.y)*(y - v.y); +} + +double Vertex::distance(const Vertex &v) const { + return sqrt(distanceSq(v)); +} + + +Vertex Vertex::operator+(const Vertex &v) const { + return Vertex(x + v.x, y + v.y); +} + +Vertex Vertex::operator-(const Vertex &v) const { + return Vertex(x - v.x, y - v.y); +} + +Vertex& Vertex::operator+=(const Vertex &v) { + x += v.x; + y += v.y; + + return *this; +} + +Vertex& Vertex::operator-=(const Vertex &v) { + x -= v.x; + y -= v.y; + + return *this; +} |