From 1606dfb058a5e8c3c3e8fdf251eaff7795a86592 Mon Sep 17 00:00:00 2001 From: Anna Wiggins Date: Wed, 22 Jun 2011 22:47:56 -0400 Subject: [PATCH] Fixed bug with distance calculations... distance <> slope --- gamecore.cpp | 13 +++++++++---- graph.cpp | 9 ++------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/gamecore.cpp b/gamecore.cpp index 2926237..83dc130 100644 --- a/gamecore.cpp +++ b/gamecore.cpp @@ -1,9 +1,6 @@ #include "gamecore.h" #include "drawutils.h" - -#ifdef DEBUG -#include -#endif +#include "debug.h" int GameCore::NODE_SIZE = 25; int GameCore::MAX_MOVE_DISTANCE = 200; @@ -132,6 +129,14 @@ void GameCore::on_lbutton_down(int x, int y) new_v.x = x; new_v.y = y; +#ifdef DEBUG + if (v != NULL) + cerr << "debug: GameCore::on_lbutton_down(): distance=" + << Vertex::distance(*v, new_v) << "\n"; + else + cerr << "debug: GameCore::on_lbutton_down(): distance=0, current_vertex is NULL\n"; +#endif + if (v != NULL && (Vertex::distance(*v, new_v) > MAX_MOVE_DISTANCE)) return; diff --git a/graph.cpp b/graph.cpp index 62ba6b4..57efbaf 100644 --- a/graph.cpp +++ b/graph.cpp @@ -1,13 +1,9 @@ #include "graph.h" +#include "debug.h" #include using std::abs; -#ifdef DEBUG -#include -using std::cerr; -#endif - Graph::Graph() { @@ -110,6 +106,5 @@ float Vertex::distance(Vertex a, Vertex b) { float dy = abs(static_cast(b.y) - a.y); float dx = abs(static_cast(b.x) - a.x); - if (dx == 0) return 0; - return dy/dx; + return sqrt(dy*dy + dx*dx); }