summaryrefslogtreecommitdiffstats
path: root/Vertex.cpp
diff options
context:
space:
mode:
authorneoraider <devnull@localhost>2007-09-16 16:07:03 +0200
committerneoraider <devnull@localhost>2007-09-16 16:07:03 +0200
commit01e98d51fedf65ad71d468c3b0410d6e7764a384 (patch)
tree3259e2655249865cd335d96cc4b32815a4236532 /Vertex.cpp
parent2bdbece75f9dcc9b98d7f9d5794c4b5e5f441b26 (diff)
downloadzoomedit-01e98d51fedf65ad71d468c3b0410d6e7764a384.tar
zoomedit-01e98d51fedf65ad71d468c3b0410d6e7764a384.zip
zoomedit: C++ized Vertex
Diffstat (limited to 'Vertex.cpp')
-rw-r--r--Vertex.cpp33
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;
+}