Fixed bug with distance calculations... distance <> slope
This commit is contained in:
parent
5b53e0b115
commit
1606dfb058
13
gamecore.cpp
13
gamecore.cpp
|
@ -1,9 +1,6 @@
|
|||
#include "gamecore.h"
|
||||
#include "drawutils.h"
|
||||
|
||||
#ifdef DEBUG
|
||||
#include <iostream>
|
||||
#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;
|
||||
|
||||
|
|
|
@ -1,13 +1,9 @@
|
|||
#include "graph.h"
|
||||
#include "debug.h"
|
||||
#include <cmath>
|
||||
|
||||
using std::abs;
|
||||
|
||||
#ifdef DEBUG
|
||||
#include <iostream>
|
||||
using std::cerr;
|
||||
#endif
|
||||
|
||||
|
||||
Graph::Graph()
|
||||
{
|
||||
|
@ -110,6 +106,5 @@ float Vertex::distance(Vertex a, Vertex b)
|
|||
{
|
||||
float dy = abs(static_cast<float>(b.y) - a.y);
|
||||
float dx = abs(static_cast<float>(b.x) - a.x);
|
||||
if (dx == 0) return 0;
|
||||
return dy/dx;
|
||||
return sqrt(dy*dy + dx*dx);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user