Support different colours for different vertices
This commit is contained in:
16
graph.cpp
16
graph.cpp
@ -58,14 +58,14 @@ bool Graph::crosses_edge(Edge e)
|
||||
}
|
||||
|
||||
|
||||
void Graph::do_vertex(int x, int y, int r)
|
||||
void Graph::do_vertex(int x, int y, int r, int colour)
|
||||
{
|
||||
if (vertex_present(x, y, r)) select_vertex(x, y);
|
||||
else add_vertex(x, y, r);
|
||||
else add_vertex(x, y, r, colour);
|
||||
}
|
||||
|
||||
|
||||
void Graph::select_vertex(int x, int y)
|
||||
Vertex* Graph::select_vertex(int x, int y)
|
||||
{
|
||||
for (list<Vertex*>::iterator cursor = vertices.begin();
|
||||
cursor != vertices.end(); cursor++)
|
||||
@ -73,16 +73,17 @@ void Graph::select_vertex(int x, int y)
|
||||
Vertex* v = *cursor;
|
||||
if (MathUtils::distance(v->x, v->y, x, y) <= v->r)
|
||||
{
|
||||
current_vertex = v;
|
||||
current_vertex = v
|
||||
return;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
void Graph::add_vertex(int x, int y, int r)
|
||||
void Graph::add_vertex(int x, int y, int r, int colour)
|
||||
{
|
||||
Vertex* v = new Vertex(x, y, r);
|
||||
Vertex* v = new Vertex(x, y, r, colour);
|
||||
|
||||
// Make sure the nodes won't overlap
|
||||
if (vertex_would_overlap(v->x, v->y, v->r))
|
||||
@ -124,9 +125,10 @@ void Graph::add_vertex(int x, int y, int r)
|
||||
}
|
||||
|
||||
|
||||
Vertex::Vertex(int x, int y, int r)
|
||||
Vertex::Vertex(int x, int y, int r, int colour)
|
||||
{
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
this->r = r;
|
||||
this->colour = colour;
|
||||
}
|
||||
|
Reference in New Issue
Block a user