added a score value and some docs to Graph class
This commit is contained in:
parent
6560b1c28b
commit
3a3132e44a
|
@ -71,9 +71,9 @@ bool Graph::crosses_edge(Edge e)
|
|||
}
|
||||
|
||||
|
||||
bool Graph::add_vertex(int x, int y, int r, int colour, Vertex* src)
|
||||
bool Graph::add_vertex(int x, int y, int r, int colour, int score, Vertex* src)
|
||||
{
|
||||
Vertex* v = new Vertex(x, y, r, colour);
|
||||
Vertex* v = new Vertex(x, y, r, colour, score);
|
||||
|
||||
// Make sure the nodes won't overlap
|
||||
if (vertex_would_overlap(v->x, v->y, v->r))
|
||||
|
|
27
graph.h
27
graph.h
|
@ -1,7 +1,17 @@
|
|||
/* Represents an undirected graph.
|
||||
* Also contains the vertex and edge classes
|
||||
* vertexes know their center point on the SDL Surface -
|
||||
* bad decoupling maybe, but not too bad, all things considered
|
||||
* These are not quite traditional graph theory graphs, because they also have
|
||||
* cartesian coordinates, and can do some math to ensure planarity is preserved
|
||||
* (that is, planarity in the existant layout, not being isomorphic to a
|
||||
* planar)
|
||||
*
|
||||
* Each vertex also contains a 'colour' and a 'score', which are just integers
|
||||
* but may be useful for various algorithms
|
||||
*
|
||||
* fixme: this isn't a terribly *efficient* setup - Vertices don't know about
|
||||
* their neighbors, because the 'edge' class handles that instead. This makes
|
||||
* walking the tree O(n^2) or so, which is crappy. However, this implementation
|
||||
* is *simple* and will do well for small-to-medium graphs, I suspect
|
||||
*/
|
||||
|
||||
#ifndef _GRAPH_H_
|
||||
|
@ -14,18 +24,20 @@ using std::list;
|
|||
class Vertex
|
||||
{
|
||||
public:
|
||||
Vertex(int x, int y, int r, int colour = 0x000000);
|
||||
Vertex(int x, int y, int r, int colour = 0, int score = 0);
|
||||
|
||||
int x;
|
||||
int y;
|
||||
int r;
|
||||
int colour;
|
||||
int score;
|
||||
};
|
||||
|
||||
struct Edge
|
||||
{
|
||||
Vertex* a;
|
||||
Vertex* b;
|
||||
int score;
|
||||
};
|
||||
|
||||
class Graph
|
||||
|
@ -39,20 +51,19 @@ class Graph
|
|||
|
||||
bool point_in_vertex(int x, int y, int size);
|
||||
Vertex * vertex_at(int x, int y);
|
||||
virtual bool add_vertex(int x, int y, int r, int colour, Vertex* src=NULL);
|
||||
virtual bool add_vertex(int x, int y, int r, int colour = 0, int score = 0,
|
||||
Vertex* src=NULL);
|
||||
|
||||
bool is_planar() const { return planar; }
|
||||
void set_planar(bool planar) { this->planar = planar; }
|
||||
|
||||
private:
|
||||
bool vertex_would_overlap(int x, int y, int r);
|
||||
bool crosses_edge(Edge e);
|
||||
|
||||
protected:
|
||||
list<Vertex*> vertices;
|
||||
list<Edge> edges;
|
||||
|
||||
private:
|
||||
bool vertex_would_overlap(int x, int y, int r);
|
||||
bool crosses_edge(Edge e);
|
||||
bool planar;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user