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 "gamecore.h"
|
||||||
#include "drawutils.h"
|
#include "drawutils.h"
|
||||||
|
#include "debug.h"
|
||||||
#ifdef DEBUG
|
|
||||||
#include <iostream>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int GameCore::NODE_SIZE = 25;
|
int GameCore::NODE_SIZE = 25;
|
||||||
int GameCore::MAX_MOVE_DISTANCE = 200;
|
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.x = x;
|
||||||
new_v.y = y;
|
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))
|
if (v != NULL && (Vertex::distance(*v, new_v) > MAX_MOVE_DISTANCE))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,9 @@
|
||||||
#include "graph.h"
|
#include "graph.h"
|
||||||
|
#include "debug.h"
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
using std::abs;
|
using std::abs;
|
||||||
|
|
||||||
#ifdef DEBUG
|
|
||||||
#include <iostream>
|
|
||||||
using std::cerr;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
Graph::Graph()
|
Graph::Graph()
|
||||||
{
|
{
|
||||||
|
@ -110,6 +106,5 @@ float Vertex::distance(Vertex a, Vertex b)
|
||||||
{
|
{
|
||||||
float dy = abs(static_cast<float>(b.y) - a.y);
|
float dy = abs(static_cast<float>(b.y) - a.y);
|
||||||
float dx = abs(static_cast<float>(b.x) - a.x);
|
float dx = abs(static_cast<float>(b.x) - a.x);
|
||||||
if (dx == 0) return 0;
|
return sqrt(dy*dy + dx*dx);
|
||||||
return dy/dx;
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user