60 lines
1.1 KiB
C++
60 lines
1.1 KiB
C++
/* 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;
|
|
|
|
class Vertex
|
|
{
|
|
public:
|
|
Vertex(int x, int y, int r, int colour = 0x000000);
|
|
|
|
int x;
|
|
int y;
|
|
int r;
|
|
int colour;
|
|
};
|
|
|
|
struct Edge
|
|
{
|
|
Vertex* a;
|
|
Vertex* b;
|
|
};
|
|
|
|
class Graph
|
|
{
|
|
public:
|
|
Graph(bool planar);
|
|
virtual ~Graph();
|
|
|
|
list<Vertex*> get_vertices() const { return vertices; }
|
|
list<Edge> get_edges() const { return edges; }
|
|
|
|
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);
|
|
|
|
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 planar;
|
|
};
|
|
|
|
#endif
|