2011-06-22 21:29:41 +00:00
|
|
|
/* Represents an undirected graph.
|
2011-06-27 22:10:24 +00:00
|
|
|
* Also contains the vertex class
|
2011-06-24 14:18:31 +00:00
|
|
|
* 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
|
2011-06-22 21:29:41 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _GRAPH_H_
|
|
|
|
#define _GRAPH_H_
|
|
|
|
|
2011-07-03 20:37:07 +00:00
|
|
|
#include "vertex.h"
|
2011-06-22 21:29:41 +00:00
|
|
|
#include <list>
|
|
|
|
|
|
|
|
using std::list;
|
|
|
|
|
2011-06-27 22:10:24 +00:00
|
|
|
|
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; }
|
2011-06-24 15:03:40 +00:00
|
|
|
list<Vertex*> get_colour(int colour);
|
2011-06-22 21:29:41 +00:00
|
|
|
|
2011-07-01 16:24:52 +00:00
|
|
|
bool point_in_vertex(int x, int y, int z);
|
|
|
|
Vertex * vertex_at(int x, int y, int z);
|
2011-07-02 02:04:58 +00:00
|
|
|
virtual bool add_vertex(Vertex* v, Vertex* src=NULL);
|
2011-06-24 18:59:18 +00:00
|
|
|
void remove_vertex(Vertex* target);
|
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
|
|
|
|
2011-06-23 21:28:49 +00:00
|
|
|
protected:
|
2011-06-23 01:54:35 +00:00
|
|
|
list<Vertex*> vertices;
|
2011-06-23 21:28:49 +00:00
|
|
|
|
|
|
|
private:
|
2011-07-01 16:24:52 +00:00
|
|
|
bool vertex_would_overlap(int x, int y, int z, int r);
|
2011-06-27 22:10:24 +00:00
|
|
|
bool crosses_edge(Vertex* a, Vertex* b);
|
2011-06-23 21:28:49 +00:00
|
|
|
bool planar;
|
2011-06-22 21:29:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|