2011-06-22 21:29:41 +00:00
|
|
|
/* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _GRAPH_H_
|
|
|
|
#define _GRAPH_H_
|
|
|
|
|
|
|
|
#include <list>
|
|
|
|
|
|
|
|
using std::list;
|
|
|
|
|
2011-06-23 01:54:35 +00:00
|
|
|
class Vertex
|
2011-06-22 21:29:41 +00:00
|
|
|
{
|
2011-06-23 01:54:35 +00:00
|
|
|
public:
|
2011-06-23 19:10:40 +00:00
|
|
|
Vertex(int x, int y, int r, int colour = 0x000000);
|
2011-06-23 03:06:23 +00:00
|
|
|
|
2011-06-22 21:29:41 +00:00
|
|
|
int x;
|
|
|
|
int y;
|
2011-06-23 16:36:40 +00:00
|
|
|
int r;
|
2011-06-23 19:10:40 +00:00
|
|
|
int colour;
|
2011-06-22 21:29:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Edge
|
|
|
|
{
|
2011-06-23 01:54:35 +00:00
|
|
|
Vertex* a;
|
|
|
|
Vertex* b;
|
2011-06-22 21:29:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class Graph
|
|
|
|
{
|
|
|
|
public:
|
2011-06-23 21:28:49 +00:00
|
|
|
Graph(bool planar);
|
|
|
|
virtual ~Graph();
|
2011-06-22 21:29:41 +00:00
|
|
|
|
2011-06-23 18:42:07 +00:00
|
|
|
list<Vertex*> get_vertices() const { return vertices; }
|
|
|
|
list<Edge> get_edges() const { return edges; }
|
2011-06-22 21:29:41 +00:00
|
|
|
|
2011-06-23 21:28:49 +00:00
|
|
|
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);
|
2011-06-23 18:42:07 +00:00
|
|
|
|
2011-06-23 21:28:49 +00:00
|
|
|
bool is_planar() const { return planar; }
|
|
|
|
void set_planar(bool planar) { this->planar = planar; }
|
2011-06-22 21:29:41 +00:00
|
|
|
|
|
|
|
private:
|
2011-06-23 19:10:40 +00:00
|
|
|
bool vertex_would_overlap(int x, int y, int r);
|
|
|
|
bool crosses_edge(Edge e);
|
2011-06-23 02:32:33 +00:00
|
|
|
|
2011-06-23 21:28:49 +00:00
|
|
|
protected:
|
2011-06-23 01:54:35 +00:00
|
|
|
list<Vertex*> vertices;
|
2011-06-22 21:29:41 +00:00
|
|
|
list<Edge> edges;
|
2011-06-23 21:28:49 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
bool planar;
|
2011-06-22 21:29:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|