49 lines
1023 B
C++
49 lines
1023 B
C++
#include "graph.h"
|
|
|
|
bool Graph::vertex_present(int x, int y, int size)
|
|
{
|
|
int delta = size / 2;
|
|
|
|
int x_min = x - delta;
|
|
int x_max = x + delta;
|
|
int y_min = y - delta;
|
|
int y_max = y + delta;
|
|
|
|
for (list<Vertex>::iterator cursor = vertices.begin();
|
|
cursor != vertices.end(); cursor++)
|
|
{
|
|
Vertex v = *cursor;
|
|
if (((x_min >= v.x_min && x_min <= x_max) &&
|
|
((y_min >= v.y_min && y_min <= y_max) ||
|
|
(y_max >= v.y_min && y_max <= y_max))) ||
|
|
((x_max >= v.x_min && x_max <= x_max) &&
|
|
((y_min >= v.y_min && y_min <= y_max) ||
|
|
(y_max >= v.y_min && y_max <= y_max))))
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
void Graph::add_vertex(int x, int y, int size)
|
|
{
|
|
Vertex v;
|
|
v.x = x;
|
|
v.y = y;
|
|
|
|
v.x_min = x - size/2;
|
|
v.x_max = x + size/2;
|
|
v.y_min = y - size/2;
|
|
v.y_max = y + size/2;
|
|
|
|
if (vertex_present(v.x, v.y, 25)) return;
|
|
|
|
vertices.push_back(v);
|
|
Edge e;
|
|
e.a = last_vertex;
|
|
e.b = v;
|
|
edges.push_back(e);
|
|
last_vertex = v;
|
|
}
|
|
|