Factored distance calculation into separate utility class
This commit is contained in:
18
graph.cpp
18
graph.cpp
@ -1,8 +1,6 @@
|
||||
#include "graph.h"
|
||||
#include "debug.h"
|
||||
#include <cmath>
|
||||
|
||||
using std::abs;
|
||||
#include "mathutils.h"
|
||||
|
||||
int Graph::MAX_MOVE_DISTANCE = 100;
|
||||
|
||||
@ -77,7 +75,11 @@ void Graph::select_vertex(int x, int y)
|
||||
void Graph::add_vertex(int x, int y, int size)
|
||||
{
|
||||
if (current_vertex != NULL &&
|
||||
(Vertex::distance(*current_vertex, Vertex(x, y)) > MAX_MOVE_DISTANCE))
|
||||
(MathUtils::distance(static_cast<float>(current_vertex->x),
|
||||
static_cast<float>(current_vertex->y),
|
||||
static_cast<float>(x),
|
||||
static_cast<float>(y))
|
||||
> MAX_MOVE_DISTANCE))
|
||||
return;
|
||||
|
||||
Vertex* v = new Vertex(x, y);
|
||||
@ -102,11 +104,3 @@ void Graph::add_vertex(int x, int y, int size)
|
||||
edges.push_back(e);
|
||||
current_vertex = v;
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
return sqrt(dy*dy + dx*dx);
|
||||
}
|
||||
|
Reference in New Issue
Block a user